Search in sources :

Example 11 with WriteByteBuffer

use of org.janusgraph.diskstorage.util.WriteByteBuffer 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 : ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer) Test(org.junit.Test)

Example 12 with WriteByteBuffer

use of org.janusgraph.diskstorage.util.WriteByteBuffer in project janusgraph by JanusGraph.

the class StaticArrayEntryTest method testTTLMetadata.

@Test
public void testTTLMetadata() {
    WriteBuffer wb = new WriteByteBuffer(128);
    wb.putInt(1).putInt(2).putInt(3).putInt(4);
    int valuePos = wb.getPosition();
    wb.putInt(5).putInt(6);
    StaticArrayEntry entry = new StaticArrayEntry(wb.getStaticBuffer(), valuePos);
    entry.setMetaData(EntryMetaData.TTL, 42);
    assertEquals(42, entry.getMetaData().get(EntryMetaData.TTL));
}
Also used : WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) Test(org.junit.Test)

Example 13 with WriteByteBuffer

use of org.janusgraph.diskstorage.util.WriteByteBuffer in project janusgraph by JanusGraph.

the class UUIDSerializerTest method testRoundTrip.

@Test
public void testRoundTrip() {
    // Write the UUID
    UUIDSerializer serializer = new UUIDSerializer();
    UUID uuid1 = UUID.randomUUID();
    WriteByteBuffer buffer = new WriteByteBuffer();
    serializer.write(buffer, uuid1);
    // And read it in again
    ReadArrayBuffer readBuffer = new ReadArrayBuffer(buffer.getStaticBuffer().getBytes(0, 16));
    UUID uuid2 = serializer.read(readBuffer);
    Assert.assertEquals(uuid1, uuid2);
}
Also used : ReadArrayBuffer(org.janusgraph.diskstorage.util.ReadArrayBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer) UUID(java.util.UUID) Test(org.junit.Test)

Example 14 with WriteByteBuffer

use of org.janusgraph.diskstorage.util.WriteByteBuffer in project janusgraph by JanusGraph.

the class VariableLongTest method readWriteTest.

private void readWriteTest(final ReadWriteLong impl, long maxValue, long jump, boolean negative, boolean backward) {
    Preconditions.checkArgument(maxValue % jump == 0);
    long allocate = maxValue / jump * 8 * (negative ? 2 : 1);
    Preconditions.checkArgument(allocate < (1 << 28));
    WriteBuffer wb = new WriteByteBuffer((int) allocate);
    int num = 0;
    StopWatch w = new StopWatch();
    w.start();
    for (long i = (negative ? -maxValue : 0); i <= maxValue; i += jump) {
        impl.write(wb, i);
        num++;
    }
    // for (int i=0;i<b.remaining();i++) System.out.print(b.get(i)+"|");
    w.stop();
    ReadBuffer rb = wb.getStaticBuffer().asReadBuffer();
    log.info("Writing " + num + " longs in " + rb.length() + " bytes. in time: " + w.getTime());
    final ReadVerify read = (rb1, expected) -> {
        int beforePos = rb1.getPosition();
        long value = impl.read(rb1);
        assertEquals(expected, value);
        int length = Math.abs(rb1.getPosition() - beforePos);
        assertEquals("On: " + expected, length, impl.length(expected));
    };
    if (backward) {
        rb.movePositionTo(rb.length());
        for (long i = maxValue; i != (negative ? -maxValue : 0); i -= jump) {
            read.next(rb, i);
        }
    } else {
        for (long i = (negative ? -maxValue : 0); i <= maxValue; i += jump) {
            read.next(rb, i);
        }
    }
    // Test boundaries
    wb = new WriteByteBuffer(512);
    impl.write(wb, 0);
    impl.write(wb, Long.MAX_VALUE);
    if (negative)
        impl.write(wb, -Long.MAX_VALUE);
    rb = wb.getStaticBuffer().asReadBuffer();
    if (backward) {
        rb.movePositionTo(rb.length());
        if (negative)
            assertEquals(-Long.MAX_VALUE, impl.read(rb));
        assertEquals(Long.MAX_VALUE, impl.read(rb));
        assertEquals(0, impl.read(rb));
    } else {
        assertEquals(0, impl.read(rb));
        assertEquals(Long.MAX_VALUE, impl.read(rb));
        if (negative)
            assertEquals(-Long.MAX_VALUE, impl.read(rb));
    }
}
Also used : ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) Logger(org.slf4j.Logger) WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer) VariableLong(org.janusgraph.graphdb.database.idhandling.VariableLong) StopWatch(org.apache.commons.lang.time.StopWatch) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) LoggerFactory(org.slf4j.LoggerFactory) Preconditions(com.google.common.base.Preconditions) Test(org.junit.Test) Random(java.util.Random) Assert.assertEquals(org.junit.Assert.assertEquals) ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer) StopWatch(org.apache.commons.lang.time.StopWatch)

Aggregations

WriteByteBuffer (org.janusgraph.diskstorage.util.WriteByteBuffer)14 WriteBuffer (org.janusgraph.diskstorage.WriteBuffer)10 Test (org.junit.Test)8 ReadBuffer (org.janusgraph.diskstorage.ReadBuffer)4 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)3 StaticArrayEntry (org.janusgraph.diskstorage.util.StaticArrayEntry)3 Preconditions (com.google.common.base.Preconditions)1 Random (java.util.Random)1 UUID (java.util.UUID)1 StopWatch (org.apache.commons.lang.time.StopWatch)1 ReadArrayBuffer (org.janusgraph.diskstorage.util.ReadArrayBuffer)1 IDHandler (org.janusgraph.graphdb.database.idhandling.IDHandler)1 VariableLong (org.janusgraph.graphdb.database.idhandling.VariableLong)1 DataOutput (org.janusgraph.graphdb.database.serialize.DataOutput)1 Serializer (org.janusgraph.graphdb.database.serialize.Serializer)1 StandardSerializer (org.janusgraph.graphdb.database.serialize.StandardSerializer)1 RelationCategory (org.janusgraph.graphdb.internal.RelationCategory)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1