01: /*
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 1999 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19: * USA
20: *
21: * --------------------------------------------------------------------------
22: * $Id: A_TimerSession.java 8387 2006-05-24 11:43:09Z durieuxp $
23: * --------------------------------------------------------------------------
24: */
25:
26: package org.objectweb.jonas.jtests.clients.timer;
27:
28: import org.objectweb.jonas.jtests.beans.transacted.Simple;
29:
30: /**
31: * This is test of the TimerService.
32: * @author Philippe Durieux (jonas team)
33: */
34: public abstract class A_TimerSession extends A_Timer {
35:
36: /**
37: * constructor
38: * @param name name of the test suite.
39: */
40: public A_TimerSession(String name) {
41: super (name);
42: }
43:
44: protected void setUp() {
45: super .setUp();
46: }
47:
48: /**
49: * - cancel timers from test
50: */
51: protected void tearDown() throws Exception {
52: super .tearDown();
53: }
54:
55: /**
56: * Test interval timer
57: */
58: public void testTimerS2() throws Exception {
59: int duration = 4;
60: int intervalduration = 3;
61: Simple s = getSimple(10);
62: int expected = s.getTimerCount();
63: int id = s.setTimer(duration, intervalduration);
64: try {
65: assertEquals("timer expired too quickly", expected, s
66: .getTimerCount());
67: sleep(1000 * duration + 1500);
68: expected++;
69: assertEquals("timer did not expire first", expected, s
70: .getTimerCount());
71: // Change session. Timer must survive.
72: s.remove();
73: s = getSimple(103);
74: for (int i = 0; i < 3; i++) {
75: sleep(1000 * intervalduration);
76: expected++;
77: assertEquals("timer did not expired at " + i, expected,
78: s.getTimerCount());
79: }
80: } finally {
81: // Remove this line to test persistent timers.
82: s.cancelTimer(id); // necessary in case of stateless or MDB
83: s.remove();
84: }
85: }
86:
87: }
|