Search in sources :

Example 6 with ReleaseStrategy

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

the class AggregatorParserTests method testPropertyAssignment.

@Test
public void testPropertyAssignment() throws Exception {
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("completelyDefinedAggregator");
    ReleaseStrategy releaseStrategy = (ReleaseStrategy) context.getBean("releaseStrategy");
    CorrelationStrategy correlationStrategy = (CorrelationStrategy) context.getBean("correlationStrategy");
    MessageChannel outputChannel = (MessageChannel) context.getBean("outputChannel");
    MessageChannel discardChannel = (MessageChannel) context.getBean("discardChannel");
    Object consumer = new DirectFieldAccessor(endpoint).getPropertyValue("handler");
    assertThat(consumer, is(instanceOf(AggregatingMessageHandler.class)));
    DirectFieldAccessor accessor = new DirectFieldAccessor(consumer);
    Object handlerMethods = new DirectFieldAccessor(new DirectFieldAccessor(new DirectFieldAccessor(accessor.getPropertyValue("outputProcessor")).getPropertyValue("processor")).getPropertyValue("delegate")).getPropertyValue("handlerMethods");
    assertNull(handlerMethods);
    Object handlerMethod = new DirectFieldAccessor(new DirectFieldAccessor(new DirectFieldAccessor(accessor.getPropertyValue("outputProcessor")).getPropertyValue("processor")).getPropertyValue("delegate")).getPropertyValue("handlerMethod");
    assertTrue(handlerMethod.toString().contains("createSingleMessageFromGroup"));
    assertEquals("The AggregatorEndpoint is not injected with the appropriate ReleaseStrategy instance", releaseStrategy, accessor.getPropertyValue("releaseStrategy"));
    assertEquals("The AggregatorEndpoint is not injected with the appropriate CorrelationStrategy instance", correlationStrategy, accessor.getPropertyValue("correlationStrategy"));
    assertEquals("The AggregatorEndpoint is not injected with the appropriate output channel", outputChannel, accessor.getPropertyValue("outputChannel"));
    assertEquals("The AggregatorEndpoint is not injected with the appropriate discard channel", discardChannel, accessor.getPropertyValue("discardChannel"));
    assertEquals("The AggregatorEndpoint is not set with the appropriate timeout value", 86420000L, TestUtils.getPropertyValue(consumer, "messagingTemplate.sendTimeout"));
    assertEquals("The AggregatorEndpoint is not configured with the appropriate 'send partial results on timeout' flag", true, accessor.getPropertyValue("sendPartialResultOnExpiry"));
    assertFalse(TestUtils.getPropertyValue(consumer, "expireGroupsUponTimeout", Boolean.class));
    assertTrue(TestUtils.getPropertyValue(consumer, "expireGroupsUponCompletion", Boolean.class));
    assertEquals(123L, TestUtils.getPropertyValue(consumer, "minimumTimeoutForEmptyGroups"));
    assertEquals("456", TestUtils.getPropertyValue(consumer, "groupTimeoutExpression", Expression.class).getExpressionString());
    assertSame(this.context.getBean(LockRegistry.class), TestUtils.getPropertyValue(consumer, "lockRegistry"));
    assertSame(this.context.getBean("scheduler"), TestUtils.getPropertyValue(consumer, "taskScheduler"));
    assertSame(this.context.getBean("store"), TestUtils.getPropertyValue(consumer, "messageStore"));
    assertEquals(5, TestUtils.getPropertyValue(consumer, "order"));
    assertNotNull(TestUtils.getPropertyValue(consumer, "forceReleaseAdviceChain"));
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) MessageChannel(org.springframework.messaging.MessageChannel) LockRegistry(org.springframework.integration.support.locks.LockRegistry) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) CorrelationStrategy(org.springframework.integration.aggregator.CorrelationStrategy) ExpressionEvaluatingCorrelationStrategy(org.springframework.integration.aggregator.ExpressionEvaluatingCorrelationStrategy) MethodInvokingReleaseStrategy(org.springframework.integration.aggregator.MethodInvokingReleaseStrategy) ReleaseStrategy(org.springframework.integration.aggregator.ReleaseStrategy) ExpressionEvaluatingReleaseStrategy(org.springframework.integration.aggregator.ExpressionEvaluatingReleaseStrategy) Test(org.junit.Test)

Example 7 with ReleaseStrategy

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

the class AggregatorParserTests method testAggregatorWithPojoReleaseStrategyAsCollection.

