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());
}
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));
}
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());
}
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();
}
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();
}
Aggregations