Search in sources :

Example 21 with KsqlHostInfoEntity

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

the class PullQueryRoutingFunctionalTest method shouldQueryActiveWhenActiveAliveStandbyDeadQueryIssuedToRouter.

@Test
public void shouldQueryActiveWhenActiveAliveStandbyDeadQueryIssuedToRouter() {
    // Given:
    ClusterFormation clusterFormation = findClusterFormation(TEST_APP_0, TEST_APP_1, TEST_APP_2);
    waitForClusterToBeDiscovered(clusterFormation.router.getApp(), 3, USER_CREDS);
    waitForRemoteServerToChangeStatus(clusterFormation.router.getApp(), clusterFormation.router.getHost(), HighAvailabilityTestUtil.lagsReported(3), USER_CREDS);
    // Partition off the standby
    clusterFormation.standBy.getShutoffs().shutOffAll();
    waitForRemoteServerToChangeStatus(clusterFormation.router.getApp(), clusterFormation.active.getHost(), HighAvailabilityTestUtil::remoteServerIsUp, USER_CREDS);
    waitForRemoteServerToChangeStatus(clusterFormation.router.getApp(), clusterFormation.standBy.getHost(), HighAvailabilityTestUtil::remoteServerIsDown, USER_CREDS);
    // When:
    final List<StreamedRow> rows_0 = makePullQueryRequest(clusterFormation.router.getApp(), sql, null, USER_CREDS);
    // Then:
    assertThat(rows_0, hasSize(HEADER + 1));
    KsqlHostInfoEntity host = rows_0.get(1).getSourceHost().get();
    assertThat(host.getHost(), is(clusterFormation.active.getHost().getHost()));
    assertThat(host.getPort(), is(clusterFormation.active.getHost().getPort()));
    assertThat(rows_0.get(1).getRow(), is(not(Optional.empty())));
    assertThat(rows_0.get(1).getRow().get().getColumns(), is(ImmutableList.of(KEY, 1)));
}
Also used : StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Example 22 with KsqlHostInfoEntity

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

the class PullQueryRoutingFunctionalTest method shouldQueryActiveWhenActiveAliveQueryIssuedToStandby.

@Test
public void shouldQueryActiveWhenActiveAliveQueryIssuedToStandby() throws Exception {
    // Given:
    ClusterFormation clusterFormation = findClusterFormation(TEST_APP_0, TEST_APP_1, TEST_APP_2);
    waitForClusterToBeDiscovered(clusterFormation.standBy.getApp(), 3, USER_CREDS);
    waitForRemoteServerToChangeStatus(clusterFormation.router.getApp(), clusterFormation.router.getHost(), HighAvailabilityTestUtil.lagsReported(3), USER_CREDS);
    waitForRemoteServerToChangeStatus(clusterFormation.standBy.getApp(), clusterFormation.active.getHost(), HighAvailabilityTestUtil::remoteServerIsUp, USER_CREDS);
    // When:
    List<StreamedRow> rows_0 = makePullQueryRequest(clusterFormation.standBy.getApp(), sql, null, USER_CREDS);
    // Then:
    assertThat(rows_0, hasSize(HEADER + 1));
    KsqlHostInfoEntity host = rows_0.get(1).getSourceHost().get();
    assertThat(host.getHost(), is(clusterFormation.active.getHost().getHost()));
    assertThat(host.getPort(), is(clusterFormation.active.getHost().getPort()));
    assertThat(rows_0.get(1).getRow(), is(not(Optional.empty())));
    assertThat(rows_0.get(1).getRow().get().getColumns(), is(ImmutableList.of(KEY, 1)));
}
Also used : StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Example 23 with KsqlHostInfoEntity

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

the class PullQueryRoutingFunctionalTest method shouldFilterLaggyServers.

