Search in sources :

Example 1 with TClass1

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();
        }
    }
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) TClass2(org.janusgraph.graphdb.serializer.attributes.TClass2) TClass1(org.janusgraph.graphdb.serializer.attributes.TClass1) JanusGraphTransaction(org.janusgraph.core.JanusGraphTransaction) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Example 2 with TClass1

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);
}
Also used : TClass1(org.janusgraph.graphdb.serializer.attributes.TClass1) TEnum(org.janusgraph.graphdb.serializer.attributes.TEnum) TEnumSerializer(org.janusgraph.graphdb.serializer.attributes.TEnumSerializer) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) TClass1Serializer(org.janusgraph.graphdb.serializer.attributes.TClass1Serializer) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with TClass1

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());
}
Also used : TClass2(org.janusgraph.graphdb.serializer.attributes.TClass2) DataOutput(org.janusgraph.graphdb.database.serialize.DataOutput) ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) TClass1(org.janusgraph.graphdb.serializer.attributes.TClass1) TEnum(org.janusgraph.graphdb.serializer.attributes.TEnum)

Example 4 with TClass1

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());
}
Also used : DataOutput(org.janusgraph.graphdb.database.serialize.DataOutput) TClass2(org.janusgraph.graphdb.serializer.attributes.TClass2) ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) TClass1(org.janusgraph.graphdb.serializer.attributes.TClass1) IOException(java.io.IOException) TClass1Serializer(org.janusgraph.graphdb.serializer.attributes.TClass1Serializer) Test(org.junit.jupiter.api.Test)

Aggregations

TClass1 (org.janusgraph.graphdb.serializer.attributes.TClass1)4 TClass2 (org.janusgraph.graphdb.serializer.attributes.TClass2)3 ReadBuffer (org.janusgraph.diskstorage.ReadBuffer)2 DataOutput (org.janusgraph.graphdb.database.serialize.DataOutput)2 TClass1Serializer (org.janusgraph.graphdb.serializer.attributes.TClass1Serializer)2 TEnum (org.janusgraph.graphdb.serializer.attributes.TEnum)2 IOException (java.io.IOException)1 JanusGraphTransaction (org.janusgraph.core.JanusGraphTransaction)1 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)1 PropertyKey (org.janusgraph.core.PropertyKey)1 JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)1 ModifiableConfiguration (org.janusgraph.diskstorage.configuration.ModifiableConfiguration)1 TEnumSerializer (org.janusgraph.graphdb.serializer.attributes.TEnumSerializer)1 Test (org.junit.Test)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1