This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-event.git

commit 2b00fbf72e87200a04479385f692aa6b74668745
Author: Karl Pauls <pa...@apache.org>
AuthorDate: Wed Jun 21 11:19:32 2017 +0000

    SLING-6975: Use the Statistics from the getStatistics() method of queues 
for jmx if the queue isn't an instanceof Statistics itself.
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1799427 
13f79535-47bb-0310-9956-ffa450edef68
---
 .../apache/sling/event/impl/jobs/jmx/QueueMBeanImpl.java |  7 ++-----
 .../sling/event/impl/jobs/jmx/QueuesMBeanImplTest.java   | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/event/impl/jobs/jmx/QueueMBeanImpl.java 
b/src/main/java/org/apache/sling/event/impl/jobs/jmx/QueueMBeanImpl.java
index 615ac90..d623515 100644
--- a/src/main/java/org/apache/sling/event/impl/jobs/jmx/QueueMBeanImpl.java
+++ b/src/main/java/org/apache/sling/event/impl/jobs/jmx/QueueMBeanImpl.java
@@ -31,11 +31,8 @@ public class QueueMBeanImpl extends AbstractJobStatistics {
 
     public QueueMBeanImpl(Queue queue) {
         this.name = queue.getName();
-        if (queue instanceof Statistics) {
-            this.statistics = (Statistics) queue;
-        } else {
-            this.statistics = new EmptyStatistics();
-        }
+        Statistics stats = queue instanceof Statistics ? (Statistics) queue : 
queue.getStatistics();
+        this.statistics = stats != null ? stats : new EmptyStatistics();
     }
 
     @Override
diff --git 
a/src/test/java/org/apache/sling/event/impl/jobs/jmx/QueuesMBeanImplTest.java 
b/src/test/java/org/apache/sling/event/impl/jobs/jmx/QueuesMBeanImplTest.java
index f8b5740..89cc0f0 100644
--- 
a/src/test/java/org/apache/sling/event/impl/jobs/jmx/QueuesMBeanImplTest.java
+++ 
b/src/test/java/org/apache/sling/event/impl/jobs/jmx/QueuesMBeanImplTest.java
@@ -78,6 +78,22 @@ public class QueuesMBeanImplTest {
         testStatistics((StatisticsMBean) serviceObject.getValue());
         return queue;
     }
+    
+    @Test
+    public void testAddQueueWithStatistics() {
+        Queue queue = Mockito.mock(Queue.class);
+        Statistics stats = Mockito.mock(Statistics.class);
+        mockStatistics(stats);
+        Mockito.when(queue.getStatistics()).thenReturn(stats);
+        Mockito.when(queue.getName()).thenReturn("queue-name");
+        Mockito.when(bundleContext.registerService(Mockito.anyString(), 
Mockito.any(StatisticsMBean.class), 
Mockito.any(Dictionary.class))).thenReturn(serviceRegistration);
+        mbean.sendEvent(new QueueStatusEvent(queue,null));
+        Mockito.verify(bundleContext, 
Mockito.only()).registerService(serviceClass.capture(), 
serviceObject.capture(), serviceProperties.capture());
+        Assert.assertEquals("Expected bean to be registerd as a 
StatisticsMBean ", StatisticsMBean.class.getName(), serviceClass.getValue());
+        Assert.assertTrue("Expected service to be an instance of 
SatisticsMBean", serviceObject.getValue() instanceof StatisticsMBean);
+        Assert.assertNotNull("Expected properties to have a jmx.objectname", 
serviceProperties.getValue().get("jmx.objectname"));
+        testStatistics((StatisticsMBean) serviceObject.getValue());
+    }
 
 
     @Test

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Reply via email to