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