use of org.janusgraph.diskstorage.WriteBuffer 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();
}
use of org.janusgraph.diskstorage.WriteBuffer 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.WriteBuffer in project janusgraph by JanusGraph.
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 org.janusgraph.diskstorage.WriteBuffer 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.WriteBuffer 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)));
}
}
Aggregations