From ff6cd8d18fa436118879c478b651ec5e4e94b2d8 Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Mon, 22 Jun 2015 09:40:34 -0400 Subject: [PATCH] Fixing test that was using reflection by exposing a few properties on the RemotingServiceImpl --- .../core/remoting/server/RemotingService.java | 6 +++ .../server/impl/RemotingServiceImpl.java | 51 ++++++++++++------- .../server/impl/RemotingServiceImplTest.java | 27 ++++------ 3 files changed, 48 insertions(+), 36 deletions(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/server/RemotingService.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/server/RemotingService.java index 3f88446b1b..72d61fe081 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/server/RemotingService.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/server/RemotingService.java @@ -16,8 +16,10 @@ */ package org.apache.activemq.artemis.core.remoting.server; +import java.util.List; import java.util.Set; +import org.apache.activemq.artemis.api.core.BaseInterceptor; import org.apache.activemq.artemis.api.core.Interceptor; import org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection; import org.apache.activemq.artemis.core.security.ActiveMQPrincipal; @@ -43,8 +45,12 @@ public interface RemotingService void addIncomingInterceptor(Interceptor interceptor); + List getIncomingInterceptors(); + void addOutgoingInterceptor(Interceptor interceptor); + List getOutgoinInterceptors(); + boolean removeIncomingInterceptor(Interceptor interceptor); boolean removeOutgoingInterceptor(Interceptor interceptor); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/server/impl/RemotingServiceImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/server/impl/RemotingServiceImpl.java index 07adbedb73..1b43e2104f 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/server/impl/RemotingServiceImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/server/impl/RemotingServiceImpl.java @@ -16,6 +16,26 @@ */ package org.apache.activemq.artemis.core.remoting.server.impl; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.ServiceLoader; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; + import org.apache.activemq.artemis.api.core.ActiveMQBuffer; import org.apache.activemq.artemis.api.core.ActiveMQException; import org.apache.activemq.artemis.api.core.ActiveMQInterruptedException; @@ -51,25 +71,6 @@ import org.apache.activemq.artemis.utils.ActiveMQThreadFactory; import org.apache.activemq.artemis.utils.ConfigurationHelper; import org.apache.activemq.artemis.utils.ReusableLatch; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.ServiceLoader; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.TimeUnit; - public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycleListener { // Constants ----------------------------------------------------- @@ -611,6 +612,12 @@ public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycle updateProtocols(); } + @Override + public List getIncomingInterceptors() + { + return Collections.unmodifiableList(incomingInterceptors); + } + @Override public boolean removeIncomingInterceptor(final Interceptor interceptor) { @@ -632,6 +639,12 @@ public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycle updateProtocols(); } + @Override + public List getOutgoinInterceptors() + { + return Collections.unmodifiableList(outgoingInterceptors); + } + @Override public boolean removeOutgoingInterceptor(final Interceptor interceptor) { diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/server/impl/RemotingServiceImplTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/server/impl/RemotingServiceImplTest.java index 09f8b66a0e..8486f922ad 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/server/impl/RemotingServiceImplTest.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/server/impl/RemotingServiceImplTest.java @@ -22,14 +22,13 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; -import org.apache.activemq.artemis.api.core.Interceptor; import org.apache.activemq.artemis.api.core.TransportConfiguration; -import org.apache.activemq.artemis.core.server.ServiceRegistry; -import org.apache.activemq.artemis.tests.unit.core.remoting.server.impl.fake.FakeInterceptor; import org.apache.activemq.artemis.core.config.Configuration; import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl; import org.apache.activemq.artemis.core.remoting.server.impl.RemotingServiceImpl; +import org.apache.activemq.artemis.core.server.ServiceRegistry; import org.apache.activemq.artemis.core.server.impl.ServiceRegistryImpl; +import org.apache.activemq.artemis.tests.unit.core.remoting.server.impl.fake.FakeInterceptor; import org.junit.Before; import org.junit.Test; @@ -53,27 +52,21 @@ public class RemotingServiceImplTest } /** - * Tests that the method addReflectivelyInstantiatedInterceptors creates new instances of interceptors and adds - * them to the provided list. + * Tests that the service registry gets propaged into remotingService. */ @Test - public void testAddReflectivelyInstantiatedInterceptorsAddsNewInstancesToList() throws Exception + public void testPropagatingInterceptors() throws Exception { - Method method = RemotingServiceImpl.class.getDeclaredMethod("addReflectivelyInstantiatedInterceptors", - List.class, - List.class); - method.setAccessible(true); - List interceptorClassNames = new ArrayList(); for (int i = 0; i < 5; i++) { - interceptorClassNames.add(FakeInterceptor.class.getCanonicalName()); + serviceRegistry.addIncomingInterceptor(new FakeInterceptor()); } - List interceptors = new ArrayList(); - method.invoke(remotingService, interceptorClassNames, interceptors); - assertTrue(interceptors.size() == 5); - assertTrue(interceptors.get(0) instanceof FakeInterceptor); - assertTrue(interceptors.get(0) != interceptors.get(1)); + remotingService = new RemotingServiceImpl(null, configuration, null, null, null, null, null, serviceRegistry); + + assertTrue(remotingService.getIncomingInterceptors().size() == 5); + assertTrue(remotingService.getIncomingInterceptors().get(0) instanceof FakeInterceptor); + assertTrue(remotingService.getIncomingInterceptors().get(0) != remotingService.getIncomingInterceptors().get(1)); } /**