Search in sources :

Example 1 with TASK_2_0

use of org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_2_0 in project kafka by apache.

the class HighAvailabilityTaskAssignorTest method shouldAssignActiveStatefulTasksEvenlyOverClientsWhereNumberOfClientsNotIntegralDivisorOfNumberOfTasks.

@Test
public void shouldAssignActiveStatefulTasksEvenlyOverClientsWhereNumberOfClientsNotIntegralDivisorOfNumberOfTasks() {
    final Set<TaskId> allTaskIds = mkSet(TASK_0_0, TASK_0_1, TASK_0_2, TASK_1_0, TASK_1_1, TASK_1_2, TASK_2_0, TASK_2_1, TASK_2_2);
    final Map<TaskId, Long> lags = allTaskIds.stream().collect(Collectors.toMap(k -> k, k -> 10L));
    final ClientState clientState1 = new ClientState(emptySet(), emptySet(), lags, 1);
    final ClientState clientState2 = new ClientState(emptySet(), emptySet(), lags, 1);
    final Map<UUID, ClientState> clientStates = getClientStatesMap(clientState1, clientState2);
    final boolean unstable = new HighAvailabilityTaskAssignor().assign(clientStates, allTaskIds, allTaskIds, new AssignmentConfigs(0L, 1, 0, 60_000L));
    assertThat(unstable, is(false));
    assertValidAssignment(0, allTaskIds, emptySet(), clientStates, new StringBuilder());
    assertBalancedActiveAssignment(clientStates, new StringBuilder());
    assertBalancedStatefulAssignment(allTaskIds, clientStates, new StringBuilder());
    assertBalancedTasks(clientStates);
}
Also used : TaskId(org.apache.kafka.streams.processor.TaskId) AssignmentConfigs(org.apache.kafka.streams.processor.internals.assignment.AssignorConfiguration.AssignmentConfigs) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Matchers.not(org.hamcrest.Matchers.not) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Utils.mkMap(org.apache.kafka.common.utils.Utils.mkMap) AssignmentTestUtils.analyzeTaskAssignmentBalance(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.analyzeTaskAssignmentBalance) Collections.singleton(java.util.Collections.singleton) Map(java.util.Map) AssignmentTestUtils.hasStandbyTasks(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.hasStandbyTasks) Collections.singletonMap(java.util.Collections.singletonMap) Assert.fail(org.junit.Assert.fail) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) UUID_1(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.UUID_1) AssignmentTestUtils.hasAssignedTasks(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.hasAssignedTasks) UUID_3(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.UUID_3) AssignmentTestUtils.assertValidAssignment(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.assertValidAssignment) UUID_2(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.UUID_2) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Collections.emptySet(java.util.Collections.emptySet) TASK_0_0(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_0) Utils.mkSet(org.apache.kafka.common.utils.Utils.mkSet) TASK_0_1(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_1) TASK_1_1(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_1_1) TASK_2_0(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_2_0) Set(java.util.Set) TASK_0_2(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_2) TASK_1_0(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_1_0) Test(org.junit.Test) TASK_0_3(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_3) TASK_1_3(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_1_3) TASK_2_2(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_2_2) UUID(java.util.UUID) TASK_1_2(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_1_2) TASK_2_1(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_2_1) AssignmentTestUtils.assertBalancedActiveAssignment(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.assertBalancedActiveAssignment) Collectors(java.util.stream.Collectors) EMPTY_TASKS(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.EMPTY_TASKS) AssignmentTestUtils.getClientStatesMap(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.getClientStatesMap) Utils.mkEntry(org.apache.kafka.common.utils.Utils.mkEntry) AssignmentTestUtils.assertBalancedStatefulAssignment(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.assertBalancedStatefulAssignment) Matchers.is(org.hamcrest.Matchers.is) AssignmentTestUtils.hasActiveTasks(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.hasActiveTasks) AssignmentTestUtils.assertBalancedTasks(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.assertBalancedTasks) TaskId(org.apache.kafka.streams.processor.TaskId) AssignmentConfigs(org.apache.kafka.streams.processor.internals.assignment.AssignorConfiguration.AssignmentConfigs) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with TASK_2_0

use of org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_2_0 in project kafka by apache.

the class HighAvailabilityTaskAssignorTest method shouldAssignActiveStatefulTasksEvenlyOverClientsWhereNumberOfClientsIntegralDivisorOfNumberOfTasks.

