Search in sources :

Example 6 with ResequencingMessageHandler

use of org.springframework.integration.aggregator.ResequencingMessageHandler in project spring-integration by spring-projects.

the class ResequencerParserTests method testPropertyAssignment.

@Test
public void testPropertyAssignment() throws Exception {
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("completelyDefinedResequencer");
    MessageChannel outputChannel = (MessageChannel) context.getBean("outputChannel");
    MessageChannel discardChannel = (MessageChannel) context.getBean("discardChannel");
    ResequencingMessageHandler resequencer = TestUtils.getPropertyValue(endpoint, "handler", ResequencingMessageHandler.class);
    assertEquals("The ResequencerEndpoint is not injected with the appropriate output channel", outputChannel, getPropertyValue(resequencer, "outputChannel"));
    assertEquals("The ResequencerEndpoint is not injected with the appropriate discard channel", discardChannel, getPropertyValue(resequencer, "discardChannel"));
    assertEquals("The ResequencerEndpoint is not set with the appropriate timeout value", 86420000L, getPropertyValue(resequencer, "messagingTemplate.sendTimeout"));
    assertEquals("The ResequencerEndpoint is not configured with the appropriate 'send partial results on timeout' flag", true, getPropertyValue(resequencer, "sendPartialResultOnExpiry"));
    assertEquals("The ResequencerEndpoint is not configured with the appropriate 'release partial sequences' flag", true, getPropertyValue(getPropertyValue(resequencer, "releaseStrategy"), "releasePartialSequences"));
    assertEquals(60000L, getPropertyValue(resequencer, "minimumTimeoutForEmptyGroups", Long.class).longValue());
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) MessageChannel(org.springframework.messaging.MessageChannel) ResequencingMessageHandler(org.springframework.integration.aggregator.ResequencingMessageHandler) Test(org.junit.Test)

Example 7 with ResequencingMessageHandler

use of org.springframework.integration.aggregator.ResequencingMessageHandler in project spring-integration by spring-projects.

the class ResequencerParserTests method testDefaultResequencerProperties.

