use of org.zalando.nakadi.domain.ItemsWrapper in project nakadi by zalando.
the class SubscriptionService method getSubscriptionStat.
public ItemsWrapper<SubscriptionEventTypeStats> getSubscriptionStat(final String subscriptionId) throws InconsistentStateException, NoSuchSubscriptionException, ServiceTemporarilyUnavailableException {
final Subscription subscription;
try {
subscription = subscriptionRepository.getSubscription(subscriptionId);
} catch (final ServiceUnavailableException ex) {
throw new InconsistentStateException(ex.getMessage());
}
final List<SubscriptionEventTypeStats> subscriptionStat = createSubscriptionStat(subscription);
return new ItemsWrapper<>(subscriptionStat);
}
use of org.zalando.nakadi.domain.ItemsWrapper in project nakadi by zalando.
the class NakadiTestUtils method getNumberOfAssignedStreams.
public static int getNumberOfAssignedStreams(final String sid) {
final Response response = when().get("/subscriptions/{sid}/stats", sid).thenReturn();
final ItemsWrapper<SubscriptionEventTypeStats> statsItems;
try {
statsItems = MAPPER.readValue(response.print(), new TypeReference<ItemsWrapper<SubscriptionEventTypeStats>>() {
});
} catch (final IOException e) {
throw new AssertionError("Failed to get stats", e);
}
final long assignedUniqueStreamsCount = statsItems.getItems().stream().flatMap(stat -> stat.getPartitions().stream()).filter(p -> "assigned".equals(p.getState())).map(SubscriptionEventTypeStats.Partition::getStreamId).distinct().count();
return (int) assignedUniqueStreamsCount;
}
use of org.zalando.nakadi.domain.ItemsWrapper 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);
});
}
use of org.zalando.nakadi.domain.ItemsWrapper in project nakadi by zalando.
the class HilaAT method whenResetCursorsThenStreamFromResetCursorOffset.
@Test(timeout = 15000)
public void whenResetCursorsThenStreamFromResetCursorOffset() throws Exception {
publishEvents(eventType.getName(), 20, i -> "{\"foo\":\"bar\"}");
final TestStreamingClient client1 = TestStreamingClient.create(subscription.getId()).start();
waitFor(() -> assertThat(client1.getBatches(), hasSize(10)));
int statusCode = commitCursors(subscription.getId(), Collections.singletonList(client1.getBatches().get(9).getCursor()), client1.getSessionId());
Assert.assertEquals(SC_NO_CONTENT, statusCode);
final List<SubscriptionCursor> resetCursors = Collections.singletonList(client1.getBatches().get(4).getCursor());
statusCode = given().body(MAPPER.writeValueAsString(new ItemsWrapper<>(resetCursors))).contentType(JSON).patch("/subscriptions/{id}/cursors", subscription.getId()).getStatusCode();
Assert.assertEquals(SC_NO_CONTENT, statusCode);
Assert.assertFalse(client1.isRunning());
Assert.assertTrue(client1.getBatches().stream().anyMatch(streamBatch -> streamBatch.getMetadata() != null && streamBatch.getMetadata().getDebug().equals("Resetting subscription cursors")));
final TestStreamingClient client2 = TestStreamingClient.create(subscription.getId()).start();
waitFor(() -> assertThat(client2.getBatches(), hasSize(10)));
Assert.assertEquals("001-0001-000000000000000005", client2.getBatches().get(0).getCursor().getOffset());
}
use of org.zalando.nakadi.domain.ItemsWrapper in project nakadi by zalando.
the class HilaAT method whenPatchThenCursorsAreInitializedAndPatched.
@Test(timeout = 15000)
public void whenPatchThenCursorsAreInitializedAndPatched() throws Exception {
final EventType et = createEventType();
publishEvents(et.getName(), 10, i -> "{\"foo\": \"bar\"}");
final List<EventTypePartitionView> etStats = MAPPER.readValue(given().get("/event-types/{et}/partitions", et.getName()).getBody().asString(), new TypeReference<List<EventTypePartitionView>>() {
});
final EventTypePartitionView begin = etStats.get(0);
final Subscription s = createSubscription(RandomSubscriptionBuilder.builder().withEventType(et.getName()).withStartFrom(END).buildSubscriptionBase());
given().body(MAPPER.writeValueAsString(new ItemsWrapper<>(Collections.singletonList(new SubscriptionCursorWithoutToken(et.getName(), begin.getPartitionId(), begin.getOldestAvailableOffset()))))).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>>() {
});
Assert.assertEquals(subscriptionCursors.getItems().size(), etStats.size());
subscriptionCursors.getItems().forEach(item -> {
if (item.getPartition().equals(begin.getPartitionId())) {
Assert.assertEquals(begin.getOldestAvailableOffset(), item.getOffset());
} else {
Assert.assertEquals(begin.getNewestAvailableOffset(), item.getOffset());
}
});
}
Aggregations