@Test
public void shouldAssignActiveStatefulTasksEvenlyOverClientsWhereNumberOfClientsIntegralDivisorOfNumberOfTasks() {
    final Set<TaskId> allTaskIds = mkSet(TASK_0_0, TASK_0_1, TASK_0_2, TASK_1_0, TASK_1_1, TASK_1_2, TASK_2_0, TASK_2_1, TASK_2_2);
    final Map<TaskId, Long> lags = allTaskIds.stream().collect(Collectors.toMap(k -> k, k -> 10L));
    final ClientState clientState1 = new ClientState(emptySet(), emptySet(), lags, 1);
    final ClientState clientState2 = new ClientState(emptySet(), emptySet(), lags, 1);
    final ClientState clientState3 = new ClientState(emptySet(), emptySet(), lags, 1);
    final Map<UUID, ClientState> clientStates = getClientStatesMap(clientState1, clientState2, clientState3);
    final boolean unstable = new HighAvailabilityTaskAssignor().assign(clientStates, allTaskIds, allTaskIds, new AssignmentConfigs(0L, 1, 0, 60_000L));
    assertThat(unstable, is(false));
    assertValidAssignment(0, allTaskIds, emptySet(), clientStates, new StringBuilder());
    assertBalancedActiveAssignment(clientStates, new StringBuilder());
    assertBalancedStatefulAssignment(allTaskIds, clientStates, new StringBuilder());
    assertBalancedTasks(clientStates);
}
Also used : TaskId(org.apache.kafka.streams.processor.TaskId) AssignmentConfigs(org.apache.kafka.streams.processor.internals.assignment.AssignorConfiguration.AssignmentConfigs) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Matchers.not(org.hamcrest.Matchers.not) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Utils.mkMap(org.apache.kafka.common.utils.Utils.mkMap) AssignmentTestUtils.analyzeTaskAssignmentBalance(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.analyzeTaskAssignmentBalance) Collections.singleton(java.util.Collections.singleton) Map(java.util.Map) AssignmentTestUtils.hasStandbyTasks(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.hasStandbyTasks) Collections.singletonMap(java.util.Collections.singletonMap) Assert.fail(org.junit.Assert.fail) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) UUID_1(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.UUID_1) AssignmentTestUtils.hasAssignedTasks(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.hasAssignedTasks) UUID_3(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.UUID_3) AssignmentTestUtils.assertValidAssignment(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.assertValidAssignment) UUID_2(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.UUID_2) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Collections.emptySet(java.util.Collections.emptySet) TASK_0_0(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_0) Utils.mkSet(org.apache.kafka.common.utils.Utils.mkSet) TASK_0_1(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_1) TASK_1_1(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_1_1) TASK_2_0(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_2_0) Set(java.util.Set) TASK_0_2(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_2) TASK_1_0(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_1_0) Test(org.junit.Test) TASK_0_3(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_3) TASK_1_3(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_1_3) TASK_2_2(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_2_2) UUID(java.util.UUID) TASK_1_2(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_1_2) TASK_2_1(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_2_1) AssignmentTestUtils.assertBalancedActiveAssignment(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.assertBalancedActiveAssignment) Collectors(java.util.stream.Collectors) EMPTY_TASKS(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.EMPTY_TASKS) AssignmentTestUtils.getClientStatesMap(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.getClientStatesMap) Utils.mkEntry(org.apache.kafka.common.utils.Utils.mkEntry) AssignmentTestUtils.assertBalancedStatefulAssignment(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.assertBalancedStatefulAssignment) Matchers.is(org.hamcrest.Matchers.is) AssignmentTestUtils.hasActiveTasks(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.hasActiveTasks) AssignmentTestUtils.assertBalancedTasks(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.assertBalancedTasks) TaskId(org.apache.kafka.streams.processor.TaskId) AssignmentConfigs(org.apache.kafka.streams.processor.internals.assignment.AssignorConfiguration.AssignmentConfigs) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with TASK_2_0

use of org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_2_0 in project kafka by apache.

the class HighAvailabilityTaskAssignorTest method shouldAssignActiveStatefulTasksEvenlyOverStreamThreadsButBestEffortOverClients.

