Skip to content

Commit

Permalink
apply review
Browse files Browse the repository at this point in the history
  • Loading branch information
chickenchickenlove committed May 9, 2024
1 parent 8e8113c commit e89c6d9
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
37 changes: 37 additions & 0 deletions samples/sample-07/.gitignore
Original file line number Diff line number Diff line change
@@ -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/
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit e89c6d9

Please sign in to comment.