KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > bus > management > InstrumentationManagerTest


1 package org.objectweb.celtix.bus.management;
2
3 import java.util.List JavaDoc;
4 import junit.framework.TestCase;
5
6 import org.easymock.classextension.EasyMock;
7 import org.objectweb.celtix.Bus;
8 import org.objectweb.celtix.BusException;
9 import org.objectweb.celtix.bus.busimpl.ComponentCreatedEvent;
10 import org.objectweb.celtix.bus.busimpl.ComponentRemovedEvent;
11
12 import org.objectweb.celtix.bus.management.jmx.export.AnnotationTestInstrumentation;
13 import org.objectweb.celtix.bus.transports.http.HTTPClientTransport;
14 import org.objectweb.celtix.bus.transports.jms.JMSClientTransport;
15 import org.objectweb.celtix.bus.workqueue.WorkQueueInstrumentation;
16 import org.objectweb.celtix.bus.workqueue.WorkQueueManagerImpl;
17 import org.objectweb.celtix.management.Instrumentation;
18 import org.objectweb.celtix.management.InstrumentationManager;
19
20
21 public class InstrumentationManagerTest extends TestCase {
22     Bus bus;
23     InstrumentationManager im;
24     
25     public void setUp() throws Exception JavaDoc {
26         bus = Bus.init();
27         im = bus.getInstrumentationManager();
28     }
29     
30     public void tearDown() throws Exception JavaDoc {
31         //test case had done the bus.shutdown
32
}
33     
34     // try to get WorkQueue information
35
public void testWorkQueueInstrumentation() throws BusException {
36         //im.getAllInstrumentation();
37
WorkQueueManagerImpl wqm = new WorkQueueManagerImpl(bus);
38         bus.sendEvent(new ComponentCreatedEvent(wqm));
39         bus.sendEvent(new ComponentCreatedEvent(wqm));
40         //NOTE: now the bus WorkQueueManager is lazy load , if WorkQueueManager
41
//create with bus , this test could be failed.
42
List JavaDoc<Instrumentation> list = im.getAllInstrumentation();
43         //NOTE: change for the BindingManager and TransportFactoryManager instrumentation
44
// create with the bus.
45
assertEquals("Too many instrumented items", 4, list.size());
46         Instrumentation it1 = list.get(2);
47         Instrumentation it2 = list.get(3);
48         assertTrue("Item 1 not a WorkQueueInstrumentation",
49                    WorkQueueInstrumentation.class.isAssignableFrom(it1.getClass()));
50         assertTrue("Item 2 not a WorkQueueInstrumentation",
51                    WorkQueueInstrumentation.class.isAssignableFrom(it2.getClass()));
52         
53         // not check for the instrumentation unique name
54
// sleep for the MBServer connector thread startup
55
try {
56             Thread.sleep(100);
57         } catch (InterruptedException JavaDoc e) {
58             // do nothing
59
}
60         bus.sendEvent(new ComponentRemovedEvent(wqm));
61         assertEquals("Instrumented stuff not removed from list", 2, list.size());
62         bus.shutdown(true);
63         assertEquals("Instrumented stuff not removed from list", 0, list.size());
64     }
65     
66
67     public void testMoreInstrumentation() throws BusException {
68         //im.getAllInstrumentation();
69
WorkQueueManagerImpl wqm = new WorkQueueManagerImpl(bus);
70         bus.sendEvent(new ComponentCreatedEvent(wqm));
71         
72         JMSClientTransport jct =
73             EasyMock.createMock(JMSClientTransport.class);
74         bus.sendEvent(new ComponentCreatedEvent(jct));
75         
76         HTTPClientTransport hct =
77             EasyMock.createMock(HTTPClientTransport.class);
78         bus.sendEvent(new ComponentCreatedEvent(hct));
79         
80         // TODO should test for the im getInstrumentation
81
List JavaDoc<Instrumentation> list = im.getAllInstrumentation();
82         assertEquals("Too many instrumented items", 5, list.size());
83         // sleep for the MBServer connector thread startup
84
try {
85             Thread.sleep(100);
86         } catch (InterruptedException JavaDoc e) {
87             // do nothing
88
}
89         
90         bus.sendEvent(new ComponentRemovedEvent(wqm));
91         bus.sendEvent(new ComponentRemovedEvent(jct));
92         bus.sendEvent(new ComponentRemovedEvent(hct));
93         assertEquals("Instrumented stuff not removed from list", 2, list.size());
94         bus.shutdown(true);
95         assertEquals("Instrumented stuff not removed from list", 0, list.size());
96     }
97     
98     public void testCustemerInstrumentationByEvent() throws BusException {
99         AnnotationTestInstrumentation ati = new AnnotationTestInstrumentation();
100         bus.sendEvent(new ComponentCreatedEvent(ati));
101         
102         List JavaDoc<Instrumentation> list = im.getAllInstrumentation();
103         assertEquals("Not exactly the number of instrumented item", 3, list.size());
104         
105         // get the ati for more assert
106
Instrumentation instr = list.get(2);
107         assertEquals("Not exactly the name of AnnotationTestInstrumentation",
108                      "AnnotationTestInstrumentation",
109                      instr.getInstrumentationName());
110         bus.sendEvent(new ComponentRemovedEvent(ati));
111         assertEquals("AnnotationTestInstrumented stuff not removed from list", 2, list.size());
112         bus.shutdown(true);
113         assertEquals("Instrumented stuff not removed from list", 0, list.size());
114         
115     }
116     
117     public void testCustemerInstrumentationByInstrumentationManager() throws BusException {
118         AnnotationTestInstrumentation ati = new AnnotationTestInstrumentation();
119         im.register(ati);
120         
121         List JavaDoc<Instrumentation> list = im.getAllInstrumentation();
122         assertEquals("Not exactly the number of instrumented item", 3, list.size());
123         
124         // get the ati for more assert
125
Instrumentation instr = list.get(2);
126         assertEquals("Not exactly the name of AnnotationTestInstrumentation",
127                      "AnnotationTestInstrumentation",
128                      instr.getInstrumentationName());
129         im.unregister(ati);
130         assertEquals("AnnotationTestInstrumented stuff not removed from list", 2, list.size());
131         bus.shutdown(true);
132         assertEquals("Instrumented stuff not removed from list", 0, list.size());
133     }
134     
135       
136
137 }
138
Popular Tags