Search in sources :

Example 26 with ReadBuffer

use of org.janusgraph.diskstorage.ReadBuffer in project janusgraph by JanusGraph.

the class IDManagementTest method writingInlineEdgeTypes.

@Test
public void writingInlineEdgeTypes() {
    int numTries = 100;
    WriteBuffer out = new WriteByteBuffer(8 * numTries);
    for (SystemRelationType t : SYSTEM_TYPES) {
        IDHandler.writeInlineRelationType(out, t.longId());
    }
    for (long i = 1; i <= numTries; i++) {
        IDHandler.writeInlineRelationType(out, IDManager.getSchemaId(IDManager.VertexIDType.UserEdgeLabel, i * 1000));
    }
    ReadBuffer in = out.getStaticBuffer().asReadBuffer();
    for (SystemRelationType t : SYSTEM_TYPES) {
        assertEquals(t, SystemTypeManager.getSystemType(IDHandler.readInlineRelationType(in)));
    }
    for (long i = 1; i <= numTries; i++) {
        assertEquals(i * 1000, IDManager.stripEntireRelationTypePadding(IDHandler.readInlineRelationType(in)));
    }
}
Also used : SystemRelationType(org.janusgraph.graphdb.types.system.SystemRelationType) ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer) Test(org.junit.jupiter.api.Test)

Example 27 with ReadBuffer

use of org.janusgraph.diskstorage.ReadBuffer in project janusgraph by JanusGraph.

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, IDManager.getSchemaCountBound());
        long id;
        IDHandler.DirectionID dirID;
        RelationCategory type;
        if (Math.random() < 0.5) {
            id = IDManager.getSchemaId(IDManager.VertexIDType.UserEdgeLabel, count);
            assertTrue(eid.isEdgeLabelId(id));
            assertFalse(IDManager.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 = IDManager.getSchemaId(IDManager.VertexIDType.UserPropertyKey, count);
            assertTrue(eid.isPropertyKeyId(id));
            assertFalse(IDManager.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(org.janusgraph.graphdb.database.serialize.DataOutput) WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) RelationCategory(org.janusgraph.graphdb.internal.RelationCategory) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer) StandardSerializer(org.janusgraph.graphdb.database.serialize.StandardSerializer) IDHandler(org.janusgraph.graphdb.database.idhandling.IDHandler) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) Serializer(org.janusgraph.graphdb.database.serialize.Serializer) StandardSerializer(org.janusgraph.graphdb.database.serialize.StandardSerializer) Test(org.junit.jupiter.api.Test)

Example 28 with ReadBuffer

use of org.janusgraph.diskstorage.ReadBuffer in project janusgraph by JanusGraph.

the class SerializerTest method testObjectVerification.

@Test
public void testObjectVerification() {
    serialize.registerClass(2, TClass1.class, new TClass1Serializer());
    TClass1 t1 = new TClass1(24223, 0.25f);
    DataOutput out = serialize.getDataOutput(128);
    out.writeClassAndObject(t1);
    out.writeClassAndObject(null);
    out.writeObject(t1, TClass1.class);
    out.writeObject(null, TClass1.class);
    // Test failure
    for (Object o : new Object[] { new TClass2("abc", 2), Calendar.getInstance(), Lists.newArrayList() }) {
        try {
            out.writeObjectNotNull(o);
            fail();
        } catch (Exception ignored) {
        }
    }
    ReadBuffer b = out.getStaticBuffer().asReadBuffer();
    assertEquals(t1, serialize.readClassAndObject(b));
    assertNull(serialize.readClassAndObject(b));
    assertEquals(t1, serialize.readObject(b, TClass1.class));
    assertNull(serialize.readObject(b, TClass1.class));
    assertFalse(b.hasRemaining());
}
Also used : DataOutput(org.janusgraph.graphdb.database.serialize.DataOutput) TClass2(org.janusgraph.graphdb.serializer.attributes.TClass2) ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) TClass1(org.janusgraph.graphdb.serializer.attributes.TClass1) IOException(java.io.IOException) TClass1Serializer(org.janusgraph.graphdb.serializer.attributes.TClass1Serializer) Test(org.junit.jupiter.api.Test)

Example 29 with ReadBuffer

use of org.janusgraph.diskstorage.ReadBuffer in project janusgraph by JanusGraph.

the class ConsistentKeyLockerSerializer method fromLockColumn.

public TimestampRid fromLockColumn(StaticBuffer lockKey, TimestampProvider provider) {
    ReadBuffer r = lockKey.asReadBuffer();
    int len = r.length();
    long tsNS = r.getLong();
    len -= 8;
    byte[] curRid = new byte[len];
    for (int i = 0; r.hasRemaining(); i++) {
        curRid[i] = r.getByte();
    }
    StaticBuffer rid = new StaticArrayBuffer(curRid);
    Instant time = provider.getTime(tsNS);
    return new TimestampRid(time, rid);
}
Also used : ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) Instant(java.time.Instant) StaticArrayBuffer(org.janusgraph.diskstorage.util.StaticArrayBuffer) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer)

Aggregations

ReadBuffer (org.janusgraph.diskstorage.ReadBuffer)29 Test (org.junit.jupiter.api.Test)19 DataOutput (org.janusgraph.graphdb.database.serialize.DataOutput)16 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)9 WriteBuffer (org.janusgraph.diskstorage.WriteBuffer)7 WriteByteBuffer (org.janusgraph.diskstorage.util.WriteByteBuffer)7 Instant (java.time.Instant)3 Entry (org.janusgraph.diskstorage.Entry)3 StaticArrayEntry (org.janusgraph.diskstorage.util.StaticArrayEntry)3 TClass2 (org.janusgraph.graphdb.serializer.attributes.TClass2)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Geoshape (org.janusgraph.core.attribute.Geoshape)2 Serializer (org.janusgraph.graphdb.database.serialize.Serializer)2 TClass1 (org.janusgraph.graphdb.serializer.attributes.TClass1)2 TClass1Serializer (org.janusgraph.graphdb.serializer.attributes.TClass1Serializer)2 SpatialContextFactory (org.locationtech.spatial4j.context.SpatialContextFactory)2 LoggerFactory (org.slf4j.LoggerFactory)2 LongObjectHashMap (com.carrotsearch.hppc.LongObjectHashMap)1