List of usage examples for javax.transaction TransactionManager commit
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException;
From source file:org.apache.servicemix.jms.JmsSpringJcaTest.java
public void testInOut() throws Exception { TransactionManager tm = (TransactionManager) getBean("transactionManager"); tm.begin();// w w w . j av a 2 s .c om InOut me = client.createInOutExchange(); me.setService(new QName("http://test", "MyProviderService")); me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>")); client.send(me); tm.commit(); me = (InOut) client.receive(); assertEquals(ExchangeStatus.ERROR, me.getStatus()); assertNotNull(me.getError()); assertTrue(me.getError() instanceof UnsupportedOperationException); }
From source file:org.apache.servicemix.jms.JmsSpringJcaTest.java
public void testInOnlyWithAsyncConsumer() throws Exception { TransactionManager tm = (TransactionManager) getBean("transactionManager"); tm.begin();/*from w ww . j av a 2 s .com*/ Destination dest = client.createDestination("endpoint:http://test/MyProviderService/async"); InOnly me = dest.createInOnlyExchange(); me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>")); client.send(me); tm.commit(); me = (InOnly) client.receive(); assertEquals(ExchangeStatus.DONE, me.getStatus()); receiver.getMessageList().assertMessagesReceived(1); }
From source file:org.apache.servicemix.jms.JmsSpringJcaTest.java
public void testInOnlyWithSyncConsumer() throws Exception { TransactionManager tm = (TransactionManager) getBean("transactionManager"); tm.begin();//from w w w . j a va 2 s . c o m Destination dest = client.createDestination("endpoint:http://test/MyProviderService/synchronous"); InOnly me = dest.createInOnlyExchange(); me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>")); client.send(me); tm.commit(); me = (InOnly) client.receive(); assertEquals(ExchangeStatus.DONE, me.getStatus()); receiver.getMessageList().assertMessagesReceived(1); }
From source file:org.apache.servicemix.jms.JmsSpringJcaTest.java
public void testInOnlySyncWithAsyncConsumer() throws Exception { TransactionManager tm = (TransactionManager) getBean("transactionManager"); tm.begin();// ww w . ja va 2 s . com Destination dest = client.createDestination("endpoint:http://test/MyProviderService/async"); InOnly me = dest.createInOnlyExchange(); me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>")); client.sendSync(me); assertEquals(ExchangeStatus.DONE, me.getStatus()); tm.commit(); receiver.getMessageList().assertMessagesReceived(1); }
From source file:org.apache.servicemix.jms.JmsSpringJcaTest.java
public void testInOnlySyncWithSyncConsumer() throws Exception { TransactionManager tm = (TransactionManager) getBean("transactionManager"); tm.begin();// w w w. j a v a 2 s.com Destination dest = client.createDestination("endpoint:http://test/MyProviderService/synchronous"); InOnly me = dest.createInOnlyExchange(); me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>")); client.sendSync(me); assertEquals(ExchangeStatus.DONE, me.getStatus()); tm.commit(); receiver.getMessageList().assertMessagesReceived(1); }
From source file:edu.illinois.enforcemop.examples.jbosscache.PessimisticSyncReplTxTest.java
public void testSimpleTxPut() throws Exception { TransactionManager tm; final Fqn NODE1 = Fqn.fromString("/one/two/three"); tm = beginTransaction();/*from w w w . j av a 2 s . c o m*/ cache1.put(NODE1, "age", 38); tm.commit(); /* * tx=beginTransaction(); cache1.put(NODE1, "age", new Integer(38)); * cache1.put(NODE2, "name", "Ben of The Far East"); cache1.put(NODE3, * "key", "UnknowKey"); * * tx.commit(); */ /* * tx=beginTransaction(); cache1.put(NODE1, "age", new Integer(38)); * cache1.put(NODE1, "AOPInstance", new AOPInstance()); cache1.put(NODE2, * "AOPInstance", new AOPInstance()); cache1.put(NODE1, "AOPInstance", new * AOPInstance()); tx.commit(); */ }
From source file:edu.illinois.enforcemop.examples.jbosscache.PessimisticSyncReplTxTest.java
public void testLockRemoval() throws Exception { cache1.getConfiguration().setSyncCommitPhase(true); TestingUtil.extractLockManager(cache1).unlockAll(cache1.getRoot()); TransactionManager tm = beginTransaction(); cache1.put("/bela/ban", "name", "Bela Ban"); assertEquals(3, cache1.getNumberOfLocksHeld()); assertEquals(0, cache2.getNumberOfLocksHeld()); tm.commit(); assertEquals(0, cache1.getNumberOfLocksHeld()); assertEquals(0, cache2.getNumberOfLocksHeld()); }
From source file:edu.illinois.enforcemop.examples.jbosscache.PessimisticSyncReplTxTest.java
public void testSyncReplWithModficationsOnBothCachesSameData() throws Exception { TransactionManager tm; final Fqn NODE = Fqn.fromString("/one/two/three"); tm = beginTransaction();/* ww w . j av a 2 s. c om*/ cache1.put(NODE, "age", 38); cache2.put(NODE, "age", 39); try { tm.commit(); fail("commit should throw a RollbackException, we should not get here"); } catch (RollbackException rollback) { } assertEquals(0, cache1.getNumberOfLocksHeld()); assertEquals(0, cache2.getNumberOfLocksHeld()); assertEquals(0, cache1.getNumberOfNodes()); assertEquals(0, cache2.getNumberOfNodes()); }
From source file:edu.illinois.enforcemop.examples.jbosscache.PessimisticSyncReplTxTest.java
public void testASyncRepl() throws Exception { Integer age;/*from w ww .j ava2s .c o m*/ TransactionManager tm; tm = beginTransaction(); cache1.put("/a/b/c", "age", 38); Thread.sleep(1000); assertNull("age on cache2 must be null as the TX has not yet been committed", cache2.get("/a/b/c", "age")); tm.commit(); Thread.sleep(1000); // value on cache2 must be 38 age = (Integer) cache2.get("/a/b/c", "age"); assertNotNull("\"age\" obtained from cache2 is null ", age); assertTrue("\"age\" must be 38", age == 38); }
From source file:edu.illinois.enforcemop.examples.jbosscache.PessimisticSyncReplTxTest.java
/** * Should reproduce JBCACHE-32 problem/*from www. j av a 2s . co m*/ * (http://jira.jboss.com/jira/browse/JBCACHE-32) */ private void _testConcurrentCommits(int num_threads) { Object myMutex = new Object(); Configuration conf1 = new Configuration(); Configuration conf2 = new Configuration(); conf1.setClusterName("TempCluster"); conf2.setClusterName("TempCluster"); conf1.setCacheMode(Configuration.CacheMode.REPL_SYNC); conf2.setCacheMode(Configuration.CacheMode.REPL_SYNC); conf1.setSyncCommitPhase(true); conf2.setSyncCommitPhase(true); conf1.setSyncRollbackPhase(true); conf2.setSyncRollbackPhase(true); conf1.setIsolationLevel(IsolationLevel.REPEATABLE_READ); conf2.setIsolationLevel(IsolationLevel.REPEATABLE_READ); conf1.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup"); conf2.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup"); conf1.setLockAcquisitionTimeout(5000); conf2.setLockAcquisitionTimeout(5000); final CacheSPI<Object, Object> c1 = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>() .createCache(conf1, false, getClass()); final CacheSPI<Object, Object> c2 = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>() .createCache(conf2, false, getClass()); c1.start(); c2.start(); final List<Exception> exceptions = new ArrayList<Exception>(); class MyThread extends Thread { final Object mutex; public MyThread(String name, Object mutex) { super(name); this.mutex = mutex; } public void run() { TransactionManager tm = null; try { tm = beginTransaction(c1); c1.put("/thread/" + getName(), null); //OPWAIT synchronized (mutex) { //OPWAIT mutex.wait(); //OPWAIT } tm.commit(); } catch (Exception e) { exceptions.add(e); } finally { try { if (tm != null) tm.rollback(); } catch (Exception e) { // do nothing } } } } MyThread[] threads = new MyThread[num_threads]; for (int i = 0; i < threads.length; i++) { threads[i] = new MyThread("t" + (i + 1), myMutex); } for (int i = 0; i < threads.length; i++) { MyThread thread = threads[i]; thread.start(); } try { Thread.sleep(6000); } catch (Exception e1) { e1.printStackTrace(); } //OPWAIT synchronized (myMutex) { //OPWAIT myMutex.notifyAll(); //OPWAIT } for (MyThread thread : threads) { try { thread.join(); } catch (InterruptedException e) { e.printStackTrace(); } } assertEquals(0, c1.getNumberOfLocksHeld()); assertEquals(0, c2.getNumberOfLocksHeld()); c1.stop(); c2.stop(); // if(ex != null) // { // ex.printStackTrace(); // fail("Thread failed: " + ex); // } // we can only expect 1 thread to succeed. The others will fail. So, // threads.length -1 exceptions. // this is a timing issue - 2 threads still may succeed on a multi cpu // system // assertEquals(threads.length - 1, exceptions.size()); for (Exception exception : exceptions) assertEquals(TimeoutException.class, exception.getClass()); }