Search in sources :

Example 1 with EventTypePartition

use of org.zalando.nakadi.domain.EventTypePartition in project nakadi by zalando.

the class SubscriptionRebalancerTest method rebalanceShouldRemoveDeadSessions.

@Test
public void rebalanceShouldRemoveDeadSessions() {
    final Partition[] changeset = new SubscriptionRebalancer().apply(ImmutableList.of(new Session("1", 1), new Session("2", 1)), new Partition[] { new Partition("0", "0", "0", null, ASSIGNED), new Partition("0", "1", "0", "1", REASSIGNING), new Partition("1", "0", "1", null, ASSIGNED), new Partition("1", "1", "0", null, ASSIGNED) });
    assertEquals(3, changeset.length);
    // All partitions must be in assigned state
    assertFalse(Stream.of(changeset).anyMatch(p -> p.getState() != ASSIGNED));
    // All partitions must not have nextSessionId
    assertFalse(Stream.of(changeset).anyMatch(p -> p.getNextSession() != null));
    assertFalse(Stream.of(changeset).anyMatch(p -> p.getKey().equals(new EventTypePartition("1", "0"))));
    assertEquals(1, Stream.of(changeset).filter(p -> p.getSession().equals("1")).count());
    assertEquals(2, Stream.of(changeset).filter(p -> p.getSession().equals("2")).count());
    assertFalse(Stream.of(changeset).anyMatch(p -> p.getState() != ASSIGNED));
}
Also used : ASSIGNED(org.zalando.nakadi.service.subscription.model.Partition.State.ASSIGNED) Matchers.emptyArray(org.hamcrest.Matchers.emptyArray) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Session(org.zalando.nakadi.service.subscription.model.Session) UNASSIGNED(org.zalando.nakadi.service.subscription.model.Partition.State.UNASSIGNED) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Partition(org.zalando.nakadi.service.subscription.model.Partition) List(java.util.List) Stream(java.util.stream.Stream) ImmutableList(com.google.common.collect.ImmutableList) Assert.assertFalse(org.junit.Assert.assertFalse) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) REASSIGNING(org.zalando.nakadi.service.subscription.model.Partition.State.REASSIGNING) Assert.assertEquals(org.junit.Assert.assertEquals) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Partition(org.zalando.nakadi.service.subscription.model.Partition) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Session(org.zalando.nakadi.service.subscription.model.Session) Test(org.junit.Test)

Example 2 with EventTypePartition

use of org.zalando.nakadi.domain.EventTypePartition in project nakadi by zalando.

the class SubscriptionRebalancerTest method rebalanceShouldTakeRebalancingPartitions.

@Test
public void rebalanceShouldTakeRebalancingPartitions() {
    final Partition[] changeset = new SubscriptionRebalancer().apply(ImmutableList.of(new Session("1", 1), new Session("2", 1), new Session("3", 1)), new Partition[] { new Partition("0", "0", "1", null, ASSIGNED), new Partition("0", "1", "1", null, ASSIGNED), new Partition("1", "0", "2", null, REASSIGNING), new Partition("1", "1", "2", null, ASSIGNED) });
    assertEquals(1, changeset.length);
    final Partition changed = changeset[0];
    assertEquals(new EventTypePartition("1", "0"), changed.getKey());
    assertEquals("2", changed.getSession());
    assertEquals("3", changed.getNextSession());
    assertEquals(REASSIGNING, changed.getState());
}
Also used : EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Partition(org.zalando.nakadi.service.subscription.model.Partition) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Session(org.zalando.nakadi.service.subscription.model.Session) Test(org.junit.Test)

Example 3 with EventTypePartition

use of org.zalando.nakadi.domain.EventTypePartition in project nakadi by zalando.

the class SubscriptionRebalancerTest method directlyRequestedPartitionsAreTransferred.

