use of org.zalando.nakadi.domain.Subscription in project nakadi by zalando.
the class Aruha771MigrationHelper method fillSubscriptionsHashes.
public void fillSubscriptionsHashes() throws Exception {
try (Connection con = DriverManager.getConnection(url, user, pass)) {
final Statement st = con.createStatement();
final ResultSet rs = st.executeQuery("SELECT s_subscription_object FROM zn_data.subscription");
int i = 0;
while (rs.next()) {
final String jsonSubscription = rs.getString("s_subscription_object");
final Subscription subscription = jsonMapper.readValue(jsonSubscription, Subscription.class);
final String hash = hashGenerator.generateSubscriptionKeyFieldsHash(subscription);
final Statement statement = con.createStatement();
statement.execute("UPDATE zn_data.subscription SET s_key_fields_hash='" + hash + "' " + "WHERE s_id='" + subscription.getId() + "'");
System.out.println(++i + " | " + subscription.getId() + " | " + hash);
}
} catch (final Exception e) {
e.printStackTrace();
}
}
use of org.zalando.nakadi.domain.Subscription in project nakadi by zalando.
the class HilaAT method testSubscriptionStatsMultiET.
@Test
public void testSubscriptionStatsMultiET() throws IOException {
final List<EventType> eventTypes = Lists.newArrayList(createEventType(), createEventType());
publishEvents(eventTypes.get(0).getName(), 10, i -> "{\"foo\":\"bar\"}");
publishEvents(eventTypes.get(1).getName(), 20, i -> "{\"foo\":\"bar\"}");
final Subscription subscription = NakadiTestUtils.createSubscription(RandomSubscriptionBuilder.builder().withEventTypes(eventTypes.stream().map(EventType::getName).collect(Collectors.toSet())).withStartFrom(END).build());
// client is needed only to initialize stats
final TestStreamingClient client = TestStreamingClient.create(URL, subscription.getId(), "batch_flush_timeout=1").start();
waitFor(() -> assertThat(client.getBatches().isEmpty(), is(false)));
publishEvents(eventTypes.get(0).getName(), 1, i -> "{\"foo\":\"bar\"}");
publishEvents(eventTypes.get(1).getName(), 2, i -> "{\"foo\":\"bar\"}");
NakadiTestUtils.getSubscriptionStat(subscription).then().content(new StringContains(JSON_TEST_HELPER.asJsonString(new SubscriptionEventTypeStats(eventTypes.get(0).getName(), Collections.singletonList(new SubscriptionEventTypeStats.Partition("0", "assigned", 1L, client.getSessionId(), AUTO)))))).content(new StringContains(JSON_TEST_HELPER.asJsonString(new SubscriptionEventTypeStats(eventTypes.get(1).getName(), Collections.singletonList(new SubscriptionEventTypeStats.Partition("0", "assigned", 2L, client.getSessionId(), AUTO))))));
client.close();
}
use of org.zalando.nakadi.domain.Subscription 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.Subscription 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());
}
});
}
use of org.zalando.nakadi.domain.Subscription in project nakadi by zalando.
the class SubscriptionDbRepositoryTest method whenGetSubscriptionByKeyPropertiesThenOk.
@Test
public void whenGetSubscriptionByKeyPropertiesThenOk() throws Exception {
final String owningApplication = TestUtils.randomUUID();
// insert subscription into DB
final Subscription subscription = RandomSubscriptionBuilder.builder().withOwningApplication(owningApplication).withEventTypes(ImmutableSet.of("my-et", "second-et")).withConsumerGroup("my-cg").build();
insertSubscriptionToDB(subscription);
// get subscription by key properties and compare to original
final Subscription gotSubscription = repository.getSubscription(owningApplication, ImmutableSet.of("second-et", "my-et"), "my-cg");
assertThat("We found the needed subscription", gotSubscription, equalTo(subscription));
}
Aggregations