Search in sources :

Example 41 with Subscription

use of org.zalando.nakadi.domain.Subscription in project nakadi by zalando.

the class SubscriptionAT method testDeleteSubscription.

@Test
public void testDeleteSubscription() throws Exception {
    final String etName = createEventType().getName();
    final Subscription subscription = createSubscriptionForEventType(etName);
    when().delete("/subscriptions/{sid}", subscription.getId()).then().statusCode(HttpStatus.SC_NO_CONTENT);
    when().get("/subscriptions/{sid}", subscription.getId()).then().statusCode(HttpStatus.SC_NOT_FOUND);
    final Stat stat = CURATOR.checkExists().forPath(format("/nakadi/subscriptions/{0}", subscription.getId()));
    final boolean subscriptionExistsInZk = stat != null;
    assertThat(subscriptionExistsInZk, is(false));
}
Also used : Stat(org.apache.zookeeper.data.Stat) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Subscription(org.zalando.nakadi.domain.Subscription) NakadiTestUtils.createSubscription(org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription) Test(org.junit.Test)

Example 42 with Subscription

use of org.zalando.nakadi.domain.Subscription in project nakadi by zalando.

the class SubscriptionAT method whenStatsOnNotInitializedSubscriptionThanCorrectResponse.

@Test
public void whenStatsOnNotInitializedSubscriptionThanCorrectResponse() throws IOException {
    final String et = createEventType().getName();
    final Subscription s = createSubscriptionForEventType(et);
    final Response response = when().get("/subscriptions/{sid}/stats", s.getId()).thenReturn();
    final ItemsWrapper<SubscriptionEventTypeStats> statsItems = MAPPER.readValue(response.print(), new TypeReference<ItemsWrapper<SubscriptionEventTypeStats>>() {
    });
    Assert.assertEquals(1, statsItems.getItems().size());
    final SubscriptionEventTypeStats stats = statsItems.getItems().get(0);
    Assert.assertEquals(et, stats.getEventType());
    Assert.assertEquals(1, stats.getPartitions().size());
    for (final SubscriptionEventTypeStats.Partition partition : stats.getPartitions()) {
        Assert.assertNotNull(partition);
        Assert.assertNotNull(partition.getPartition());
        Assert.assertEquals("", partition.getStreamId());
        Assert.assertNull(partition.getUnconsumedEvents());
        Assert.assertEquals(partition.getState(), "unassigned");
    }
}
Also used : Response(com.jayway.restassured.response.Response) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) SubscriptionEventTypeStats(org.zalando.nakadi.domain.SubscriptionEventTypeStats) Subscription(org.zalando.nakadi.domain.Subscription) NakadiTestUtils.createSubscription(org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription) ItemsWrapper(org.zalando.nakadi.domain.ItemsWrapper) Test(org.junit.Test)

Example 43 with Subscription

use of org.zalando.nakadi.domain.Subscription in project nakadi by zalando.

the class SubscriptionAT method testSubscriptionWithManyEventTypesIsNotCreated.

@Test
public void testSubscriptionWithManyEventTypesIsNotCreated() {
    final List<String> eventTypes = IntStream.range(0, 31).mapToObj(i -> createEventType()).map(et -> et.getName()).collect(Collectors.toList());
    final String subscription = "{\"owning_application\":\"app\",\"event_types\":" + "[" + eventTypes.stream().map(et -> "\"" + et + "\"").collect(Collectors.joining(",")) + "]}";
    final Response response = given().body(subscription).contentType(JSON).post(SUBSCRIPTIONS_URL);
    // assert response
    response.then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENTITY).contentType(JSON).body("title", equalTo("Unprocessable Entity")).body("detail", equalTo("total partition count for subscription is 31, but the maximum partition count is 30"));
}
Also used : PaginationLinks(org.zalando.nakadi.domain.PaginationLinks) MoreStatus(org.zalando.problem.MoreStatus) RandomSubscriptionBuilder(org.zalando.nakadi.utils.RandomSubscriptionBuilder) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) Matchers.not(org.hamcrest.Matchers.not) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) HttpStatus(org.apache.http.HttpStatus) RestAssured.given(com.jayway.restassured.RestAssured.given) Stat(org.apache.zookeeper.data.Stat) Subscription(org.zalando.nakadi.domain.Subscription) BaseAT(org.zalando.nakadi.webservice.BaseAT) NakadiTestUtils.publishBusinessEventWithUserDefinedPartition(org.zalando.nakadi.webservice.utils.NakadiTestUtils.publishBusinessEventWithUserDefinedPartition) SubscriptionCursorWithoutToken(org.zalando.nakadi.view.SubscriptionCursorWithoutToken) Problem(org.zalando.problem.Problem) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ImmutableSet(com.google.common.collect.ImmutableSet) JSON(com.jayway.restassured.http.ContentType.JSON) TestUtils(org.zalando.nakadi.utils.TestUtils) ZookeeperTestUtils(org.zalando.nakadi.webservice.utils.ZookeeperTestUtils) Collectors(java.util.stream.Collectors) TestUtils.randomUUID(org.zalando.nakadi.utils.TestUtils.randomUUID) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) SubscriptionBase(org.zalando.nakadi.domain.SubscriptionBase) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) EventTypeBase(org.zalando.nakadi.domain.EventTypeBase) Optional(java.util.Optional) SubscriptionCursor(org.zalando.nakadi.view.SubscriptionCursor) Matchers.is(org.hamcrest.Matchers.is) NakadiTestUtils.createBusinessEventTypeWithPartitions(org.zalando.nakadi.webservice.utils.NakadiTestUtils.createBusinessEventTypeWithPartitions) IntStream(java.util.stream.IntStream) PaginationWrapper(org.zalando.nakadi.domain.PaginationWrapper) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) SubscriptionEventTypeStats(org.zalando.nakadi.domain.SubscriptionEventTypeStats) JsonTestHelper(org.zalando.nakadi.utils.JsonTestHelper) Cursor(org.zalando.nakadi.view.Cursor) Response(com.jayway.restassured.response.Response) MessageFormat.format(java.text.MessageFormat.format) 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) NakadiTestUtils.createSubscription(org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription) ItemsWrapper(org.zalando.nakadi.domain.ItemsWrapper) NakadiTestUtils.createSubscriptionForEventType(org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscriptionForEventType) Charsets(com.google.common.base.Charsets) SESSION_ID_UNKNOWN(org.zalando.nakadi.webservice.utils.TestStreamingClient.SESSION_ID_UNKNOWN) EventType(org.zalando.nakadi.domain.EventType) RestAssured.when(com.jayway.restassured.RestAssured.when) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TestUtils.waitFor(org.zalando.nakadi.utils.TestUtils.waitFor) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) IOException(java.io.IOException) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) RestAssured.get(com.jayway.restassured.RestAssured.get) TestStreamingClient(org.zalando.nakadi.webservice.utils.TestStreamingClient) Assert(org.junit.Assert) Response(com.jayway.restassured.response.Response) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Test(org.junit.Test)

