123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- const delta_registry_1 = require("./delta_registry");
- const test_helpers_1 = require("./util/test_helpers");
- const assert_1 = require("./util/assert");
- describe("Primitive Delta", () => {
- it("Delete/delete node conflict", () => {
- const registry = new delta_registry_1.DeltaRegistry();
- const getId = (0, test_helpers_1.mockUuid)();
- const creation = registry.newNodeCreation(getId());
- (0, assert_1.assert)(creation.conflictsWith.length === 0, "did not expect node creation to be conflicting with any other operation");
- const deletion1 = registry.newNodeDeletion(creation, [], []);
- (0, assert_1.assert)(deletion1.conflictsWith.length === 0, "did not expect first deletion alone to be conflicting with anything");
- const deletion2 = registry.newNodeDeletion(creation, [], []);
- (0, assert_1.assert)(deletion1 === deletion2, "expected deltas to be identical");
- (0, assert_1.assert)(deletion1.conflictsWith.length === 0, "expected no conflicts");
- (0, assert_1.assert)(deletion1.hash.equals(deletion2.hash), "deletions should have equal hash");
- });
- it("Create/create edge conflict", () => {
- const registry = new delta_registry_1.DeltaRegistry();
- const getId = (0, test_helpers_1.mockUuid)();
- const sourceCreation = registry.newNodeCreation(getId());
- const target1Creation = registry.newNodeCreation(getId());
- const target2Creation = registry.newNodeCreation(getId());
- const edge1Creation = registry.newEdgeUpdate(sourceCreation.createOutgoingEdge("label"), target1Creation);
- (0, assert_1.assert)(edge1Creation.conflictsWith.length === 0, "expected a single edge alone to not be involved in conflicts");
- const edge2Creation = registry.newEdgeUpdate(sourceCreation.createOutgoingEdge("label"), target2Creation);
- (0, assert_1.assert)(edge1Creation.conflictsWith.length === 1, "expected conflict: same edge created twice, concurrently");
- (0, assert_1.assert)(edge2Creation.conflictsWith.length === 1, "expected conflict: same edge created twice, concurrently");
- });
- it("Update/update edge conflict", () => {
- const registry = new delta_registry_1.DeltaRegistry();
- const getId = (0, test_helpers_1.mockUuid)();
- const sourceCreation = registry.newNodeCreation(getId());
- const targetCreation = registry.newNodeCreation(getId());
- const newTarget1Creation = registry.newNodeCreation(getId());
- const newTarget2Creation = registry.newNodeCreation(getId());
- const edgeCreation = registry.newEdgeUpdate(sourceCreation.createOutgoingEdge("label"), targetCreation);
- const update1 = registry.newEdgeUpdate(edgeCreation.overwrite(), newTarget1Creation);
- (0, assert_1.assert)(update1.conflictsWith.length === 0, "expected no conflict with a single edge update.");
- const update2 = registry.newEdgeUpdate(edgeCreation.overwrite(), newTarget2Creation);
- (0, assert_1.assert)(update1.conflictsWith.length === 1, "expected conflict between concurrent edge updates.");
- (0, assert_1.assert)(update2.conflictsWith.length === 1, "expected conflict between concurrent edge updates.");
- });
- it("Delete/require (edge source) conflict", () => {
- const registry = new delta_registry_1.DeltaRegistry();
- const getId = (0, test_helpers_1.mockUuid)();
- const sourceCreation = registry.newNodeCreation(getId());
- const targetCreation = registry.newNodeCreation(getId());
- const sourceDeletion = registry.newNodeDeletion(sourceCreation, [], []);
- (0, assert_1.assert)(sourceDeletion.conflictsWith.length === 0, "expected no conflicts so far");
- const edgeCreation = registry.newEdgeUpdate(sourceCreation.createOutgoingEdge("label"), targetCreation);
- (0, assert_1.assert)(edgeCreation.conflictsWith.length === 1, "expected require/delete conflict, because edge source is concurrently deleted");
- (0, assert_1.assert)(sourceDeletion.conflictsWith.length === 1, "expected require/delete conflict, because edge source is concurrently deleted");
- });
- it("Delete/require (edge source) conflict (reverse order)", () => {
- const registry = new delta_registry_1.DeltaRegistry();
- const getId = (0, test_helpers_1.mockUuid)();
- // same as before, but now the 'order' of edgeCreation and sourceDeletion is reversed.
- const sourceCreation = registry.newNodeCreation(getId());
- const targetCreation = registry.newNodeCreation(getId());
- const edgeCreation = registry.newEdgeUpdate(sourceCreation.createOutgoingEdge("label"), targetCreation);
- (0, assert_1.assert)(edgeCreation.conflictsWith.length === 0, "expected no conflicts so far");
- const sourceDeletion = registry.newNodeDeletion(sourceCreation, [], []);
- (0, assert_1.assert)(edgeCreation.conflictsWith.length === 1, "expected require/delete conflict, because edge source is concurrently deleted");
- (0, assert_1.assert)(sourceDeletion.conflictsWith.length === 1, "expected require/delete conflict, because edge source is concurrently deleted");
- });
- it("Require (edge source), then delete (no conflict)", () => {
- const registry = new delta_registry_1.DeltaRegistry();
- const getId = (0, test_helpers_1.mockUuid)();
- // proper way of deleting the source of an edge: the deletion must depend on the edgeCreation
- const sourceCreation = registry.newNodeCreation(getId());
- const targetCreation = registry.newNodeCreation(getId());
- const edgeCreation = registry.newEdgeUpdate(sourceCreation.createOutgoingEdge("label"), targetCreation);
- const edgeDeletion = registry.newEdgeUpdate(edgeCreation.overwrite(), null);
- const sourceDeletion = registry.newNodeDeletion(sourceCreation, [edgeDeletion], []);
- (0, assert_1.assert)(sourceDeletion.conflictsWith.length === 0, "Since node deletion was aware of outgoing edge deletion, there should be no conflict");
- });
- it("Delete/require (edge source) conflict (3)", () => {
- const registry = new delta_registry_1.DeltaRegistry();
- const getId = (0, test_helpers_1.mockUuid)();
- // Same as (2), really, because the additional EdgeUpdate doesn't change anything.
- // Only the earliest conflict, between EdgeCreation and source NodeDeletion, matters.
- const sourceCreation = registry.newNodeCreation(getId());
- const targetCreation = registry.newNodeCreation(getId());
- const edgeCreation = registry.newEdgeUpdate(sourceCreation.createOutgoingEdge("label"), targetCreation);
- const newTargetCreation = registry.newNodeCreation(getId());
- const edgeUpdate = registry.newEdgeUpdate(edgeCreation.overwrite(), newTargetCreation);
- // no conflicts so far
- const sourceDeletion = registry.newNodeDeletion(sourceCreation, [], []);
- (0, assert_1.assert)(edgeCreation.conflictsWith.length === 1, "expected require/delete conflict, because edge source is concurrently deleted");
- (0, assert_1.assert)(sourceDeletion.conflictsWith.length === 1, "expected require/delete conflict, because edge source is concurrently deleted");
- (0, assert_1.assert)(edgeUpdate.conflictsWith.length === 0, "edge update should not be involved in any conflict");
- });
- it("Update edge after deletion of source node conflict", () => {
- const registry = new delta_registry_1.DeltaRegistry();
- const getId = (0, test_helpers_1.mockUuid)();
- // create edge between 2 nodes, and then properly delete the source node
- const sourceCreation = registry.newNodeCreation(getId());
- const targetCreation = registry.newNodeCreation(getId());
- const edgeCreation = registry.newEdgeUpdate(sourceCreation.createOutgoingEdge("label"), targetCreation);
- const edgeDeletion = registry.newEdgeUpdate(edgeCreation.overwrite(), null);
- const sourceDeletion = registry.newNodeDeletion(sourceCreation, [edgeDeletion], []);
- // no conflicts so far
- const newTargetCreation = registry.newNodeCreation(getId()); // no conflict
- const edgeUpdate = registry.newEdgeUpdate(edgeCreation.overwrite(), newTargetCreation);
- // console.log("edgeUpdate.conflictsWith", edgeUpdate.conflictsWith, "edgeDeletion.conflictsWith", edgeDeletion.conflictsWith);
- (0, assert_1.assert)(edgeUpdate.conflictsWith.length === 2, "expected U/U conflict");
- (0, assert_1.assert)(edgeUpdate.conflictsWith.some(([d]) => d === edgeDeletion), "expected U/U conflict");
- (0, assert_1.assert)(edgeUpdate.conflictsWith.some(([d]) => d === sourceDeletion), "expected U/U conflict");
- (0, assert_1.assert)(edgeDeletion.conflictsWith.length === 1, "expected U/U conflict");
- (0, assert_1.assert)(edgeDeletion.conflictsWith.some(([d]) => d === edgeUpdate), "expected U/U conflict");
- });
- it("Delete/require (edge target) conflict", () => {
- const registry = new delta_registry_1.DeltaRegistry();
- const getId = (0, test_helpers_1.mockUuid)();
- const sourceCreation = registry.newNodeCreation(getId());
- const targetCreation = registry.newNodeCreation(getId());
- const targetDeletion = registry.newNodeDeletion(targetCreation, [], []);
- const edgeCreation = registry.newEdgeUpdate(sourceCreation.createOutgoingEdge("label"), targetCreation);
- (0, assert_1.assert)(edgeCreation.conflictsWith.length === 1, "expected require/delete conflict");
- (0, assert_1.assert)(targetDeletion.conflictsWith.length === 1, "expected require/delete conflict");
- });
- it("Delete/require (edge target) conflict (reverse order)", () => {
- const registry = new delta_registry_1.DeltaRegistry();
- const getId = (0, test_helpers_1.mockUuid)();
- const sourceCreation = registry.newNodeCreation(getId());
- const targetCreation = registry.newNodeCreation(getId());
- const edgeCreation = registry.newEdgeUpdate(sourceCreation.createOutgoingEdge("label"), targetCreation);
- // delete target of edge, unaware that edge exists:
- const targetDeletion = registry.newNodeDeletion(targetCreation, [], []);
- (0, assert_1.assert)(edgeCreation.conflictsWith.length === 1, "expected require/delete conflict");
- (0, assert_1.assert)(targetDeletion.conflictsWith.length === 1, "expected require/delete conflict");
- });
- it("Require (edge target), then delete (no conflict)", () => {
- const registry = new delta_registry_1.DeltaRegistry();
- const getId = (0, test_helpers_1.mockUuid)();
- const sourceCreation = registry.newNodeCreation(getId());
- const targetCreation = registry.newNodeCreation(getId());
- const edgeCreation = registry.newEdgeUpdate(sourceCreation.createOutgoingEdge("label"), targetCreation);
- const edgeUpdate = registry.newEdgeUpdate(edgeCreation.overwrite(), sourceCreation); // turn edge into self-edge
- // because of the edgeUpdate, 'target' is no longer the target of the edge, and can be deleted:
- const targetDeletion = registry.newNodeDeletion(targetCreation, [], [edgeUpdate]);
- // console.log(edgeCreation.conflictsWith)
- (0, assert_1.assert)(edgeCreation.conflictsWith.length === 0, "expected no require/delete conflict");
- (0, assert_1.assert)(targetDeletion.conflictsWith.length === 0, "expected no require/delete conflict");
- });
- it("Delete source and target of edge (no conflict)", () => {
- const registry = new delta_registry_1.DeltaRegistry();
- const getId = (0, test_helpers_1.mockUuid)();
- const sourceCreation = registry.newNodeCreation(getId());
- const targetCreation = registry.newNodeCreation(getId());
- const edgeCreation = registry.newEdgeUpdate(sourceCreation.createOutgoingEdge("label"), targetCreation);
- const edgeDeletion = registry.newEdgeUpdate(edgeCreation.overwrite(), null);
- const sourceDeletion = registry.newNodeDeletion(sourceCreation, [edgeDeletion], []);
- (0, assert_1.assert)(sourceDeletion.conflictsWith.length === 0, "expected no conflicts");
- const targetDeletion = registry.newNodeDeletion(targetCreation, [], [edgeDeletion]);
- (0, assert_1.assert)(targetDeletion.conflictsWith.length === 0, "expected no conflicts");
- });
- it("Delete node with self-edge", () => {
- const registry = new delta_registry_1.DeltaRegistry();
- const getId = (0, test_helpers_1.mockUuid)();
- const nodeCreation = registry.newNodeCreation(getId());
- const edgeCreation = registry.newEdgeUpdate(nodeCreation.createOutgoingEdge("label"), nodeCreation);
- const edgeDeletion = registry.newEdgeUpdate(edgeCreation.overwrite(), null);
- const nodeDeletion = registry.newNodeDeletion(nodeCreation, [edgeDeletion], [edgeDeletion]);
- // console.log(nodeDeletion.conflictsWith);
- (0, assert_1.assert)(nodeDeletion.conflictsWith.length === 0, "expected no conflicts");
- });
- it("Read/write conflict", () => {
- const registry = new delta_registry_1.DeltaRegistry();
- const getId = (0, test_helpers_1.mockUuid)();
- const envCreation = registry.newNodeCreation(getId());
- const xInitial = registry.newEdgeUpdate(envCreation.createOutgoingEdge("x"), 1);
- const yInitial = registry.newEdgeUpdate(envCreation.createOutgoingEdge("y"), 2);
- // so now, x == 1, y == 2
- // then, x := x + 1
- const xUpdate = registry.newEdgeUpdate(xInitial.overwrite(), 2, [xInitial.overwrite()]);
- // and concurrently, y := x + y
- const yUpdate = registry.newEdgeUpdate(yInitial.overwrite(), 3, [xInitial.overwrite(), yInitial.overwrite()]);
- (0, assert_1.assert)(xUpdate.conflictsWith.length === 1 && yUpdate.conflictsWith.length === 1, "expected one conflict");
- (0, assert_1.assert)(xUpdate.conflictsWith.some(([d]) => d === yUpdate), "expected one conflict");
- });
- it("No Read/Read conflict", () => {
- const registry = new delta_registry_1.DeltaRegistry();
- const getId = (0, test_helpers_1.mockUuid)();
- const envCreation = registry.newNodeCreation(getId());
- const xInitial = registry.newEdgeUpdate(envCreation.createOutgoingEdge("x"), 1);
- // so now, x == 1
- // then, y := x + 1
- const yInitial = registry.newEdgeUpdate(envCreation.createOutgoingEdge("y"), 2, [xInitial.overwrite()]);
- // and concurrently, z := x + 2
- const zInitial = registry.newEdgeUpdate(envCreation.createOutgoingEdge("z"), 3, [xInitial.overwrite()]);
- (0, assert_1.assert)(yInitial.conflictsWith.length === 0 && zInitial.conflictsWith.length === 0, "expected no conflicts");
- });
- it("R*/U conflict", () => {
- const registry = new delta_registry_1.DeltaRegistry();
- const getId = (0, test_helpers_1.mockUuid)();
- const collection = registry.newNodeCreation(getId());
- const newEdge = collection.createOutgoingEdge("x");
- (0, assert_1.assert)(newEdge === collection.createOutgoingEdge("x"), "Should return same object");
- const addItemX = registry.newEdgeUpdate(newEdge, "x");
- (0, assert_1.assert)(newEdge === collection.createOutgoingEdge("x"), "Should return same object");
- (0, assert_1.assert)(addItemX.conflictsWith.length === 0, "No conflicts so far");
- // Now we'll create our conflict:
- const readAll = registry.newReadAllOutgoing(collection, [collection.createOutgoingEdge("x")]);
- const addItemY = registry.newEdgeUpdate(collection.createOutgoingEdge("y"), "y");
- console.log(collection);
- console.log(readAll.conflictsWith);
- console.log(addItemY.conflictsWith);
- (0, assert_1.assert)(readAll.conflictsWith.length === 1
- && addItemY.conflictsWith.length === 1, "Expected one conflict here");
- (0, assert_1.assert)(readAll.conflictsWith.some(([d]) => d === addItemY)
- && addItemY.conflictsWith.some(([d]) => d === readAll), "Expected 'addItemY' and 'readAll' to be conflicting");
- (0, assert_1.assert)(addItemX.conflictsWith.length === 0, "Still no conflicts here");
- });
- });
- //# sourceMappingURL=delta.test.js.map
|