Search in sources :

Example 1 with PushConnectionsHandle

use of io.confluent.ksql.physical.scalablepush.PushRouting.PushConnectionsHandle in project ksql by confluentinc.

the class PushRoutingTest method shouldFail_duringPlanExecute.

@Test
public void shouldFail_duringPlanExecute() throws ExecutionException, InterruptedException {
    // Given:
    when(pushRoutingOptions.getHasBeenForwarded()).thenReturn(true);
    final PushRouting routing = new PushRouting();
    when(pushPhysicalPlanManager.execute()).thenThrow(new RuntimeException("Error!"));
    // When:
    final PushConnectionsHandle handle = handlePushRouting(routing);
    // Then:
    assertThat(handle.getError().getMessage(), containsString("Error!"));
}
Also used : PushConnectionsHandle(io.confluent.ksql.physical.scalablepush.PushRouting.PushConnectionsHandle) Test(org.junit.Test)

Example 2 with PushConnectionsHandle

use of io.confluent.ksql.physical.scalablepush.PushRouting.PushConnectionsHandle in project ksql by confluentinc.

the class PushRoutingTest method shouldFail_hitRequestLimitLocal.

@Test
public void shouldFail_hitRequestLimitLocal() throws ExecutionException, InterruptedException {
    // Given:
    transientQueryQueue = new TransientQueryQueue(OptionalInt.empty(), 1, 100);
    when(pushRoutingOptions.getHasBeenForwarded()).thenReturn(true);
    final PushRouting routing = new PushRouting();
    BufferedPublisher<QueryRow> localPublisher = new BufferedPublisher<>(context);
    when(pushPhysicalPlanManager.execute()).thenReturn(localPublisher);
    // When:
    final PushConnectionsHandle handle = handlePushRouting(routing);
    context.runOnContext(v -> {
        localPublisher.accept(LOCAL_ROW1);
        localPublisher.accept(LOCAL_ROW2);
    });
    // Then:
    Set<List<?>> rows = waitOnRows(1);
    handle.close();
    assertThat(rows.contains(LOCAL_ROW1.value().values()), is(true));
    assertThat(handle.getError().getMessage(), containsString("Hit limit of request queue"));
}
Also used : QueryRow(io.confluent.ksql.physical.common.QueryRow) BufferedPublisher(io.confluent.ksql.reactive.BufferedPublisher) TransientQueryQueue(io.confluent.ksql.query.TransientQueryQueue) PushConnectionsHandle(io.confluent.ksql.physical.scalablepush.PushRouting.PushConnectionsHandle) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test)

Example 3 with PushConnectionsHandle

use of io.confluent.ksql.physical.scalablepush.PushRouting.PushConnectionsHandle in project ksql by confluentinc.

the class PushRoutingTest method shouldSucceed_remoteNodeComplete.

@Test
public void shouldSucceed_remoteNodeComplete() throws ExecutionException, InterruptedException {
    // Given:
    final AtomicReference<Set<KsqlNode>> nodes = new AtomicReference<>(ImmutableSet.of(ksqlNodeLocal, ksqlNodeRemote));
    final PushRouting routing = new PushRouting(sqr -> nodes.get(), 50, false);
    // When:
    final PushConnectionsHandle handle = handlePushRouting(routing);
    context.runOnContext(v -> {
        localPublisher.accept(LOCAL_ROW1);
        localPublisher.accept(LOCAL_ROW2);
        remotePublisher.accept(REMOTE_ROW1);
        remotePublisher.accept(REMOTE_ROW2);
        remotePublisher.complete();
    });
    Set<List<?>> rows = waitOnRows(4);
    waitOnNodeStatus(handle, ksqlNodeRemote, RoutingResultStatus.COMPLETE);
    handle.close();
    // Then:
    assertThat(rows.contains(LOCAL_ROW1.value().values()), is(true));
    assertThat(rows.contains(LOCAL_ROW2.value().values()), is(true));
    assertThat(rows.contains(REMOTE_ROW1.getRow().get().getColumns()), is(true));
    assertThat(rows.contains(REMOTE_ROW2.getRow().get().getColumns()), is(true));
    assertThat(handle.get(ksqlNodeRemote).get().getStatus(), is(RoutingResultStatus.COMPLETE));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashSet(java.util.HashSet) PushConnectionsHandle(io.confluent.ksql.physical.scalablepush.PushRouting.PushConnectionsHandle) AtomicReference(java.util.concurrent.atomic.AtomicReference) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test)