@Test
public void shouldAssignActiveStatefulTasksEvenlyOverStreamThreadsButBestEffortOverClients() {
    final Set<TaskId> allTaskIds = mkSet(TASK_0_0, TASK_0_1, TASK_0_2, TASK_1_0, TASK_1_1, TASK_1_2, TASK_2_0, TASK_2_1, TASK_2_2);
    final Map<TaskId, Long> lags = allTaskIds.stream().collect(Collectors.toMap(k -> k, k -> 10L));
    final ClientState clientState1 = new ClientState(emptySet(), emptySet(), lags, 6);
    final ClientState clientState2 = new ClientState(emptySet(), emptySet(), lags, 3);
    final Map<UUID, ClientState> clientStates = getClientStatesMap(clientState1, clientState2);
    final boolean unstable = new HighAvailabilityTaskAssignor().assign(clientStates, allTaskIds, allTaskIds, new AssignmentConfigs(0L, 1, 0, 60_000L));
    assertThat(unstable, is(false));
    assertValidAssignment(0, allTaskIds, emptySet(), clientStates, new StringBuilder());
    assertBalancedActiveAssignment(clientStates, new StringBuilder());
    assertBalancedStatefulAssignment(allTaskIds, clientStates, new StringBuilder());
    assertThat(clientState1, hasActiveTasks(6));
    assertThat(clientState2, hasActiveTasks(3));
}
Also used : TaskId(org.apache.kafka.streams.processor.TaskId) AssignmentConfigs(org.apache.kafka.streams.processor.internals.assignment.AssignorConfiguration.AssignmentConfigs) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Matchers.not(org.hamcrest.Matchers.not) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Utils.mkMap(org.apache.kafka.common.utils.Utils.mkMap) AssignmentTestUtils.analyzeTaskAssignmentBalance(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.analyzeTaskAssignmentBalance) Collections.singleton(java.util.Collections.singleton) Map(java.util.Map) AssignmentTestUtils.hasStandbyTasks(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.hasStandbyTasks) Collections.singletonMap(java.util.Collections.singletonMap) Assert.fail(org.junit.Assert.fail) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) UUID_1(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.UUID_1) AssignmentTestUtils.hasAssignedTasks(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.hasAssignedTasks) UUID_3(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.UUID_3) AssignmentTestUtils.assertValidAssignment(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.assertValidAssignment) UUID_2(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.UUID_2) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Collections.emptySet(java.util.Collections.emptySet) TASK_0_0(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_0) Utils.mkSet(org.apache.kafka.common.utils.Utils.mkSet) TASK_0_1(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_1) TASK_1_1(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_1_1) TASK_2_0(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_2_0) Set(java.util.Set) TASK_0_2(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_2) TASK_1_0(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_1_0) Test(org.junit.Test) TASK_0_3(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_3) TASK_1_3(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_1_3) TASK_2_2(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_2_2) UUID(java.util.UUID) TASK_1_2(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_1_2) TASK_2_1(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_2_1) AssignmentTestUtils.assertBalancedActiveAssignment(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.assertBalancedActiveAssignment) Collectors(java.util.stream.Collectors) EMPTY_TASKS(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.EMPTY_TASKS) AssignmentTestUtils.getClientStatesMap(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.getClientStatesMap) Utils.mkEntry(org.apache.kafka.common.utils.Utils.mkEntry) AssignmentTestUtils.assertBalancedStatefulAssignment(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.assertBalancedStatefulAssignment) Matchers.is(org.hamcrest.Matchers.is) AssignmentTestUtils.hasActiveTasks(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.hasActiveTasks) AssignmentTestUtils.assertBalancedTasks(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.assertBalancedTasks) TaskId(org.apache.kafka.streams.processor.TaskId) AssignmentConfigs(org.apache.kafka.streams.processor.internals.assignment.AssignorConfiguration.AssignmentConfigs) UUID(java.util.UUID) Test(org.junit.Test)

Example 4 with TASK_2_0

use of org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_2_0 in project kafka by apache.

the class HighAvailabilityTaskAssignorTest method shouldAssignActiveStatefulTasksEvenlyOverClientsAndStreamThreadsWithEqualStreamThreadsPerClientAsTasks.

