use of org.zalando.nakadi.exceptions.InvalidStreamIdException 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.exceptions.InvalidStreamIdException in project nakadi by zalando.
the class CursorsService method validateStreamId.
private void validateStreamId(final List<NakadiCursor> cursors, final String streamId, final ZkSubscriptionClient subscriptionClient) throws ServiceUnavailableException, InvalidCursorException, InvalidStreamIdException {
if (!uuidGenerator.isUUID(streamId)) {
throw new InvalidStreamIdException(String.format("Stream id has to be valid UUID, but `%s was provided", streamId), streamId);
}
if (!subscriptionClient.isActiveSession(streamId)) {
throw new InvalidStreamIdException("Session with stream id " + streamId + " not found", streamId);
}
final Map<EventTypePartition, String> partitionSessions = Stream.of(subscriptionClient.getTopology().getPartitions()).collect(Collectors.toMap(Partition::getKey, Partition::getSession));
for (final NakadiCursor cursor : cursors) {
final EventTypePartition etPartition = cursor.getEventTypePartition();
final String partitionSession = partitionSessions.get(etPartition);
if (partitionSession == null) {
throw new InvalidCursorException(CursorError.PARTITION_NOT_FOUND, cursor);
}
if (!streamId.equals(partitionSession)) {
throw new InvalidStreamIdException("Cursor " + cursor + " cannot be committed with stream id " + streamId, streamId);
}
}
}
Aggregations