use of org.apache.commons.collections4.map.ReferenceMap in project commons-collections by apache.
the class ReferenceMapTest method testDataSizeAfterSerialization.
/**
* Test whether after serialization the "data" HashEntry array is the same size as the original.<p>
*
* See <a href="https://issues.apache.org/jira/browse/COLLECTIONS-599">COLLECTIONS-599: HashEntry array object naming data initialized with double the size during deserialization</a>
*/
@Test
public void testDataSizeAfterSerialization() throws IOException, ClassNotFoundException {
final ReferenceMap<String, String> serializeMap = new ReferenceMap<>(ReferenceStrength.WEAK, ReferenceStrength.WEAK, true);
serializeMap.put("KEY", "VALUE");
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (ObjectOutputStream out = new ObjectOutputStream(baos)) {
out.writeObject(serializeMap);
}
final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
try (ObjectInputStream in = new ObjectInputStream(bais)) {
@SuppressWarnings("unchecked") final ReferenceMap<String, String> deserializedMap = (ReferenceMap<String, String>) in.readObject();
assertEquals(1, deserializedMap.size());
assertEquals(serializeMap.data.length, deserializedMap.data.length);
}
}
Aggregations