use of org.janusgraph.graphdb.serializer.attributes.TClass1 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.TClass1 in project janusgraph by JanusGraph.
the class SerializerGraphConfiguration method initialize.
@BeforeEach
public void initialize() {
ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
config.set(GraphDatabaseConfiguration.STORAGE_BACKEND, "inmemory");
config.set(GraphDatabaseConfiguration.CUSTOM_ATTRIBUTE_CLASS, TClass1.class.getName(), "attribute1");
config.set(GraphDatabaseConfiguration.CUSTOM_SERIALIZER_CLASS, TClass1Serializer.class.getName(), "attribute1");
config.set(GraphDatabaseConfiguration.CUSTOM_ATTRIBUTE_CLASS, TEnum.class.getName(), "attribute4");
config.set(GraphDatabaseConfiguration.CUSTOM_SERIALIZER_CLASS, TEnumSerializer.class.getName(), "attribute4");
graph = (StandardJanusGraph) JanusGraphFactory.open(config);
}
use of org.janusgraph.graphdb.serializer.attributes.TClass1 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.TClass1 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