Search in sources :

Example 1 with WriteByteBuffer

use of com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer in project titan by thinkaurelius.

the class StaticArrayEntryTest method testInversion.

@Test
public void testInversion() {
    WriteBuffer wb = new WriteByteBuffer(20);
    wb.putInt(1).putInt(2).putInt(3).putInt(4);
    Entry entry = new StaticArrayEntry(wb.getStaticBufferFlipBytes(4, 2 * 4), 3 * 4);
    ReadBuffer rb = entry.asReadBuffer();
    assertEquals(1, rb.getInt());
    assertEquals(2, rb.subrange(4, true).getInt());
    assertEquals(~2, rb.getInt());
    assertEquals(3, rb.getInt());
    assertEquals(4, rb.getInt());
    rb.movePositionTo(entry.getValuePosition());
    assertEquals(4, rb.getInt());
}
Also used : KeyValueEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.keyvalue.KeyValueEntry) StaticArrayEntry(com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry) WriteByteBuffer(com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer) StaticArrayEntry(com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry) Test(org.junit.Test)

Example 2 with WriteByteBuffer

use of com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer in project titan by thinkaurelius.

the class StaticArrayEntryTest method testArrayBuffer.

@Test
public void testArrayBuffer() {
    WriteBuffer wb = new WriteByteBuffer(128);
    wb.putInt(1).putInt(2).putInt(3).putInt(4);
    int valuePos = wb.getPosition();
    wb.putInt(5).putInt(6);
    Entry entry = new StaticArrayEntry(wb.getStaticBuffer(), valuePos);
    assertEquals(4 * 4, entry.getValuePosition());
    assertEquals(6 * 4, entry.length());
    assertTrue(entry.hasValue());
    for (int i = 1; i <= 6; i++) assertEquals(i, entry.getInt((i - 1) * 4));
    ReadBuffer rb = entry.asReadBuffer();
    for (int i = 1; i <= 6; i++) assertEquals(i, rb.getInt());
    assertFalse(rb.hasRemaining());
    assertNull(entry.getCache());
    entry.setCache(cache);
    assertEquals(cache, entry.getCache());
    rb = entry.getColumnAs(StaticBuffer.STATIC_FACTORY).asReadBuffer();
    for (int i = 1; i <= 4; i++) assertEquals(i, rb.getInt());
    assertFalse(rb.hasRemaining());
    rb = entry.getValueAs(StaticBuffer.STATIC_FACTORY).asReadBuffer();
    for (int i = 5; i <= 6; i++) assertEquals(i, rb.getInt());
    assertFalse(rb.hasRemaining());
}
Also used : KeyValueEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.keyvalue.KeyValueEntry) StaticArrayEntry(com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry) WriteByteBuffer(com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer) StaticArrayEntry(com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry) Test(org.junit.Test)

Example 3 with WriteByteBuffer

use of com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer in project titan by thinkaurelius.

the class VariableLongTest method byteOrderPreservingPositiveBackward.

@Test
public void byteOrderPreservingPositiveBackward() {
    long[] scalingFactors = { Long.MAX_VALUE, 1000, 1000000000l };
    for (int t = 0; t < 10000000; t++) {
        StaticBuffer[] b = new StaticBuffer[2];
        long[] l = new long[2];
        for (int i = 0; i < 2; i++) {
            l[i] = randomPosLong(scalingFactors[random.nextInt(scalingFactors.length)]);
            WriteBuffer out = new WriteByteBuffer(11);
            VariableLong.writePositiveBackward(out, l[i]);
            b[i] = out.getStaticBuffer();
            ReadBuffer res = b[i].asReadBuffer();
            res.movePositionTo(res.length());
            assertEquals(l[i], VariableLong.readPositiveBackward(res));
        }
        //            System.out.println(l[0] + " vs " + l[1]);
        assertEquals(Math.signum(Long.compare(l[0], l[1])), Math.signum(b[0].compareTo(b[1])), 0.01);
    }
}
Also used : ReadBuffer(com.thinkaurelius.titan.diskstorage.ReadBuffer) WriteBuffer(com.thinkaurelius.titan.diskstorage.WriteBuffer) WriteByteBuffer(com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) Test(org.junit.Test)

Example 4 with WriteByteBuffer

use of com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer in project titan by thinkaurelius.

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(com.thinkaurelius.titan.diskstorage.util.ReadArrayBuffer) WriteByteBuffer(com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer) UUID(java.util.UUID) Test(org.junit.Test)

Example 5 with WriteByteBuffer

use of com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer in project titan by thinkaurelius.

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(com.thinkaurelius.titan.diskstorage.WriteBuffer) WriteByteBuffer(com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer)

Aggregations

WriteByteBuffer (com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer)18 WriteBuffer (com.thinkaurelius.titan.diskstorage.WriteBuffer)14 Test (org.junit.Test)7 ReadBuffer (com.thinkaurelius.titan.diskstorage.ReadBuffer)4 StaticArrayEntry (com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry)3 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)2 KeyValueEntry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.keyvalue.KeyValueEntry)2 ReadArrayBuffer (com.thinkaurelius.titan.diskstorage.util.ReadArrayBuffer)1 DataOutput (com.thinkaurelius.titan.graphdb.database.serialize.DataOutput)1 KryoSerializer (com.thinkaurelius.titan.graphdb.database.serialize.kryo.KryoSerializer)1 RelationType (com.thinkaurelius.titan.graphdb.internal.RelationType)1 UUID (java.util.UUID)1 StopWatch (org.apache.commons.lang.time.StopWatch)1