Search in sources :

Example 1 with FakeInterceptor

use of org.apache.activemq.artemis.tests.unit.core.remoting.server.impl.fake.FakeInterceptor in project activemq-artemis by apache.

the class RemotingServiceImplTest method testInterceptorsAreAddedOnCreationOfServiceRegistry.

/**
 * Tests ensures that both interceptors from the service registry and also interceptors defined in the configuration
 * are added to the RemotingServiceImpl on creation
 */
@Test
public void testInterceptorsAreAddedOnCreationOfServiceRegistry() throws Exception {
    Field incomingInterceptors = RemotingServiceImpl.class.getDeclaredField("incomingInterceptors");
    Field outgoingInterceptors = RemotingServiceImpl.class.getDeclaredField("outgoingInterceptors");
    incomingInterceptors.setAccessible(true);
    outgoingInterceptors.setAccessible(true);
    serviceRegistry.addIncomingInterceptor(new FakeInterceptor());
    serviceRegistry.addOutgoingInterceptor(new FakeInterceptor());
    List<String> interceptorClassNames = new ArrayList<>();
    interceptorClassNames.add(FakeInterceptor.class.getCanonicalName());
    configuration.setIncomingInterceptorClassNames(interceptorClassNames);
    configuration.setOutgoingInterceptorClassNames(interceptorClassNames);
    remotingService = new RemotingServiceImpl(null, configuration, null, null, null, null, null, serviceRegistry);
    assertTrue(((List) incomingInterceptors.get(remotingService)).size() == 2);
    assertTrue(((List) outgoingInterceptors.get(remotingService)).size() == 2);
    assertTrue(((List) incomingInterceptors.get(remotingService)).contains(serviceRegistry.getIncomingInterceptors(null).get(0)));
    assertTrue(((List) outgoingInterceptors.get(remotingService)).contains(serviceRegistry.getOutgoingInterceptors(null).get(0)));
}
Also used : RemotingServiceImpl(org.apache.activemq.artemis.core.remoting.server.impl.RemotingServiceImpl) Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) FakeInterceptor(org.apache.activemq.artemis.tests.unit.core.remoting.server.impl.fake.FakeInterceptor) Test(org.junit.Test)

Example 2 with FakeInterceptor

use of org.apache.activemq.artemis.tests.unit.core.remoting.server.impl.fake.FakeInterceptor in project activemq-artemis by apache.

the class RemotingServiceImplTest method testPropagatingInterceptors.

/**
 * Tests that the service registry gets propaged into remotingService.
 */
@Test
public void testPropagatingInterceptors() throws Exception {
    for (int i = 0; i < 5; i++) {
        serviceRegistry.addIncomingInterceptor(new FakeInterceptor());
    }
    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));
}
Also used : RemotingServiceImpl(org.apache.activemq.artemis.core.remoting.server.impl.RemotingServiceImpl) FakeInterceptor(org.apache.activemq.artemis.tests.unit.core.remoting.server.impl.fake.FakeInterceptor) Test(org.junit.Test)

Example 3 with FakeInterceptor

use of org.apache.activemq.artemis.tests.unit.core.remoting.server.impl.fake.FakeInterceptor in project activemq-artemis by apache.

the class RemotingServiceImplTest method testSetInterceptorsAddsBothInterceptorsFromConfigAndServiceRegistry.

/**
 * Tests ensures that setInterceptors methods adds both interceptors from the service registry and also interceptors
 * defined in the configuration.
 */
@Test
public void testSetInterceptorsAddsBothInterceptorsFromConfigAndServiceRegistry() throws Exception {
    Method method = RemotingServiceImpl.class.getDeclaredMethod("setInterceptors", Configuration.class);
    Field incomingInterceptors = RemotingServiceImpl.class.getDeclaredField("incomingInterceptors");
    Field outgoingInterceptors = RemotingServiceImpl.class.getDeclaredField("outgoingInterceptors");
    method.setAccessible(true);
    incomingInterceptors.setAccessible(true);
    outgoingInterceptors.setAccessible(true);
    serviceRegistry.addIncomingInterceptor(new FakeInterceptor());
    serviceRegistry.addOutgoingInterceptor(new FakeInterceptor());
    List<String> interceptorClassNames = new ArrayList<>();
    interceptorClassNames.add(FakeInterceptor.class.getCanonicalName());
    configuration.setIncomingInterceptorClassNames(interceptorClassNames);
    configuration.setOutgoingInterceptorClassNames(interceptorClassNames);
    method.invoke(remotingService, configuration);
    assertTrue(((List) incomingInterceptors.get(remotingService)).size() == 2);
    assertTrue(((List) outgoingInterceptors.get(remotingService)).size() == 2);
    assertTrue(((List) incomingInterceptors.get(remotingService)).contains(serviceRegistry.getIncomingInterceptors(null).get(0)));
    assertTrue(((List) outgoingInterceptors.get(remotingService)).contains(serviceRegistry.getOutgoingInterceptors(null).get(0)));
}
Also used : Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Method(java.lang.reflect.Method) FakeInterceptor(org.apache.activemq.artemis.tests.unit.core.remoting.server.impl.fake.FakeInterceptor) Test(org.junit.Test)

Aggregations

FakeInterceptor (org.apache.activemq.artemis.tests.unit.core.remoting.server.impl.fake.FakeInterceptor)3 Test (org.junit.Test)3 Field (java.lang.reflect.Field)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 RemotingServiceImpl (org.apache.activemq.artemis.core.remoting.server.impl.RemotingServiceImpl)2 Method (java.lang.reflect.Method)1