use of org.zalando.nakadi.webservice.utils.TestStreamingClient in project nakadi by zalando.
the class HilaAT method whenNoEventsThenFirstOffsetIsBEGIN.
@Test(timeout = 5000)
public void whenNoEventsThenFirstOffsetIsBEGIN() {
final TestStreamingClient client = TestStreamingClient.create(URL, subscription.getId(), "batch_flush_timeout=1").start();
waitFor(() -> assertThat(client.getBatches(), not(empty())));
assertThat(client.getBatches().get(0).getCursor().getOffset(), equalTo("001-0001--1"));
}
use of org.zalando.nakadi.webservice.utils.TestStreamingClient in project nakadi by zalando.
the class HilaAT method whenOffsetIsCommittedNextSessionStartsFromNextEventAfterCommitted.
@Test(timeout = 30000)
public void whenOffsetIsCommittedNextSessionStartsFromNextEventAfterCommitted() throws Exception {
// write 4 events to event-type
publishEvents(eventType.getName(), 4, x -> "{\"foo\":\"bar" + x + "\"}");
// create session, read from subscription and wait for events to be sent
final TestStreamingClient client = TestStreamingClient.create(URL, subscription.getId(), "stream_limit=2").start();
waitFor(() -> assertThat(client.getBatches(), hasSize(2)));
assertThat(client.getBatches().get(0), equalToBatchIgnoringToken(singleEventBatch("0", "001-0001-000000000000000000", eventType.getName(), ImmutableMap.of("foo", "bar0"), "Stream started")));
assertThat(client.getBatches().get(1), equalToBatchIgnoringToken(singleEventBatch("0", "001-0001-000000000000000001", eventType.getName(), ImmutableMap.of("foo", "bar1"))));
// commit offset that will also trigger session closing as we reached stream_limit and committed
commitCursors(subscription.getId(), ImmutableList.of(client.getBatches().get(1).getCursor()), client.getSessionId());
waitFor(() -> assertThat(client.isRunning(), is(false)));
// create new session and read from subscription again
client.start();
waitFor(() -> assertThat(client.getBatches(), hasSize(2)));
// check that we have read the next two events with correct offsets
assertThat(client.getBatches().get(0), equalToBatchIgnoringToken(singleEventBatch("0", "001-0001-000000000000000002", eventType.getName(), ImmutableMap.of("foo", "bar2"), "Stream started")));
assertThat(client.getBatches().get(1), equalToBatchIgnoringToken(singleEventBatch("0", "001-0001-000000000000000003", eventType.getName(), ImmutableMap.of("foo", "bar3"))));
}
use of org.zalando.nakadi.webservice.utils.TestStreamingClient in project nakadi by zalando.
the class HilaAT method testSubscriptionStatsMultiET.
@Test
public void testSubscriptionStatsMultiET() throws IOException {
final List<EventType> eventTypes = Lists.newArrayList(createEventType(), createEventType());
publishEvents(eventTypes.get(0).getName(), 10, i -> "{\"foo\":\"bar\"}");
publishEvents(eventTypes.get(1).getName(), 20, i -> "{\"foo\":\"bar\"}");
final Subscription subscription = NakadiTestUtils.createSubscription(RandomSubscriptionBuilder.builder().withEventTypes(eventTypes.stream().map(EventType::getName).collect(Collectors.toSet())).withStartFrom(END).build());
// client is needed only to initialize stats
final TestStreamingClient client = TestStreamingClient.create(URL, subscription.getId(), "batch_flush_timeout=1").start();
waitFor(() -> assertThat(client.getBatches().isEmpty(), is(false)));
publishEvents(eventTypes.get(0).getName(), 1, i -> "{\"foo\":\"bar\"}");
publishEvents(eventTypes.get(1).getName(), 2, i -> "{\"foo\":\"bar\"}");
NakadiTestUtils.getSubscriptionStat(subscription).then().content(new StringContains(JSON_TEST_HELPER.asJsonString(new SubscriptionEventTypeStats(eventTypes.get(0).getName(), Collections.singletonList(new SubscriptionEventTypeStats.Partition("0", "assigned", 1L, client.getSessionId(), AUTO)))))).content(new StringContains(JSON_TEST_HELPER.asJsonString(new SubscriptionEventTypeStats(eventTypes.get(1).getName(), Collections.singletonList(new SubscriptionEventTypeStats.Partition("0", "assigned", 2L, client.getSessionId(), AUTO))))));
client.close();
}
use of org.zalando.nakadi.webservice.utils.TestStreamingClient in project nakadi by zalando.
the class HilaAT method whenCommitVeryFirstEventThenOk.
@Test(timeout = 5000)
public void whenCommitVeryFirstEventThenOk() throws Exception {
publishEvent(eventType.getName(), "{\"foo\":\"bar\"}");
// create session, read from subscription and wait for events to be sent
final TestStreamingClient client = TestStreamingClient.create(subscription.getId()).start();
waitFor(() -> assertThat(client.getBatches(), not(empty())));
// commit and check that status is 204
final int commitResult = commitCursors(subscription.getId(), ImmutableList.of(new SubscriptionCursor("0", "0", eventType.getName(), "token")), client.getSessionId());
assertThat(commitResult, equalTo(SC_NO_CONTENT));
}
use of org.zalando.nakadi.webservice.utils.TestStreamingClient in project nakadi by zalando.
the class HilaAT method testGetSubscriptionStatWhenDirectAssignment.
@Test(timeout = 10000)
public void testGetSubscriptionStatWhenDirectAssignment() throws Exception {
// connect with 1 stream directly requesting the partition
final TestStreamingClient client = new TestStreamingClient(URL, subscription.getId(), "", Optional.empty(), Optional.of("{\"partitions\":[" + "{\"event_type\":\"" + eventType.getName() + "\",\"partition\":\"0\"}]}"));
client.start();
// wait for rebalance to finish
waitFor(() -> assertThat(getNumberOfAssignedStreams(subscription.getId()), Matchers.is(1)));
NakadiTestUtils.getSubscriptionStat(subscription).then().content(new StringContains(JSON_TEST_HELPER.asJsonString(new SubscriptionEventTypeStats(eventType.getName(), Collections.singletonList(new SubscriptionEventTypeStats.Partition("0", "assigned", 0L, client.getSessionId(), DIRECT))))));
}
Aggregations