use of org.janusgraph.graphdb.serializer.attributes.TClass1Serializer in project janusgraph by JanusGraph.
the class SerializerTest method testSerializedOrder.
@Test
public void testSerializedOrder() {
serialize.registerClass(1, TClass1.class, new TClass1Serializer());
final Map<Class, Factory> sortTypes = new HashMap<>();
for (Map.Entry<Class, Factory> entry : TYPES.entrySet()) {
if (serialize.isOrderPreservingDatatype(entry.getKey()))
sortTypes.put(entry.getKey(), entry.getValue());
}
assertEquals(10, sortTypes.size());
for (int t = 0; t < 3000000; t++) {
DataOutput o1 = serialize.getDataOutput(64);
DataOutput o2 = serialize.getDataOutput(64);
Map.Entry<Class, Factory> type = Iterables.get(sortTypes.entrySet(), random.nextInt(sortTypes.size()));
Comparable c1 = (Comparable) type.getValue().newInstance();
Comparable c2 = (Comparable) type.getValue().newInstance();
o1.writeObjectByteOrder(c1, type.getKey());
o2.writeObjectByteOrder(c2, type.getKey());
StaticBuffer s1 = o1.getStaticBuffer();
StaticBuffer s2 = o2.getStaticBuffer();
assertEquals(Math.signum(c1.compareTo(c2)), Math.signum(s1.compareTo(s2)));
Object c1o = serialize.readObjectByteOrder(s1.asReadBuffer(), type.getKey());
Object c2o = serialize.readObjectByteOrder(s2.asReadBuffer(), type.getKey());
assertEquals(c1, c1o);
assertEquals(c2, c2o);
}
}
use of org.janusgraph.graphdb.serializer.attributes.TClass1Serializer in project janusgraph by JanusGraph.
the class SerializerTest method objectWriteReadTest.
@Test
public void objectWriteReadTest() {
serialize.registerClass(2, TClass1.class, new TClass1Serializer());
serialize.registerClass(80342, TClass2.class, new TClass2Serializer());
serialize.registerClass(999, TEnum.class, new TEnumSerializer());
objectWriteRead();
}
use of org.janusgraph.graphdb.serializer.attributes.TClass1Serializer in project janusgraph by JanusGraph.
the class SerializerSpeedTest method performanceTestObjectSerialization.
@RepeatedTest(10)
public void performanceTestObjectSerialization() {
serialize.registerClass(2, TClass1.class, new TClass1Serializer());
serialize.registerClass(80342, TClass2.class, new TClass2Serializer());
serialize.registerClass(999, TEnum.class, new TEnumSerializer());
int runs = 1000000;
for (int i = 0; i < runs; i++) {
objectWriteRead();
}
}
use of org.janusgraph.graphdb.serializer.attributes.TClass1Serializer in project janusgraph by JanusGraph.
the class SerializerTest method testSerializationMixture.
@Test
public void testSerializationMixture() {
serialize.registerClass(1, TClass1.class, new TClass1Serializer());
for (int t = 0; t < 1000; t++) {
DataOutput out = serialize.getDataOutput(128);
int num = random.nextInt(100) + 1;
final List<SerialEntry> entries = new ArrayList<>(num);
for (int i = 0; i < num; i++) {
Map.Entry<Class, Factory> type = Iterables.get(TYPES.entrySet(), random.nextInt(TYPES.size()));
Object element = type.getValue().newInstance();
boolean notNull = true;
if (random.nextDouble() < 0.5) {
notNull = false;
if (random.nextDouble() < 0.2)
element = null;
}
entries.add(new SerialEntry(element, type.getKey(), notNull));
if (notNull)
out.writeObjectNotNull(element);
else
out.writeObject(element, type.getKey());
}
StaticBuffer sb = out.getStaticBuffer();
ReadBuffer in = sb.asReadBuffer();
for (SerialEntry entry : entries) {
Object read;
if (entry.notNull)
read = serialize.readObjectNotNull(in, entry.clazz);
else
read = serialize.readObject(in, entry.clazz);
if (entry.object == null)
assertNull(read);
else if (entry.clazz.isArray()) {
assertEquals(Array.getLength(entry.object), Array.getLength(read));
for (int i = 0; i < Array.getLength(read); i++) {
assertEquals(Array.get(entry.object, i), Array.get(read, i));
}
} else
assertEquals(entry.object, read);
}
}
}
use of org.janusgraph.graphdb.serializer.attributes.TClass1Serializer 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