GeezerVison is showing github.com — KAFKA-20684 [6/N]: Migrate core integration tests to RebalanceListene… · coderbruis/kafka@831fdfe
File treeExpand file treeCollapse file tree Open diff view settings core/src/test/scala/integration/kafka/api
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: core/src/test/scala/integration/kafka/api/AbstractConsumerTest.scala +13-11Lines changed: 13 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -162,16 +162,16 @@ abstract class AbstractConsumerTest extends BaseRequestTest { | 162 | 162 | Some(s"Did not get valid assignment for partitions ${subscriptions.asJava} after we changed subscription")) | 163 | 163 | } | 164 | 164 |
| 165 | | - protected class TestConsumerReassignmentListener extends ConsumerRebalanceListener { | | 165 | + protected class TestConsumerReassignmentListener extends RebalanceListener { | 166 | 166 | var callsToAssigned = 0 | 167 | 167 | var callsToRevoked = 0 | 168 | 168 |
| 169 | | - def onPartitionsAssigned(partitions: java.util.Collection[TopicPartition]): Unit = { | | 169 | + def onPartitionsAssigned(partitions: java.util.Collection[TopicPartition], rebalanceConsumer: RebalanceConsumer): Unit = { | 170 | 170 | info("onPartitionsAssigned called.") | 171 | 171 | callsToAssigned += 1 | 172 | 172 | } | 173 | 173 |
| 174 | | - def onPartitionsRevoked(partitions: java.util.Collection[TopicPartition]): Unit = { | | 174 | + def onPartitionsRevoked(partitions: java.util.Collection[TopicPartition], rebalanceConsumer: RebalanceConsumer): Unit = { | 175 | 175 | info("onPartitionsRevoked called.") | 176 | 176 | callsToRevoked += 1 | 177 | 177 | } | @@ -434,7 +434,7 @@ abstract class AbstractConsumerTest extends BaseRequestTest { | 434 | 434 | protected class ConsumerAssignmentPoller(consumer: Consumer[Array[Byte], Array[Byte]], | 435 | 435 | topicsToSubscribe: List[String], | 436 | 436 | partitionsToAssign: Set[TopicPartition], | 437 | | - userRebalanceListener: ConsumerRebalanceListener) | | 437 | + userRebalanceListener: RebalanceListener) | 438 | 438 | extends ShutdownableThread("daemon-consumer-assignment", false) { | 439 | 439 |
| 440 | 440 | def this(consumer: Consumer[Array[Byte], Array[Byte]], topicsToSubscribe: List[String]) = { | @@ -452,22 +452,23 @@ abstract class AbstractConsumerTest extends BaseRequestTest { | 452 | 452 | @volatile private var subscriptionChanged = false | 453 | 453 | private var topicsSubscription = topicsToSubscribe | 454 | 454 |
| 455 | | - val rebalanceListener: ConsumerRebalanceListener = new ConsumerRebalanceListener { | 456 | | - override def onPartitionsAssigned(partitions: util.Collection[TopicPartition]): Unit = { | | 455 | + val rebalanceListener: RebalanceListener = new RebalanceListener { | | 456 | + override def onPartitionsAssigned(partitions: util.Collection[TopicPartition], rebalanceConsumer: RebalanceConsumer): Unit = { | 457 | 457 | partitionAssignment ++= partitions.toArray(new Array[TopicPartition](0)) | 458 | 458 | if (userRebalanceListener != null) | 459 | | - userRebalanceListener.onPartitionsAssigned(partitions) | | 459 | + userRebalanceListener.onPartitionsAssigned(partitions, rebalanceConsumer) | 460 | 460 | } | 461 | 461 |
| 462 | | - override def onPartitionsRevoked(partitions: util.Collection[TopicPartition]): Unit = { | | 462 | + override def onPartitionsRevoked(partitions: util.Collection[TopicPartition], rebalanceConsumer: RebalanceConsumer): Unit = { | 463 | 463 | partitionAssignment --= partitions.toArray(new Array[TopicPartition](0)) | 464 | 464 | if (userRebalanceListener != null) | 465 | | - userRebalanceListener.onPartitionsRevoked(partitions) | | 465 | + userRebalanceListener.onPartitionsRevoked(partitions, rebalanceConsumer) | 466 | 466 | } | 467 | 467 | } | 468 | 468 |
| 469 | 469 | if (partitionsToAssign.isEmpty) { | 470 | | - consumer.subscribe(topicsToSubscribe.asJava, rebalanceListener) | | 470 | + consumer.setRebalanceListener(rebalanceListener) | | 471 | + consumer.subscribe(topicsToSubscribe.asJava) | 471 | 472 | } else { | 472 | 473 | consumer.assign(partitionsToAssign.asJava) | 473 | 474 | } | @@ -508,7 +509,8 @@ abstract class AbstractConsumerTest extends BaseRequestTest { | 508 | 509 |
| 509 | 510 | override def doWork(): Unit = { | 510 | 511 | if (subscriptionChanged) { | 511 | | - consumer.subscribe(topicsSubscription.asJava, rebalanceListener) | | 512 | + consumer.setRebalanceListener(rebalanceListener) | | 513 | + consumer.subscribe(topicsSubscription.asJava) | 512 | 514 | subscriptionChanged = false | 513 | 515 | } | 514 | 516 | try { | |
Collapse file Copy file name to clipboardExpand all lines: core/src/test/scala/integration/kafka/api/AuthorizerIntegrationTest.scala +8-6Lines changed: 8 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1507,12 +1507,13 @@ class AuthorizerIntegrationTest extends AbstractAuthorizerIntegrationTest { | 1507 | 1507 | addAndVerifyAcls(Set(new AccessControlEntry(clientPrincipalString, WILDCARD_HOST, READ, ALLOW)), groupResource) | 1508 | 1508 |
| 1509 | 1509 | val consumer = createConsumer() | 1510 | | - consumer.subscribe(Pattern.compile(topicPattern), new ConsumerRebalanceListener { | 1511 | | - def onPartitionsAssigned(partitions: util.Collection[TopicPartition]): Unit = { | | 1510 | + consumer.setRebalanceListener(new RebalanceListener { | | 1511 | + def onPartitionsAssigned(partitions: util.Collection[TopicPartition], rebalanceConsumer: RebalanceConsumer): Unit = { | 1512 | 1512 | assignSemaphore.release() | 1513 | 1513 | } | 1514 | | - def onPartitionsRevoked(partitions: util.Collection[TopicPartition]): Unit = { | | 1514 | + def onPartitionsRevoked(partitions: util.Collection[TopicPartition], rebalanceConsumer: RebalanceConsumer): Unit = { | 1515 | 1515 | }}) | | 1516 | + consumer.subscribe(Pattern.compile(topicPattern)) | 1516 | 1517 | TestUtils.waitUntilTrue(() => { | 1517 | 1518 | consumer.poll(Duration.ofMillis(500)) | 1518 | 1519 | assignSemaphore.tryAcquire() | @@ -1565,12 +1566,13 @@ class AuthorizerIntegrationTest extends AbstractAuthorizerIntegrationTest { | 1565 | 1566 | // internal topics are not included, we should not be assigned any partitions from this topic | 1566 | 1567 | addAndVerifyAcls(Set(new AccessControlEntry(clientPrincipalString, WILDCARD_HOST, READ, ALLOW)), new ResourcePattern(TOPIC, | 1567 | 1568 | GROUP_METADATA_TOPIC_NAME, LITERAL)) | 1568 | | - consumer.subscribe(Pattern.compile(GROUP_METADATA_TOPIC_NAME), new ConsumerRebalanceListener { | 1569 | | - def onPartitionsAssigned(partitions: util.Collection[TopicPartition]): Unit = { | | 1569 | + consumer.setRebalanceListener(new RebalanceListener { | | 1570 | + def onPartitionsAssigned(partitions: util.Collection[TopicPartition], rebalanceConsumer: RebalanceConsumer): Unit = { | 1570 | 1571 | assignSemaphore.release() | 1571 | 1572 | } | 1572 | | - def onPartitionsRevoked(partitions: util.Collection[TopicPartition]): Unit = { | | 1573 | + def onPartitionsRevoked(partitions: util.Collection[TopicPartition], rebalanceConsumer: RebalanceConsumer): Unit = { | 1573 | 1574 | }}) | | 1575 | + consumer.subscribe(Pattern.compile(GROUP_METADATA_TOPIC_NAME)) | 1574 | 1576 | TestUtils.waitUntilTrue(() => { | 1575 | 1577 | consumer.poll(Duration.ofMillis(500)) | 1576 | 1578 | assignSemaphore.tryAcquire() | |
Collapse file Copy file name to clipboardExpand all lines: core/src/test/scala/integration/kafka/api/BaseConsumerTest.scala +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -111,7 +111,8 @@ abstract class BaseConsumerTest extends AbstractConsumerTest { | 111 | 111 | this.consumerConfig.setProperty(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG, "15000") | 112 | 112 | val consumer = createConsumer() | 113 | 113 |
| 114 | | - consumer.subscribe(java.util.List.of(topic), listener) | | 114 | + consumer.setRebalanceListener(listener) | | 115 | + consumer.subscribe(java.util.List.of(topic)) | 115 | 116 |
| 116 | 117 | // the initial subscription should cause a callback execution | 117 | 118 | awaitRebalance(consumer, listener) | |
Collapse file Copy file name to clipboardExpand all lines: core/src/test/scala/integration/kafka/api/PlaintextAdminIntegrationTest.scala +5-4Lines changed: 5 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -35,7 +35,7 @@ import org.apache.kafka.clients.admin.AlterConfigOp.OpType | 35 | 35 | import org.apache.kafka.clients.admin.ConfigEntry.ConfigSource | 36 | 36 | import org.apache.kafka.clients.admin._ | 37 | 37 | import org.apache.kafka.clients.consumer.internals.AsyncKafkaConsumer | 38 | | -import org.apache.kafka.clients.consumer.{CommitFailedException, Consumer, ConsumerConfig, ConsumerRebalanceListener, ConsumerRecords, GroupProtocol, KafkaConsumer, OffsetAndMetadata, ShareConsumer} | | 38 | +import org.apache.kafka.clients.consumer.{CommitFailedException, Consumer, ConsumerConfig, ConsumerRecords, GroupProtocol, KafkaConsumer, OffsetAndMetadata, RebalanceConsumer, RebalanceListener, ShareConsumer} | 39 | 39 | import org.apache.kafka.clients.producer.{KafkaProducer, ProducerConfig, ProducerRecord} | 40 | 40 | import org.apache.kafka.common.acl.{AccessControlEntry, AclBinding, AclBindingFilter, AclOperation, AclPermissionType} | 41 | 41 | import org.apache.kafka.common.config.{ConfigResource, LogLevelConfig, SslConfigs, TopicConfig} | @@ -3887,15 +3887,16 @@ class PlaintextAdminIntegrationTest extends BaseAdminIntegrationTest { | 3887 | 3887 | new Thread { | 3888 | 3888 | override def run : Unit = { | 3889 | 3889 | var started = false | 3890 | | - consumer.subscribe(util.Set.of(topic), new ConsumerRebalanceListener { | 3891 | | - override def onPartitionsRevoked(partitions: util.Collection[TopicPartition]): Unit = {} | 3892 | | - override def onPartitionsAssigned(partitions: util.Collection[TopicPartition]): Unit = { | | 3890 | + consumer.setRebalanceListener(new RebalanceListener { | | 3891 | + override def onPartitionsRevoked(partitions: util.Collection[TopicPartition], rebalanceConsumer: RebalanceConsumer): Unit = {} | | 3892 | + override def onPartitionsAssigned(partitions: util.Collection[TopicPartition], rebalanceConsumer: RebalanceConsumer): Unit = { | 3893 | 3893 | if (!started) { | 3894 | 3894 | startLatch.countDown() | 3895 | 3895 | started = true | 3896 | 3896 | } | 3897 | 3897 | } | 3898 | 3898 | }) | | 3899 | + consumer.subscribe(util.Set.of(topic)) | 3899 | 3900 | try { | 3900 | 3901 | while (consumerThreadRunning.get()) { | 3901 | 3902 | consumer.poll(JDuration.ofSeconds(5)) | |
|