01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
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: /**
30: * @author Thomas.Diesler@jboss.org
31: * @since 07-Apr-2004
32: */
33: public class CanceledTimerTestCase extends TimerTestBase {
34: public CanceledTimerTestCase(String name) {
35: super (name);
36: }
37:
38: public void testSingleEventDuration() throws Exception {
39: TimedMockObject to = new TimedMockObject();
40: TimerService service = createTimerService(to);
41:
42: Timer timer = service.createTimer(500, null);
43: assertEquals("Expected one txtimer", 1, service.getTimers()
44: .size());
45: timer.cancel();
46: sleep(1000);
47: assertEquals("TimedObject called", 0, to.getCallCount());
48: assertEquals("Expected no txtimer", 0, service.getTimers()
49: .size());
50: }
51:
52: public void testSingleEventExpire() throws Exception {
53: TimedMockObject to = new TimedMockObject();
54: TimerService service = createTimerService(to);
55:
56: Timer timer = service.createTimer(new Date(System
57: .currentTimeMillis() + 500), null);
58: assertEquals("Expected one txtimer", 1, service.getTimers()
59: .size());
60: timer.cancel();
61: sleep(1000);
62: assertEquals("TimedObject called", 0, to.getCallCount());
63: assertEquals("Expected no txtimer", 0, service.getTimers()
64: .size());
65: }
66:
67: public void testMultipleEventDuration() throws Exception {
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()
73: .size());
74: sleep(2000);
75: assertEquals("TimedObject not called", 1, to.getCallCount());
76: assertEquals("Expected no txtimer", 0, service.getTimers()
77: .size());
78: }
79:
80: public void testMultipleEventExpire() throws Exception {
81: TimedMockObject to = new CancelTimedMockObject();
82: TimerService service = createTimerService(to);
83:
84: Timer timer = service.createTimer(new Date(System
85: .currentTimeMillis() + 500), 500, null);
86: assertEquals("Expected one txtimer", 1, service.getTimers()
87: .size());
88: sleep(2000);
89: assertEquals("TimedObject not called", 1, to.getCallCount());
90: assertEquals("Expected no txtimer", 0, service.getTimers()
91: .size());
92: }
93: }
|