Atomikos Forum |
|
Hello!
I'm trying to use TCCServiceManager within a single JVM and the standalone tx-service for a prototype. I would like to be able to propagate txs bethween threads but ran into problems with a much simpler use-case. In the test below the second test always fails. The third fails every now and then. What am I missing? I'm using an eval version of AtomikosExtremeTransactions-3.8.0. Regards, Martin transaction.properties: com.atomikos.icatch.service=com.atomikos.icatch.standalone.UserTransactionServiceFactory == cut here import org.junit.Test; import static org.junit.Assert.*; import static org.mockito.Mockito.*; import com.atomikos.icatch.HeurCommitException; import com.atomikos.icatch.HeurRollbackException; import com.atomikos.icatch.config.UserTransactionService; import com.atomikos.icatch.config.UserTransactionServiceImp; import com.atomikos.icatch.tcc.UserTccServiceManager; import com.atomikos.tcc.TccException; import com.atomikos.tcc.TccService; import com.atomikos.tcc.TccServiceManager; import java.util.Properties; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import org.apache.log4j.BasicConfigurator; import org.junit.After; import org.junit.Before; import org.junit.Ignore; /** * * @author mac */ public class TccServiceTest { private static UserTransactionService userTransactionService; private static TccServiceManager tccServiceManager; @Before public void setUp() { BasicConfigurator.configure(); userTransactionService = new UserTransactionServiceImp(); userTransactionService.init(new Properties()); tccServiceManager = new UserTccServiceManager(); } @After public void tearDown() { userTransactionService.shutdown(true); } @Test public void shouldConfirmServices() throws HeurRollbackException, TccException, HeurCommitException { final String rootId = tccServiceManager.register(null, 10); final TccService service1 = tccServiceMock(); final String subId1 = tccServiceManager.register(service1, 10); tccServiceManager.completed(subId1); final TccService service2 = tccServiceMock(); final String subId2 = tccServiceManager.register(service2, 10); tccServiceManager.completed(subId2); tccServiceManager.completed(rootId); verify(service1).confirm(subId1); verify(service2).confirm(subId2); verify(service1, never()).cancel(anyString()); verify(service2, never()).cancel(anyString()); } @Test public void subtaskFailedShouldCancelServices() throws HeurCommitException, TccException, HeurRollbackException { final String rootId = tccServiceManager.register(null, 10); final TccService service1 = tccServiceMock(); final String subId1 = tccServiceManager.register(service1, 10); tccServiceManager.completed(subId1); final TccService service2 = tccServiceMock(); final String subId2 = tccServiceManager.register(service2, 10); tccServiceManager.failed(subId2); tccServiceManager.completed(rootId); verify(service1, never()).confirm(anyString()); verify(service2, never()).confirm(anyString()); verify(service1).cancel(subId1); verify(service2).cancel(subId2); } @Test public void rootFailedShouldCancelServices() throws HeurCommitException, TccException, HeurRollbackException { final String rootId = tccServiceManager.register(null, 10); final TccService service1 = tccServiceMock(); final String subId1 = tccServiceManager.register(service1, 10); tccServiceManager.completed(subId1); final TccService service2 = tccServiceMock(); final String subId2 = tccServiceManager.register(service2, 10); tccServiceManager.completed(subId2); tccServiceManager.failed(rootId); verify(service1, never()).confirm(anyString()); verify(service2, never()).confirm(anyString()); verify(service1).cancel(subId1); // subId1); verify(service2).cancel(subId2); //subId2); } private TccService tccServiceMock() { final TccService mock = mock(TccService.class); return mock; } } |