@Test
public void shouldAssignActiveStatefulTasksEvenlyOverClientsAndStreamThreadsWithEqualStreamThreadsPerClientAsTasks() {
    final Set<TaskId> allTaskIds = mkSet(TASK_0_0, TASK_0_1, TASK_0_2, TASK_1_0, TASK_1_1, TASK_1_2, TASK_2_0, TASK_2_1, TASK_2_2);
    final Map<TaskId, Long> lags = allTaskIds.stream().collect(Collectors.toMap(k -> k, k -> 10L));
    final ClientState clientState1 = new ClientState(emptySet(), emptySet(), lags, 9);
    final ClientState clientState2 = new ClientState(emptySet(), emptySet(), lags, 9);
    final ClientState clientState3 = new ClientState(emptySet(), emptySet(), lags, 9);
    final Map<UUID, ClientState> clientStates = getClientStatesMap(clientState1, clientState2, clientState3);
    final boolean unstable = new HighAvailabilityTaskAssignor().assign(clientStates, allTaskIds, allTaskIds, new AssignmentConfigs(0L, 1, 0, 60_000L));
    assertThat(unstable, is(false));
    assertValidAssignment(0, allTaskIds, emptySet(), clientStates, new StringBuilder());
    assertBalancedActiveAssignment(clientStates, new StringBuilder());
    assertBalancedStatefulAssignment(allTaskIds, clientStates, new StringBuilder());
    assertBalancedTasks(clientStates);
}
Also used : TaskId(org.apache.kafka.streams.processor.TaskId) AssignmentConfigs(org.apache.kafka.streams.processor.internals.assignment.AssignorConfiguration.AssignmentConfigs) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Matchers.not(org.hamcrest.Matchers.not) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Utils.mkMap(org.apache.kafka.common.utils.Utils.mkMap) AssignmentTestUtils.analyzeTaskAssignmentBalance(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.analyzeTaskAssignmentBalance) Collections.singleton(java.util.Collections.singleton) Map(java.util.Map) AssignmentTestUtils.hasStandbyTasks(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.hasStandbyTasks) Collections.singletonMap(java.util.Collections.singletonMap) Assert.fail(org.junit.Assert.fail) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) UUID_1(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.UUID_1) AssignmentTestUtils.hasAssignedTasks(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.hasAssignedTasks) UUID_3(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.UUID_3) AssignmentTestUtils.assertValidAssignment(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.assertValidAssignment) UUID_2(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.UUID_2) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Collections.emptySet(java.util.Collections.emptySet) TASK_0_0(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_0) Utils.mkSet(org.apache.kafka.common.utils.Utils.mkSet) TASK_0_1(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_1) TASK_1_1(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_1_1) TASK_2_0(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_2_0) Set(java.util.Set) TASK_0_2(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_2) TASK_1_0(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_1_0) Test(org.junit.Test) TASK_0_3(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_3) TASK_1_3(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_1_3) TASK_2_2(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_2_2) UUID(java.util.UUID) TASK_1_2(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_1_2) TASK_2_1(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_2_1) AssignmentTestUtils.assertBalancedActiveAssignment(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.assertBalancedActiveAssignment) Collectors(java.util.stream.Collectors) EMPTY_TASKS(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.EMPTY_TASKS) AssignmentTestUtils.getClientStatesMap(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.getClientStatesMap) Utils.mkEntry(org.apache.kafka.common.utils.Utils.mkEntry) AssignmentTestUtils.assertBalancedStatefulAssignment(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.assertBalancedStatefulAssignment) Matchers.is(org.hamcrest.Matchers.is) AssignmentTestUtils.hasActiveTasks(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.hasActiveTasks) AssignmentTestUtils.assertBalancedTasks(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.assertBalancedTasks) TaskId(org.apache.kafka.streams.processor.TaskId) AssignmentConfigs(org.apache.kafka.streams.processor.internals.assignment.AssignorConfiguration.AssignmentConfigs) UUID(java.util.UUID) Test(org.junit.Test)

Example 5 with TASK_2_0

use of org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_2_0 in project kafka by apache.

the class HighAvailabilityTaskAssignorTest method shouldAssignActiveStatefulTasksEvenlyOverClientsWhereNumberOfThreadsIntegralDivisorOfNumberOfTasks.

