Search in sources :

Example 6 with TestStreamingClient

use of org.zalando.nakadi.webservice.utils.TestStreamingClient in project nakadi by zalando.

the class HilaAT method whenThereAreNoEmptySlotsThenConflict.

@Test(timeout = 10000)
public void whenThereAreNoEmptySlotsThenConflict() {
    final TestStreamingClient client = TestStreamingClient.create(URL, subscription.getId(), "batch_flush_timeout=1");
    client.start();
    waitFor(() -> assertThat(client.getBatches(), hasSize(1)));
    given().get(format("/subscriptions/{0}/events", subscription.getId())).then().statusCode(SC_CONFLICT);
}
Also used : TestStreamingClient(org.zalando.nakadi.webservice.utils.TestStreamingClient) Test(org.junit.Test)

Example 7 with TestStreamingClient

use of org.zalando.nakadi.webservice.utils.TestStreamingClient in project nakadi by zalando.

the class HilaAT method whenBatchLimitAndTimeoutAreSetTheyAreConsidered.

@Test(timeout = 10000)
public void whenBatchLimitAndTimeoutAreSetTheyAreConsidered() {
    publishEvents(eventType.getName(), 12, i -> "{\"foo\":\"bar\"}");
    final TestStreamingClient client = TestStreamingClient.create(URL, subscription.getId(), "batch_limit=5&batch_flush_timeout=1&max_uncommitted_events=20").start();
    waitFor(() -> assertThat(client.getBatches(), hasSize(3)));
    assertThat(client.getBatches().get(0).getEvents(), hasSize(5));
    assertThat(client.getBatches().get(0).getCursor().getOffset(), is("001-0001-000000000000000004"));
    assertThat(client.getBatches().get(1).getEvents(), hasSize(5));
    assertThat(client.getBatches().get(1).getCursor().getOffset(), is("001-0001-000000000000000009"));
    assertThat(client.getBatches().get(2).getEvents(), hasSize(2));
    assertThat(client.getBatches().get(2).getCursor().getOffset(), is("001-0001-000000000000000011"));
}
Also used : TestStreamingClient(org.zalando.nakadi.webservice.utils.TestStreamingClient) Test(org.junit.Test)

Example 8 with TestStreamingClient

use of org.zalando.nakadi.webservice.utils.TestStreamingClient in project nakadi by zalando.

the class HilaAT method whenConsumerIsBlocked403.

@Test(timeout = 10000)
public void whenConsumerIsBlocked403() throws Exception {
    SettingsControllerAT.blacklist(eventType.getName(), BlacklistService.Type.CONSUMER_ET);
    final TestStreamingClient client1 = TestStreamingClient.create(subscription.getId()).start();
    waitFor(() -> Assert.assertEquals(403, client1.getResponseCode()));
    SettingsControllerAT.whitelist(eventType.getName(), BlacklistService.Type.CONSUMER_ET);
    final TestStreamingClient client2 = TestStreamingClient.create(subscription.getId()).start();
    waitFor(() -> Assert.assertEquals(HttpStatus.SC_OK, client2.getResponseCode()));
}
Also used : TestStreamingClient(org.zalando.nakadi.webservice.utils.TestStreamingClient) Test(org.junit.Test)

Example 9 with TestStreamingClient

use of org.zalando.nakadi.webservice.utils.TestStreamingClient in project nakadi by zalando.

the class HilaAT method whenStreamTimeout0ThenInfiniteStreaming.

