forked from confluentinc/parallel-consumer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7146ad
commit 01782c6
Showing
4 changed files
with
109 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,7 @@ hs_err_pid* | |
*.iml | ||
target/ | ||
.DS_Store | ||
*.versionsBackup | ||
*.versionsBackup | ||
|
||
# JENV | ||
.java-version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...-example-core/src/test/java/io/confluent/parallelconsumer/examples/core/Bug25AppTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package io.confluent.parallelconsumer.examples.core; | ||
|
||
/*- | ||
* Copyright (C) 2020 Confluent, Inc. | ||
*/ | ||
|
||
import io.confluent.parallelconsumer.integrationTests.KafkaTest; | ||
import lombok.SneakyThrows; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.kafka.clients.consumer.Consumer; | ||
import org.apache.kafka.clients.consumer.ConsumerConfig; | ||
import org.apache.kafka.clients.consumer.KafkaConsumer; | ||
import org.apache.kafka.clients.producer.Producer; | ||
import org.apache.kafka.clients.producer.ProducerRecord; | ||
import org.assertj.core.api.Assertions; | ||
import org.awaitility.Awaitility; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.Duration; | ||
import java.util.Properties; | ||
|
||
@Slf4j | ||
public class Bug25AppTest extends KafkaTest<String, String> { | ||
|
||
@SneakyThrows | ||
@Test | ||
public void test() { | ||
log.info("Test start"); | ||
ensureTopic(CoreApp.inputTopic, 1); | ||
ensureTopic(CoreApp.outputTopic, 1); | ||
|
||
|
||
AppUnderTest coreApp = new AppUnderTest(); | ||
|
||
log.info("Producing 1000 messages before starting application"); | ||
try (Producer<String, String> kafkaProducer = kcu.createNewProducer(false)) { | ||
for (int i = 0; i < 1000; i++) { | ||
kafkaProducer.send(new ProducerRecord<>(CoreApp.inputTopic, "key-" + i, "value-" + i)); | ||
} | ||
} | ||
|
||
log.info("Starting application..."); | ||
coreApp.runPollAndProduce(); | ||
|
||
Awaitility.waitAtMost(Duration.ofSeconds(30)).untilAsserted(() -> { | ||
log.info("Processed-count: " + coreApp.messagesProcessed.get()); | ||
log.info("Produced-count: " + coreApp.messagesProduced.get()); | ||
Assertions.assertThat(coreApp.messagesProcessed.get()).isEqualTo(1000); | ||
Assertions.assertThat(coreApp.messagesProduced.get()).isEqualTo(1000); | ||
}); | ||
|
||
coreApp.close(); | ||
} | ||
|
||
class AppUnderTest extends CoreApp { | ||
|
||
@Override | ||
Consumer<String, String> getKafkaConsumer() { | ||
Properties props = kcu.props; | ||
// props.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, 1); // Sometimes causes test to fail | ||
// props.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, 10000); Invalid transition attempted from state READY to state COMMITTING_TRANSACTION | ||
return new KafkaConsumer<>(props); | ||
} | ||
|
||
@Override | ||
Producer<String, String> getKafkaProducer() { | ||
return kcu.createNewProducer(true); | ||
} | ||
} | ||
} |