use of org.springframework.integration.handler.AbstractMessageHandler in project spring-integration by spring-projects.
the class IntegrationManagementConfigurerTests method testDefaults.
@Test
public void testDefaults() {
DirectChannel channel = new DirectChannel();
AbstractMessageHandler handler = new RecipientListRouter();
AbstractMessageSource<?> source = new AbstractMessageSource<Object>() {
@Override
public String getComponentType() {
return null;
}
@Override
protected Object doReceive() {
return null;
}
};
assertTrue(channel.isLoggingEnabled());
assertTrue(handler.isLoggingEnabled());
assertTrue(source.isLoggingEnabled());
channel.setCountsEnabled(true);
channel.setStatsEnabled(true);
ApplicationContext ctx = mock(ApplicationContext.class);
Map<String, IntegrationManagement> beans = new HashMap<String, IntegrationManagement>();
beans.put("foo", channel);
beans.put("bar", handler);
beans.put("baz", source);
when(ctx.getBeansOfType(IntegrationManagement.class)).thenReturn(beans);
IntegrationManagementConfigurer configurer = new IntegrationManagementConfigurer();
configurer.setBeanName(IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME);
configurer.setApplicationContext(ctx);
configurer.setDefaultLoggingEnabled(false);
configurer.afterSingletonsInstantiated();
assertFalse(channel.isLoggingEnabled());
assertFalse(handler.isLoggingEnabled());
assertFalse(source.isLoggingEnabled());
assertTrue(channel.isCountsEnabled());
assertTrue(channel.isStatsEnabled());
}
use of org.springframework.integration.handler.AbstractMessageHandler in project spring-integration by spring-projects.
the class AggregatorTests method testCustomAggPerf.
@Test
public void testCustomAggPerf() throws InterruptedException, ExecutionException, TimeoutException {
class CustomHandler extends AbstractMessageHandler {
// custom aggregator, only handles a single correlation
private final ReentrantLock lock = new ReentrantLock();
private final Collection<Message<?>> messages = new ArrayList<Message<?>>(60000);
private final MessageChannel outputChannel;
private CustomHandler(MessageChannel outputChannel) {
this.outputChannel = outputChannel;
}
@Override
public void handleMessageInternal(Message<?> requestMessage) {
lock.lock();
try {
this.messages.add(requestMessage);
if (this.messages.size() == 60000) {
List<Object> payloads = new ArrayList<Object>(this.messages.size());
for (Message<?> message : this.messages) {
payloads.add(message.getPayload());
}
this.messages.clear();
outputChannel.send(getMessageBuilderFactory().withPayload(payloads).copyHeaders(requestMessage.getHeaders()).build());
}
} finally {
lock.unlock();
}
}
}
DirectChannel outputChannel = new DirectChannel();
CustomHandler handler = new CustomHandler(outputChannel);
final CompletableFuture<Collection<?>> resultFuture = new CompletableFuture<>();
outputChannel.subscribe(message -> {
Collection<?> payload = (Collection<?>) message.getPayload();
logger.warn("Received " + payload.size());
resultFuture.complete(payload);
});
Message<?> message = new GenericMessage<String>("foo");
StopWatch stopwatch = new StopWatch();
stopwatch.start();
for (int i = 0; i < 120000; i++) {
if (i % 10000 == 0) {
stopwatch.stop();
logger.warn("Sent " + i + " in " + stopwatch.getTotalTimeSeconds() + " (10k in " + stopwatch.getLastTaskTimeMillis() + "ms)");
stopwatch.start();
}
handler.handleMessage(message);
}
stopwatch.stop();
logger.warn("Sent " + 120000 + " in " + stopwatch.getTotalTimeSeconds() + " (10k in " + stopwatch.getLastTaskTimeMillis() + "ms)");
Collection<?> result = resultFuture.get(10, TimeUnit.SECONDS);
assertNotNull(result);
assertEquals(60000, result.size());
}
Aggregations