@Test(timeout = 15000)
public void whenStreamTimeout0ThenInfiniteStreaming() {
    publishEvents(eventType.getName(), 5, i -> "{\"foo\":\"bar\"}");
    final TestStreamingClient client = TestStreamingClient.create(URL, subscription.getId(), "stream_timeout=0").start();
    waitFor(() -> assertThat(client.getBatches(), hasSize(5)));
    Assert.assertFalse(client.getBatches().stream().anyMatch(streamBatch -> streamBatch.getMetadata() != null && streamBatch.getMetadata().getDebug().equals("Stream timeout reached")));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) NakadiTestUtils.createEventType(org.zalando.nakadi.webservice.utils.NakadiTestUtils.createEventType) NakadiTestUtils.getNumberOfAssignedStreams(org.zalando.nakadi.webservice.utils.NakadiTestUtils.getNumberOfAssignedStreams) NakadiTestUtils.publishEvent(org.zalando.nakadi.webservice.utils.NakadiTestUtils.publishEvent) RandomSubscriptionBuilder(org.zalando.nakadi.utils.RandomSubscriptionBuilder) Matchers.not(org.hamcrest.Matchers.not) HttpStatus(org.apache.http.HttpStatus) RestAssured.given(com.jayway.restassured.RestAssured.given) Subscription(org.zalando.nakadi.domain.Subscription) BaseAT(org.zalando.nakadi.webservice.BaseAT) AUTO(org.zalando.nakadi.domain.SubscriptionEventTypeStats.Partition.AssignmentType.AUTO) StringContains(org.hamcrest.core.StringContains) StreamBatch.singleEventBatch(org.zalando.nakadi.webservice.hila.StreamBatch.singleEventBatch) SubscriptionCursorWithoutToken(org.zalando.nakadi.view.SubscriptionCursorWithoutToken) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ImmutableMap(com.google.common.collect.ImmutableMap) JSON(com.jayway.restassured.http.ContentType.JSON) BlacklistService(org.zalando.nakadi.service.BlacklistService) Collectors(java.util.stream.Collectors) NakadiTestUtils.commitCursors(org.zalando.nakadi.webservice.utils.NakadiTestUtils.commitCursors) List(java.util.List) EventTypePartitionView(org.zalando.nakadi.view.EventTypePartitionView) SubscriptionBase(org.zalando.nakadi.domain.SubscriptionBase) Optional(java.util.Optional) SubscriptionCursor(org.zalando.nakadi.view.SubscriptionCursor) SettingsControllerAT(org.zalando.nakadi.webservice.SettingsControllerAT) SC_NO_CONTENT(org.apache.http.HttpStatus.SC_NO_CONTENT) BEGIN(org.zalando.nakadi.domain.SubscriptionBase.InitialPosition.BEGIN) SubscriptionEventTypeStats(org.zalando.nakadi.domain.SubscriptionEventTypeStats) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) JsonTestHelper(org.zalando.nakadi.utils.JsonTestHelper) Cursor(org.zalando.nakadi.view.Cursor) MessageFormat.format(java.text.MessageFormat.format) Lists(com.google.common.collect.Lists) JsonConfig(org.zalando.nakadi.config.JsonConfig) ImmutableList(com.google.common.collect.ImmutableList) NakadiTestUtils(org.zalando.nakadi.webservice.utils.NakadiTestUtils) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) END(org.zalando.nakadi.domain.SubscriptionBase.InitialPosition.END) NakadiTestUtils.createSubscription(org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription) Before(org.junit.Before) ItemsWrapper(org.zalando.nakadi.domain.ItemsWrapper) SESSION_ID_UNKNOWN(org.zalando.nakadi.webservice.utils.TestStreamingClient.SESSION_ID_UNKNOWN) EventType(org.zalando.nakadi.domain.EventType) Matchers.empty(org.hamcrest.Matchers.empty) RestAssured.when(com.jayway.restassured.RestAssured.when) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Matchers(org.hamcrest.Matchers) TestUtils.waitFor(org.zalando.nakadi.utils.TestUtils.waitFor) Test(org.junit.Test) IOException(java.io.IOException) DIRECT(org.zalando.nakadi.domain.SubscriptionEventTypeStats.Partition.AssignmentType.DIRECT) TimeUnit(java.util.concurrent.TimeUnit) SC_OK(org.apache.http.HttpStatus.SC_OK) MatcherIgnoringToken.equalToBatchIgnoringToken(org.zalando.nakadi.webservice.hila.StreamBatch.MatcherIgnoringToken.equalToBatchIgnoringToken) NakadiTestUtils.publishEvents(org.zalando.nakadi.webservice.utils.NakadiTestUtils.publishEvents) TestStreamingClient(org.zalando.nakadi.webservice.utils.TestStreamingClient) SC_CONFLICT(org.apache.http.HttpStatus.SC_CONFLICT) Assert(org.junit.Assert) Collections(java.util.Collections) TestStreamingClient(org.zalando.nakadi.webservice.utils.TestStreamingClient) Test(org.junit.Test)

Example 10 with TestStreamingClient

use of org.zalando.nakadi.webservice.utils.TestStreamingClient in project nakadi by zalando.

the class HilaAT method testGetSubscriptionStat.

@Test(timeout = 10000)
public void testGetSubscriptionStat() throws Exception {
    publishEvents(eventType.getName(), 15, i -> "{\"foo\":\"bar\"}");
    final TestStreamingClient client = TestStreamingClient.create(URL, subscription.getId(), "max_uncommitted_events=20").start();
    waitFor(() -> assertThat(client.getBatches(), hasSize(15)));
    List<SubscriptionEventTypeStats> subscriptionStats = Collections.singletonList(new SubscriptionEventTypeStats(eventType.getName(), Collections.singletonList(new SubscriptionEventTypeStats.Partition("0", "assigned", 15L, client.getSessionId(), AUTO))));
    NakadiTestUtils.getSubscriptionStat(subscription).then().content(new StringContains(JSON_TEST_HELPER.asJsonString(new ItemsWrapper<>(subscriptionStats))));
    final String partition = client.getBatches().get(0).getCursor().getPartition();
    final SubscriptionCursor cursor = new SubscriptionCursor(partition, "9", eventType.getName(), "token");
    commitCursors(subscription.getId(), ImmutableList.of(cursor), client.getSessionId());
    subscriptionStats = Collections.singletonList(new SubscriptionEventTypeStats(eventType.getName(), Collections.singletonList(new SubscriptionEventTypeStats.Partition("0", "assigned", 5L, client.getSessionId(), AUTO))));
    NakadiTestUtils.getSubscriptionStat(subscription).then().content(new StringContains(JSON_TEST_HELPER.asJsonString(new ItemsWrapper<>(subscriptionStats))));
}
Also used : SubscriptionCursor(org.zalando.nakadi.view.SubscriptionCursor) TestStreamingClient(org.zalando.nakadi.webservice.utils.TestStreamingClient) SubscriptionEventTypeStats(org.zalando.nakadi.domain.SubscriptionEventTypeStats) StringContains(org.hamcrest.core.StringContains) Test(org.junit.Test)

Aggregations

TestStreamingClient (org.zalando.nakadi.webservice.utils.TestStreamingClient)30 Test (org.junit.Test)29 SubscriptionCursor (org.zalando.nakadi.view.SubscriptionCursor)11 Subscription (org.zalando.nakadi.domain.Subscription)8 NakadiTestUtils.createSubscription (org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription)8 EventType (org.zalando.nakadi.domain.EventType)6 StringContains (org.hamcrest.core.StringContains)5 SubscriptionBase (org.zalando.nakadi.domain.SubscriptionBase)5 SubscriptionEventTypeStats (org.zalando.nakadi.domain.SubscriptionEventTypeStats)5 IOException (java.io.IOException)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)4 Matchers.hasSize (org.hamcrest.Matchers.hasSize)4 Before (org.junit.Before)4 BEGIN (org.zalando.nakadi.domain.SubscriptionBase.InitialPosition.BEGIN)4 RandomSubscriptionBuilder (org.zalando.nakadi.utils.RandomSubscriptionBuilder)4 TestUtils.waitFor (org.zalando.nakadi.utils.TestUtils.waitFor)4 NakadiTestUtils.commitCursors (org.zalando.nakadi.webservice.utils.NakadiTestUtils.commitCursors)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3