now correctly comparing char[] values

This commit is contained in:
Rob Austin
2014-12-23 16:14:52 +00:00
parent 874b675661
commit 9db7295f2b
2 changed files with 36 additions and 24 deletions
@@ -63,12 +63,12 @@ public class ChronicleMapConverter<K, V> implements Converter {
final AbstractMap.SimpleEntry e = (AbstractMap.SimpleEntry) o;
final Object key = e.getKey();
writer.startNode(key.getClass().getCanonicalName());
writer.startNode(key.getClass().getName());
marshallingContext.convertAnother(key);
writer.endNode();
Object value = e.getValue();
writer.startNode(value.getClass().getCanonicalName());
writer.startNode(value.getClass().getName());
marshallingContext.convertAnother(value);
writer.endNode();
@@ -114,9 +114,7 @@ public class ChronicleMapConverter<K, V> implements Converter {
static <E> E deserialize(@NotNull UnmarshallingContext unmarshallingContext,
@NotNull HierarchicalStreamReader reader) {
final String clazz = reader.getNodeName();
switch (clazz) {
switch (reader.getNodeName()) {
case "java.util.Collections$EmptySet":
return (E) Collections.EMPTY_SET;
@@ -130,7 +128,7 @@ public class ChronicleMapConverter<K, V> implements Converter {
}
return (E) unmarshallingContext.convertAnother(null, forName(clazz));
return (E) unmarshallingContext.convertAnother(null, forName(reader.getNodeName()));
}
static Class forName(String clazz) {
@@ -159,3 +157,4 @@ public class ChronicleMapConverter<K, V> implements Converter {
}
}
@@ -122,8 +122,8 @@ public class CHMUseCasesTest {
return;
// waitTillEqual(5000);
// assertEquals(map1, map2);
waitTillEqual(5000);
assertEquals(map1, map2);
}
if (typeOfMap == TypeOfMap.SIMPLE)
@@ -131,35 +131,48 @@ public class CHMUseCasesTest {
}
private void assertArrayValueEquals(ChronicleMap map1, ChronicleMap map2) {
assertEquals(map1.size(), map2.size());
for (Object key : map1.keySet()) {
if (map1.valueClass() == byte[].class)
Assert.assertArrayEquals((byte[]) map1.get(key), (byte[]) map2.get(key));
else if (map1.valueClass() == char[].class)
Assert.assertArrayEquals((char[]) map1.get(key), (char[]) map2.get(key));
else throw new IllegalStateException("unsupported type");
}
}
private void checkJsonSerilization() {
// see HCOLL-265 Chronicle Maps with Identical char[] values are not equal1
if (map1.keyClass() == char[].class || map1.valueClass() == char[].class) {
return;
}
File file = new File(TMP + "/chronicle-map-" + System.nanoTime() + ".json");
file.deleteOnExit();
try {
try {
map1.getAll(file);
map1.getAll(file);
try (ChronicleMap<Integer, Double> actual = ChronicleMapBuilder.of(map1.keyClass(),
map1.valueClass())
.create()) {
actual.putAll(file);
try (ChronicleMap<Integer, Double> actual = ChronicleMapBuilder.of(map1.keyClass(),
map1.valueClass())
.create()) {
actual.putAll(file);
if (map1.keyClass() == char[].class || map1.valueClass() == char[].class) {
assertArrayValueEquals(map1, actual);
} else {
Assert.assertEquals(map1, actual);
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (IOException e) {
Assert.fail();
} finally {
file.delete();
}