use of org.zalando.nakadi.domain.SubscriptionBase.InitialPosition.BEGIN in project nakadi by zalando.
the class UserJourneyAT method userJourneyHila.
@Test(timeout = 15000)
public void userJourneyHila() throws InterruptedException, IOException {
postEvents(rangeClosed(0, 3).mapToObj(x -> "{\"foo\":\"bar" + x + "\"}").collect(Collectors.toList()).toArray(new String[4]));
// create subscription
final SubscriptionBase subscriptionToCreate = RandomSubscriptionBuilder.builder().withOwningApplication("stups_aruha-test-end2end-nakadi").withEventType(eventTypeName).withStartFrom(BEGIN).buildSubscriptionBase();
final Subscription subscription = createSubscription(jsonRequestSpec(), subscriptionToCreate);
// list subscriptions
jsonRequestSpec().param("event_type", eventTypeName).get("/subscriptions").then().statusCode(OK.value()).body("items.size()", equalTo(1)).body("items[0].id", equalTo(subscription.getId()));
// create client and wait till we receive all events
final TestStreamingClient client = new TestStreamingClient(RestAssured.baseURI + ":" + RestAssured.port, subscription.getId(), "", oauthToken).start();
waitFor(() -> assertThat(client.getBatches(), hasSize(4)));
final List<StreamBatch> batches = client.getBatches();
// validate the content of events
for (int i = 0; i < batches.size(); i++) {
final SubscriptionCursor cursor = new SubscriptionCursor("0", TestUtils.toTimelineOffset(i), eventTypeName, "");
final StreamBatch expectedBatch = new StreamBatch(cursor, ImmutableList.of(ImmutableMap.of("foo", "bar" + i)), i == 0 ? new StreamMetadata("Stream started") : null);
final StreamBatch batch = batches.get(i);
assertThat(batch, equalToBatchIgnoringToken(expectedBatch));
}
// as we didn't commit, there should be still 4 unconsumed events
jsonRequestSpec().get("/subscriptions/{sid}/stats", subscription.getId()).then().statusCode(OK.value()).body("items[0].partitions[0].unconsumed_events", equalTo(4));
// commit cursor of latest event
final StreamBatch lastBatch = batches.get(batches.size() - 1);
final int commitCode = commitCursors(jsonRequestSpec(), subscription.getId(), ImmutableList.of(lastBatch.getCursor()), client.getSessionId());
assertThat(commitCode, equalTo(NO_CONTENT.value()));
// now there should be 0 unconsumed events
jsonRequestSpec().get("/subscriptions/{sid}/stats", subscription.getId()).then().statusCode(OK.value()).body("items[0].partitions[0].unconsumed_events", equalTo(0));
// get cursors
jsonRequestSpec().get("/subscriptions/{sid}/cursors", subscription.getId()).then().statusCode(OK.value()).body("items[0].partition", equalTo("0")).body("items[0].offset", equalTo("001-0001-000000000000000003"));
// delete subscription
jsonRequestSpec().delete("/subscriptions/{sid}", subscription.getId()).then().statusCode(NO_CONTENT.value());
}
Aggregations