Search in sources :

Example 11 with PublishSubscribeChannel

use of org.springframework.integration.channel.PublishSubscribeChannel in project spring-integration by spring-projects.

the class PublishSubscribeChannelParserTests method channelWithTaskExecutor.

@Test
public void channelWithTaskExecutor() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("publishSubscribeChannelParserTests.xml", this.getClass());
    PublishSubscribeChannel channel = (PublishSubscribeChannel) context.getBean("channelWithTaskExecutor");
    DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
    BroadcastingDispatcher dispatcher = (BroadcastingDispatcher) accessor.getPropertyValue("dispatcher");
    DirectFieldAccessor dispatcherAccessor = new DirectFieldAccessor(dispatcher);
    Executor executor = (Executor) dispatcherAccessor.getPropertyValue("executor");
    assertNotNull(executor);
    assertEquals(ErrorHandlingTaskExecutor.class, executor.getClass());
    DirectFieldAccessor executorAccessor = new DirectFieldAccessor(executor);
    Executor innerExecutor = (Executor) executorAccessor.getPropertyValue("executor");
    assertEquals(context.getBean("pool"), innerExecutor);
    context.close();
}
Also used : ErrorHandlingTaskExecutor(org.springframework.integration.util.ErrorHandlingTaskExecutor) Executor(java.util.concurrent.Executor) PublishSubscribeChannel(org.springframework.integration.channel.PublishSubscribeChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) BroadcastingDispatcher(org.springframework.integration.dispatcher.BroadcastingDispatcher) Test(org.junit.Test)

Example 12 with PublishSubscribeChannel

use of org.springframework.integration.channel.PublishSubscribeChannel in project spring-integration by spring-projects.

the class PublishSubscribeChannelParserTests method applySequenceEnabled.

@Test
public void applySequenceEnabled() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("publishSubscribeChannelParserTests.xml", this.getClass());
    PublishSubscribeChannel channel = (PublishSubscribeChannel) context.getBean("channelWithApplySequenceEnabled");
    DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
    BroadcastingDispatcher dispatcher = (BroadcastingDispatcher) accessor.getPropertyValue("dispatcher");
    assertTrue((Boolean) new DirectFieldAccessor(dispatcher).getPropertyValue("applySequence"));
    context.close();
}
Also used : PublishSubscribeChannel(org.springframework.integration.channel.PublishSubscribeChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) BroadcastingDispatcher(org.springframework.integration.dispatcher.BroadcastingDispatcher) Test(org.junit.Test)

Example 13 with PublishSubscribeChannel

use of org.springframework.integration.channel.PublishSubscribeChannel in project spring-integration by spring-projects.

the class MessageProducerSupportTests method validateExceptionIfSendToErrorChannelFails.

@Test(expected = MessageDeliveryException.class)
public void validateExceptionIfSendToErrorChannelFails() {
    DirectChannel outChannel = new DirectChannel();
    outChannel.subscribe(message -> {
        throw new RuntimeException("problems");
    });
    PublishSubscribeChannel errorChannel = new PublishSubscribeChannel();
    errorChannel.subscribe(message -> {
        throw new RuntimeException("ooops");
    });
    MessageProducerSupport mps = new MessageProducerSupport() {
    };
    mps.setOutputChannel(outChannel);
    mps.setErrorChannel(errorChannel);
    mps.setBeanFactory(TestUtils.createTestApplicationContext());
    mps.afterPropertiesSet();
    mps.start();
    mps.sendMessage(new GenericMessage<String>("hello"));
}
Also used : PublishSubscribeChannel(org.springframework.integration.channel.PublishSubscribeChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) Test(org.junit.Test)

Example 14 with PublishSubscribeChannel

use of org.springframework.integration.channel.PublishSubscribeChannel in project spring-integration by spring-projects.

the class MessageProducerSupportTests method validateSuccessfulErrorFlowDoesNotThrowErrors.

