Search in sources :

Example 1 with THashMapSerializer

use of org.janusgraph.graphdb.serializer.attributes.THashMapSerializer in project janusgraph by JanusGraph.

the class SerializerTest method customHashMapSerializeTest.

@Test
public void customHashMapSerializeTest() {
    serialize.registerClass(1, HashMap.class, new THashMapSerializer());
    DataOutput out = serialize.getDataOutput(128);
    final String property1 = "property1";
    final String value1 = "value1";
    final HashMap<String, Object> hashMapIn = new HashMap<>();
    hashMapIn.put(property1, value1);
    out.writeObjectNotNull(hashMapIn);
    ReadBuffer b = out.getStaticBuffer().asReadBuffer();
    if (printStats)
        log.debug(bufferStats(b));
    final HashMap<String, Object> hashMapOut = serialize.readObjectNotNull(b, HashMap.class);
    assertNotNull(hashMapOut);
    assertEquals(2, hashMapOut.size());
    assertEquals(value1, hashMapOut.get(property1));
    // THashMapSerializer adds this
    assertTrue(hashMapOut.containsKey(THashMapSerializer.class.getName()));
}
Also used : DataOutput(org.janusgraph.graphdb.database.serialize.DataOutput) ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) THashMapSerializer(org.janusgraph.graphdb.serializer.attributes.THashMapSerializer) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Aggregations

HashMap (java.util.HashMap)1 ReadBuffer (org.janusgraph.diskstorage.ReadBuffer)1 DataOutput (org.janusgraph.graphdb.database.serialize.DataOutput)1 THashMapSerializer (org.janusgraph.graphdb.serializer.attributes.THashMapSerializer)1 Test (org.junit.jupiter.api.Test)1