use of org.zalando.nakadi.service.subscription.model.Partition in project nakadi by zalando.
the class CursorsServiceAT method whenPartitionIsStreamedToDifferentClientThenFalse.
@Test
public void whenPartitionIsStreamedToDifferentClientThenFalse() throws Exception {
setPartitions(new Partition[] { new Partition(etName, P1, "wrong-stream-id", null, Partition.State.ASSIGNED) });
try {
cursorsService.commitCursors(streamId, sid, testCursors);
fail("Expected InvalidStreamIdException to be thrown");
} catch (final InvalidStreamIdException ignore) {
}
checkCurrentOffsetInZk(P1, OLD_OFFSET);
}
use of org.zalando.nakadi.service.subscription.model.Partition in project nakadi by zalando.
the class CursorsServiceAT method whenCommitCursorsThenTrue.
@Test
public void whenCommitCursorsThenTrue() throws Exception {
setPartitions(new Partition[] { new Partition(etName, P1, streamId, null, Partition.State.ASSIGNED) });
final List<Boolean> commitResult = cursorsService.commitCursors(streamId, sid, testCursors);
assertThat(commitResult, equalTo(ImmutableList.of(true)));
checkCurrentOffsetInZk(P1, NEW_OFFSET);
}
use of org.zalando.nakadi.service.subscription.model.Partition in project nakadi by zalando.
the class CursorsServiceAT method whenCommitOldCursorsThenFalse.
@Test
public void whenCommitOldCursorsThenFalse() throws Exception {
final NakadiCursor cursor = NakadiCursor.of(buildTimeline(etName, topic, CREATED_AT), P1, OLDEST_OFFSET);
registerNakadiCursor(cursor);
testCursors = ImmutableList.of(cursor);
setPartitions(new Partition[] { new Partition(etName, P1, streamId, null, Partition.State.ASSIGNED) });
final List<Boolean> commitResult = cursorsService.commitCursors(streamId, sid, testCursors);
assertThat(commitResult, equalTo(ImmutableList.of(false)));
checkCurrentOffsetInZk(P1, OLD_OFFSET);
}
use of org.zalando.nakadi.service.subscription.model.Partition in project nakadi by zalando.
the class CursorsServiceAT method whenFirstCursorIsNotCommittedThenNextCursorsAreNotSkipped.
@Test
public void whenFirstCursorIsNotCommittedThenNextCursorsAreNotSkipped() throws Exception {
final NakadiCursor c1 = NakadiCursor.of(timeline, P1, OLDEST_OFFSET);
final NakadiCursor c2 = NakadiCursor.of(timeline, P2, NEW_OFFSET);
testCursors = ImmutableList.of(c1, c2);
testCursors.forEach(this::registerNakadiCursor);
setPartitions(new Partition[] { new Partition(etName, P1, streamId, null, Partition.State.ASSIGNED), new Partition(etName, P2, streamId, null, Partition.State.ASSIGNED) });
final List<Boolean> result = cursorsService.commitCursors(streamId, sid, testCursors);
assertFalse(result.get(0));
assertTrue(result.get(1));
checkCurrentOffsetInZk(P1, OLD_OFFSET);
checkCurrentOffsetInZk(P2, NEW_OFFSET);
}
use of org.zalando.nakadi.service.subscription.model.Partition in project nakadi by zalando.
the class NewZkSubscriptionClient method createTopologyAndOffsets.
@Override
protected byte[] createTopologyAndOffsets(final Collection<SubscriptionCursorWithoutToken> cursors) throws Exception {
for (final SubscriptionCursorWithoutToken cursor : cursors) {
getCurator().create().creatingParentsIfNeeded().forPath(getOffsetPath(cursor.getEventTypePartition()), cursor.getOffset().getBytes(UTF_8));
}
final Partition[] partitions = cursors.stream().map(cursor -> new Partition(cursor.getEventType(), cursor.getPartition(), null, null, Partition.State.UNASSIGNED)).toArray(Partition[]::new);
final Topology topology = new Topology(partitions, "", 0);
getLog().info("Generating topology {}", topology);
return objectMapper.writeValueAsBytes(topology);
}
Aggregations