Search in sources :

Example 1 with ASSIGNED

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

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 List (java.util.List)1 Stream (java.util.stream.Stream)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers.emptyArray (org.hamcrest.Matchers.emptyArray)1 Assert.assertArrayEquals (org.junit.Assert.assertArrayEquals)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Test (org.junit.Test)1 EventTypePartition (org.zalando.nakadi.domain.EventTypePartition)1 Partition (org.zalando.nakadi.service.subscription.model.Partition)1 ASSIGNED (org.zalando.nakadi.service.subscription.model.Partition.State.ASSIGNED)1 REASSIGNING (org.zalando.nakadi.service.subscription.model.Partition.State.REASSIGNING)1 UNASSIGNED (org.zalando.nakadi.service.subscription.model.Partition.State.UNASSIGNED)1 Session (org.zalando.nakadi.service.subscription.model.Session)1