Search in sources :

Example 1 with WriteByteBuffer

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

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 : ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) Entry(org.janusgraph.diskstorage.Entry) WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) Test(org.junit.jupiter.api.Test)

Example 2 with WriteByteBuffer

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

the class StaticArrayEntryTest method testReadWrite.

@Test
public void testReadWrite() {
    WriteBuffer b = new WriteByteBuffer(10);
    for (int i = 1; i < 4; i++) b.putByte((byte) i);
    for (int i = 1; i < 4; i++) b.putShort((short) i);
    for (int i = 1; i < 4; i++) b.putInt(i);
    for (int i = 1; i < 4; i++) b.putLong(i);
    for (int i = 1; i < 4; i++) b.putFloat(i);
    for (int i = 1; i < 4; i++) b.putDouble(i);
    for (int i = 101; i < 104; i++) b.putChar((char) i);
    ReadBuffer r = b.getStaticBuffer().asReadBuffer();
    assertEquals(1, r.getByte());
    assertArrayEquals(new byte[] { 2, 3 }, r.getBytes(2));
    assertEquals(1, r.getShort());
    assertArrayEquals(new short[] { 2, 3 }, r.getShorts(2));
    assertEquals(1, r.getInt());
    assertEquals(2, r.getInt());
    assertArrayEquals(new int[] { 3 }, r.getInts(1));
    assertEquals(1, r.getLong());
    assertArrayEquals(new long[] { 2, 3 }, r.getLongs(2));
    assertEquals(1.0, r.getFloat(), 0.00001);
    assertArrayEquals(new float[] { 2.0f, 3.0f }, r.getFloats(2));
    assertEquals(1, r.getDouble(), 0.0001);
    assertArrayEquals(new double[] { 2.0, 3.0 }, r.getDoubles(2));
    assertEquals((char) 101, r.getChar());
    assertEquals((char) 102, r.getChar());
    assertArrayEquals(new char[] { (char) 103 }, r.getChars(1));
}
Also used : ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer) Test(org.junit.jupiter.api.Test)

Example 3 with WriteByteBuffer

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

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 : ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) Entry(org.janusgraph.diskstorage.Entry) WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) Test(org.junit.jupiter.api.Test)

Example 4 with WriteByteBuffer

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

the class IDManagementTest method getBufferOf.

private static StaticBuffer getBufferOf(int s, long l) {
    WriteBuffer out = new WriteByteBuffer(4 + 8);
    out.putInt(s);
    out.putLong(l);
    return out.getStaticBuffer();
}
Also used : WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer)

Example 5 with WriteByteBuffer

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

the class ConsistentKeyLockerSerializer method toLockKey.

public StaticBuffer toLockKey(StaticBuffer key, StaticBuffer column) {
    WriteBuffer b = new WriteByteBuffer(key.length() + column.length() + 4);
    b.putInt(key.length());
    WriteBufferUtil.put(b, key);
    WriteBufferUtil.put(b, column);
    return b.getStaticBuffer();
}
Also used : WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer)

Aggregations

WriteByteBuffer (org.janusgraph.diskstorage.util.WriteByteBuffer)17 WriteBuffer (org.janusgraph.diskstorage.WriteBuffer)14 Test (org.junit.jupiter.api.Test)10 ReadBuffer (org.janusgraph.diskstorage.ReadBuffer)7 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)3 StaticArrayEntry (org.janusgraph.diskstorage.util.StaticArrayEntry)3 UUID (java.util.UUID)2 Entry (org.janusgraph.diskstorage.Entry)2 ReadArrayBuffer (org.janusgraph.diskstorage.util.ReadArrayBuffer)2 Preconditions (com.google.common.base.Preconditions)1 Random (java.util.Random)1 StopWatch (org.apache.commons.lang3.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 SystemRelationType (org.janusgraph.graphdb.types.system.SystemRelationType)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1