Search in sources :

Example 61 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer 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 62 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer 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 63 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer 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 64 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer 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)

Example 65 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.

the class DirectChannelSubscriptionTests method sendAndReceiveForRegisteredEndpoint.

@Test
public void sendAndReceiveForRegisteredEndpoint() {
    TestApplicationContext context = TestUtils.createTestApplicationContext();
    ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "handle");
    serviceActivator.setOutputChannel(targetChannel);
    EventDrivenConsumer endpoint = new EventDrivenConsumer(sourceChannel, serviceActivator);
    context.registerEndpoint("testEndpoint", endpoint);
    context.refresh();
    this.sourceChannel.send(new GenericMessage<String>("foo"));
    Message<?> response = this.targetChannel.receive();
    assertEquals("foo!", response.getPayload());
    context.stop();
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) TestApplicationContext(org.springframework.integration.test.util.TestUtils.TestApplicationContext) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Aggregations

EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)106 Test (org.junit.Test)96 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)29 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)27 DirectChannel (org.springframework.integration.channel.DirectChannel)19 PollableChannel (org.springframework.messaging.PollableChannel)19 GenericMessage (org.springframework.messaging.support.GenericMessage)18 MessageChannel (org.springframework.messaging.MessageChannel)16 QueueChannel (org.springframework.integration.channel.QueueChannel)14 MessageHandler (org.springframework.messaging.MessageHandler)12 List (java.util.List)9 ResequencingMessageHandler (org.springframework.integration.aggregator.ResequencingMessageHandler)9 Message (org.springframework.messaging.Message)8 SmartLifecycle (org.springframework.context.SmartLifecycle)6 JmsOutboundGateway (org.springframework.integration.jms.JmsOutboundGateway)6 MongoDbAvailable (org.springframework.integration.mongodb.rules.MongoDbAvailable)6 SmartLifecycleRoleController (org.springframework.integration.support.SmartLifecycleRoleController)6 MethodInvokingReleaseStrategy (org.springframework.integration.aggregator.MethodInvokingReleaseStrategy)5 ReleaseStrategy (org.springframework.integration.aggregator.ReleaseStrategy)5 AbstractReplyProducingMessageHandler (org.springframework.integration.handler.AbstractReplyProducingMessageHandler)5