1 22 package org.jboss.test.txtimer.test; 23 24 import java.util.Date ; 25 26 import javax.ejb.Timer ; 27 import javax.ejb.TimerService ; 28 29 33 public class CanceledTimerTestCase extends TimerTestBase 34 { 35 public CanceledTimerTestCase(String name) 36 { 37 super(name); 38 } 39 40 public void testSingleEventDuration() throws Exception 41 { 42 TimedMockObject to = new TimedMockObject(); 43 TimerService service = createTimerService(to); 44 45 Timer timer = service.createTimer(500, null); 46 assertEquals("Expected one txtimer", 1, service.getTimers().size()); 47 timer.cancel(); 48 sleep(1000); 49 assertEquals("TimedObject called", 0, to.getCallCount()); 50 assertEquals("Expected no txtimer", 0, service.getTimers().size()); 51 } 52 53 public void testSingleEventExpire() throws Exception 54 { 55 TimedMockObject to = new TimedMockObject(); 56 TimerService service = createTimerService(to); 57 58 Timer timer = service.createTimer(new Date (System.currentTimeMillis() + 500), null); 59 assertEquals("Expected one txtimer", 1, service.getTimers().size()); 60 timer.cancel(); 61 sleep(1000); 62 assertEquals("TimedObject called", 0, to.getCallCount()); 63 assertEquals("Expected no txtimer", 0, service.getTimers().size()); 64 } 65 66 public void testMultipleEventDuration() throws Exception 67 { 68 TimedMockObject to = new CancelTimedMockObject(); 69 TimerService service = createTimerService(to); 70 71 Timer timer = service.createTimer(500, 1000, null); 72 assertEquals("Expected one txtimer", 1, service.getTimers().size()); 73 sleep(2000); 74 assertEquals("TimedObject not called", 1, to.getCallCount()); 75 assertEquals("Expected no txtimer", 0, service.getTimers().size()); 76 } 77 78 public void testMultipleEventExpire() throws Exception 79 { 80 TimedMockObject to = new CancelTimedMockObject(); 81 TimerService service = createTimerService(to); 82 83 Timer timer = service.createTimer(new Date (System.currentTimeMillis() + 500), 500, null); 84 assertEquals("Expected one txtimer", 1, service.getTimers().size()); 85 sleep(2000); 86 assertEquals("TimedObject not called", 1, to.getCallCount()); 87 assertEquals("Expected no txtimer", 0, service.getTimers().size()); 88 } 89 } 90 | Popular Tags |