use of org.janusgraph.diskstorage.ReadBuffer 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.ReadBuffer in project janusgraph by JanusGraph.
the class IDManagementTest method edgeTypeIDTest.
@Test
public void edgeTypeIDTest() {
int partitionBits = 16;
IDManager eid = new IDManager(partitionBits);
int trails = 1000000;
assertEquals(eid.getPartitionBound(), (1L << partitionBits));
Serializer serializer = new StandardSerializer();
for (int t = 0; t < trails; t++) {
long count = RandomGenerator.randomLong(1, IDManager.getSchemaCountBound());
long id;
IDHandler.DirectionID dirID;
RelationCategory type;
if (Math.random() < 0.5) {
id = IDManager.getSchemaId(IDManager.VertexIDType.UserEdgeLabel, count);
assertTrue(eid.isEdgeLabelId(id));
assertFalse(IDManager.isSystemRelationTypeId(id));
type = RelationCategory.EDGE;
if (Math.random() < 0.5)
dirID = IDHandler.DirectionID.EDGE_IN_DIR;
else
dirID = IDHandler.DirectionID.EDGE_OUT_DIR;
} else {
type = RelationCategory.PROPERTY;
id = IDManager.getSchemaId(IDManager.VertexIDType.UserPropertyKey, count);
assertTrue(eid.isPropertyKeyId(id));
assertFalse(IDManager.isSystemRelationTypeId(id));
dirID = IDHandler.DirectionID.PROPERTY_DIR;
}
assertTrue(eid.isRelationTypeId(id));
StaticBuffer b = IDHandler.getRelationType(id, dirID, false);
// System.out.println(dirID);
// System.out.println(getBinary(id));
// System.out.println(getBuffer(b.asReadBuffer()));
ReadBuffer rb = b.asReadBuffer();
IDHandler.RelationTypeParse parse = IDHandler.readRelationType(rb);
assertEquals(id, parse.typeId);
assertEquals(dirID, parse.dirID);
assertFalse(rb.hasRemaining());
// Inline edge type
WriteBuffer wb = new WriteByteBuffer(9);
IDHandler.writeInlineRelationType(wb, id);
long newId = IDHandler.readInlineRelationType(wb.getStaticBuffer().asReadBuffer());
assertEquals(id, newId);
// Compare to Kryo
DataOutput out = serializer.getDataOutput(10);
IDHandler.writeRelationType(out, id, dirID, false);
assertEquals(b, out.getStaticBuffer());
// Make sure the bounds are right
StaticBuffer[] bounds = IDHandler.getBounds(type, false);
assertTrue(bounds[0].compareTo(b) < 0);
assertTrue(bounds[1].compareTo(b) > 0);
bounds = IDHandler.getBounds(RelationCategory.RELATION, false);
assertTrue(bounds[0].compareTo(b) < 0);
assertTrue(bounds[1].compareTo(b) > 0);
}
}
use of org.janusgraph.diskstorage.ReadBuffer in project janusgraph by JanusGraph.
the class SerializerTest method testObjectVerification.
@Test
public void testObjectVerification() {
serialize.registerClass(2, TClass1.class, new TClass1Serializer());
TClass1 t1 = new TClass1(24223, 0.25f);
DataOutput out = serialize.getDataOutput(128);
out.writeClassAndObject(t1);
out.writeClassAndObject(null);
out.writeObject(t1, TClass1.class);
out.writeObject(null, TClass1.class);
// Test failure
for (Object o : new Object[] { new TClass2("abc", 2), Calendar.getInstance(), Lists.newArrayList() }) {
try {
out.writeObjectNotNull(o);
fail();
} catch (Exception ignored) {
}
}
ReadBuffer b = out.getStaticBuffer().asReadBuffer();
assertEquals(t1, serialize.readClassAndObject(b));
assertNull(serialize.readClassAndObject(b));
assertEquals(t1, serialize.readObject(b, TClass1.class));
assertNull(serialize.readObject(b, TClass1.class));
assertFalse(b.hasRemaining());
}
use of org.janusgraph.diskstorage.ReadBuffer in project janusgraph by JanusGraph.
the class ConsistentKeyLockerSerializer method fromLockColumn.
public TimestampRid fromLockColumn(StaticBuffer lockKey, TimestampProvider provider) {
ReadBuffer r = lockKey.asReadBuffer();
int len = r.length();
long tsNS = r.getLong();
len -= 8;
byte[] curRid = new byte[len];
for (int i = 0; r.hasRemaining(); i++) {
curRid[i] = r.getByte();
}
StaticBuffer rid = new StaticArrayBuffer(curRid);
Instant time = provider.getTime(tsNS);
return new TimestampRid(time, rid);
}
Aggregations