Fixing test that was using reflection by exposing a few properties on the RemotingServiceImpl

This commit is contained in:
Clebert Suconic 2015-06-22 09:40:34 -04:00
parent aa5ff90807
commit ff6cd8d18f
3 changed files with 48 additions and 36 deletions

View File

@ -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<BaseInterceptor> getIncomingInterceptors();
void addOutgoingInterceptor(Interceptor interceptor);
List<BaseInterceptor> getOutgoinInterceptors();
boolean removeIncomingInterceptor(Interceptor interceptor);
boolean removeOutgoingInterceptor(Interceptor interceptor);

View File

@ -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<BaseInterceptor> 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<BaseInterceptor> getOutgoinInterceptors()
{
return Collections.unmodifiableList(outgoingInterceptors);
}
@Override
public boolean removeOutgoingInterceptor(final Interceptor interceptor)
{

View File

@ -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<String> interceptorClassNames = new ArrayList<String>();
for (int i = 0; i < 5; i++)
{
interceptorClassNames.add(FakeInterceptor.class.getCanonicalName());
serviceRegistry.addIncomingInterceptor(new FakeInterceptor());
}
List<Interceptor> interceptors = new ArrayList<Interceptor>();
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));
}
/**