Search in sources :

Example 11 with BackendMutation

use of com.baidu.hugegraph.backend.store.BackendMutation in project incubator-hugegraph by apache.

the class BackendMutationTest method testInsertAndEliminateEntry.

@Test
public void testInsertAndEliminateEntry() {
    BackendMutation mutation = new BackendMutation();
    BackendEntry entry1 = constructBackendEntry("1", "name", "marko");
    BackendEntry entry2 = constructBackendEntry("1", "name", "marko");
    mutation.add(entry1, Action.INSERT);
    Assert.assertThrows(HugeException.class, () -> {
        mutation.add(entry2, Action.ELIMINATE);
    });
}
Also used : BackendMutation(com.baidu.hugegraph.backend.store.BackendMutation) BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) TextBackendEntry(com.baidu.hugegraph.backend.serializer.TextBackendEntry) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 12 with BackendMutation

use of com.baidu.hugegraph.backend.store.BackendMutation in project incubator-hugegraph by apache.

the class BackendMutationTest method testInsertAndDeleteEntry.

@Test
public void testInsertAndDeleteEntry() {
    BackendMutation mutation = new BackendMutation();
    BackendEntry entry1 = constructBackendEntry("1");
    BackendEntry entry2 = constructBackendEntry("1");
    mutation.add(entry1, Action.INSERT);
    Assert.assertThrows(HugeException.class, () -> {
        mutation.add(entry2, Action.DELETE);
    });
}
Also used : BackendMutation(com.baidu.hugegraph.backend.store.BackendMutation) BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) TextBackendEntry(com.baidu.hugegraph.backend.serializer.TextBackendEntry) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 13 with BackendMutation

use of com.baidu.hugegraph.backend.store.BackendMutation 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 14 with BackendMutation

use of com.baidu.hugegraph.backend.store.BackendMutation in project incubator-hugegraph by apache.

the class GraphTransaction method commitPartOfEdgeDeletions.

private void commitPartOfEdgeDeletions(Map<Id, HugeEdge> removedEdges) {
    assert this.commitPartOfAdjacentEdges > 0;
    this.prepareDeletions(removedEdges);
    BackendMutation mutation = this.mutation();
    BackendMutation idxMutation = this.indexTransaction().mutation();
    try {
        this.commitMutation2Backend(mutation, idxMutation);
    } catch (Throwable e) {
        this.rollbackBackend();
    } finally {
        mutation.clear();
        idxMutation.clear();
    }
    removedEdges.clear();
}
Also used : BackendMutation(com.baidu.hugegraph.backend.store.BackendMutation)

Example 15 with BackendMutation

use of com.baidu.hugegraph.backend.store.BackendMutation in project incubator-hugegraph by apache.

the class AbstractTransaction method commit2Backend.

protected void commit2Backend() {
    BackendMutation mutation = this.prepareCommit();
    assert !mutation.isEmpty();
    this.commitMutation2Backend(mutation);
}
Also used : BackendMutation(com.baidu.hugegraph.backend.store.BackendMutation)

Aggregations

BackendMutation (com.baidu.hugegraph.backend.store.BackendMutation)31 Test (org.junit.Test)22 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)21 TextBackendEntry (com.baidu.hugegraph.backend.serializer.TextBackendEntry)20 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)20 BinaryBackendEntry (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry)3 BytesBuffer (com.baidu.hugegraph.backend.serializer.BytesBuffer)3 BackendAction (com.baidu.hugegraph.backend.store.BackendAction)2 BackendException (com.baidu.hugegraph.backend.BackendException)1 Id (com.baidu.hugegraph.backend.id.Id)1 BackendStore (com.baidu.hugegraph.backend.store.BackendStore)1 IncrCounter (com.baidu.hugegraph.backend.store.raft.RaftBackendStore.IncrCounter)1 StoreCommand (com.baidu.hugegraph.backend.store.raft.StoreCommand)1 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)1 HugeType (com.baidu.hugegraph.type.HugeType)1 Action (com.baidu.hugegraph.type.define.Action)1 ArrayList (java.util.ArrayList)1