KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > timer > A_TimerEntity


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * 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_TimerEntity.java,v 1.8 2004/09/27 11:55:28 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.timer;
27
28 import org.objectweb.jonas.jtests.beans.transacted.Simple;
29 import org.objectweb.jonas.jtests.beans.transacted.SimpleEHome;
30
31 /**
32  * Tests of the TimerService, specific to entity beans.
33  * @author Philippe Durieux (jonas team)
34  */

35 public abstract class A_TimerEntity extends A_Timer {
36
37     /**
38      * constructor
39      * @param name name of the test suite.
40      */

41     public A_TimerEntity(String JavaDoc name) {
42         super(name);
43     }
44
45     /**
46      * return SimpleHome, that can be either BMP, CMP1, or CMP2 bean.
47      */

48     protected abstract SimpleEHome getHome();
49
50     /**
51      * Test interval timer
52      */

53     public void testTimer2() throws Exception JavaDoc {
54         int duration = 4;
55         int intervalduration = 3;
56         Simple s = getSimple(10);
57         int expected = s.getTimerCount();
58         int id = s.setTimer(duration, intervalduration);
59         try {
60             assertEquals("timer expired too quickly", expected, s.getTimerCount());
61             sleep(1000 * duration + 1500);
62             expected++;
63             assertEquals("timer did not expire first", expected, s.getTimerCount());
64             for (int i = 0; i < 3; i++) {
65                 sleep(1000 * intervalduration);
66                 expected++;
67                 assertEquals("timer did not expired at " + i, expected, s.getTimerCount());
68             }
69         } finally {
70             s.remove(); // should remove the timer too.
71
}
72     }
73
74     /**
75      * test timer in ejbPostCreate
76      */

77     public void testTimerInEjbPostCreate() throws Exception JavaDoc {
78         Simple s = getHome().createWithTimer(10, 2000);
79         sleep(4000);
80         s.remove();
81     }
82
83     /**
84      * test immediate timer in ejbPostCreate (bug #300502)
85      */

86     public void testTimerInEjbPostCreate2() throws Exception JavaDoc {
87         Simple s = getHome().createWithTimer(10, 2);
88         sleep(1000);
89         s.remove();
90     }
91     
92     /**
93      * test cancel in ejbTimeout (bug #300306)
94      */

95     public void testCancelInTimeout() throws Exception JavaDoc {
96         int duration = 2;
97         int intervalduration = -1;
98         Simple s = getSimple(100);
99         int id = s.setTimer(duration, intervalduration);
100         // timer should be cancelled at first expiration.
101
// TODO: test this.
102
sleep(6000);
103         s.remove();
104     }
105 }
106
Popular Tags