int partitionBits = 21;
IDManager eid = new IDManager(partitionBits);
int trails = 1000000;
assertEquals(eid.getMaxPartitionCount(), (1 << partitionBits) - 1);
KryoSerializer serializer = new KryoSerializer();
for (int t = 0; t < trails; t++) {
long count = RandomGenerator.randomLong(1, eid.getMaxTitanTypeCount());
long id;
int dirID;
RelationType type;
if (Math.random() < 0.5) {
id = eid.getEdgeLabelID(count);
assertTrue(eid.isEdgeLabelID(id));
type = RelationType.EDGE;
if (Math.random() < 0.5)
dirID = IDHandler.EDGE_IN_DIR;
else
dirID = IDHandler.EDGE_OUT_DIR;
} else {
type = RelationType.PROPERTY;
id = eid.getPropertyKeyID(count);
assertTrue(eid.isPropertyKeyID(id));
dirID = IDHandler.PROPERTY_DIR;
}
assertTrue(eid.isTypeID(id));
StaticBuffer b = IDHandler.getEdgeType(id, dirID);
// System.out.println(dirID);
// System.out.println(getBinary(id));
// System.out.println(getBuffer(b.asReadBuffer()));
ReadBuffer rb = b.asReadBuffer();
long[] vals = IDHandler.readEdgeType(rb);
assertEquals(id,vals[0]);
assertEquals(dirID, vals[1]);
assertFalse(rb.hasRemaining());
//Inline edge type
WriteBuffer wb = new WriteByteBuffer(9);
IDHandler.writeInlineEdgeType(wb, id);
long newId = IDHandler.readInlineEdgeType(wb.getStaticBuffer().asReadBuffer());
assertEquals(id,newId);
//Compare to Kryo
DataOutput out = serializer.getDataOutput(10, true);
IDHandler.writeEdgeType(out, id, dirID);
assertEquals(b, out.getStaticBuffer());
//Make sure the bounds are right
StaticBuffer[] bounds = IDHandler.getBounds(type);