Example 44 with Subscription

use of org.zalando.nakadi.domain.Subscription in project nakadi by zalando.

the class SubscriptionAT method whenStreamDuplicatePartitionsThenUnprocessableEntity.

@Test
public void whenStreamDuplicatePartitionsThenUnprocessableEntity() throws IOException {
    final String et = createEventType().getName();
    final Subscription s = createSubscriptionForEventType(et);
    final String body = "{\"partitions\":[" + "{\"event_type\":\"et1\",\"partition\":\"0\"}," + "{\"event_type\":\"et1\",\"partition\":\"0\"}]}";
    given().body(body).contentType(JSON).when().post("/subscriptions/{sid}/events", s.getId()).then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENTITY).body(JSON_HELPER.matchesObject(Problem.valueOf(MoreStatus.UNPROCESSABLE_ENTITY, "Duplicated partition specified")));
}
Also used : Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Subscription(org.zalando.nakadi.domain.Subscription) NakadiTestUtils.createSubscription(org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription) Test(org.junit.Test)

Example 45 with Subscription

use of org.zalando.nakadi.domain.Subscription in project nakadi by zalando.

the class SubscriptionAT method testOffsetsCommit.

@Test
public void testOffsetsCommit() throws Exception {
    // create event type in Nakadi
    final String etName = createEventType().getName();
    final Subscription subscription = createSubscriptionForEventType(etName);
    final TestStreamingClient client = TestStreamingClient.create(URL, subscription.getId(), "").start();
    waitFor(() -> assertThat(client.getSessionId(), not(equalTo(SESSION_ID_UNKNOWN))));
    String cursor = "{\"items\":[{\"partition\":\"0\",\"offset\":\"25\",\"event_type\":\"" + etName + "\",\"cursor_token\":\"abc\"}]}";
    commitCursors(subscription, cursor, client.getSessionId()).then().statusCode(HttpStatus.SC_NO_CONTENT);
    // check that offset is actually committed to Zookeeper
    String committedOffset = getCommittedOffsetFromZk(etName, subscription, "0");
    assertThat(committedOffset, equalTo(TestUtils.toTimelineOffset(25)));
    // commit lower offsets and expect 200
    cursor = "{\"items\":[{\"partition\":\"0\",\"offset\":\"10\",\"event_type\":\"" + etName + "\",\"cursor_token\":\"abc\"}]}";
    commitCursors(subscription, cursor, client.getSessionId()).then().statusCode(HttpStatus.SC_OK);
    // check that committed offset in Zookeeper is not changed
    committedOffset = getCommittedOffsetFromZk(etName, subscription, "0");
    assertThat(committedOffset, equalTo(TestUtils.toTimelineOffset(25)));
}
Also used : TestStreamingClient(org.zalando.nakadi.webservice.utils.TestStreamingClient) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Subscription(org.zalando.nakadi.domain.Subscription) NakadiTestUtils.createSubscription(org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription) Test(org.junit.Test)

Aggregations

Subscription (org.zalando.nakadi.domain.Subscription)55 Test (org.junit.Test)40 NakadiTestUtils.createSubscription (org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription)21 EventType (org.zalando.nakadi.domain.EventType)15 SubscriptionBase (org.zalando.nakadi.domain.SubscriptionBase)12 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)11 List (java.util.List)10 SubscriptionCursorWithoutToken (org.zalando.nakadi.view.SubscriptionCursorWithoutToken)9 TestStreamingClient (org.zalando.nakadi.webservice.utils.TestStreamingClient)9 ImmutableList (com.google.common.collect.ImmutableList)8 Collectors (java.util.stream.Collectors)8 SubscriptionCursor (org.zalando.nakadi.view.SubscriptionCursor)8 ItemsWrapper (org.zalando.nakadi.domain.ItemsWrapper)7 PaginationLinks (org.zalando.nakadi.domain.PaginationLinks)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 IOException (java.io.IOException)6 Optional (java.util.Optional)6 PaginationWrapper (org.zalando.nakadi.domain.PaginationWrapper)6 SubscriptionEventTypeStats (org.zalando.nakadi.domain.SubscriptionEventTypeStats)6 NakadiTestUtils.createEventType (org.zalando.nakadi.webservice.utils.NakadiTestUtils.createEventType)5