|
|
@ -67,10 +67,8 @@ public class KafkaAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void consumerProperties() {
|
|
|
|
public void consumerProperties() {
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
|
|
|
.withUserConfiguration(TestConfiguration.class)
|
|
|
|
.withPropertyValues("spring.kafka.bootstrap-servers=foo:1234",
|
|
|
|
.withPropertyValues(
|
|
|
|
|
|
|
|
"spring.kafka.bootstrap-servers=foo:1234",
|
|
|
|
|
|
|
|
"spring.kafka.properties.foo=bar",
|
|
|
|
"spring.kafka.properties.foo=bar",
|
|
|
|
"spring.kafka.properties.baz=qux",
|
|
|
|
"spring.kafka.properties.baz=qux",
|
|
|
|
"spring.kafka.properties.foo.bar.baz=qux.fiz.buz",
|
|
|
|
"spring.kafka.properties.foo.bar.baz=qux.fiz.buz",
|
|
|
@ -90,53 +88,62 @@ public class KafkaAutoConfigurationTests {
|
|
|
|
"spring.kafka.consumer.group-id=bar",
|
|
|
|
"spring.kafka.consumer.group-id=bar",
|
|
|
|
"spring.kafka.consumer.heartbeat-interval=234",
|
|
|
|
"spring.kafka.consumer.heartbeat-interval=234",
|
|
|
|
"spring.kafka.consumer.key-deserializer = org.apache.kafka.common.serialization.LongDeserializer",
|
|
|
|
"spring.kafka.consumer.key-deserializer = org.apache.kafka.common.serialization.LongDeserializer",
|
|
|
|
"spring.kafka.consumer.value-deserializer = org.apache.kafka.common.serialization.IntegerDeserializer"
|
|
|
|
"spring.kafka.consumer.value-deserializer = org.apache.kafka.common.serialization.IntegerDeserializer")
|
|
|
|
).run((context) -> {
|
|
|
|
.run((context) -> {
|
|
|
|
DefaultKafkaConsumerFactory<?, ?> consumerFactory = context
|
|
|
|
DefaultKafkaConsumerFactory<?, ?> consumerFactory = context
|
|
|
|
.getBean(DefaultKafkaConsumerFactory.class);
|
|
|
|
.getBean(DefaultKafkaConsumerFactory.class);
|
|
|
|
Map<String, Object> configs = consumerFactory.getConfigurationProperties();
|
|
|
|
Map<String, Object> configs = consumerFactory
|
|
|
|
// common
|
|
|
|
.getConfigurationProperties();
|
|
|
|
assertThat(configs.get(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG))
|
|
|
|
// common
|
|
|
|
.isEqualTo(Collections.singletonList("foo:1234"));
|
|
|
|
assertThat(configs.get(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG))
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_KEY_PASSWORD_CONFIG)).isEqualTo("p1");
|
|
|
|
.isEqualTo(Collections.singletonList("foo:1234"));
|
|
|
|
assertThat((String) configs.get(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG))
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_KEY_PASSWORD_CONFIG))
|
|
|
|
.endsWith(File.separator + "ksLoc");
|
|
|
|
.isEqualTo("p1");
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG)).isEqualTo("p2");
|
|
|
|
assertThat(
|
|
|
|
assertThat((String) configs.get(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG))
|
|
|
|
(String) configs.get(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG))
|
|
|
|
.endsWith(File.separator + "tsLoc");
|
|
|
|
.endsWith(File.separator + "ksLoc");
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG))
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG))
|
|
|
|
.isEqualTo("p3");
|
|
|
|
.isEqualTo("p2");
|
|
|
|
// consumer
|
|
|
|
assertThat((String) configs
|
|
|
|
assertThat(configs.get(ConsumerConfig.CLIENT_ID_CONFIG)).isEqualTo("ccid"); // override
|
|
|
|
.get(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG))
|
|
|
|
assertThat(configs.get(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG))
|
|
|
|
.endsWith(File.separator + "tsLoc");
|
|
|
|
.isEqualTo(Boolean.FALSE);
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG))
|
|
|
|
assertThat(configs.get(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG))
|
|
|
|
.isEqualTo("p3");
|
|
|
|
.isEqualTo(123);
|
|
|
|
// consumer
|
|
|
|
assertThat(configs.get(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG))
|
|
|
|
assertThat(configs.get(ConsumerConfig.CLIENT_ID_CONFIG))
|
|
|
|
.isEqualTo("earliest");
|
|
|
|
.isEqualTo("ccid"); // override
|
|
|
|
assertThat(configs.get(ConsumerConfig.FETCH_MAX_WAIT_MS_CONFIG)).isEqualTo(456);
|
|
|
|
assertThat(configs.get(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG))
|
|
|
|
assertThat(configs.get(ConsumerConfig.FETCH_MIN_BYTES_CONFIG)).isEqualTo(789);
|
|
|
|
.isEqualTo(Boolean.FALSE);
|
|
|
|
assertThat(configs.get(ConsumerConfig.GROUP_ID_CONFIG)).isEqualTo("bar");
|
|
|
|
assertThat(configs.get(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG))
|
|
|
|
assertThat(configs.get(ConsumerConfig.HEARTBEAT_INTERVAL_MS_CONFIG))
|
|
|
|
.isEqualTo(123);
|
|
|
|
.isEqualTo(234);
|
|
|
|
assertThat(configs.get(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG))
|
|
|
|
assertThat(configs.get(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG))
|
|
|
|
.isEqualTo("earliest");
|
|
|
|
.isEqualTo(LongDeserializer.class);
|
|
|
|
assertThat(configs.get(ConsumerConfig.FETCH_MAX_WAIT_MS_CONFIG))
|
|
|
|
assertThat(configs.get(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG))
|
|
|
|
.isEqualTo(456);
|
|
|
|
.isEqualTo(IntegerDeserializer.class);
|
|
|
|
assertThat(configs.get(ConsumerConfig.FETCH_MIN_BYTES_CONFIG))
|
|
|
|
assertThat(configs.get(ConsumerConfig.MAX_POLL_RECORDS_CONFIG)).isEqualTo(42);
|
|
|
|
.isEqualTo(789);
|
|
|
|
assertThat(configs.get("foo")).isEqualTo("bar");
|
|
|
|
assertThat(configs.get(ConsumerConfig.GROUP_ID_CONFIG))
|
|
|
|
assertThat(configs.get("baz")).isEqualTo("qux");
|
|
|
|
.isEqualTo("bar");
|
|
|
|
assertThat(configs.get("foo.bar.baz")).isEqualTo("qux.fiz.buz");
|
|
|
|
assertThat(configs.get(ConsumerConfig.HEARTBEAT_INTERVAL_MS_CONFIG))
|
|
|
|
assertThat(configs.get("fiz.buz")).isEqualTo("fix.fox");
|
|
|
|
.isEqualTo(234);
|
|
|
|
});
|
|
|
|
assertThat(configs.get(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG))
|
|
|
|
|
|
|
|
.isEqualTo(LongDeserializer.class);
|
|
|
|
|
|
|
|
assertThat(
|
|
|
|
|
|
|
|
configs.get(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG))
|
|
|
|
|
|
|
|
.isEqualTo(IntegerDeserializer.class);
|
|
|
|
|
|
|
|
assertThat(configs.get(ConsumerConfig.MAX_POLL_RECORDS_CONFIG))
|
|
|
|
|
|
|
|
.isEqualTo(42);
|
|
|
|
|
|
|
|
assertThat(configs.get("foo")).isEqualTo("bar");
|
|
|
|
|
|
|
|
assertThat(configs.get("baz")).isEqualTo("qux");
|
|
|
|
|
|
|
|
assertThat(configs.get("foo.bar.baz")).isEqualTo("qux.fiz.buz");
|
|
|
|
|
|
|
|
assertThat(configs.get("fiz.buz")).isEqualTo("fix.fox");
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void producerProperties() {
|
|
|
|
public void producerProperties() {
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
|
|
|
.withUserConfiguration(TestConfiguration.class)
|
|
|
|
.withPropertyValues("spring.kafka.clientId=cid",
|
|
|
|
.withPropertyValues(
|
|
|
|
|
|
|
|
"spring.kafka.clientId=cid",
|
|
|
|
|
|
|
|
"spring.kafka.properties.foo.bar.baz=qux.fiz.buz",
|
|
|
|
"spring.kafka.properties.foo.bar.baz=qux.fiz.buz",
|
|
|
|
"spring.kafka.producer.acks=all",
|
|
|
|
"spring.kafka.producer.acks=all",
|
|
|
|
"spring.kafka.producer.batch-size=20",
|
|
|
|
"spring.kafka.producer.batch-size=20",
|
|
|
@ -152,71 +159,89 @@ public class KafkaAutoConfigurationTests {
|
|
|
|
"spring.kafka.producer.ssl.keystore-password=p5",
|
|
|
|
"spring.kafka.producer.ssl.keystore-password=p5",
|
|
|
|
"spring.kafka.producer.ssl.truststore-location=classpath:tsLocP",
|
|
|
|
"spring.kafka.producer.ssl.truststore-location=classpath:tsLocP",
|
|
|
|
"spring.kafka.producer.ssl.truststore-password=p6",
|
|
|
|
"spring.kafka.producer.ssl.truststore-password=p6",
|
|
|
|
"spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.IntegerSerializer"
|
|
|
|
"spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.IntegerSerializer")
|
|
|
|
).run((context) -> {
|
|
|
|
.run((context) -> {
|
|
|
|
DefaultKafkaProducerFactory<?, ?> producerFactory = context
|
|
|
|
DefaultKafkaProducerFactory<?, ?> producerFactory = context
|
|
|
|
.getBean(DefaultKafkaProducerFactory.class);
|
|
|
|
.getBean(DefaultKafkaProducerFactory.class);
|
|
|
|
Map<String, Object> configs = producerFactory.getConfigurationProperties();
|
|
|
|
Map<String, Object> configs = producerFactory
|
|
|
|
// common
|
|
|
|
.getConfigurationProperties();
|
|
|
|
assertThat(configs.get(ProducerConfig.CLIENT_ID_CONFIG)).isEqualTo("cid");
|
|
|
|
// common
|
|
|
|
// producer
|
|
|
|
assertThat(configs.get(ProducerConfig.CLIENT_ID_CONFIG))
|
|
|
|
assertThat(configs.get(ProducerConfig.ACKS_CONFIG)).isEqualTo("all");
|
|
|
|
.isEqualTo("cid");
|
|
|
|
assertThat(configs.get(ProducerConfig.BATCH_SIZE_CONFIG)).isEqualTo(20);
|
|
|
|
// producer
|
|
|
|
assertThat(configs.get(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG))
|
|
|
|
assertThat(configs.get(ProducerConfig.ACKS_CONFIG)).isEqualTo("all");
|
|
|
|
.isEqualTo(Collections.singletonList("bar:1234")); // override
|
|
|
|
assertThat(configs.get(ProducerConfig.BATCH_SIZE_CONFIG))
|
|
|
|
assertThat(configs.get(ProducerConfig.BUFFER_MEMORY_CONFIG)).isEqualTo(12345L);
|
|
|
|
.isEqualTo(20);
|
|
|
|
assertThat(configs.get(ProducerConfig.COMPRESSION_TYPE_CONFIG)).isEqualTo("gzip");
|
|
|
|
assertThat(configs.get(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG))
|
|
|
|
assertThat(configs.get(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG))
|
|
|
|
.isEqualTo(Collections.singletonList("bar:1234")); // override
|
|
|
|
.isEqualTo(LongSerializer.class);
|
|
|
|
assertThat(configs.get(ProducerConfig.BUFFER_MEMORY_CONFIG))
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_KEY_PASSWORD_CONFIG)).isEqualTo("p4");
|
|
|
|
.isEqualTo(12345L);
|
|
|
|
assertThat((String) configs.get(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG))
|
|
|
|
assertThat(configs.get(ProducerConfig.COMPRESSION_TYPE_CONFIG))
|
|
|
|
.endsWith(File.separator + "ksLocP");
|
|
|
|
.isEqualTo("gzip");
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG)).isEqualTo("p5");
|
|
|
|
assertThat(configs.get(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG))
|
|
|
|
assertThat((String) configs.get(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG))
|
|
|
|
.isEqualTo(LongSerializer.class);
|
|
|
|
.endsWith(File.separator + "tsLocP");
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_KEY_PASSWORD_CONFIG))
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG))
|
|
|
|
.isEqualTo("p4");
|
|
|
|
.isEqualTo("p6");
|
|
|
|
assertThat(
|
|
|
|
assertThat(configs.get(ProducerConfig.RETRIES_CONFIG)).isEqualTo(2);
|
|
|
|
(String) configs.get(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG))
|
|
|
|
assertThat(configs.get(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG))
|
|
|
|
.endsWith(File.separator + "ksLocP");
|
|
|
|
.isEqualTo(IntegerSerializer.class);
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG))
|
|
|
|
assertThat(context.getBeansOfType(KafkaJaasLoginModuleInitializer.class))
|
|
|
|
.isEqualTo("p5");
|
|
|
|
.isEmpty();
|
|
|
|
assertThat((String) configs
|
|
|
|
assertThat(configs.get("foo.bar.baz")).isEqualTo("qux.fiz.buz");
|
|
|
|
.get(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG))
|
|
|
|
assertThat(configs.get("fiz.buz")).isEqualTo("fix.fox");
|
|
|
|
.endsWith(File.separator + "tsLocP");
|
|
|
|
});
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG))
|
|
|
|
|
|
|
|
.isEqualTo("p6");
|
|
|
|
|
|
|
|
assertThat(configs.get(ProducerConfig.RETRIES_CONFIG)).isEqualTo(2);
|
|
|
|
|
|
|
|
assertThat(configs.get(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG))
|
|
|
|
|
|
|
|
.isEqualTo(IntegerSerializer.class);
|
|
|
|
|
|
|
|
assertThat(
|
|
|
|
|
|
|
|
context.getBeansOfType(KafkaJaasLoginModuleInitializer.class))
|
|
|
|
|
|
|
|
.isEmpty();
|
|
|
|
|
|
|
|
assertThat(configs.get("foo.bar.baz")).isEqualTo("qux.fiz.buz");
|
|
|
|
|
|
|
|
assertThat(configs.get("fiz.buz")).isEqualTo("fix.fox");
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void adminProperties() {
|
|
|
|
public void adminProperties() {
|
|
|
|
this.contextRunner.withPropertyValues("spring.kafka.clientId=cid",
|
|
|
|
this.contextRunner
|
|
|
|
"spring.kafka.properties.foo.bar.baz=qux.fiz.buz",
|
|
|
|
.withPropertyValues("spring.kafka.clientId=cid",
|
|
|
|
"spring.kafka.admin.fail-fast=true",
|
|
|
|
"spring.kafka.properties.foo.bar.baz=qux.fiz.buz",
|
|
|
|
"spring.kafka.admin.properties.fiz.buz=fix.fox",
|
|
|
|
"spring.kafka.admin.fail-fast=true",
|
|
|
|
"spring.kafka.admin.ssl.key-password=p4",
|
|
|
|
"spring.kafka.admin.properties.fiz.buz=fix.fox",
|
|
|
|
"spring.kafka.admin.ssl.keystore-location=classpath:ksLocP",
|
|
|
|
"spring.kafka.admin.ssl.key-password=p4",
|
|
|
|
"spring.kafka.admin.ssl.keystore-password=p5",
|
|
|
|
"spring.kafka.admin.ssl.keystore-location=classpath:ksLocP",
|
|
|
|
"spring.kafka.admin.ssl.truststore-location=classpath:tsLocP",
|
|
|
|
"spring.kafka.admin.ssl.keystore-password=p5",
|
|
|
|
"spring.kafka.admin.ssl.truststore-password=p6").run((context) -> {
|
|
|
|
"spring.kafka.admin.ssl.truststore-location=classpath:tsLocP",
|
|
|
|
KafkaAdmin admin = context.getBean(KafkaAdmin.class);
|
|
|
|
"spring.kafka.admin.ssl.truststore-password=p6")
|
|
|
|
Map<String, Object> configs = admin.getConfig();
|
|
|
|
.run((context) -> {
|
|
|
|
// common
|
|
|
|
KafkaAdmin admin = context.getBean(KafkaAdmin.class);
|
|
|
|
assertThat(configs.get(AdminClientConfig.CLIENT_ID_CONFIG)).isEqualTo("cid");
|
|
|
|
Map<String, Object> configs = admin.getConfig();
|
|
|
|
// admin
|
|
|
|
// common
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_KEY_PASSWORD_CONFIG)).isEqualTo("p4");
|
|
|
|
assertThat(configs.get(AdminClientConfig.CLIENT_ID_CONFIG))
|
|
|
|
assertThat((String) configs.get(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG))
|
|
|
|
.isEqualTo("cid");
|
|
|
|
.endsWith(File.separator + "ksLocP");
|
|
|
|
// admin
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG)).isEqualTo("p5");
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_KEY_PASSWORD_CONFIG))
|
|
|
|
assertThat((String) configs.get(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG))
|
|
|
|
.isEqualTo("p4");
|
|
|
|
.endsWith(File.separator + "tsLocP");
|
|
|
|
assertThat(
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG))
|
|
|
|
(String) configs.get(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG))
|
|
|
|
.isEqualTo("p6");
|
|
|
|
.endsWith(File.separator + "ksLocP");
|
|
|
|
assertThat(context.getBeansOfType(KafkaJaasLoginModuleInitializer.class))
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG))
|
|
|
|
.isEmpty();
|
|
|
|
.isEqualTo("p5");
|
|
|
|
assertThat(configs.get("foo.bar.baz")).isEqualTo("qux.fiz.buz");
|
|
|
|
assertThat((String) configs
|
|
|
|
assertThat(configs.get("fiz.buz")).isEqualTo("fix.fox");
|
|
|
|
.get(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG))
|
|
|
|
assertThat(KafkaTestUtils.getPropertyValue(admin, "fatalIfBrokerNotAvailable",
|
|
|
|
.endsWith(File.separator + "tsLocP");
|
|
|
|
Boolean.class)).isTrue();
|
|
|
|
assertThat(configs.get(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG))
|
|
|
|
});
|
|
|
|
.isEqualTo("p6");
|
|
|
|
|
|
|
|
assertThat(
|
|
|
|
|
|
|
|
context.getBeansOfType(KafkaJaasLoginModuleInitializer.class))
|
|
|
|
|
|
|
|
.isEmpty();
|
|
|
|
|
|
|
|
assertThat(configs.get("foo.bar.baz")).isEqualTo("qux.fiz.buz");
|
|
|
|
|
|
|
|
assertThat(configs.get("fiz.buz")).isEqualTo("fix.fox");
|
|
|
|
|
|
|
|
assertThat(KafkaTestUtils.getPropertyValue(admin,
|
|
|
|
|
|
|
|
"fatalIfBrokerNotAvailable", Boolean.class)).isTrue();
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@ -233,48 +258,56 @@ public class KafkaAutoConfigurationTests {
|
|
|
|
"spring.kafka.jaas.enabled=true",
|
|
|
|
"spring.kafka.jaas.enabled=true",
|
|
|
|
"spring.kafka.jaas.login-module=foo",
|
|
|
|
"spring.kafka.jaas.login-module=foo",
|
|
|
|
"spring.kafka.jaas.control-flag=REQUISITE",
|
|
|
|
"spring.kafka.jaas.control-flag=REQUISITE",
|
|
|
|
"spring.kafka.jaas.options.useKeyTab=true"
|
|
|
|
"spring.kafka.jaas.options.useKeyTab=true")
|
|
|
|
).run((context) -> {
|
|
|
|
.run((context) -> {
|
|
|
|
DefaultKafkaProducerFactory<?, ?> producerFactory = context
|
|
|
|
DefaultKafkaProducerFactory<?, ?> producerFactory = context
|
|
|
|
.getBean(DefaultKafkaProducerFactory.class);
|
|
|
|
.getBean(DefaultKafkaProducerFactory.class);
|
|
|
|
DefaultKafkaConsumerFactory<?, ?> consumerFactory = context
|
|
|
|
DefaultKafkaConsumerFactory<?, ?> consumerFactory = context
|
|
|
|
.getBean(DefaultKafkaConsumerFactory.class);
|
|
|
|
.getBean(DefaultKafkaConsumerFactory.class);
|
|
|
|
KafkaTemplate<?, ?> kafkaTemplate = context.getBean(KafkaTemplate.class);
|
|
|
|
KafkaTemplate<?, ?> kafkaTemplate = context
|
|
|
|
KafkaListenerContainerFactory<?> kafkaListenerContainerFactory = context
|
|
|
|
.getBean(KafkaTemplate.class);
|
|
|
|
.getBean(KafkaListenerContainerFactory.class);
|
|
|
|
KafkaListenerContainerFactory<?> kafkaListenerContainerFactory = context
|
|
|
|
assertThat(kafkaTemplate.getMessageConverter()).isInstanceOf(
|
|
|
|
.getBean(KafkaListenerContainerFactory.class);
|
|
|
|
MessagingMessageConverter.class);
|
|
|
|
assertThat(kafkaTemplate.getMessageConverter())
|
|
|
|
assertThat(new DirectFieldAccessor(kafkaTemplate)
|
|
|
|
.isInstanceOf(MessagingMessageConverter.class);
|
|
|
|
.getPropertyValue("producerFactory")).isEqualTo(producerFactory);
|
|
|
|
assertThat(new DirectFieldAccessor(kafkaTemplate)
|
|
|
|
assertThat(kafkaTemplate.getDefaultTopic()).isEqualTo("testTopic");
|
|
|
|
.getPropertyValue("producerFactory"))
|
|
|
|
DirectFieldAccessor dfa = new DirectFieldAccessor(kafkaListenerContainerFactory);
|
|
|
|
.isEqualTo(producerFactory);
|
|
|
|
assertThat(dfa.getPropertyValue("consumerFactory")).isEqualTo(consumerFactory);
|
|
|
|
assertThat(kafkaTemplate.getDefaultTopic()).isEqualTo("testTopic");
|
|
|
|
assertThat(dfa.getPropertyValue("containerProperties.ackMode"))
|
|
|
|
DirectFieldAccessor dfa = new DirectFieldAccessor(
|
|
|
|
.isEqualTo(AckMode.MANUAL);
|
|
|
|
kafkaListenerContainerFactory);
|
|
|
|
assertThat(dfa.getPropertyValue("containerProperties.ackCount")).isEqualTo(123);
|
|
|
|
assertThat(dfa.getPropertyValue("consumerFactory"))
|
|
|
|
assertThat(dfa.getPropertyValue("containerProperties.ackTime")).isEqualTo(456L);
|
|
|
|
.isEqualTo(consumerFactory);
|
|
|
|
assertThat(dfa.getPropertyValue("concurrency")).isEqualTo(3);
|
|
|
|
assertThat(dfa.getPropertyValue("containerProperties.ackMode"))
|
|
|
|
assertThat(dfa.getPropertyValue("containerProperties.pollTimeout"))
|
|
|
|
.isEqualTo(AckMode.MANUAL);
|
|
|
|
.isEqualTo(2000L);
|
|
|
|
assertThat(dfa.getPropertyValue("containerProperties.ackCount"))
|
|
|
|
assertThat(dfa.getPropertyValue("batchListener")).isEqualTo(true);
|
|
|
|
.isEqualTo(123);
|
|
|
|
assertThat(context.getBeansOfType(KafkaJaasLoginModuleInitializer.class))
|
|
|
|
assertThat(dfa.getPropertyValue("containerProperties.ackTime"))
|
|
|
|
.hasSize(1);
|
|
|
|
.isEqualTo(456L);
|
|
|
|
KafkaJaasLoginModuleInitializer jaas = context
|
|
|
|
assertThat(dfa.getPropertyValue("concurrency")).isEqualTo(3);
|
|
|
|
.getBean(KafkaJaasLoginModuleInitializer.class);
|
|
|
|
assertThat(dfa.getPropertyValue("containerProperties.pollTimeout"))
|
|
|
|
dfa = new DirectFieldAccessor(jaas);
|
|
|
|
.isEqualTo(2000L);
|
|
|
|
assertThat(dfa.getPropertyValue("loginModule")).isEqualTo("foo");
|
|
|
|
assertThat(dfa.getPropertyValue("batchListener")).isEqualTo(true);
|
|
|
|
assertThat(dfa.getPropertyValue("controlFlag"))
|
|
|
|
assertThat(
|
|
|
|
.isEqualTo(AppConfigurationEntry.LoginModuleControlFlag.REQUISITE);
|
|
|
|
context.getBeansOfType(KafkaJaasLoginModuleInitializer.class))
|
|
|
|
assertThat(((Map<String, String>) dfa.getPropertyValue("options")))
|
|
|
|
.hasSize(1);
|
|
|
|
.containsExactly(entry("useKeyTab", "true"));
|
|
|
|
KafkaJaasLoginModuleInitializer jaas = context
|
|
|
|
});
|
|
|
|
.getBean(KafkaJaasLoginModuleInitializer.class);
|
|
|
|
|
|
|
|
dfa = new DirectFieldAccessor(jaas);
|
|
|
|
|
|
|
|
assertThat(dfa.getPropertyValue("loginModule")).isEqualTo("foo");
|
|
|
|
|
|
|
|
assertThat(dfa.getPropertyValue("controlFlag")).isEqualTo(
|
|
|
|
|
|
|
|
AppConfigurationEntry.LoginModuleControlFlag.REQUISITE);
|
|
|
|
|
|
|
|
assertThat(((Map<String, String>) dfa.getPropertyValue("options")))
|
|
|
|
|
|
|
|
.containsExactly(entry("useKeyTab", "true"));
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testKafkaTemplateRecordMessageConverters() {
|
|
|
|
public void testKafkaTemplateRecordMessageConverters() {
|
|
|
|
this.contextRunner.withUserConfiguration(MessageConverterConfiguration.class)
|
|
|
|
this.contextRunner.withUserConfiguration(MessageConverterConfiguration.class)
|
|
|
|
.run((context) -> {
|
|
|
|
.run((context) -> {
|
|
|
|
KafkaTemplate<?, ?> kafkaTemplate = context.getBean(KafkaTemplate.class);
|
|
|
|
KafkaTemplate<?, ?> kafkaTemplate = context
|
|
|
|
|
|
|
|
.getBean(KafkaTemplate.class);
|
|
|
|
assertThat(kafkaTemplate.getMessageConverter())
|
|
|
|
assertThat(kafkaTemplate.getMessageConverter())
|
|
|
|
.isSameAs(context.getBean("myMessageConverter"));
|
|
|
|
.isSameAs(context.getBean("myMessageConverter"));
|
|
|
|
});
|
|
|
|
});
|
|
|
|