Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flakiness caused by hash map #1133

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.hubspot.jinjava.util.EagerReconstructionUtils;
import com.hubspot.jinjava.util.PrefixToPreserveState;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -188,8 +188,8 @@ private static void constructFullAliasPathMap(
currentMap.put(
allAliases[allAliases.length - 1],
child.getContext().isDeferredExecutionMode()
? DeferredValue.instance(new PyMap(new HashMap<>()))
: new PyMap(new HashMap<>())
? DeferredValue.instance(new PyMap(new LinkedHashMap<>()))
: new PyMap(new LinkedHashMap<>())
);
}

Expand All @@ -211,14 +211,14 @@ private static Map<String, Object> getMapForCurrentContextAlias(
(DeferredValue) parentValueForChild
).getOriginalValue();
}
Map<String, Object> newMap = new PyMap(new HashMap<>());
Map<String, Object> newMap = new PyMap(new LinkedHashMap<>());
child
.getContext()
.getParent()
.put(currentImportAlias, DeferredValue.instance(newMap));
return newMap;
} else {
Map<String, Object> newMap = new PyMap(new HashMap<>());
Map<String, Object> newMap = new PyMap(new LinkedHashMap<>());
child
.getContext()
.getParent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.RandomStringUtils;
Expand All @@ -23,26 +24,26 @@ public class PyishObjectMapperTest {

@Test
public void itSerializesMapWithNullKeysAsEmptyString() {
Map<String, Object> map = new SizeLimitingPyMap(new HashMap<>(), 10);
Map<String, Object> map = new SizeLimitingPyMap(new LinkedHashMap<>(), 10);
map.put("foo", "bar");
map.put(null, "null");
assertThat(PyishObjectMapper.getAsPyishString(map))
.isEqualTo("{'': 'null', 'foo': 'bar'} ");
.isEqualTo("{'foo': 'bar', '': 'null'} ");
}

@Test
public void itSerializesMapEntrySet() {
SizeLimitingPyMap map = new SizeLimitingPyMap(new HashMap<>(), 10);
SizeLimitingPyMap map = new SizeLimitingPyMap(new LinkedHashMap<>(), 10);
map.put("foo", "bar");
map.put("bar", ImmutableMap.of("foobar", new ArrayList<>()));
String result = PyishObjectMapper.getAsPyishString(map.items());
assertThat(result)
.isEqualTo("[fn:map_entry('bar', {'foobar': []} ), fn:map_entry('foo', 'bar')]");
.isEqualTo("[fn:map_entry('foo', 'bar'), fn:map_entry('bar', {'foobar': []} )]");
}

@Test
public void itSerializesMapEntrySetWithLimit() {
SizeLimitingPyMap map = new SizeLimitingPyMap(new HashMap<>(), 10);
SizeLimitingPyMap map = new SizeLimitingPyMap(new LinkedHashMap<>(), 10);
map.put("foo", "bar");
map.put("bar", ImmutableMap.of("foobar", new ArrayList<>()));

Expand All @@ -53,19 +54,19 @@ public void itSerializesMapEntrySetWithLimit() {
JinjavaInterpreter.pushCurrent(jinjava.newInterpreter());
String result = PyishObjectMapper.getAsPyishString(map.items());
assertThat(result)
.isEqualTo("[fn:map_entry('bar', {'foobar': []} ), fn:map_entry('foo', 'bar')]");
.isEqualTo("[fn:map_entry('foo', 'bar'), fn:map_entry('bar', {'foobar': []} )]");
} finally {
JinjavaInterpreter.popCurrent();
}
}

@Test
public void itSerializesMapWithNullValues() {
Map<String, Object> map = new SizeLimitingPyMap(new HashMap<>(), 10);
Map<String, Object> map = new SizeLimitingPyMap(new LinkedHashMap<>(), 10);
map.put("foo", "bar");
map.put("foobar", null);
assertThat(PyishObjectMapper.getAsPyishString(map))
.isEqualTo("{'foobar': null, 'foo': 'bar'} ");
.isEqualTo("{'foo': 'bar', 'foobar': null} ");
}

@Test
Expand Down