@Test
public void shouldFilterLaggyServers() throws Exception {
    // Given:
    ClusterFormation clusterFormation = findClusterFormation(TEST_APP_0, TEST_APP_1, TEST_APP_2);
    waitForClusterToBeDiscovered(clusterFormation.router.getApp(), 3, USER_CREDS);
    waitForRemoteServerToChangeStatus(clusterFormation.router.getApp(), clusterFormation.router.getHost(), HighAvailabilityTestUtil.lagsReported(3), USER_CREDS);
    waitForRemoteServerToChangeStatus(clusterFormation.router.getApp(), clusterFormation.active.getHost(), HighAvailabilityTestUtil::remoteServerIsUp, USER_CREDS);
    waitForRemoteServerToChangeStatus(clusterFormation.router.getApp(), clusterFormation.standBy.getHost(), HighAvailabilityTestUtil::remoteServerIsUp, USER_CREDS);
    waitForRemoteServerToChangeStatus(clusterFormation.router.getApp(), clusterFormation.router.getHost(), HighAvailabilityTestUtil.lagsReported(clusterFormation.standBy.getHost(), Optional.of(5L), 5), USER_CREDS);
    // Cut off standby from Kafka to simulate lag
    clusterFormation.standBy.getShutoffs().setKafkaPauseOffset(0);
    Thread.sleep(2000);
    // Produce more data that will now only be available on active since standby is cut off
    TEST_HARNESS.produceRows(topic, USER_PROVIDER, FormatFactory.KAFKA, FormatFactory.JSON, timestampSupplier::getAndIncrement);
    // Make sure that the lags get reported before we kill active
    waitForRemoteServerToChangeStatus(clusterFormation.router.getApp(), clusterFormation.router.getHost(), HighAvailabilityTestUtil.lagsReported(clusterFormation.active.getHost(), Optional.of(10L), 10), USER_CREDS);
    // Partition active off
    clusterFormation.active.getShutoffs().shutOffAll();
    waitForRemoteServerToChangeStatus(clusterFormation.router.getApp(), clusterFormation.standBy.getHost(), HighAvailabilityTestUtil::remoteServerIsUp, USER_CREDS);
    waitForRemoteServerToChangeStatus(clusterFormation.router.getApp(), clusterFormation.active.getHost(), HighAvailabilityTestUtil::remoteServerIsDown, USER_CREDS);
    // When:
    final List<StreamedRow> rows_0 = makePullQueryRequest(clusterFormation.router.getApp(), sql, LAG_FILTER_6, USER_CREDS);
    // Then:
    assertThat(rows_0, hasSize(HEADER + 1));
    KsqlHostInfoEntity host = rows_0.get(1).getSourceHost().get();
    assertThat(host.getHost(), is(clusterFormation.standBy.getHost().getHost()));
    assertThat(host.getPort(), is(clusterFormation.standBy.getHost().getPort()));
    assertThat(rows_0.get(1).getRow(), is(not(Optional.empty())));
    // This line ensures that we've not processed the new data
    assertThat(rows_0.get(1).getRow().get().getColumns(), is(ImmutableList.of(KEY, 1)));
    KsqlErrorMessage errorMessage = makePullQueryRequestWithError(clusterFormation.router.getApp(), sql, LAG_FILTER_3);
    Assert.assertEquals(40001, errorMessage.getErrorCode());
    assertThat(errorMessage.getMessage(), containsString("Partition 0 failed to find valid host."));
    assertThat(errorMessage.getMessage(), containsString("was not selected because Host is not alive as of "));
    assertThat(errorMessage.getMessage(), containsString("was not selected because Host excluded because lag 5 exceeds maximum allowed lag 3"));
}
Also used : StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) IntegrationTest(io.confluent.common.utils.IntegrationTest) Test(org.junit.Test)

Aggregations

KsqlHostInfoEntity (io.confluent.ksql.rest.entity.KsqlHostInfoEntity)23 Test (org.junit.Test)17 StreamedRow (io.confluent.ksql.rest.entity.StreamedRow)9 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)7 IntegrationTest (io.confluent.common.utils.IntegrationTest)6 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)6 QueryDescriptionList (io.confluent.ksql.rest.entity.QueryDescriptionList)6 KsqlQueryStatus (io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 QueryDescription (io.confluent.ksql.rest.entity.QueryDescription)5 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)5 Map (java.util.Map)5 Optional (java.util.Optional)5 ListQueries (io.confluent.ksql.parser.tree.ListQueries)4 ClusterStatusResponse (io.confluent.ksql.rest.entity.ClusterStatusResponse)4 HeartbeatResponse (io.confluent.ksql.rest.entity.HeartbeatResponse)4 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 ImmutableList (com.google.common.collect.ImmutableList)3