Search in sources :

Example 21 with Subscription

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

the class SubscriptionDbRepositoryTest method whenGetSubscriptionByIdThenOk.

@Test
public void whenGetSubscriptionByIdThenOk() throws Exception {
    // insert subscription into DB
    final Subscription subscription = RandomSubscriptionBuilder.builder().build();
    insertSubscriptionToDB(subscription);
    // get subscription by id and compare to original
    final Subscription gotSubscription = repository.getSubscription(subscription.getId());
    assertThat("We found the needed subscription", gotSubscription, equalTo(subscription));
}
Also used : Subscription(org.zalando.nakadi.domain.Subscription) Test(org.junit.Test)

Example 22 with Subscription

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

the class SubscriptionDbRepositoryTest method whenListSubscriptionsLimitAndOffsetAreRespected.

@Test
public void whenListSubscriptionsLimitAndOffsetAreRespected() throws ServiceUnavailableException {
    final String owningApp = TestUtils.randomUUID();
    final List<Subscription> testSubscriptions = createRandomSubscriptions(10, owningApp);
    testSubscriptions.forEach(this::insertSubscriptionToDB);
    testSubscriptions.sort(SUBSCRIPTION_CREATION_DATE_DESC_COMPARATOR);
    testSubscriptions.subList(0, 2).clear();
    testSubscriptions.subList(3, testSubscriptions.size()).clear();
    final List<Subscription> subscriptions = repository.listSubscriptions(emptySet(), Optional.of(owningApp), 2, 3);
    assertThat(subscriptions, equalTo(testSubscriptions));
}
Also used : Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Subscription(org.zalando.nakadi.domain.Subscription) Test(org.junit.Test)

Example 23 with Subscription

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

the class SubscriptionDbRepositoryTest method whenCreateSubscriptionThenOk.

@Test
public void whenCreateSubscriptionThenOk() throws Exception {
    final SubscriptionBase subscription = RandomSubscriptionBuilder.builder().build();
    final Subscription createdSubscription = repository.createSubscription(subscription);
    checkSubscriptionCreatedFromSubscriptionBase(createdSubscription, subscription);
    final int rows = template.queryForObject("SELECT count(*) FROM zn_data.subscription where s_id=?", Integer.class, createdSubscription.getId());
    assertThat("Number of rows should be 1", rows, equalTo(1));
    final Map<String, Object> result = template.queryForMap("SELECT s_subscription_object FROM zn_data.subscription WHERE s_id=?", createdSubscription.getId());
    final ObjectMapper mapper = (new JsonConfig()).jacksonObjectMapper();
    final Subscription saved = mapper.readValue(result.get("s_subscription_object").toString(), Subscription.class);
    assertThat("Saved subscription equal to original one", saved, equalTo(createdSubscription));
}
Also used : SubscriptionBase(org.zalando.nakadi.domain.SubscriptionBase) JsonConfig(org.zalando.nakadi.config.JsonConfig) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Subscription(org.zalando.nakadi.domain.Subscription) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 24 with Subscription

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

the class SubscriptionDbRepositoryTest method whenListSubscriptionsByMultipleEventTypesThenOk.

@Test
public void whenListSubscriptionsByMultipleEventTypesThenOk() throws ServiceUnavailableException {
    final String et1 = TestUtils.randomUUID();
    final String et2 = TestUtils.randomUUID();
    final String et3 = TestUtils.randomUUID();
    final String et4 = TestUtils.randomUUID();
    final String et5 = TestUtils.randomUUID();
    final List<Subscription> testSubscriptions = ImmutableList.of(RandomSubscriptionBuilder.builder().withEventTypes(ImmutableSet.of(et1, et2)).build(), RandomSubscriptionBuilder.builder().withEventTypes(ImmutableSet.of(et1, et2, et3)).build(), RandomSubscriptionBuilder.builder().withEventTypes(ImmutableSet.of(et1)).build(), RandomSubscriptionBuilder.builder().withEventTypes(ImmutableSet.of(et2)).build(), RandomSubscriptionBuilder.builder().withEventTypes(ImmutableSet.of(et3, et4, et5)).build());
    testSubscriptions.forEach(this::insertSubscriptionToDB);
    final List<Subscription> expectedSubscriptions = testSubscriptions.stream().filter(sub -> sub.getEventTypes().containsAll(ImmutableSet.of(et1, et2))).sorted(SUBSCRIPTION_CREATION_DATE_DESC_COMPARATOR).collect(toList());
    final List<Subscription> subscriptions = repository.listSubscriptions(ImmutableSet.of(et1, et2), Optional.empty(), 0, 10);
    assertThat(subscriptions, equalTo(expectedSubscriptions));
}
Also used : Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Subscription(org.zalando.nakadi.domain.Subscription) Test(org.junit.Test)

Example 25 with Subscription

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

the class HilaAT method whenPatchThenCursorsAreInitializedToDefault.

@Test(timeout = 15000)
public void whenPatchThenCursorsAreInitializedToDefault() throws Exception {
    final EventType et = createEventType();
    publishEvents(et.getName(), 10, i -> "{\"foo\": \"bar\"}");
    Thread.sleep(1000L);
    final Subscription s = createSubscription(RandomSubscriptionBuilder.builder().withEventType(et.getName()).withStartFrom(END).buildSubscriptionBase());
    given().body(MAPPER.writeValueAsString(new ItemsWrapper<>(Collections.emptyList()))).contentType(JSON).patch("/subscriptions/{id}/cursors", s.getId()).then().statusCode(SC_NO_CONTENT);
    final ItemsWrapper<SubscriptionCursor> subscriptionCursors = MAPPER.readValue(given().get("/subscriptions/{id}/cursors", s.getId()).getBody().asString(), new TypeReference<ItemsWrapper<SubscriptionCursor>>() {
    });
    final List<EventTypePartitionView> etStats = MAPPER.readValue(given().get("/event-types/{et}/partitions", et.getName()).getBody().asString(), new TypeReference<List<EventTypePartitionView>>() {
    });
    Assert.assertEquals(subscriptionCursors.getItems().size(), etStats.size());
    subscriptionCursors.getItems().forEach(sCursor -> {
        final boolean offsetSame = etStats.stream().anyMatch(ss -> ss.getPartitionId().equals(sCursor.getPartition()) && ss.getNewestAvailableOffset().equals(sCursor.getOffset()));
        // Check that after patch cursors are the same as END
        Assert.assertTrue(offsetSame);
    });
}
Also used : SubscriptionCursor(org.zalando.nakadi.view.SubscriptionCursor) NakadiTestUtils.createEventType(org.zalando.nakadi.webservice.utils.NakadiTestUtils.createEventType) EventType(org.zalando.nakadi.domain.EventType) EventTypePartitionView(org.zalando.nakadi.view.EventTypePartitionView) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) 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)

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