use of org.janusgraph.diskstorage.util.WriteByteBuffer in project janusgraph by JanusGraph.
the class IDManagementTest method writingInlineEdgeTypes.
@Test
public void writingInlineEdgeTypes() {
int numTries = 100;
WriteBuffer out = new WriteByteBuffer(8 * numTries);
for (SystemRelationType t : SYSTEM_TYPES) {
IDHandler.writeInlineRelationType(out, t.longId());
}
for (long i = 1; i <= numTries; i++) {
IDHandler.writeInlineRelationType(out, IDManager.getSchemaId(IDManager.VertexIDType.UserEdgeLabel, i * 1000));
}
ReadBuffer in = out.getStaticBuffer().asReadBuffer();
for (SystemRelationType t : SYSTEM_TYPES) {
assertEquals(t, SystemTypeManager.getSystemType(IDHandler.readInlineRelationType(in)));
}
for (long i = 1; i <= numTries; i++) {
assertEquals(i * 1000, IDManager.stripEntireRelationTypePadding(IDHandler.readInlineRelationType(in)));
}
}
use of org.janusgraph.diskstorage.util.WriteByteBuffer in project janusgraph by JanusGraph.
the class StaticArrayEntryTest method testTTLMetadata.
@Test
public void testTTLMetadata() {
WriteBuffer wb = new WriteByteBuffer(128);
wb.putInt(1).putInt(2).putInt(3).putInt(4);
int valuePos = wb.getPosition();
wb.putInt(5).putInt(6);
StaticArrayEntry entry = new StaticArrayEntry(wb.getStaticBuffer(), valuePos);
entry.setMetaData(EntryMetaData.TTL, 42);
assertEquals(42, entry.getMetaData().get(EntryMetaData.TTL));
}
use of org.janusgraph.diskstorage.util.WriteByteBuffer in project janusgraph by JanusGraph.
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 org.janusgraph.diskstorage.util.WriteByteBuffer 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));
}
}
Aggregations