use of org.apache.kafka.clients.consumer.ConsumerPartitionAssignor in project kafka by apache.
the class ConsumerCoordinatorTest method testPerformAssignmentShouldSkipValidateCooperativeAssignmentForBuiltInCooperativeStickyAssignor.
@Test
public void testPerformAssignmentShouldSkipValidateCooperativeAssignmentForBuiltInCooperativeStickyAssignor() {
SubscriptionState mockSubscriptionState = Mockito.mock(SubscriptionState.class);
List<JoinGroupResponseData.JoinGroupResponseMember> metadata = validateCooperativeAssignmentTestSetup();
List<ConsumerPartitionAssignor> assignorsWithCooperativeStickyAssignor = new ArrayList<>(assignors);
// create a mockPartitionAssignor with the same name as cooperative sticky assignor
MockPartitionAssignor mockCooperativeStickyAssignor = new MockPartitionAssignor(Collections.singletonList(protocol)) {
@Override
public String name() {
return COOPERATIVE_STICKY_ASSIGNOR_NAME;
}
};
assignorsWithCooperativeStickyAssignor.add(mockCooperativeStickyAssignor);
// simulate the cooperative sticky assignor do the assignment with out-of-date ownedPartition
Map<String, List<TopicPartition>> assignment = new HashMap<>();
assignment.put(consumerId, Arrays.asList(t1p));
assignment.put(consumerId2, Arrays.asList(t2p));
mockCooperativeStickyAssignor.prepare(assignment);
try (ConsumerCoordinator coordinator = buildCoordinator(rebalanceConfig, new Metrics(), assignorsWithCooperativeStickyAssignor, false, mockSubscriptionState)) {
// should not validate assignment for built-in cooperative sticky assignor
coordinator.onLeaderElected("1", mockCooperativeStickyAssignor.name(), metadata, false);
}
}
use of org.apache.kafka.clients.consumer.ConsumerPartitionAssignor in project kafka by apache.
the class ConsumerCoordinatorTest method testOnLeaderElectedShouldSkipAssignment.
@Test
public void testOnLeaderElectedShouldSkipAssignment() {
SubscriptionState mockSubscriptionState = Mockito.mock(SubscriptionState.class);
ConsumerPartitionAssignor assignor = Mockito.mock(ConsumerPartitionAssignor.class);
String assignorName = "mock-assignor";
Mockito.when(assignor.name()).thenReturn(assignorName);
Mockito.when(assignor.supportedProtocols()).thenReturn(Collections.singletonList(protocol));
Map<String, List<String>> memberSubscriptions = singletonMap(consumerId, singletonList(topic1));
List<JoinGroupResponseData.JoinGroupResponseMember> metadata = new ArrayList<>();
for (Map.Entry<String, List<String>> subscriptionEntry : memberSubscriptions.entrySet()) {
ConsumerPartitionAssignor.Subscription subscription = new ConsumerPartitionAssignor.Subscription(subscriptionEntry.getValue());
ByteBuffer buf = ConsumerProtocol.serializeSubscription(subscription);
metadata.add(new JoinGroupResponseData.JoinGroupResponseMember().setMemberId(subscriptionEntry.getKey()).setMetadata(buf.array()));
}
try (ConsumerCoordinator coordinator = buildCoordinator(rebalanceConfig, new Metrics(), Collections.singletonList(assignor), false, mockSubscriptionState)) {
assertEquals(Collections.emptyMap(), coordinator.onLeaderElected("1", assignorName, metadata, true));
assertTrue(coordinator.isLeader());
}
Mockito.verify(assignor, Mockito.never()).assign(Mockito.any(), Mockito.any());
}
Aggregations