Search in sources :

Example 1 with KryoSerializer

use of com.thinkaurelius.titan.graphdb.database.serialize.kryo.KryoSerializer in project titan by thinkaurelius.

the class SerializerTest method testObjectVerification.

@Test
public void testObjectVerification() {
    KryoSerializer s = new KryoSerializer();
    DataOutput out = s.getDataOutput(128, true);
    Long l = Long.valueOf(128);
    out.writeClassAndObject(l);
    Calendar c = Calendar.getInstance();
    out.writeClassAndObject(c);
    NoDefaultConstructor dc = new NoDefaultConstructor(5);
    try {
        out.writeClassAndObject(dc);
        fail();
    } catch (IllegalArgumentException e) {
    }
    TestTransientClass d = new TestTransientClass(101);
    try {
        out.writeClassAndObject(d);
        fail();
    } catch (IllegalArgumentException e) {
    }
    out.writeObject(null, TestClass.class);
}
Also used : DataOutput(com.thinkaurelius.titan.graphdb.database.serialize.DataOutput) Calendar(java.util.Calendar) KryoSerializer(com.thinkaurelius.titan.graphdb.database.serialize.kryo.KryoSerializer) Test(org.junit.Test) PerformanceTest(com.thinkaurelius.titan.testutil.PerformanceTest)

Example 2 with KryoSerializer

use of com.thinkaurelius.titan.graphdb.database.serialize.kryo.KryoSerializer in project titan by thinkaurelius.

the class GraphDatabaseConfiguration method getSerializer.

public Serializer getSerializer() {
    Configuration config = configuration.subset(ATTRIBUTE_NAMESPACE);
    Serializer serializer = new KryoSerializer(config);
    for (RegisteredAttributeClass<?> clazz : getRegisteredAttributeClasses(config)) {
        clazz.registerWith(serializer);
    }
    return serializer;
}
Also used : Configuration(org.apache.commons.configuration.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) KryoSerializer(com.thinkaurelius.titan.graphdb.database.serialize.kryo.KryoSerializer) Serializer(com.thinkaurelius.titan.graphdb.database.serialize.Serializer) KryoSerializer(com.thinkaurelius.titan.graphdb.database.serialize.kryo.KryoSerializer)

Example 3 with KryoSerializer

use of com.thinkaurelius.titan.graphdb.database.serialize.kryo.KryoSerializer in project titan by thinkaurelius.

the class IDManagementTest method edgeTypeIDTest.

@Test
public void edgeTypeIDTest() {
    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);
        assertTrue(bounds[0].compareTo(b) < 0);
        assertTrue(bounds[1].compareTo(b) > 0);
        bounds = IDHandler.getBounds(RelationType.RELATION);
        assertTrue(bounds[0].compareTo(b) < 0);
        assertTrue(bounds[1].compareTo(b) > 0);
    }
}
Also used : ReadBuffer(com.thinkaurelius.titan.diskstorage.ReadBuffer) DataOutput(com.thinkaurelius.titan.graphdb.database.serialize.DataOutput) WriteBuffer(com.thinkaurelius.titan.diskstorage.WriteBuffer) WriteByteBuffer(com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer) RelationType(com.thinkaurelius.titan.graphdb.internal.RelationType) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) KryoSerializer(com.thinkaurelius.titan.graphdb.database.serialize.kryo.KryoSerializer) Test(org.junit.Test)

Example 4 with KryoSerializer

use of com.thinkaurelius.titan.graphdb.database.serialize.kryo.KryoSerializer in project titan by thinkaurelius.

the class KeyValueStoreUtil method setUTF8Serializer.

public static void setUTF8Serializer() {
    Configuration conf = new PropertiesConfiguration();
    conf.setProperty(GraphDatabaseConfiguration.STRING_COMPACT_SERIALIZE, true);
    KeyValueStoreUtil.serial = new KryoSerializer(conf);
}
Also used : Configuration(org.apache.commons.configuration.Configuration) GraphDatabaseConfiguration(com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) KryoSerializer(com.thinkaurelius.titan.graphdb.database.serialize.kryo.KryoSerializer)

Example 5 with KryoSerializer

use of com.thinkaurelius.titan.graphdb.database.serialize.kryo.KryoSerializer in project titan by thinkaurelius.

the class SerializerTest method setUp.

@Before
public void setUp() throws Exception {
    Configuration conf = new PropertiesConfiguration();
    conf.setProperty(GraphDatabaseConfiguration.ATTRIBUTE_ALLOW_ALL_SERIALIZABLE_KEY, false);
    serialize = new KryoSerializer(conf);
    serialize.registerClass(TestEnum.class, RESERVED_ID_OFFSET + 1);
    serialize.registerClass(TestClass.class, RESERVED_ID_OFFSET + 2);
    serialize.registerClass(short[].class, RESERVED_ID_OFFSET + 3);
    printStats = true;
}
Also used : Configuration(org.apache.commons.configuration.Configuration) GraphDatabaseConfiguration(com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) KryoSerializer(com.thinkaurelius.titan.graphdb.database.serialize.kryo.KryoSerializer) Before(org.junit.Before)

Aggregations

KryoSerializer (com.thinkaurelius.titan.graphdb.database.serialize.kryo.KryoSerializer)6 Configuration (org.apache.commons.configuration.Configuration)4 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)4 GraphDatabaseConfiguration (com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration)3 DataOutput (com.thinkaurelius.titan.graphdb.database.serialize.DataOutput)2 Before (org.junit.Before)2 Test (org.junit.Test)2 ReadBuffer (com.thinkaurelius.titan.diskstorage.ReadBuffer)1 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)1 WriteBuffer (com.thinkaurelius.titan.diskstorage.WriteBuffer)1 WriteByteBuffer (com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer)1 Serializer (com.thinkaurelius.titan.graphdb.database.serialize.Serializer)1 RelationType (com.thinkaurelius.titan.graphdb.internal.RelationType)1 PerformanceTest (com.thinkaurelius.titan.testutil.PerformanceTest)1 Calendar (java.util.Calendar)1 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)1