Search in sources :

Example 1 with PartitionLocation

use of io.confluent.ksql.execution.streams.materialization.ks.KsLocator.PartitionLocation in project ksql by confluentinc.

the class HARoutingTest method shouldCallRouteQuery_couldNotFindHost.

@Test
public void shouldCallRouteQuery_couldNotFindHost() {
    // Given:
    location1 = new PartitionLocation(Optional.empty(), 1, ImmutableList.of());
    locate(location1, location2, location3, location4);
    // When:
    final Exception e = assertThrows(MaterializationException.class, () -> haRouting.handlePullQuery(serviceContext, pullPhysicalPlan, statement, routingOptions, logicalSchema, queryId, pullQueryQueue, disconnect, Optional.empty()));
    // Then:
    assertThat(e.getMessage(), containsString("Unable to execute pull query. " + "[Partition 1 failed to find valid host. Hosts scanned: []]"));
    final double fetch_count = getMetricValue("-partition-fetch-count");
    final double resubmission_count = getMetricValue("-partition-fetch-resubmission-count");
    assertThat(fetch_count, is(0.0));
    assertThat(resubmission_count, is(0.0));
}
Also used : PartitionLocation(io.confluent.ksql.execution.streams.materialization.ks.KsLocator.PartitionLocation) KsqlPartitionLocation(io.confluent.ksql.execution.streams.materialization.Locator.KsqlPartitionLocation) MaterializationException(io.confluent.ksql.execution.streams.materialization.MaterializationException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 2 with PartitionLocation

use of io.confluent.ksql.execution.streams.materialization.ks.KsLocator.PartitionLocation in project ksql by confluentinc.

the class HARoutingTest method shouldNotRouteToFilteredHost.

@Test
public void shouldNotRouteToFilteredHost() throws InterruptedException, ExecutionException {
    // Given:
    location1 = new PartitionLocation(Optional.empty(), 1, ImmutableList.of(badNode, node1));
    when(ksqlClient.makeQueryRequest(any(), any(), any(), any(), any(), any())).then(invocationOnMock -> RestResponse.successful(200, 2));
    locate(location1, location2, location3, location4);
    // When:
    final CompletableFuture<Void> fut = haRouting.handlePullQuery(serviceContext, pullPhysicalPlan, statement, routingOptions, logicalSchema, queryId, pullQueryQueue, disconnect, Optional.empty());
    fut.get();
    // Then:
    verify(ksqlClient, never()).makeQueryRequest(eq(badNode.location()), any(), any(), any(), any(), any());
    final double fetch_count = getMetricValue("-partition-fetch-count");
    final double resubmission_count = getMetricValue("-partition-fetch-resubmission-count");
    assertThat(fetch_count, is(4.0));
    assertThat(resubmission_count, is(0.0));
}
Also used : PartitionLocation(io.confluent.ksql.execution.streams.materialization.ks.KsLocator.PartitionLocation) KsqlPartitionLocation(io.confluent.ksql.execution.streams.materialization.Locator.KsqlPartitionLocation) Test(org.junit.Test)

Example 3 with PartitionLocation

use of io.confluent.ksql.execution.streams.materialization.ks.KsLocator.PartitionLocation in project ksql by confluentinc.

the class HARoutingTest method shouldCallRouteQuery_allFilteredWithCause.

@Test
public void shouldCallRouteQuery_allFilteredWithCause() {
    // Given:
    location1 = new PartitionLocation(Optional.empty(), 1, ImmutableList.of(badNode));
    locate(location1, location2, location3, location4);
    // When:
    final Exception e = assertThrows(MaterializationException.class, () -> haRouting.handlePullQuery(serviceContext, pullPhysicalPlan, statement, routingOptions, logicalSchema, queryId, pullQueryQueue, disconnect, Optional.empty()));
    // Then:
    assertThat(e.getMessage(), containsString("Hosts scanned: [badnode:8090 was not selected because BAD]]"));
    final double fetch_count = getMetricValue("-partition-fetch-count");
    final double resubmission_count = getMetricValue("-partition-fetch-resubmission-count");
    assertThat(fetch_count, is(0.0));
    assertThat(resubmission_count, is(0.0));
}
Also used : PartitionLocation(io.confluent.ksql.execution.streams.materialization.ks.KsLocator.PartitionLocation) KsqlPartitionLocation(io.confluent.ksql.execution.streams.materialization.Locator.KsqlPartitionLocation) MaterializationException(io.confluent.ksql.execution.streams.materialization.MaterializationException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 4 with PartitionLocation

use of io.confluent.ksql.execution.streams.materialization.ks.KsLocator.PartitionLocation in project ksql by confluentinc.

the class HARoutingTest method setUp.

@Before
public void setUp() {
    when(pullPhysicalPlan.getMaterialization()).thenReturn(materialization);
    when(pullPhysicalPlan.getMaterialization().locator()).thenReturn(locator);
    when(statement.getStatementText()).thenReturn("foo");
    when(statement.getSessionConfig()).thenReturn(SessionConfig.of(ksqlConfig, ImmutableMap.of()));
    when(node1.isLocal()).thenReturn(true);
    when(node2.isLocal()).thenReturn(false);
    when(node1.location()).thenReturn(URI.create("http://node1:8088"));
    when(node2.location()).thenReturn(URI.create("http://node2:8089"));
    when(badNode.location()).thenReturn(URI.create("http://badnode:8090"));
    when(node1.getHost()).thenReturn(Host.include(new KsqlHostInfo("node1", 8088)));
    when(node2.getHost()).thenReturn(Host.include(new KsqlHostInfo("node2", 8089)));
    when(badNode.getHost()).thenReturn(Host.exclude(new KsqlHostInfo("badnode", 8090), "BAD"));
    location1 = new PartitionLocation(Optional.empty(), 1, ImmutableList.of(node1, node2));
    location2 = new PartitionLocation(Optional.empty(), 2, ImmutableList.of(node2, node1));
    location3 = new PartitionLocation(Optional.empty(), 3, ImmutableList.of(node1, node2));
    location4 = new PartitionLocation(Optional.empty(), 4, ImmutableList.of(node2, node1));
    location5 = new PartitionLocation(Optional.empty(), 4, ImmutableList.of(node2));
    // We require at least two threads, one for the orchestrator, and the other for the partitions.
    when(ksqlConfig.getInt(KsqlConfig.KSQL_QUERY_PULL_THREAD_POOL_SIZE_CONFIG)).thenReturn(1);
    when(ksqlConfig.getInt(KsqlConfig.KSQL_QUERY_PULL_ROUTER_THREAD_POOL_SIZE_CONFIG)).thenReturn(1);
    when(serviceContext.getKsqlClient()).thenReturn(ksqlClient);
    pullMetrics = new PullQueryExecutorMetrics(KSQL_SERVICE_ID, Collections.emptyMap(), time, new Metrics());
    haRouting = new HARouting(routingFilterFactory, Optional.of(pullMetrics), ksqlConfig);
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) PullQueryExecutorMetrics(io.confluent.ksql.internal.PullQueryExecutorMetrics) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) PullQueryExecutorMetrics(io.confluent.ksql.internal.PullQueryExecutorMetrics) PartitionLocation(io.confluent.ksql.execution.streams.materialization.ks.KsLocator.PartitionLocation) KsqlPartitionLocation(io.confluent.ksql.execution.streams.materialization.Locator.KsqlPartitionLocation) Before(org.junit.Before)

Aggregations

KsqlPartitionLocation (io.confluent.ksql.execution.streams.materialization.Locator.KsqlPartitionLocation)4 PartitionLocation (io.confluent.ksql.execution.streams.materialization.ks.KsLocator.PartitionLocation)4 Test (org.junit.Test)3 MaterializationException (io.confluent.ksql.execution.streams.materialization.MaterializationException)2 ExecutionException (java.util.concurrent.ExecutionException)2 PullQueryExecutorMetrics (io.confluent.ksql.internal.PullQueryExecutorMetrics)1 KsqlHostInfo (io.confluent.ksql.util.KsqlHostInfo)1 Metrics (org.apache.kafka.common.metrics.Metrics)1 Before (org.junit.Before)1