use of io.confluent.ksql.rest.entity.ClusterStatusResponse in project ksql by confluentinc.
the class ClusterStatusResourceTest method shouldReturnEmptyLagsForDeadHost.
@Test
public void shouldReturnEmptyLagsForDeadHost() {
// Given:
when(heartbeatAgent.getHostsStatus()).thenReturn(HOSTS);
when(lagReportingAgent.getLagPerHost(any())).thenReturn(Optional.of(HOST_STORE_LAGS));
// When:
final EndpointResponse response = clusterStatusResource.checkClusterStatus();
// Then:
assertThat(response.getStatus(), is(200));
assertThat(response.getEntity(), instanceOf(ClusterStatusResponse.class));
ClusterStatusResponse clusterStatusResponse = (ClusterStatusResponse) response.getEntity();
assertEquals(HOST_STORE_LAGS, clusterStatusResponse.getClusterStatus().get(HOST1_ENTITY).getHostStoreLags());
assertEquals(EMPTY_HOST_STORE_LAGS, clusterStatusResponse.getClusterStatus().get(HOST2_ENTITY).getHostStoreLags());
}
use of io.confluent.ksql.rest.entity.ClusterStatusResponse in project ksql by confluentinc.
the class HighAvailabilityTestUtil method waitForStreamsMetadataToInitialize.
static void waitForStreamsMetadataToInitialize(final TestKsqlRestApp restApp, List<KsqlHostInfoEntity> hosts, final Optional<BasicCredentials> credentials) {
while (true) {
ClusterStatusResponse clusterStatusResponse = HighAvailabilityTestUtil.sendClusterStatusRequest(restApp, credentials);
List<KsqlHostInfoEntity> initialized = hosts.stream().filter(hostInfo -> Optional.ofNullable(clusterStatusResponse.getClusterStatus().get(hostInfo)).map(hostStatusEntity -> hostStatusEntity.getActiveStandbyPerQuery().isEmpty()).isPresent()).collect(Collectors.toList());
if (initialized.size() == hosts.size())
break;
}
try {
Thread.sleep(200);
} catch (final Exception e) {
// Meh
}
}
use of io.confluent.ksql.rest.entity.ClusterStatusResponse in project ksql by confluentinc.
the class LagReportingAgentFunctionalTest method shouldExchangeLags.
@Test(timeout = 60000)
public void shouldExchangeLags() {
// Given:
waitForClusterCondition(LagReportingAgentFunctionalTest::allServersDiscovered);
// When:
ClusterStatusResponse resp = waitForClusterCondition(LagReportingAgentFunctionalTest::allLagsReported);
StateStoreLags stateStoreLags = resp.getClusterStatus().entrySet().iterator().next().getValue().getHostStoreLags().getStateStoreLags(STORE_0).get();
// Then:
// Read the raw Kafka data from the topic to verify the reported lags
final List<ConsumerRecord<byte[], byte[]>> records = TEST_HARNESS.verifyAvailableRecords("_confluent-ksql-default_query_CTAS_USER_VIEWS_3-" + "Aggregate-Aggregate-Materialize-changelog", NUM_ROWS);
Map<Integer, Optional<ConsumerRecord<byte[], byte[]>>> partitionToMaxOffset = records.stream().collect(Collectors.groupingBy(ConsumerRecord::partition, Collectors.maxBy(Comparator.comparingLong(ConsumerRecord::offset))));
Assert.assertEquals(2, partitionToMaxOffset.size());
Optional<LagInfoEntity> lagInfoEntity0 = stateStoreLags.getLagByPartition(0);
Optional<LagInfoEntity> lagInfoEntity1 = stateStoreLags.getLagByPartition(1);
long partition0Offset = lagInfoEntity0.get().getCurrentOffsetPosition();
long partition1Offset = lagInfoEntity1.get().getCurrentOffsetPosition();
Assert.assertEquals(partition0Offset, partitionToMaxOffset.get(0).get().offset() + 1);
Assert.assertEquals(partition1Offset, partitionToMaxOffset.get(1).get().offset() + 1);
}
use of io.confluent.ksql.rest.entity.ClusterStatusResponse in project ksql by confluentinc.
the class HeartbeatAgentFunctionalTest method shouldMarkRemoteServerAsDown.
@Test(timeout = 60000)
public void shouldMarkRemoteServerAsDown() {
// Given:
waitForClusterToBeDiscovered(REST_APP_0, 2);
// When:
ClusterStatusResponse clusterStatusResponse = waitForRemoteServerToChangeStatus(REST_APP_0, host1, HighAvailabilityTestUtil::remoteServerIsDown);
// Then:
assertThat(clusterStatusResponse.getClusterStatus().get(host0).getHostAlive(), is(true));
assertThat(clusterStatusResponse.getClusterStatus().get(host1).getHostAlive(), is(false));
}
use of io.confluent.ksql.rest.entity.ClusterStatusResponse in project ksql by confluentinc.
the class HeartbeatAgentFunctionalTest method shouldMarkServersAsUp.
@Test(timeout = 60000)
public void shouldMarkServersAsUp() {
// Given:
waitForClusterToBeDiscovered(REST_APP_0, 2);
waitForRemoteServerToChangeStatus(REST_APP_0, host1, HighAvailabilityTestUtil::remoteServerIsDown);
// When:
sendHeartbeartsForWindowLength(REST_APP_0, host1, 3000);
final ClusterStatusResponse clusterStatusResponseUp = waitForRemoteServerToChangeStatus(REST_APP_0, host1, HighAvailabilityTestUtil::remoteServerIsUp);
// Then:
assertThat(clusterStatusResponseUp.getClusterStatus().get(host0).getHostAlive(), is(true));
assertThat(clusterStatusResponseUp.getClusterStatus().get(host1).getHostAlive(), is(true));
}
Aggregations