use of org.zalando.nakadi.webservice.utils.TestStreamingClient in project nakadi by zalando.
the class HilaAT method whenConsumerIsBlockedDuringConsumption.
@Test(timeout = 10000)
public void whenConsumerIsBlockedDuringConsumption() throws Exception {
publishEvents(eventType.getName(), 5, i -> "{\"foo\":\"bar\"}");
final TestStreamingClient client = TestStreamingClient.create(subscription.getId()).start();
waitFor(() -> assertThat(client.getBatches(), hasSize(5)));
SettingsControllerAT.blacklist(eventType.getName(), BlacklistService.Type.CONSUMER_ET);
waitFor(() -> assertThat(client.getBatches(), hasSize(6)));
Assert.assertEquals("Consumption is blocked", client.getBatches().get(client.getBatches().size() - 1).getMetadata().getDebug());
SettingsControllerAT.whitelist(eventType.getName(), BlacklistService.Type.CONSUMER_ET);
}
use of org.zalando.nakadi.webservice.utils.TestStreamingClient in project nakadi by zalando.
the class HilaAT method whenResetCursorsThenStreamFromResetCursorOffset.
@Test(timeout = 15000)
public void whenResetCursorsThenStreamFromResetCursorOffset() throws Exception {
publishEvents(eventType.getName(), 20, i -> "{\"foo\":\"bar\"}");
final TestStreamingClient client1 = TestStreamingClient.create(subscription.getId()).start();
waitFor(() -> assertThat(client1.getBatches(), hasSize(10)));
int statusCode = commitCursors(subscription.getId(), Collections.singletonList(client1.getBatches().get(9).getCursor()), client1.getSessionId());
Assert.assertEquals(SC_NO_CONTENT, statusCode);
final List<SubscriptionCursor> resetCursors = Collections.singletonList(client1.getBatches().get(4).getCursor());
statusCode = given().body(MAPPER.writeValueAsString(new ItemsWrapper<>(resetCursors))).contentType(JSON).patch("/subscriptions/{id}/cursors", subscription.getId()).getStatusCode();
Assert.assertEquals(SC_NO_CONTENT, statusCode);
Assert.assertFalse(client1.isRunning());
Assert.assertTrue(client1.getBatches().stream().anyMatch(streamBatch -> streamBatch.getMetadata() != null && streamBatch.getMetadata().getDebug().equals("Resetting subscription cursors")));
final TestStreamingClient client2 = TestStreamingClient.create(subscription.getId()).start();
waitFor(() -> assertThat(client2.getBatches(), hasSize(10)));
Assert.assertEquals("001-0001-000000000000000005", client2.getBatches().get(0).getCursor().getOffset());
}
use of org.zalando.nakadi.webservice.utils.TestStreamingClient in project nakadi by zalando.
the class HilaAT method whenWindowSizeIsSetItIsConsidered.
@Test(timeout = 15000)
public void whenWindowSizeIsSetItIsConsidered() throws Exception {
publishEvents(eventType.getName(), 15, i -> "{\"foo\":\"bar\"}");
final TestStreamingClient client = TestStreamingClient.create(URL, subscription.getId(), "max_uncommitted_events=5").start();
waitFor(() -> assertThat(client.getBatches(), hasSize(5)));
SubscriptionCursor cursorToCommit = client.getBatches().get(4).getCursor();
commitCursors(subscription.getId(), ImmutableList.of(cursorToCommit), client.getSessionId());
waitFor(() -> assertThat(client.getBatches(), hasSize(10)));
cursorToCommit = client.getBatches().get(6).getCursor();
commitCursors(subscription.getId(), ImmutableList.of(cursorToCommit), client.getSessionId());
waitFor(() -> assertThat(client.getBatches(), hasSize(12)));
}
use of org.zalando.nakadi.webservice.utils.TestStreamingClient in project nakadi by zalando.
the class HilaAT method whenStreamTimeoutReachedSessionIsClosed.
@Test(timeout = 15000)
public void whenStreamTimeoutReachedSessionIsClosed() throws Exception {
publishEvent(eventType.getName(), "{\"foo\":\"bar\"}");
final TestStreamingClient client = TestStreamingClient.create(URL, subscription.getId(), "stream_timeout=3").start();
waitFor(() -> assertThat(client.getBatches(), hasSize(1)));
// to check that stream_timeout works we need to commit everything we consumed, in other case
// Nakadi will first wait till commit_timeout exceeds
final SubscriptionCursor lastBatchCursor = client.getBatches().get(client.getBatches().size() - 1).getCursor();
commitCursors(subscription.getId(), ImmutableList.of(lastBatchCursor), client.getSessionId());
waitFor(() -> assertThat(client.isRunning(), is(false)), 5000);
}
use of org.zalando.nakadi.webservice.utils.TestStreamingClient in project nakadi by zalando.
the class HilaAT method whenCommitTimeoutReachedSessionIsClosed.
@Test(timeout = 15000)
public void whenCommitTimeoutReachedSessionIsClosed() {
publishEvent(eventType.getName(), "{\"foo\":\"bar\"}");
final TestStreamingClient client = TestStreamingClient.create(// commit_timeout is 5 seconds for test
subscription.getId()).start();
waitFor(() -> assertThat(client.getBatches(), hasSize(2)), 10000);
waitFor(() -> assertThat(client.isRunning(), is(false)), 10000);
assertThat(client.getBatches().get(1), equalToBatchIgnoringToken(singleEventBatch("0", "001-0001-000000000000000000", eventType.getName(), ImmutableMap.of(), "Commit timeout reached")));
}
Aggregations