Fixing test that was using reflection by exposing a few properties on the RemotingServiceImpl
This commit is contained in:
parent
aa5ff90807
commit
ff6cd8d18f
|
@ -16,8 +16,10 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.artemis.core.remoting.server;
|
package org.apache.activemq.artemis.core.remoting.server;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
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.api.core.Interceptor;
|
||||||
import org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection;
|
import org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection;
|
||||||
import org.apache.activemq.artemis.core.security.ActiveMQPrincipal;
|
import org.apache.activemq.artemis.core.security.ActiveMQPrincipal;
|
||||||
|
@ -43,8 +45,12 @@ public interface RemotingService
|
||||||
|
|
||||||
void addIncomingInterceptor(Interceptor interceptor);
|
void addIncomingInterceptor(Interceptor interceptor);
|
||||||
|
|
||||||
|
List<BaseInterceptor> getIncomingInterceptors();
|
||||||
|
|
||||||
void addOutgoingInterceptor(Interceptor interceptor);
|
void addOutgoingInterceptor(Interceptor interceptor);
|
||||||
|
|
||||||
|
List<BaseInterceptor> getOutgoinInterceptors();
|
||||||
|
|
||||||
boolean removeIncomingInterceptor(Interceptor interceptor);
|
boolean removeIncomingInterceptor(Interceptor interceptor);
|
||||||
|
|
||||||
boolean removeOutgoingInterceptor(Interceptor interceptor);
|
boolean removeOutgoingInterceptor(Interceptor interceptor);
|
||||||
|
|
|
@ -16,6 +16,26 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.artemis.core.remoting.server.impl;
|
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.ActiveMQBuffer;
|
||||||
import org.apache.activemq.artemis.api.core.ActiveMQException;
|
import org.apache.activemq.artemis.api.core.ActiveMQException;
|
||||||
import org.apache.activemq.artemis.api.core.ActiveMQInterruptedException;
|
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.ConfigurationHelper;
|
||||||
import org.apache.activemq.artemis.utils.ReusableLatch;
|
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
|
public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycleListener
|
||||||
{
|
{
|
||||||
// Constants -----------------------------------------------------
|
// Constants -----------------------------------------------------
|
||||||
|
@ -611,6 +612,12 @@ public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycle
|
||||||
updateProtocols();
|
updateProtocols();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BaseInterceptor> getIncomingInterceptors()
|
||||||
|
{
|
||||||
|
return Collections.unmodifiableList(incomingInterceptors);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeIncomingInterceptor(final Interceptor interceptor)
|
public boolean removeIncomingInterceptor(final Interceptor interceptor)
|
||||||
{
|
{
|
||||||
|
@ -632,6 +639,12 @@ public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycle
|
||||||
updateProtocols();
|
updateProtocols();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BaseInterceptor> getOutgoinInterceptors()
|
||||||
|
{
|
||||||
|
return Collections.unmodifiableList(outgoingInterceptors);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeOutgoingInterceptor(final Interceptor interceptor)
|
public boolean removeOutgoingInterceptor(final Interceptor interceptor)
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,14 +22,13 @@ import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
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.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.Configuration;
|
||||||
import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
|
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.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.core.server.impl.ServiceRegistryImpl;
|
||||||
|
import org.apache.activemq.artemis.tests.unit.core.remoting.server.impl.fake.FakeInterceptor;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -53,27 +52,21 @@ public class RemotingServiceImplTest
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that the method addReflectivelyInstantiatedInterceptors creates new instances of interceptors and adds
|
* Tests that the service registry gets propaged into remotingService.
|
||||||
* them to the provided list.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@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++)
|
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);
|
remotingService = new RemotingServiceImpl(null, configuration, null, null, null, null, null, serviceRegistry);
|
||||||
assertTrue(interceptors.get(0) instanceof FakeInterceptor);
|
|
||||||
assertTrue(interceptors.get(0) != interceptors.get(1));
|
assertTrue(remotingService.getIncomingInterceptors().size() == 5);
|
||||||
|
assertTrue(remotingService.getIncomingInterceptors().get(0) instanceof FakeInterceptor);
|
||||||
|
assertTrue(remotingService.getIncomingInterceptors().get(0) != remotingService.getIncomingInterceptors().get(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue