Search in sources :

Example 1 with NakadiTestUtils.createSubscription

use of org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription 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();
}
Also used : TestStreamingClient(org.zalando.nakadi.webservice.utils.TestStreamingClient) NakadiTestUtils.createEventType(org.zalando.nakadi.webservice.utils.NakadiTestUtils.createEventType) EventType(org.zalando.nakadi.domain.EventType) SubscriptionEventTypeStats(org.zalando.nakadi.domain.SubscriptionEventTypeStats) Subscription(org.zalando.nakadi.domain.Subscription) NakadiTestUtils.createSubscription(org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription) StringContains(org.hamcrest.core.StringContains) Test(org.junit.Test)

Aggregations

StringContains (org.hamcrest.core.StringContains)1 Test (org.junit.Test)1 EventType (org.zalando.nakadi.domain.EventType)1 Subscription (org.zalando.nakadi.domain.Subscription)1 SubscriptionEventTypeStats (org.zalando.nakadi.domain.SubscriptionEventTypeStats)1 NakadiTestUtils.createEventType (org.zalando.nakadi.webservice.utils.NakadiTestUtils.createEventType)1 NakadiTestUtils.createSubscription (org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription)1 TestStreamingClient (org.zalando.nakadi.webservice.utils.TestStreamingClient)1