public void obtainEntityInTerminatedTransaction( Consumer<T> f ) { GraphDatabaseService graphDatabaseService = dbRule.getGraphDatabaseAPI(); try ( Transaction tx = graphDatabaseService.beginTx() ) { T result = obtainEntityInTransaction( graphDatabaseService ); tx.terminate(); f.accept(result); } }
worker.start(); txSet.await(); outer[0].terminate(); terminated.countDown(); worker.join();
worker.start(); txSet.await(); outer[0].terminate(); terminated.countDown(); worker.join();
@Test public void terminateTransactionThrowsExceptionOnNextOperation() { // Given final GraphDatabaseService db = globalDb; try ( Transaction tx = db.beginTx() ) { tx.terminate(); try { db.createNode(); fail( "Failed to throw TransactionTerminateException" ); } catch ( TransactionTerminatedException ignored ) { } } }
@Test public void terminateNestedTransactionThrowsExceptionOnNextNestedOperation() { // Given final GraphDatabaseService db = globalDb; try ( Transaction tx = db.beginTx() ) { try ( Transaction nested = db.beginTx() ) { tx.terminate(); try { db.createNode(); fail( "Failed to throw TransactionTerminateException" ); } catch ( TransactionTerminatedException ignored ) { } } } }
@Test public void terminateNestedTransactionThrowsExceptionOnNextOperation() { // Given final GraphDatabaseService db = globalDb; try ( Transaction tx = db.beginTx() ) { try ( Transaction nested = db.beginTx() ) { tx.terminate(); } try { db.createNode(); fail( "Failed to throw TransactionTerminateException" ); } catch ( TransactionTerminatedException ignored ) { } } }
/** * GitHub issue #5996 */ @Test public void terminationOfClosedTransactionDoesNotInfluenceNextTransaction() { GraphDatabaseService db = globalDb; try ( Transaction tx = db.beginTx() ) { db.createNode(); tx.success(); } Transaction transaction = db.beginTx(); try ( Transaction tx = transaction ) { db.createNode(); tx.success(); } transaction.terminate(); try ( Transaction tx = db.beginTx() ) { assertThat( db.getAllNodes(), is( iterableWithSize( 2 ) ) ); tx.success(); } }
@Test public void shouldCountTerminatedTransactions() throws Exception { GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase(); try { TransactionCounters counts = db.getDependencyResolver().resolveDependency( TransactionCounters.class ); TransactionCountersChecker checker = new TransactionCountersChecker( counts ); try ( Transaction tx = db.beginTx() ) { dbConsumer.accept( db ); tx.terminate(); } checker.verifyTerminated( isWriteTx, counts ); } finally { db.shutdown(); } } }
log.info("tx is null, either the other transaction finished gracefully or has not yet been start."); } else { tx.terminate(); offerToQueue(queue, POISON, timeout); log.warn("terminating transaction, putting POISON onto queue");
@Test public void testSleepWithTerminate() { String cypherSleep = "call apoc.util.sleep({duration})"; testCallEmpty(db, cypherSleep, MapUtil.map("duration", 0l)); // force building query plan long duration = 300; TestUtil.assertDuration(Matchers.lessThan(duration), () -> { final Transaction[] tx = new Transaction[1]; Future future = Executors.newSingleThreadScheduledExecutor().submit( () -> { tx[0] = db.beginTx(); try { Result result = db.execute(cypherSleep, MapUtil.map("duration", 10000)); tx[0].success(); return result; } finally { tx[0].close(); } }); sleepUntil( dummy -> tx[0]!=null ); tx[0].terminate(); try { future.get(); } catch (InterruptedException|ExecutionException e) { throw new RuntimeException(e); } return null; }); }
@Override public void run() { long startTime = System.currentTimeMillis(); do { try { Thread.sleep( millis ); } catch ( InterruptedException ignored ) { // terminated while sleeping } } while ( (System.currentTimeMillis() - startTime) < millis ); // START SNIPPET: terminateTx tx.terminate(); // END SNIPPET: terminateTx } } );