use of org.zalando.nakadi.webservice.utils.TestStreamingClient in project nakadi by zalando.
the class HilaRebalanceAT method whenDirectlyRequestPartitionsTheyAssignedCorrectly.
@Test(timeout = 15000)
public void whenDirectlyRequestPartitionsTheyAssignedCorrectly() throws IOException {
// publish 2 events to each partition
publishBusinessEventWithUserDefinedPartition(eventType.getName(), 16, x -> "blah" + x, x -> String.valueOf(x % 8));
// start a stream requesting to read from partitions 5, 6
final TestStreamingClient client = new TestStreamingClient(URL, subscription.getId(), "", Optional.empty(), Optional.of("{\"partitions\":[" + "{\"event_type\":\"" + eventType.getName() + "\",\"partition\":\"6\"}," + "{\"event_type\":\"" + eventType.getName() + "\",\"partition\":\"5\"}" + "]}"));
client.start();
// wait till we receive 4 batches (2 per partition)
waitFor(() -> assertThat(client.getBatches(), hasSize(4)));
// check that all batches are from partitions 5, 6
checkAllEventsAreFromPartitions(client, ImmutableSet.of("5", "6"));
}
use of org.zalando.nakadi.webservice.utils.TestStreamingClient in project nakadi by zalando.
the class HilaRebalanceAT method whenNotCommittedThenEventsAreReplayedAfterRebalance.
@Test(timeout = 15000)
public void whenNotCommittedThenEventsAreReplayedAfterRebalance() {
publishBusinessEventWithUserDefinedPartition(eventType.getName(), 2, x -> "blah" + x, x -> String.valueOf(x % 8));
final TestStreamingClient clientA = TestStreamingClient.create(URL, subscription.getId(), "").start();
waitFor(() -> assertThat(clientA.getBatches(), hasSize(2)));
final TestStreamingClient clientB = TestStreamingClient.create(URL, subscription.getId(), "").start();
// after commit_timeout of first client exceeds it is closed and all events are resent to second client
waitFor(() -> assertThat(clientB.getBatches(), hasSize(2)), 10000);
}
use of org.zalando.nakadi.webservice.utils.TestStreamingClient in project nakadi by zalando.
the class HilaRebalanceAT method whenNoFreeSlotsForAutoClientThenConflict.
@Test(timeout = 15000)
public void whenNoFreeSlotsForAutoClientThenConflict() throws IOException, InterruptedException {
// direct client reads all but one partition
final TestStreamingClient directClient = new TestStreamingClient(URL, subscription.getId(), "", Optional.empty(), Optional.of("{\"partitions\":[" + "{\"event_type\":\"" + eventType.getName() + "\",\"partition\":\"0\"}," + "{\"event_type\":\"" + eventType.getName() + "\",\"partition\":\"1\"}," + "{\"event_type\":\"" + eventType.getName() + "\",\"partition\":\"2\"}," + "{\"event_type\":\"" + eventType.getName() + "\",\"partition\":\"3\"}," + "{\"event_type\":\"" + eventType.getName() + "\",\"partition\":\"4\"}," + "{\"event_type\":\"" + eventType.getName() + "\",\"partition\":\"5\"}," + "{\"event_type\":\"" + eventType.getName() + "\",\"partition\":\"6\"}" + "]}"));
directClient.start();
waitFor(() -> assertThat(directClient.getResponseCode(), is(HttpStatus.OK.value())));
// first auto-balance client reads remaining partition
final TestStreamingClient autoClient1 = new TestStreamingClient(URL, subscription.getId(), "");
autoClient1.start();
waitFor(() -> assertThat(autoClient1.getResponseCode(), is(HttpStatus.OK.value())));
// second auto-balance client has nothing to read - should get 409 (Conflict) status code
final TestStreamingClient autoClient2 = new TestStreamingClient(URL, subscription.getId(), "");
autoClient2.start();
waitFor(() -> assertThat(autoClient2.getResponseCode(), is(HttpStatus.CONFLICT.value())));
}
use of org.zalando.nakadi.webservice.utils.TestStreamingClient in project nakadi by zalando.
the class SubscriptionAT method testOffsetsCommit.
@Test
public void testOffsetsCommit() throws Exception {
// create event type in Nakadi
final String etName = createEventType().getName();
final Subscription subscription = createSubscriptionForEventType(etName);
final TestStreamingClient client = TestStreamingClient.create(URL, subscription.getId(), "").start();
waitFor(() -> assertThat(client.getSessionId(), not(equalTo(SESSION_ID_UNKNOWN))));
String cursor = "{\"items\":[{\"partition\":\"0\",\"offset\":\"25\",\"event_type\":\"" + etName + "\",\"cursor_token\":\"abc\"}]}";
commitCursors(subscription, cursor, client.getSessionId()).then().statusCode(HttpStatus.SC_NO_CONTENT);
// check that offset is actually committed to Zookeeper
String committedOffset = getCommittedOffsetFromZk(etName, subscription, "0");
assertThat(committedOffset, equalTo(TestUtils.toTimelineOffset(25)));
// commit lower offsets and expect 200
cursor = "{\"items\":[{\"partition\":\"0\",\"offset\":\"10\",\"event_type\":\"" + etName + "\",\"cursor_token\":\"abc\"}]}";
commitCursors(subscription, cursor, client.getSessionId()).then().statusCode(HttpStatus.SC_OK);
// check that committed offset in Zookeeper is not changed
committedOffset = getCommittedOffsetFromZk(etName, subscription, "0");
assertThat(committedOffset, equalTo(TestUtils.toTimelineOffset(25)));
}
use of org.zalando.nakadi.webservice.utils.TestStreamingClient in project nakadi by zalando.
the class SubscriptionConsumptionTest method createParallelConsumer.
private static void createParallelConsumer(final Subscription subscription, final int expectedEvents, final CountDownLatch finished, final Consumer<String[]> inTimeCursors) throws InterruptedException {
final String params = Stream.of("batch_limit=1", "batch_flush_timeout=1", "stream_limit=" + expectedEvents, "stream_timeout=30").collect(Collectors.joining("&"));
final TestStreamingClient streamingClient = new TestStreamingClient(BaseAT.URL, subscription.getId(), params);
streamingClient.startWithAutocommit(batches -> {
inTimeCursors.accept(batchesToCursors(batches));
finished.countDown();
});
}
Aggregations