Search in sources :

Example 1 with StandardSerializer

use of com.thinkaurelius.titan.graphdb.database.serialize.StandardSerializer in project titan by thinkaurelius.

the class SerializerTestCommon method setUp.

@Before
public void setUp() throws Exception {
    serialize = new StandardSerializer();
    printStats = false;
}
Also used : StandardSerializer(com.thinkaurelius.titan.graphdb.database.serialize.StandardSerializer) Before(org.junit.Before)

Example 2 with StandardSerializer

use of com.thinkaurelius.titan.graphdb.database.serialize.StandardSerializer in project titan by thinkaurelius.

the class IDManagementTest method edgeTypeIDTest.

@Test
public void edgeTypeIDTest() {
    int partitionBits = 16;
    IDManager eid = new IDManager(partitionBits);
    int trails = 1000000;
    assertEquals(eid.getPartitionBound(), (1l << partitionBits));
    Serializer serializer = new StandardSerializer();
    for (int t = 0; t < trails; t++) {
        long count = RandomGenerator.randomLong(1, eid.getSchemaCountBound());
        long id;
        IDHandler.DirectionID dirID;
        RelationCategory type;
        if (Math.random() < 0.5) {
            id = eid.getSchemaId(IDManager.VertexIDType.UserEdgeLabel, count);
            assertTrue(eid.isEdgeLabelId(id));
            assertFalse(eid.isSystemRelationTypeId(id));
            type = RelationCategory.EDGE;
            if (Math.random() < 0.5)
                dirID = IDHandler.DirectionID.EDGE_IN_DIR;
            else
                dirID = IDHandler.DirectionID.EDGE_OUT_DIR;
        } else {
            type = RelationCategory.PROPERTY;
            id = eid.getSchemaId(IDManager.VertexIDType.UserPropertyKey, count);
            assertTrue(eid.isPropertyKeyId(id));
            assertFalse(eid.isSystemRelationTypeId(id));
            dirID = IDHandler.DirectionID.PROPERTY_DIR;
        }
        assertTrue(eid.isRelationTypeId(id));
        StaticBuffer b = IDHandler.getRelationType(id, dirID, false);
        //            System.out.println(dirID);
        //            System.out.println(getBinary(id));
        //            System.out.println(getBuffer(b.asReadBuffer()));
        ReadBuffer rb = b.asReadBuffer();
        IDHandler.RelationTypeParse parse = IDHandler.readRelationType(rb);
        assertEquals(id, parse.typeId);
        assertEquals(dirID, parse.dirID);
        assertFalse(rb.hasRemaining());
        //Inline edge type
        WriteBuffer wb = new WriteByteBuffer(9);
        IDHandler.writeInlineRelationType(wb, id);
        long newId = IDHandler.readInlineRelationType(wb.getStaticBuffer().asReadBuffer());
        assertEquals(id, newId);
        //Compare to Kryo
        DataOutput out = serializer.getDataOutput(10);
        IDHandler.writeRelationType(out, id, dirID, false);
        assertEquals(b, out.getStaticBuffer());
        //Make sure the bounds are right
        StaticBuffer[] bounds = IDHandler.getBounds(type, false);
        assertTrue(bounds[0].compareTo(b) < 0);
        assertTrue(bounds[1].compareTo(b) > 0);
        bounds = IDHandler.getBounds(RelationCategory.RELATION, false);
        assertTrue(bounds[0].compareTo(b) < 0);
        assertTrue(bounds[1].compareTo(b) > 0);
    }
}
Also used : DataOutput(com.thinkaurelius.titan.graphdb.database.serialize.DataOutput) WriteBuffer(com.thinkaurelius.titan.diskstorage.WriteBuffer) ReadBuffer(com.thinkaurelius.titan.diskstorage.ReadBuffer) RelationCategory(com.thinkaurelius.titan.graphdb.internal.RelationCategory) WriteByteBuffer(com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer) StandardSerializer(com.thinkaurelius.titan.graphdb.database.serialize.StandardSerializer) IDHandler(com.thinkaurelius.titan.graphdb.database.idhandling.IDHandler) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) Serializer(com.thinkaurelius.titan.graphdb.database.serialize.Serializer) StandardSerializer(com.thinkaurelius.titan.graphdb.database.serialize.StandardSerializer) Test(org.junit.Test)

Aggregations

StandardSerializer (com.thinkaurelius.titan.graphdb.database.serialize.StandardSerializer)2 ReadBuffer (com.thinkaurelius.titan.diskstorage.ReadBuffer)1 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)1 WriteBuffer (com.thinkaurelius.titan.diskstorage.WriteBuffer)1 WriteByteBuffer (com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer)1 IDHandler (com.thinkaurelius.titan.graphdb.database.idhandling.IDHandler)1 DataOutput (com.thinkaurelius.titan.graphdb.database.serialize.DataOutput)1 Serializer (com.thinkaurelius.titan.graphdb.database.serialize.Serializer)1 RelationCategory (com.thinkaurelius.titan.graphdb.internal.RelationCategory)1 Before (org.junit.Before)1 Test (org.junit.Test)1