use of org.springframework.integration.aggregator.MethodInvokingReleaseStrategy in project spring-integration by spring-projects.
the class AggregatorAnnotationTests method testAnnotationWithCustomReleaseStrategy.
@Test
public void testAnnotationWithCustomReleaseStrategy() throws Exception {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "classpath:/org/springframework/integration/config/annotation/testAnnotatedAggregator.xml" });
final String endpointName = "endpointWithDefaultAnnotationAndCustomReleaseStrategy";
MessageHandler aggregator = this.getAggregator(context, endpointName);
Object releaseStrategy = getPropertyValue(aggregator, "releaseStrategy");
Assert.assertTrue(releaseStrategy instanceof MethodInvokingReleaseStrategy);
MethodInvokingReleaseStrategy releaseStrategyAdapter = (MethodInvokingReleaseStrategy) releaseStrategy;
Object handlerMethods = new DirectFieldAccessor(releaseStrategyAdapter).getPropertyValue("adapter.delegate.handlerMethods");
assertNull(handlerMethods);
Object handlerMethod = new DirectFieldAccessor(releaseStrategyAdapter).getPropertyValue("adapter.delegate.handlerMethod");
assertTrue(handlerMethod.toString().contains("completionChecker"));
context.close();
}
use of org.springframework.integration.aggregator.MethodInvokingReleaseStrategy in project spring-integration by spring-projects.
the class AggregatorParserTests method testAggregatorWithPojoReleaseStrategy.
@Test
@SuppressWarnings("unchecked")
public void testAggregatorWithPojoReleaseStrategy() {
MessageChannel input = this.context.getBean("aggregatorWithPojoReleaseStrategyInput", MessageChannel.class);
EventDrivenConsumer endpoint = this.context.getBean("aggregatorWithPojoReleaseStrategy", EventDrivenConsumer.class);
ReleaseStrategy releaseStrategy = TestUtils.getPropertyValue(endpoint, "handler.releaseStrategy", ReleaseStrategy.class);
Assert.assertTrue(releaseStrategy instanceof MethodInvokingReleaseStrategy);
MessagingMethodInvokerHelper<Long> methodInvokerHelper = TestUtils.getPropertyValue(releaseStrategy, "adapter.delegate", MessagingMethodInvokerHelper.class);
Object handlerMethods = TestUtils.getPropertyValue(methodInvokerHelper, "handlerMethods");
assertNull(handlerMethods);
Object handlerMethod = TestUtils.getPropertyValue(methodInvokerHelper, "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());
}
use of org.springframework.integration.aggregator.MethodInvokingReleaseStrategy 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());
}
use of org.springframework.integration.aggregator.MethodInvokingReleaseStrategy 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));
}
use of org.springframework.integration.aggregator.MethodInvokingReleaseStrategy in project spring-integration by spring-projects.
the class AggregatorAnnotationPostProcessor method createHandler.
@Override
protected MessageHandler createHandler(Object bean, Method method, List<Annotation> annotations) {
MethodInvokingMessageGroupProcessor processor = new MethodInvokingMessageGroupProcessor(bean, method);
processor.setBeanFactory(this.beanFactory);
MethodInvokingReleaseStrategy releaseStrategy = null;
Method releaseStrategyMethod = MessagingAnnotationUtils.findAnnotatedMethod(bean, ReleaseStrategy.class);
if (releaseStrategyMethod != null) {
releaseStrategy = new MethodInvokingReleaseStrategy(bean, releaseStrategyMethod);
}
MethodInvokingCorrelationStrategy correlationStrategy = null;
Method correlationStrategyMethod = MessagingAnnotationUtils.findAnnotatedMethod(bean, CorrelationStrategy.class);
if (correlationStrategyMethod != null) {
correlationStrategy = new MethodInvokingCorrelationStrategy(bean, correlationStrategyMethod);
}
AggregatingMessageHandler handler = new AggregatingMessageHandler(processor, new SimpleMessageStore(), correlationStrategy, releaseStrategy);
String discardChannelName = MessagingAnnotationUtils.resolveAttribute(annotations, "discardChannel", String.class);
if (StringUtils.hasText(discardChannelName)) {
handler.setDiscardChannelName(discardChannelName);
}
String outputChannelName = MessagingAnnotationUtils.resolveAttribute(annotations, "outputChannel", String.class);
if (StringUtils.hasText(outputChannelName)) {
handler.setOutputChannelName(outputChannelName);
}
String sendPartialResultsOnExpiry = MessagingAnnotationUtils.resolveAttribute(annotations, "sendPartialResultsOnExpiry", String.class);
if (sendPartialResultsOnExpiry != null) {
handler.setSendPartialResultOnExpiry(Boolean.parseBoolean(this.beanFactory.resolveEmbeddedValue(sendPartialResultsOnExpiry)));
}
handler.setBeanFactory(this.beanFactory);
return handler;
}
Aggregations