@Test
public void validateSuccessfulErrorFlowDoesNotThrowErrors() {
    TestApplicationContext testApplicationContext = TestUtils.createTestApplicationContext();
    testApplicationContext.refresh();
    DirectChannel outChannel = new DirectChannel();
    outChannel.subscribe(message -> {
        throw new RuntimeException("problems");
    });
    PublishSubscribeChannel errorChannel = new PublishSubscribeChannel();
    SuccessfulErrorService errorService = new SuccessfulErrorService();
    ServiceActivatingHandler handler = new ServiceActivatingHandler(errorService);
    handler.setBeanFactory(testApplicationContext);
    handler.afterPropertiesSet();
    errorChannel.subscribe(handler);
    MessageProducerSupport mps = new MessageProducerSupport() {
    };
    mps.setOutputChannel(outChannel);
    mps.setErrorChannel(errorChannel);
    mps.setBeanFactory(testApplicationContext);
    mps.afterPropertiesSet();
    mps.start();
    Message<?> message = new GenericMessage<String>("hello");
    mps.sendMessage(message);
    assertThat(errorService.lastMessage, instanceOf(ErrorMessage.class));
    ErrorMessage errorMessage = (ErrorMessage) errorService.lastMessage;
    assertEquals(MessageDeliveryException.class, errorMessage.getPayload().getClass());
    MessageDeliveryException exception = (MessageDeliveryException) errorMessage.getPayload();
    assertEquals(message, exception.getFailedMessage());
    testApplicationContext.close();
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) PublishSubscribeChannel(org.springframework.integration.channel.PublishSubscribeChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) ErrorMessage(org.springframework.messaging.support.ErrorMessage) TestApplicationContext(org.springframework.integration.test.util.TestUtils.TestApplicationContext) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 15 with PublishSubscribeChannel

use of org.springframework.integration.channel.PublishSubscribeChannel in project spring-integration by spring-projects.

the class MessagingGatewayTests method validateErroMessageCanNotBeReplyMessage.

// should fail but it doesn't now
@Test(expected = MessagingException.class)
public void validateErroMessageCanNotBeReplyMessage() {
    DirectChannel reqChannel = new DirectChannel();
    reqChannel.subscribe(message -> {
        throw new RuntimeException("ooops");
    });
    PublishSubscribeChannel errorChannel = new PublishSubscribeChannel();
    ServiceActivatingHandler handler = new ServiceActivatingHandler(new MyErrorService());
    handler.setBeanFactory(mock(BeanFactory.class));
    handler.afterPropertiesSet();
    errorChannel.subscribe(handler);
    this.messagingGateway = new MessagingGatewaySupport() {
    };
    this.messagingGateway.setRequestChannel(reqChannel);
    this.messagingGateway.setErrorChannel(errorChannel);
    this.messagingGateway.setReplyChannel(null);
    this.messagingGateway.setBeanFactory(mock(BeanFactory.class));
    this.messagingGateway.afterPropertiesSet();
    this.messagingGateway.start();
    this.messagingGateway.sendAndReceiveMessage("hello");
}
Also used : PublishSubscribeChannel(org.springframework.integration.channel.PublishSubscribeChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) BeanFactory(org.springframework.beans.factory.BeanFactory) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Aggregations

PublishSubscribeChannel (org.springframework.integration.channel.PublishSubscribeChannel)16 Test (org.junit.Test)13 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)7 BroadcastingDispatcher (org.springframework.integration.dispatcher.BroadcastingDispatcher)6 DirectChannel (org.springframework.integration.channel.DirectChannel)5 Executor (java.util.concurrent.Executor)3 ServiceActivatingHandler (org.springframework.integration.handler.ServiceActivatingHandler)3 TestApplicationContext (org.springframework.integration.test.util.TestUtils.TestApplicationContext)3 ErrorHandlingTaskExecutor (org.springframework.integration.util.ErrorHandlingTaskExecutor)3 BeanFactory (org.springframework.beans.factory.BeanFactory)2 AbstractMessageChannel (org.springframework.integration.channel.AbstractMessageChannel)2 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)2 SubscribableChannel (org.springframework.messaging.SubscribableChannel)2 ErrorMessage (org.springframework.messaging.support.ErrorMessage)2 GenericMessage (org.springframework.messaging.support.GenericMessage)2 Set (java.util.Set)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)1