use of org.janusgraph.graphdb.serializer.attributes.TClass2 in project janusgraph by JanusGraph.
the class SerializerGraphConfiguration method testOnlyRegisteredSerialization.
@Test
public void testOnlyRegisteredSerialization() {
JanusGraphManagement management = graph.openManagement();
PropertyKey time = management.makePropertyKey("time").dataType(Integer.class).make();
management.makePropertyKey("any").cardinality(Cardinality.LIST).dataType(Object.class).make();
management.buildIndex("byTime", Vertex.class).addKey(time).buildCompositeIndex();
management.makeEdgeLabel("knows").make();
management.makeVertexLabel("person").make();
management.commit();
JanusGraphTransaction tx = graph.newTransaction();
JanusGraphVertex v = tx.addVertex("person");
v.property("time", 5);
v.property("any", 5.0);
v.property("any", new TClass1(5, 1.5f));
v.property("any", TEnum.THREE);
tx.commit();
tx = graph.newTransaction();
v = tx.query().has("time", 5).vertices().iterator().next();
assertEquals(5, (int) v.value("time"));
assertEquals(3, Iterators.size(v.properties("any")));
tx.rollback();
// Verify that non-registered objects aren't allowed
for (Object o : new Object[] { new TClass2("abc", 5) }) {
tx = graph.newTransaction();
v = tx.addVertex("person");
try {
// Should not be allowed
v.property("any", o);
tx.commit();
fail();
} catch (IllegalArgumentException ignored) {
} finally {
if (tx.isOpen())
tx.rollback();
}
}
}
use of org.janusgraph.graphdb.serializer.attributes.TClass2 in project janusgraph by JanusGraph.
the class SerializerTest method parallelDeserialization.
@Test
public void parallelDeserialization() throws InterruptedException {
serialize.registerClass(1, TClass2.class, new TClass2Serializer());
final long value = 8;
final String str = "123456";
final TClass2 c = new TClass2("abcdefg", 333);
DataOutput out = serialize.getDataOutput(128);
out.putLong(value);
out.writeClassAndObject(value);
out.writeObject(c, TClass2.class);
out.writeObjectNotNull(str);
final StaticBuffer b = out.getStaticBuffer();
int numThreads = 4;
Thread[] threads = new Thread[numThreads];
for (int i = 0; i < numThreads; i++) {
threads[i] = new Thread(() -> {
for (int j = 0; j < 100000; j++) {
ReadBuffer buffer = b.asReadBuffer();
assertEquals(8, buffer.getLong());
assertEquals(value, (long) serialize.readClassAndObject(buffer));
assertEquals(c, serialize.readObject(buffer, TClass2.class));
assertEquals(str, serialize.readObjectNotNull(buffer, String.class));
}
});
threads[i].start();
}
for (int i = 0; i < numThreads; i++) {
threads[i].join();
}
}
use of org.janusgraph.graphdb.serializer.attributes.TClass2 in project janusgraph by JanusGraph.
the class SerializerTestCommon method objectWriteRead.
protected void objectWriteRead() {
TClass1 t1 = new TClass1(3245234223423433123L, 0.333f);
TClass2 t2 = new TClass2("This is a test", 4234234);
TEnum t3 = TEnum.THREE;
TEnum t4 = TEnum.TWO;
DataOutput out = serialize.getDataOutput(128);
out.writeObjectNotNull(t1);
out.writeClassAndObject(t2);
out.writeObject(t3, TEnum.class);
out.writeClassAndObject(t4);
ReadBuffer b = out.getStaticBuffer().asReadBuffer();
assertEquals(t1, serialize.readObjectNotNull(b, TClass1.class));
assertEquals(t2, serialize.readClassAndObject(b));
assertEquals(t3, serialize.readObject(b, TEnum.class));
assertEquals(t4, serialize.readClassAndObject(b));
assertFalse(b.hasRemaining());
}
use of org.janusgraph.graphdb.serializer.attributes.TClass2 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());
}
Aggregations