You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ay...@apache.org on 2012/07/19 16:29:15 UTC

svn commit: r1363350 - in /cxf/trunk/rt/management/src: main/java/org/apache/cxf/management/counters/CounterRepository.java test/java/org/apache/cxf/management/counters/CounterRepositoryTest.java

Author: ay
Date: Thu Jul 19 14:29:15 2012
New Revision: 1363350

URL: http://svn.apache.org/viewvc?rev=1363350&view=rev
Log:
[CXF-4435] CounterRepository bean not registering to the bus in BP

Modified:
    cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/CounterRepository.java
    cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/counters/CounterRepositoryTest.java

Modified: cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/CounterRepository.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/CounterRepository.java?rev=1363350&r1=1363349&r2=1363350&view=diff
==============================================================================
--- cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/CounterRepository.java (original)
+++ cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/counters/CounterRepository.java Thu Jul 19 14:29:15 2012
@@ -26,7 +26,6 @@ import java.util.concurrent.locks.Reentr
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import javax.annotation.PostConstruct;
 import javax.management.JMException;
 import javax.management.ObjectName;
 
@@ -56,6 +55,9 @@ public class CounterRepository {
     
     public void setBus(Bus b) {
         bus = b;
+        if (bus != null) {
+            registerInterceptorsToBus();
+        }
     }
 
     public Bus getBus() {
@@ -66,7 +68,6 @@ public class CounterRepository {
         return counters;
     }
     
-    @PostConstruct
     void registerInterceptorsToBus() {
         ResponseTimeMessageInInterceptor in = new ResponseTimeMessageInInterceptor();
         ResponseTimeMessageInvokerInterceptor invoker = new ResponseTimeMessageInvokerInterceptor();

Modified: cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/counters/CounterRepositoryTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/counters/CounterRepositoryTest.java?rev=1363350&r1=1363349&r2=1363350&view=diff
==============================================================================
--- cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/counters/CounterRepositoryTest.java (original)
+++ cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/counters/CounterRepositoryTest.java Thu Jul 19 14:29:15 2012
@@ -18,10 +18,15 @@
  */
 package org.apache.cxf.management.counters;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import javax.management.ObjectName;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.management.InstrumentationManager;
+import org.apache.cxf.message.Message;
 import org.easymock.EasyMock;
 import org.junit.Assert;
 import org.junit.Before;
@@ -29,26 +34,37 @@ import org.junit.Test;
 
 public class CounterRepositoryTest extends Assert {
     private Bus bus;
+    private CounterRepository cr;
+    private List<Interceptor<? extends Message>> inlist = new ArrayList<Interceptor<? extends Message>>();
+    private List<Interceptor<? extends Message>> outlist = new ArrayList<Interceptor<? extends Message>>();
     //private InstrumentationManager im;
     private ObjectName serviceCounter;
     private ObjectName operationCounter;
     
     @Before
     public void setUp() throws Exception {
+        inlist.clear();
+        outlist.clear();
         
         serviceCounter = new ObjectName("tandoori:type=counter,service=help");
         operationCounter = new ObjectName("tandoori:type=counter,service=help,operation=me");
-        bus = EasyMock.createMock(Bus.class);        
+        bus = EasyMock.createMock(Bus.class);
+        EasyMock.expect(bus.getInInterceptors()).andReturn(inlist).anyTimes();
+        EasyMock.expect(bus.getOutInterceptors()).andReturn(outlist).anyTimes();
         bus.getExtension(InstrumentationManager.class);
         EasyMock.expectLastCall().andReturn(null).anyTimes();
+
+        cr = new CounterRepository();
+        bus.setExtension(cr, CounterRepository.class);
+        EasyMock.expectLastCall().once();
+        
         EasyMock.replay(bus);
+        cr.setBus(bus);
     }
     
     @Test
     public void testIncreaseOneWayResponseCounter() throws Exception {        
         
-        CounterRepository cr = new CounterRepository();
-        cr.setBus(bus);
         //cr.createCounter(operationCounter, true);
         MessageHandlingTimeRecorder mhtr = EasyMock.createMock(MessageHandlingTimeRecorder.class);
         EasyMock.expect(mhtr.isOneWay()).andReturn(true).anyTimes();
@@ -64,15 +80,13 @@ public class CounterRepositoryTest exten
         assertEquals("The operation counter isn't increased", opCounter.getNumInvocations(), 1);
         assertEquals("The Service counter isn't increased", sCounter.getNumInvocations(), 1);
         
-        EasyMock.verify(bus);
-        EasyMock.verify(mhtr);        
+        verifyBus();
+        EasyMock.verify(mhtr);
     }
     
     @Test
     public void testIncreaseOneWayNoResponseCounter() throws Exception {        
         
-        CounterRepository cr = new CounterRepository();
-        cr.setBus(bus);
         //cr.createCounter(operationCounter, true);
         MessageHandlingTimeRecorder mhtr = EasyMock.createMock(MessageHandlingTimeRecorder.class);
         EasyMock.expect(mhtr.isOneWay()).andReturn(true).anyTimes();
@@ -87,14 +101,12 @@ public class CounterRepositoryTest exten
         assertEquals("The operation counter isn't increased", opCounter.getNumInvocations(), 1);
         assertEquals("The Service counter isn't increased", sCounter.getNumInvocations(), 1);
         
-        EasyMock.verify(bus);
+        verifyBus();
         EasyMock.verify(mhtr);        
     }
     
     @Test
     public void testIncreaseResponseCounter() throws Exception {
-        CounterRepository cr = new CounterRepository();
-        cr.setBus(bus);
         
         MessageHandlingTimeRecorder mhtr1 = EasyMock.createMock(MessageHandlingTimeRecorder.class);
         EasyMock.expect(mhtr1.isOneWay()).andReturn(false).anyTimes();
@@ -142,9 +154,18 @@ public class CounterRepositoryTest exten
         assertTrue(opCounter.getMinResponseTime().longValue() == Integer.MAX_VALUE);
         assertTrue(opCounter.getMaxResponseTime().intValue() == 0);
         
-        EasyMock.verify(bus);
+        verifyBus();
         EasyMock.verify(mhtr1);
         EasyMock.verify(mhtr2);
     }
    
+    
+    private void verifyBus() {
+        EasyMock.verify(bus);
+
+        // the numbers should match the implementation of CounterRepository
+        assertEquals(2, inlist.size());
+        assertEquals(1, outlist.size());
+    }
+
 }