Fix broken tests
This commit is contained in:
@@ -16,9 +16,16 @@
|
||||
|
||||
package multibinder;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.*;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.cloud.stream.binder.BinderFactory;
|
||||
@@ -32,14 +39,12 @@ import org.springframework.cloud.stream.binder.test.junit.rabbit.RabbitTestSuppo
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.kafka.test.rule.KafkaEmbedded;
|
||||
import org.springframework.kafka.test.rule.EmbeddedKafkaRule;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Marius Bogoevici
|
||||
* @author Gary Russell
|
||||
@@ -52,7 +57,8 @@ public class RabbitAndKafkaBinderApplicationTests {
|
||||
public static RabbitTestSupport rabbitTestSupport = new RabbitTestSupport();
|
||||
|
||||
@ClassRule
|
||||
public static KafkaEmbedded kafkaEmbedded = new KafkaEmbedded(1, true, "test");
|
||||
public static EmbeddedKafkaRule embeddedKafka = new EmbeddedKafkaRule(1, true, "test");
|
||||
|
||||
|
||||
private final String randomGroup = UUID.randomUUID().toString();
|
||||
|
||||
@@ -68,8 +74,7 @@ public class RabbitAndKafkaBinderApplicationTests {
|
||||
public void contextLoads() throws Exception {
|
||||
// passing connection arguments arguments to the embedded Kafka instance
|
||||
ConfigurableApplicationContext context = SpringApplication.run(MultibinderApplication.class,
|
||||
"--spring.cloud.stream.kafka.binder.brokers=" + kafkaEmbedded.getBrokersAsString(),
|
||||
"--spring.cloud.stream.kafka.binder.zkNodes=" + kafkaEmbedded.getZookeeperConnectionString());
|
||||
"--spring.cloud.stream.kafka.binder.brokers=" + embeddedKafka.getEmbeddedKafka().getBrokersAsString());
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -77,8 +82,7 @@ public class RabbitAndKafkaBinderApplicationTests {
|
||||
public void messagingWorks() throws Exception {
|
||||
// passing connection arguments arguments to the embedded Kafka instance
|
||||
ConfigurableApplicationContext context = SpringApplication.run(MultibinderApplication.class,
|
||||
"--spring.cloud.stream.kafka.binder.brokers=" + kafkaEmbedded.getBrokersAsString(),
|
||||
"--spring.cloud.stream.kafka.binder.zkNodes=" + kafkaEmbedded.getZookeeperConnectionString(),
|
||||
"--spring.cloud.stream.kafka.binder.brokers=" + embeddedKafka.getEmbeddedKafka().getBrokersAsString(),
|
||||
"--spring.cloud.stream.bindings.input.group=testGroup",
|
||||
"--spring.cloud.stream.bindings.output.producer.requiredGroups=" + this.randomGroup);
|
||||
DirectChannel dataProducer = new DirectChannel();
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package multibinder;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Assert;
|
||||
@@ -23,6 +25,7 @@ import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -33,14 +36,12 @@ import org.springframework.cloud.stream.binder.kafka.KafkaMessageChannelBinder;
|
||||
import org.springframework.cloud.stream.binder.kafka.properties.KafkaBinderConfigurationProperties;
|
||||
import org.springframework.cloud.stream.binder.kafka.properties.KafkaConsumerProperties;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.kafka.test.rule.KafkaEmbedded;
|
||||
import org.springframework.kafka.test.rule.EmbeddedKafkaRule;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.hamcrest.Matchers.arrayWithSize;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@@ -51,18 +52,17 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
public class TwoKafkaBindersApplicationTest {
|
||||
|
||||
@ClassRule
|
||||
public static KafkaEmbedded kafkaTestSupport1 = new KafkaEmbedded(1);
|
||||
public static EmbeddedKafkaRule kafkaTestSupport1 = new EmbeddedKafkaRule(1, true, "input", "output");
|
||||
|
||||
@ClassRule
|
||||
public static KafkaEmbedded kafkaTestSupport2 = new KafkaEmbedded(1);
|
||||
public static EmbeddedKafkaRule kafkaTestSupport2 = new EmbeddedKafkaRule(1, true, "input", "output");
|
||||
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void setupEnvironment() {
|
||||
System.setProperty("kafkaBroker1", kafkaTestSupport1.getBrokersAsString());
|
||||
System.setProperty("zk1", kafkaTestSupport1.getZookeeperConnectionString());
|
||||
System.setProperty("kafkaBroker2", kafkaTestSupport2.getBrokersAsString());
|
||||
System.setProperty("zk2", kafkaTestSupport2.getZookeeperConnectionString());
|
||||
System.setProperty("kafkaBroker1", kafkaTestSupport1.getEmbeddedKafka().getBrokersAsString());
|
||||
System.setProperty("kafkaBroker2", kafkaTestSupport2.getEmbeddedKafka().getBrokersAsString());
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@@ -76,7 +76,7 @@ public class TwoKafkaBindersApplicationTest {
|
||||
KafkaBinderConfigurationProperties configuration1 =
|
||||
(KafkaBinderConfigurationProperties) directFieldAccessor1.getPropertyValue("configurationProperties");
|
||||
Assert.assertThat(configuration1.getBrokers(), arrayWithSize(1));
|
||||
Assert.assertThat(configuration1.getBrokers()[0], equalTo(kafkaTestSupport1.getBrokersAsString()));
|
||||
Assert.assertThat(configuration1.getBrokers()[0], equalTo(kafkaTestSupport1.getEmbeddedKafka().getBrokersAsString()));
|
||||
|
||||
Binder<MessageChannel, ?, ?> binder2 = binderFactory.getBinder("kafka2", MessageChannel.class);
|
||||
KafkaMessageChannelBinder kafka2 = (KafkaMessageChannelBinder) binder2;
|
||||
@@ -84,7 +84,7 @@ public class TwoKafkaBindersApplicationTest {
|
||||
KafkaBinderConfigurationProperties configuration2 =
|
||||
(KafkaBinderConfigurationProperties) directFieldAccessor2.getPropertyValue("configurationProperties");
|
||||
Assert.assertThat(configuration2.getBrokers(), arrayWithSize(1));
|
||||
Assert.assertThat(configuration2.getBrokers()[0], equalTo(kafkaTestSupport2.getBrokersAsString()));
|
||||
Assert.assertThat(configuration2.getBrokers()[0], equalTo(kafkaTestSupport2.getEmbeddedKafka().getBrokersAsString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -33,7 +34,7 @@ import org.springframework.cloud.stream.binder.kafka.KafkaMessageChannelBinder;
|
||||
import org.springframework.cloud.stream.binder.kafka.properties.KafkaBinderConfigurationProperties;
|
||||
import org.springframework.cloud.stream.binder.kafka.properties.KafkaConsumerProperties;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.kafka.test.rule.KafkaEmbedded;
|
||||
import org.springframework.kafka.test.rule.EmbeddedKafkaRule;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
@@ -51,18 +52,16 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
public class TwoKafkaBindersApplicationTest {
|
||||
|
||||
@ClassRule
|
||||
public static KafkaEmbedded kafkaTestSupport1 = new KafkaEmbedded(1);
|
||||
public static EmbeddedKafkaRule kafkaTestSupport1 = new EmbeddedKafkaRule(1, true, "input", "output");
|
||||
|
||||
@ClassRule
|
||||
public static KafkaEmbedded kafkaTestSupport2 = new KafkaEmbedded(1);
|
||||
public static EmbeddedKafkaRule kafkaTestSupport2 = new EmbeddedKafkaRule(1, true, "input", "output");
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void setupEnvironment() {
|
||||
System.setProperty("kafkaBroker1", kafkaTestSupport1.getBrokersAsString());
|
||||
System.setProperty("zk1", kafkaTestSupport1.getZookeeperConnectionString());
|
||||
System.setProperty("kafkaBroker2", kafkaTestSupport2.getBrokersAsString());
|
||||
System.setProperty("zk2", kafkaTestSupport2.getZookeeperConnectionString());
|
||||
System.setProperty("kafkaBroker1", kafkaTestSupport1.getEmbeddedKafka().getBrokersAsString());
|
||||
System.setProperty("kafkaBroker2", kafkaTestSupport2.getEmbeddedKafka().getBrokersAsString());
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@@ -76,7 +75,7 @@ public class TwoKafkaBindersApplicationTest {
|
||||
KafkaBinderConfigurationProperties configuration1 =
|
||||
(KafkaBinderConfigurationProperties) directFieldAccessor1.getPropertyValue("configurationProperties");
|
||||
Assert.assertThat(configuration1.getBrokers(), arrayWithSize(1));
|
||||
Assert.assertThat(configuration1.getBrokers()[0], equalTo(kafkaTestSupport1.getBrokersAsString()));
|
||||
Assert.assertThat(configuration1.getBrokers()[0], equalTo(kafkaTestSupport1.getEmbeddedKafka().getBrokersAsString()));
|
||||
|
||||
Binder<MessageChannel, ?, ?> binder2 = binderFactory.getBinder("kafka2", MessageChannel.class);
|
||||
KafkaMessageChannelBinder kafka2 = (KafkaMessageChannelBinder) binder2;
|
||||
@@ -84,7 +83,7 @@ public class TwoKafkaBindersApplicationTest {
|
||||
KafkaBinderConfigurationProperties configuration2 =
|
||||
(KafkaBinderConfigurationProperties) directFieldAccessor2.getPropertyValue("configurationProperties");
|
||||
Assert.assertThat(configuration2.getBrokers(), arrayWithSize(1));
|
||||
Assert.assertThat(configuration2.getBrokers()[0], equalTo(kafkaTestSupport2.getBrokersAsString()));
|
||||
Assert.assertThat(configuration2.getBrokers()[0], equalTo(kafkaTestSupport2.getEmbeddedKafka().getBrokersAsString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
|
||||
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.kafka.test.rule.KafkaEmbedded;
|
||||
import org.springframework.kafka.test.rule.EmbeddedKafkaRule;
|
||||
import org.springframework.kafka.test.utils.KafkaTestUtils;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@@ -52,7 +52,8 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
public class PolledConsumerApplicationTests {
|
||||
|
||||
@ClassRule
|
||||
public static KafkaEmbedded embeddedKafka = new KafkaEmbedded(1);
|
||||
public static EmbeddedKafkaRule embeddedKafka = new EmbeddedKafkaRule(1, true, "input", "output");
|
||||
|
||||
|
||||
@Value("${spring.cloud.stream.bindings.input.destination}")
|
||||
private String inputTopic;
|
||||
@@ -62,12 +63,12 @@ public class PolledConsumerApplicationTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
System.setProperty("spring.kafka.bootstrap-servers", embeddedKafka.getBrokersAsString());
|
||||
System.setProperty("spring.cloud.stream.kafka.binder.brokers", embeddedKafka.getEmbeddedKafka().getBrokersAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendReceive() throws Exception {
|
||||
Map<String, Object> senderProps = KafkaTestUtils.producerProps(embeddedKafka);
|
||||
Map<String, Object> senderProps = KafkaTestUtils.producerProps(embeddedKafka.getEmbeddedKafka());
|
||||
senderProps.put("key.serializer", ByteArraySerializer.class);
|
||||
senderProps.put("value.serializer", ByteArraySerializer.class);
|
||||
DefaultKafkaProducerFactory<byte[], byte[]> pf = new DefaultKafkaProducerFactory<>(senderProps);
|
||||
@@ -75,7 +76,7 @@ public class PolledConsumerApplicationTests {
|
||||
template.setDefaultTopic(inputTopic);
|
||||
template.sendDefault("foo".getBytes());
|
||||
|
||||
Map<String, Object> consumerProps = KafkaTestUtils.consumerProps("testGroup", "false", embeddedKafka);
|
||||
Map<String, Object> consumerProps = KafkaTestUtils.consumerProps("testGroup", "false", embeddedKafka.getEmbeddedKafka());
|
||||
consumerProps.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
|
||||
consumerProps.put("key.deserializer", ByteArrayDeserializer.class);
|
||||
consumerProps.put("value.deserializer", ByteArrayDeserializer.class);
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.stream.testing.processor.integration;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.kafka.clients.consumer.Consumer;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
||||
@@ -24,18 +26,17 @@ import org.junit.ClassRule;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.stream.testing.processor.ToUpperCaseProcessor;
|
||||
import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.kafka.test.rule.KafkaEmbedded;
|
||||
import org.springframework.kafka.test.rule.EmbeddedKafkaRule;
|
||||
import org.springframework.kafka.test.utils.KafkaTestUtils;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
@@ -62,7 +63,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class ToUpperCaseProcessorIntTests {
|
||||
|
||||
@ClassRule
|
||||
public static KafkaEmbedded kafkaEmbedded = new KafkaEmbedded(1, true, "output");
|
||||
public static EmbeddedKafkaRule kafkaEmbedded = new EmbeddedKafkaRule(1, true, "output");
|
||||
|
||||
@Autowired
|
||||
private KafkaTemplate<byte[], byte[]> template;
|
||||
@@ -72,8 +73,7 @@ public class ToUpperCaseProcessorIntTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
System.setProperty("spring.kafka.bootstrap-servers", kafkaEmbedded.getBrokersAsString());
|
||||
System.setProperty("spring.cloud.stream.kafka.binder.zkNodes", kafkaEmbedded.getZookeeperConnectionString());
|
||||
System.setProperty("spring.kafka.bootstrap-servers", kafkaEmbedded.getEmbeddedKafka().getBrokersAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,7 +82,7 @@ public class ToUpperCaseProcessorIntTests {
|
||||
|
||||
Consumer<byte[], String> consumer = this.consumerFactory.createConsumer();
|
||||
|
||||
kafkaEmbedded.consumeFromAnEmbeddedTopic(consumer, "output");
|
||||
kafkaEmbedded.getEmbeddedKafka().consumeFromAnEmbeddedTopic(consumer, "output");
|
||||
|
||||
ConsumerRecords<byte[], String> replies = KafkaTestUtils.getRecords(consumer);
|
||||
assertThat(replies.count()).isEqualTo(1);
|
||||
|
||||
Reference in New Issue
Block a user