// see INT-2011
@Test
public void testAggregatorWithPojoReleaseStrategyAsCollection() {
    MessageChannel input = (MessageChannel) context.getBean("aggregatorWithPojoReleaseStrategyInputAsCollection");
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("aggregatorWithPojoReleaseStrategyAsCollection");
    ReleaseStrategy releaseStrategy = (ReleaseStrategy) new DirectFieldAccessor(new DirectFieldAccessor(endpoint).getPropertyValue("handler")).getPropertyValue("releaseStrategy");
    Assert.assertTrue(releaseStrategy instanceof MethodInvokingReleaseStrategy);
    DirectFieldAccessor releaseStrategyAccessor = new DirectFieldAccessor(new DirectFieldAccessor(new DirectFieldAccessor(releaseStrategy).getPropertyValue("adapter")).getPropertyValue("delegate"));
    Object handlerMethods = releaseStrategyAccessor.getPropertyValue("handlerMethods");
    assertNull(handlerMethods);
    Object handlerMethod = releaseStrategyAccessor.getPropertyValue("handlerMethod");
    assertTrue(handlerMethod.toString().contains("checkCompleteness"));
    input.send(createMessage(1L, "correlationId", 4, 0, null));
    input.send(createMessage(2L, "correlationId", 4, 1, null));
    input.send(createMessage(3L, "correlationId", 4, 2, null));
    PollableChannel outputChannel = (PollableChannel) context.getBean("outputChannel");
    Message<?> reply = outputChannel.receive(0);
    Assert.assertNull(reply);
    input.send(createMessage(5L, "correlationId", 4, 3, null));
    reply = outputChannel.receive(0);
    Assert.assertNotNull(reply);
    assertEquals(11L, reply.getPayload());
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) MessageChannel(org.springframework.messaging.MessageChannel) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) PollableChannel(org.springframework.messaging.PollableChannel) MethodInvokingReleaseStrategy(org.springframework.integration.aggregator.MethodInvokingReleaseStrategy) MethodInvokingReleaseStrategy(org.springframework.integration.aggregator.MethodInvokingReleaseStrategy) ReleaseStrategy(org.springframework.integration.aggregator.ReleaseStrategy) ExpressionEvaluatingReleaseStrategy(org.springframework.integration.aggregator.ExpressionEvaluatingReleaseStrategy) Test(org.junit.Test)

Example 8 with ReleaseStrategy

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

the class AggregatorParserTests method testAggregationWithExpressionsAndPojoAggregator.

@Test
public void testAggregationWithExpressionsAndPojoAggregator() {
    EventDrivenConsumer aggregatorConsumer = (EventDrivenConsumer) context.getBean("aggregatorWithExpressionsAndPojoAggregator");
    AggregatingMessageHandler aggregatingMessageHandler = (AggregatingMessageHandler) TestUtils.getPropertyValue(aggregatorConsumer, "handler");
    MethodInvokingMessageGroupProcessor messageGroupProcessor = (MethodInvokingMessageGroupProcessor) TestUtils.getPropertyValue(aggregatingMessageHandler, "outputProcessor");
    Object messageGroupProcessorTargetObject = TestUtils.getPropertyValue(messageGroupProcessor, "processor.delegate.targetObject");
    assertSame(context.getBean("aggregatorBean"), messageGroupProcessorTargetObject);
    ReleaseStrategy releaseStrategy = (ReleaseStrategy) TestUtils.getPropertyValue(aggregatingMessageHandler, "releaseStrategy");
    CorrelationStrategy correlationStrategy = (CorrelationStrategy) TestUtils.getPropertyValue(aggregatingMessageHandler, "correlationStrategy");
    Long minimumTimeoutForEmptyGroups = TestUtils.getPropertyValue(aggregatingMessageHandler, "minimumTimeoutForEmptyGroups", Long.class);
    assertTrue(ExpressionEvaluatingReleaseStrategy.class.equals(releaseStrategy.getClass()));
    assertTrue(ExpressionEvaluatingCorrelationStrategy.class.equals(correlationStrategy.getClass()));
    assertEquals(60000L, minimumTimeoutForEmptyGroups.longValue());
}
Also used : AggregatingMessageHandler(org.springframework.integration.aggregator.AggregatingMessageHandler) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) MethodInvokingMessageGroupProcessor(org.springframework.integration.aggregator.MethodInvokingMessageGroupProcessor) CorrelationStrategy(org.springframework.integration.aggregator.CorrelationStrategy) ExpressionEvaluatingCorrelationStrategy(org.springframework.integration.aggregator.ExpressionEvaluatingCorrelationStrategy) ExpressionEvaluatingReleaseStrategy(org.springframework.integration.aggregator.ExpressionEvaluatingReleaseStrategy) MethodInvokingReleaseStrategy(org.springframework.integration.aggregator.MethodInvokingReleaseStrategy) ReleaseStrategy(org.springframework.integration.aggregator.ReleaseStrategy) ExpressionEvaluatingReleaseStrategy(org.springframework.integration.aggregator.ExpressionEvaluatingReleaseStrategy) ExpressionEvaluatingCorrelationStrategy(org.springframework.integration.aggregator.ExpressionEvaluatingCorrelationStrategy) Test(org.junit.Test)

