BasicChannelSemantics extends AbstractChannel { @Override public Transaction getTransaction() { if (!initialized) { synchronized (this) { if (!initialized) { initialize(); initialized = true; } } } BasicTransactionSemantics transaction = currentTransaction.get(); if (transaction == null || transaction.getState().equals( BasicTransactionSemantics.State.CLOSED)) { transaction = createTransaction(); currentTransaction.set(transaction); } return transaction; }  @Override void put(Event event); @Override Event take(); @Override Transaction getTransaction();  }
@Test public void testGetTransaction() throws Exception { final Transaction transaction = channel.getTransaction(); executor.submit(new Runnable() { @Override public void run() { Assert.assertNotSame(transaction, channel.getTransaction()); } }).get(); Assert.assertSame(transaction, channel.getTransaction()); transaction.begin(); executor.submit(new Runnable() { @Override public void run() { Assert.assertNotSame(transaction, channel.getTransaction()); } }).get(); Assert.assertSame(transaction, channel.getTransaction()); transaction.commit(); executor.submit(new Runnable() { @Override public void run() { Assert.assertNotSame(transaction, channel.getTransaction()); } }).get(); Assert.assertSame(transaction, channel.getTransaction()); transaction.close(); executor.submit(new Runnable() { @Override public void run() { Assert.assertNotSame(transaction, channel.getTransaction()); } }).get(); Assert.assertNotSame(transaction, channel.getTransaction()); }
@Test public void testBegin() throws Exception { final Transaction transaction = channel.getTransaction(); testExceptions(new Runnable() { @Override public void run() { transaction.begin(); } }); transaction.begin(); testIllegalState(new Runnable() { @Override public void run() { transaction.begin(); } }); transaction.commit(); testIllegalState(new Runnable() { @Override public void run() { transaction.begin(); } }); transaction.close(); testIllegalState(new Runnable() { @Override public void run() { transaction.begin(); } }); }
@Test public void testCommit1() throws Exception { final Transaction transaction = channel.getTransaction(); testIllegalState(new Runnable() { @Override public void run() { transaction.commit(); } }); transaction.begin(); testExceptions(new Runnable() { @Override public void run() { transaction.commit(); } }); transaction.commit(); testIllegalState(new Runnable() { @Override public void run() { transaction.commit(); } }); transaction.close(); testIllegalState(new Runnable() { @Override public void run() { transaction.commit(); } }); }
@Test public void testCommit2() throws Exception { final Transaction transaction = channel.getTransaction(); transaction.begin(); transaction.rollback(); testIllegalState(new Runnable() { @Override public void run() { transaction.commit(); } }); transaction.close(); testIllegalState(new Runnable() { @Override public void run() { transaction.commit(); } }); }
@Test public void testRollback1() throws Exception { final Transaction transaction = channel.getTransaction(); testIllegalState(new Runnable() { @Override public void run() { transaction.rollback(); } }); transaction.begin(); testWrongThread(new Runnable() { @Override public void run() { transaction.rollback(); } }); transaction.rollback(); testIllegalState(new Runnable() { @Override public void run() { transaction.rollback(); } }); transaction.close(); testIllegalState(new Runnable() { @Override public void run() { transaction.rollback(); } }); }
@Test public void testRollback2() throws Exception { final Transaction transaction = channel.getTransaction(); testIllegalState(new Runnable() { @Override public void run() { transaction.rollback(); } }); transaction.begin(); testError(new Runnable() { @Override public void run() { transaction.rollback(); } }); testIllegalState(new Runnable() { @Override public void run() { transaction.rollback(); } }); transaction.close(); testIllegalState(new Runnable() { @Override public void run() { transaction.rollback(); } }); }
@Test public void testRollback3() throws Exception { final Transaction transaction = channel.getTransaction(); testIllegalState(new Runnable() { @Override public void run() { transaction.rollback(); } }); transaction.begin(); testRuntimeException(new Runnable() { @Override public void run() { transaction.rollback(); } }); testIllegalState(new Runnable() { @Override public void run() { transaction.rollback(); } }); transaction.close(); testIllegalState(new Runnable() { @Override public void run() { transaction.rollback(); } }); }
@Test public void testRollback4() throws Exception { final Transaction transaction = channel.getTransaction(); testIllegalState(new Runnable() { @Override public void run() { transaction.rollback(); } }); transaction.begin(); testChannelException(new Runnable() { @Override public void run() { transaction.rollback(); } }); testIllegalState(new Runnable() { @Override public void run() { transaction.rollback(); } }); transaction.close(); testIllegalState(new Runnable() { @Override public void run() { transaction.rollback(); } }); }
@Test public void testRollback5() throws Exception { final Transaction transaction = channel.getTransaction(); testIllegalState(new Runnable() { @Override public void run() { transaction.rollback(); } }); transaction.begin(); testInterrupt(new Runnable() { @Override public void run() { transaction.rollback(); } }); testIllegalState(new Runnable() { @Override public void run() { transaction.rollback(); } }); transaction.close(); testIllegalState(new Runnable() { @Override public void run() { transaction.rollback(); } }); }
@Test public void testRollback6() throws Exception { final Transaction transaction = channel.getTransaction(); transaction.begin(); transaction.commit(); testIllegalState(new Runnable() { @Override public void run() { transaction.rollback(); } }); transaction.close(); testIllegalState(new Runnable() { @Override public void run() { transaction.rollback(); } }); }
@Test public void testRollback7() throws Exception { final Transaction transaction = channel.getTransaction(); transaction.begin(); testExceptions(new Runnable() { @Override public void run() { transaction.commit(); } }); transaction.rollback(); testIllegalState(new Runnable() { @Override public void run() { transaction.rollback(); } }); transaction.close(); testIllegalState(new Runnable() { @Override public void run() { transaction.rollback(); } }); }
@Test public void testClose1() throws Exception { final Transaction transaction = channel.getTransaction(); testError(new Runnable() { @Override public void run() { transaction.close(); } }); testIllegalState(new Runnable() { @Override public void run() { transaction.close(); } }); }
@Test public void testClose2() throws Exception { final Transaction transaction = channel.getTransaction(); testRuntimeException(new Runnable() { @Override public void run() { transaction.close(); } }); testIllegalState(new Runnable() { @Override public void run() { transaction.close(); } }); }
@Test public void testClose3() throws Exception { final Transaction transaction = channel.getTransaction(); testChannelException(new Runnable() { @Override public void run() { transaction.close(); } }); testIllegalState(new Runnable() { @Override public void run() { transaction.close(); } }); }
@Test public void testClose4() throws Exception { final Transaction transaction = channel.getTransaction(); transaction.begin(); testIllegalState(new Runnable() { @Override public void run() { transaction.close(); } }); }
@Test public void testClose5() throws Exception { final Transaction transaction = channel.getTransaction(); transaction.begin(); testChannelException(new Runnable() { @Override public void run() { transaction.commit(); } }); testIllegalState(new Runnable() { @Override public void run() { transaction.close(); } }); }