@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()); }
public TransactionalEventQueue(final Graph graph) { if (!graph.features().graph().supportsTransactions()) throw new IllegalStateException(String.format("%s requires the graph to support transactions", EventStrategy.class.getName())); // since this is a transactional graph events are enqueued so the events should be fired/reset only after // transaction is committed/rolled back as tied to a graph transaction graph.tx().addTransactionListener(status -> { if (status == Transaction.Status.COMMIT) fireEventQueue(); else if (status == Transaction.Status.ROLLBACK) resetEventQueue(); else throw new RuntimeException(String.format("The %s is not aware of this status: %s", EventQueue.class.getName(), status)); }); }
@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()); }
@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()); }
@Override public void addTransactionListener(final Consumer<Transaction.Status> listener) { this.getDelegate().addTransactionListener(listener); }
@Override public void addTransactionListener(final Consumer<Transaction.Status> listener) { this.getDelegate().addTransactionListener(listener); }
@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 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()); }
public TransactionalEventQueue(final Graph graph) { if (!graph.features().graph().supportsTransactions()) throw new IllegalStateException(String.format("%s requires the graph to support transactions", EventStrategy.class.getName())); // since this is a transactional graph events are enqueued so the events should be fired/reset only after // transaction is committed/rolled back as tied to a graph transaction graph.tx().addTransactionListener(status -> { if (status == Transaction.Status.COMMIT) fireEventQueue(); else if (status == Transaction.Status.ROLLBACK) resetEventQueue(); else throw new RuntimeException(String.format("The %s is not aware of this status: %s", EventQueue.class.getName(), status)); }); }
@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()); }