Example 4 with PushConnectionsHandle

use of io.confluent.ksql.physical.scalablepush.PushRouting.PushConnectionsHandle in project ksql by confluentinc.

the class PushRoutingTest method shouldSucceed_addRemoteNode.

@Test
public void shouldSucceed_addRemoteNode() throws ExecutionException, InterruptedException {
    // Given:
    final AtomicReference<Set<KsqlNode>> nodes = new AtomicReference<>(ImmutableSet.of(ksqlNodeLocal));
    final PushRouting routing = new PushRouting(sqr -> nodes.get(), 50, true);
    // When:
    final PushConnectionsHandle handle = handlePushRouting(routing);
    context.runOnContext(v -> {
        localPublisher.accept(LOCAL_ROW1);
        localPublisher.accept(LOCAL_ROW2);
    });
    Set<List<?>> rows = waitOnRows(2);
    nodes.set(ImmutableSet.of(ksqlNodeLocal, ksqlNodeRemote));
    context.runOnContext(v -> {
        remotePublisher.accept(REMOTE_ROW1);
        remotePublisher.accept(REMOTE_ROW2);
    });
    // Then:
    rows.addAll(waitOnRows(2));
    handle.close();
    assertThat(rows.contains(LOCAL_ROW1.value().values()), is(true));
    assertThat(rows.contains(LOCAL_ROW2.value().values()), is(true));
    assertThat(rows.contains(REMOTE_ROW1.getRow().get().getColumns()), is(true));
    assertThat(rows.contains(REMOTE_ROW2.getRow().get().getColumns()), is(true));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashSet(java.util.HashSet) PushConnectionsHandle(io.confluent.ksql.physical.scalablepush.PushRouting.PushConnectionsHandle) AtomicReference(java.util.concurrent.atomic.AtomicReference) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test)

Example 5 with PushConnectionsHandle

use of io.confluent.ksql.physical.scalablepush.PushRouting.PushConnectionsHandle in project ksql by confluentinc.

the class PushRoutingTest method shouldFail_non200RemoteCall.

@Test
public void shouldFail_non200RemoteCall() throws ExecutionException, InterruptedException {
    // Given:
    when(locator.locate()).thenReturn(ImmutableList.of(ksqlNodeRemote));
    final PushRouting routing = new PushRouting();
    when(simpleKsqlClient.makeQueryRequestStreamed(any(), any(), any(), any())).thenReturn(createFuture(RestResponse.erroneous(500, "Error response!")));
    // When:
    final PushConnectionsHandle handle = handlePushRouting(routing);
    // Then:
    assertThat(handle.getError().getMessage(), containsString("Error response!"));
}
Also used : PushConnectionsHandle(io.confluent.ksql.physical.scalablepush.PushRouting.PushConnectionsHandle) Test(org.junit.Test)

Aggregations

PushConnectionsHandle (io.confluent.ksql.physical.scalablepush.PushRouting.PushConnectionsHandle)18 Test (org.junit.Test)18 ImmutableList (com.google.common.collect.ImmutableList)14 List (java.util.List)14 ImmutableSet (com.google.common.collect.ImmutableSet)11 HashSet (java.util.HashSet)11 Set (java.util.Set)11 AtomicReference (java.util.concurrent.atomic.AtomicReference)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 PushOffsetRange (io.confluent.ksql.util.PushOffsetRange)3 TransientQueryQueue (io.confluent.ksql.query.TransientQueryQueue)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 QueryRow (io.confluent.ksql.physical.common.QueryRow)1 RoutingResult (io.confluent.ksql.physical.scalablepush.PushRouting.RoutingResult)1 BufferedPublisher (io.confluent.ksql.reactive.BufferedPublisher)1