1 package org.objectweb.celtix.bus.management; 2 3 import java.util.List ; 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 { 26 bus = Bus.init(); 27 im = bus.getInstrumentationManager(); 28 } 29 30 public void tearDown() throws Exception { 31 } 33 34 public void testWorkQueueInstrumentation() throws BusException { 36 WorkQueueManagerImpl wqm = new WorkQueueManagerImpl(bus); 38 bus.sendEvent(new ComponentCreatedEvent(wqm)); 39 bus.sendEvent(new ComponentCreatedEvent(wqm)); 40 List <Instrumentation> list = im.getAllInstrumentation(); 43 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 try { 56 Thread.sleep(100); 57 } catch (InterruptedException e) { 58 } 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 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 List <Instrumentation> list = im.getAllInstrumentation(); 82 assertEquals("Too many instrumented items", 5, list.size()); 83 try { 85 Thread.sleep(100); 86 } catch (InterruptedException e) { 87 } 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 <Instrumentation> list = im.getAllInstrumentation(); 103 assertEquals("Not exactly the number of instrumented item", 3, list.size()); 104 105 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 <Instrumentation> list = im.getAllInstrumentation(); 122 assertEquals("Not exactly the number of instrumented item", 3, list.size()); 123 124 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 |