@Test @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) public void shouldNotifyTransactionListenersInSameThreadOnlyOnCommitSuccess() throws Exception { final AtomicInteger count = new AtomicInteger(0); g.tx().addTransactionListener(s -> { if (s == Transaction.Status.COMMIT) count.incrementAndGet(); }); final Thread t = new Thread(() -> g.tx().commit()); t.start(); t.join(); assertEquals(0, count.get()); }
@Test @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) public void shouldNotifyTransactionListenersInSameThreadOnlyOnRollbackSuccess() throws Exception { final AtomicInteger count = new AtomicInteger(0); g.tx().addTransactionListener(s -> { if (s == Transaction.Status.ROLLBACK) count.incrementAndGet(); }); final Thread t = new Thread(() -> g.tx().rollback()); t.start(); t.join(); assertEquals(0, count.get()); }
@Test @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) public void shouldAllowAutoTransactionToWorkWithoutMutationByDefault() { // expecting no exceptions to be thrown here g.tx().commit(); assertThat(g.tx().isOpen(), is(false)); g.tx().rollback(); assertThat(g.tx().isOpen(), is(false)); g.tx().commit(); assertThat(g.tx().isOpen(), is(false)); }
@Test @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) public void shouldNotifyTransactionListenersOnCommitSuccess() { final AtomicInteger count = new AtomicInteger(0); g.tx().addTransactionListener(s -> { if (s == Transaction.Status.COMMIT) count.incrementAndGet(); }); g.tx().commit(); assertEquals(1, count.get()); }
@Test @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) public void shouldNotifyTransactionListenersOnRollbackSuccess() { final AtomicInteger count = new AtomicInteger(0); g.tx().addTransactionListener(s -> { if (s == Transaction.Status.ROLLBACK) count.incrementAndGet(); }); g.tx().rollback(); assertEquals(1, count.get()); }
@Override public void run() { graph.addVertex(); g.tx().commit(); } };
@Test @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldHaveExceptionConsistencyWhenTransactionAlreadyOpen() { if (!g.tx().isOpen()) g.tx().open(); try { g.tx().open(); fail("An exception should be thrown when a transaction is opened twice"); } catch (Exception ex) { validateException(Transaction.Exceptions.transactionAlreadyOpen(), ex); } }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) public void shouldAllowReferenceOfVertexIdOutsideOfOriginalThreadAuto() throws Exception { final Vertex v1 = graph.addVertex("name", "stephen"); final AtomicReference<Object> id = new AtomicReference<>(); final Thread t = new Thread(() -> id.set(v1.id())); t.start(); t.join(); assertEquals(v1.id(), id.get()); g.tx().rollback(); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) public void shouldAllowReferenceOfEdgeIdOutsideOfOriginalThreadAuto() throws Exception { final Vertex v1 = graph.addVertex(); final Edge e = v1.addEdge("self", v1, "weight", 0.5d); final AtomicReference<Object> id = new AtomicReference<>(); final Thread t = new Thread(() -> id.set(e.id())); t.start(); t.join(); assertEquals(e.id(), id.get()); g.tx().rollback(); }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldAllowJustRollbackOnlyWithAutoTransaction() { // not expecting any exceptions here g.tx().rollback(); }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldHaveExceptionConsistencyWhenUsingManualTransactionOnCommit() { g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); try { g.tx().commit(); fail("An exception should be thrown when read/write behavior is manual and no transaction is opened"); } catch (Exception ex) { validateException(Transaction.Exceptions.transactionMustBeOpenToReadWrite(), ex); } }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldAllowJustCommitOnlyWithAutoTransaction() { // not expecting any exceptions here g.tx().commit(); }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldHaveExceptionConsistencyWhenUsingManualTransactionOnRollback() { g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); try { g.tx().rollback(); fail("An exception should be thrown when read/write behavior is manual and no transaction is opened"); } catch (Exception ex) { validateException(Transaction.Exceptions.transactionMustBeOpenToReadWrite(), ex); } }
@Test @LoadGraphWith(MODERN) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldTraverseIfAutoTxEnabledAndOriginalTxIsClosed() { // this should be the default, but manually set in just in case the implementation has other ideas g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.AUTO); // close down the current transaction final Traversal t = g.V().has("name", "marko"); g.tx().rollback(); // the traversal should still work since there are auto transactions assertEquals(1, IteratorUtils.count(t)); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) public void shouldAllowReferenceOfVertexOutsideOfOriginalTransactionalContextAuto() { final Vertex v1 = graph.addVertex("name", "stephen"); g.tx().commit(); assertEquals("stephen", v1.value("name")); g.tx().rollback(); assertEquals("stephen", v1.value("name")); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) public void shouldAllowReferenceOfEdgeOutsideOfOriginalTransactionalContextAuto() { final Vertex v1 = graph.addVertex(); final Edge e = v1.addEdge("self", v1, "weight", 0.5d); g.tx().commit(); assertEquals(0.5d, e.value("weight"), 0.00001d); g.tx().rollback(); assertEquals(0.5d, e.value("weight"), 0.00001d); }
@Test @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldHaveExceptionConsistencyWhenOnCloseToNull() { try { g.tx().onClose(null); fail("An exception should be thrown when onClose behavior is set to null"); } catch (Exception ex) { validateException(Transaction.Exceptions.onCloseBehaviorCannotBeNull(), ex); } }
@Test @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldHaveExceptionConsistencyWhenOnReadWriteToNull() { try { g.tx().onReadWrite(null); fail("An exception should be thrown when onClose behavior is set to null"); } catch (Exception ex) { validateException(Transaction.Exceptions.onReadWriteBehaviorCannotBeNull(), ex); } }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_THREADED_TRANSACTIONS) public void shouldOpenTxWhenThreadedTransactionIsCreated() throws Exception { // threaded transactions should be immediately open on creation final Graph threadedG = g.tx().createThreadedTx(); assertThat(threadedG.tx().isOpen(), is(true)); threadedG.tx().rollback(); assertThat(threadedG.tx().isOpen(), is(false)); }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS) public void shouldHaveExceptionConsistencyWhenUsingManualTransaction() { g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL); try { graph.addVertex(); fail("An exception should be thrown when read/write behavior is manual and no transaction is opened"); } catch (Exception ex) { validateException(Transaction.Exceptions.transactionMustBeOpenToReadWrite(), ex); } }