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));
}
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));
}
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));
}
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));
}
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);
});
}
Aggregations