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 34 public class SimpleTimerTestCase extends TimerTestBase 35 { 36 public SimpleTimerTestCase(String name) 37 { 38 super(name); 39 } 40 41 public void testSingleEventDuration() throws Exception 42 { 43 TimedMockObject to = new TimedMockObject(); 44 TimerService service = createTimerService(to); 45 46 service.createTimer(500, null); 47 assertEquals("Expected one txtimer", 1, service.getTimers().size()); 48 sleep(1000); 49 assertTrue("TimedObject not called", 1 == 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 service.createTimer(new Date (System.currentTimeMillis() + 500), null); 59 assertEquals("Expected one txtimer", 1, service.getTimers().size()); 60 sleep(1000); 61 assertTrue("TimedObject not called", 1 == to.getCallCount()); 62 assertEquals("Expected no txtimer", 0, service.getTimers().size()); 63 } 64 65 public void testMultipleEventDuration() throws Exception 66 { 67 TimedMockObject to = new TimedMockObject(); 68 TimerService service = createTimerService(to); 69 70 Timer timer = service.createTimer(500, 1000, null); 71 assertEquals("Expected one txtimer", 1, service.getTimers().size()); 72 sleep(2000); 73 assertTrue("TimedObject not called enough", 1 < to.getCallCount()); 74 75 timer.cancel(); 76 assertEquals("Expected no txtimer", 0, service.getTimers().size()); 77 } 78 79 public void testMultipleEventExpire() throws Exception 80 { 81 TimedMockObject to = new TimedMockObject(); 82 TimerService service = createTimerService(to); 83 84 Timer timer = service.createTimer(new Date (System.currentTimeMillis() + 500), 500, null); 85 assertEquals("Expected one txtimer", 1, service.getTimers().size()); 86 sleep(2000); 87 assertTrue("TimedObject not called enough", 1 < to.getCallCount()); 88 89 timer.cancel(); 90 assertEquals("Expected no txtimer", 0, service.getTimers().size()); 91 } 92 93 } 94 | Popular Tags |