Search in sources :

Example 1 with DefaultMessageChannelMetrics

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());
}
Also used : DefaultMessageChannelMetrics(org.springframework.integration.support.management.DefaultMessageChannelMetrics)

Example 2 with DefaultMessageChannelMetrics

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));
}
Also used : DefaultMessageChannelMetrics(org.springframework.integration.support.management.DefaultMessageChannelMetrics) MessagingTemplate(org.springframework.integration.core.MessagingTemplate) MetricsContext(org.springframework.integration.support.management.MetricsContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

DefaultMessageChannelMetrics (org.springframework.integration.support.management.DefaultMessageChannelMetrics)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 MessagingTemplate (org.springframework.integration.core.MessagingTemplate)1 MetricsContext (org.springframework.integration.support.management.MetricsContext)1