Example 9 with ReleaseStrategy

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

the class ResequencerParserTests method testReleaseStrategyRefAndMethod.

@Test
public void testReleaseStrategyRefAndMethod() throws Exception {
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("resequencerWithReleaseStrategyRefAndMethod");
    ResequencingMessageHandler resequencer = getPropertyValue(endpoint, "handler", ResequencingMessageHandler.class);
    Object releaseStrategyBean = context.getBean("testReleaseStrategyPojo");
    assertTrue("Release strategy is not of the expected type", releaseStrategyBean instanceof TestReleaseStrategyPojo);
    TestReleaseStrategyPojo expectedReleaseStrategy = (TestReleaseStrategyPojo) releaseStrategyBean;
    int currentInvocationCount = expectedReleaseStrategy.invocationCount;
    ReleaseStrategy effectiveReleaseStrategy = (ReleaseStrategy) getPropertyValue(resequencer, "releaseStrategy");
    assertTrue("The release strategy is expected to be a MethodInvokingReleaseStrategy", effectiveReleaseStrategy instanceof MethodInvokingReleaseStrategy);
    effectiveReleaseStrategy.canRelease(new SimpleMessageGroup("test"));
    assertEquals("The ResequencerEndpoint was not invoked the expected number of times;", currentInvocationCount + 1, expectedReleaseStrategy.invocationCount);
    assertTrue(TestUtils.getPropertyValue(resequencer, "expireGroupsUponTimeout", Boolean.class));
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ResequencingMessageHandler(org.springframework.integration.aggregator.ResequencingMessageHandler) MethodInvokingReleaseStrategy(org.springframework.integration.aggregator.MethodInvokingReleaseStrategy) MethodInvokingReleaseStrategy(org.springframework.integration.aggregator.MethodInvokingReleaseStrategy) ReleaseStrategy(org.springframework.integration.aggregator.ReleaseStrategy) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Test(org.junit.Test)

Example 10 with ReleaseStrategy

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

the class ReleaseStrategyFactoryBeanTests method testRefThatImplementsWithDifferentMethod.

@Test
public void testRefThatImplementsWithDifferentMethod() throws Exception {
    Baz baz = new Baz();
    ReleaseStrategyFactoryBean factory = new ReleaseStrategyFactoryBean();
    factory.setTarget(baz);
    factory.setMethodName("doRelease2");
    factory.afterPropertiesSet();
    ReleaseStrategy delegate = factory.getObject();
    assertThat(delegate, instanceOf(MethodInvokingReleaseStrategy.class));
    assertThat(TestUtils.getPropertyValue(delegate, "adapter.delegate.targetObject", Baz.class), is(baz));
    assertThat(TestUtils.getPropertyValue(delegate, "adapter.delegate.handlerMethod.expressionString"), equalTo("#target.doRelease2(messages)"));
}
Also used : MethodInvokingReleaseStrategy(org.springframework.integration.aggregator.MethodInvokingReleaseStrategy) MethodInvokingReleaseStrategy(org.springframework.integration.aggregator.MethodInvokingReleaseStrategy) ReleaseStrategy(org.springframework.integration.aggregator.ReleaseStrategy) SequenceSizeReleaseStrategy(org.springframework.integration.aggregator.SequenceSizeReleaseStrategy) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 MethodInvokingReleaseStrategy (org.springframework.integration.aggregator.MethodInvokingReleaseStrategy)11 ReleaseStrategy (org.springframework.integration.aggregator.ReleaseStrategy)11 SequenceSizeReleaseStrategy (org.springframework.integration.aggregator.SequenceSizeReleaseStrategy)6 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)5 ExpressionEvaluatingReleaseStrategy (org.springframework.integration.aggregator.ExpressionEvaluatingReleaseStrategy)4 MessageChannel (org.springframework.messaging.MessageChannel)3 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 CorrelationStrategy (org.springframework.integration.aggregator.CorrelationStrategy)2 ExpressionEvaluatingCorrelationStrategy (org.springframework.integration.aggregator.ExpressionEvaluatingCorrelationStrategy)2 PollableChannel (org.springframework.messaging.PollableChannel)2 AggregatingMessageHandler (org.springframework.integration.aggregator.AggregatingMessageHandler)1 MethodInvokingMessageGroupProcessor (org.springframework.integration.aggregator.MethodInvokingMessageGroupProcessor)1 ResequencingMessageHandler (org.springframework.integration.aggregator.ResequencingMessageHandler)1 SimpleMessageGroup (org.springframework.integration.store.SimpleMessageGroup)1 LockRegistry (org.springframework.integration.support.locks.LockRegistry)1