1 22 package org.jboss.test.txtimer.test; 23 24 import javax.ejb.Timer ; 25 import javax.ejb.TimerService ; 26 import javax.transaction.TransactionManager ; 27 28 import org.jboss.tm.TransactionManagerLocator; 29 30 35 public class TransactionalTimerTestCase extends TimerTestBase 36 { 37 protected static TransactionManager txManager = TransactionManagerLocator.getInstance().locate(); 38 39 public TransactionalTimerTestCase(String name) 40 { 41 super(name); 42 } 43 44 public void testRollbackBeforeExpire() throws Exception 45 { 46 txManager.begin(); 47 48 TimedMockObject to = new TimedMockObject(); 49 TimerService service = createTimerService(to); 50 51 service.createTimer(500, null); 52 assertEquals("Expected one txtimer", 1, service.getTimers().size()); 53 txManager.rollback(); 54 sleep(1000); 55 assertEquals("TimedObject called", 0, to.getCallCount()); 56 assertEquals("Expected no txtimer", 0, service.getTimers().size()); 57 } 58 59 public void testRollbackAfterCreate() throws Exception 60 { 61 txManager.begin(); 62 63 TimedMockObject to = new TimedMockObject(); 64 TimerService service = createTimerService(to); 65 service.createTimer(500, null); 66 txManager.rollback(); 67 assertEquals("Expected no txtimer", 0, service.getTimers().size()); 68 } 69 70 public void testRollbackCancel() throws Exception 71 { 72 TimedMockObject to = new TimedMockObject(); 73 TimerService service = createTimerService(to); 74 Timer timer = service.createTimer(500, null); 75 76 txManager.begin(); 77 timer.cancel(); 78 txManager.rollback(); 79 80 assertEquals("Expected one txtimer", 1, service.getTimers().size()); 81 sleep(1000); 82 assertEquals("TimedObject not called", 1, to.getCallCount()); 83 } 84 85 public void testExpireBeforeCommit() throws Exception 86 { 87 TimedMockObject to = new TimedMockObject(); 88 TimerService service = createTimerService(to); 89 90 txManager.begin(); 91 Timer timer = service.createTimer(500, null); 92 sleep(1000); 93 assertEquals("TimedObject called", 0, to.getCallCount()); 94 txManager.commit(); 95 sleep(1000); 99 assertEquals("TimedObject called", 1, to.getCallCount()); 100 assertEquals("Expected no txtimer", 0, service.getTimers().size()); 101 } 102 } 103 | Popular Tags |