@Override public void registerSynchronization(Synchronization sync) throws RollbackException, SystemException { this.transactionManager.getTransaction().registerSynchronization(sync); }
@Override public Transaction createTransaction(@Nullable String name, int timeout) throws NotSupportedException, SystemException { if (timeout >= 0) { this.transactionManager.setTransactionTimeout(timeout); } this.transactionManager.begin(); return new ManagedTransactionAdapter(this.transactionManager); }
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations="classpath:/fooService.xml") public class FooServiceTests { private @Autowired TransactionManager transactionManager; private @Autowired FooService fooService; @Test public void testProvideService() { TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition()); fooService.provideService(); transactionManager.rollback(status); // assert repository values are unchanged ... }
private void doRollback(boolean isNew, Throwable originalException) { Throwable rollbackEx = null; try { if (isNew) { transactionManager.rollback(); } else { transactionManager.setRollbackOnly(); } } catch (SystemException e) { LOGGER.debug("Error when rolling back transaction", e); } catch (RuntimeException e) { rollbackEx = e; throw e; } catch (Error e) { rollbackEx = e; throw e; } finally { if (rollbackEx != null && originalException != null) { LOGGER.error("Error when rolling back transaction, original exception was:", originalException); } } }
public void testInvalidation() throws Exception { assertEquals(Collections.singletonList(address(0)), advancedCache(0).getDistributionManager().locate(k0)); assertEquals(Collections.singletonList(address(0)), advancedCache(1).getDistributionManager().locate(k0)); advancedCache(1).put(k0, "k1"); assertTrue(advancedCache(1).getDataContainer().containsKey(k0)); assertTrue(advancedCache(0).getDataContainer().containsKey(k0)); tm(0).begin(); cache(0).put(k0, "v2"); tm(0).commit(); assertFalse(advancedCache(1).getDataContainer().containsKey(k0)); }
public void testPutIfAbsent() throws Throwable { Object k1 = getKeyForCache(0); tm(0).begin(); assertNull(cache(0).putIfAbsent(k1, "v1")); Transaction suspendedTx = tm(0).suspend(); cache(0).put(k1, "v2"); assertEquals(cache(0).get(k1), "v2"); assertEquals(cache(1).get(k1), "v2"); suspendedTx.commit(); assertEquals("v1", cache(0).get(k1)); assertEquals("v1", cache(1).get(k1)); }
public void testFailure() throws Exception { TransactionManager transactionManager = cache.getAdvancedCache().getTransactionManager(); transactionManager.begin(); try { cache.put("k", "v"); assert false; } catch (Exception e) { log.debug("Ignoring expected exception during put", e); assertEquals(transactionManager.getTransaction().getStatus(), Status.STATUS_MARKED_ROLLBACK); } } }
public void testLockWithTmCommit() throws Throwable { tm().begin(); cache.getAdvancedCache().lock("k"); assertTrue(lockManager().isLocked("k")); tm().commit(); assertFalse(lockManager().isLocked("k")); } }
public void testLockWithTmRollback() throws Throwable { tm().begin(); cache.getAdvancedCache().lock("k"); assertTrue(lockManager().isLocked("k")); tm().rollback(); assertFalse(lockManager().isLocked("k")); }
@Override public void call() throws Exception { Cache<Object, Object> c = cm.getCache(); if (inTran) c.getAdvancedCache().getTransactionManager().begin(); c.put("key1", new SEntity(1, "name1", "surname1")); if (inTran) c.getAdvancedCache().getTransactionManager().commit(); assertEquals(searchByName("name1", c).size(), 1, "should be 1, even repeating this"); } });
public void testKeySetIsEmptyAfterLocalClear() throws Exception { cache.put(1, "v1"); tm().begin(); try { cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).clear(); assertTrue(cache.keySet().isEmpty()); } finally { tm().commit(); } }
public void testEntrySetIsEmptyAfterLocalClear() throws Exception { cache.put(1, "v1"); tm().begin(); try { cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).clear(); assertTrue(cache.entrySet().isEmpty()); } finally { tm().commit(); } }
public void testValuesIsEmptyAfterLocalClear() throws Exception { cache.put(1, "v1"); tm().begin(); try { cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).clear(); assertTrue(cache.values().isEmpty()); } finally { tm().commit(); } }
private void testLocalOperation(CheckRemoteLockAcquiredOnlyOnceTest.CacheOperation o) throws Exception { assert !advancedCache(1).getRpcManager().getTransport().isCoordinator(); assert advancedCache(0).getRpcManager().getTransport().isCoordinator(); tm(0).begin(); o.execute(); assert lockManager(0).isLocked(key); assert !lockManager(1).isLocked(key); assertEquals(controlInterceptor.remoteInvocations, 0); tm(0).rollback(); } }
public void testTxCommit1() throws Exception { TransactionManager tm = TestingUtil.getTransactionManager(cache); tm.begin(); cache.put("key", "value"); Transaction t = tm.suspend(); assertTrue(cache.isEmpty()); tm.resume(t); tm.commit(); assertFalse(cache.isEmpty()); }
@Test public void jtaTransactionManagerWithPropagationRequiresNewAndAdapter() throws Exception { TransactionManager tm = mock(TransactionManager.class); Transaction tx = mock(Transaction.class); given(tm.getStatus()).willReturn(Status.STATUS_ACTIVE); given(tm.suspend()).willReturn(tx); JtaTransactionManager ptm = newJtaTransactionManager(tm); TransactionTemplate tt = new TransactionTemplate(ptm); tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); assertFalse(TransactionSynchronizationManager.isSynchronizationActive()); tt.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { assertTrue(TransactionSynchronizationManager.isSynchronizationActive()); } }); assertFalse(TransactionSynchronizationManager.isSynchronizationActive()); verify(tm).begin(); verify(tm).commit(); verify(tm).resume(tx); }
public void testPreviousValueIgnored() throws Exception { cache.put("k", "init"); tm.begin(); cache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).put("k", "v1"); assertEquals("v1", cache.put("k", "v2")); Transaction tx = tm.suspend(); assertEquals("init", cache.put("k", "other")); tm.resume(tx); commit(); }
@Test public void test() throws Exception { javax.transaction.TransactionManager transactionManager = com.arjuna.ats.jta.TransactionManager.transactionManager(); transactionManager.begin(); Transaction currentTrans = transactionManager.getTransaction(); TestResource res1, res2; currentTrans.enlistResource( res1 = new TestResource() ); currentTrans.enlistResource( res2 = new TestResource() ); currentTrans.delistResource( res2, XAResource.TMSUCCESS ); currentTrans.delistResource( res1, XAResource.TMSUCCESS ); transactionManager.commit(); } }
@Test public void test() throws Exception { javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager(); tm.begin(); javax.transaction.Transaction theTransaction = tm.getTransaction(); tm.commit(); tm.resume(theTransaction); } }