Search in sources :

Example 1 with LagReportingMessage

use of io.confluent.ksql.rest.entity.LagReportingMessage in project ksql by confluentinc.

the class LagReportingAgentTest method shouldSendLags.

@Test
public void shouldSendLags() {
    // Given:
    when(clock.millis()).thenReturn(TIME_NOW_MS);
    when(lagInfo0.currentOffsetPosition()).thenReturn(M2_A1_CUR);
    when(lagInfo0.endOffsetPosition()).thenReturn(M2_A1_END);
    when(lagInfo0.offsetLag()).thenReturn(M2_A1_LAG);
    when(lagInfo1.currentOffsetPosition()).thenReturn(M2_B4_CUR);
    when(lagInfo1.endOffsetPosition()).thenReturn(M2_B4_END);
    when(lagInfo1.offsetLag()).thenReturn(M2_B4_LAG);
    Map<String, Map<Integer, LagInfo>> query0Lag = ImmutableMap.<String, Map<Integer, LagInfo>>builder().put(STATE_STORE0, ImmutableMap.<Integer, LagInfo>builder().put(1, lagInfo0).build()).build();
    Map<String, Map<Integer, LagInfo>> query1Lag = ImmutableMap.<String, Map<Integer, LagInfo>>builder().put(STATE_STORE1, ImmutableMap.<Integer, LagInfo>builder().put(4, lagInfo1).build()).build();
    when(ksqlEngine.getPersistentQueries()).thenReturn(ImmutableList.of(query0, query1));
    when(query0.getAllLocalStorePartitionLags()).thenReturn(query0Lag);
    when(query0.getQueryApplicationId()).thenReturn(QUERY_ID0);
    when(query1.getAllLocalStorePartitionLags()).thenReturn(query1Lag);
    when(query1.getQueryApplicationId()).thenReturn(QUERY_ID1);
    SendLagService sendLagService = lagReportingAgent.new SendLagService();
    // When:
    lagReportingAgent.onHostStatusUpdated(HOSTS_ALIVE);
    sendLagService.runOneIteration();
    // Then:
    LagReportingMessage exp = hostLag(LOCALHOST_INFO, LAG_MAP2, TIME_NOW_MS);
    verify(ksqlClient).makeAsyncLagReportRequest(eq(URI.create("http://host2:1234/")), eq(exp));
    verify(ksqlClient).makeAsyncLagReportRequest(eq(URI.create("http://host1:1234/")), eq(exp));
}
Also used : Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) LagInfo(org.apache.kafka.streams.LagInfo) LagReportingMessage(io.confluent.ksql.rest.entity.LagReportingMessage) SendLagService(io.confluent.ksql.rest.server.LagReportingAgent.SendLagService) Test(org.junit.Test)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 LagReportingMessage (io.confluent.ksql.rest.entity.LagReportingMessage)1 SendLagService (io.confluent.ksql.rest.server.LagReportingAgent.SendLagService)1 Map (java.util.Map)1 LagInfo (org.apache.kafka.streams.LagInfo)1 Test (org.junit.Test)1