001: package org.objectweb.celtix.bus.management;
002:
003: import java.util.List;
004: import junit.framework.TestCase;
005:
006: import org.easymock.classextension.EasyMock;
007: import org.objectweb.celtix.Bus;
008: import org.objectweb.celtix.BusException;
009: import org.objectweb.celtix.bus.busimpl.ComponentCreatedEvent;
010: import org.objectweb.celtix.bus.busimpl.ComponentRemovedEvent;
011:
012: import org.objectweb.celtix.bus.management.jmx.export.AnnotationTestInstrumentation;
013: import org.objectweb.celtix.bus.transports.http.HTTPClientTransport;
014: import org.objectweb.celtix.bus.transports.jms.JMSClientTransport;
015: import org.objectweb.celtix.bus.workqueue.WorkQueueInstrumentation;
016: import org.objectweb.celtix.bus.workqueue.WorkQueueManagerImpl;
017: import org.objectweb.celtix.management.Instrumentation;
018: import org.objectweb.celtix.management.InstrumentationManager;
019:
020: public class InstrumentationManagerTest extends TestCase {
021: Bus bus;
022: InstrumentationManager im;
023:
024: public void setUp() throws Exception {
025: bus = Bus.init();
026: im = bus.getInstrumentationManager();
027: }
028:
029: public void tearDown() throws Exception {
030: //test case had done the bus.shutdown
031: }
032:
033: // try to get WorkQueue information
034: public void testWorkQueueInstrumentation() throws BusException {
035: //im.getAllInstrumentation();
036: WorkQueueManagerImpl wqm = new WorkQueueManagerImpl(bus);
037: bus.sendEvent(new ComponentCreatedEvent(wqm));
038: bus.sendEvent(new ComponentCreatedEvent(wqm));
039: //NOTE: now the bus WorkQueueManager is lazy load , if WorkQueueManager
040: //create with bus , this test could be failed.
041: List<Instrumentation> list = im.getAllInstrumentation();
042: //NOTE: change for the BindingManager and TransportFactoryManager instrumentation
043: // create with the bus.
044: assertEquals("Too many instrumented items", 4, list.size());
045: Instrumentation it1 = list.get(2);
046: Instrumentation it2 = list.get(3);
047: assertTrue("Item 1 not a WorkQueueInstrumentation",
048: WorkQueueInstrumentation.class.isAssignableFrom(it1
049: .getClass()));
050: assertTrue("Item 2 not a WorkQueueInstrumentation",
051: WorkQueueInstrumentation.class.isAssignableFrom(it2
052: .getClass()));
053:
054: // not check for the instrumentation unique name
055: // sleep for the MBServer connector thread startup
056: try {
057: Thread.sleep(100);
058: } catch (InterruptedException e) {
059: // do nothing
060: }
061: bus.sendEvent(new ComponentRemovedEvent(wqm));
062: assertEquals("Instrumented stuff not removed from list", 2,
063: list.size());
064: bus.shutdown(true);
065: assertEquals("Instrumented stuff not removed from list", 0,
066: list.size());
067: }
068:
069: public void testMoreInstrumentation() throws BusException {
070: //im.getAllInstrumentation();
071: WorkQueueManagerImpl wqm = new WorkQueueManagerImpl(bus);
072: bus.sendEvent(new ComponentCreatedEvent(wqm));
073:
074: JMSClientTransport jct = EasyMock
075: .createMock(JMSClientTransport.class);
076: bus.sendEvent(new ComponentCreatedEvent(jct));
077:
078: HTTPClientTransport hct = EasyMock
079: .createMock(HTTPClientTransport.class);
080: bus.sendEvent(new ComponentCreatedEvent(hct));
081:
082: // TODO should test for the im getInstrumentation
083: List<Instrumentation> list = im.getAllInstrumentation();
084: assertEquals("Too many instrumented items", 5, list.size());
085: // sleep for the MBServer connector thread startup
086: try {
087: Thread.sleep(100);
088: } catch (InterruptedException e) {
089: // do nothing
090: }
091:
092: bus.sendEvent(new ComponentRemovedEvent(wqm));
093: bus.sendEvent(new ComponentRemovedEvent(jct));
094: bus.sendEvent(new ComponentRemovedEvent(hct));
095: assertEquals("Instrumented stuff not removed from list", 2,
096: list.size());
097: bus.shutdown(true);
098: assertEquals("Instrumented stuff not removed from list", 0,
099: list.size());
100: }
101:
102: public void testCustemerInstrumentationByEvent()
103: throws BusException {
104: AnnotationTestInstrumentation ati = new AnnotationTestInstrumentation();
105: bus.sendEvent(new ComponentCreatedEvent(ati));
106:
107: List<Instrumentation> list = im.getAllInstrumentation();
108: assertEquals("Not exactly the number of instrumented item", 3,
109: list.size());
110:
111: // get the ati for more assert
112: Instrumentation instr = list.get(2);
113: assertEquals(
114: "Not exactly the name of AnnotationTestInstrumentation",
115: "AnnotationTestInstrumentation", instr
116: .getInstrumentationName());
117: bus.sendEvent(new ComponentRemovedEvent(ati));
118: assertEquals(
119: "AnnotationTestInstrumented stuff not removed from list",
120: 2, list.size());
121: bus.shutdown(true);
122: assertEquals("Instrumented stuff not removed from list", 0,
123: list.size());
124:
125: }
126:
127: public void testCustemerInstrumentationByInstrumentationManager()
128: throws BusException {
129: AnnotationTestInstrumentation ati = new AnnotationTestInstrumentation();
130: im.register(ati);
131:
132: List<Instrumentation> list = im.getAllInstrumentation();
133: assertEquals("Not exactly the number of instrumented item", 3,
134: list.size());
135:
136: // get the ati for more assert
137: Instrumentation instr = list.get(2);
138: assertEquals(
139: "Not exactly the name of AnnotationTestInstrumentation",
140: "AnnotationTestInstrumentation", instr
141: .getInstrumentationName());
142: im.unregister(ati);
143: assertEquals(
144: "AnnotationTestInstrumented stuff not removed from list",
145: 2, list.size());
146: bus.shutdown(true);
147: assertEquals("Instrumented stuff not removed from list", 0,
148: list.size());
149: }
150:
151: }
|