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