use of com.baidu.hugegraph.backend.serializer.BinaryBackendEntry in project incubator-hugegraph by apache.
the class StoreSerializerTest method testSerializeBackendMutation.
@Test
public void testSerializeBackendMutation() {
BinaryBackendEntry entry = new BinaryBackendEntry(HugeType.VERTEX, new byte[] { 1, 2 });
entry.column(new byte[] { 1 }, new byte[] { 1 });
entry.column(new byte[] { 2 }, new byte[] { 2 });
entry.column(new byte[] { 127 }, new byte[] { 127 });
BackendMutation origin = new BackendMutation();
origin.add(entry, Action.INSERT);
byte[] bytes = StoreSerializer.writeMutation(origin);
BytesBuffer buffer = BytesBuffer.wrap(bytes);
BackendMutation actual = StoreSerializer.readMutation(buffer);
Assert.assertEquals(1, actual.size());
Iterator<BackendAction> iter = actual.mutation();
while (iter.hasNext()) {
BackendAction item = iter.next();
Assert.assertEquals(Action.INSERT, item.action());
BackendEntry e = item.entry();
Assert.assertEquals(entry.type(), e.type());
Assert.assertEquals(entry.id(), e.id());
Assert.assertEquals(entry.subId(), e.subId());
Assert.assertEquals(entry.ttl(), e.ttl());
Assert.assertEquals(entry.columnsSize(), e.columnsSize());
Assert.assertEquals(entry.columns(), e.columns());
}
}
use of com.baidu.hugegraph.backend.serializer.BinaryBackendEntry in project incubator-hugegraph by apache.
the class StoreSerializer method readMutation.
public static BackendMutation readMutation(BytesBuffer buffer) {
int size = buffer.readVInt();
BackendMutation mutation = new BackendMutation(size);
for (int i = 0; i < size; i++) {
// read action
Action action = Action.fromCode(buffer.read());
// read HugeType
HugeType type = SerialEnum.fromCode(HugeType.class, buffer.read());
// read id
byte[] idBytes = buffer.readBytes();
// read subId
Id subId = buffer.readId();
if (subId.equals(IdGenerator.ZERO)) {
subId = null;
}
// read ttl
long ttl = buffer.readVLong();
BinaryBackendEntry entry = new BinaryBackendEntry(type, idBytes);
entry.subId(subId);
entry.ttl(ttl);
// read columns
int columnsSize = buffer.readVInt();
for (int c = 0; c < columnsSize; c++) {
byte[] name = buffer.readBytes();
byte[] value = buffer.readBytes();
entry.column(BackendColumn.of(name, value));
}
mutation.put(entry, action);
}
return mutation;
}
use of com.baidu.hugegraph.backend.serializer.BinaryBackendEntry in project incubator-hugegraph by apache.
the class RocksDBTable method newEntryIterator.
protected static final BackendEntryIterator newEntryIterator(BackendColumnIterator cols, Query query) {
return new BinaryEntryIterator<>(cols, query, (entry, col) -> {
if (entry == null || !entry.belongToMe(col)) {
HugeType type = query.resultType();
// NOTE: only support BinaryBackendEntry currently
entry = new BinaryBackendEntry(type, col.name);
} else {
assert !Bytes.equals(entry.id().asBytes(), col.name);
}
entry.columns(col);
return entry;
});
}
use of com.baidu.hugegraph.backend.serializer.BinaryBackendEntry in project incubator-hugegraph by apache.
the class StoreSerializerTest method testSerializeStoreCommand.
@Test
public void testSerializeStoreCommand() {
BinaryBackendEntry entry = new BinaryBackendEntry(HugeType.VERTEX, new byte[] { 1, 2 });
entry.column(new byte[] { 1 }, new byte[] { 1 });
entry.column(new byte[] { 2 }, new byte[] { 2 });
entry.column(new byte[] { 127 }, new byte[] { 127 });
BackendMutation origin = new BackendMutation();
origin.add(entry, Action.INSERT);
byte[] mutationBytes = StoreSerializer.writeMutation(origin);
StoreCommand command = new StoreCommand(StoreType.GRAPH, StoreAction.MUTATE, mutationBytes);
Assert.assertEquals(StoreAction.MUTATE, command.action());
Assert.assertArrayEquals(mutationBytes, command.data());
byte[] commandBytes = command.data();
StoreCommand actual = StoreCommand.fromBytes(commandBytes);
Assert.assertEquals(StoreType.GRAPH, command.type());
Assert.assertEquals(command.action(), actual.action());
Assert.assertArrayEquals(command.data(), actual.data());
}
use of com.baidu.hugegraph.backend.serializer.BinaryBackendEntry in project incubator-hugegraph by apache.
the class BinaryBackendEntryTest method testClear.
@Test
public void testClear() {
BinaryBackendEntry entry = new BinaryBackendEntry(HugeType.VERTEX, new byte[] { 1, 2 });
BackendColumn col = BackendColumn.of(new byte[] { 1, 2 }, new byte[] { 3, 4 });
entry.column(col);
Assert.assertEquals(1, entry.columnsSize());
Assert.assertEquals(ImmutableList.of(col), entry.columns());
entry.clear();
Assert.assertEquals(0, entry.columnsSize());
Assert.assertEquals(ImmutableList.of(), entry.columns());
}
Aggregations