Search in sources :

Example 6 with WriteBuffer

use of org.janusgraph.diskstorage.WriteBuffer 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)

Example 7 with WriteBuffer

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

the class IDHandler method getRelationType.

public static StaticBuffer getRelationType(long relationTypeId, DirectionID dirID, boolean invisible) {
    WriteBuffer b = new WriteByteBuffer(relationTypeLength(relationTypeId));
    IDHandler.writeRelationType(b, relationTypeId, dirID, invisible);
    return b.getStaticBuffer();
}
Also used : WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer)

Example 8 with WriteBuffer

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

the class ConsistentKeyLockerSerializer method toLockCol.

public StaticBuffer toLockCol(Instant ts, StaticBuffer rid, TimestampProvider provider) {
    WriteBuffer b = new WriteByteBuffer(rid.length() + 8);
    b.putLong(provider.getTime(ts));
    WriteBufferUtil.put(b, rid);
    return b.getStaticBuffer();
}
Also used : WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer)

Example 9 with WriteBuffer

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

the class VariableLong method positiveBuffer.

public static StaticBuffer positiveBuffer(final long value) {
    WriteBuffer buffer = new WriteByteBuffer(positiveLength(value));
    writePositive(buffer, value);
    return buffer.getStaticBuffer();
}
Also used : WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer)

Example 10 with WriteBuffer

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

the class VariableLong method positiveBuffer.

public static StaticBuffer positiveBuffer(long[] value) {
    int len = 0;
    for (long aValue : value) len += positiveLength(aValue);
    WriteBuffer buffer = new WriteByteBuffer(len);
    for (long aValue : value) writePositive(buffer, aValue);
    return buffer.getStaticBuffer();
}
Also used : WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer)

Aggregations

WriteBuffer (org.janusgraph.diskstorage.WriteBuffer)10 WriteByteBuffer (org.janusgraph.diskstorage.util.WriteByteBuffer)10 ReadBuffer (org.janusgraph.diskstorage.ReadBuffer)4 Test (org.junit.Test)4 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)3 Preconditions (com.google.common.base.Preconditions)1 Random (java.util.Random)1 StopWatch (org.apache.commons.lang.time.StopWatch)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