Search in sources :

Example 1 with Splitter

use of org.springframework.integration.annotation.Splitter in project spring-integration by spring-projects.

the class StreamingSplitterTests method splitToIterator_allMessagesContainSequenceNumber.

@Test
public void splitToIterator_allMessagesContainSequenceNumber() throws Exception {
    final int messageQuantity = 5;
    MethodInvokingSplitter splitter = new MethodInvokingSplitter(new IteratorTestBean(messageQuantity));
    DirectChannel replyChannel = new DirectChannel();
    splitter.setOutputChannel(replyChannel);
    new EventDrivenConsumer(replyChannel, message -> assertThat("Failure with msg: " + message, message.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, Integer.class), is(Integer.valueOf((String) message.getPayload())))).start();
    splitter.handleMessage(message);
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Iterator(java.util.Iterator) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UUID(java.util.UUID) MessageHeaders(org.springframework.messaging.MessageHeaders) Splitter(org.springframework.integration.annotation.Splitter) Assert.assertThat(org.junit.Assert.assertThat) MessageBuilder(org.springframework.integration.support.MessageBuilder) List(java.util.List) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) Matchers.is(org.hamcrest.Matchers.is) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) DirectChannel(org.springframework.integration.channel.DirectChannel) Collections(java.util.Collections) Before(org.junit.Before) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) DirectChannel(org.springframework.integration.channel.DirectChannel) Test(org.junit.Test)

Example 2 with Splitter

use of org.springframework.integration.annotation.Splitter in project spring-integration by spring-projects.

the class StreamingSplitterTests method splitWithMassiveReplyMessages_allMessagesSent.

@Test
public void splitWithMassiveReplyMessages_allMessagesSent() throws Exception {
    final int messageQuantity = 100000;
    MethodInvokingSplitter splitter = new MethodInvokingSplitter(new IteratorTestBean(messageQuantity));
    DirectChannel replyChannel = new DirectChannel();
    splitter.setOutputChannel(replyChannel);
    final AtomicInteger receivedMessageCounter = new AtomicInteger(0);
    new EventDrivenConsumer(replyChannel, message -> {
        assertThat("Failure with msg: " + message, message.getPayload(), is(notNullValue()));
        receivedMessageCounter.incrementAndGet();
    }).start();
    splitter.handleMessage(message);
    assertThat(receivedMessageCounter.get(), is(messageQuantity));
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Iterator(java.util.Iterator) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UUID(java.util.UUID) MessageHeaders(org.springframework.messaging.MessageHeaders) Splitter(org.springframework.integration.annotation.Splitter) Assert.assertThat(org.junit.Assert.assertThat) MessageBuilder(org.springframework.integration.support.MessageBuilder) List(java.util.List) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) Matchers.is(org.hamcrest.Matchers.is) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) DirectChannel(org.springframework.integration.channel.DirectChannel) Collections(java.util.Collections) Before(org.junit.Before) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) DirectChannel(org.springframework.integration.channel.DirectChannel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Aggregations

Collections (java.util.Collections)2 Iterator (java.util.Iterator)2 List (java.util.List)2 UUID (java.util.UUID)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Matchers.is (org.hamcrest.Matchers.is)2 Matchers.notNullValue (org.hamcrest.Matchers.notNullValue)2 Assert.assertThat (org.junit.Assert.assertThat)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 Before (org.junit.Before)2 Test (org.junit.Test)2 IntegrationMessageHeaderAccessor (org.springframework.integration.IntegrationMessageHeaderAccessor)2 Splitter (org.springframework.integration.annotation.Splitter)2 DirectChannel (org.springframework.integration.channel.DirectChannel)2 QueueChannel (org.springframework.integration.channel.QueueChannel)2 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)2 MessageBuilder (org.springframework.integration.support.MessageBuilder)2 Message (org.springframework.messaging.Message)2 MessageHeaders (org.springframework.messaging.MessageHeaders)2 GenericMessage (org.springframework.messaging.support.GenericMessage)2