@Test
public void testDefaultResequencerProperties() {
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("defaultResequencer");
    ResequencingMessageHandler resequencer = TestUtils.getPropertyValue(endpoint, "handler", ResequencingMessageHandler.class);
    assertNull(getPropertyValue(resequencer, "outputChannel"));
    assertTrue(getPropertyValue(resequencer, "discardChannel") instanceof NullChannel);
    assertEquals("The ResequencerEndpoint is not set with the appropriate timeout value", -1L, getPropertyValue(resequencer, "messagingTemplate.sendTimeout"));
    assertEquals("The ResequencerEndpoint is not configured with the appropriate 'send partial results on timeout' flag", false, getPropertyValue(resequencer, "sendPartialResultOnExpiry"));
    assertEquals("The ResequencerEndpoint is not configured with the appropriate 'release partial sequences' flag", false, getPropertyValue(getPropertyValue(resequencer, "releaseStrategy"), "releasePartialSequences"));
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ResequencingMessageHandler(org.springframework.integration.aggregator.ResequencingMessageHandler) NullChannel(org.springframework.integration.channel.NullChannel) Test(org.junit.Test)

Example 8 with ResequencingMessageHandler

use of org.springframework.integration.aggregator.ResequencingMessageHandler in project spring-integration by spring-projects.

the class ResequencerIntegrationTests method validateUnboundedResequencerLight.

@Test
public void validateUnboundedResequencerLight() {
    MessageChannel inputChannel = context.getBean("resequencerLightInput", MessageChannel.class);
    QueueChannel outputChannel = context.getBean("outputChannel", QueueChannel.class);
    EventDrivenConsumer edc = context.getBean("resequencerLight", EventDrivenConsumer.class);
    ResequencingMessageHandler handler = TestUtils.getPropertyValue(edc, "handler", ResequencingMessageHandler.class);
    MessageGroupStore store = TestUtils.getPropertyValue(handler, "messageStore", MessageGroupStore.class);
    Message<?> message1 = MessageBuilder.withPayload("1").setCorrelationId("A").setSequenceNumber(1).build();
    Message<?> message2 = MessageBuilder.withPayload("2").setCorrelationId("A").setSequenceNumber(2).setCorrelationId("A").setSequenceNumber(2).setHeader("foo", "foo").build();
    Message<?> message3 = MessageBuilder.withPayload("3").setCorrelationId("A").setSequenceNumber(3).build();
    Message<?> message4 = MessageBuilder.withPayload("4").setCorrelationId("A").setSequenceNumber(4).setHeader("foo", "foo").build();
    Message<?> message5 = MessageBuilder.withPayload("5").setCorrelationId("A").setSequenceNumber(5).build();
    Message<?> message6 = MessageBuilder.withPayload("6").setCorrelationId("A").setSequenceNumber(6).build();
    inputChannel.send(message3);
    assertNull(outputChannel.receive(0));
    inputChannel.send(message1);
    message1 = outputChannel.receive(0);
    assertNotNull(message1);
    assertEquals(1, new IntegrationMessageHeaderAccessor(message1).getSequenceNumber());
    assertFalse(message1.getHeaders().containsKey("foo"));
    inputChannel.send(message2);
    message2 = outputChannel.receive(0);
    message3 = outputChannel.receive(0);
    assertNotNull(message2);
    assertNotNull(message3);
    assertEquals(2, new IntegrationMessageHeaderAccessor(message2).getSequenceNumber());
    assertTrue(message2.getHeaders().containsKey("foo"));
    assertEquals(3, new IntegrationMessageHeaderAccessor(message3).getSequenceNumber());
    assertFalse(message3.getHeaders().containsKey("foo"));
    inputChannel.send(message5);
    assertNull(outputChannel.receive(0));
    inputChannel.send(message6);
    assertNull(outputChannel.receive(0));
    inputChannel.send(message4);
    message4 = outputChannel.receive(0);
    message5 = outputChannel.receive(0);
    message6 = outputChannel.receive(0);
    assertNotNull(message4);
    assertNotNull(message5);
    assertNotNull(message6);
    assertEquals(4, new IntegrationMessageHeaderAccessor(message4).getSequenceNumber());
    assertTrue(message4.getHeaders().containsKey("foo"));
    assertEquals(5, new IntegrationMessageHeaderAccessor(message5).getSequenceNumber());
    assertFalse(message5.getHeaders().containsKey("foo"));
    assertEquals(6, new IntegrationMessageHeaderAccessor(message6).getSequenceNumber());
    assertFalse(message6.getHeaders().containsKey("foo"));
    assertEquals(0, store.getMessageGroup("A").getMessages().size());
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) MessageGroupStore(org.springframework.integration.store.MessageGroupStore) MessageChannel(org.springframework.messaging.MessageChannel) QueueChannel(org.springframework.integration.channel.QueueChannel) ResequencingMessageHandler(org.springframework.integration.aggregator.ResequencingMessageHandler) Test(org.junit.Test)

Example 9 with ResequencingMessageHandler

use of org.springframework.integration.aggregator.ResequencingMessageHandler in project spring-integration by spring-projects.

the class ResequencerIntegrationTests method validateUnboundedResequencerDeep.

@Test
public void validateUnboundedResequencerDeep() {
    MessageChannel inputChannel = context.getBean("resequencerDeepInput", MessageChannel.class);
    QueueChannel outputChannel = context.getBean("outputChannel", QueueChannel.class);
    EventDrivenConsumer edc = context.getBean("resequencerDeep", EventDrivenConsumer.class);
    ResequencingMessageHandler handler = TestUtils.getPropertyValue(edc, "handler", ResequencingMessageHandler.class);
    MessageGroupStore store = TestUtils.getPropertyValue(handler, "messageStore", MessageGroupStore.class);
    Message<?> message1 = MessageBuilder.withPayload("1").setCorrelationId("A").setSequenceNumber(1).build();
    Message<?> message2 = MessageBuilder.withPayload("2").setCorrelationId("A").setSequenceNumber(2).build();
    Message<?> message3 = MessageBuilder.withPayload("3").setCorrelationId("A").setSequenceNumber(3).build();
    inputChannel.send(message3);
    assertNull(outputChannel.receive(0));
    inputChannel.send(message1);
    assertNotNull(outputChannel.receive(0));
    inputChannel.send(message2);
    assertNotNull(outputChannel.receive(0));
    assertNotNull(outputChannel.receive(0));
    assertEquals(0, store.getMessageGroup("A").getMessages().size());
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) MessageGroupStore(org.springframework.integration.store.MessageGroupStore) MessageChannel(org.springframework.messaging.MessageChannel) QueueChannel(org.springframework.integration.channel.QueueChannel) ResequencingMessageHandler(org.springframework.integration.aggregator.ResequencingMessageHandler) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 ResequencingMessageHandler (org.springframework.integration.aggregator.ResequencingMessageHandler)9 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)9 MessageChannel (org.springframework.messaging.MessageChannel)3 QueueChannel (org.springframework.integration.channel.QueueChannel)2 MessageGroupStore (org.springframework.integration.store.MessageGroupStore)2 IntegrationMessageHeaderAccessor (org.springframework.integration.IntegrationMessageHeaderAccessor)1 MethodInvokingCorrelationStrategy (org.springframework.integration.aggregator.MethodInvokingCorrelationStrategy)1 MethodInvokingReleaseStrategy (org.springframework.integration.aggregator.MethodInvokingReleaseStrategy)1 ReleaseStrategy (org.springframework.integration.aggregator.ReleaseStrategy)1 NullChannel (org.springframework.integration.channel.NullChannel)1 SimpleMessageGroup (org.springframework.integration.store.SimpleMessageGroup)1