Search in sources :

Example 6 with BinaryBackendEntry

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());
    }
}
Also used : BackendMutation(com.baidu.hugegraph.backend.store.BackendMutation) BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) BinaryBackendEntry(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry) BackendAction(com.baidu.hugegraph.backend.store.BackendAction) BinaryBackendEntry(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry) BytesBuffer(com.baidu.hugegraph.backend.serializer.BytesBuffer) Test(org.junit.Test)

Example 7 with BinaryBackendEntry

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;
}
Also used : BackendMutation(com.baidu.hugegraph.backend.store.BackendMutation) Action(com.baidu.hugegraph.type.define.Action) BackendAction(com.baidu.hugegraph.backend.store.BackendAction) BinaryBackendEntry(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry) Id(com.baidu.hugegraph.backend.id.Id) HugeType(com.baidu.hugegraph.type.HugeType)

Example 8 with BinaryBackendEntry

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;
    });
}
Also used : BinaryEntryIterator(com.baidu.hugegraph.backend.serializer.BinaryEntryIterator) BinaryBackendEntry(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry) HugeType(com.baidu.hugegraph.type.HugeType)

Example 9 with BinaryBackendEntry

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());
}
Also used : BackendMutation(com.baidu.hugegraph.backend.store.BackendMutation) BinaryBackendEntry(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry) StoreCommand(com.baidu.hugegraph.backend.store.raft.StoreCommand) Test(org.junit.Test)

Example 10 with BinaryBackendEntry

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());
}
Also used : BackendColumn(com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn) BinaryBackendEntry(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Aggregations

BinaryBackendEntry (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry)10 Test (org.junit.Test)6 BackendColumn (com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn)4 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)4 BackendMutation (com.baidu.hugegraph.backend.store.BackendMutation)3 HugeType (com.baidu.hugegraph.type.HugeType)3 BinaryEntryIterator (com.baidu.hugegraph.backend.serializer.BinaryEntryIterator)2 BackendAction (com.baidu.hugegraph.backend.store.BackendAction)2 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)2 BackendException (com.baidu.hugegraph.backend.BackendException)1 Id (com.baidu.hugegraph.backend.id.Id)1 BytesBuffer (com.baidu.hugegraph.backend.serializer.BytesBuffer)1 StoreCommand (com.baidu.hugegraph.backend.store.raft.StoreCommand)1 Action (com.baidu.hugegraph.type.define.Action)1 IOException (java.io.IOException)1