use of org.janusgraph.graphdb.database.serialize.DataOutput in project janusgraph by JanusGraph.
the class SerializerTest method testLegacyNonJtsSerialization.
@Test
public void testLegacyNonJtsSerialization() throws Exception {
final SpatialContextFactory factory = new SpatialContextFactory();
factory.geo = true;
final SpatialContext context = new SpatialContext(factory);
BinaryCodec binaryCodec = new BinaryCodec(context, factory);
Shape[] shapes = new Shape[] { context.getShapeFactory().pointXY(2.5, 0.5), context.getShapeFactory().rect(2.5, 3.5, 0.5, 1.5), context.getShapeFactory().circle(2.5, 0.5, DistanceUtils.dist2Degrees(5, DistanceUtils.EARTH_MEAN_RADIUS_KM)) };
DataOutput out = serialize.getDataOutput(128);
for (final Shape shape : shapes) {
// manually serialize with non-JTS codec
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
outputStream.write(1);
try (DataOutputStream dataOutput = new DataOutputStream(outputStream)) {
binaryCodec.writeShape(dataOutput, shape);
dataOutput.flush();
}
outputStream.flush();
byte[] bytes = outputStream.toByteArray();
VariableLong.writePositive(out, bytes.length);
out.putBytes(bytes);
}
// deserialize with standard serializer
ReadBuffer b = out.getStaticBuffer().asReadBuffer();
assertEquals(Geoshape.geoshape(shapes[0]), serialize.readObjectNotNull(b, Geoshape.class));
assertEquals(Geoshape.geoshape(shapes[1]), serialize.readObjectNotNull(b, Geoshape.class));
assertEquals(Geoshape.geoshape(shapes[2]), serialize.readObjectNotNull(b, Geoshape.class));
}
use of org.janusgraph.graphdb.database.serialize.DataOutput in project janusgraph by JanusGraph.
the class SerializerTest method classSerialization.
@Test
public void classSerialization() {
DataOutput out = serialize.getDataOutput(128);
out.writeObjectNotNull(Boolean.class);
out.writeObjectNotNull(Byte.class);
out.writeObjectNotNull(Double.class);
ReadBuffer b = out.getStaticBuffer().asReadBuffer();
assertEquals(Boolean.class, serialize.readObjectNotNull(b, Class.class));
assertEquals(Byte.class, serialize.readObjectNotNull(b, Class.class));
assertEquals(Double.class, serialize.readObjectNotNull(b, Class.class));
}
use of org.janusgraph.graphdb.database.serialize.DataOutput 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());
}
use of org.janusgraph.graphdb.database.serialize.DataOutput in project janusgraph by JanusGraph.
the class ManagementSystem method commit.
@Override
public synchronized void commit() {
ensureOpen();
// Commit config changes
if (transactionalConfig.hasMutations()) {
DataOutput out = graph.getDataSerializer().getDataOutput(128);
out.writeObjectNotNull(MgmtLogType.CONFIG_MUTATION);
transactionalConfig.logMutations(out);
sysLog.add(out.getStaticBuffer());
}
transactionalConfig.commit();
// Commit underlying transaction
transaction.commit();
// Communicate schema changes
if (!updatedTypes.isEmpty() || evictGraphFromCache) {
managementLogger.sendCacheEviction(updatedTypes, evictGraphFromCache, updatedTypeTriggers, getOpenInstancesInternal());
for (JanusGraphSchemaVertex schemaVertex : updatedTypes) {
schemaCache.expireSchemaElement(schemaVertex.longId());
for (JanusGraphTransaction tx : graph.getOpenTransactions()) {
tx.expireSchemaElement(schemaVertex.longId());
}
}
}
if (graphShutdownRequired)
graph.close();
close();
}
use of org.janusgraph.graphdb.database.serialize.DataOutput in project janusgraph by JanusGraph.
the class TransactionLogHeader method serializeHeader.
private DataOutput serializeHeader(Serializer serializer, int capacity, LogTxStatus status, EnumMap<LogTxMeta, Object> meta) {
Preconditions.checkArgument(status != null && meta != null, "Invalid status or meta");
DataOutput out = serializer.getDataOutput(capacity);
out.putLong(times.getTime(txTimestamp));
VariableLong.writePositive(out, transactionId);
out.writeObjectNotNull(status);
Preconditions.checkArgument(meta.size() < Byte.MAX_VALUE, "Too much meta data: %s", meta.size());
out.putByte(VariableLong.unsignedByte(meta.size()));
for (Map.Entry<LogTxMeta, Object> metaEntry : meta.entrySet()) {
assert metaEntry.getValue() != null;
out.putByte(VariableLong.unsignedByte(metaEntry.getKey().ordinal()));
out.writeObjectNotNull(metaEntry.getValue());
}
return out;
}
Aggregations