Search in sources :

Example 16 with Partition

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

Example 17 with Partition

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

Example 18 with Partition

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

Example 19 with Partition

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

Example 20 with Partition

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);
}
Also used : KeeperException(org.apache.zookeeper.KeeperException) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Session(org.zalando.nakadi.service.subscription.model.Session) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) UTF_8(com.google.common.base.Charsets.UTF_8) ArrayList(java.util.ArrayList) Partition(org.zalando.nakadi.service.subscription.model.Partition) NakadiRuntimeException(org.zalando.nakadi.exceptions.NakadiRuntimeException) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) Stream(java.util.stream.Stream) ImmutableList(com.google.common.collect.ImmutableList) SubscriptionCursorWithoutToken(org.zalando.nakadi.view.SubscriptionCursorWithoutToken) ServiceTemporarilyUnavailableException(org.zalando.nakadi.exceptions.runtime.ServiceTemporarilyUnavailableException) Map(java.util.Map) SubscriptionCursorWithoutToken(org.zalando.nakadi.view.SubscriptionCursorWithoutToken) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Partition(org.zalando.nakadi.service.subscription.model.Partition)

Aggregations

Partition (org.zalando.nakadi.service.subscription.model.Partition)25 Test (org.junit.Test)18 EventTypePartition (org.zalando.nakadi.domain.EventTypePartition)18 Session (org.zalando.nakadi.service.subscription.model.Session)13 SubscriptionCursorWithoutToken (org.zalando.nakadi.view.SubscriptionCursorWithoutToken)6 Stream (java.util.stream.Stream)5 NakadiCursor (org.zalando.nakadi.domain.NakadiCursor)5 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 List (java.util.List)4 Map (java.util.Map)4 ImmutableList (com.google.common.collect.ImmutableList)3 Lists (com.google.common.collect.Lists)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 BiFunction (java.util.function.BiFunction)2 Collectors (java.util.stream.Collectors)2 IntStream (java.util.stream.IntStream)2 Subscription (org.zalando.nakadi.domain.Subscription)2 NakadiRuntimeException (org.zalando.nakadi.exceptions.NakadiRuntimeException)2