Search in sources :

Example 1 with InvalidStreamIdException

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);
}
Also used : Partition(org.zalando.nakadi.service.subscription.model.Partition) InvalidStreamIdException(org.zalando.nakadi.exceptions.InvalidStreamIdException) Test(org.junit.Test)

Example 2 with InvalidStreamIdException

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);
        }
    }
}
Also used : NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) InvalidCursorException(org.zalando.nakadi.exceptions.InvalidCursorException) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) InvalidStreamIdException(org.zalando.nakadi.exceptions.InvalidStreamIdException)

Aggregations

InvalidStreamIdException (org.zalando.nakadi.exceptions.InvalidStreamIdException)2 Test (org.junit.Test)1 EventTypePartition (org.zalando.nakadi.domain.EventTypePartition)1 NakadiCursor (org.zalando.nakadi.domain.NakadiCursor)1 InvalidCursorException (org.zalando.nakadi.exceptions.InvalidCursorException)1 Partition (org.zalando.nakadi.service.subscription.model.Partition)1