Search in sources :

Example 1 with Session

use of org.zalando.nakadi.service.subscription.model.Session in project nakadi by zalando.

the class SubscriptionRebalancerTest method rebalanceShouldHaveEmptyChangesetForBalancedData.

@Test
public void rebalanceShouldHaveEmptyChangesetForBalancedData() {
    final SubscriptionRebalancer rebalancer = new SubscriptionRebalancer();
    // 1. Data contains only assigned
    final List<Session> sessions = ImmutableList.of(new Session("0", 1), new Session("1", 1));
    assertThat(rebalancer.apply(sessions, new Partition[] { new Partition("0", "0", "0", null, ASSIGNED), new Partition("0", "1", "1", null, ASSIGNED), new Partition("1", "0", "1", null, ASSIGNED), new Partition("1", "1", "0", null, ASSIGNED) }), emptyArray());
    // 2. Data contains reassinging
    assertThat(rebalancer.apply(sessions, 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) }), emptyArray());
    // 3. Data contains only reassinging
    assertThat(rebalancer.apply(sessions, new Partition[] { new Partition("0", "0", "0", "1", REASSIGNING), new Partition("0", "1", "0", "1", REASSIGNING), new Partition("1", "0", "1", "0", REASSIGNING), new Partition("1", "1", "1", "0", REASSIGNING) }), emptyArray());
}
Also used : EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Partition(org.zalando.nakadi.service.subscription.model.Partition) Session(org.zalando.nakadi.service.subscription.model.Session) Test(org.junit.Test)

Example 2 with Session

use of org.zalando.nakadi.service.subscription.model.Session 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 3 with Session

use of org.zalando.nakadi.service.subscription.model.Session 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 4 with Session

use of org.zalando.nakadi.service.subscription.model.Session 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 5 with Session

use of org.zalando.nakadi.service.subscription.model.Session 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)

Aggregations

Session (org.zalando.nakadi.service.subscription.model.Session)14 EventTypePartition (org.zalando.nakadi.domain.EventTypePartition)13 Partition (org.zalando.nakadi.service.subscription.model.Partition)12 Test (org.junit.Test)9 List (java.util.List)4 Lists (com.google.common.collect.Lists)3 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 Map (java.util.Map)3 BiFunction (java.util.function.BiFunction)3 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IntStream (java.util.stream.IntStream)2 Charsets (com.google.common.base.Charsets)1 UTF_8 (com.google.common.base.Charsets.UTF_8)1 ImmutableList (com.google.common.collect.ImmutableList)1 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 Closeable (java.io.Closeable)1