-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
And move config related test in the config package.
- Loading branch information
1 parent
9fd2371
commit 3b30bce
Showing
5 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
.../src/test/java/io/smallrye/reactive/messaging/kafka/config/ConfigOverrideFromEnvTest.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,71 @@ | ||
package io.smallrye.reactive.messaging.kafka.config; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
import java.time.Duration; | ||
import java.util.List; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import org.apache.kafka.clients.consumer.ConsumerConfig; | ||
import org.apache.kafka.clients.producer.ProducerRecord; | ||
import org.apache.kafka.common.serialization.StringDeserializer; | ||
import org.eclipse.microprofile.reactive.messaging.Incoming; | ||
import org.junit.jupiter.api.Test; | ||
import org.junitpioneer.jupiter.SetEnvironmentVariable; | ||
|
||
import io.smallrye.reactive.messaging.kafka.KafkaConnector; | ||
import io.smallrye.reactive.messaging.kafka.base.KafkaBrokerExtension; | ||
import io.smallrye.reactive.messaging.kafka.base.KafkaTestBase; | ||
import io.smallrye.reactive.messaging.test.common.config.MapBasedConfig; | ||
|
||
public class ConfigOverrideFromEnvTest extends KafkaTestBase { | ||
|
||
final static String TOPIC = "ConfigOverrideFromEnvTest-Topic"; | ||
|
||
@Test | ||
@SetEnvironmentVariable(key = "MP_MESSAGING_INCOMING_MY_CHANNEL_TOPIC", value = TOPIC) | ||
public void testOverridingTopicFromEnv() throws InterruptedException { | ||
MapBasedConfig config = new MapBasedConfig() | ||
.with("mp.messaging.incoming.my-channel.graceful-shutdown", false) | ||
.with("mp.messaging.incoming.my-channel.topic", "should not be used") | ||
.with("mp.messaging.incoming.my-channel.bootstrap.servers", KafkaBrokerExtension.getBootstrapServers()) | ||
.with("mp.messaging.incoming.my-channel.connector", | ||
KafkaConnector.CONNECTOR_NAME) | ||
.with("mp.messaging.incoming.my-channel.value.deserializer", | ||
StringDeserializer.class.getName()) | ||
.with("mp.messaging.incoming.my-channel." | ||
+ ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); | ||
|
||
Consumer consumer = runApplication(config, Consumer.class); | ||
await().until(() -> isReady() && isAlive()); | ||
|
||
CountDownLatch latch = new CountDownLatch(1); | ||
usage.produceStrings(5, latch::countDown, () -> new ProducerRecord<>(TOPIC, "key", "hello")); | ||
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue(); | ||
|
||
await() | ||
.atMost(Duration.ofMinutes(1)) | ||
.until(() -> consumer.list().size() == 5); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class Consumer { | ||
|
||
private final List<String> list = new CopyOnWriteArrayList<>(); | ||
|
||
@Incoming("my-channel") | ||
public void consume(String data) { | ||
list.add(data); | ||
} | ||
|
||
public List<String> list() { | ||
return list; | ||
} | ||
} | ||
|
||
} |
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
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
2 changes: 1 addition & 1 deletion
2
.../messaging/kafka/EnvAndSysConfigTest.java → ...ing/kafka/config/EnvAndSysConfigTest.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