@Test
public void shouldAssignActiveStatefulTasksEvenlyOverClientsWhereNumberOfThreadsIntegralDivisorOfNumberOfTasks() {
    final Set<TaskId> allTaskIds = mkSet(TASK_0_0, TASK_0_1, TASK_0_2, TASK_1_0, TASK_1_1, TASK_1_2, TASK_2_0, TASK_2_1, TASK_2_2);
    final Map<TaskId, Long> lags = allTaskIds.stream().collect(Collectors.toMap(k -> k, k -> 10L));
    final ClientState clientState1 = new ClientState(emptySet(), emptySet(), lags, 3);
    final ClientState clientState2 = new ClientState(emptySet(), emptySet(), lags, 3);
    final ClientState clientState3 = new ClientState(emptySet(), emptySet(), lags, 3);
    final Map<UUID, ClientState> clientStates = getClientStatesMap(clientState1, clientState2, clientState3);
    final boolean unstable = new HighAvailabilityTaskAssignor().assign(clientStates, allTaskIds, allTaskIds, new AssignmentConfigs(0L, 1, 0, 60_000L));
    assertThat(unstable, is(false));
    assertValidAssignment(0, allTaskIds, emptySet(), clientStates, new StringBuilder());
    assertBalancedActiveAssignment(clientStates, new StringBuilder());
    assertBalancedStatefulAssignment(allTaskIds, clientStates, new StringBuilder());
    assertBalancedTasks(clientStates);
}
Also used : TaskId(org.apache.kafka.streams.processor.TaskId) AssignmentConfigs(org.apache.kafka.streams.processor.internals.assignment.AssignorConfiguration.AssignmentConfigs) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Matchers.not(org.hamcrest.Matchers.not) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Utils.mkMap(org.apache.kafka.common.utils.Utils.mkMap) AssignmentTestUtils.analyzeTaskAssignmentBalance(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.analyzeTaskAssignmentBalance) Collections.singleton(java.util.Collections.singleton) Map(java.util.Map) AssignmentTestUtils.hasStandbyTasks(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.hasStandbyTasks) Collections.singletonMap(java.util.Collections.singletonMap) Assert.fail(org.junit.Assert.fail) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) UUID_1(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.UUID_1) AssignmentTestUtils.hasAssignedTasks(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.hasAssignedTasks) UUID_3(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.UUID_3) AssignmentTestUtils.assertValidAssignment(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.assertValidAssignment) UUID_2(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.UUID_2) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Collections.emptySet(java.util.Collections.emptySet) TASK_0_0(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_0) Utils.mkSet(org.apache.kafka.common.utils.Utils.mkSet) TASK_0_1(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_1) TASK_1_1(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_1_1) TASK_2_0(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_2_0) Set(java.util.Set) TASK_0_2(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_2) TASK_1_0(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_1_0) Test(org.junit.Test) TASK_0_3(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_3) TASK_1_3(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_1_3) TASK_2_2(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_2_2) UUID(java.util.UUID) TASK_1_2(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_1_2) TASK_2_1(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_2_1) AssignmentTestUtils.assertBalancedActiveAssignment(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.assertBalancedActiveAssignment) Collectors(java.util.stream.Collectors) EMPTY_TASKS(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.EMPTY_TASKS) AssignmentTestUtils.getClientStatesMap(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.getClientStatesMap) Utils.mkEntry(org.apache.kafka.common.utils.Utils.mkEntry) AssignmentTestUtils.assertBalancedStatefulAssignment(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.assertBalancedStatefulAssignment) Matchers.is(org.hamcrest.Matchers.is) AssignmentTestUtils.hasActiveTasks(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.hasActiveTasks) AssignmentTestUtils.assertBalancedTasks(org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.assertBalancedTasks) TaskId(org.apache.kafka.streams.processor.TaskId) AssignmentConfigs(org.apache.kafka.streams.processor.internals.assignment.AssignorConfiguration.AssignmentConfigs) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

Collections.emptySet (java.util.Collections.emptySet)5 Collections.singleton (java.util.Collections.singleton)5 Collections.singletonMap (java.util.Collections.singletonMap)5 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 Map (java.util.Map)5 Set (java.util.Set)5 UUID (java.util.UUID)5 Collectors (java.util.stream.Collectors)5 Utils.mkEntry (org.apache.kafka.common.utils.Utils.mkEntry)5 Utils.mkMap (org.apache.kafka.common.utils.Utils.mkMap)5 Utils.mkSet (org.apache.kafka.common.utils.Utils.mkSet)5 TaskId (org.apache.kafka.streams.processor.TaskId)5 EMPTY_TASKS (org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.EMPTY_TASKS)5 TASK_0_0 (org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_0)5 TASK_0_1 (org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_1)5 TASK_0_2 (org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_2)5 TASK_0_3 (org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_0_3)5 TASK_1_0 (org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_1_0)5 TASK_1_1 (org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.TASK_1_1)5