@Test public void commitTxAndStartNewTx() { assertInTransaction(true); assertTrue(TestTransaction.isActive()); assertUsers("Dilbert"); deleteFromTables("user"); assertUsers(); // Commit TestTransaction.flagForCommit(); assertFalse(TestTransaction.isFlaggedForRollback()); TestTransaction.end(); assertInTransaction(false); assertFalse(TestTransaction.isActive()); assertUsers(); executeSqlScript("classpath:/org/springframework/test/context/jdbc/data-add-dogbert.sql", false); assertUsers("Dogbert"); TestTransaction.start(); assertInTransaction(true); assertTrue(TestTransaction.isActive()); }
@Test(expectedExceptions = IllegalStateException.class) @Transactional(propagation = Propagation.NOT_SUPPORTED) public void flagForRollbackWithNonExistentTransactionContext() { TestTransaction.flagForRollback(); }
/** * Start a new test-managed transaction. * <p>Only call this method if {@link #end} has been called or if no * transaction has been previously started. * @throws IllegalStateException if the transaction context could not be * retrieved or if a transaction is already active for the current test * @see #isActive() * @see #end() */ public static void start() { requireCurrentTransactionContext().startTransaction(); }
@Test public void rollbackTxButDoNotStartNewTx() { assertInTransaction(true); assertTrue(TestTransaction.isActive()); assertUsers("Dilbert"); deleteFromTables("user"); assertUsers(); // Rollback (automatically) assertTrue(TestTransaction.isFlaggedForRollback()); TestTransaction.end(); assertFalse(TestTransaction.isActive()); assertInTransaction(false); assertUsers("Dilbert"); }
/** * Manually trigger the cleanup registry */ @SuppressWarnings("deprecation") public void testNodeCleanupRegistry() throws Exception { TestTransaction.flagForCommit(); TestTransaction.end(); // REPO-2963: this test takes a long time in order to pass on a clean DB. NodeCleanupRegistry cleanupRegistry = (NodeCleanupRegistry) applicationContext.getBean("nodeCleanupRegistry"); cleanupRegistry.doClean(); }
TestTransaction.start(); final List<TransferManifestNode> nodes = new ArrayList<TransferManifestNode>(); final TransferManifestNormalNode node1 = createContentNode(); TestTransaction.flagForCommit(); TestTransaction.end(); TestTransaction.start(); receiver.saveSnapshot(transferId, new ByteArrayInputStream(snapshot.getBytes("UTF-8"))); TestTransaction.flagForCommit(); TestTransaction.end(); TestTransaction.start(); receiver.saveContent(transferId, node.getUuid(), new ByteArrayInputStream(dummyContentBytes)); TestTransaction.flagForCommit(); TestTransaction.end(); TestTransaction.start(); receiver.commitAsync(transferId); TestTransaction.flagForCommit(); TestTransaction.end(); TestTransaction.start(); progress = progressMonitor.getProgress(transferId); TestTransaction.flagForCommit(); TestTransaction.end(); log.debug("Progress indication: " + progress.getStatus() + ": " + progress.getCurrentPosition() + "/" + progress.getEndPosition());
TestTransaction.flagForCommit(); TestTransaction.end(); TestTransaction.start(); TestTransaction.flagForRollback(); TestTransaction.end(); TestTransaction.start(); try TestTransaction.flagForRollback(); TestTransaction.end();
private void restartAuditableTxn() throws Exception { TestTransaction.end(); // Wait long enough that AuditablePropertiesEntity.setAuditModified // will recognize subsequent changes as needing new audit entries try { Thread.sleep(1250L); } catch(InterruptedException e) { } TestTransaction.start(); } }
/** * Flag the current test-managed transaction for <em>rollback</em>. * <p>Invoking this method will <em>not</em> end the current transaction. * Rather, the value of this flag will be used to determine whether or not * the current test-managed transaction should be rolled back or committed * once it is {@linkplain #end ended}. * @throws IllegalStateException if no transaction is active for the current test * @see #isActive() * @see #isFlaggedForRollback() * @see #start() * @see #end() */ public static void flagForRollback() { setFlaggedForRollback(true); }
@Test(expectedExceptions = IllegalStateException.class) public void startTxWithExistingTransaction() { TestTransaction.start(); }
@Test(expectedExceptions = IllegalStateException.class) @Transactional(propagation = Propagation.NOT_SUPPORTED) public void endTxWithNonExistentTransactionContext() { TestTransaction.end(); }
@Test(expectedExceptions = IllegalStateException.class) @Transactional(propagation = Propagation.NOT_SUPPORTED) public void flagForCommitWithNonExistentTransactionContext() { TestTransaction.flagForCommit(); }
@Test(expectedExceptions = IllegalStateException.class) @Transactional(propagation = Propagation.NOT_SUPPORTED) public void isFlaggedForRollbackWithNonExistentTransactionContext() { TestTransaction.isFlaggedForRollback(); }
@Test @Transactional(propagation = Propagation.NOT_SUPPORTED) public void isActiveWithNonExistentTransactionContext() { assertFalse(TestTransaction.isActive()); }
/** * Ensure that transactionless calls are handled */ public void testCallWithoutTxn() { TestTransaction.flagForCommit(); TestTransaction.end(); nodeService.getAllRootNodes(rootNodeRef.getStoreRef()); }
@Before public void before() throws Exception TestTransaction.flagForCommit(); this.nodeService = (NodeService) this.applicationContext.getBean("nodeService"); this.contentService = (ContentService) this.applicationContext.getBean("contentService"); MessageService messageService = (MessageService)this.applicationContext.getBean("messageService"); TestTransaction.end(); TestTransaction.start(); TestTransaction.flagForCommit(); TestTransaction.end(); TestTransaction.start();
TestTransaction.flagForCommit(); TestTransaction.end(); TestTransaction.start(); try TestTransaction.flagForRollback(); TestTransaction.end(); TestTransaction.start(); try TestTransaction.flagForRollback(); TestTransaction.end();
@Test public void rollbackTxButDoNotStartNewTx() { assertInTransaction(true); assertTrue(TestTransaction.isActive()); assertUsers("Dilbert"); deleteFromTables("user"); assertUsers(); // Rollback (automatically) assertTrue(TestTransaction.isFlaggedForRollback()); TestTransaction.end(); assertFalse(TestTransaction.isActive()); assertInTransaction(false); assertUsers("Dilbert"); }
/** * Flag the current test-managed transaction for <em>commit</em>. * <p>Invoking this method will <em>not</em> end the current transaction. * Rather, the value of this flag will be used to determine whether or not * the current test-managed transaction should be rolled back or committed * once it is {@linkplain #end ended}. * @throws IllegalStateException if no transaction is active for the current test * @see #isActive() * @see #isFlaggedForRollback() * @see #start() * @see #end() */ public static void flagForCommit() { setFlaggedForRollback(false); }