ableegoldman commented on a change in pull request #8892: URL: https://github.com/apache/kafka/pull/8892#discussion_r488267594
########## File path: streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsAssignmentScaleTest.java ########## @@ -0,0 +1,224 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kafka.streams.processor.internals; + +import static java.util.Arrays.asList; +import static java.util.Collections.emptySet; +import static java.util.Collections.singletonList; +import static org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.EMPTY_TASKS; +import static org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.createMockAdminClientForAssignor; +import static org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.getInfo; +import static org.apache.kafka.streams.processor.internals.assignment.AssignmentTestUtils.uuidForInt; +import static org.easymock.EasyMock.expect; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; +import org.apache.kafka.clients.admin.AdminClient; +import org.apache.kafka.clients.consumer.Consumer; +import org.apache.kafka.clients.consumer.ConsumerPartitionAssignor.Assignment; +import org.apache.kafka.clients.consumer.ConsumerPartitionAssignor.GroupSubscription; +import org.apache.kafka.clients.consumer.ConsumerPartitionAssignor.Subscription; +import org.apache.kafka.common.Cluster; +import org.apache.kafka.common.Node; +import org.apache.kafka.common.PartitionInfo; +import org.apache.kafka.common.TopicPartition; +import org.apache.kafka.common.utils.MockTime; +import org.apache.kafka.streams.StreamsConfig; +import org.apache.kafka.streams.StreamsConfig.InternalConfig; +import org.apache.kafka.streams.processor.internals.assignment.AssignmentInfo; +import org.apache.kafka.streams.processor.internals.assignment.FallbackPriorTaskAssignor; +import org.apache.kafka.streams.processor.internals.assignment.HighAvailabilityTaskAssignor; +import org.apache.kafka.streams.processor.internals.assignment.StickyTaskAssignor; +import org.apache.kafka.streams.processor.internals.assignment.TaskAssignor; +import org.apache.kafka.test.MockApiProcessorSupplier; +import org.apache.kafka.test.MockClientSupplier; +import org.apache.kafka.test.MockInternalTopicManager; +import org.apache.kafka.test.MockKeyValueStoreBuilder; +import org.easymock.EasyMock; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@RunWith(value = Parameterized.class) +public class StreamsAssignmentScaleTest { + final static long MAX_ASSIGNMENT_DURATION = 60 * 1000L; //each individual assignment should complete within 20s + final static String APPLICATION_ID = "streams-assignment-scale-test"; + + private final Logger log = LoggerFactory.getLogger(StreamsAssignmentScaleTest.class); + + private final Class<? extends TaskAssignor> taskAssignor; + + @Parameterized.Parameters(name = "task assignor = {0}") + public static Collection<Object[]> parameters() { + return asList( + new Object[]{StickyTaskAssignor.class}, + new Object[]{HighAvailabilityTaskAssignor.class}, + new Object[]{FallbackPriorTaskAssignor.class} + ); + } + + public StreamsAssignmentScaleTest(final Class<? extends TaskAssignor> taskAssignor) { + this.taskAssignor = taskAssignor; + } + + @Test(timeout = 120 * 1000) + public void testLargePartitionCount() { + shouldCompleteLargeAssignmentInReasonableTime(3_000, 1, 1, 1); + } + + @Test(timeout = 120 * 1000) + public void testLargeNumConsumers() { + shouldCompleteLargeAssignmentInReasonableTime(1_000, 1_000, 1, 1); + } + + @Test(timeout = 120 * 1000) + public void testManyStandbys() { + shouldCompleteLargeAssignmentInReasonableTime(1_000, 100, 1, 50); + } + + @Test(timeout = 120 * 1000) + public void testManyThreadsPerClient() { + shouldCompleteLargeAssignmentInReasonableTime(1_000, 10, 1000, 1); + } + + private void shouldCompleteLargeAssignmentInReasonableTime(final int numPartitions, + final int numClients, + final int numThreadsPerClient, + final int numStandbys) { + final List<String> topic = singletonList("topic"); + final Map<TopicPartition, Long> changelogEndOffsets = new HashMap<>(); + for (int p = 0; p < numPartitions; ++p) { + changelogEndOffsets.put(new TopicPartition(APPLICATION_ID + "-store-changelog", p), 100_000L); + } + final List<PartitionInfo> partitionInfos = getPartitionInfos(numPartitions); + final Cluster clusterMetadata = new Cluster( + "cluster", + Collections.singletonList(Node.noNode()), + partitionInfos, + emptySet(), + emptySet() + ); + + final InternalTopologyBuilder builder = new InternalTopologyBuilder(); + builder.addSource(null, "source", null, null, null, "topic"); + builder.addProcessor("processor", new MockApiProcessorSupplier<>(), "source"); + builder.addStateStore(new MockKeyValueStoreBuilder("store", false), "processor"); + builder.setApplicationId(APPLICATION_ID); + builder.buildTopology(); + + final Consumer<byte[], byte[]> mainConsumer = EasyMock.createNiceMock(Consumer.class); + final TaskManager taskManager = EasyMock.createNiceMock(TaskManager.class); + expect(taskManager.builder()).andReturn(builder).anyTimes(); Review comment: I copied this over from StreamsPartitionAssignorTest, I'll fix it over there too ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org