use of org.zalando.nakadi.domain.EventTypePartition in project nakadi by zalando.
the class PartitionTest method moveToSessionIdUnassignedShouldProduceCorrectData.
@Test
public void moveToSessionIdUnassignedShouldProduceCorrectData() {
final Collection<String> valid = singletonList("T");
final String eventType = "et";
final String partition = "partition";
final Partition test = new Partition(eventType, partition, "x", "x", Partition.State.UNASSIGNED).moveToSessionId("T", valid);
assertEquals(new EventTypePartition(eventType, partition), test.getKey());
assertEquals("T", test.getSession());
assertNull(test.getNextSession());
Assert.assertEquals(Partition.State.ASSIGNED, test.getState());
}
use of org.zalando.nakadi.domain.EventTypePartition in project nakadi by zalando.
the class SubscriptionRebalancerTest method directlyRequestedPartitionsAreCaptured.
@Test
public void directlyRequestedPartitionsAreCaptured() {
final Partition[] changeset = new SubscriptionRebalancer().apply(ImmutableList.of(new Session("s1", 1), new Session("s2", 1), new Session("s3", 1, ImmutableList.of(new EventTypePartition("et1", "p1"), new EventTypePartition("et1", "p4")))), new Partition[] { new Partition("et1", "p1", "s7", null, ASSIGNED), new Partition("et1", "p2", "s7", null, ASSIGNED), new Partition("et1", "p3", "s7", null, ASSIGNED), new Partition("et1", "p4", "s7", null, ASSIGNED) });
assertEquals(newHashSet(changeset), newHashSet(new Partition("et1", "p1", "s3", null, ASSIGNED), new Partition("et1", "p2", "s1", null, ASSIGNED), new Partition("et1", "p3", "s2", null, ASSIGNED), new Partition("et1", "p4", "s3", null, ASSIGNED)));
}
use of org.zalando.nakadi.domain.EventTypePartition in project nakadi by zalando.
the class SubscriptionRebalancerTest method directlyAssignedPartitionsAreNotTransferred.
@Test
public void directlyAssignedPartitionsAreNotTransferred() {
final Partition[] changeset = new SubscriptionRebalancer().apply(ImmutableList.of(new Session("s1", 1, ImmutableList.of(new EventTypePartition("et1", "p1"))), new Session("s2", 1)), new Partition[] { new Partition("et1", "p1", "s1", null, ASSIGNED), new Partition("et1", "p2", null, null, UNASSIGNED) });
assertEquals(newHashSet(changeset), newHashSet(new Partition("et1", "p2", "s2", null, ASSIGNED)));
}
use of org.zalando.nakadi.domain.EventTypePartition 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);
}
}
}
use of org.zalando.nakadi.domain.EventTypePartition in project nakadi by zalando.
the class SubscriptionValidationService method validateInitialCursors.
private void validateInitialCursors(final SubscriptionBase subscription, final List<EventTypePartition> allPartitions) throws WrongInitialCursorsException, RepositoryProblemException {
final boolean cursorsMissing = allPartitions.stream().anyMatch(p -> !subscription.getInitialCursors().stream().anyMatch(p::ownsCursor));
if (cursorsMissing) {
throw new WrongInitialCursorsException("initial_cursors should contain cursors for all partitions of subscription");
}
final boolean hasCursorForWrongPartition = subscription.getInitialCursors().stream().anyMatch(c -> !allPartitions.contains(new EventTypePartition(c.getEventType(), c.getPartition())));
if (hasCursorForWrongPartition) {
throw new WrongInitialCursorsException("initial_cursors should contain cursors only for partitions of this subscription");
}
if (subscription.getInitialCursors().size() > allPartitions.size()) {
throw new WrongInitialCursorsException("there should be no more than 1 cursor for each partition in initial_cursors");
}
try {
for (final SubscriptionCursorWithoutToken cursor : subscription.getInitialCursors()) {
final NakadiCursor nakadiCursor = cursorConverter.convert(cursor);
if (nakadiCursor.getTimeline().isDeleted()) {
throw new InvalidCursorException(UNAVAILABLE, nakadiCursor);
}
timelineService.getTopicRepository(nakadiCursor.getTimeline()).validateReadCursors(Collections.singletonList(nakadiCursor));
}
} catch (final InvalidCursorException ex) {
throw new WrongInitialCursorsException(ex.getMessage(), ex);
} catch (final NakadiException ex) {
throw new RepositoryProblemException("Topic repository problem occurred when validating cursors", ex);
}
}
Aggregations