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());
}
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));
}
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());
}
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)));
}
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());
}
Aggregations