From e89c6d930b262e079cb375a0b60191a745e2b59f Mon Sep 17 00:00:00 2001 From: chickenchickenlove Date: Thu, 9 May 2024 19:57:48 +0900 Subject: [PATCH] apply review --- samples/sample-07/.gitignore | 37 +++++++++++++++++++ .../NewConsumerRebalanceProtocolTest.java | 37 ++++++++++++++++++- 2 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 samples/sample-07/.gitignore diff --git a/samples/sample-07/.gitignore b/samples/sample-07/.gitignore new file mode 100644 index 000000000..c2065bc26 --- /dev/null +++ b/samples/sample-07/.gitignore @@ -0,0 +1,37 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ diff --git a/samples/sample-07/src/test/java/com/example/sample07/NewConsumerRebalanceProtocolTest.java b/samples/sample-07/src/test/java/com/example/sample07/NewConsumerRebalanceProtocolTest.java index 2ab7a7e94..f192062a1 100644 --- a/samples/sample-07/src/test/java/com/example/sample07/NewConsumerRebalanceProtocolTest.java +++ b/samples/sample-07/src/test/java/com/example/sample07/NewConsumerRebalanceProtocolTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2022-2024 the original author or authors. + * + * Licensed 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 + * + * https://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 com.example.sample07; import org.apache.kafka.clients.consumer.Consumer; @@ -36,6 +52,15 @@ import static org.assertj.core.api.Assertions.assertThat; +/** + * New consumer rebalance protocol sample which purpose is only to be used in the test assertions. + * In this sample, Testcontainers is used for testing instead of @EmbeddedKafka. + * See unit tests for this project for more information. + * + * @author Sanghyeok An. + * + * @since 3.3 + */ @SpringBootTest @DirtiesContext public class NewConsumerRebalanceProtocolTest { @@ -59,8 +84,17 @@ public class NewConsumerRebalanceProtocolTest { CountDownLatch rawConsumerAssignedCount; + /* + Test Scenario + 1. spring-kafka consumer subscribe hello-topic. (1st consumer rebalancing occurs) + 2. rawKafkaConsumer subscribe hello-topic, too. (2nd consumer rebalancing occurs) + 3. rawKafkaConsumer is closed. (3rd consumer rebalancing occurs) + + Execute this step and check side effect by ConsumerRebalancing at each step, + testing the new consumer rebalancing protocol. + */ @Test - public void test3() throws InterruptedException, ExecutionException { + public void newConsumerRebalancingProtocolTest() throws InterruptedException, ExecutionException { // One spring-kafka listener subscribe final MessageListenerContainer listenerContainer = registry.getListenerContainer(GROUP_ID); @@ -109,7 +143,6 @@ public void test3() throws InterruptedException, ExecutionException { assertThat(config.partitionRevokedLatch.await(20, TimeUnit.SECONDS)).isTrue(); assertThat(config.partitionAssignedLatch.await(20, TimeUnit.SECONDS)).isTrue(); - // Send two messages each partition to broker. this.template.send(TOPIC_NAME, 0, null, "my-data"); this.template.send(TOPIC_NAME, 1, null,"my-data");