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);
}
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;
}
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);
}
}
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);
}
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;
}
Aggregations