Update to Spring Cloud Stream Brooklyn.BUILD-SNAPSHOT
This commit is contained in:
@@ -16,10 +16,6 @@
|
||||
|
||||
package multibinder;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
@@ -32,7 +28,9 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.stream.binder.Binder;
|
||||
import org.springframework.cloud.stream.binder.BinderFactory;
|
||||
import org.springframework.cloud.stream.binder.ExtendedConsumerProperties;
|
||||
@@ -40,12 +38,10 @@ import org.springframework.cloud.stream.binder.ExtendedProducerProperties;
|
||||
import org.springframework.cloud.stream.binder.kafka.KafkaConsumerProperties;
|
||||
import org.springframework.cloud.stream.binder.kafka.KafkaMessageChannelBinder;
|
||||
import org.springframework.cloud.stream.binder.kafka.KafkaProducerProperties;
|
||||
import org.springframework.cloud.stream.test.junit.kafka.KafkaTestSupport;
|
||||
import org.springframework.cloud.stream.test.junit.redis.RedisTestSupport;
|
||||
import org.springframework.cloud.stream.binder.kafka.config.KafkaBinderConfigurationProperties;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.kafka.core.BrokerAddress;
|
||||
import org.springframework.integration.kafka.core.Configuration;
|
||||
import org.springframework.kafka.test.rule.KafkaEmbedded;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
@@ -53,27 +49,28 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
import static org.hamcrest.Matchers.arrayWithSize;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = MultibinderApplication.class)
|
||||
@SpringBootTest(classes = MultibinderApplication.class)
|
||||
@WebAppConfiguration
|
||||
@DirtiesContext
|
||||
public class TwoKafkaBindersApplicationTest {
|
||||
|
||||
@ClassRule
|
||||
public static KafkaTestSupport kafkaTestSupport1 = new KafkaTestSupport(true);
|
||||
public static KafkaEmbedded kafkaTestSupport1 = new KafkaEmbedded(1);
|
||||
|
||||
@ClassRule
|
||||
public static KafkaTestSupport kafkaTestSupport2 = new KafkaTestSupport(true);
|
||||
public static KafkaEmbedded kafkaTestSupport2 = new KafkaEmbedded(1);
|
||||
|
||||
@ClassRule
|
||||
public static RedisTestSupport redisTestSupport = new RedisTestSupport();
|
||||
|
||||
@BeforeClass
|
||||
public static void setupEnvironment() {
|
||||
System.setProperty("kafkaBroker1", kafkaTestSupport1.getBrokerAddress());
|
||||
System.setProperty("zk1", kafkaTestSupport1.getZkConnectString());
|
||||
System.setProperty("kafkaBroker2", kafkaTestSupport2.getBrokerAddress());
|
||||
System.setProperty("zk2", kafkaTestSupport2.getZkConnectString());
|
||||
System.setProperty("kafkaBroker1", kafkaTestSupport1.getBrokersAsString());
|
||||
System.setProperty("zk1", kafkaTestSupport1.getZookeeperConnectionString());
|
||||
System.setProperty("kafkaBroker2", kafkaTestSupport2.getBrokersAsString());
|
||||
System.setProperty("zk2", kafkaTestSupport2.getZookeeperConnectionString());
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@@ -83,18 +80,19 @@ public class TwoKafkaBindersApplicationTest {
|
||||
public void contextLoads() {
|
||||
Binder<MessageChannel, ?, ?> binder1 = binderFactory.getBinder("kafka1");
|
||||
KafkaMessageChannelBinder kafka1 = (KafkaMessageChannelBinder) binder1;
|
||||
DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(kafka1.getConnectionFactory());
|
||||
Configuration configuration = (Configuration) directFieldAccessor.getPropertyValue("configuration");
|
||||
List<BrokerAddress> brokerAddresses = configuration.getBrokerAddresses();
|
||||
Assert.assertThat(brokerAddresses, hasSize(1));
|
||||
Assert.assertThat(brokerAddresses, contains(BrokerAddress.fromAddress(kafkaTestSupport1.getBrokerAddress())));
|
||||
DirectFieldAccessor directFieldAccessor1 = new DirectFieldAccessor(kafka1);
|
||||
KafkaBinderConfigurationProperties configuration1 =
|
||||
(KafkaBinderConfigurationProperties) directFieldAccessor1.getPropertyValue("configurationProperties");
|
||||
Assert.assertThat(configuration1.getBrokers(), arrayWithSize(1));
|
||||
Assert.assertThat(configuration1.getBrokers()[0], equalTo(kafkaTestSupport1.getBrokersAsString()));
|
||||
|
||||
Binder<MessageChannel, ?, ?> binder2 = binderFactory.getBinder("kafka2");
|
||||
KafkaMessageChannelBinder kafka2 = (KafkaMessageChannelBinder) binder2;
|
||||
DirectFieldAccessor directFieldAccessor2 = new DirectFieldAccessor(kafka2.getConnectionFactory());
|
||||
Configuration configuration2 = (Configuration) directFieldAccessor2.getPropertyValue("configuration");
|
||||
List<BrokerAddress> brokerAddresses2 = configuration2.getBrokerAddresses();
|
||||
Assert.assertThat(brokerAddresses2, hasSize(1));
|
||||
Assert.assertThat(brokerAddresses2, contains(BrokerAddress.fromAddress(kafkaTestSupport2.getBrokerAddress())));
|
||||
DirectFieldAccessor directFieldAccessor2 = new DirectFieldAccessor(kafka2);
|
||||
KafkaBinderConfigurationProperties configuration2 =
|
||||
(KafkaBinderConfigurationProperties) directFieldAccessor2.getPropertyValue("configurationProperties");
|
||||
Assert.assertThat(configuration2.getBrokers(), arrayWithSize(1));
|
||||
Assert.assertThat(configuration2.getBrokers()[0], equalTo(kafkaTestSupport2.getBrokersAsString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -110,7 +108,7 @@ public class TwoKafkaBindersApplicationTest {
|
||||
String testPayload = "testFoo" + UUID.randomUUID().toString();
|
||||
dataProducer.send(MessageBuilder.withPayload(testPayload).build());
|
||||
|
||||
Message<?> receive = dataConsumer.receive(2000);
|
||||
Message<?> receive = dataConsumer.receive(5000);
|
||||
Assert.assertThat(receive, Matchers.notNullValue());
|
||||
Assert.assertThat(receive.getPayload(), CoreMatchers.equalTo(testPayload));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user