use of org.springframework.integration.support.management.DefaultMessageChannelMetrics in project spring-integration by spring-projects.
the class NullChannel method setBeanName.
@Override
public void setBeanName(String beanName) {
this.beanName = beanName;
this.channelMetrics = new DefaultMessageChannelMetrics(getComponentName());
}
use of org.springframework.integration.support.management.DefaultMessageChannelMetrics in project spring-integration by spring-projects.
the class MonitorTests method testStats.
@Test
public void testStats() throws InterruptedException {
final CountDownLatch afterSendLatch = new CountDownLatch(1);
DefaultMessageChannelMetrics channelMetrics = TestUtils.getPropertyValue(this.next, "channelMetrics", DefaultMessageChannelMetrics.class);
channelMetrics = Mockito.spy(channelMetrics);
Mockito.doAnswer(invocation -> {
Object result = invocation.callRealMethod();
afterSendLatch.countDown();
return result;
}).when(channelMetrics).afterSend(Mockito.any(MetricsContext.class), Mockito.eq(Boolean.TRUE));
new DirectFieldAccessor(this.next).setPropertyValue("channelMetrics", channelMetrics);
MessagingTemplate messagingTemplate = new MessagingTemplate(this.input);
messagingTemplate.setReceiveTimeout(10000);
Integer active = messagingTemplate.convertSendAndReceive("foo", Integer.class);
assertEquals(1, active.intValue());
assertTrue(afterSendLatch.await(10, TimeUnit.SECONDS));
assertEquals(0, this.handler.getActiveCount());
assertEquals(1, this.handler.getHandleCount());
assertThat(this.handler.getDuration().getMax(), greaterThan(99.0));
assertThat(this.handler.getDuration().getMax(), lessThan(10000.0));
assertEquals(1, this.input.getSendCount());
assertEquals(1, this.input.getReceiveCount());
assertEquals(1, this.next.getSendCount());
assertThat(this.next.getSendDuration().getMax(), greaterThan(99.0));
assertThat(this.next.getSendDuration().getMax(), lessThan(10000.0));
Message<?> fromInbound = this.output.receive(10000);
assertNotNull(fromInbound);
assertEquals(0, fromInbound.getPayload());
fromInbound = this.output.receive(10000);
assertNotNull(fromInbound);
assertEquals(1, fromInbound.getPayload());
assertThat(this.source.getMessageCount(), greaterThanOrEqualTo(2));
assertThat(this.nullChannel.getSendCount(), greaterThanOrEqualTo(2));
assertThat(this.pubsub.getSendCount(), greaterThanOrEqualTo(2));
}
Aggregations