@Test
public void directlyRequestedPartitionsAreTransferred() {
    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", "s1", null, ASSIGNED), new Partition("et1", "p2", "s1", null, ASSIGNED), new Partition("et1", "p3", "s2", null, ASSIGNED), new Partition("et1", "p4", "s2", null, ASSIGNED) });
    assertEquals(newHashSet(changeset), newHashSet(new Partition("et1", "p1", "s1", "s3", REASSIGNING), new Partition("et1", "p4", "s2", "s3", REASSIGNING)));
}
Also used : EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Partition(org.zalando.nakadi.service.subscription.model.Partition) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Session(org.zalando.nakadi.service.subscription.model.Session) Test(org.junit.Test)

Example 4 with EventTypePartition

use of org.zalando.nakadi.domain.EventTypePartition in project nakadi by zalando.

the class SubscriptionRebalancerTest method rebalanceShouldMoveToReassigningState.

@Test
public void rebalanceShouldMoveToReassigningState() {
    final Partition[] changeset = new SubscriptionRebalancer().apply(ImmutableList.of(new Session("1", 1), new Session("2", 1), new Session("3", 1)), new Partition[] { new Partition("0", "0", "1", null, ASSIGNED), new Partition("0", "1", "1", null, ASSIGNED), new Partition("1", "0", "2", null, ASSIGNED), new Partition("1", "1", "2", null, ASSIGNED) });
    assertEquals(1, changeset.length);
    final Partition changed = changeset[0];
    assertTrue(changed.getKey().equals(new EventTypePartition("1", "0")) || changed.getKey().equals(new EventTypePartition("1", "1")));
    assertEquals("2", changed.getSession());
    assertEquals("3", changed.getNextSession());
    assertEquals(REASSIGNING, changed.getState());
}
Also used : EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Partition(org.zalando.nakadi.service.subscription.model.Partition) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Session(org.zalando.nakadi.service.subscription.model.Session) Test(org.junit.Test)

Example 5 with EventTypePartition

use of org.zalando.nakadi.domain.EventTypePartition in project nakadi by zalando.

the class SubscriptionRebalancerTest method onlyDirectSessionsWorkFine.

@Test
public void onlyDirectSessionsWorkFine() {
    final Partition[] changeset = new SubscriptionRebalancer().apply(ImmutableList.of(new Session("s1", 1, ImmutableList.of(new EventTypePartition("et1", "p3"))), new Session("s2", 1, ImmutableList.of(new EventTypePartition("et1", "p2")))), new Partition[] { new Partition("et1", "p1", null, null, UNASSIGNED), new Partition("et1", "p2", null, null, UNASSIGNED), new Partition("et1", "p3", null, null, UNASSIGNED), new Partition("et1", "p4", null, null, UNASSIGNED) });
    assertEquals(newHashSet(changeset), newHashSet(new Partition("et1", "p3", "s1", null, ASSIGNED), new Partition("et1", "p2", "s2", null, ASSIGNED)));
}
Also used : EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Partition(org.zalando.nakadi.service.subscription.model.Partition) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Session(org.zalando.nakadi.service.subscription.model.Session) Test(org.junit.Test)

Aggregations

EventTypePartition (org.zalando.nakadi.domain.EventTypePartition)27 Test (org.junit.Test)16 Partition (org.zalando.nakadi.service.subscription.model.Partition)15 Session (org.zalando.nakadi.service.subscription.model.Session)11 SubscriptionCursorWithoutToken (org.zalando.nakadi.view.SubscriptionCursorWithoutToken)9 NakadiCursor (org.zalando.nakadi.domain.NakadiCursor)6 Map (java.util.Map)5 NakadiRuntimeException (org.zalando.nakadi.exceptions.NakadiRuntimeException)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Stream (java.util.stream.Stream)4 InvalidCursorException (org.zalando.nakadi.exceptions.InvalidCursorException)4 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 TimeUnit (java.util.concurrent.TimeUnit)3 Collectors (java.util.stream.Collectors)3 Subscription (org.zalando.nakadi.domain.Subscription)3 NakadiException (org.zalando.nakadi.exceptions.NakadiException)3 ZkSubscriptionClient (org.zalando.nakadi.service.subscription.zk.ZkSubscriptionClient)3