Move tests to AssertJ
This commit is contained in:
committed by
Soby Chacko
parent
fbe9bbac7e
commit
aef08a28a3
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>spring-cloud-stream-binders-parent</artifactId>
|
<artifactId>spring-cloud-stream-binders-parent</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
@@ -26,10 +27,5 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-logging</artifactId>
|
<artifactId>spring-boot-starter-logging</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
import kafka.admin.AdminUtils;
|
import kafka.admin.AdminUtils;
|
||||||
import kafka.api.TopicMetadata;
|
import kafka.api.TopicMetadata;
|
||||||
import org.hamcrest.collection.IsCollectionWithSize;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.ClassRule;
|
import org.junit.ClassRule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -59,22 +58,9 @@ import org.springframework.retry.backoff.FixedBackOffPolicy;
|
|||||||
import org.springframework.retry.policy.SimpleRetryPolicy;
|
import org.springframework.retry.policy.SimpleRetryPolicy;
|
||||||
import org.springframework.retry.support.RetryTemplate;
|
import org.springframework.retry.support.RetryTemplate;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.arrayWithSize;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.Matchers.containsString;
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
|
||||||
import static org.hamcrest.Matchers.hasItemInArray;
|
|
||||||
import static org.hamcrest.Matchers.hasSize;
|
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
|
||||||
import static org.hamcrest.Matchers.not;
|
|
||||||
import static org.hamcrest.Matchers.nullValue;
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration tests for the {@link KafkaMessageChannelBinder}.
|
* Integration tests for the {@link KafkaMessageChannelBinder}.
|
||||||
* @author Eric Bottard
|
* @author Eric Bottard
|
||||||
@@ -151,7 +137,7 @@ public class KafkaBinderTests extends
|
|||||||
KafkaTestBinder binder = getBinder();
|
KafkaTestBinder binder = getBinder();
|
||||||
DirectChannel moduleOutputChannel = new DirectChannel();
|
DirectChannel moduleOutputChannel = new DirectChannel();
|
||||||
DirectChannel moduleInputChannel = new DirectChannel();
|
DirectChannel moduleInputChannel = new DirectChannel();
|
||||||
QueueChannel dlqChannel = new QueueChannel();
|
QueueChannel dlqChannel = new QueueChannel();
|
||||||
FailingInvocationCountingMessageHandler handler = new FailingInvocationCountingMessageHandler();
|
FailingInvocationCountingMessageHandler handler = new FailingInvocationCountingMessageHandler();
|
||||||
moduleInputChannel.subscribe(handler);
|
moduleInputChannel.subscribe(handler);
|
||||||
ExtendedProducerProperties<KafkaProducerProperties> producerProperties = createProducerProperties();
|
ExtendedProducerProperties<KafkaProducerProperties> producerProperties = createProducerProperties();
|
||||||
@@ -164,8 +150,8 @@ public class KafkaBinderTests extends
|
|||||||
long uniqueBindingId = System.currentTimeMillis();
|
long uniqueBindingId = System.currentTimeMillis();
|
||||||
Binding<MessageChannel> producerBinding = binder.bindProducer("retryTest." + uniqueBindingId + ".0",
|
Binding<MessageChannel> producerBinding = binder.bindProducer("retryTest." + uniqueBindingId + ".0",
|
||||||
moduleOutputChannel, producerProperties);
|
moduleOutputChannel, producerProperties);
|
||||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer("retryTest." + uniqueBindingId + ".0", "testGroup",
|
Binding<MessageChannel> consumerBinding = binder.bindConsumer("retryTest." + uniqueBindingId + ".0",
|
||||||
moduleInputChannel, consumerProperties);
|
"testGroup", moduleInputChannel, consumerProperties);
|
||||||
|
|
||||||
ExtendedConsumerProperties<KafkaConsumerProperties> dlqConsumerProperties = createConsumerProperties();
|
ExtendedConsumerProperties<KafkaConsumerProperties> dlqConsumerProperties = createConsumerProperties();
|
||||||
dlqConsumerProperties.setMaxAttempts(1);
|
dlqConsumerProperties.setMaxAttempts(1);
|
||||||
@@ -178,9 +164,9 @@ public class KafkaBinderTests extends
|
|||||||
moduleOutputChannel.send(testMessage);
|
moduleOutputChannel.send(testMessage);
|
||||||
|
|
||||||
Message<?> receivedMessage = receive(dlqChannel, 3);
|
Message<?> receivedMessage = receive(dlqChannel, 3);
|
||||||
assertNotNull(receivedMessage);
|
assertThat(receivedMessage).isNotNull();
|
||||||
assertEquals(testMessagePayload, receivedMessage.getPayload());
|
assertThat(receivedMessage.getPayload()).isEqualTo(testMessagePayload);
|
||||||
assertThat(handler.getInvocationCount(), equalTo(consumerProperties.getMaxAttempts()));
|
assertThat(handler.getInvocationCount()).isEqualTo(consumerProperties.getMaxAttempts());
|
||||||
dlqConsumerBinding.unbind();
|
dlqConsumerBinding.unbind();
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
producerBinding.unbind();
|
producerBinding.unbind();
|
||||||
@@ -209,13 +195,13 @@ public class KafkaBinderTests extends
|
|||||||
Message<String> testMessage = MessageBuilder.withPayload(testMessagePayload).build();
|
Message<String> testMessage = MessageBuilder.withPayload(testMessagePayload).build();
|
||||||
moduleOutputChannel.send(testMessage);
|
moduleOutputChannel.send(testMessage);
|
||||||
|
|
||||||
assertTrue(handler.getLatch().await((int) (timeoutMultiplier * 1000), TimeUnit.MILLISECONDS));
|
assertThat(handler.getLatch().await((int) (timeoutMultiplier * 1000), TimeUnit.MILLISECONDS));
|
||||||
// first attempt fails
|
// first attempt fails
|
||||||
assertThat(handler.getReceivedMessages().entrySet(), hasSize(1));
|
assertThat(handler.getReceivedMessages().entrySet()).hasSize(1);
|
||||||
Message<?> receivedMessage = handler.getReceivedMessages().entrySet().iterator().next().getValue();
|
Message<?> receivedMessage = handler.getReceivedMessages().entrySet().iterator().next().getValue();
|
||||||
assertNotNull(receivedMessage);
|
assertThat(receivedMessage).isNotNull();
|
||||||
assertEquals(testMessagePayload, receivedMessage.getPayload());
|
assertThat(receivedMessage.getPayload()).isEqualTo(testMessagePayload);
|
||||||
assertThat(handler.getInvocationCount(), equalTo(consumerProperties.getMaxAttempts()));
|
assertThat(handler.getInvocationCount()).isEqualTo(consumerProperties.getMaxAttempts());
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
|
|
||||||
// on the second attempt the message is redelivered
|
// on the second attempt the message is redelivered
|
||||||
@@ -227,9 +213,9 @@ public class KafkaBinderTests extends
|
|||||||
moduleOutputChannel.send(testMessage2);
|
moduleOutputChannel.send(testMessage2);
|
||||||
|
|
||||||
Message<?> firstReceived = receive(successfulInputChannel);
|
Message<?> firstReceived = receive(successfulInputChannel);
|
||||||
assertEquals(testMessagePayload, firstReceived.getPayload());
|
assertThat(firstReceived.getPayload()).isEqualTo(testMessagePayload);
|
||||||
Message<?> secondReceived = receive(successfulInputChannel);
|
Message<?> secondReceived = receive(successfulInputChannel);
|
||||||
assertEquals(testMessage2Payload, secondReceived.getPayload());
|
assertThat(secondReceived.getPayload()).isEqualTo(testMessage2Payload);
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
producerBinding.unbind();
|
producerBinding.unbind();
|
||||||
}
|
}
|
||||||
@@ -264,20 +250,19 @@ public class KafkaBinderTests extends
|
|||||||
moduleOutputChannel.send(testMessage);
|
moduleOutputChannel.send(testMessage);
|
||||||
|
|
||||||
Message<?> dlqMessage = receive(dlqChannel, 3);
|
Message<?> dlqMessage = receive(dlqChannel, 3);
|
||||||
assertNotNull(dlqMessage);
|
assertThat(dlqMessage).isNotNull();
|
||||||
assertEquals(testMessagePayload, dlqMessage.getPayload());
|
assertThat(dlqMessage.getPayload()).isEqualTo(testMessagePayload);
|
||||||
|
|
||||||
// first attempt fails
|
// first attempt fails
|
||||||
assertThat(handler.getReceivedMessages().entrySet(), hasSize(1));
|
assertThat(handler.getReceivedMessages().entrySet()).hasSize(1);
|
||||||
Message<?> handledMessage = handler.getReceivedMessages().entrySet().iterator().next().getValue();
|
Message<?> handledMessage = handler.getReceivedMessages().entrySet().iterator().next().getValue();
|
||||||
assertNotNull(handledMessage);
|
assertThat(handledMessage).isNotNull();
|
||||||
assertEquals(testMessagePayload, handledMessage.getPayload());
|
assertThat(handledMessage.getPayload()).isEqualTo(testMessagePayload);
|
||||||
assertThat(handler.getInvocationCount(), equalTo(consumerProperties.getMaxAttempts()));
|
assertThat(handler.getInvocationCount()).isEqualTo(consumerProperties.getMaxAttempts());
|
||||||
|
|
||||||
dlqConsumerBinding.unbind();
|
dlqConsumerBinding.unbind();
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
|
|
||||||
|
|
||||||
// on the second attempt the message is not redelivered because the DLQ is set
|
// on the second attempt the message is not redelivered because the DLQ is set
|
||||||
QueueChannel successfulInputChannel = new QueueChannel();
|
QueueChannel successfulInputChannel = new QueueChannel();
|
||||||
consumerBinding = binder.bindConsumer("retryTest." + uniqueBindingId + ".0", "testGroup",
|
consumerBinding = binder.bindConsumer("retryTest." + uniqueBindingId + ".0", "testGroup",
|
||||||
@@ -287,7 +272,7 @@ public class KafkaBinderTests extends
|
|||||||
moduleOutputChannel.send(testMessage2);
|
moduleOutputChannel.send(testMessage2);
|
||||||
|
|
||||||
Message<?> receivedMessage = receive(successfulInputChannel);
|
Message<?> receivedMessage = receive(successfulInputChannel);
|
||||||
assertEquals(testMessage2Payload, receivedMessage.getPayload());
|
assertThat(receivedMessage.getPayload()).isEqualTo(testMessage2Payload);
|
||||||
|
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
producerBinding.unbind();
|
producerBinding.unbind();
|
||||||
@@ -301,28 +286,28 @@ public class KafkaBinderTests extends
|
|||||||
@Test
|
@Test
|
||||||
public void testCompression() throws Exception {
|
public void testCompression() throws Exception {
|
||||||
final ProducerMetadata.CompressionType[] codecs = new ProducerMetadata.CompressionType[] {
|
final ProducerMetadata.CompressionType[] codecs = new ProducerMetadata.CompressionType[] {
|
||||||
ProducerMetadata.CompressionType.none,
|
ProducerMetadata.CompressionType.none, ProducerMetadata.CompressionType.gzip,
|
||||||
ProducerMetadata.CompressionType.gzip,
|
|
||||||
ProducerMetadata.CompressionType.snappy };
|
ProducerMetadata.CompressionType.snappy };
|
||||||
|
byte[] testPayload = new byte[2048];
|
||||||
byte[] ratherBigPayload = new byte[2048];
|
Arrays.fill(testPayload, (byte) 65);
|
||||||
Arrays.fill(ratherBigPayload, (byte) 65);
|
|
||||||
KafkaTestBinder binder = getBinder();
|
KafkaTestBinder binder = getBinder();
|
||||||
|
|
||||||
for (ProducerMetadata.CompressionType codec : codecs) {
|
for (ProducerMetadata.CompressionType codec : codecs) {
|
||||||
DirectChannel moduleOutputChannel = new DirectChannel();
|
DirectChannel moduleOutputChannel = new DirectChannel();
|
||||||
QueueChannel moduleInputChannel = new QueueChannel();
|
QueueChannel moduleInputChannel = new QueueChannel();
|
||||||
ExtendedProducerProperties<KafkaProducerProperties> producerProperties = createProducerProperties();
|
ExtendedProducerProperties<KafkaProducerProperties> producerProperties = createProducerProperties();
|
||||||
producerProperties.getExtension().setCompressionType(codec);
|
producerProperties.getExtension().setCompressionType(codec);
|
||||||
Binding<MessageChannel> producerBinding = binder.bindProducer("foo.0", moduleOutputChannel, producerProperties);
|
Binding<MessageChannel> producerBinding = binder.bindProducer("foo.0", moduleOutputChannel,
|
||||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer("foo.0", "test", moduleInputChannel, createConsumerProperties());
|
producerProperties);
|
||||||
Message<?> message = org.springframework.integration.support.MessageBuilder.withPayload(ratherBigPayload).build();
|
Binding<MessageChannel> consumerBinding = binder.bindConsumer("foo.0", "test", moduleInputChannel,
|
||||||
|
createConsumerProperties());
|
||||||
|
Message<?> message = org.springframework.integration.support.MessageBuilder.withPayload(testPayload)
|
||||||
|
.build();
|
||||||
// Let the consumer actually bind to the producer before sending a msg
|
// Let the consumer actually bind to the producer before sending a msg
|
||||||
binderBindUnbindLatency();
|
binderBindUnbindLatency();
|
||||||
moduleOutputChannel.send(message);
|
moduleOutputChannel.send(message);
|
||||||
Message<?> inbound = receive(moduleInputChannel);
|
Message<?> inbound = receive(moduleInputChannel);
|
||||||
assertNotNull(inbound);
|
assertThat(inbound).isNotNull();
|
||||||
assertArrayEquals(ratherBigPayload, (byte[]) inbound.getPayload());
|
assertThat((byte[]) inbound.getPayload()).containsExactly(testPayload);
|
||||||
producerBinding.unbind();
|
producerBinding.unbind();
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
}
|
}
|
||||||
@@ -331,8 +316,8 @@ public class KafkaBinderTests extends
|
|||||||
@Test
|
@Test
|
||||||
public void testCustomPartitionCountOverridesDefaultIfLarger() throws Exception {
|
public void testCustomPartitionCountOverridesDefaultIfLarger() throws Exception {
|
||||||
|
|
||||||
byte[] ratherBigPayload = new byte[2048];
|
byte[] testPayload = new byte[2048];
|
||||||
Arrays.fill(ratherBigPayload, (byte) 65);
|
Arrays.fill(testPayload, (byte) 65);
|
||||||
KafkaBinderConfigurationProperties binderConfiguration = createConfigurationProperties();
|
KafkaBinderConfigurationProperties binderConfiguration = createConfigurationProperties();
|
||||||
binderConfiguration.setMinPartitionCount(10);
|
binderConfiguration.setMinPartitionCount(10);
|
||||||
KafkaTestBinder binder = new KafkaTestBinder(binderConfiguration);
|
KafkaTestBinder binder = new KafkaTestBinder(binderConfiguration);
|
||||||
@@ -343,18 +328,21 @@ public class KafkaBinderTests extends
|
|||||||
producerProperties.setPartitionCount(10);
|
producerProperties.setPartitionCount(10);
|
||||||
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
|
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
|
||||||
long uniqueBindingId = System.currentTimeMillis();
|
long uniqueBindingId = System.currentTimeMillis();
|
||||||
Binding<MessageChannel> producerBinding = binder.bindProducer("foo" + uniqueBindingId + ".0", moduleOutputChannel, producerProperties);
|
Binding<MessageChannel> producerBinding = binder.bindProducer("foo" + uniqueBindingId + ".0",
|
||||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer("foo" + uniqueBindingId + ".0", null, moduleInputChannel, consumerProperties);
|
moduleOutputChannel, producerProperties);
|
||||||
Message<?> message = org.springframework.integration.support.MessageBuilder.withPayload(ratherBigPayload).build();
|
Binding<MessageChannel> consumerBinding = binder.bindConsumer("foo" + uniqueBindingId + ".0", null,
|
||||||
|
moduleInputChannel, consumerProperties);
|
||||||
|
Message<?> message = org.springframework.integration.support.MessageBuilder.withPayload(testPayload)
|
||||||
|
.build();
|
||||||
// Let the consumer actually bind to the producer before sending a msg
|
// Let the consumer actually bind to the producer before sending a msg
|
||||||
binderBindUnbindLatency();
|
binderBindUnbindLatency();
|
||||||
moduleOutputChannel.send(message);
|
moduleOutputChannel.send(message);
|
||||||
Message<?> inbound = receive(moduleInputChannel);
|
Message<?> inbound = receive(moduleInputChannel);
|
||||||
assertNotNull(inbound);
|
assertThat(inbound).isNotNull();
|
||||||
assertArrayEquals(ratherBigPayload, (byte[]) inbound.getPayload());
|
assertThat((byte[]) inbound.getPayload()).containsExactly(testPayload);
|
||||||
Collection<Partition> partitions = binder.getCoreBinder().getConnectionFactory().getPartitions(
|
Collection<Partition> partitions = binder.getCoreBinder().getConnectionFactory()
|
||||||
"foo" + uniqueBindingId + ".0");
|
.getPartitions("foo" + uniqueBindingId + ".0");
|
||||||
assertThat(partitions, hasSize(10));
|
assertThat(partitions).hasSize(10);
|
||||||
producerBinding.unbind();
|
producerBinding.unbind();
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
}
|
}
|
||||||
@@ -362,8 +350,8 @@ public class KafkaBinderTests extends
|
|||||||
@Test
|
@Test
|
||||||
public void testCustomPartitionCountDoesNotOverridePartitioningIfSmaller() throws Exception {
|
public void testCustomPartitionCountDoesNotOverridePartitioningIfSmaller() throws Exception {
|
||||||
|
|
||||||
byte[] ratherBigPayload = new byte[2048];
|
byte[] testPayload = new byte[2048];
|
||||||
Arrays.fill(ratherBigPayload, (byte) 65);
|
Arrays.fill(testPayload, (byte) 65);
|
||||||
KafkaBinderConfigurationProperties binderConfiguration = createConfigurationProperties();
|
KafkaBinderConfigurationProperties binderConfiguration = createConfigurationProperties();
|
||||||
binderConfiguration.setMinPartitionCount(6);
|
binderConfiguration.setMinPartitionCount(6);
|
||||||
KafkaTestBinder binder = new KafkaTestBinder(binderConfiguration);
|
KafkaTestBinder binder = new KafkaTestBinder(binderConfiguration);
|
||||||
@@ -374,18 +362,21 @@ public class KafkaBinderTests extends
|
|||||||
producerProperties.setPartitionKeyExpression(spelExpressionParser.parseExpression("payload"));
|
producerProperties.setPartitionKeyExpression(spelExpressionParser.parseExpression("payload"));
|
||||||
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
|
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
|
||||||
long uniqueBindingId = System.currentTimeMillis();
|
long uniqueBindingId = System.currentTimeMillis();
|
||||||
Binding<MessageChannel> producerBinding = binder.bindProducer("foo" + uniqueBindingId + ".0", moduleOutputChannel, producerProperties);
|
Binding<MessageChannel> producerBinding = binder.bindProducer("foo" + uniqueBindingId + ".0",
|
||||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer("foo" + uniqueBindingId + ".0", null, moduleInputChannel, consumerProperties);
|
moduleOutputChannel, producerProperties);
|
||||||
Message<?> message = org.springframework.integration.support.MessageBuilder.withPayload(ratherBigPayload).build();
|
Binding<MessageChannel> consumerBinding = binder.bindConsumer("foo" + uniqueBindingId + ".0", null,
|
||||||
|
moduleInputChannel, consumerProperties);
|
||||||
|
Message<?> message = org.springframework.integration.support.MessageBuilder.withPayload(testPayload)
|
||||||
|
.build();
|
||||||
// Let the consumer actually bind to the producer before sending a msg
|
// Let the consumer actually bind to the producer before sending a msg
|
||||||
binderBindUnbindLatency();
|
binderBindUnbindLatency();
|
||||||
moduleOutputChannel.send(message);
|
moduleOutputChannel.send(message);
|
||||||
Message<?> inbound = receive(moduleInputChannel);
|
Message<?> inbound = receive(moduleInputChannel);
|
||||||
assertNotNull(inbound);
|
assertThat(inbound).isNotNull();
|
||||||
assertArrayEquals(ratherBigPayload, (byte[]) inbound.getPayload());
|
assertThat((byte[]) inbound.getPayload()).containsExactly(testPayload);
|
||||||
Collection<Partition> partitions = binder.getCoreBinder().getConnectionFactory().getPartitions(
|
Collection<Partition> partitions = binder.getCoreBinder().getConnectionFactory()
|
||||||
"foo" + uniqueBindingId + ".0");
|
.getPartitions("foo" + uniqueBindingId + ".0");
|
||||||
assertThat(partitions, hasSize(6));
|
assertThat(partitions).hasSize(6);
|
||||||
producerBinding.unbind();
|
producerBinding.unbind();
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
}
|
}
|
||||||
@@ -393,8 +384,8 @@ public class KafkaBinderTests extends
|
|||||||
@Test
|
@Test
|
||||||
public void testCustomPartitionCountOverridesPartitioningIfLarger() throws Exception {
|
public void testCustomPartitionCountOverridesPartitioningIfLarger() throws Exception {
|
||||||
|
|
||||||
byte[] ratherBigPayload = new byte[2048];
|
byte[] testPayload = new byte[2048];
|
||||||
Arrays.fill(ratherBigPayload, (byte) 65);
|
Arrays.fill(testPayload, (byte) 65);
|
||||||
KafkaBinderConfigurationProperties binderConfiguration = createConfigurationProperties();
|
KafkaBinderConfigurationProperties binderConfiguration = createConfigurationProperties();
|
||||||
binderConfiguration.setMinPartitionCount(4);
|
binderConfiguration.setMinPartitionCount(4);
|
||||||
KafkaTestBinder binder = new KafkaTestBinder(binderConfiguration);
|
KafkaTestBinder binder = new KafkaTestBinder(binderConfiguration);
|
||||||
@@ -406,18 +397,21 @@ public class KafkaBinderTests extends
|
|||||||
producerProperties.setPartitionKeyExpression(spelExpressionParser.parseExpression("payload"));
|
producerProperties.setPartitionKeyExpression(spelExpressionParser.parseExpression("payload"));
|
||||||
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
|
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
|
||||||
long uniqueBindingId = System.currentTimeMillis();
|
long uniqueBindingId = System.currentTimeMillis();
|
||||||
Binding<MessageChannel> producerBinding = binder.bindProducer("foo" + uniqueBindingId + ".0", moduleOutputChannel, producerProperties);
|
Binding<MessageChannel> producerBinding = binder.bindProducer("foo" + uniqueBindingId + ".0",
|
||||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer("foo" + uniqueBindingId + ".0", null, moduleInputChannel, consumerProperties);
|
moduleOutputChannel, producerProperties);
|
||||||
Message<?> message = org.springframework.integration.support.MessageBuilder.withPayload(ratherBigPayload).build();
|
Binding<MessageChannel> consumerBinding = binder.bindConsumer("foo" + uniqueBindingId + ".0", null,
|
||||||
|
moduleInputChannel, consumerProperties);
|
||||||
|
Message<?> message = org.springframework.integration.support.MessageBuilder.withPayload(testPayload)
|
||||||
|
.build();
|
||||||
// Let the consumer actually bind to the producer before sending a msg
|
// Let the consumer actually bind to the producer before sending a msg
|
||||||
binderBindUnbindLatency();
|
binderBindUnbindLatency();
|
||||||
moduleOutputChannel.send(message);
|
moduleOutputChannel.send(message);
|
||||||
Message<?> inbound = receive(moduleInputChannel);
|
Message<?> inbound = receive(moduleInputChannel);
|
||||||
assertNotNull(inbound);
|
assertThat(inbound).isNotNull();
|
||||||
assertArrayEquals(ratherBigPayload, (byte[]) inbound.getPayload());
|
assertThat((byte[]) inbound.getPayload()).containsExactly(testPayload);
|
||||||
Collection<Partition> partitions = binder.getCoreBinder().getConnectionFactory().getPartitions(
|
Collection<Partition> partitions = binder.getCoreBinder().getConnectionFactory()
|
||||||
"foo" + uniqueBindingId + ".0");
|
.getPartitions("foo" + uniqueBindingId + ".0");
|
||||||
assertThat(partitions, hasSize(5));
|
assertThat(partitions).hasSize(5);
|
||||||
producerBinding.unbind();
|
producerBinding.unbind();
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
}
|
}
|
||||||
@@ -439,13 +433,13 @@ public class KafkaBinderTests extends
|
|||||||
output.send(new GenericMessage<>(testPayload1.getBytes()));
|
output.send(new GenericMessage<>(testPayload1.getBytes()));
|
||||||
binder.bindConsumer(testTopicName, "startOffsets", input1, createConsumerProperties());
|
binder.bindConsumer(testTopicName, "startOffsets", input1, createConsumerProperties());
|
||||||
Message<byte[]> receivedMessage1 = (Message<byte[]>) receive(input1);
|
Message<byte[]> receivedMessage1 = (Message<byte[]>) receive(input1);
|
||||||
assertThat(receivedMessage1, not(nullValue()));
|
assertThat(receivedMessage1).isNotNull();
|
||||||
assertThat(new String(receivedMessage1.getPayload()), equalTo(testPayload1));
|
assertThat(new String(receivedMessage1.getPayload())).isEqualTo(testPayload1);
|
||||||
String testPayload2 = "foo-" + UUID.randomUUID().toString();
|
String testPayload2 = "foo-" + UUID.randomUUID().toString();
|
||||||
output.send(new GenericMessage<>(testPayload2.getBytes()));
|
output.send(new GenericMessage<>(testPayload2.getBytes()));
|
||||||
Message<byte[]> receivedMessage2 = (Message<byte[]>) receive(input1);
|
Message<byte[]> receivedMessage2 = (Message<byte[]>) receive(input1);
|
||||||
assertThat(receivedMessage2, not(nullValue()));
|
assertThat(receivedMessage2).isNotNull();
|
||||||
assertThat(new String(receivedMessage2.getPayload()), equalTo(testPayload2));
|
assertThat(new String(receivedMessage2.getPayload())).isEqualTo(testPayload2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -463,12 +457,12 @@ public class KafkaBinderTests extends
|
|||||||
properties.getExtension().setStartOffset(KafkaMessageChannelBinder.StartOffset.earliest);
|
properties.getExtension().setStartOffset(KafkaMessageChannelBinder.StartOffset.earliest);
|
||||||
binder.bindConsumer(testTopicName, "startOffsets", input1, properties);
|
binder.bindConsumer(testTopicName, "startOffsets", input1, properties);
|
||||||
Message<byte[]> receivedMessage1 = (Message<byte[]>) receive(input1);
|
Message<byte[]> receivedMessage1 = (Message<byte[]>) receive(input1);
|
||||||
assertThat(receivedMessage1, not(nullValue()));
|
assertThat(receivedMessage1).isNotNull();
|
||||||
String testPayload2 = "foo-" + UUID.randomUUID().toString();
|
String testPayload2 = "foo-" + UUID.randomUUID().toString();
|
||||||
output.send(new GenericMessage<>(testPayload2.getBytes()));
|
output.send(new GenericMessage<>(testPayload2.getBytes()));
|
||||||
Message<byte[]> receivedMessage2 = (Message<byte[]>) receive(input1);
|
Message<byte[]> receivedMessage2 = (Message<byte[]>) receive(input1);
|
||||||
assertThat(receivedMessage2, not(nullValue()));
|
assertThat(receivedMessage2).isNotNull();
|
||||||
assertThat(new String(receivedMessage2.getPayload()), equalTo(testPayload2));
|
assertThat(new String(receivedMessage2.getPayload())).isEqualTo(testPayload2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -480,21 +474,22 @@ public class KafkaBinderTests extends
|
|||||||
|
|
||||||
String testTopicName = UUID.randomUUID().toString();
|
String testTopicName = UUID.randomUUID().toString();
|
||||||
|
|
||||||
Binding<MessageChannel> producerBinding = binder.bindProducer(testTopicName, output, createProducerProperties());
|
Binding<MessageChannel> producerBinding = binder.bindProducer(testTopicName, output,
|
||||||
|
createProducerProperties());
|
||||||
String testPayload1 = "foo-" + UUID.randomUUID().toString();
|
String testPayload1 = "foo-" + UUID.randomUUID().toString();
|
||||||
output.send(new GenericMessage<>(testPayload1.getBytes()));
|
output.send(new GenericMessage<>(testPayload1.getBytes()));
|
||||||
ExtendedConsumerProperties<KafkaConsumerProperties> properties = createConsumerProperties();
|
ExtendedConsumerProperties<KafkaConsumerProperties> properties = createConsumerProperties();
|
||||||
properties.getExtension().setResetOffsets(true);
|
properties.getExtension().setResetOffsets(true);
|
||||||
properties.getExtension().setStartOffset(KafkaMessageChannelBinder.StartOffset.earliest);
|
properties.getExtension().setStartOffset(KafkaMessageChannelBinder.StartOffset.earliest);
|
||||||
Binding<MessageChannel> consumerBinding =
|
Binding<MessageChannel> consumerBinding = binder.bindConsumer(testTopicName, "startOffsets", input1,
|
||||||
binder.bindConsumer(testTopicName, "startOffsets", input1, properties);
|
properties);
|
||||||
Message<byte[]> receivedMessage1 = (Message<byte[]>) receive(input1);
|
Message<byte[]> receivedMessage1 = (Message<byte[]>) receive(input1);
|
||||||
assertThat(receivedMessage1, not(nullValue()));
|
assertThat(receivedMessage1).isNotNull();
|
||||||
String testPayload2 = "foo-" + UUID.randomUUID().toString();
|
String testPayload2 = "foo-" + UUID.randomUUID().toString();
|
||||||
output.send(new GenericMessage<>(testPayload2.getBytes()));
|
output.send(new GenericMessage<>(testPayload2.getBytes()));
|
||||||
Message<byte[]> receivedMessage2 = (Message<byte[]>) receive(input1);
|
Message<byte[]> receivedMessage2 = (Message<byte[]>) receive(input1);
|
||||||
assertThat(receivedMessage2, not(nullValue()));
|
assertThat(receivedMessage2).isNotNull();
|
||||||
assertThat(new String(receivedMessage2.getPayload()), equalTo(testPayload2));
|
assertThat(new String(receivedMessage2.getPayload())).isEqualTo(testPayload2);
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
|
|
||||||
String testPayload3 = "foo-" + UUID.randomUUID().toString();
|
String testPayload3 = "foo-" + UUID.randomUUID().toString();
|
||||||
@@ -503,17 +498,16 @@ public class KafkaBinderTests extends
|
|||||||
ExtendedConsumerProperties<KafkaConsumerProperties> properties2 = createConsumerProperties();
|
ExtendedConsumerProperties<KafkaConsumerProperties> properties2 = createConsumerProperties();
|
||||||
properties2.getExtension().setResetOffsets(true);
|
properties2.getExtension().setResetOffsets(true);
|
||||||
properties2.getExtension().setStartOffset(KafkaMessageChannelBinder.StartOffset.earliest);
|
properties2.getExtension().setStartOffset(KafkaMessageChannelBinder.StartOffset.earliest);
|
||||||
consumerBinding =
|
consumerBinding = binder.bindConsumer(testTopicName, "startOffsets", input1, properties2);
|
||||||
binder.bindConsumer(testTopicName, "startOffsets", input1, properties2);
|
|
||||||
Message<byte[]> receivedMessage4 = (Message<byte[]>) receive(input1);
|
Message<byte[]> receivedMessage4 = (Message<byte[]>) receive(input1);
|
||||||
assertThat(receivedMessage4, not(nullValue()));
|
assertThat(receivedMessage4).isNotNull();
|
||||||
assertThat(new String(receivedMessage4.getPayload()), equalTo(testPayload1));
|
assertThat(new String(receivedMessage4.getPayload())).isEqualTo(testPayload1);
|
||||||
Message<byte[]> receivedMessage5 = (Message<byte[]>) receive(input1);
|
Message<byte[]> receivedMessage5 = (Message<byte[]>) receive(input1);
|
||||||
assertThat(receivedMessage5, not(nullValue()));
|
assertThat(receivedMessage5).isNotNull();
|
||||||
assertThat(new String(receivedMessage5.getPayload()), equalTo(testPayload2));
|
assertThat(new String(receivedMessage5.getPayload())).isEqualTo(testPayload2);
|
||||||
Message<byte[]> receivedMessage6 = (Message<byte[]>) receive(input1);
|
Message<byte[]> receivedMessage6 = (Message<byte[]>) receive(input1);
|
||||||
assertThat(receivedMessage6, not(nullValue()));
|
assertThat(receivedMessage6).isNotNull();
|
||||||
assertThat(new String(receivedMessage6.getPayload()), equalTo(testPayload3));
|
assertThat(new String(receivedMessage6.getPayload())).isEqualTo(testPayload3);
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
producerBinding.unbind();
|
producerBinding.unbind();
|
||||||
}
|
}
|
||||||
@@ -531,28 +525,29 @@ public class KafkaBinderTests extends
|
|||||||
QueueChannel input1 = new QueueChannel();
|
QueueChannel input1 = new QueueChannel();
|
||||||
|
|
||||||
String testTopicName = UUID.randomUUID().toString();
|
String testTopicName = UUID.randomUUID().toString();
|
||||||
Binding<MessageChannel> producerBinding = binder.bindProducer(testTopicName, output, createProducerProperties());
|
Binding<MessageChannel> producerBinding = binder.bindProducer(testTopicName, output,
|
||||||
|
createProducerProperties());
|
||||||
String testPayload1 = "foo-" + UUID.randomUUID().toString();
|
String testPayload1 = "foo-" + UUID.randomUUID().toString();
|
||||||
output.send(new GenericMessage<>(testPayload1.getBytes()));
|
output.send(new GenericMessage<>(testPayload1.getBytes()));
|
||||||
ExtendedConsumerProperties<KafkaConsumerProperties> firstConsumerProperties = createConsumerProperties();
|
ExtendedConsumerProperties<KafkaConsumerProperties> firstConsumerProperties = createConsumerProperties();
|
||||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(testTopicName, "startOffsets", input1, firstConsumerProperties);
|
Binding<MessageChannel> consumerBinding = binder.bindConsumer(testTopicName, "startOffsets", input1,
|
||||||
|
firstConsumerProperties);
|
||||||
Message<byte[]> receivedMessage1 = (Message<byte[]>) receive(input1);
|
Message<byte[]> receivedMessage1 = (Message<byte[]>) receive(input1);
|
||||||
assertThat(receivedMessage1, not(nullValue()));
|
assertThat(receivedMessage1).isNotNull();
|
||||||
String testPayload2 = "foo-" + UUID.randomUUID().toString();
|
String testPayload2 = "foo-" + UUID.randomUUID().toString();
|
||||||
output.send(new GenericMessage<>(testPayload2.getBytes()));
|
output.send(new GenericMessage<>(testPayload2.getBytes()));
|
||||||
Message<byte[]> receivedMessage2 = (Message<byte[]>) receive(input1);
|
Message<byte[]> receivedMessage2 = (Message<byte[]>) receive(input1);
|
||||||
assertThat(receivedMessage2, not(nullValue()));
|
assertThat(receivedMessage2).isNotNull();
|
||||||
assertThat(new String(receivedMessage2.getPayload()), equalTo(testPayload2));
|
assertThat(new String(receivedMessage2.getPayload())).isNotNull();
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
|
|
||||||
String testPayload3 = "foo-" + UUID.randomUUID().toString();
|
String testPayload3 = "foo-" + UUID.randomUUID().toString();
|
||||||
output.send(new GenericMessage<>(testPayload3.getBytes()));
|
output.send(new GenericMessage<>(testPayload3.getBytes()));
|
||||||
|
|
||||||
consumerBinding =
|
consumerBinding = binder.bindConsumer(testTopicName, "startOffsets", input1, createConsumerProperties());
|
||||||
binder.bindConsumer(testTopicName, "startOffsets", input1, createConsumerProperties());
|
|
||||||
Message<byte[]> receivedMessage3 = (Message<byte[]>) receive(input1);
|
Message<byte[]> receivedMessage3 = (Message<byte[]>) receive(input1);
|
||||||
assertThat(receivedMessage3, not(nullValue()));
|
assertThat(receivedMessage3).isNotNull();
|
||||||
assertThat(new String(receivedMessage3.getPayload()), equalTo(testPayload3));
|
assertThat(new String(receivedMessage3.getPayload())).isEqualTo(testPayload3);
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
producerBinding.unbind();
|
producerBinding.unbind();
|
||||||
}
|
}
|
||||||
@@ -572,8 +567,10 @@ public class KafkaBinderTests extends
|
|||||||
DirectFieldAccessor accessor = new DirectFieldAccessor(extractEndpoint(producerBinding));
|
DirectFieldAccessor accessor = new DirectFieldAccessor(extractEndpoint(producerBinding));
|
||||||
MessageHandler handler = (MessageHandler) accessor.getPropertyValue("handler");
|
MessageHandler handler = (MessageHandler) accessor.getPropertyValue("handler");
|
||||||
DirectFieldAccessor accessor1 = new DirectFieldAccessor(handler);
|
DirectFieldAccessor accessor1 = new DirectFieldAccessor(handler);
|
||||||
ProducerConfiguration producerConfiguration = (ProducerConfiguration) accessor1.getPropertyValue("producerConfiguration");
|
ProducerConfiguration producerConfiguration = (ProducerConfiguration) accessor1
|
||||||
assertTrue("Kafka Sync Producer should have been enabled.", producerConfiguration.getProducerMetadata().isSync());
|
.getPropertyValue("producerConfiguration");
|
||||||
|
assertThat(producerConfiguration.getProducerMetadata().isSync())
|
||||||
|
.withFailMessage("Kafka Sync Producer should have been enabled.");
|
||||||
producerBinding.unbind();
|
producerBinding.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -594,14 +591,14 @@ public class KafkaBinderTests extends
|
|||||||
binder.setMetadataRetryOperations(metatadataRetrievalRetryOperations);
|
binder.setMetadataRetryOperations(metatadataRetrievalRetryOperations);
|
||||||
DirectChannel output = new DirectChannel();
|
DirectChannel output = new DirectChannel();
|
||||||
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
|
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
|
||||||
String testTopicName = "nonexisting" + System.currentTimeMillis();
|
String testTopicName = "nonexisting" + System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
binder.doBindConsumer(testTopicName, "test", output, consumerProperties);
|
binder.doBindConsumer(testTopicName, "test", output, consumerProperties);
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
assertTrue(e instanceof BinderException);
|
assertThat(e).isInstanceOf(BinderException.class);
|
||||||
assertThat(e.getMessage(), containsString("Topic " + testTopicName + " does not exist"));
|
assertThat(e).hasMessageContaining("Topic " + testTopicName + " does not exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -609,13 +606,13 @@ public class KafkaBinderTests extends
|
|||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
assertThat(e, instanceOf(TopicNotFoundException.class));
|
assertThat(e).isInstanceOf(TopicNotFoundException.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAutoConfigureTopicsDisabledSucceedsIfTopicExisting() throws Exception {
|
public void testAutoConfigureTopicsDisabledSucceedsIfTopicExisting() throws Exception {
|
||||||
String testTopicName = "existing" + System.currentTimeMillis();
|
String testTopicName = "existing" + System.currentTimeMillis();
|
||||||
AdminUtils.createTopic(kafkaTestSupport.getZkClient(), testTopicName, 5, 1, new Properties());
|
AdminUtils.createTopic(kafkaTestSupport.getZkClient(), testTopicName, 5, 1, new Properties());
|
||||||
KafkaBinderConfigurationProperties configurationProperties = createConfigurationProperties();
|
KafkaBinderConfigurationProperties configurationProperties = createConfigurationProperties();
|
||||||
configurationProperties.setAutoCreateTopics(false);
|
configurationProperties.setAutoCreateTopics(false);
|
||||||
@@ -632,7 +629,7 @@ public class KafkaBinderTests extends
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAutoAddPartitionsDisabledFailsIfTopicUnderpartitioned() throws Exception {
|
public void testAutoAddPartitionsDisabledFailsIfTopicUnderpartitioned() throws Exception {
|
||||||
String testTopicName = "existing" + System.currentTimeMillis();
|
String testTopicName = "existing" + System.currentTimeMillis();
|
||||||
AdminUtils.createTopic(kafkaTestSupport.getZkClient(), testTopicName, 1, 1, new Properties());
|
AdminUtils.createTopic(kafkaTestSupport.getZkClient(), testTopicName, 1, 1, new Properties());
|
||||||
KafkaBinderConfigurationProperties configurationProperties = createConfigurationProperties();
|
KafkaBinderConfigurationProperties configurationProperties = createConfigurationProperties();
|
||||||
configurationProperties.setAutoAddPartitions(false);
|
configurationProperties.setAutoAddPartitions(false);
|
||||||
@@ -650,16 +647,16 @@ public class KafkaBinderTests extends
|
|||||||
binder.doBindConsumer(testTopicName, "test", output, consumerProperties);
|
binder.doBindConsumer(testTopicName, "test", output, consumerProperties);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
assertThat(e, instanceOf(BinderException.class));
|
assertThat(e).isInstanceOf(BinderException.class);
|
||||||
assertThat(e.getMessage(),
|
assertThat(e)
|
||||||
containsString("The number of expected partitions was: 3, but 1 has been found instead"));
|
.hasMessageContaining("The number of expected partitions was: 3, but 1 has been found instead");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAutoAddPartitionsDisabledSucceedsIfTopicPartitionedCorrectly() throws Exception {
|
public void testAutoAddPartitionsDisabledSucceedsIfTopicPartitionedCorrectly() throws Exception {
|
||||||
|
|
||||||
String testTopicName = "existing" + System.currentTimeMillis();
|
String testTopicName = "existing" + System.currentTimeMillis();
|
||||||
AdminUtils.createTopic(kafkaTestSupport.getZkClient(), testTopicName, 6, 1, new Properties());
|
AdminUtils.createTopic(kafkaTestSupport.getZkClient(), testTopicName, 6, 1, new Properties());
|
||||||
KafkaBinderConfigurationProperties configurationProperties = createConfigurationProperties();
|
KafkaBinderConfigurationProperties configurationProperties = createConfigurationProperties();
|
||||||
configurationProperties.setAutoAddPartitions(false);
|
configurationProperties.setAutoAddPartitions(false);
|
||||||
@@ -682,14 +679,13 @@ public class KafkaBinderTests extends
|
|||||||
|
|
||||||
Binding<?> binding = binder.doBindConsumer(testTopicName, "test", output, consumerProperties);
|
Binding<?> binding = binder.doBindConsumer(testTopicName, "test", output, consumerProperties);
|
||||||
|
|
||||||
Partition[] listenedPartitions
|
Partition[] listenedPartitions = TestUtils.getPropertyValue(binding,
|
||||||
= TestUtils.getPropertyValue(binding, "endpoint.val$messageListenerContainer.partitions", Partition[].class);
|
"endpoint.val$messageListenerContainer.partitions", Partition[].class);
|
||||||
|
|
||||||
assertThat(listenedPartitions, arrayWithSize(2));
|
assertThat(listenedPartitions).hasSize(2);
|
||||||
assertThat(listenedPartitions, hasItemInArray(new Partition(testTopicName, 2)));
|
assertThat(listenedPartitions).contains(new Partition(testTopicName, 2), new Partition(testTopicName, 5));
|
||||||
assertThat(listenedPartitions, hasItemInArray(new Partition(testTopicName, 5)));
|
|
||||||
Collection<Partition> partitions = binder.getConnectionFactory().getPartitions(testTopicName);
|
Collection<Partition> partitions = binder.getConnectionFactory().getPartitions(testTopicName);
|
||||||
assertThat(partitions, IsCollectionWithSize.hasSize(6));
|
assertThat(partitions).hasSize(6);
|
||||||
binding.unbind();
|
binding.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -710,14 +706,14 @@ public class KafkaBinderTests extends
|
|||||||
binder.setMetadataRetryOperations(metatadataRetrievalRetryOperations);
|
binder.setMetadataRetryOperations(metatadataRetrievalRetryOperations);
|
||||||
DirectChannel output = new DirectChannel();
|
DirectChannel output = new DirectChannel();
|
||||||
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
|
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
|
||||||
String testTopicName = "nonexisting" + System.currentTimeMillis();
|
String testTopicName = "nonexisting" + System.currentTimeMillis();
|
||||||
Binding<?> binding = binder.doBindConsumer(testTopicName, "test", output, consumerProperties);
|
Binding<?> binding = binder.doBindConsumer(testTopicName, "test", output, consumerProperties);
|
||||||
binding.unbind();
|
binding.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPartitionCountNotReduced() throws Exception {
|
public void testPartitionCountNotReduced() throws Exception {
|
||||||
String testTopicName = "existing" + System.currentTimeMillis();
|
String testTopicName = "existing" + System.currentTimeMillis();
|
||||||
AdminUtils.createTopic(kafkaTestSupport.getZkClient(), testTopicName, 6, 1, new Properties());
|
AdminUtils.createTopic(kafkaTestSupport.getZkClient(), testTopicName, 6, 1, new Properties());
|
||||||
KafkaBinderConfigurationProperties configurationProperties = createConfigurationProperties();
|
KafkaBinderConfigurationProperties configurationProperties = createConfigurationProperties();
|
||||||
configurationProperties.setAutoAddPartitions(true);
|
configurationProperties.setAutoAddPartitions(true);
|
||||||
@@ -736,13 +732,14 @@ public class KafkaBinderTests extends
|
|||||||
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
|
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
|
||||||
Binding<?> binding = binder.doBindConsumer(testTopicName, "test", output, consumerProperties);
|
Binding<?> binding = binder.doBindConsumer(testTopicName, "test", output, consumerProperties);
|
||||||
binding.unbind();
|
binding.unbind();
|
||||||
TopicMetadata topicMetadata = AdminUtils.fetchTopicMetadataFromZk(testTopicName, kafkaTestSupport.getZkClient());
|
TopicMetadata topicMetadata = AdminUtils.fetchTopicMetadataFromZk(testTopicName,
|
||||||
assertThat(topicMetadata.partitionsMetadata().size(), equalTo(6));
|
kafkaTestSupport.getZkClient());
|
||||||
|
assertThat(topicMetadata.partitionsMetadata().size()).isEqualTo(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPartitionCountIncreasedIfAutoAddPartitionsSet() throws Exception {
|
public void testPartitionCountIncreasedIfAutoAddPartitionsSet() throws Exception {
|
||||||
String testTopicName = "existing" + System.currentTimeMillis();
|
String testTopicName = "existing" + System.currentTimeMillis();
|
||||||
AdminUtils.createTopic(kafkaTestSupport.getZkClient(), testTopicName, 1, 1, new Properties());
|
AdminUtils.createTopic(kafkaTestSupport.getZkClient(), testTopicName, 1, 1, new Properties());
|
||||||
KafkaBinderConfigurationProperties configurationProperties = createConfigurationProperties();
|
KafkaBinderConfigurationProperties configurationProperties = createConfigurationProperties();
|
||||||
configurationProperties.setMinPartitionCount(6);
|
configurationProperties.setMinPartitionCount(6);
|
||||||
@@ -762,8 +759,9 @@ public class KafkaBinderTests extends
|
|||||||
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
|
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
|
||||||
Binding<?> binding = binder.doBindConsumer(testTopicName, "test", output, consumerProperties);
|
Binding<?> binding = binder.doBindConsumer(testTopicName, "test", output, consumerProperties);
|
||||||
binding.unbind();
|
binding.unbind();
|
||||||
TopicMetadata topicMetadata = AdminUtils.fetchTopicMetadataFromZk(testTopicName, kafkaTestSupport.getZkClient());
|
TopicMetadata topicMetadata = AdminUtils.fetchTopicMetadataFromZk(testTopicName,
|
||||||
assertThat(topicMetadata.partitionsMetadata().size(), equalTo(6));
|
kafkaTestSupport.getZkClient());
|
||||||
|
assertThat(topicMetadata.partitionsMetadata().size()).isEqualTo(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class FailingInvocationCountingMessageHandler implements MessageHandler {
|
private static final class FailingInvocationCountingMessageHandler implements MessageHandler {
|
||||||
@@ -786,7 +784,8 @@ public class KafkaBinderTests extends
|
|||||||
public void handleMessage(Message<?> message) throws MessagingException {
|
public void handleMessage(Message<?> message) throws MessagingException {
|
||||||
invocationCount++;
|
invocationCount++;
|
||||||
Long offset = message.getHeaders().get(KafkaHeaders.OFFSET, Long.class);
|
Long offset = message.getHeaders().get(KafkaHeaders.OFFSET, Long.class);
|
||||||
// using the offset as key allows to ensure that we don't store duplicate messages on retry
|
// using the offset as key allows to ensure that we don't store duplicate
|
||||||
|
// messages on retry
|
||||||
if (!receivedMessages.containsKey(offset)) {
|
if (!receivedMessages.containsKey(offset)) {
|
||||||
receivedMessages.put(offset, message);
|
receivedMessages.put(offset, message);
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import java.util.Arrays;
|
|||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.cloud.stream.binder.BinderHeaders;
|
|
||||||
import org.springframework.cloud.stream.binder.Binding;
|
import org.springframework.cloud.stream.binder.Binding;
|
||||||
import org.springframework.cloud.stream.binder.ExtendedConsumerProperties;
|
import org.springframework.cloud.stream.binder.ExtendedConsumerProperties;
|
||||||
import org.springframework.cloud.stream.binder.ExtendedProducerProperties;
|
import org.springframework.cloud.stream.binder.ExtendedProducerProperties;
|
||||||
@@ -35,13 +34,7 @@ import org.springframework.messaging.Message;
|
|||||||
import org.springframework.messaging.MessageChannel;
|
import org.springframework.messaging.MessageChannel;
|
||||||
import org.springframework.messaging.support.GenericMessage;
|
import org.springframework.messaging.support.GenericMessage;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.Matchers.containsString;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Marius Bogoevici
|
* @author Marius Bogoevici
|
||||||
@@ -88,14 +81,14 @@ public class RawModeKafkaBinderTests extends KafkaBinderTests {
|
|||||||
output.send(new GenericMessage<>(new byte[] { (byte) 2 }));
|
output.send(new GenericMessage<>(new byte[] { (byte) 2 }));
|
||||||
|
|
||||||
Message<?> receive0 = receive(input0);
|
Message<?> receive0 = receive(input0);
|
||||||
assertNotNull(receive0);
|
assertThat(receive0).isNotNull();
|
||||||
Message<?> receive1 = receive(input1);
|
Message<?> receive1 = receive(input1);
|
||||||
assertNotNull(receive1);
|
assertThat(receive1).isNotNull();
|
||||||
Message<?> receive2 = receive(input2);
|
Message<?> receive2 = receive(input2);
|
||||||
assertNotNull(receive2);
|
assertThat(receive2).isNotNull();
|
||||||
|
|
||||||
assertThat(Arrays.asList(((byte[]) receive0.getPayload())[0], ((byte[]) receive1.getPayload())[0],
|
assertThat(Arrays.asList(((byte[]) receive0.getPayload())[0], ((byte[]) receive1.getPayload())[0],
|
||||||
((byte[]) receive2.getPayload())[0]), containsInAnyOrder((byte) 0, (byte) 1, (byte) 2));
|
((byte[]) receive2.getPayload())[0])).containsExactlyInAnyOrder((byte) 0, (byte) 1, (byte) 2);
|
||||||
|
|
||||||
input0Binding.unbind();
|
input0Binding.unbind();
|
||||||
input1Binding.unbind();
|
input1Binding.unbind();
|
||||||
@@ -118,7 +111,7 @@ public class RawModeKafkaBinderTests extends KafkaBinderTests {
|
|||||||
Binding<MessageChannel> outputBinding = binder.bindProducer("part.0", output, properties);
|
Binding<MessageChannel> outputBinding = binder.bindProducer("part.0", output, properties);
|
||||||
try {
|
try {
|
||||||
AbstractEndpoint endpoint = extractEndpoint(outputBinding);
|
AbstractEndpoint endpoint = extractEndpoint(outputBinding);
|
||||||
assertThat(getEndpointRouting(endpoint), containsString("part.0-' + headers['partition']"));
|
assertThat(getEndpointRouting(endpoint)).contains("part.0-' + headers['partition']");
|
||||||
}
|
}
|
||||||
catch (UnsupportedOperationException ignored) {
|
catch (UnsupportedOperationException ignored) {
|
||||||
|
|
||||||
@@ -142,29 +135,21 @@ public class RawModeKafkaBinderTests extends KafkaBinderTests {
|
|||||||
input2.setBeanName("test.input2S");
|
input2.setBeanName("test.input2S");
|
||||||
Binding<MessageChannel> input2Binding = binder.bindConsumer("part.0", "test", input2, consumerProperties);
|
Binding<MessageChannel> input2Binding = binder.bindConsumer("part.0", "test", input2, consumerProperties);
|
||||||
|
|
||||||
Message<byte[]> message2 = MessageBuilder.withPayload(new byte[]{2})
|
Message<byte[]> message2 = MessageBuilder.withPayload(new byte[] { 2 })
|
||||||
.setHeader(IntegrationMessageHeaderAccessor.CORRELATION_ID, "foo")
|
.setHeader(IntegrationMessageHeaderAccessor.CORRELATION_ID, "foo")
|
||||||
.setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, 42)
|
.setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, 42)
|
||||||
.setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE, 43)
|
.setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE, 43).build();
|
||||||
.build();
|
|
||||||
output.send(message2);
|
output.send(message2);
|
||||||
output.send(new GenericMessage<>(new byte[]{1}));
|
output.send(new GenericMessage<>(new byte[] { 1 }));
|
||||||
output.send(new GenericMessage<>(new byte[]{0}));
|
output.send(new GenericMessage<>(new byte[] { 0 }));
|
||||||
|
|
||||||
Message<?> receive0 = receive(input0);
|
Message<?> receive0 = receive(input0);
|
||||||
assertNotNull(receive0);
|
assertThat(receive0).isNotNull();
|
||||||
Message<?> receive1 = receive(input1);
|
Message<?> receive1 = receive(input1);
|
||||||
assertNotNull(receive1);
|
assertThat(receive1).isNotNull();
|
||||||
Message<?> receive2 = receive(input2);
|
Message<?> receive2 = receive(input2);
|
||||||
assertNotNull(receive2);
|
assertThat(receive2).isNotNull();
|
||||||
|
assertThat(Arrays.asList(((byte[]) receive0.getPayload())[0], ((byte[]) receive1.getPayload())[0],
|
||||||
|
((byte[]) receive2.getPayload())[0])).containsExactlyInAnyOrder((byte) 0, (byte) 1, (byte) 2);
|
||||||
assertThat(Arrays.asList(
|
|
||||||
((byte[]) receive0.getPayload())[0],
|
|
||||||
((byte[]) receive1.getPayload())[0],
|
|
||||||
((byte[]) receive2.getPayload())[0]),
|
|
||||||
containsInAnyOrder((byte) 0, (byte) 1, (byte) 2));
|
|
||||||
|
|
||||||
input0Binding.unbind();
|
input0Binding.unbind();
|
||||||
input1Binding.unbind();
|
input1Binding.unbind();
|
||||||
input2Binding.unbind();
|
input2Binding.unbind();
|
||||||
@@ -182,14 +167,15 @@ public class RawModeKafkaBinderTests extends KafkaBinderTests {
|
|||||||
Binding<MessageChannel> producerBinding = binder.bindProducer("foo.0", moduleOutputChannel, producerProperties);
|
Binding<MessageChannel> producerBinding = binder.bindProducer("foo.0", moduleOutputChannel, producerProperties);
|
||||||
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
|
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
|
||||||
consumerProperties.setHeaderMode(HeaderMode.raw);
|
consumerProperties.setHeaderMode(HeaderMode.raw);
|
||||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer("foo.0", "test", moduleInputChannel, consumerProperties);
|
Binding<MessageChannel> consumerBinding = binder.bindConsumer("foo.0", "test", moduleInputChannel,
|
||||||
|
consumerProperties);
|
||||||
Message<?> message = MessageBuilder.withPayload("foo".getBytes()).build();
|
Message<?> message = MessageBuilder.withPayload("foo".getBytes()).build();
|
||||||
// Let the consumer actually bind to the producer before sending a msg
|
// Let the consumer actually bind to the producer before sending a msg
|
||||||
binderBindUnbindLatency();
|
binderBindUnbindLatency();
|
||||||
moduleOutputChannel.send(message);
|
moduleOutputChannel.send(message);
|
||||||
Message<?> inbound = receive(moduleInputChannel);
|
Message<?> inbound = receive(moduleInputChannel);
|
||||||
assertNotNull(inbound);
|
assertThat(inbound).isNotNull();
|
||||||
assertEquals("foo", new String((byte[]) inbound.getPayload()));
|
assertThat(new String((byte[]) inbound.getPayload())).isEqualTo("foo");
|
||||||
producerBinding.unbind();
|
producerBinding.unbind();
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
}
|
}
|
||||||
@@ -215,13 +201,16 @@ public class RawModeKafkaBinderTests extends KafkaBinderTests {
|
|||||||
Binding<MessageChannel> producerBinding = binder.bindProducer("baz.0", moduleOutputChannel, producerProperties);
|
Binding<MessageChannel> producerBinding = binder.bindProducer("baz.0", moduleOutputChannel, producerProperties);
|
||||||
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
|
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
|
||||||
consumerProperties.setHeaderMode(HeaderMode.raw);
|
consumerProperties.setHeaderMode(HeaderMode.raw);
|
||||||
Binding<MessageChannel> input1Binding = binder.bindConsumer("baz.0", "test", module1InputChannel, consumerProperties);
|
Binding<MessageChannel> input1Binding = binder.bindConsumer("baz.0", "test", module1InputChannel,
|
||||||
|
consumerProperties);
|
||||||
// A new module is using the tap as an input channel
|
// A new module is using the tap as an input channel
|
||||||
String fooTapName = "baz.0";
|
String fooTapName = "baz.0";
|
||||||
Binding<MessageChannel> input2Binding = binder.bindConsumer(fooTapName, "tap1", module2InputChannel, consumerProperties);
|
Binding<MessageChannel> input2Binding = binder.bindConsumer(fooTapName, "tap1", module2InputChannel,
|
||||||
|
consumerProperties);
|
||||||
// Another new module is using tap as an input channel
|
// Another new module is using tap as an input channel
|
||||||
String barTapName = "baz.0";
|
String barTapName = "baz.0";
|
||||||
Binding<MessageChannel> input3Binding = binder.bindConsumer(barTapName, "tap2", module3InputChannel, consumerProperties);
|
Binding<MessageChannel> input3Binding = binder.bindConsumer(barTapName, "tap2", module3InputChannel,
|
||||||
|
consumerProperties);
|
||||||
|
|
||||||
Message<?> message = MessageBuilder.withPayload("foo".getBytes()).build();
|
Message<?> message = MessageBuilder.withPayload("foo".getBytes()).build();
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
@@ -229,20 +218,20 @@ public class RawModeKafkaBinderTests extends KafkaBinderTests {
|
|||||||
while (!success) {
|
while (!success) {
|
||||||
moduleOutputChannel.send(message);
|
moduleOutputChannel.send(message);
|
||||||
Message<?> inbound = receive(module1InputChannel);
|
Message<?> inbound = receive(module1InputChannel);
|
||||||
assertNotNull(inbound);
|
assertThat(inbound).isNotNull();
|
||||||
assertEquals("foo", new String((byte[]) inbound.getPayload()));
|
assertThat(new String((byte[]) inbound.getPayload())).isEqualTo("foo");
|
||||||
|
|
||||||
Message<?> tapped1 = receive(module2InputChannel);
|
Message<?> tapped1 = receive(module2InputChannel);
|
||||||
Message<?> tapped2 = receive(module3InputChannel);
|
Message<?> tapped2 = receive(module3InputChannel);
|
||||||
if (tapped1 == null || tapped2 == null) {
|
if (tapped1 == null || tapped2 == null) {
|
||||||
// listener may not have started
|
// listener may not have started
|
||||||
assertFalse("Failed to receive tap after retry", retried);
|
assertThat(retried).isFalse().withFailMessage("Failed to receive tap after retry");
|
||||||
retried = true;
|
retried = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
success = true;
|
success = true;
|
||||||
assertEquals("foo", new String((byte[]) tapped1.getPayload()));
|
assertThat(new String((byte[]) tapped1.getPayload())).isEqualTo("foo");
|
||||||
assertEquals("foo", new String((byte[]) tapped2.getPayload()));
|
assertThat(new String((byte[]) tapped2.getPayload())).isEqualTo("foo");
|
||||||
}
|
}
|
||||||
// delete one tap stream is deleted
|
// delete one tap stream is deleted
|
||||||
input3Binding.unbind();
|
input3Binding.unbind();
|
||||||
@@ -251,31 +240,23 @@ public class RawModeKafkaBinderTests extends KafkaBinderTests {
|
|||||||
|
|
||||||
// other tap still receives messages
|
// other tap still receives messages
|
||||||
Message<?> tapped = receive(module2InputChannel);
|
Message<?> tapped = receive(module2InputChannel);
|
||||||
assertNotNull(tapped);
|
assertThat(tapped).isNotNull();
|
||||||
|
|
||||||
// removed tap does not
|
// removed tap does not
|
||||||
assertNull(receive(module3InputChannel));
|
assertThat(receive(module3InputChannel)).isNull();
|
||||||
|
|
||||||
// re-subscribed tap does receive the message
|
// re-subscribed tap does receive the message
|
||||||
input3Binding = binder.bindConsumer(barTapName, "tap2", module3InputChannel, createConsumerProperties());
|
input3Binding = binder.bindConsumer(barTapName, "tap2", module3InputChannel, createConsumerProperties());
|
||||||
assertNotNull(receive(module3InputChannel));
|
assertThat(receive(module3InputChannel)).isNotNull();
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
input1Binding.unbind();
|
input1Binding.unbind();
|
||||||
input2Binding.unbind();
|
input2Binding.unbind();
|
||||||
input3Binding.unbind();
|
input3Binding.unbind();
|
||||||
producerBinding.unbind();
|
producerBinding.unbind();
|
||||||
assertFalse(extractEndpoint(input1Binding).isRunning());
|
assertThat(extractEndpoint(input1Binding).isRunning()).isFalse();
|
||||||
assertFalse(extractEndpoint(input2Binding).isRunning());
|
assertThat(extractEndpoint(input2Binding).isRunning()).isFalse();
|
||||||
assertFalse(extractEndpoint(input3Binding).isRunning());
|
assertThat(extractEndpoint(input3Binding).isRunning()).isFalse();
|
||||||
assertFalse(extractEndpoint(producerBinding).isRunning());
|
assertThat(extractEndpoint(producerBinding).isRunning()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertMessageReceive(QueueChannel moduleInputChannel, String payload) {
|
|
||||||
Message<?> inbound = receive(moduleInputChannel);
|
|
||||||
assertNotNull(inbound);
|
|
||||||
assertEquals(payload, new String((byte[]) inbound.getPayload()));
|
|
||||||
assertNull(inbound.getHeaders().get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
|||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
import org.springframework.cloud.stream.test.junit.rabbit.RabbitTestSupport;
|
import org.springframework.cloud.stream.test.junit.rabbit.RabbitTestSupport;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,7 +65,7 @@ public class LocalizedQueueConnectionFactoryIntegrationTests {
|
|||||||
ConnectionFactory targetConnectionFactory = this.lqcf.getTargetConnectionFactory("[" + queue.getName() + "]");
|
ConnectionFactory targetConnectionFactory = this.lqcf.getTargetConnectionFactory("[" + queue.getName() + "]");
|
||||||
RabbitTemplate template = new RabbitTemplate(targetConnectionFactory);
|
RabbitTemplate template = new RabbitTemplate(targetConnectionFactory);
|
||||||
template.convertAndSend("", queue.getName(), "foo");
|
template.convertAndSend("", queue.getName(), "foo");
|
||||||
assertEquals("foo", template.receiveAndConvert(queue.getName()));
|
assertThat(template.receiveAndConvert(queue.getName())).isEqualTo("foo");
|
||||||
((CachingConnectionFactory) targetConnectionFactory).destroy();
|
((CachingConnectionFactory) targetConnectionFactory).destroy();
|
||||||
admin.deleteQueue(queue.getName());
|
admin.deleteQueue(queue.getName());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,10 +39,7 @@ import org.springframework.cloud.stream.test.junit.rabbit.RabbitTestSupport;
|
|||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -116,7 +113,7 @@ public class RabbitBinderCleanerTests {
|
|||||||
fail("Expected exception");
|
fail("Expected exception");
|
||||||
}
|
}
|
||||||
catch (RabbitAdminException e) {
|
catch (RabbitAdminException e) {
|
||||||
assertEquals("Queue " + queueName + " is in use", e.getMessage());
|
assertThat(e).hasMessageContaining("Queue " + queueName + " is in use");
|
||||||
}
|
}
|
||||||
channel.basicCancel(consumerTag);
|
channel.basicCancel(consumerTag);
|
||||||
waitForConsumerStateNot(queueName, 1);
|
waitForConsumerStateNot(queueName, 1);
|
||||||
@@ -125,8 +122,8 @@ public class RabbitBinderCleanerTests {
|
|||||||
fail("Expected exception");
|
fail("Expected exception");
|
||||||
}
|
}
|
||||||
catch (RabbitAdminException e) {
|
catch (RabbitAdminException e) {
|
||||||
assertThat(e.getMessage(), containsString("Cannot delete exchange "));
|
assertThat(e).hasMessageContaining("Cannot delete exchange ");
|
||||||
assertThat(e.getMessage(), containsString("; it has bindings:"));
|
assertThat(e).hasMessageContaining("; it has bindings:");
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -144,7 +141,7 @@ public class RabbitBinderCleanerTests {
|
|||||||
}
|
}
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
}
|
}
|
||||||
assertTrue("Consumer state remained at " + state + " after 10 seconds", n < 100);
|
assertThat(n < 100).withFailMessage("Consumer state remained at " + state + " after 10 seconds");
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -153,27 +150,27 @@ public class RabbitBinderCleanerTests {
|
|||||||
rabbitAdmin.deleteQueue(foreignQueue);
|
rabbitAdmin.deleteQueue(foreignQueue);
|
||||||
connectionFactory.destroy();
|
connectionFactory.destroy();
|
||||||
Map<String, List<String>> cleanedMap = cleaner.clean(stream1, false);
|
Map<String, List<String>> cleanedMap = cleaner.clean(stream1, false);
|
||||||
assertEquals(2, cleanedMap.size());
|
assertThat(cleanedMap).hasSize(2);
|
||||||
List<String> cleanedQueues = cleanedMap.get("queues");
|
List<String> cleanedQueues = cleanedMap.get("queues");
|
||||||
// should *not* clean stream2
|
// should *not* clean stream2
|
||||||
assertEquals(10, cleanedQueues.size());
|
assertThat(cleanedQueues).hasSize(10);
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
assertEquals(BINDER_PREFIX + stream1 + ".default." + i, cleanedQueues.get(i * 2));
|
assertThat(cleanedQueues.get(i * 2)).isEqualTo(BINDER_PREFIX + stream1 + ".default." + i);
|
||||||
assertEquals(BINDER_PREFIX + stream1 + ".default." + i + ".dlq", cleanedQueues.get(i * 2 + 1));
|
assertThat(cleanedQueues.get(i * 2 + 1)).isEqualTo(BINDER_PREFIX + stream1 + ".default." + i + ".dlq");
|
||||||
}
|
}
|
||||||
List<String> cleanedExchanges = cleanedMap.get("exchanges");
|
List<String> cleanedExchanges = cleanedMap.get("exchanges");
|
||||||
assertEquals(6, cleanedExchanges.size());
|
assertThat(cleanedExchanges).hasSize(6);
|
||||||
|
|
||||||
// wild card *should* clean stream2
|
// wild card *should* clean stream2
|
||||||
cleanedMap = cleaner.clean(stream1 + "*", false);
|
cleanedMap = cleaner.clean(stream1 + "*", false);
|
||||||
assertEquals(2, cleanedMap.size());
|
assertThat(cleanedMap).hasSize(2);
|
||||||
cleanedQueues = cleanedMap.get("queues");
|
cleanedQueues = cleanedMap.get("queues");
|
||||||
assertEquals(5, cleanedQueues.size());
|
assertThat(cleanedQueues).hasSize(5);
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
assertEquals(BINDER_PREFIX + stream2 + ".default." + i, cleanedQueues.get(i));
|
assertThat(cleanedQueues.get(i)).isEqualTo(BINDER_PREFIX + stream2 + ".default." + i);
|
||||||
}
|
}
|
||||||
cleanedExchanges = cleanedMap.get("exchanges");
|
cleanedExchanges = cleanedMap.get("exchanges");
|
||||||
assertEquals(6, cleanedExchanges.size());
|
assertThat(cleanedExchanges).hasSize(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class AmqpQueue {
|
public static class AmqpQueue {
|
||||||
|
|||||||
@@ -63,15 +63,7 @@ import org.springframework.messaging.MessageHeaders;
|
|||||||
import org.springframework.messaging.MessagingException;
|
import org.springframework.messaging.MessagingException;
|
||||||
import org.springframework.messaging.support.GenericMessage;
|
import org.springframework.messaging.support.GenericMessage;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
|
||||||
import static org.hamcrest.Matchers.startsWith;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -81,7 +73,8 @@ import static org.mockito.Mockito.when;
|
|||||||
* @author Gary Russell
|
* @author Gary Russell
|
||||||
* @author David Turanski
|
* @author David Turanski
|
||||||
*/
|
*/
|
||||||
public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBinder, ExtendedConsumerProperties<RabbitConsumerProperties>, ExtendedProducerProperties<RabbitProducerProperties>> {
|
public class RabbitBinderTests extends
|
||||||
|
PartitionCapableBinderTests<RabbitTestBinder, ExtendedConsumerProperties<RabbitConsumerProperties>, ExtendedProducerProperties<RabbitProducerProperties>> {
|
||||||
|
|
||||||
private final String CLASS_UNDER_TEST_NAME = RabbitMessageChannelBinder.class.getSimpleName();
|
private final String CLASS_UNDER_TEST_NAME = RabbitMessageChannelBinder.class.getSimpleName();
|
||||||
|
|
||||||
@@ -118,10 +111,12 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
RabbitTestBinder binder = getBinder();
|
RabbitTestBinder binder = getBinder();
|
||||||
DirectChannel moduleOutputChannel = new DirectChannel();
|
DirectChannel moduleOutputChannel = new DirectChannel();
|
||||||
DirectChannel moduleInputChannel = new DirectChannel();
|
DirectChannel moduleInputChannel = new DirectChannel();
|
||||||
Binding<MessageChannel> producerBinding = binder.bindProducer("bad.0", moduleOutputChannel, createProducerProperties());
|
Binding<MessageChannel> producerBinding = binder.bindProducer("bad.0", moduleOutputChannel,
|
||||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer("bad.0", "test", moduleInputChannel, createConsumerProperties());
|
createProducerProperties());
|
||||||
Message<?> message = MessageBuilder.withPayload("bad").setHeader(MessageHeaders.CONTENT_TYPE,
|
Binding<MessageChannel> consumerBinding = binder.bindConsumer("bad.0", "test", moduleInputChannel,
|
||||||
"foo/bar").build();
|
createConsumerProperties());
|
||||||
|
Message<?> message = MessageBuilder.withPayload("bad").setHeader(MessageHeaders.CONTENT_TYPE, "foo/bar")
|
||||||
|
.build();
|
||||||
final CountDownLatch latch = new CountDownLatch(3);
|
final CountDownLatch latch = new CountDownLatch(3);
|
||||||
moduleInputChannel.subscribe(new MessageHandler() {
|
moduleInputChannel.subscribe(new MessageHandler() {
|
||||||
|
|
||||||
@@ -132,7 +127,7 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
moduleOutputChannel.send(message);
|
moduleOutputChannel.send(message);
|
||||||
assertTrue(latch.await(10, TimeUnit.SECONDS));
|
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||||
producerBinding.unbind();
|
producerBinding.unbind();
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
}
|
}
|
||||||
@@ -146,22 +141,21 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
AbstractEndpoint endpoint = extractEndpoint(consumerBinding);
|
AbstractEndpoint endpoint = extractEndpoint(consumerBinding);
|
||||||
SimpleMessageListenerContainer container = TestUtils.getPropertyValue(endpoint, "messageListenerContainer",
|
SimpleMessageListenerContainer container = TestUtils.getPropertyValue(endpoint, "messageListenerContainer",
|
||||||
SimpleMessageListenerContainer.class);
|
SimpleMessageListenerContainer.class);
|
||||||
assertEquals(AcknowledgeMode.AUTO, container.getAcknowledgeMode());
|
assertThat(container.getAcknowledgeMode()).isEqualTo(AcknowledgeMode.AUTO);
|
||||||
assertThat(container.getQueueNames()[0],
|
assertThat(container.getQueueNames()[0]).startsWith(properties.getExtension().getPrefix());
|
||||||
startsWith(properties.getExtension().getPrefix()));
|
assertThat(TestUtils.getPropertyValue(container, "transactional", Boolean.class)).isTrue();
|
||||||
assertTrue(TestUtils.getPropertyValue(container, "transactional", Boolean.class));
|
assertThat(TestUtils.getPropertyValue(container, "concurrentConsumers")).isEqualTo(1);
|
||||||
assertEquals(1, TestUtils.getPropertyValue(container, "concurrentConsumers"));
|
assertThat(TestUtils.getPropertyValue(container, "maxConcurrentConsumers")).isNull();
|
||||||
assertNull(TestUtils.getPropertyValue(container, "maxConcurrentConsumers"));
|
assertThat(TestUtils.getPropertyValue(container, "defaultRequeueRejected", Boolean.class)).isTrue();
|
||||||
assertTrue(TestUtils.getPropertyValue(container, "defaultRequeueRejected", Boolean.class));
|
assertThat(TestUtils.getPropertyValue(container, "prefetchCount")).isEqualTo(1);
|
||||||
assertEquals(1, TestUtils.getPropertyValue(container, "prefetchCount"));
|
assertThat(TestUtils.getPropertyValue(container, "txSize")).isEqualTo(1);
|
||||||
assertEquals(1, TestUtils.getPropertyValue(container, "txSize"));
|
|
||||||
Advice retry = TestUtils.getPropertyValue(container, "adviceChain", Advice[].class)[0];
|
Advice retry = TestUtils.getPropertyValue(container, "adviceChain", Advice[].class)[0];
|
||||||
assertEquals(3, TestUtils.getPropertyValue(retry, "retryOperations.retryPolicy.maxAttempts"));
|
assertThat(TestUtils.getPropertyValue(retry, "retryOperations.retryPolicy.maxAttempts")).isEqualTo(3);
|
||||||
assertEquals(1000L, TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.initialInterval"));
|
assertThat(TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.initialInterval")).isEqualTo(1000L);
|
||||||
assertEquals(10000L, TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.maxInterval"));
|
assertThat(TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.maxInterval")).isEqualTo(10000L);
|
||||||
assertEquals(2.0, TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.multiplier"));
|
assertThat(TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.multiplier")).isEqualTo(2.0);
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
assertFalse(endpoint.isRunning());
|
assertThat(endpoint.isRunning()).isFalse();
|
||||||
|
|
||||||
properties = createConsumerProperties();
|
properties = createConsumerProperties();
|
||||||
properties.getExtension().setAcknowledgeMode(AcknowledgeMode.NONE);
|
properties.getExtension().setAcknowledgeMode(AcknowledgeMode.NONE);
|
||||||
@@ -173,7 +167,7 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
properties.getExtension().setMaxConcurrency(3);
|
properties.getExtension().setMaxConcurrency(3);
|
||||||
properties.getExtension().setPrefix("foo.");
|
properties.getExtension().setPrefix("foo.");
|
||||||
properties.getExtension().setPrefetch(20);
|
properties.getExtension().setPrefetch(20);
|
||||||
properties.getExtension().setRequestHeaderPatterns(new String[] {"foo"});
|
properties.getExtension().setRequestHeaderPatterns(new String[] { "foo" });
|
||||||
properties.getExtension().setRequeueRejected(false);
|
properties.getExtension().setRequeueRejected(false);
|
||||||
properties.getExtension().setTxSize(10);
|
properties.getExtension().setTxSize(10);
|
||||||
properties.setInstanceIndex(0);
|
properties.setInstanceIndex(0);
|
||||||
@@ -182,32 +176,34 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
endpoint = extractEndpoint(consumerBinding);
|
endpoint = extractEndpoint(consumerBinding);
|
||||||
container = verifyContainer(endpoint);
|
container = verifyContainer(endpoint);
|
||||||
|
|
||||||
assertEquals("foo.props.0.test", container.getQueueNames()[0]);
|
assertThat(container.getQueueNames()[0]).isEqualTo("foo.props.0.test");
|
||||||
|
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
assertFalse(endpoint.isRunning());
|
assertThat(endpoint.isRunning()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProducerProperties() throws Exception {
|
public void testProducerProperties() throws Exception {
|
||||||
RabbitTestBinder binder = getBinder();
|
RabbitTestBinder binder = getBinder();
|
||||||
Binding<MessageChannel> producerBinding = binder.bindProducer("props.0", new DirectChannel(), createProducerProperties());
|
Binding<MessageChannel> producerBinding = binder.bindProducer("props.0", new DirectChannel(),
|
||||||
|
createProducerProperties());
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
AbstractEndpoint endpoint = extractEndpoint(producerBinding);
|
AbstractEndpoint endpoint = extractEndpoint(producerBinding);
|
||||||
MessageDeliveryMode mode = TestUtils.getPropertyValue(endpoint, "handler.delegate.defaultDeliveryMode",
|
MessageDeliveryMode mode = TestUtils.getPropertyValue(endpoint, "handler.delegate.defaultDeliveryMode",
|
||||||
MessageDeliveryMode.class);
|
MessageDeliveryMode.class);
|
||||||
assertEquals(MessageDeliveryMode.PERSISTENT, mode);
|
assertThat(mode).isEqualTo(MessageDeliveryMode.PERSISTENT);
|
||||||
List<?> requestHeaders = TestUtils.getPropertyValue(endpoint,
|
List<?> requestHeaders = TestUtils.getPropertyValue(endpoint,
|
||||||
"handler.delegate.headerMapper.requestHeaderMatcher.matchers", List.class);
|
"handler.delegate.headerMapper.requestHeaderMatcher.matchers", List.class);
|
||||||
assertEquals(2, requestHeaders.size());
|
assertThat(requestHeaders).hasSize(2);
|
||||||
producerBinding.unbind();
|
producerBinding.unbind();
|
||||||
assertFalse(endpoint.isRunning());
|
assertThat(endpoint.isRunning()).isFalse();
|
||||||
assertFalse(TestUtils.getPropertyValue(endpoint, "handler.delegate.amqpTemplate.transactional", Boolean.class));
|
assertThat(TestUtils.getPropertyValue(endpoint, "handler.delegate.amqpTemplate.transactional", Boolean.class))
|
||||||
|
.isFalse();
|
||||||
|
|
||||||
ExtendedProducerProperties<RabbitProducerProperties> properties = createProducerProperties();
|
ExtendedProducerProperties<RabbitProducerProperties> properties = createProducerProperties();
|
||||||
properties.getExtension().setPrefix("foo.");
|
properties.getExtension().setPrefix("foo.");
|
||||||
properties.getExtension().setDeliveryMode(MessageDeliveryMode.NON_PERSISTENT);
|
properties.getExtension().setDeliveryMode(MessageDeliveryMode.NON_PERSISTENT);
|
||||||
properties.getExtension().setRequestHeaderPatterns(new String[] {"foo"});
|
properties.getExtension().setRequestHeaderPatterns(new String[] { "foo" });
|
||||||
properties.setPartitionKeyExpression(spelExpressionParser.parseExpression("'foo'"));
|
properties.setPartitionKeyExpression(spelExpressionParser.parseExpression("'foo'"));
|
||||||
properties.setPartitionKeyExtractorClass(TestPartitionKeyExtractorClass.class);
|
properties.setPartitionKeyExtractorClass(TestPartitionKeyExtractorClass.class);
|
||||||
properties.setPartitionSelectorExpression(spelExpressionParser.parseExpression("0"));
|
properties.setPartitionSelectorExpression(spelExpressionParser.parseExpression("0"));
|
||||||
@@ -217,18 +213,16 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
|
|
||||||
producerBinding = binder.bindProducer("props.0", new DirectChannel(), properties);
|
producerBinding = binder.bindProducer("props.0", new DirectChannel(), properties);
|
||||||
endpoint = extractEndpoint(producerBinding);
|
endpoint = extractEndpoint(producerBinding);
|
||||||
assertEquals(
|
assertThat(TestUtils.getPropertyValue(endpoint, "handler.delegate.routingKeyExpression", SpelExpression.class)
|
||||||
"'props.0-' + headers['partition']",
|
.getExpressionString()).isEqualTo("'props.0-' + headers['partition']");
|
||||||
TestUtils.getPropertyValue(endpoint, "handler.delegate.routingKeyExpression",
|
mode = TestUtils.getPropertyValue(endpoint, "handler.delegate.defaultDeliveryMode", MessageDeliveryMode.class);
|
||||||
SpelExpression.class).getExpressionString());
|
assertThat(mode).isEqualTo(MessageDeliveryMode.NON_PERSISTENT);
|
||||||
mode = TestUtils.getPropertyValue(endpoint, "handler.delegate.defaultDeliveryMode",
|
assertThat(TestUtils.getPropertyValue(endpoint, "handler.delegate.amqpTemplate.transactional", Boolean.class))
|
||||||
MessageDeliveryMode.class);
|
.isTrue();
|
||||||
assertEquals(MessageDeliveryMode.NON_PERSISTENT, mode);
|
|
||||||
assertTrue(TestUtils.getPropertyValue(endpoint, "handler.delegate.amqpTemplate.transactional", Boolean.class));
|
|
||||||
verifyFooRequestProducer(endpoint);
|
verifyFooRequestProducer(endpoint);
|
||||||
|
|
||||||
producerBinding.unbind();
|
producerBinding.unbind();
|
||||||
assertFalse(endpoint.isRunning());
|
assertThat(endpoint.isRunning()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -253,7 +247,8 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer("durabletest.0", "tgroup", moduleInputChannel, properties);
|
Binding<MessageChannel> consumerBinding = binder.bindConsumer("durabletest.0", "tgroup", moduleInputChannel,
|
||||||
|
properties);
|
||||||
|
|
||||||
RabbitTemplate template = new RabbitTemplate(this.rabbitAvailableRule.getResource());
|
RabbitTemplate template = new RabbitTemplate(this.rabbitAvailableRule.getResource());
|
||||||
template.convertAndSend(TEST_PREFIX + "durabletest.0", "", "foo");
|
template.convertAndSend(TEST_PREFIX + "durabletest.0", "", "foo");
|
||||||
@@ -262,15 +257,15 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
while (n++ < 100) {
|
while (n++ < 100) {
|
||||||
Object deadLetter = template.receiveAndConvert(TEST_PREFIX + "durabletest.0.tgroup.dlq");
|
Object deadLetter = template.receiveAndConvert(TEST_PREFIX + "durabletest.0.tgroup.dlq");
|
||||||
if (deadLetter != null) {
|
if (deadLetter != null) {
|
||||||
assertEquals("foo", deadLetter);
|
assertThat(deadLetter).isEqualTo("foo");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
}
|
}
|
||||||
assertTrue(n < 100);
|
assertThat(n).isLessThan(100);
|
||||||
|
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
assertNotNull(admin.getQueueProperties(TEST_PREFIX + "durabletest.0.tgroup.dlq"));
|
assertThat(admin.getQueueProperties(TEST_PREFIX + "durabletest.0.tgroup.dlq")).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -294,10 +289,11 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer("nondurabletest.0", "tgroup", moduleInputChannel, properties);
|
Binding<MessageChannel> consumerBinding = binder.bindConsumer("nondurabletest.0", "tgroup", moduleInputChannel,
|
||||||
|
properties);
|
||||||
|
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
assertNull(admin.getQueueProperties(TEST_PREFIX + "nondurabletest.0.dlq"));
|
assertThat(admin.getQueueProperties(TEST_PREFIX + "nondurabletest.0.dlq")).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -319,7 +315,8 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer("dlqtest", "default", moduleInputChannel, properties);
|
Binding<MessageChannel> consumerBinding = binder.bindConsumer("dlqtest", "default", moduleInputChannel,
|
||||||
|
properties);
|
||||||
|
|
||||||
RabbitTemplate template = new RabbitTemplate(this.rabbitAvailableRule.getResource());
|
RabbitTemplate template = new RabbitTemplate(this.rabbitAvailableRule.getResource());
|
||||||
template.convertAndSend("", TEST_PREFIX + "dlqtest.default", "foo");
|
template.convertAndSend("", TEST_PREFIX + "dlqtest.default", "foo");
|
||||||
@@ -328,21 +325,21 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
while (n++ < 100) {
|
while (n++ < 100) {
|
||||||
Object deadLetter = template.receiveAndConvert(TEST_PREFIX + "dlqtest.default.dlq");
|
Object deadLetter = template.receiveAndConvert(TEST_PREFIX + "dlqtest.default.dlq");
|
||||||
if (deadLetter != null) {
|
if (deadLetter != null) {
|
||||||
assertEquals("foo", deadLetter);
|
assertThat(deadLetter).isEqualTo("foo");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
}
|
}
|
||||||
assertTrue(n < 100);
|
assertThat(n).isLessThan(100);
|
||||||
|
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
|
|
||||||
ApplicationContext context = TestUtils.getPropertyValue(binder, "binder.autoDeclareContext",
|
ApplicationContext context = TestUtils.getPropertyValue(binder, "binder.autoDeclareContext",
|
||||||
ApplicationContext.class);
|
ApplicationContext.class);
|
||||||
assertFalse(context.containsBean(TEST_PREFIX + "dlqtest.default.binding"));
|
assertThat(context.containsBean(TEST_PREFIX + "dlqtest.default.binding")).isFalse();
|
||||||
assertFalse(context.containsBean(TEST_PREFIX + "dlqtest.default"));
|
assertThat(context.containsBean(TEST_PREFIX + "dlqtest.default")).isFalse();
|
||||||
assertFalse(context.containsBean(TEST_PREFIX + "dlqtest.default.dlq.binding"));
|
assertThat(context.containsBean(TEST_PREFIX + "dlqtest.default.dlq.binding")).isFalse();
|
||||||
assertFalse(context.containsBean(TEST_PREFIX + "dlqtest.default.dlq"));
|
assertThat(context.containsBean(TEST_PREFIX + "dlqtest.default.dlq")).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -358,13 +355,14 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
DirectChannel input0 = new DirectChannel();
|
DirectChannel input0 = new DirectChannel();
|
||||||
input0.setBeanName("test.input0DLQ");
|
input0.setBeanName("test.input0DLQ");
|
||||||
Binding<MessageChannel> input0Binding = binder.bindConsumer("partDLQ.0", "dlqPartGrp", input0, properties);
|
Binding<MessageChannel> input0Binding = binder.bindConsumer("partDLQ.0", "dlqPartGrp", input0, properties);
|
||||||
Binding<MessageChannel> defaultConsumerBinding1 =
|
Binding<MessageChannel> defaultConsumerBinding1 = binder.bindConsumer("partDLQ.0", "default",
|
||||||
binder.bindConsumer("partDLQ.0", "default", new QueueChannel(), properties);
|
new QueueChannel(), properties);
|
||||||
properties.setInstanceIndex(1);
|
properties.setInstanceIndex(1);
|
||||||
DirectChannel input1 = new DirectChannel();
|
DirectChannel input1 = new DirectChannel();
|
||||||
input1.setBeanName("test.input1DLQ");
|
input1.setBeanName("test.input1DLQ");
|
||||||
Binding<MessageChannel> input1Binding = binder.bindConsumer("partDLQ.0", "dlqPartGrp", input1, properties);
|
Binding<MessageChannel> input1Binding = binder.bindConsumer("partDLQ.0", "dlqPartGrp", input1, properties);
|
||||||
Binding<MessageChannel> defaultConsumerBinding2 = binder.bindConsumer("partDLQ.0", "default", new QueueChannel(), properties);
|
Binding<MessageChannel> defaultConsumerBinding2 = binder.bindConsumer("partDLQ.0", "default",
|
||||||
|
new QueueChannel(), properties);
|
||||||
|
|
||||||
ExtendedProducerProperties<RabbitProducerProperties> producerProperties = createProducerProperties();
|
ExtendedProducerProperties<RabbitProducerProperties> producerProperties = createProducerProperties();
|
||||||
producerProperties.getExtension().setPrefix("bindertest.");
|
producerProperties.getExtension().setPrefix("bindertest.");
|
||||||
@@ -402,13 +400,13 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
output.send(new GenericMessage<Integer>(1));
|
output.send(new GenericMessage<>(1));
|
||||||
assertTrue(latch1.await(10, TimeUnit.SECONDS));
|
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
|
||||||
|
|
||||||
output.send(new GenericMessage<Integer>(0));
|
output.send(new GenericMessage<>(0));
|
||||||
assertTrue(latch0.await(10, TimeUnit.SECONDS));
|
assertThat(latch0.await(10, TimeUnit.SECONDS)).isTrue();
|
||||||
|
|
||||||
output.send(new GenericMessage<Integer>(1));
|
output.send(new GenericMessage<>(1));
|
||||||
|
|
||||||
RabbitTemplate template = new RabbitTemplate(this.rabbitAvailableRule.getResource());
|
RabbitTemplate template = new RabbitTemplate(this.rabbitAvailableRule.getResource());
|
||||||
template.setReceiveTimeout(10000);
|
template.setReceiveTimeout(10000);
|
||||||
@@ -416,13 +414,13 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
String streamDLQName = "bindertest.partDLQ.0.dlqPartGrp.dlq";
|
String streamDLQName = "bindertest.partDLQ.0.dlqPartGrp.dlq";
|
||||||
|
|
||||||
org.springframework.amqp.core.Message received = template.receive(streamDLQName);
|
org.springframework.amqp.core.Message received = template.receive(streamDLQName);
|
||||||
assertNotNull(received);
|
assertThat(received).isNotNull();
|
||||||
assertEquals(1, received.getMessageProperties().getHeaders().get("partition"));
|
assertThat(received.getMessageProperties().getHeaders()).containsEntry("partition", 1);
|
||||||
|
|
||||||
output.send(new GenericMessage<Integer>(0));
|
output.send(new GenericMessage<>(0));
|
||||||
received = template.receive(streamDLQName);
|
received = template.receive(streamDLQName);
|
||||||
assertNotNull(received);
|
assertThat(received).isNotNull();
|
||||||
assertEquals(0, received.getMessageProperties().getHeaders().get("partition"));
|
assertThat(received.getMessageProperties().getHeaders()).containsEntry("partition", 0);
|
||||||
|
|
||||||
input0Binding.unbind();
|
input0Binding.unbind();
|
||||||
input1Binding.unbind();
|
input1Binding.unbind();
|
||||||
@@ -455,13 +453,17 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
consumerProperties.setInstanceIndex(0);
|
consumerProperties.setInstanceIndex(0);
|
||||||
DirectChannel input0 = new DirectChannel();
|
DirectChannel input0 = new DirectChannel();
|
||||||
input0.setBeanName("test.input0DLQ");
|
input0.setBeanName("test.input0DLQ");
|
||||||
Binding<MessageChannel> input0Binding = binder.bindConsumer("partDLQ.1", "dlqPartGrp", input0, consumerProperties);
|
Binding<MessageChannel> input0Binding = binder.bindConsumer("partDLQ.1", "dlqPartGrp", input0,
|
||||||
Binding<MessageChannel> defaultConsumerBinding1 = binder.bindConsumer("partDLQ.1", "defaultConsumer", new QueueChannel(), consumerProperties);
|
consumerProperties);
|
||||||
|
Binding<MessageChannel> defaultConsumerBinding1 = binder.bindConsumer("partDLQ.1", "defaultConsumer",
|
||||||
|
new QueueChannel(), consumerProperties);
|
||||||
consumerProperties.setInstanceIndex(1);
|
consumerProperties.setInstanceIndex(1);
|
||||||
DirectChannel input1 = new DirectChannel();
|
DirectChannel input1 = new DirectChannel();
|
||||||
input1.setBeanName("test.input1DLQ");
|
input1.setBeanName("test.input1DLQ");
|
||||||
Binding<MessageChannel> input1Binding = binder.bindConsumer("partDLQ.1", "dlqPartGrp", input1, consumerProperties);
|
Binding<MessageChannel> input1Binding = binder.bindConsumer("partDLQ.1", "dlqPartGrp", input1,
|
||||||
Binding<MessageChannel> defaultConsumerBinding2 = binder.bindConsumer("partDLQ.1", "defaultConsumer", new QueueChannel(), consumerProperties);
|
consumerProperties);
|
||||||
|
Binding<MessageChannel> defaultConsumerBinding2 = binder.bindConsumer("partDLQ.1", "defaultConsumer",
|
||||||
|
new QueueChannel(), consumerProperties);
|
||||||
|
|
||||||
final CountDownLatch latch0 = new CountDownLatch(1);
|
final CountDownLatch latch0 = new CountDownLatch(1);
|
||||||
input0.subscribe(new MessageHandler() {
|
input0.subscribe(new MessageHandler() {
|
||||||
@@ -490,10 +492,10 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
});
|
});
|
||||||
|
|
||||||
output.send(new GenericMessage<Integer>(1));
|
output.send(new GenericMessage<Integer>(1));
|
||||||
assertTrue(latch1.await(10, TimeUnit.SECONDS));
|
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
|
||||||
|
|
||||||
output.send(new GenericMessage<Integer>(0));
|
output.send(new GenericMessage<Integer>(0));
|
||||||
assertTrue(latch0.await(10, TimeUnit.SECONDS));
|
assertThat(latch0.await(10, TimeUnit.SECONDS)).isTrue();
|
||||||
|
|
||||||
output.send(new GenericMessage<Integer>(1));
|
output.send(new GenericMessage<Integer>(1));
|
||||||
|
|
||||||
@@ -503,13 +505,13 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
String streamDLQName = "bindertest.partDLQ.1.dlqPartGrp.dlq";
|
String streamDLQName = "bindertest.partDLQ.1.dlqPartGrp.dlq";
|
||||||
|
|
||||||
org.springframework.amqp.core.Message received = template.receive(streamDLQName);
|
org.springframework.amqp.core.Message received = template.receive(streamDLQName);
|
||||||
assertNotNull(received);
|
assertThat(received).isNotNull();
|
||||||
assertEquals(1, received.getMessageProperties().getHeaders().get("partition"));
|
assertThat(received.getMessageProperties().getHeaders()).containsEntry("partition", 1);
|
||||||
|
|
||||||
output.send(new GenericMessage<Integer>(0));
|
output.send(new GenericMessage<Integer>(0));
|
||||||
received = template.receive(streamDLQName);
|
received = template.receive(streamDLQName);
|
||||||
assertNotNull(received);
|
assertThat(received).isNotNull();
|
||||||
assertEquals(0, received.getMessageProperties().getHeaders().get("partition"));
|
assertThat(received.getMessageProperties().getHeaders()).containsEntry("partition", 0);
|
||||||
|
|
||||||
input0Binding.unbind();
|
input0Binding.unbind();
|
||||||
input1Binding.unbind();
|
input1Binding.unbind();
|
||||||
@@ -546,7 +548,8 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer("dlqpubtest", "default", moduleInputChannel, properties);
|
Binding<MessageChannel> consumerBinding = binder.bindConsumer("dlqpubtest", "default", moduleInputChannel,
|
||||||
|
properties);
|
||||||
|
|
||||||
RabbitTemplate template = new RabbitTemplate(this.rabbitAvailableRule.getResource());
|
RabbitTemplate template = new RabbitTemplate(this.rabbitAvailableRule.getResource());
|
||||||
template.convertAndSend("", TEST_PREFIX + "dlqpubtest.default", "foo");
|
template.convertAndSend("", TEST_PREFIX + "dlqpubtest.default", "foo");
|
||||||
@@ -555,13 +558,13 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
while (n++ < 100) {
|
while (n++ < 100) {
|
||||||
org.springframework.amqp.core.Message deadLetter = template.receive(TEST_PREFIX + "dlqpubtest.default.dlq");
|
org.springframework.amqp.core.Message deadLetter = template.receive(TEST_PREFIX + "dlqpubtest.default.dlq");
|
||||||
if (deadLetter != null) {
|
if (deadLetter != null) {
|
||||||
assertEquals("foo", new String(deadLetter.getBody()));
|
assertThat(new String(deadLetter.getBody())).isEqualTo("foo");
|
||||||
assertNotNull(deadLetter.getMessageProperties().getHeaders().get("x-exception-stacktrace"));
|
assertThat(deadLetter.getMessageProperties().getHeaders()).containsKey(("x-exception-stacktrace"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
}
|
}
|
||||||
assertTrue(n < 100);
|
assertThat(n).isLessThan(100);
|
||||||
|
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
}
|
}
|
||||||
@@ -589,41 +592,43 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
.setPropertyValue("logger", logger);
|
.setPropertyValue("logger", logger);
|
||||||
when(logger.isTraceEnabled()).thenReturn(true);
|
when(logger.isTraceEnabled()).thenReturn(true);
|
||||||
|
|
||||||
assertEquals(Deflater.BEST_SPEED, TestUtils.getPropertyValue(binder, "binder.compressingPostProcessor.level"));
|
assertThat(TestUtils.getPropertyValue(binder, "binder.compressingPostProcessor.level"))
|
||||||
|
.isEqualTo(Deflater.BEST_SPEED);
|
||||||
|
|
||||||
output.send(new GenericMessage<>("foo".getBytes()));
|
output.send(new GenericMessage<>("foo".getBytes()));
|
||||||
output.send(new GenericMessage<>("bar".getBytes()));
|
output.send(new GenericMessage<>("bar".getBytes()));
|
||||||
|
|
||||||
Object out = spyOn("batching.0.default").receive(false);
|
Object out = spyOn("batching.0.default").receive(false);
|
||||||
assertThat(out, instanceOf(byte[].class));
|
assertThat(out).isInstanceOf(byte[].class);
|
||||||
assertEquals("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar", new String((byte[]) out));
|
assertThat(new String((byte[]) out)).isEqualTo("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar");
|
||||||
|
|
||||||
ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class);
|
ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class);
|
||||||
verify(logger).trace(captor.capture());
|
verify(logger).trace(captor.capture());
|
||||||
assertThat(captor.getValue().toString(), containsString("Compressed 14 to "));
|
assertThat(captor.getValue().toString()).contains(("Compressed 14 to "));
|
||||||
|
|
||||||
QueueChannel input = new QueueChannel();
|
QueueChannel input = new QueueChannel();
|
||||||
input.setBeanName("batchingConsumer");
|
input.setBeanName("batchingConsumer");
|
||||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer("batching.0", "test", input, createConsumerProperties());
|
Binding<MessageChannel> consumerBinding = binder.bindConsumer("batching.0", "test", input,
|
||||||
|
createConsumerProperties());
|
||||||
|
|
||||||
output.send(new GenericMessage<>("foo".getBytes()));
|
output.send(new GenericMessage<>("foo".getBytes()));
|
||||||
output.send(new GenericMessage<>("bar".getBytes()));
|
output.send(new GenericMessage<>("bar".getBytes()));
|
||||||
|
|
||||||
Message<byte[]> in = (Message<byte[]>) input.receive(10000);
|
Message<byte[]> in = (Message<byte[]>) input.receive(10000);
|
||||||
assertNotNull(in);
|
assertThat(in).isNotNull();
|
||||||
assertEquals("foo", new String(in.getPayload()));
|
assertThat(new String(in.getPayload())).isEqualTo("foo");
|
||||||
in = (Message<byte[]>) input.receive(10000);
|
in = (Message<byte[]>) input.receive(10000);
|
||||||
assertNotNull(in);
|
assertThat(in).isNotNull();
|
||||||
assertEquals("bar", new String(in.getPayload()));
|
assertThat(new String(in.getPayload())).isEqualTo("bar");
|
||||||
assertNull(in.getHeaders().get(AmqpHeaders.DELIVERY_MODE));
|
assertThat(in.getHeaders().get(AmqpHeaders.DELIVERY_MODE)).isNull();
|
||||||
|
|
||||||
producerBinding.unbind();
|
producerBinding.unbind();
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test late binding due to broker down; queues with and without DLQs, and
|
* Test late binding due to broker down; queues with and without DLQs, and partitioned
|
||||||
* partitioned queues.
|
* queues.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testLateBinding() throws Exception {
|
public void testLateBinding() throws Exception {
|
||||||
@@ -642,14 +647,16 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
QueueChannel moduleInputChannel = new QueueChannel();
|
QueueChannel moduleInputChannel = new QueueChannel();
|
||||||
ExtendedConsumerProperties<RabbitConsumerProperties> rabbitConsumerProperties = createConsumerProperties();
|
ExtendedConsumerProperties<RabbitConsumerProperties> rabbitConsumerProperties = createConsumerProperties();
|
||||||
rabbitConsumerProperties.getExtension().setPrefix("latebinder.");
|
rabbitConsumerProperties.getExtension().setPrefix("latebinder.");
|
||||||
Binding<MessageChannel> late0ConsumerBinding = binder.bindConsumer("late.0", "test", moduleInputChannel, rabbitConsumerProperties);
|
Binding<MessageChannel> late0ConsumerBinding = binder.bindConsumer("late.0", "test", moduleInputChannel,
|
||||||
|
rabbitConsumerProperties);
|
||||||
|
|
||||||
properties.setPartitionKeyExpression(spelExpressionParser.parseExpression("payload.equals('0') ? 0 : 1"));
|
properties.setPartitionKeyExpression(spelExpressionParser.parseExpression("payload.equals('0') ? 0 : 1"));
|
||||||
properties.setPartitionSelectorExpression(spelExpressionParser.parseExpression("hashCode()"));
|
properties.setPartitionSelectorExpression(spelExpressionParser.parseExpression("hashCode()"));
|
||||||
properties.setPartitionCount(2);
|
properties.setPartitionCount(2);
|
||||||
|
|
||||||
MessageChannel partOutputChannel = new DirectChannel();
|
MessageChannel partOutputChannel = new DirectChannel();
|
||||||
Binding<MessageChannel> partlate0ProducerBinding = binder.bindProducer("partlate.0", partOutputChannel, properties);
|
Binding<MessageChannel> partlate0ProducerBinding = binder.bindProducer("partlate.0", partOutputChannel,
|
||||||
|
properties);
|
||||||
|
|
||||||
QueueChannel partInputChannel0 = new QueueChannel();
|
QueueChannel partInputChannel0 = new QueueChannel();
|
||||||
QueueChannel partInputChannel1 = new QueueChannel();
|
QueueChannel partInputChannel1 = new QueueChannel();
|
||||||
@@ -658,57 +665,64 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
partLateConsumerProperties.getExtension().setPrefix("latebinder.");
|
partLateConsumerProperties.getExtension().setPrefix("latebinder.");
|
||||||
partLateConsumerProperties.setPartitioned(true);
|
partLateConsumerProperties.setPartitioned(true);
|
||||||
partLateConsumerProperties.setInstanceIndex(0);
|
partLateConsumerProperties.setInstanceIndex(0);
|
||||||
Binding<MessageChannel> partlate0Consumer0Binding = binder.bindConsumer("partlate.0", "test", partInputChannel0, partLateConsumerProperties);
|
Binding<MessageChannel> partlate0Consumer0Binding = binder.bindConsumer("partlate.0", "test", partInputChannel0,
|
||||||
|
partLateConsumerProperties);
|
||||||
partLateConsumerProperties.setInstanceIndex(1);
|
partLateConsumerProperties.setInstanceIndex(1);
|
||||||
Binding<MessageChannel> partlate0Consumer1Binding = binder.bindConsumer("partlate.0", "test", partInputChannel1, partLateConsumerProperties);
|
Binding<MessageChannel> partlate0Consumer1Binding = binder.bindConsumer("partlate.0", "test", partInputChannel1,
|
||||||
|
partLateConsumerProperties);
|
||||||
|
|
||||||
ExtendedProducerProperties<RabbitProducerProperties> noDlqProducerProperties = createProducerProperties();
|
ExtendedProducerProperties<RabbitProducerProperties> noDlqProducerProperties = createProducerProperties();
|
||||||
noDlqProducerProperties.getExtension().setPrefix("latebinder.");
|
noDlqProducerProperties.getExtension().setPrefix("latebinder.");
|
||||||
MessageChannel noDLQOutputChannel = new DirectChannel();
|
MessageChannel noDLQOutputChannel = new DirectChannel();
|
||||||
Binding<MessageChannel> noDlqProducerBinding = binder.bindProducer("lateNoDLQ.0", noDLQOutputChannel, noDlqProducerProperties);
|
Binding<MessageChannel> noDlqProducerBinding = binder.bindProducer("lateNoDLQ.0", noDLQOutputChannel,
|
||||||
|
noDlqProducerProperties);
|
||||||
|
|
||||||
QueueChannel noDLQInputChannel = new QueueChannel();
|
QueueChannel noDLQInputChannel = new QueueChannel();
|
||||||
ExtendedConsumerProperties<RabbitConsumerProperties> noDlqConsumerProperties = createConsumerProperties();
|
ExtendedConsumerProperties<RabbitConsumerProperties> noDlqConsumerProperties = createConsumerProperties();
|
||||||
noDlqConsumerProperties.getExtension().setPrefix("latebinder.");
|
noDlqConsumerProperties.getExtension().setPrefix("latebinder.");
|
||||||
Binding<MessageChannel> noDlqConsumerBinding = binder.bindConsumer("lateNoDLQ.0", "test", noDLQInputChannel, noDlqConsumerProperties);
|
Binding<MessageChannel> noDlqConsumerBinding = binder.bindConsumer("lateNoDLQ.0", "test", noDLQInputChannel,
|
||||||
|
noDlqConsumerProperties);
|
||||||
|
|
||||||
MessageChannel outputChannel = new DirectChannel();
|
MessageChannel outputChannel = new DirectChannel();
|
||||||
Binding<MessageChannel> pubSubProducerBinding = binder.bindProducer("latePubSub", outputChannel, noDlqProducerProperties);
|
Binding<MessageChannel> pubSubProducerBinding = binder.bindProducer("latePubSub", outputChannel,
|
||||||
|
noDlqProducerProperties);
|
||||||
QueueChannel pubSubInputChannel = new QueueChannel();
|
QueueChannel pubSubInputChannel = new QueueChannel();
|
||||||
noDlqConsumerProperties.getExtension().setDurableSubscription(false);
|
noDlqConsumerProperties.getExtension().setDurableSubscription(false);
|
||||||
Binding<MessageChannel> nonDurableConsumerBinding = binder.bindConsumer("latePubSub", "lategroup", pubSubInputChannel, noDlqConsumerProperties);
|
Binding<MessageChannel> nonDurableConsumerBinding = binder.bindConsumer("latePubSub", "lategroup",
|
||||||
|
pubSubInputChannel, noDlqConsumerProperties);
|
||||||
QueueChannel durablePubSubInputChannel = new QueueChannel();
|
QueueChannel durablePubSubInputChannel = new QueueChannel();
|
||||||
noDlqConsumerProperties.getExtension().setDurableSubscription(true);
|
noDlqConsumerProperties.getExtension().setDurableSubscription(true);
|
||||||
Binding<MessageChannel> durableConsumerBinding = binder.bindConsumer("latePubSub", "lateDurableGroup", durablePubSubInputChannel, noDlqConsumerProperties);
|
Binding<MessageChannel> durableConsumerBinding = binder.bindConsumer("latePubSub", "lateDurableGroup",
|
||||||
|
durablePubSubInputChannel, noDlqConsumerProperties);
|
||||||
|
|
||||||
proxy.start();
|
proxy.start();
|
||||||
|
|
||||||
moduleOutputChannel.send(new GenericMessage<>("foo"));
|
moduleOutputChannel.send(new GenericMessage<>("foo"));
|
||||||
Message<?> message = moduleInputChannel.receive(10000);
|
Message<?> message = moduleInputChannel.receive(10000);
|
||||||
assertNotNull(message);
|
assertThat(message).isNotNull();
|
||||||
assertEquals("foo", message.getPayload());
|
assertThat(message.getPayload()).isNotNull();
|
||||||
|
|
||||||
noDLQOutputChannel.send(new GenericMessage<>("bar"));
|
noDLQOutputChannel.send(new GenericMessage<>("bar"));
|
||||||
message = noDLQInputChannel.receive(10000);
|
message = noDLQInputChannel.receive(10000);
|
||||||
assertNotNull(message);
|
assertThat(message);
|
||||||
assertEquals("bar", message.getPayload());
|
assertThat(message.getPayload()).isEqualTo("bar");
|
||||||
|
|
||||||
outputChannel.send(new GenericMessage<>("baz"));
|
outputChannel.send(new GenericMessage<>("baz"));
|
||||||
message = pubSubInputChannel.receive(10000);
|
message = pubSubInputChannel.receive(10000);
|
||||||
assertNotNull(message);
|
assertThat(message);
|
||||||
assertEquals("baz", message.getPayload());
|
assertThat(message.getPayload()).isEqualTo("baz");
|
||||||
message = durablePubSubInputChannel.receive(10000);
|
message = durablePubSubInputChannel.receive(10000);
|
||||||
assertNotNull(message);
|
assertThat(message).isNotNull();
|
||||||
assertEquals("baz", message.getPayload());
|
assertThat(message.getPayload()).isEqualTo("baz");
|
||||||
|
|
||||||
partOutputChannel.send(new GenericMessage<>("0"));
|
partOutputChannel.send(new GenericMessage<>("0"));
|
||||||
partOutputChannel.send(new GenericMessage<>("1"));
|
partOutputChannel.send(new GenericMessage<>("1"));
|
||||||
message = partInputChannel0.receive(10000);
|
message = partInputChannel0.receive(10000);
|
||||||
assertNotNull(message);
|
assertThat(message).isNotNull();
|
||||||
assertEquals("0", message.getPayload());
|
assertThat(message.getPayload()).isEqualTo("0");
|
||||||
message = partInputChannel1.receive(10000);
|
message = partInputChannel1.receive(10000);
|
||||||
assertNotNull(message);
|
assertThat(message).isNotNull();
|
||||||
assertEquals("1", message.getPayload());
|
assertThat(message.getPayload()).isEqualTo("1");
|
||||||
|
|
||||||
late0ProducerBinding.unbind();
|
late0ProducerBinding.unbind();
|
||||||
late0ConsumerBinding.unbind();
|
late0ConsumerBinding.unbind();
|
||||||
@@ -734,41 +748,39 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
Advice retry;
|
Advice retry;
|
||||||
container = TestUtils.getPropertyValue(endpoint, "messageListenerContainer",
|
container = TestUtils.getPropertyValue(endpoint, "messageListenerContainer",
|
||||||
SimpleMessageListenerContainer.class);
|
SimpleMessageListenerContainer.class);
|
||||||
assertEquals(AcknowledgeMode.NONE, container.getAcknowledgeMode());
|
assertThat(container.getAcknowledgeMode()).isEqualTo(AcknowledgeMode.NONE);
|
||||||
assertThat(container.getQueueNames()[0], startsWith("foo.props.0"));
|
assertThat(container.getQueueNames()[0]).startsWith("foo.props.0");
|
||||||
assertFalse(TestUtils.getPropertyValue(container, "transactional", Boolean.class));
|
assertThat(TestUtils.getPropertyValue(container, "transactional", Boolean.class)).isFalse();
|
||||||
assertEquals(2, TestUtils.getPropertyValue(container, "concurrentConsumers"));
|
assertThat(TestUtils.getPropertyValue(container, "concurrentConsumers")).isEqualTo(2);
|
||||||
assertEquals(3, TestUtils.getPropertyValue(container, "maxConcurrentConsumers"));
|
assertThat(TestUtils.getPropertyValue(container, "maxConcurrentConsumers")).isEqualTo(3);
|
||||||
assertFalse(TestUtils.getPropertyValue(container, "defaultRequeueRejected", Boolean.class));
|
assertThat(TestUtils.getPropertyValue(container, "defaultRequeueRejected", Boolean.class)).isFalse();
|
||||||
assertEquals(20, TestUtils.getPropertyValue(container, "prefetchCount"));
|
assertThat(TestUtils.getPropertyValue(container, "prefetchCount")).isEqualTo(20);
|
||||||
assertEquals(10, TestUtils.getPropertyValue(container, "txSize"));
|
assertThat(TestUtils.getPropertyValue(container, "txSize")).isEqualTo(10);
|
||||||
retry = TestUtils.getPropertyValue(container, "adviceChain", Advice[].class)[0];
|
retry = TestUtils.getPropertyValue(container, "adviceChain", Advice[].class)[0];
|
||||||
assertEquals(23, TestUtils.getPropertyValue(retry, "retryOperations.retryPolicy.maxAttempts"));
|
assertThat(TestUtils.getPropertyValue(retry, "retryOperations.retryPolicy.maxAttempts")).isEqualTo(23);
|
||||||
assertEquals(2000L, TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.initialInterval"));
|
assertThat(TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.initialInterval")).isEqualTo(2000L);
|
||||||
assertEquals(20000L, TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.maxInterval"));
|
assertThat(TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.maxInterval")).isEqualTo(20000L);
|
||||||
assertEquals(5.0, TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.multiplier"));
|
assertThat(TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.multiplier")).isEqualTo(5.0);
|
||||||
|
|
||||||
List<?> requestMatchers = TestUtils.getPropertyValue(endpoint,
|
List<?> requestMatchers = TestUtils.getPropertyValue(endpoint, "headerMapper.requestHeaderMatcher.matchers",
|
||||||
"headerMapper.requestHeaderMatcher.matchers",
|
|
||||||
List.class);
|
List.class);
|
||||||
assertEquals(1, requestMatchers.size());
|
assertThat(requestMatchers).hasSize(1);
|
||||||
assertEquals("foo", TestUtils.getPropertyValue(requestMatchers.get(0), "pattern"));
|
assertThat(TestUtils.getPropertyValue(requestMatchers.get(0), "pattern")).isEqualTo("foo");
|
||||||
|
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyFooRequestProducer(AbstractEndpoint endpoint) {
|
private void verifyFooRequestProducer(AbstractEndpoint endpoint) {
|
||||||
List<?> requestMatchers = TestUtils.getPropertyValue(endpoint,
|
List<?> requestMatchers = TestUtils.getPropertyValue(endpoint,
|
||||||
"handler.delegate.headerMapper.requestHeaderMatcher.matchers",
|
"handler.delegate.headerMapper.requestHeaderMatcher.matchers", List.class);
|
||||||
List.class);
|
assertThat(requestMatchers).hasSize(1);
|
||||||
assertEquals(1, requestMatchers.size());
|
assertThat(TestUtils.getPropertyValue(requestMatchers.get(0), "pattern")).isEqualTo("foo");
|
||||||
assertEquals("foo", TestUtils.getPropertyValue(requestMatchers.get(0), "pattern"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getEndpointRouting(AbstractEndpoint endpoint) {
|
protected String getEndpointRouting(AbstractEndpoint endpoint) {
|
||||||
return TestUtils.getPropertyValue(endpoint, "handler.delegate.routingKeyExpression",
|
return TestUtils.getPropertyValue(endpoint, "handler.delegate.routingKeyExpression", SpelExpression.class)
|
||||||
SpelExpression.class).getExpressionString();
|
.getExpressionString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -778,8 +790,8 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getPubSubEndpointRouting(AbstractEndpoint endpoint) {
|
protected String getPubSubEndpointRouting(AbstractEndpoint endpoint) {
|
||||||
return TestUtils.getPropertyValue(endpoint, "handler.delegate.exchangeNameExpression",
|
return TestUtils.getPropertyValue(endpoint, "handler.delegate.exchangeNameExpression", SpelExpression.class)
|
||||||
SpelExpression.class).getExpressionString();
|
.getExpressionString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -805,7 +817,7 @@ public class RabbitBinderTests extends PartitionCapableBinderTests<RabbitTestBin
|
|||||||
bar = template.receiveAndConvert(new RabbitConsumerProperties().getPrefix() + queue);
|
bar = template.receiveAndConvert(new RabbitConsumerProperties().getPrefix() + queue);
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
}
|
}
|
||||||
assertTrue("Message did not arrive in RabbitMQ", n < 100);
|
assertThat(n).isLessThan(100).withFailMessage("Message did not arrive in RabbitMQ");
|
||||||
return bar;
|
return bar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,14 +48,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
|||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.messaging.MessageChannel;
|
import org.springframework.messaging.MessageChannel;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.Matchers.hasKey;
|
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
|
||||||
import static org.hamcrest.Matchers.is;
|
|
||||||
import static org.hamcrest.Matchers.not;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Marius Bogoevici
|
* @author Marius Bogoevici
|
||||||
@@ -89,22 +82,22 @@ public class RabbitBinderModuleTests {
|
|||||||
context = SpringApplication.run(SimpleProcessor.class, "--server.port=0");
|
context = SpringApplication.run(SimpleProcessor.class, "--server.port=0");
|
||||||
BinderFactory<?> binderFactory = context.getBean(BinderFactory.class);
|
BinderFactory<?> binderFactory = context.getBean(BinderFactory.class);
|
||||||
Binder binder = binderFactory.getBinder(null);
|
Binder binder = binderFactory.getBinder(null);
|
||||||
assertThat(binder, instanceOf(RabbitMessageChannelBinder.class));
|
assertThat(binder).isInstanceOf(RabbitMessageChannelBinder.class);
|
||||||
DirectFieldAccessor binderFieldAccessor = new DirectFieldAccessor(binder);
|
DirectFieldAccessor binderFieldAccessor = new DirectFieldAccessor(binder);
|
||||||
ConnectionFactory binderConnectionFactory = (ConnectionFactory) binderFieldAccessor
|
ConnectionFactory binderConnectionFactory = (ConnectionFactory) binderFieldAccessor
|
||||||
.getPropertyValue("connectionFactory");
|
.getPropertyValue("connectionFactory");
|
||||||
assertThat(binderConnectionFactory, instanceOf(CachingConnectionFactory.class));
|
assertThat(binderConnectionFactory).isInstanceOf(CachingConnectionFactory.class);
|
||||||
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
|
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
|
||||||
assertThat(binderConnectionFactory, is(connectionFactory));
|
assertThat(binderConnectionFactory).isSameAs(connectionFactory);
|
||||||
CompositeHealthIndicator bindersHealthIndicator = context.getBean("bindersHealthIndicator",
|
CompositeHealthIndicator bindersHealthIndicator = context.getBean("bindersHealthIndicator",
|
||||||
CompositeHealthIndicator.class);
|
CompositeHealthIndicator.class);
|
||||||
DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(bindersHealthIndicator);
|
DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(bindersHealthIndicator);
|
||||||
assertNotNull(bindersHealthIndicator);
|
assertThat(bindersHealthIndicator).isNotNull();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, HealthIndicator> healthIndicators = (Map<String, HealthIndicator>) directFieldAccessor
|
Map<String, HealthIndicator> healthIndicators = (Map<String, HealthIndicator>) directFieldAccessor
|
||||||
.getPropertyValue("indicators");
|
.getPropertyValue("indicators");
|
||||||
assertThat(healthIndicators, hasKey("rabbit"));
|
assertThat(healthIndicators).containsKey(("rabbit"));
|
||||||
assertThat(healthIndicators.get("rabbit").health().getStatus(), equalTo(Status.UP));
|
assertThat(healthIndicators.get("rabbit").health().getStatus()).isEqualTo((Status.UP));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -115,7 +108,7 @@ public class RabbitBinderModuleTests {
|
|||||||
"--spring.cloud.stream.rabbit.bindings.output.producer.transacted=true");
|
"--spring.cloud.stream.rabbit.bindings.output.producer.transacted=true");
|
||||||
BinderFactory<?> binderFactory = context.getBean(BinderFactory.class);
|
BinderFactory<?> binderFactory = context.getBean(BinderFactory.class);
|
||||||
Binder binder = binderFactory.getBinder(null);
|
Binder binder = binderFactory.getBinder(null);
|
||||||
assertThat(binder, instanceOf(RabbitMessageChannelBinder.class));
|
assertThat(binder).isInstanceOf(RabbitMessageChannelBinder.class);
|
||||||
ChannelBindingService channelBindingService = context.getBean(ChannelBindingService.class);
|
ChannelBindingService channelBindingService = context.getBean(ChannelBindingService.class);
|
||||||
DirectFieldAccessor channelBindingServiceAccessor = new DirectFieldAccessor(channelBindingService);
|
DirectFieldAccessor channelBindingServiceAccessor = new DirectFieldAccessor(channelBindingService);
|
||||||
Map<String, List<Binding<MessageChannel>>> consumerBindings = (Map<String, List<Binding<MessageChannel>>>) channelBindingServiceAccessor
|
Map<String, List<Binding<MessageChannel>>> consumerBindings = (Map<String, List<Binding<MessageChannel>>>) channelBindingServiceAccessor
|
||||||
@@ -123,27 +116,27 @@ public class RabbitBinderModuleTests {
|
|||||||
Binding<MessageChannel> inputBinding = consumerBindings.get("input").get(0);
|
Binding<MessageChannel> inputBinding = consumerBindings.get("input").get(0);
|
||||||
SimpleMessageListenerContainer container = TestUtils.getPropertyValue(inputBinding,
|
SimpleMessageListenerContainer container = TestUtils.getPropertyValue(inputBinding,
|
||||||
"endpoint.messageListenerContainer", SimpleMessageListenerContainer.class);
|
"endpoint.messageListenerContainer", SimpleMessageListenerContainer.class);
|
||||||
assertTrue(TestUtils.getPropertyValue(container, "transactional", Boolean.class));
|
assertThat(TestUtils.getPropertyValue(container, "transactional", Boolean.class)).isTrue();
|
||||||
Map<String, Binding<MessageChannel>> producerBindings = (Map<String, Binding<MessageChannel>>) TestUtils
|
Map<String, Binding<MessageChannel>> producerBindings = (Map<String, Binding<MessageChannel>>) TestUtils
|
||||||
.getPropertyValue(channelBindingService, "producerBindings");
|
.getPropertyValue(channelBindingService, "producerBindings");
|
||||||
Binding<MessageChannel> outputBinding = producerBindings.get("output");
|
Binding<MessageChannel> outputBinding = producerBindings.get("output");
|
||||||
assertTrue(TestUtils.getPropertyValue(outputBinding, "endpoint.handler.delegate.amqpTemplate.transactional",
|
assertThat(TestUtils.getPropertyValue(outputBinding, "endpoint.handler.delegate.amqpTemplate.transactional",
|
||||||
Boolean.class));
|
Boolean.class)).isTrue();
|
||||||
DirectFieldAccessor binderFieldAccessor = new DirectFieldAccessor(binder);
|
DirectFieldAccessor binderFieldAccessor = new DirectFieldAccessor(binder);
|
||||||
ConnectionFactory binderConnectionFactory = (ConnectionFactory) binderFieldAccessor
|
ConnectionFactory binderConnectionFactory = (ConnectionFactory) binderFieldAccessor
|
||||||
.getPropertyValue("connectionFactory");
|
.getPropertyValue("connectionFactory");
|
||||||
assertThat(binderConnectionFactory, instanceOf(CachingConnectionFactory.class));
|
assertThat(binderConnectionFactory).isInstanceOf(CachingConnectionFactory.class);
|
||||||
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
|
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
|
||||||
assertThat(binderConnectionFactory, is(connectionFactory));
|
assertThat(binderConnectionFactory).isSameAs(connectionFactory);
|
||||||
CompositeHealthIndicator bindersHealthIndicator = context.getBean("bindersHealthIndicator",
|
CompositeHealthIndicator bindersHealthIndicator = context.getBean("bindersHealthIndicator",
|
||||||
CompositeHealthIndicator.class);
|
CompositeHealthIndicator.class);
|
||||||
DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(bindersHealthIndicator);
|
DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(bindersHealthIndicator);
|
||||||
assertNotNull(bindersHealthIndicator);
|
assertThat(bindersHealthIndicator).isNotNull();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, HealthIndicator> healthIndicators = (Map<String, HealthIndicator>) directFieldAccessor
|
Map<String, HealthIndicator> healthIndicators = (Map<String, HealthIndicator>) directFieldAccessor
|
||||||
.getPropertyValue("indicators");
|
.getPropertyValue("indicators");
|
||||||
assertThat(healthIndicators, hasKey("rabbit"));
|
assertThat(healthIndicators).containsKey("rabbit");
|
||||||
assertThat(healthIndicators.get("rabbit").health().getStatus(), equalTo(Status.UP));
|
assertThat(healthIndicators.get("rabbit").health().getStatus()).isEqualTo(Status.UP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -152,23 +145,23 @@ public class RabbitBinderModuleTests {
|
|||||||
.run("--server.port=0");
|
.run("--server.port=0");
|
||||||
BinderFactory<?> binderFactory = context.getBean(BinderFactory.class);
|
BinderFactory<?> binderFactory = context.getBean(BinderFactory.class);
|
||||||
Binder binder = binderFactory.getBinder(null);
|
Binder binder = binderFactory.getBinder(null);
|
||||||
assertThat(binder, instanceOf(RabbitMessageChannelBinder.class));
|
assertThat(binder).isInstanceOf(RabbitMessageChannelBinder.class);
|
||||||
DirectFieldAccessor binderFieldAccessor = new DirectFieldAccessor(binder);
|
DirectFieldAccessor binderFieldAccessor = new DirectFieldAccessor(binder);
|
||||||
ConnectionFactory binderConnectionFactory = (ConnectionFactory) binderFieldAccessor
|
ConnectionFactory binderConnectionFactory = (ConnectionFactory) binderFieldAccessor
|
||||||
.getPropertyValue("connectionFactory");
|
.getPropertyValue("connectionFactory");
|
||||||
assertThat(binderConnectionFactory, is(MOCK_CONNECTION_FACTORY));
|
assertThat(binderConnectionFactory).isSameAs(MOCK_CONNECTION_FACTORY);
|
||||||
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
|
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
|
||||||
assertThat(binderConnectionFactory, is(connectionFactory));
|
assertThat(binderConnectionFactory).isSameAs(connectionFactory);
|
||||||
CompositeHealthIndicator bindersHealthIndicator = context.getBean("bindersHealthIndicator",
|
CompositeHealthIndicator bindersHealthIndicator = context.getBean("bindersHealthIndicator",
|
||||||
CompositeHealthIndicator.class);
|
CompositeHealthIndicator.class);
|
||||||
assertNotNull(bindersHealthIndicator);
|
assertThat(bindersHealthIndicator).isNotNull();
|
||||||
DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(bindersHealthIndicator);
|
DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(bindersHealthIndicator);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, HealthIndicator> healthIndicators = (Map<String, HealthIndicator>) directFieldAccessor
|
Map<String, HealthIndicator> healthIndicators = (Map<String, HealthIndicator>) directFieldAccessor
|
||||||
.getPropertyValue("indicators");
|
.getPropertyValue("indicators");
|
||||||
assertThat(healthIndicators, hasKey("rabbit"));
|
assertThat(healthIndicators).containsKey("rabbit");
|
||||||
// mock connection factory behaves as if down
|
// mock connection factory behaves as if down
|
||||||
assertThat(healthIndicators.get("rabbit").health().getStatus(), equalTo(Status.DOWN));
|
assertThat(healthIndicators.get("rabbit").health().getStatus()).isEqualTo(Status.DOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -182,21 +175,21 @@ public class RabbitBinderModuleTests {
|
|||||||
context = SpringApplication.run(SimpleProcessor.class, params.toArray(new String[params.size()]));
|
context = SpringApplication.run(SimpleProcessor.class, params.toArray(new String[params.size()]));
|
||||||
BinderFactory<?> binderFactory = context.getBean(BinderFactory.class);
|
BinderFactory<?> binderFactory = context.getBean(BinderFactory.class);
|
||||||
Binder binder = binderFactory.getBinder(null);
|
Binder binder = binderFactory.getBinder(null);
|
||||||
assertThat(binder, instanceOf(RabbitMessageChannelBinder.class));
|
assertThat(binder).isInstanceOf(RabbitMessageChannelBinder.class);
|
||||||
DirectFieldAccessor binderFieldAccessor = new DirectFieldAccessor(binder);
|
DirectFieldAccessor binderFieldAccessor = new DirectFieldAccessor(binder);
|
||||||
ConnectionFactory binderConnectionFactory = (ConnectionFactory) binderFieldAccessor
|
ConnectionFactory binderConnectionFactory = (ConnectionFactory) binderFieldAccessor
|
||||||
.getPropertyValue("connectionFactory");
|
.getPropertyValue("connectionFactory");
|
||||||
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
|
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
|
||||||
assertThat(binderConnectionFactory, not(is(connectionFactory)));
|
assertThat(binderConnectionFactory).isNotSameAs(connectionFactory);
|
||||||
CompositeHealthIndicator bindersHealthIndicator = context.getBean("bindersHealthIndicator",
|
CompositeHealthIndicator bindersHealthIndicator = context.getBean("bindersHealthIndicator",
|
||||||
CompositeHealthIndicator.class);
|
CompositeHealthIndicator.class);
|
||||||
assertNotNull(bindersHealthIndicator);
|
assertThat(bindersHealthIndicator);
|
||||||
DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(bindersHealthIndicator);
|
DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(bindersHealthIndicator);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, HealthIndicator> healthIndicators = (Map<String, HealthIndicator>) directFieldAccessor
|
Map<String, HealthIndicator> healthIndicators = (Map<String, HealthIndicator>) directFieldAccessor
|
||||||
.getPropertyValue("indicators");
|
.getPropertyValue("indicators");
|
||||||
assertThat(healthIndicators, hasKey("custom"));
|
assertThat(healthIndicators).containsKey("custom");
|
||||||
assertThat(healthIndicators.get("custom").health().getStatus(), equalTo(Status.UP));
|
assertThat(healthIndicators.get("custom").health().getStatus()).isEqualTo(Status.UP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EnableBinding(Processor.class)
|
@EnableBinding(Processor.class)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>spring-cloud-stream-binder-test</artifactId>
|
<artifactId>spring-cloud-stream-binder-test</artifactId>
|
||||||
@@ -33,5 +34,10 @@
|
|||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-stream</artifactId>
|
<artifactId>spring-cloud-stream</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ package org.springframework.cloud.stream.binder;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.hamcrest.collection.IsArrayContainingInAnyOrder;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@@ -32,19 +31,14 @@ import org.springframework.messaging.MessageHeaders;
|
|||||||
import org.springframework.messaging.PollableChannel;
|
import org.springframework.messaging.PollableChannel;
|
||||||
import org.springframework.util.MimeTypeUtils;
|
import org.springframework.util.MimeTypeUtils;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.Matchers.hasProperty;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gary Russell
|
* @author Gary Russell
|
||||||
* @author Ilayaperumal Gopinathan
|
* @author Ilayaperumal Gopinathan
|
||||||
* @author David Turanski
|
* @author David Turanski
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
|
* @author Marius Bogoevici
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends AbstractBinder<MessageChannel, CP, PP>, CP, PP>, CP extends ConsumerProperties, PP extends ProducerProperties> {
|
public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends AbstractBinder<MessageChannel, CP, PP>, CP, PP>, CP extends ConsumerProperties, PP extends ProducerProperties> {
|
||||||
@@ -79,21 +73,31 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
|||||||
@Test
|
@Test
|
||||||
public void testClean() throws Exception {
|
public void testClean() throws Exception {
|
||||||
Binder binder = getBinder();
|
Binder binder = getBinder();
|
||||||
Binding<MessageChannel> foo0ProducerBinding = binder.bindProducer("foo.0", new DirectChannel(), createProducerProperties());
|
Binding<MessageChannel> foo0ProducerBinding = binder.bindProducer("foo.0", new DirectChannel(),
|
||||||
Binding<MessageChannel> foo0ConsumerBinding = binder.bindConsumer("foo.0", "test", new DirectChannel(), createConsumerProperties());
|
createProducerProperties());
|
||||||
Binding<MessageChannel> foo1ProducerBinding = binder.bindProducer("foo.1", new DirectChannel(), createProducerProperties());
|
Binding<MessageChannel> foo0ConsumerBinding = binder.bindConsumer("foo.0", "test", new DirectChannel(),
|
||||||
Binding<MessageChannel> foo1ConsumerBinding = binder.bindConsumer("foo.1", "test", new DirectChannel(), createConsumerProperties());
|
createConsumerProperties());
|
||||||
Binding<MessageChannel> foo2ProducerBinding = binder.bindProducer("foo.2", new DirectChannel(), createProducerProperties());
|
Binding<MessageChannel> foo1ProducerBinding = binder.bindProducer("foo.1", new DirectChannel(),
|
||||||
|
createProducerProperties());
|
||||||
|
Binding<MessageChannel> foo1ConsumerBinding = binder.bindConsumer("foo.1", "test", new DirectChannel(),
|
||||||
|
createConsumerProperties());
|
||||||
|
Binding<MessageChannel> foo2ProducerBinding = binder.bindProducer("foo.2", new DirectChannel(),
|
||||||
|
createProducerProperties());
|
||||||
foo0ProducerBinding.unbind();
|
foo0ProducerBinding.unbind();
|
||||||
assertFalse(TestUtils.getPropertyValue(foo0ProducerBinding, "endpoint", AbstractEndpoint.class).isRunning());
|
assertThat(TestUtils.getPropertyValue(foo0ProducerBinding, "endpoint", AbstractEndpoint.class).isRunning())
|
||||||
|
.isFalse();
|
||||||
foo0ConsumerBinding.unbind();
|
foo0ConsumerBinding.unbind();
|
||||||
foo1ProducerBinding.unbind();
|
foo1ProducerBinding.unbind();
|
||||||
assertFalse(TestUtils.getPropertyValue(foo0ConsumerBinding, "endpoint", AbstractEndpoint.class).isRunning());
|
assertThat(TestUtils.getPropertyValue(foo0ConsumerBinding, "endpoint", AbstractEndpoint.class).isRunning())
|
||||||
assertFalse(TestUtils.getPropertyValue(foo1ProducerBinding, "endpoint", AbstractEndpoint.class).isRunning());
|
.isFalse();
|
||||||
|
assertThat(TestUtils.getPropertyValue(foo1ProducerBinding, "endpoint", AbstractEndpoint.class).isRunning())
|
||||||
|
.isFalse();
|
||||||
foo1ConsumerBinding.unbind();
|
foo1ConsumerBinding.unbind();
|
||||||
foo2ProducerBinding.unbind();
|
foo2ProducerBinding.unbind();
|
||||||
assertFalse(TestUtils.getPropertyValue(foo1ConsumerBinding, "endpoint", AbstractEndpoint.class).isRunning());
|
assertThat(TestUtils.getPropertyValue(foo1ConsumerBinding, "endpoint", AbstractEndpoint.class).isRunning())
|
||||||
assertFalse(TestUtils.getPropertyValue(foo2ProducerBinding, "endpoint", AbstractEndpoint.class).isRunning());
|
.isFalse();
|
||||||
|
assertThat(TestUtils.getPropertyValue(foo2ProducerBinding, "endpoint", AbstractEndpoint.class).isRunning())
|
||||||
|
.isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -101,18 +105,20 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
|||||||
Binder binder = getBinder();
|
Binder binder = getBinder();
|
||||||
DirectChannel moduleOutputChannel = new DirectChannel();
|
DirectChannel moduleOutputChannel = new DirectChannel();
|
||||||
QueueChannel moduleInputChannel = new QueueChannel();
|
QueueChannel moduleInputChannel = new QueueChannel();
|
||||||
Binding<MessageChannel> producerBinding = binder.bindProducer("foo.0", moduleOutputChannel, createProducerProperties());
|
Binding<MessageChannel> producerBinding = binder.bindProducer("foo.0", moduleOutputChannel,
|
||||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer("foo.0", "test", moduleInputChannel, createConsumerProperties());
|
createProducerProperties());
|
||||||
Message<?> message = MessageBuilder.withPayload("foo").setHeader(MessageHeaders.CONTENT_TYPE,
|
Binding<MessageChannel> consumerBinding = binder.bindConsumer("foo.0", "test", moduleInputChannel,
|
||||||
"foo/bar").build();
|
createConsumerProperties());
|
||||||
|
Message<?> message = MessageBuilder.withPayload("foo").setHeader(MessageHeaders.CONTENT_TYPE, "foo/bar")
|
||||||
|
.build();
|
||||||
// Let the consumer actually bind to the producer before sending a msg
|
// Let the consumer actually bind to the producer before sending a msg
|
||||||
binderBindUnbindLatency();
|
binderBindUnbindLatency();
|
||||||
moduleOutputChannel.send(message);
|
moduleOutputChannel.send(message);
|
||||||
Message<?> inbound = receive(moduleInputChannel);
|
Message<?> inbound = receive(moduleInputChannel);
|
||||||
assertNotNull(inbound);
|
assertThat(inbound).isNotNull();
|
||||||
assertEquals("foo", inbound.getPayload());
|
assertThat(inbound.getPayload()).isEqualTo("foo");
|
||||||
assertNull(inbound.getHeaders().get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE));
|
assertThat(inbound.getHeaders().get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)).isNull();
|
||||||
assertEquals("foo/bar", inbound.getHeaders().get(MessageHeaders.CONTENT_TYPE));
|
assertThat(inbound.getHeaders().get(MessageHeaders.CONTENT_TYPE)).isEqualTo("foo/bar");
|
||||||
producerBinding.unbind();
|
producerBinding.unbind();
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
}
|
}
|
||||||
@@ -147,12 +153,10 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
|||||||
messages[0] = receive(moduleInputChannel);
|
messages[0] = receive(moduleInputChannel);
|
||||||
messages[1] = receive(moduleInputChannel);
|
messages[1] = receive(moduleInputChannel);
|
||||||
|
|
||||||
assertNotNull(messages[0]);
|
assertThat(messages[0]).isNotNull();
|
||||||
assertNotNull(messages[1]);
|
assertThat(messages[1]).isNotNull();
|
||||||
assertThat(messages, IsArrayContainingInAnyOrder.arrayContainingInAnyOrder(
|
assertThat(messages).extracting("payload").containsExactlyInAnyOrder(testPayload1.getBytes(),
|
||||||
hasProperty("payload", equalTo(testPayload1.getBytes())),
|
testPayload2.getBytes());
|
||||||
hasProperty("payload", equalTo(testPayload2.getBytes()))));
|
|
||||||
|
|
||||||
|
|
||||||
producerBinding1.unbind();
|
producerBinding1.unbind();
|
||||||
producerBinding2.unbind();
|
producerBinding2.unbind();
|
||||||
@@ -174,10 +178,10 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
|||||||
Message<?> message = MessageBuilder.withPayload("foo").build();
|
Message<?> message = MessageBuilder.withPayload("foo").build();
|
||||||
moduleOutputChannel.send(message);
|
moduleOutputChannel.send(message);
|
||||||
Message<?> inbound = receive(moduleInputChannel);
|
Message<?> inbound = receive(moduleInputChannel);
|
||||||
assertNotNull(inbound);
|
assertThat(inbound).isNotNull();
|
||||||
assertEquals("foo", inbound.getPayload());
|
assertThat(inbound.getPayload()).isEqualTo("foo");
|
||||||
assertNull(inbound.getHeaders().get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE));
|
assertThat(inbound.getHeaders().get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)).isNull();
|
||||||
assertEquals(MimeTypeUtils.TEXT_PLAIN_VALUE, inbound.getHeaders().get(MessageHeaders.CONTENT_TYPE));
|
assertThat(inbound.getHeaders().get(MessageHeaders.CONTENT_TYPE)).isEqualTo(MimeTypeUtils.TEXT_PLAIN_VALUE);
|
||||||
producerBinding.unbind();
|
producerBinding.unbind();
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,10 +17,10 @@
|
|||||||
package org.springframework.cloud.stream.binder;
|
package org.springframework.cloud.stream.binder;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.hamcrest.CustomMatcher;
|
import org.assertj.core.api.Condition;
|
||||||
import org.hamcrest.Matcher;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.DirectFieldAccessor;
|
import org.springframework.beans.DirectFieldAccessor;
|
||||||
@@ -34,15 +34,7 @@ import org.springframework.messaging.Message;
|
|||||||
import org.springframework.messaging.MessageChannel;
|
import org.springframework.messaging.MessageChannel;
|
||||||
import org.springframework.messaging.support.GenericMessage;
|
import org.springframework.messaging.support.GenericMessage;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.Matchers.containsString;
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
|
||||||
import static org.hamcrest.Matchers.hasProperty;
|
|
||||||
import static org.hamcrest.Matchers.not;
|
|
||||||
import static org.hamcrest.Matchers.nullValue;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for binders that support partitioning.
|
* Tests for binders that support partitioning.
|
||||||
@@ -76,12 +68,12 @@ abstract public class PartitionCapableBinderTests<B extends AbstractTestBinder<?
|
|||||||
output.send(new GenericMessage<>(testPayload1.getBytes()));
|
output.send(new GenericMessage<>(testPayload1.getBytes()));
|
||||||
|
|
||||||
Message<byte[]> receivedMessage1 = (Message<byte[]>) receive(input1);
|
Message<byte[]> receivedMessage1 = (Message<byte[]>) receive(input1);
|
||||||
assertThat(receivedMessage1, not(nullValue()));
|
assertThat(receivedMessage1).isNotNull();
|
||||||
assertThat(new String(receivedMessage1.getPayload()), equalTo(testPayload1));
|
assertThat(new String(receivedMessage1.getPayload())).isEqualTo(testPayload1);
|
||||||
|
|
||||||
Message<byte[]> receivedMessage2 = (Message<byte[]>) receive(input2);
|
Message<byte[]> receivedMessage2 = (Message<byte[]>) receive(input2);
|
||||||
assertThat(receivedMessage2, not(nullValue()));
|
assertThat(receivedMessage2).isNotNull();
|
||||||
assertThat(new String(receivedMessage2.getPayload()), equalTo(testPayload1));
|
assertThat(new String(receivedMessage2.getPayload())).isEqualTo(testPayload1);
|
||||||
|
|
||||||
binding2.unbind();
|
binding2.unbind();
|
||||||
|
|
||||||
@@ -93,15 +85,15 @@ abstract public class PartitionCapableBinderTests<B extends AbstractTestBinder<?
|
|||||||
output.send(new GenericMessage<>(testPayload3.getBytes()));
|
output.send(new GenericMessage<>(testPayload3.getBytes()));
|
||||||
|
|
||||||
receivedMessage1 = (Message<byte[]>) receive(input1);
|
receivedMessage1 = (Message<byte[]>) receive(input1);
|
||||||
assertThat(receivedMessage1, not(nullValue()));
|
assertThat(receivedMessage1).isNotNull();
|
||||||
assertThat(new String(receivedMessage1.getPayload()), equalTo(testPayload2));
|
assertThat(new String(receivedMessage1.getPayload())).isEqualTo(testPayload2);
|
||||||
receivedMessage1 = (Message<byte[]>) receive(input1);
|
receivedMessage1 = (Message<byte[]>) receive(input1);
|
||||||
assertThat(receivedMessage1, not(nullValue()));
|
assertThat(receivedMessage1).isNotNull();
|
||||||
assertThat(new String(receivedMessage1.getPayload()), equalTo(testPayload3));
|
assertThat(new String(receivedMessage1.getPayload())).isNotNull();
|
||||||
|
|
||||||
receivedMessage2 = (Message<byte[]>) receive(input2);
|
receivedMessage2 = (Message<byte[]>) receive(input2);
|
||||||
assertThat(receivedMessage2, not(nullValue()));
|
assertThat(receivedMessage2).isNotNull();
|
||||||
assertThat(new String(receivedMessage2.getPayload()), equalTo(testPayload3));
|
assertThat(new String(receivedMessage2.getPayload())).isEqualTo(testPayload3);
|
||||||
|
|
||||||
producerBinding.unbind();
|
producerBinding.unbind();
|
||||||
binding1.unbind();
|
binding1.unbind();
|
||||||
@@ -128,8 +120,8 @@ abstract public class PartitionCapableBinderTests<B extends AbstractTestBinder<?
|
|||||||
createConsumerProperties());
|
createConsumerProperties());
|
||||||
|
|
||||||
Message<?> receivedMessage1 = receive(inbound1);
|
Message<?> receivedMessage1 = receive(inbound1);
|
||||||
assertThat(receivedMessage1, not(nullValue()));
|
assertThat(receivedMessage1).isNotNull();
|
||||||
assertThat(new String((byte[]) receivedMessage1.getPayload()), equalTo(testPayload));
|
assertThat(new String((byte[]) receivedMessage1.getPayload())).isEqualTo(testPayload);
|
||||||
|
|
||||||
producerBinding.unbind();
|
producerBinding.unbind();
|
||||||
consumerBinding.unbind();
|
consumerBinding.unbind();
|
||||||
@@ -157,11 +149,11 @@ abstract public class PartitionCapableBinderTests<B extends AbstractTestBinder<?
|
|||||||
createConsumerProperties());
|
createConsumerProperties());
|
||||||
|
|
||||||
Message<?> receivedMessage1 = receive(inbound1);
|
Message<?> receivedMessage1 = receive(inbound1);
|
||||||
assertThat(receivedMessage1, not(nullValue()));
|
assertThat(receivedMessage1).isNotNull();
|
||||||
assertThat(new String((byte[]) receivedMessage1.getPayload()), equalTo(testPayload));
|
assertThat(new String((byte[]) receivedMessage1.getPayload())).isEqualTo(testPayload);
|
||||||
Message<?> receivedMessage2 = receive(inbound2);
|
Message<?> receivedMessage2 = receive(inbound2);
|
||||||
assertThat(receivedMessage2, not(nullValue()));
|
assertThat(receivedMessage2).isNotNull();
|
||||||
assertThat(new String((byte[]) receivedMessage2.getPayload()), equalTo(testPayload));
|
assertThat(new String((byte[]) receivedMessage2.getPayload())).isEqualTo(testPayload);
|
||||||
|
|
||||||
consumerBinding1.unbind();
|
consumerBinding1.unbind();
|
||||||
consumerBinding2.unbind();
|
consumerBinding2.unbind();
|
||||||
@@ -199,8 +191,8 @@ abstract public class PartitionCapableBinderTests<B extends AbstractTestBinder<?
|
|||||||
Binding<MessageChannel> outputBinding = binder.bindProducer("part.0", output, producerProperties);
|
Binding<MessageChannel> outputBinding = binder.bindProducer("part.0", output, producerProperties);
|
||||||
try {
|
try {
|
||||||
AbstractEndpoint endpoint = extractEndpoint(outputBinding);
|
AbstractEndpoint endpoint = extractEndpoint(outputBinding);
|
||||||
assertThat(getEndpointRouting(endpoint),
|
assertThat(getEndpointRouting(endpoint))
|
||||||
containsString(getExpectedRoutingBaseDestination("part.0", "test") + "-' + headers['partition']"));
|
.contains(getExpectedRoutingBaseDestination("part.0", "test") + "-' + headers['partition']");
|
||||||
}
|
}
|
||||||
catch (UnsupportedOperationException ignored) {
|
catch (UnsupportedOperationException ignored) {
|
||||||
}
|
}
|
||||||
@@ -214,36 +206,38 @@ abstract public class PartitionCapableBinderTests<B extends AbstractTestBinder<?
|
|||||||
output.send(new GenericMessage<>(0));
|
output.send(new GenericMessage<>(0));
|
||||||
|
|
||||||
Message<?> receive0 = receive(input0);
|
Message<?> receive0 = receive(input0);
|
||||||
assertNotNull(receive0);
|
assertThat(receive0).isNotNull();
|
||||||
Message<?> receive1 = receive(input1);
|
Message<?> receive1 = receive(input1);
|
||||||
assertNotNull(receive1);
|
assertThat(receive1).isNotNull();
|
||||||
Message<?> receive2 = receive(input2);
|
Message<?> receive2 = receive(input2);
|
||||||
assertNotNull(receive2);
|
assertThat(receive2).isNotNull();
|
||||||
|
|
||||||
Matcher<Message<?>> fooMatcher = new CustomMatcher<Message<?>>("the message with 'foo' as its correlationId") {
|
|
||||||
|
|
||||||
|
Condition<Message<?>> correlationHeadersForPayload2 = new Condition<Message<?>>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Object item) {
|
public boolean matches(Message<?> value) {
|
||||||
IntegrationMessageHeaderAccessor accessor = new IntegrationMessageHeaderAccessor((Message<?>) item);
|
IntegrationMessageHeaderAccessor accessor = new IntegrationMessageHeaderAccessor(value);
|
||||||
boolean result = "foo".equals(accessor.getCorrelationId()) && 42 == accessor.getSequenceNumber()
|
return "foo".equals(accessor.getCorrelationId()) && 42 == accessor.getSequenceNumber()
|
||||||
&& 43 == accessor.getSequenceSize();
|
&& 43 == accessor.getSequenceSize();
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (usesExplicitRouting()) {
|
if (usesExplicitRouting()) {
|
||||||
assertEquals(0, receive0.getPayload());
|
assertThat(receive0.getPayload()).isEqualTo(0);
|
||||||
assertEquals(1, receive1.getPayload());
|
assertThat(receive1.getPayload()).isEqualTo(1);
|
||||||
assertEquals(2, receive2.getPayload());
|
assertThat(receive2.getPayload()).isEqualTo(2);
|
||||||
assertThat(receive2, fooMatcher);
|
assertThat(receive2).has(correlationHeadersForPayload2);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assertThat(Arrays.asList((Integer) receive0.getPayload(), (Integer) receive1.getPayload(),
|
List<Message<?>> receivedMessages = Arrays.asList(receive0, receive1, receive2);
|
||||||
(Integer) receive2.getPayload()), containsInAnyOrder(0, 1, 2));
|
assertThat(receivedMessages).extracting("payload").containsExactlyInAnyOrder(0, 1, 2);
|
||||||
|
Condition<Message<?>> payloadIs2 = new Condition<Message<?>>() {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@Override
|
||||||
Matcher<Iterable<? extends Message<?>>> containsOur3Messages = containsInAnyOrder(fooMatcher,
|
public boolean matches(Message<?> value) {
|
||||||
hasProperty("payload", equalTo(0)), hasProperty("payload", equalTo(1)));
|
return value.getPayload().equals(2);
|
||||||
assertThat(Arrays.asList(receive0, receive1, receive2), containsOur3Messages);
|
}
|
||||||
|
};
|
||||||
|
assertThat(receivedMessages).filteredOn(payloadIs2).areExactly(1, correlationHeadersForPayload2);
|
||||||
|
|
||||||
}
|
}
|
||||||
input0Binding.unbind();
|
input0Binding.unbind();
|
||||||
@@ -282,8 +276,8 @@ abstract public class PartitionCapableBinderTests<B extends AbstractTestBinder<?
|
|||||||
Binding<MessageChannel> outputBinding = binder.bindProducer("partJ.0", output, producerProperties);
|
Binding<MessageChannel> outputBinding = binder.bindProducer("partJ.0", output, producerProperties);
|
||||||
if (usesExplicitRouting()) {
|
if (usesExplicitRouting()) {
|
||||||
AbstractEndpoint endpoint = extractEndpoint(outputBinding);
|
AbstractEndpoint endpoint = extractEndpoint(outputBinding);
|
||||||
assertThat(getEndpointRouting(endpoint),
|
assertThat(getEndpointRouting(endpoint)).
|
||||||
containsString(getExpectedRoutingBaseDestination("partJ.0", "test") + "-' + headers['partition']"));
|
contains(getExpectedRoutingBaseDestination("partJ.0", "test") + "-' + headers['partition']");
|
||||||
}
|
}
|
||||||
|
|
||||||
output.send(new GenericMessage<>(2));
|
output.send(new GenericMessage<>(2));
|
||||||
@@ -291,21 +285,20 @@ abstract public class PartitionCapableBinderTests<B extends AbstractTestBinder<?
|
|||||||
output.send(new GenericMessage<>(0));
|
output.send(new GenericMessage<>(0));
|
||||||
|
|
||||||
Message<?> receive0 = receive(input0);
|
Message<?> receive0 = receive(input0);
|
||||||
assertNotNull(receive0);
|
assertThat(receive0).isNotNull();
|
||||||
Message<?> receive1 = receive(input1);
|
Message<?> receive1 = receive(input1);
|
||||||
assertNotNull(receive1);
|
assertThat(receive1).isNotNull();
|
||||||
Message<?> receive2 = receive(input2);
|
Message<?> receive2 = receive(input2);
|
||||||
assertNotNull(receive2);
|
assertThat(receive2).isNotNull();
|
||||||
|
|
||||||
if (usesExplicitRouting()) {
|
if (usesExplicitRouting()) {
|
||||||
assertEquals(0, receive0.getPayload());
|
assertThat(receive0.getPayload()).isEqualTo(0);
|
||||||
assertEquals(1, receive1.getPayload());
|
assertThat(receive1.getPayload()).isEqualTo(1);
|
||||||
assertEquals(2, receive2.getPayload());
|
assertThat(receive2.getPayload()).isEqualTo(2);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
List<Message<?>> receivedMessages = Arrays.asList(receive0, receive1, receive2);
|
||||||
assertThat(Arrays.asList((Integer) receive0.getPayload(), (Integer) receive1.getPayload(),
|
assertThat(receivedMessages).extracting("payload").containsExactlyInAnyOrder(0, 1, 2);
|
||||||
(Integer) receive2.getPayload()), containsInAnyOrder(0, 1, 2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
input0Binding.unbind();
|
input0Binding.unbind();
|
||||||
|
|||||||
@@ -41,9 +41,8 @@ import org.springframework.tuple.TupleBuilder;
|
|||||||
import org.springframework.util.MimeType;
|
import org.springframework.util.MimeType;
|
||||||
import org.springframework.util.MimeTypeUtils;
|
import org.springframework.util.MimeTypeUtils;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertSame;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gary Russell
|
* @author Gary Russell
|
||||||
@@ -66,61 +65,57 @@ public class MessageChannelBinderSupportTests {
|
|||||||
byte[] payload = "foo".getBytes();
|
byte[] payload = "foo".getBytes();
|
||||||
Message<byte[]> message = MessageBuilder.withPayload(payload).build();
|
Message<byte[]> message = MessageBuilder.withPayload(payload).build();
|
||||||
MessageValues converted = binder.serializePayloadIfNecessary(message);
|
MessageValues converted = binder.serializePayloadIfNecessary(message);
|
||||||
assertSame(payload, converted.getPayload());
|
assertThat(converted.getPayload()).isSameAs(payload);
|
||||||
Message<?> convertedMessage = converted.toMessage();
|
Message<?> convertedMessage = converted.toMessage();
|
||||||
assertSame(payload, convertedMessage.getPayload());
|
assertThat(convertedMessage.getPayload()).isSameAs(payload);
|
||||||
assertEquals(MimeTypeUtils.APPLICATION_OCTET_STREAM,
|
assertThat(contentTypeResolver.resolve(convertedMessage.getHeaders()))
|
||||||
contentTypeResolver.resolve(convertedMessage.getHeaders()));
|
.isEqualTo(MimeTypeUtils.APPLICATION_OCTET_STREAM);
|
||||||
MessageValues reconstructed = binder.deserializePayloadIfNecessary(convertedMessage);
|
MessageValues reconstructed = binder.deserializePayloadIfNecessary(convertedMessage);
|
||||||
payload = (byte[]) reconstructed.getPayload();
|
payload = (byte[]) reconstructed.getPayload();
|
||||||
assertSame(converted.getPayload(), payload);
|
assertThat(converted.getPayload()).isSameAs(payload);
|
||||||
assertNull(reconstructed.get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE));
|
assertThat(reconstructed.get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBytesPassThruContentType() {
|
public void testBytesPassThruContentType() {
|
||||||
byte[] payload = "foo".getBytes();
|
byte[] payload = "foo".getBytes();
|
||||||
Message<byte[]> message = MessageBuilder.withPayload(payload)
|
Message<byte[]> message = MessageBuilder.withPayload(payload)
|
||||||
.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_OCTET_STREAM_VALUE)
|
.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_OCTET_STREAM_VALUE).build();
|
||||||
.build();
|
|
||||||
MessageValues messageValues = binder.serializePayloadIfNecessary(message);
|
MessageValues messageValues = binder.serializePayloadIfNecessary(message);
|
||||||
Message<?> converted = messageValues.toMessage();
|
Message<?> converted = messageValues.toMessage();
|
||||||
assertSame(payload, converted.getPayload());
|
assertThat(converted.getPayload()).isSameAs(payload);
|
||||||
assertEquals(MimeTypeUtils.APPLICATION_OCTET_STREAM,
|
assertThat(contentTypeResolver.resolve(converted.getHeaders()))
|
||||||
contentTypeResolver.resolve(converted.getHeaders()));
|
.isEqualTo(MimeTypeUtils.APPLICATION_OCTET_STREAM);
|
||||||
MessageValues reconstructed = binder.deserializePayloadIfNecessary(converted);
|
MessageValues reconstructed = binder.deserializePayloadIfNecessary(converted);
|
||||||
payload = (byte[]) reconstructed.getPayload();
|
payload = (byte[]) reconstructed.getPayload();
|
||||||
assertSame(converted.getPayload(), payload);
|
assertThat(converted.getPayload()).isSameAs(payload);
|
||||||
assertEquals(MimeTypeUtils.APPLICATION_OCTET_STREAM_VALUE,
|
assertThat(reconstructed.get(MessageHeaders.CONTENT_TYPE))
|
||||||
reconstructed.get(MessageHeaders.CONTENT_TYPE));
|
.isEqualTo(MimeTypeUtils.APPLICATION_OCTET_STREAM_VALUE);
|
||||||
assertNull(reconstructed.get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE));
|
assertThat(reconstructed.get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testString() throws IOException {
|
public void testString() throws IOException {
|
||||||
MessageValues convertedValues = binder.serializePayloadIfNecessary(
|
MessageValues convertedValues = binder.serializePayloadIfNecessary(new GenericMessage<>("foo"));
|
||||||
new GenericMessage<String>("foo"));
|
|
||||||
|
|
||||||
Message<?> converted = convertedValues.toMessage();
|
Message<?> converted = convertedValues.toMessage();
|
||||||
assertEquals(MimeTypeUtils.TEXT_PLAIN,
|
assertThat(contentTypeResolver.resolve(converted.getHeaders())).isEqualTo(MimeTypeUtils.TEXT_PLAIN);
|
||||||
contentTypeResolver.resolve(converted.getHeaders()));
|
|
||||||
MessageValues reconstructed = binder.deserializePayloadIfNecessary(converted);
|
MessageValues reconstructed = binder.deserializePayloadIfNecessary(converted);
|
||||||
assertEquals("foo", reconstructed.getPayload());
|
assertThat(reconstructed.getPayload()).isEqualTo("foo");
|
||||||
assertNull(reconstructed.get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE));
|
assertThat(reconstructed.get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)).isNull();
|
||||||
assertEquals(MimeTypeUtils.TEXT_PLAIN_VALUE, reconstructed.get(MessageHeaders.CONTENT_TYPE));
|
assertThat(reconstructed.get(MessageHeaders.CONTENT_TYPE)).isEqualTo(MimeTypeUtils.TEXT_PLAIN_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStringXML() throws IOException {
|
public void testStringXML() throws IOException {
|
||||||
Message<?> message = MessageBuilder
|
Message<?> message = MessageBuilder
|
||||||
.withPayload("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><test></test>")
|
.withPayload("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><test></test>")
|
||||||
.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_XML)
|
.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_XML).build();
|
||||||
.build();
|
|
||||||
Message<?> converted = binder.serializePayloadIfNecessary(message).toMessage();
|
Message<?> converted = binder.serializePayloadIfNecessary(message).toMessage();
|
||||||
assertEquals(MimeTypeUtils.TEXT_PLAIN, contentTypeResolver.resolve(converted.getHeaders()));
|
assertThat(contentTypeResolver.resolve(converted.getHeaders())).isEqualTo(MimeTypeUtils.TEXT_PLAIN);
|
||||||
MessageValues reconstructed = binder.deserializePayloadIfNecessary(converted);
|
MessageValues reconstructed = binder.deserializePayloadIfNecessary(converted);
|
||||||
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><test></test>", reconstructed.getPayload());
|
assertThat(reconstructed.getPayload())
|
||||||
assertEquals(MimeTypeUtils.TEXT_XML.toString(), reconstructed.get(MessageHeaders.CONTENT_TYPE));
|
.isEqualTo("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><test></test>");
|
||||||
|
assertThat(reconstructed.get(MessageHeaders.CONTENT_TYPE)).isEqualTo(MimeTypeUtils.TEXT_XML.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -133,13 +128,11 @@ public class MessageChannelBinderSupportTests {
|
|||||||
|
|
||||||
Message<?> converted = convertedValues.toMessage();
|
Message<?> converted = convertedValues.toMessage();
|
||||||
|
|
||||||
assertEquals(MimeTypeUtils.TEXT_PLAIN,
|
assertThat(contentTypeResolver.resolve(converted.getHeaders())).isEqualTo(MimeTypeUtils.TEXT_PLAIN);
|
||||||
contentTypeResolver.resolve(converted.getHeaders()));
|
assertThat(converted.getHeaders().get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)).isEqualTo(MimeTypeUtils.APPLICATION_JSON.toString());
|
||||||
assertEquals(MimeTypeUtils.APPLICATION_JSON.toString(),
|
|
||||||
converted.getHeaders().get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE));
|
|
||||||
MessageValues reconstructed = binder.deserializePayloadIfNecessary(converted);
|
MessageValues reconstructed = binder.deserializePayloadIfNecessary(converted);
|
||||||
assertEquals("{\"foo\":\"foo\"}", reconstructed.getPayload());
|
assertThat(reconstructed.getPayload()).isEqualTo("{\"foo\":\"foo\"}");
|
||||||
assertEquals(MimeTypeUtils.APPLICATION_JSON_VALUE, reconstructed.get(MessageHeaders.CONTENT_TYPE));
|
assertThat(reconstructed.get(MessageHeaders.CONTENT_TYPE)).isEqualTo(MimeTypeUtils.APPLICATION_JSON_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -148,59 +141,24 @@ public class MessageChannelBinderSupportTests {
|
|||||||
.copyHeaders(Collections.singletonMap(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON))
|
.copyHeaders(Collections.singletonMap(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON))
|
||||||
.build();
|
.build();
|
||||||
MessageValues reconstructed = binder.deserializePayloadIfNecessary(inbound);
|
MessageValues reconstructed = binder.deserializePayloadIfNecessary(inbound);
|
||||||
assertEquals("{\"foo\":\"bar\"}", reconstructed.getPayload());
|
assertThat(reconstructed.getPayload()).isEqualTo("{\"foo\":\"bar\"}");
|
||||||
assertEquals(MimeTypeUtils.APPLICATION_JSON, reconstructed.get(MessageHeaders.CONTENT_TYPE));
|
assertThat(reconstructed.get(MessageHeaders.CONTENT_TYPE)).isEqualTo(MimeTypeUtils.APPLICATION_JSON);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPojoSerialization() {
|
public void testPojoSerialization() {
|
||||||
MessageValues convertedValues = binder.serializePayloadIfNecessary(
|
MessageValues convertedValues = binder.serializePayloadIfNecessary(new GenericMessage<>(new Foo("bar")));
|
||||||
new GenericMessage<Foo>(new Foo("bar")));
|
|
||||||
Message<?> converted = convertedValues.toMessage();
|
Message<?> converted = convertedValues.toMessage();
|
||||||
MimeType mimeType = contentTypeResolver.resolve(converted.getHeaders());
|
MimeType mimeType = contentTypeResolver.resolve(converted.getHeaders());
|
||||||
assertEquals("application", mimeType.getType());
|
assertThat(mimeType.getType()).isEqualTo("application");
|
||||||
assertEquals("x-java-object", mimeType.getSubtype());
|
assertThat(mimeType.getSubtype()).isEqualTo("x-java-object");
|
||||||
assertEquals(Foo.class.getName(), mimeType.getParameter("type"));
|
assertThat(mimeType.getParameter("type")).isEqualTo(Foo.class.getName());
|
||||||
|
|
||||||
MessageValues reconstructed = binder.deserializePayloadIfNecessary(converted);
|
MessageValues reconstructed = binder.deserializePayloadIfNecessary(converted);
|
||||||
assertEquals("bar", ((Foo) reconstructed.getPayload()).getBar());
|
assertThat(((Foo) reconstructed.getPayload()).getBar()).isEqualTo("bar");
|
||||||
assertNull(reconstructed.get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE));
|
assertThat(reconstructed.get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)).isNull();
|
||||||
assertEquals("application/x-java-object;type=org.springframework.cloud.stream.binder.MessageChannelBinderSupportTests$Foo",
|
assertThat(reconstructed.get(MessageHeaders.CONTENT_TYPE)).isEqualTo(
|
||||||
reconstructed.get(MessageHeaders.CONTENT_TYPE));
|
"application/x-java-object;type=org.springframework.cloud.stream.binder.MessageChannelBinderSupportTests$Foo");
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testPojoWithXJavaObjectMimeTypeNoType() {
|
|
||||||
MessageValues convertedValues = binder.serializePayloadIfNecessary(
|
|
||||||
new GenericMessage<Foo>(new Foo("bar")));
|
|
||||||
Message<?> converted = convertedValues.toMessage();
|
|
||||||
MimeType mimeType = contentTypeResolver.resolve(converted.getHeaders());
|
|
||||||
assertEquals("application", mimeType.getType());
|
|
||||||
assertEquals("x-java-object", mimeType.getSubtype());
|
|
||||||
assertEquals(Foo.class.getName(), mimeType.getParameter("type"));
|
|
||||||
|
|
||||||
MessageValues reconstructed = binder.deserializePayloadIfNecessary(converted);
|
|
||||||
assertEquals("bar", ((Foo) reconstructed.getPayload()).getBar());
|
|
||||||
assertNull(reconstructed.get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE));
|
|
||||||
assertEquals("application/x-java-object;type=org.springframework.cloud.stream.binder.MessageChannelBinderSupportTests$Foo",
|
|
||||||
reconstructed.get(MessageHeaders.CONTENT_TYPE));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testPojoWithXJavaObjectMimeTypeExplicitType() {
|
|
||||||
MessageValues convertedValues = binder.serializePayloadIfNecessary(
|
|
||||||
new GenericMessage<Foo>(new Foo("bar")));
|
|
||||||
Message<?> converted = convertedValues.toMessage();
|
|
||||||
MimeType mimeType = contentTypeResolver.resolve(converted.getHeaders());
|
|
||||||
assertEquals("application", mimeType.getType());
|
|
||||||
assertEquals("x-java-object", mimeType.getSubtype());
|
|
||||||
assertEquals(Foo.class.getName(), mimeType.getParameter("type"));
|
|
||||||
|
|
||||||
MessageValues reconstructed = binder.deserializePayloadIfNecessary(converted);
|
|
||||||
assertEquals("bar", ((Foo) reconstructed.getPayload()).getBar());
|
|
||||||
assertNull(reconstructed.get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE));
|
|
||||||
assertEquals("application/x-java-object;type=org.springframework.cloud.stream.binder.MessageChannelBinderSupportTests$Foo",
|
|
||||||
reconstructed.get(MessageHeaders.CONTENT_TYPE));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -209,50 +167,50 @@ public class MessageChannelBinderSupportTests {
|
|||||||
MessageValues convertedValues = binder.serializePayloadIfNecessary(new GenericMessage<>(payload));
|
MessageValues convertedValues = binder.serializePayloadIfNecessary(new GenericMessage<>(payload));
|
||||||
Message<?> converted = convertedValues.toMessage();
|
Message<?> converted = convertedValues.toMessage();
|
||||||
MimeType mimeType = contentTypeResolver.resolve(converted.getHeaders());
|
MimeType mimeType = contentTypeResolver.resolve(converted.getHeaders());
|
||||||
assertEquals("application", mimeType.getType());
|
assertThat(mimeType.getType()).isEqualTo("application");
|
||||||
assertEquals("x-java-object", mimeType.getSubtype());
|
assertThat(mimeType.getSubtype()).isEqualTo("x-java-object");
|
||||||
assertEquals(DefaultTuple.class.getName(), mimeType.getParameter("type"));
|
assertThat(mimeType.getParameter("type")).isEqualTo(DefaultTuple.class.getName());
|
||||||
|
|
||||||
MessageValues reconstructed = binder.deserializePayloadIfNecessary(converted);
|
MessageValues reconstructed = binder.deserializePayloadIfNecessary(converted);
|
||||||
assertEquals("bar", ((Tuple) reconstructed.getPayload()).getString("foo"));
|
assertThat(((Tuple) reconstructed.getPayload()).getString("foo")).isEqualTo("bar");
|
||||||
assertNull(reconstructed.get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE));
|
assertThat(reconstructed.get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)).isNull();
|
||||||
assertEquals("application/x-java-object;type=org.springframework.tuple.DefaultTuple",
|
assertThat(reconstructed.get(MessageHeaders.CONTENT_TYPE))
|
||||||
reconstructed.get(MessageHeaders.CONTENT_TYPE));
|
.isEqualTo("application/x-java-object;type=org.springframework.tuple.DefaultTuple");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mimeTypeIsSimpleObject() throws ClassNotFoundException {
|
public void mimeTypeIsSimpleObject() throws ClassNotFoundException {
|
||||||
MimeType mt = JavaClassMimeTypeConversion.mimeTypeFromObject(new Object());
|
MimeType mt = JavaClassMimeTypeConversion.mimeTypeFromObject(new Object());
|
||||||
String className = JavaClassMimeTypeConversion.classNameFromMimeType(mt);
|
String className = JavaClassMimeTypeConversion.classNameFromMimeType(mt);
|
||||||
assertEquals(Object.class, Class.forName(className));
|
assertThat(Class.forName(className)).isEqualTo(Object.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mimeTypeIsObjectArray() throws ClassNotFoundException {
|
public void mimeTypeIsObjectArray() throws ClassNotFoundException {
|
||||||
MimeType mt = JavaClassMimeTypeConversion.mimeTypeFromObject(new String[0]);
|
MimeType mt = JavaClassMimeTypeConversion.mimeTypeFromObject(new String[0]);
|
||||||
String className = JavaClassMimeTypeConversion.classNameFromMimeType(mt);
|
String className = JavaClassMimeTypeConversion.classNameFromMimeType(mt);
|
||||||
assertEquals(String[].class, Class.forName(className));
|
assertThat(Class.forName(className)).isEqualTo(String[].class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mimeTypeIsMultiDimensionalObjectArray() throws ClassNotFoundException {
|
public void mimeTypeIsMultiDimensionalObjectArray() throws ClassNotFoundException {
|
||||||
MimeType mt = JavaClassMimeTypeConversion.mimeTypeFromObject(new String[0][0][0]);
|
MimeType mt = JavaClassMimeTypeConversion.mimeTypeFromObject(new String[0][0][0]);
|
||||||
String className = JavaClassMimeTypeConversion.classNameFromMimeType(mt);
|
String className = JavaClassMimeTypeConversion.classNameFromMimeType(mt);
|
||||||
assertEquals(String[][][].class, Class.forName(className));
|
assertThat(Class.forName(className)).isEqualTo(String[][][].class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mimeTypeIsPrimitiveArray() throws ClassNotFoundException {
|
public void mimeTypeIsPrimitiveArray() throws ClassNotFoundException {
|
||||||
MimeType mt = JavaClassMimeTypeConversion.mimeTypeFromObject(new int[0]);
|
MimeType mt = JavaClassMimeTypeConversion.mimeTypeFromObject(new int[0]);
|
||||||
String className = JavaClassMimeTypeConversion.classNameFromMimeType(mt);
|
String className = JavaClassMimeTypeConversion.classNameFromMimeType(mt);
|
||||||
assertEquals(int[].class, Class.forName(className));
|
assertThat(Class.forName(className)).isEqualTo(int[].class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mimeTypeIsMultiDimensionalPrimitiveArray() throws ClassNotFoundException {
|
public void mimeTypeIsMultiDimensionalPrimitiveArray() throws ClassNotFoundException {
|
||||||
MimeType mt = JavaClassMimeTypeConversion.mimeTypeFromObject(new int[0][0][0]);
|
MimeType mt = JavaClassMimeTypeConversion.mimeTypeFromObject(new int[0][0][0]);
|
||||||
String className = JavaClassMimeTypeConversion.classNameFromMimeType(mt);
|
String className = JavaClassMimeTypeConversion.classNameFromMimeType(mt);
|
||||||
assertEquals(int[][][].class, Class.forName(className));
|
assertThat(Class.forName(className)).isEqualTo(int[][][].class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Foo {
|
public static class Foo {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>spring-cloud-dependencies-parent</artifactId>
|
<artifactId>spring-cloud-dependencies-parent</artifactId>
|
||||||
|
|||||||
@@ -33,8 +33,7 @@ import org.springframework.messaging.Message;
|
|||||||
import org.springframework.messaging.MessageHeaders;
|
import org.springframework.messaging.MessageHeaders;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Ilayaperumal Gopinathan
|
* @author Ilayaperumal Gopinathan
|
||||||
@@ -56,8 +55,8 @@ public class ContentTypeOutboundSourceTests {
|
|||||||
testSource.output().send(MessageBuilder.withPayload("{\"message\":\"Hi\"}").build());
|
testSource.output().send(MessageBuilder.withPayload("{\"message\":\"Hi\"}").build());
|
||||||
Message<String> received = (Message<String>) ((TestSupportBinder) binderFactory.getBinder(null))
|
Message<String> received = (Message<String>) ((TestSupportBinder) binderFactory.getBinder(null))
|
||||||
.messageCollector().forChannel(testSource.output()).poll();
|
.messageCollector().forChannel(testSource.output()).poll();
|
||||||
assertThat(received.getHeaders().get(MessageHeaders.CONTENT_TYPE).toString(), equalTo("application/json"));
|
assertThat(received.getHeaders().get(MessageHeaders.CONTENT_TYPE).toString()).isEqualTo("application/json");
|
||||||
assertThat(received.getPayload(), equalTo("{\"message\":\"Hi\"}"));
|
assertThat(received).hasFieldOrPropertyWithValue("payload", "{\"message\":\"Hi\"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@EnableBinding(Source.class)
|
@EnableBinding(Source.class)
|
||||||
|
|||||||
@@ -41,12 +41,8 @@ import org.springframework.messaging.MessageHeaders;
|
|||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.util.MimeType;
|
import org.springframework.util.MimeType;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.Matchers.hasItem;
|
|
||||||
import static org.hamcrest.Matchers.isA;
|
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Ilayaperumal Gopinathan
|
* @author Ilayaperumal Gopinathan
|
||||||
@@ -67,16 +63,15 @@ public class CustomMessageConverterTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCustomMessageConverter() throws Exception {
|
public void testCustomMessageConverter() throws Exception {
|
||||||
assertTrue(customMessageConverters.size() == 2);
|
assertThat(customMessageConverters).hasSize(2);
|
||||||
assertThat(customMessageConverters, hasItem(isA(FooToBarConverter.class)));
|
assertThat(customMessageConverters).extracting("class").contains(FooToBarConverter.class,
|
||||||
assertThat(customMessageConverters, hasItem(isA(BarToFooConverter.class)));
|
BarToFooConverter.class);
|
||||||
testSource.output().send(MessageBuilder.withPayload(new Foo("hi")).build());
|
testSource.output().send(MessageBuilder.withPayload(new Foo("hi")).build());
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Message<String> received = (Message<String>) ((TestSupportBinder) binderFactory.getBinder(null))
|
Message<String> received = (Message<String>) ((TestSupportBinder) binderFactory.getBinder(null))
|
||||||
.messageCollector().forChannel(testSource.output()).poll(1, TimeUnit.SECONDS);
|
.messageCollector().forChannel(testSource.output()).poll(1, TimeUnit.SECONDS);
|
||||||
Assert.assertThat(received, notNullValue());
|
Assert.assertThat(received, notNullValue());
|
||||||
assertThat(received.getHeaders().get(MessageHeaders.CONTENT_TYPE).toString(),
|
assertThat(received.getHeaders().get(MessageHeaders.CONTENT_TYPE)).isEqualTo("test/bar");
|
||||||
equalTo("test/bar"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EnableBinding(Source.class)
|
@EnableBinding(Source.class)
|
||||||
|
|||||||
@@ -44,9 +44,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|||||||
import org.springframework.tuple.Tuple;
|
import org.springframework.tuple.Tuple;
|
||||||
import org.springframework.util.MimeTypeUtils;
|
import org.springframework.util.MimeTypeUtils;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Ilayaperumal Gopinathan
|
* @author Ilayaperumal Gopinathan
|
||||||
@@ -71,15 +69,15 @@ public class MessageChannelConfigurerTests {
|
|||||||
MessageHandler messageHandler = new MessageHandler() {
|
MessageHandler messageHandler = new MessageHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message<?> message) throws MessagingException {
|
public void handleMessage(Message<?> message) throws MessagingException {
|
||||||
assertThat(message.getPayload(), instanceOf(Tuple.class));
|
assertThat(message.getPayload()).isInstanceOf(Tuple.class);
|
||||||
assertTrue(((Tuple) message.getPayload()).getFieldNames().get(0).equals("message"));
|
assertThat(((Tuple) message.getPayload()).getFieldNames().get(0)).isEqualTo("message");
|
||||||
assertTrue(((Tuple) message.getPayload()).getValue(0).equals("Hi"));
|
assertThat(((Tuple) message.getPayload()).getValue(0)).isEqualTo("Hi");
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
testSink.input().subscribe(messageHandler);
|
testSink.input().subscribe(messageHandler);
|
||||||
testSink.input().send(MessageBuilder.withPayload("{\"message\":\"Hi\"}").build());
|
testSink.input().send(MessageBuilder.withPayload("{\"message\":\"Hi\"}").build());
|
||||||
assertTrue(latch.await(10, TimeUnit.SECONDS));
|
assertThat(latch.await(10, TimeUnit.SECONDS));
|
||||||
testSink.input().unsubscribe(messageHandler);
|
testSink.input().unsubscribe(messageHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,10 +89,9 @@ public class MessageChannelConfigurerTests {
|
|||||||
DirectFieldAccessor converterAccessor = new DirectFieldAccessor(converter);
|
DirectFieldAccessor converterAccessor = new DirectFieldAccessor(converter);
|
||||||
ObjectMapper objectMapper = (ObjectMapper) converterAccessor.getPropertyValue("objectMapper");
|
ObjectMapper objectMapper = (ObjectMapper) converterAccessor.getPropertyValue("objectMapper");
|
||||||
// assert that the ObjectMapper used by the converters is compliant with the Boot configuration
|
// assert that the ObjectMapper used by the converters is compliant with the Boot configuration
|
||||||
assertTrue("SerializationFeature 'WRITE_DATES_AS_TIMESTAMPS' should be disabled",
|
assertThat(!objectMapper.getSerializationConfig().isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)).withFailMessage("SerializationFeature 'WRITE_DATES_AS_TIMESTAMPS' should be disabled");
|
||||||
!objectMapper.getSerializationConfig().isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS));
|
|
||||||
// assert that the globally set bean is used by the converters
|
// assert that the globally set bean is used by the converters
|
||||||
assertTrue(objectMapper == this.objectMapper);
|
assertThat(objectMapper).isSameAs(this.objectMapper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,16 +43,7 @@ import org.springframework.messaging.handler.annotation.Headers;
|
|||||||
import org.springframework.messaging.handler.annotation.Payload;
|
import org.springframework.messaging.handler.annotation.Payload;
|
||||||
import org.springframework.messaging.handler.annotation.SendTo;
|
import org.springframework.messaging.handler.annotation.SendTo;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.Matchers.hasEntry;
|
|
||||||
import static org.hamcrest.Matchers.hasProperty;
|
|
||||||
import static org.hamcrest.Matchers.hasSize;
|
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
|
||||||
import static org.hamcrest.Matchers.not;
|
|
||||||
import static org.hamcrest.Matchers.nullValue;
|
|
||||||
import static org.hamcrest.Matchers.startsWith;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,42 +60,34 @@ public class StreamListenerTests {
|
|||||||
String id = UUID.randomUUID().toString();
|
String id = UUID.randomUUID().toString();
|
||||||
sink.input().send(MessageBuilder.withPayload("{\"bar\":\"barbar" + id + "\"}")
|
sink.input().send(MessageBuilder.withPayload("{\"bar\":\"barbar" + id + "\"}")
|
||||||
.setHeader("contentType", "application/json").build());
|
.setHeader("contentType", "application/json").build());
|
||||||
assertTrue(testSink.latch.await(10, TimeUnit.SECONDS));
|
assertThat(testSink.latch.await(10, TimeUnit.SECONDS));
|
||||||
assertThat(testSink.receivedArguments, hasSize(1));
|
assertThat(testSink.receivedArguments).hasSize(1);
|
||||||
assertThat(testSink.receivedArguments.get(0),
|
assertThat(testSink.receivedArguments.get(0)).hasFieldOrPropertyWithValue("bar", "barbar" + id);
|
||||||
hasProperty("bar", equalTo("barbar" + id)));
|
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testAnnotatedArguments() throws Exception {
|
public void testAnnotatedArguments() throws Exception {
|
||||||
ConfigurableApplicationContext context = SpringApplication
|
ConfigurableApplicationContext context = SpringApplication.run(TestPojoWithAnnotatedArguments.class,
|
||||||
.run(TestPojoWithAnnotatedArguments.class, "--server.port=0");
|
"--server.port=0");
|
||||||
|
|
||||||
TestPojoWithAnnotatedArguments testPojoWithAnnotatedArguments = context
|
TestPojoWithAnnotatedArguments testPojoWithAnnotatedArguments = context
|
||||||
.getBean(TestPojoWithAnnotatedArguments.class);
|
.getBean(TestPojoWithAnnotatedArguments.class);
|
||||||
Sink sink = context.getBean(Sink.class);
|
Sink sink = context.getBean(Sink.class);
|
||||||
String id = UUID.randomUUID().toString();
|
String id = UUID.randomUUID().toString();
|
||||||
sink.input()
|
sink.input().send(MessageBuilder.withPayload("{\"bar\":\"barbar" + id + "\"}")
|
||||||
.send(MessageBuilder.withPayload("{\"bar\":\"barbar" + id + "\"}")
|
.setHeader("contentType", "application/json").setHeader("testHeader", "testValue").build());
|
||||||
.setHeader("contentType", "application/json")
|
assertThat(testPojoWithAnnotatedArguments.receivedArguments).hasSize(3);
|
||||||
.setHeader("testHeader", "testValue").build());
|
assertThat(testPojoWithAnnotatedArguments.receivedArguments.get(0)).isInstanceOf(FooPojo.class);
|
||||||
assertThat(testPojoWithAnnotatedArguments.receivedArguments, hasSize(3));
|
assertThat(testPojoWithAnnotatedArguments.receivedArguments.get(0)).hasFieldOrPropertyWithValue("bar",
|
||||||
assertThat(testPojoWithAnnotatedArguments.receivedArguments.get(0),
|
"barbar" + id);
|
||||||
instanceOf(FooPojo.class));
|
assertThat(testPojoWithAnnotatedArguments.receivedArguments.get(1)).isInstanceOf(Map.class);
|
||||||
assertThat(testPojoWithAnnotatedArguments.receivedArguments.get(0),
|
assertThat((Map<String, String>) testPojoWithAnnotatedArguments.receivedArguments.get(1))
|
||||||
hasProperty("bar", equalTo("barbar" + id)));
|
.containsEntry(MessageHeaders.CONTENT_TYPE, "application/json");
|
||||||
assertThat(testPojoWithAnnotatedArguments.receivedArguments.get(1),
|
assertThat((Map<String, String>) testPojoWithAnnotatedArguments.receivedArguments.get(1))
|
||||||
instanceOf(Map.class));
|
.containsEntry("testHeader", "testValue");
|
||||||
assertThat(
|
assertThat(testPojoWithAnnotatedArguments.receivedArguments.get(2)).isEqualTo("application/json");
|
||||||
(Map<String, String>) testPojoWithAnnotatedArguments.receivedArguments
|
|
||||||
.get(1),
|
|
||||||
hasEntry(MessageHeaders.CONTENT_TYPE, "application/json"));
|
|
||||||
assertThat((Map<String, String>) testPojoWithAnnotatedArguments.receivedArguments
|
|
||||||
.get(1), hasEntry(equalTo("testHeader"), equalTo("testValue")));
|
|
||||||
assertThat((String) testPojoWithAnnotatedArguments.receivedArguments.get(2),
|
|
||||||
equalTo("application/json"));
|
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,61 +106,49 @@ public class StreamListenerTests {
|
|||||||
.forChannel(processor.output()).poll(1, TimeUnit.SECONDS);
|
.forChannel(processor.output()).poll(1, TimeUnit.SECONDS);
|
||||||
TestStringProcessor testStringProcessor = context
|
TestStringProcessor testStringProcessor = context
|
||||||
.getBean(TestStringProcessor.class);
|
.getBean(TestStringProcessor.class);
|
||||||
assertThat(testStringProcessor.receivedPojos, hasSize(1));
|
assertThat(testStringProcessor.receivedPojos).hasSize(1);
|
||||||
assertThat(testStringProcessor.receivedPojos.get(0),
|
assertThat(testStringProcessor.receivedPojos.get(0)).hasFieldOrPropertyWithValue("bar", "barbar" + id);
|
||||||
hasProperty("bar", equalTo("barbar" + id)));
|
assertThat(message).isNotNull();
|
||||||
assertThat(message, not(nullValue(Message.class)));
|
assertThat(message.getPayload()).isEqualTo("barbar" + id);
|
||||||
assertThat(message.getPayload(), equalTo("barbar" + id));
|
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testReturnConversion() throws Exception {
|
public void testReturnConversion() throws Exception {
|
||||||
ConfigurableApplicationContext context = SpringApplication.run(
|
ConfigurableApplicationContext context = SpringApplication.run(TestPojoWithMimeType.class,
|
||||||
TestPojoWithMimeType.class,
|
"--spring.cloud.stream.bindings.output.contentType=application/json", "--server.port=0");
|
||||||
"--spring.cloud.stream.bindings.output.contentType=application/json",
|
|
||||||
"--server.port=0");
|
|
||||||
MessageCollector collector = context.getBean(MessageCollector.class);
|
MessageCollector collector = context.getBean(MessageCollector.class);
|
||||||
Processor processor = context.getBean(Processor.class);
|
Processor processor = context.getBean(Processor.class);
|
||||||
String id = UUID.randomUUID().toString();
|
String id = UUID.randomUUID().toString();
|
||||||
processor.input()
|
processor.input().send(MessageBuilder.withPayload("{\"bar\":\"barbar" + id + "\"}")
|
||||||
.send(MessageBuilder.withPayload("{\"bar\":\"barbar" + id + "\"}")
|
.setHeader("contentType", "application/json").build());
|
||||||
.setHeader("contentType", "application/json").build());
|
TestPojoWithMimeType testPojoWithMimeType = context.getBean(TestPojoWithMimeType.class);
|
||||||
TestPojoWithMimeType testPojoWithMimeType = context
|
assertThat(testPojoWithMimeType.receivedPojos).hasSize(1);
|
||||||
.getBean(TestPojoWithMimeType.class);
|
assertThat(testPojoWithMimeType.receivedPojos.get(0)).hasFieldOrPropertyWithValue("bar", "barbar" + id);
|
||||||
assertThat(testPojoWithMimeType.receivedPojos, hasSize(1));
|
Message<String> message = (Message<String>) collector.forChannel(processor.output()).poll(1, TimeUnit.SECONDS);
|
||||||
assertThat(testPojoWithMimeType.receivedPojos.get(0),
|
assertThat(message).isNotNull();
|
||||||
hasProperty("bar", equalTo("barbar" + id)));
|
assertThat(message.getPayload()).isEqualTo("{\"qux\":\"barbar" + id + "\"}");
|
||||||
Message<String> message = (Message<String>) collector
|
assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE)).isEqualTo("application/json");
|
||||||
.forChannel(processor.output()).poll(1, TimeUnit.SECONDS);
|
|
||||||
assertThat(message, not(nullValue(Message.class)));
|
|
||||||
assertThat(message.getPayload(), equalTo("{\"qux\":\"barbar" + id + "\"}"));
|
|
||||||
assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE, String.class),
|
|
||||||
equalTo("application/json"));
|
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testReturnNoConversion() throws Exception {
|
public void testReturnNoConversion() throws Exception {
|
||||||
ConfigurableApplicationContext context = SpringApplication
|
ConfigurableApplicationContext context = SpringApplication.run(TestPojoWithMimeType.class, "--server.port=0");
|
||||||
.run(TestPojoWithMimeType.class, "--server.port=0");
|
|
||||||
MessageCollector collector = context.getBean(MessageCollector.class);
|
MessageCollector collector = context.getBean(MessageCollector.class);
|
||||||
Processor processor = context.getBean(Processor.class);
|
Processor processor = context.getBean(Processor.class);
|
||||||
String id = UUID.randomUUID().toString();
|
String id = UUID.randomUUID().toString();
|
||||||
processor.input()
|
processor.input().send(MessageBuilder.withPayload("{\"bar\":\"barbar" + id + "\"}")
|
||||||
.send(MessageBuilder.withPayload("{\"bar\":\"barbar" + id + "\"}")
|
.setHeader("contentType", "application/json").build());
|
||||||
.setHeader("contentType", "application/json").build());
|
TestPojoWithMimeType testPojoWithMimeType = context.getBean(TestPojoWithMimeType.class);
|
||||||
TestPojoWithMimeType testPojoWithMimeType = context
|
assertThat(testPojoWithMimeType.receivedPojos).hasSize(1);
|
||||||
.getBean(TestPojoWithMimeType.class);
|
assertThat(testPojoWithMimeType.receivedPojos.get(0)).hasFieldOrPropertyWithValue("bar", "barbar" + id);
|
||||||
assertThat(testPojoWithMimeType.receivedPojos, hasSize(1));
|
Message<BazPojo> message = (Message<BazPojo>) collector.forChannel(processor.output()).poll(1,
|
||||||
assertThat(testPojoWithMimeType.receivedPojos.get(0),
|
TimeUnit.SECONDS);
|
||||||
hasProperty("bar", equalTo("barbar" + id)));
|
assertThat(message).isNotNull();
|
||||||
Message<BazPojo> message = (Message<BazPojo>) collector
|
assertThat(message.getPayload().getQux()).isEqualTo("barbar" + id);
|
||||||
.forChannel(processor.output()).poll(1, TimeUnit.SECONDS);
|
|
||||||
assertThat(message, not(nullValue(Message.class)));
|
|
||||||
assertThat(message.getPayload().getQux(), equalTo("barbar" + id));
|
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,13 +165,12 @@ public class StreamListenerTests {
|
|||||||
.setHeader("contentType", "application/json").build());
|
.setHeader("contentType", "application/json").build());
|
||||||
TestPojoWithMessageReturn testPojoWithMessageReturn = context
|
TestPojoWithMessageReturn testPojoWithMessageReturn = context
|
||||||
.getBean(TestPojoWithMessageReturn.class);
|
.getBean(TestPojoWithMessageReturn.class);
|
||||||
assertThat(testPojoWithMessageReturn.receivedPojos, hasSize(1));
|
assertThat(testPojoWithMessageReturn.receivedPojos).hasSize(1);
|
||||||
assertThat(testPojoWithMessageReturn.receivedPojos.get(0),
|
assertThat(testPojoWithMessageReturn.receivedPojos.get(0)).hasFieldOrPropertyWithValue("bar", "barbar" + id);
|
||||||
hasProperty("bar", equalTo("barbar" + id)));
|
|
||||||
Message<BazPojo> message = (Message<BazPojo>) collector
|
Message<BazPojo> message = (Message<BazPojo>) collector
|
||||||
.forChannel(processor.output()).poll(1, TimeUnit.SECONDS);
|
.forChannel(processor.output()).poll(1, TimeUnit.SECONDS);
|
||||||
assertThat(message, not(nullValue(Message.class)));
|
assertThat(message).isNotNull();
|
||||||
assertThat(message.getPayload().getQux(), equalTo("barbar" + id));
|
assertThat(message.getPayload().getQux()).isEqualTo("barbar" + id);
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,13 +186,12 @@ public class StreamListenerTests {
|
|||||||
.setHeader("contentType", "text/plain").build());
|
.setHeader("contentType", "text/plain").build());
|
||||||
TestPojoWithMessageArgument testPojoWithMessageArgument = context
|
TestPojoWithMessageArgument testPojoWithMessageArgument = context
|
||||||
.getBean(TestPojoWithMessageArgument.class);
|
.getBean(TestPojoWithMessageArgument.class);
|
||||||
assertThat(testPojoWithMessageArgument.receivedMessages, hasSize(1));
|
assertThat(testPojoWithMessageArgument.receivedMessages).hasSize(1);
|
||||||
assertThat(testPojoWithMessageArgument.receivedMessages.get(0).getPayload(),
|
assertThat(testPojoWithMessageArgument.receivedMessages.get(0).getPayload()).isEqualTo("barbar" + id);
|
||||||
equalTo("barbar" + id));
|
|
||||||
Message<BazPojo> message = (Message<BazPojo>) collector
|
Message<BazPojo> message = (Message<BazPojo>) collector
|
||||||
.forChannel(processor.output()).poll(1, TimeUnit.SECONDS);
|
.forChannel(processor.output()).poll(1, TimeUnit.SECONDS);
|
||||||
assertThat(message, not(nullValue(Message.class)));
|
assertThat(message).isNotNull();
|
||||||
assertThat(message.getPayload().getQux(), equalTo("barbar" + id));
|
assertThat(message.getPayload().getQux()).isEqualTo("barbar" + id);
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,39 +199,32 @@ public class StreamListenerTests {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testDuplicateMapping() throws Exception {
|
public void testDuplicateMapping() throws Exception {
|
||||||
try {
|
try {
|
||||||
ConfigurableApplicationContext context = SpringApplication
|
ConfigurableApplicationContext context = SpringApplication.run(TestDuplicateMapping.class,
|
||||||
.run(TestDuplicateMapping.class, "--server.port=0");
|
"--server.port=0");
|
||||||
fail("Exception expected on duplicate mapping");
|
fail("Exception expected on duplicate mapping");
|
||||||
}
|
}
|
||||||
catch (BeanCreationException e) {
|
catch (BeanCreationException e) {
|
||||||
assertThat(e.getCause().getMessage(),
|
assertThat(e.getCause().getMessage()).startsWith("Duplicate @StreamListener mapping");
|
||||||
startsWith("Duplicate @StreamListener mapping"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testHandlerBean() throws Exception {
|
public void testHandlerBean() throws Exception {
|
||||||
ConfigurableApplicationContext context = SpringApplication.run(
|
ConfigurableApplicationContext context = SpringApplication.run(TestHandlerBean.class,
|
||||||
TestHandlerBean.class,
|
"--spring.cloud.stream.bindings.output.contentType=application/json", "--server.port=0");
|
||||||
"--spring.cloud.stream.bindings.output.contentType=application/json",
|
|
||||||
"--server.port=0");
|
|
||||||
MessageCollector collector = context.getBean(MessageCollector.class);
|
MessageCollector collector = context.getBean(MessageCollector.class);
|
||||||
Processor processor = context.getBean(Processor.class);
|
Processor processor = context.getBean(Processor.class);
|
||||||
String id = UUID.randomUUID().toString();
|
String id = UUID.randomUUID().toString();
|
||||||
processor.input()
|
processor.input().send(MessageBuilder.withPayload("{\"bar\":\"barbar" + id + "\"}")
|
||||||
.send(MessageBuilder.withPayload("{\"bar\":\"barbar" + id + "\"}")
|
.setHeader("contentType", "application/json").build());
|
||||||
.setHeader("contentType", "application/json").build());
|
|
||||||
HandlerBean handlerBean = context.getBean(HandlerBean.class);
|
HandlerBean handlerBean = context.getBean(HandlerBean.class);
|
||||||
assertThat(handlerBean.receivedPojos, hasSize(1));
|
assertThat(handlerBean.receivedPojos).hasSize(1);
|
||||||
assertThat(handlerBean.receivedPojos.get(0),
|
assertThat(handlerBean.receivedPojos.get(0)).hasFieldOrPropertyWithValue("bar", "barbar" + id);
|
||||||
hasProperty("bar", equalTo("barbar" + id)));
|
Message<String> message = (Message<String>) collector.forChannel(processor.output()).poll(1, TimeUnit.SECONDS);
|
||||||
Message<String> message = (Message<String>) collector
|
assertThat(message).isNotNull();
|
||||||
.forChannel(processor.output()).poll(1, TimeUnit.SECONDS);
|
assertThat(message.getPayload()).isEqualTo("{\"qux\":\"barbar" + id + "\"}");
|
||||||
assertThat(message, not(nullValue(Message.class)));
|
assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE)).isEqualTo("application/json");
|
||||||
assertThat(message.getPayload(), equalTo("{\"qux\":\"barbar" + id + "\"}"));
|
|
||||||
assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE, String.class),
|
|
||||||
equalTo("application/json"));
|
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,7 @@ import org.springframework.messaging.support.GenericMessage;
|
|||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration test that validates that {@link org.springframework.cloud.stream.test.binder.TestSupportBinder} applies
|
* Integration test that validates that {@link org.springframework.cloud.stream.test.binder.TestSupportBinder} applies
|
||||||
@@ -48,23 +47,23 @@ import static org.junit.Assert.assertThat;
|
|||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class ExampleTest {
|
public class ExampleTest {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
@Bindings(MyProcessor.class)
|
|
||||||
private Processor processor;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private BinderFactory<MessageChannel> binderFactory;
|
private BinderFactory<MessageChannel> binderFactory;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MessageCollector messageCollector;
|
private MessageCollector messageCollector;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Bindings(MyProcessor.class)
|
||||||
|
private Processor processor;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testWiring() {
|
public void testWiring() {
|
||||||
Message<String> message = new GenericMessage<>("hello");
|
Message<String> message = new GenericMessage<>("hello");
|
||||||
processor.input().send(message);
|
this.processor.input().send(message);
|
||||||
Message<String> received = (Message<String>) messageCollector.forChannel(processor.output()).poll();
|
Message<String> received = (Message<String>) this.messageCollector.forChannel(this.processor.output()).poll();
|
||||||
assertThat(received.getPayload(), equalTo("hello world"));
|
assertThat(received.getPayload()).isEqualTo("hello world");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -72,9 +71,6 @@ public class ExampleTest {
|
|||||||
@EnableBinding(Processor.class)
|
@EnableBinding(Processor.class)
|
||||||
public static class MyProcessor {
|
public static class MyProcessor {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private Processor channels;
|
|
||||||
|
|
||||||
@Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
|
@Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
|
||||||
public String transform(String in) {
|
public String transform(String in) {
|
||||||
return in + " world";
|
return in + " world";
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ import org.junit.Test;
|
|||||||
import org.springframework.messaging.Message;
|
import org.springframework.messaging.Message;
|
||||||
import org.springframework.messaging.support.GenericMessage;
|
import org.springframework.messaging.support.GenericMessage;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for MessageQueueMatcher.
|
* Tests for MessageQueueMatcher.
|
||||||
@@ -44,71 +44,64 @@ public class MessageQueueMatcherTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testTimeout() {
|
public void testTimeout() {
|
||||||
Message<?> msg = new GenericMessage<>("hello");
|
Message<?> msg = new GenericMessage<>("hello");
|
||||||
MessageQueueMatcher<?> matcher = MessageQueueMatcher.receivesMessageThat(is(msg)).within(2, TimeUnit.MILLISECONDS);
|
MessageQueueMatcher<?> matcher = MessageQueueMatcher.receivesMessageThat(is(msg)).within(2,
|
||||||
|
TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
boolean result = matcher.matches(queue);
|
boolean result = matcher.matches(this.queue);
|
||||||
assertThat(result, is(false));
|
assertThat(result).isFalse();
|
||||||
matcher.describeMismatch(queue, description);
|
matcher.describeMismatch(this.queue, this.description);
|
||||||
assertThat(description.toString(), is("timed out after 2 milliseconds"));
|
assertThat(this.description.toString()).isEqualTo("timed out after 2 milliseconds");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMatch() {
|
public void testMatch() {
|
||||||
Message<?> msg = new GenericMessage<>("hello");
|
Message<?> msg = new GenericMessage<>("hello");
|
||||||
MessageQueueMatcher<?> matcher = MessageQueueMatcher.receivesMessageThat(is(msg));
|
MessageQueueMatcher<?> matcher = MessageQueueMatcher.receivesMessageThat(is(msg));
|
||||||
|
this.queue.offer(msg);
|
||||||
queue.offer(msg);
|
boolean result = matcher.matches(this.queue);
|
||||||
|
assertThat(result).isTrue();
|
||||||
boolean result = matcher.matches(queue);
|
|
||||||
assertThat(result, is(true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMisMatch() {
|
public void testMismatch() {
|
||||||
Message<?> msg = new GenericMessage<>("hello");
|
Message<?> msg = new GenericMessage<>("hello");
|
||||||
Message<?> other = new GenericMessage<>("world");
|
Message<?> other = new GenericMessage<>("world");
|
||||||
|
|
||||||
MessageQueueMatcher<?> matcher = MessageQueueMatcher.receivesMessageThat(is(msg));
|
MessageQueueMatcher<?> matcher = MessageQueueMatcher.receivesMessageThat(is(msg));
|
||||||
|
this.queue.offer(other);
|
||||||
queue.offer(other);
|
boolean result = matcher.matches(this.queue);
|
||||||
|
assertThat(result).isFalse();
|
||||||
boolean result = matcher.matches(queue);
|
matcher.describeMismatch(this.queue, this.description);
|
||||||
assertThat(result, is(false));
|
assertThat(this.description.toString()).isEqualTo(("received: <" + other + ">"));
|
||||||
matcher.describeMismatch(queue, description);
|
|
||||||
assertThat(description.toString(), is("received: <" + other + ">"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExtractor() {
|
public void testExtractor() {
|
||||||
Message<?> msg = new GenericMessage<>("hello", Collections.singletonMap("foo", (Object) "bar"));
|
Message<?> msg = new GenericMessage<>("hello", Collections.singletonMap("foo", (Object) "bar"));
|
||||||
|
|
||||||
MessageQueueMatcher.Extractor<Message<?>, String> headerExtractor = new MessageQueueMatcher.Extractor<Message<?>, String>("whose 'foo' header") {
|
MessageQueueMatcher.Extractor<Message<?>, String> headerExtractor = new MessageQueueMatcher.Extractor<Message<?>, String>(
|
||||||
|
"whose 'foo' header") {
|
||||||
@Override
|
@Override
|
||||||
public String apply(Message<?> message) {
|
public String apply(Message<?> message) {
|
||||||
return message.getHeaders().get("foo", String.class);
|
return message.getHeaders().get("foo", String.class);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MessageQueueMatcher<?> matcher = new MessageQueueMatcher<>(is("bar"), -1, null, headerExtractor);
|
MessageQueueMatcher<?> matcher = new MessageQueueMatcher<>(is("bar"), -1, null, headerExtractor);
|
||||||
queue.offer(msg);
|
this.queue.offer(msg);
|
||||||
boolean result = matcher.matches(queue);
|
boolean result = matcher.matches(this.queue);
|
||||||
assertThat(result, is(true));
|
assertThat(result);
|
||||||
|
|
||||||
matcher = new MessageQueueMatcher<>(is("wizz"), -1, null, headerExtractor);
|
matcher = new MessageQueueMatcher<>(is("wizz"), -1, null, headerExtractor);
|
||||||
queue.offer(msg);
|
this.queue.offer(msg);
|
||||||
result = matcher.matches(queue);
|
result = matcher.matches(this.queue);
|
||||||
assertThat(result, is(false));
|
assertThat(result).isFalse();
|
||||||
matcher.describeMismatch(queue, description);
|
matcher.describeMismatch(this.queue, this.description);
|
||||||
assertThat(description.toString(), is("received: \"bar\""));
|
assertThat(this.description.toString()).isEqualTo(("received: \"bar\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDescription() {
|
public void testDescription() {
|
||||||
Message<?> msg = new GenericMessage<>("hello");
|
Message<?> msg = new GenericMessage<>("hello");
|
||||||
|
|
||||||
MessageQueueMatcher<?> matcher = MessageQueueMatcher.receivesMessageThat(is(msg));
|
MessageQueueMatcher<?> matcher = MessageQueueMatcher.receivesMessageThat(is(msg));
|
||||||
|
this.description.appendDescriptionOf(matcher);
|
||||||
description.appendDescriptionOf(matcher);
|
assertThat(this.description.toString()).isEqualTo(("Channel to receive a message that is <" + msg + ">"));
|
||||||
assertThat(description.toString(), is("Channel to receive a message that is <" + msg + ">"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,10 +29,7 @@ import org.springframework.cloud.stream.utils.MockBinderRegistryConfiguration;
|
|||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.messaging.MessageChannel;
|
import org.springframework.messaging.MessageChannel;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.hasSize;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Marius Bogoevici
|
* @author Marius Bogoevici
|
||||||
@@ -49,8 +46,8 @@ public class ModuleAggregationTest {
|
|||||||
.run();
|
.run();
|
||||||
SharedChannelRegistry sharedChannelRegistry = aggregatedApplicationContext.getBean(SharedChannelRegistry.class);
|
SharedChannelRegistry sharedChannelRegistry = aggregatedApplicationContext.getBean(SharedChannelRegistry.class);
|
||||||
BindableChannelFactory channelFactory = aggregatedApplicationContext.getBean(BindableChannelFactory.class);
|
BindableChannelFactory channelFactory = aggregatedApplicationContext.getBean(BindableChannelFactory.class);
|
||||||
assertNotNull(channelFactory);
|
assertThat(channelFactory).isNotNull();
|
||||||
assertThat(sharedChannelRegistry.getAll().keySet(), hasSize(2));
|
assertThat(sharedChannelRegistry.getAll().keySet()).hasSize(2);
|
||||||
aggregatedApplicationContext.close();
|
aggregatedApplicationContext.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,13 +64,13 @@ public class ModuleAggregationTest {
|
|||||||
BindableChannelFactory channelFactory
|
BindableChannelFactory channelFactory
|
||||||
= aggregatedApplicationContext.getBean(BindableChannelFactory.class);
|
= aggregatedApplicationContext.getBean(BindableChannelFactory.class);
|
||||||
Object fooOutput = sharedChannelRegistry.get("foo.output");
|
Object fooOutput = sharedChannelRegistry.get("foo.output");
|
||||||
assertNotNull(fooOutput);
|
assertThat(fooOutput).isNotNull();
|
||||||
assertThat(fooOutput, instanceOf(MessageChannel.class));
|
assertThat(fooOutput).isInstanceOf(MessageChannel.class);
|
||||||
Object barInput = sharedChannelRegistry.get("bar.input");
|
Object barInput = sharedChannelRegistry.get("bar.input");
|
||||||
assertNotNull(barInput);
|
assertThat(barInput).isNotNull();
|
||||||
assertThat(barInput, instanceOf(MessageChannel.class));
|
assertThat(barInput).isInstanceOf(MessageChannel.class);
|
||||||
assertNotNull(channelFactory);
|
assertThat(channelFactory).isNotNull();
|
||||||
assertThat(sharedChannelRegistry.getAll().keySet(), hasSize(2));
|
assertThat(sharedChannelRegistry.getAll().keySet()).hasSize(2);
|
||||||
aggregatedApplicationContext.close();
|
aggregatedApplicationContext.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,11 +55,7 @@ import org.springframework.messaging.MessagingException;
|
|||||||
import org.springframework.messaging.SubscribableChannel;
|
import org.springframework.messaging.SubscribableChannel;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.hasSize;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertSame;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
@@ -101,7 +97,7 @@ public class BinderAwareChannelResolverTests {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.channelBindingServiceProperties = new ChannelBindingServiceProperties();
|
this.channelBindingServiceProperties = new ChannelBindingServiceProperties();
|
||||||
Map<String, BindingProperties> bindings = new HashMap<String, BindingProperties>();
|
Map<String, BindingProperties> bindings = new HashMap<>();
|
||||||
BindingProperties bindingProperties = new BindingProperties();
|
BindingProperties bindingProperties = new BindingProperties();
|
||||||
bindingProperties.setContentType("text/plain");
|
bindingProperties.setContentType("text/plain");
|
||||||
bindings.put("foo", bindingProperties);
|
bindings.put("foo", bindingProperties);
|
||||||
@@ -130,11 +126,11 @@ public class BinderAwareChannelResolverTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveChannel() {
|
public void resolveChannel() {
|
||||||
assertThat(producerBindings, hasSize(0));
|
assertThat(producerBindings).hasSize(0);
|
||||||
MessageChannel registered = resolver.resolveDestination("foo");
|
MessageChannel registered = resolver.resolveDestination("foo");
|
||||||
assertThat(producerBindings, hasSize(1));
|
assertThat(producerBindings).hasSize(1);
|
||||||
TestBinder.TestBinding binding = producerBindings.get(0);
|
TestBinder.TestBinding binding = producerBindings.get(0);
|
||||||
assertTrue("Must be bound", binding.isBound());
|
assertThat(binding.isBound()).describedAs("Must be bound");
|
||||||
DirectChannel testChannel = new DirectChannel();
|
DirectChannel testChannel = new DirectChannel();
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
final List<Message<?>> received = new ArrayList<>();
|
final List<Message<?>> received = new ArrayList<>();
|
||||||
@@ -147,26 +143,26 @@ public class BinderAwareChannelResolverTests {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
binder.bindConsumer("foo", null, testChannel, new ConsumerProperties());
|
binder.bindConsumer("foo", null, testChannel, new ConsumerProperties());
|
||||||
assertEquals(0, received.size());
|
assertThat(received).hasSize(0);
|
||||||
registered.send(MessageBuilder.withPayload("hello").build());
|
registered.send(MessageBuilder.withPayload("hello").build());
|
||||||
try {
|
try {
|
||||||
assertTrue("latch timed out", latch.await(1, TimeUnit.SECONDS));
|
assertThat(latch.await(1, TimeUnit.SECONDS)).describedAs("Latch timed out");
|
||||||
}
|
}
|
||||||
catch (InterruptedException e) {
|
catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
fail("interrupted while awaiting latch");
|
fail("interrupted while awaiting latch");
|
||||||
}
|
}
|
||||||
assertEquals(1, received.size());
|
assertThat(received).hasSize(1);
|
||||||
assertEquals("hello", received.get(0).getPayload());
|
assertThat(received.get(0).getPayload()).isEqualTo("hello");
|
||||||
context.close();
|
context.close();
|
||||||
assertThat(producerBindings, hasSize(1));
|
assertThat(producerBindings).hasSize(1);
|
||||||
assertTrue("Must not be bound", !binding.isBound());
|
assertThat(binding.isBound()).isFalse().describedAs("Must not be bound");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resolveNonRegisteredChannel() {
|
public void resolveNonRegisteredChannel() {
|
||||||
MessageChannel other = resolver.resolveDestination("other");
|
MessageChannel other = resolver.resolveDestination("other");
|
||||||
assertSame(context.getBean("other"), other);
|
assertThat(context.getBean("other")).isSameAs(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -201,7 +197,7 @@ public class BinderAwareChannelResolverTests {
|
|||||||
Assert.isTrue(dataTypes.length == 1, "Data type must be set for the Foo Channel");
|
Assert.isTrue(dataTypes.length == 1, "Data type must be set for the Foo Channel");
|
||||||
Assert.isTrue(dataTypes[0].equals(String.class), "Data type should be of type String");
|
Assert.isTrue(dataTypes[0].equals(String.class), "Data type should be of type String");
|
||||||
verify(binder).bindProducer(eq("foo"), any(MessageChannel.class), any(ProducerProperties.class));
|
verify(binder).bindProducer(eq("foo"), any(MessageChannel.class), any(ProducerProperties.class));
|
||||||
assertSame(resolved, beanFactory.getBean("foo"));
|
assertThat(resolved).isSameAs(beanFactory.getBean("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -38,17 +38,7 @@ import org.springframework.core.io.ClassPathResource;
|
|||||||
import org.springframework.core.io.DefaultResourceLoader;
|
import org.springframework.core.io.DefaultResourceLoader;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.arrayContaining;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
|
||||||
import static org.hamcrest.Matchers.hasKey;
|
|
||||||
import static org.hamcrest.Matchers.hasProperty;
|
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
|
||||||
import static org.hamcrest.Matchers.is;
|
|
||||||
import static org.hamcrest.Matchers.isEmptyOrNullString;
|
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -59,16 +49,12 @@ public class BinderFactoryConfigurationTests {
|
|||||||
@Test
|
@Test
|
||||||
public void loadBinderTypeRegistry() throws Exception {
|
public void loadBinderTypeRegistry() throws Exception {
|
||||||
try {
|
try {
|
||||||
ConfigurableApplicationContext context = createBinderTestContext(
|
createBinderTestContext(new String[] {});
|
||||||
new String[] {});
|
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
catch (BeanCreationException e) {
|
catch (BeanCreationException e) {
|
||||||
assertThat(e.getMessage(),
|
assertThat(e.getMessage()).contains(
|
||||||
containsString(
|
"Cannot create binder factory, no `META-INF/spring.binders` resources found on the classpath");
|
||||||
"Cannot create binder factory, no `META-INF/spring.binders` "
|
|
||||||
+
|
|
||||||
"resources found on the classpath"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,19 +64,19 @@ public class BinderFactoryConfigurationTests {
|
|||||||
new String[] {"binder1"});
|
new String[] {"binder1"});
|
||||||
|
|
||||||
BinderTypeRegistry binderTypeRegistry = context.getBean(BinderTypeRegistry.class);
|
BinderTypeRegistry binderTypeRegistry = context.getBean(BinderTypeRegistry.class);
|
||||||
assertThat(binderTypeRegistry, notNullValue());
|
assertThat(binderTypeRegistry).isNotNull();
|
||||||
assertThat(binderTypeRegistry.getAll().size(), equalTo(1));
|
assertThat(binderTypeRegistry.getAll()).hasSize(1);
|
||||||
assertThat(binderTypeRegistry.getAll(), hasKey("binder1"));
|
assertThat(binderTypeRegistry.getAll()).containsKey("binder1");
|
||||||
assertThat(binderTypeRegistry.get("binder1"),
|
assertThat((Class[]) binderTypeRegistry.get("binder1").getConfigurationClasses())
|
||||||
hasProperty("configurationClasses", arrayContaining(StubBinder1Configuration.class)));
|
.containsExactlyInAnyOrder(StubBinder1Configuration.class);
|
||||||
|
|
||||||
BinderFactory binderFactory = context.getBean(BinderFactory.class);
|
BinderFactory binderFactory = context.getBean(BinderFactory.class);
|
||||||
|
|
||||||
Binder binder1 = binderFactory.getBinder("binder1");
|
Binder binder1 = binderFactory.getBinder("binder1");
|
||||||
assertThat(binder1, instanceOf(StubBinder1.class));
|
assertThat(binder1).isInstanceOf(StubBinder1.class);
|
||||||
|
|
||||||
Binder defaultBinder = binderFactory.getBinder(null);
|
Binder defaultBinder = binderFactory.getBinder(null);
|
||||||
assertThat(defaultBinder, is(binder1));
|
assertThat(defaultBinder).isSameAs(binder1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -101,7 +87,7 @@ public class BinderFactoryConfigurationTests {
|
|||||||
BinderFactory binderFactory = context.getBean(BinderFactory.class);
|
BinderFactory binderFactory = context.getBean(BinderFactory.class);
|
||||||
|
|
||||||
Binder binder1 = binderFactory.getBinder("binder1");
|
Binder binder1 = binderFactory.getBinder("binder1");
|
||||||
assertThat(((StubBinder1) binder1).getName(), is(equalTo("foo")));
|
assertThat(binder1).hasFieldOrPropertyWithValue("name", "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -114,7 +100,7 @@ public class BinderFactoryConfigurationTests {
|
|||||||
BinderFactory binderFactory = context.getBean(BinderFactory.class);
|
BinderFactory binderFactory = context.getBean(BinderFactory.class);
|
||||||
|
|
||||||
Binder binder1 = binderFactory.getBinder("custom");
|
Binder binder1 = binderFactory.getBinder("custom");
|
||||||
assertThat(((StubBinder1) binder1).getName(), is(equalTo("foo")));
|
assertThat(binder1).hasFieldOrPropertyWithValue("name", "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -128,23 +114,20 @@ public class BinderFactoryConfigurationTests {
|
|||||||
BinderFactory binderFactory = context.getBean(BinderFactory.class);
|
BinderFactory binderFactory = context.getBean(BinderFactory.class);
|
||||||
|
|
||||||
Binder binder1 = binderFactory.getBinder("custom");
|
Binder binder1 = binderFactory.getBinder("custom");
|
||||||
assertThat(((StubBinder1) binder1).getName(), isEmptyOrNullString());
|
assertThat(binder1).hasFieldOrPropertyWithValue("name", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void loadBinderTypeRegistryWithTwoBinders() throws Exception {
|
public void loadBinderTypeRegistryWithTwoBinders() throws Exception {
|
||||||
|
ConfigurableApplicationContext context = createBinderTestContext(new String[] { "binder1", "binder2" });
|
||||||
ConfigurableApplicationContext context = createBinderTestContext(
|
|
||||||
new String[] { "binder1", "binder2" });
|
|
||||||
BinderTypeRegistry binderTypeRegistry = context.getBean(BinderTypeRegistry.class);
|
BinderTypeRegistry binderTypeRegistry = context.getBean(BinderTypeRegistry.class);
|
||||||
assertThat(binderTypeRegistry, notNullValue());
|
assertThat(binderTypeRegistry).isNotNull();
|
||||||
assertThat(binderTypeRegistry.getAll().size(), equalTo(2));
|
assertThat(binderTypeRegistry.getAll()).hasSize(2);
|
||||||
assertThat(binderTypeRegistry.getAll().keySet(), containsInAnyOrder("binder1", "binder2"));
|
assertThat(binderTypeRegistry.getAll()).containsOnlyKeys("binder1", "binder2");
|
||||||
assertThat(binderTypeRegistry.get("binder1"),
|
assertThat((Class[]) binderTypeRegistry.get("binder1").getConfigurationClasses())
|
||||||
hasProperty("configurationClasses", arrayContaining(StubBinder1Configuration.class)));
|
.containsExactly(StubBinder1Configuration.class);
|
||||||
assertThat(binderTypeRegistry.get("binder2"),
|
assertThat((Class[]) binderTypeRegistry.get("binder2").getConfigurationClasses())
|
||||||
hasProperty("configurationClasses", arrayContaining(StubBinder2ConfigurationA.class,
|
.containsExactlyInAnyOrder(StubBinder2ConfigurationA.class, StubBinder2ConfigurationB.class);
|
||||||
StubBinder2ConfigurationB.class)));
|
|
||||||
|
|
||||||
BinderFactory binderFactory = context.getBean(BinderFactory.class);
|
BinderFactory binderFactory = context.getBean(BinderFactory.class);
|
||||||
|
|
||||||
@@ -153,15 +136,15 @@ public class BinderFactoryConfigurationTests {
|
|||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
assertThat(e, instanceOf(IllegalStateException.class));
|
assertThat(e).isInstanceOf(IllegalStateException.class);
|
||||||
assertThat(e.getMessage(), containsString("A default binder has been requested, but there is more than " +
|
assertThat(e.getMessage()).contains(
|
||||||
"one binder available:"));
|
"A default binder has been requested, but there is more than one binder available:");
|
||||||
}
|
}
|
||||||
|
|
||||||
Binder binder1 = binderFactory.getBinder("binder1");
|
Binder binder1 = binderFactory.getBinder("binder1");
|
||||||
assertThat(binder1, instanceOf(StubBinder1.class));
|
assertThat(binder1).isInstanceOf(StubBinder1.class);
|
||||||
Binder binder2 = binderFactory.getBinder("binder2");
|
Binder binder2 = binderFactory.getBinder("binder2");
|
||||||
assertThat(binder2, instanceOf(StubBinder2.class));
|
assertThat(binder2).isInstanceOf(StubBinder2.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -172,27 +155,26 @@ public class BinderFactoryConfigurationTests {
|
|||||||
new String[] { "binder1", "binder2" },
|
new String[] { "binder1", "binder2" },
|
||||||
"spring.cloud.stream.defaultBinder:binder2");
|
"spring.cloud.stream.defaultBinder:binder2");
|
||||||
BinderTypeRegistry binderTypeRegistry = context.getBean(BinderTypeRegistry.class);
|
BinderTypeRegistry binderTypeRegistry = context.getBean(BinderTypeRegistry.class);
|
||||||
assertThat(binderTypeRegistry, notNullValue());
|
assertThat(binderTypeRegistry).isNotNull();
|
||||||
assertThat(binderTypeRegistry.getAll().size(), equalTo(2));
|
assertThat(binderTypeRegistry.getAll()).hasSize(2);
|
||||||
assertThat(binderTypeRegistry.getAll().keySet(), containsInAnyOrder("binder1", "binder2"));
|
assertThat(binderTypeRegistry.getAll()).containsOnlyKeys("binder1", "binder2");
|
||||||
assertThat(binderTypeRegistry.get("binder1"),
|
assertThat((Class[]) binderTypeRegistry.get("binder1").getConfigurationClasses())
|
||||||
hasProperty("configurationClasses", arrayContaining(StubBinder1Configuration.class)));
|
.containsExactlyInAnyOrder(StubBinder1Configuration.class);
|
||||||
assertThat(binderTypeRegistry.get("binder2"),
|
assertThat((Class[]) binderTypeRegistry.get("binder2").getConfigurationClasses())
|
||||||
hasProperty("configurationClasses", arrayContaining(StubBinder2ConfigurationA.class,
|
.containsExactlyInAnyOrder(StubBinder2ConfigurationA.class, StubBinder2ConfigurationB.class);
|
||||||
StubBinder2ConfigurationB.class)));
|
|
||||||
|
|
||||||
BinderFactory binderFactory = context.getBean(BinderFactory.class);
|
BinderFactory binderFactory = context.getBean(BinderFactory.class);
|
||||||
|
|
||||||
Binder binder1 = binderFactory.getBinder("binder1");
|
Binder binder1 = binderFactory.getBinder("binder1");
|
||||||
assertThat(binder1, instanceOf(StubBinder1.class));
|
assertThat(binder1).isInstanceOf(StubBinder1.class);
|
||||||
Binder binder2 = binderFactory.getBinder("binder2");
|
Binder binder2 = binderFactory.getBinder("binder2");
|
||||||
assertThat(binder2, instanceOf(StubBinder2.class));
|
assertThat(binder2).isInstanceOf(StubBinder2.class);
|
||||||
|
|
||||||
Binder defaultBinder = binderFactory.getBinder(null);
|
Binder defaultBinder = binderFactory.getBinder(null);
|
||||||
assertThat(defaultBinder, is(binder2));
|
assertThat(defaultBinder).isSameAs(binder2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConfigurableApplicationContext createBinderTestContext(String[] additionalClasspathDirectories,
|
private static ConfigurableApplicationContext createBinderTestContext(String[] additionalClasspathDirectories,
|
||||||
String... properties) throws IOException {
|
String... properties) throws IOException {
|
||||||
URL[] urls = ObjectUtils.isEmpty(additionalClasspathDirectories) ?
|
URL[] urls = ObjectUtils.isEmpty(additionalClasspathDirectories) ?
|
||||||
new URL[0] : new URL[additionalClasspathDirectories.length];
|
new URL[0] : new URL[additionalClasspathDirectories.length];
|
||||||
|
|||||||
@@ -49,10 +49,7 @@ import org.springframework.messaging.MessageHandler;
|
|||||||
import org.springframework.messaging.MessagingException;
|
import org.springframework.messaging.MessagingException;
|
||||||
import org.springframework.messaging.SubscribableChannel;
|
import org.springframework.messaging.SubscribableChannel;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.hasSize;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,11 +107,11 @@ public class ExtendedPropertiesBinderAwareChannelResolverTests extends BinderAwa
|
|||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void resolveChannel() {
|
public void resolveChannel() {
|
||||||
assertThat(producerBindings, hasSize(0));
|
assertThat(producerBindings).hasSize(0);
|
||||||
MessageChannel registered = resolver.resolveDestination("foo");
|
MessageChannel registered = resolver.resolveDestination("foo");
|
||||||
assertThat(producerBindings, hasSize(1));
|
assertThat(producerBindings).hasSize(1);
|
||||||
TestBinder.TestBinding binding = producerBindings.get(0);
|
TestBinder.TestBinding binding = producerBindings.get(0);
|
||||||
assertTrue("Must be bound", binding.isBound());
|
assertThat(binding.isBound()).describedAs("Must be bound");
|
||||||
DirectChannel testChannel = new DirectChannel();
|
DirectChannel testChannel = new DirectChannel();
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
final List<Message<?>> received = new ArrayList<>();
|
final List<Message<?>> received = new ArrayList<>();
|
||||||
@@ -127,20 +124,20 @@ public class ExtendedPropertiesBinderAwareChannelResolverTests extends BinderAwa
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
binder.bindConsumer("foo", null, testChannel, new ExtendedConsumerProperties(new ConsumerProperties()));
|
binder.bindConsumer("foo", null, testChannel, new ExtendedConsumerProperties(new ConsumerProperties()));
|
||||||
assertEquals(0, received.size());
|
assertThat(received).hasSize(0);
|
||||||
registered.send(MessageBuilder.withPayload("hello").build());
|
registered.send(MessageBuilder.withPayload("hello").build());
|
||||||
try {
|
try {
|
||||||
assertTrue("latch timed out", latch.await(1, TimeUnit.SECONDS));
|
assertThat(latch.await(1, TimeUnit.SECONDS)).describedAs("latch timed out");
|
||||||
}
|
}
|
||||||
catch (InterruptedException e) {
|
catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
fail("interrupted while awaiting latch");
|
fail("interrupted while awaiting latch");
|
||||||
}
|
}
|
||||||
assertEquals(1, received.size());
|
assertThat(received).hasSize(1);
|
||||||
assertEquals("hello", received.get(0).getPayload());
|
assertThat(received.get(0).getPayload()).isEqualTo("hello");
|
||||||
context.close();
|
context.close();
|
||||||
assertThat(producerBindings, hasSize(1));
|
assertThat(producerBindings).hasSize(1);
|
||||||
assertTrue("Must not be bound", !binding.isBound());
|
assertThat(binding.isBound()).isFalse().describedAs("Must not be bound");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ import java.net.URL;
|
|||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hamcrest.CoreMatchers;
|
|
||||||
import org.hamcrest.collection.IsMapContaining;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.DirectFieldAccessor;
|
import org.springframework.beans.DirectFieldAccessor;
|
||||||
@@ -43,9 +41,7 @@ import org.springframework.core.io.ClassPathResource;
|
|||||||
import org.springframework.core.io.DefaultResourceLoader;
|
import org.springframework.core.io.DefaultResourceLoader;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,34 +52,25 @@ public class HealthIndicatorsConfigurationTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void healthIndicatorsCheck() throws Exception {
|
public void healthIndicatorsCheck() throws Exception {
|
||||||
ConfigurableApplicationContext context = createBinderTestContext(
|
ConfigurableApplicationContext context = createBinderTestContext(new String[] { "binder1", "binder2" },
|
||||||
new String[] { "binder1", "binder2" },
|
|
||||||
"spring.cloud.stream.defaultBinder:binder2");
|
"spring.cloud.stream.defaultBinder:binder2");
|
||||||
|
|
||||||
Binder binder1 = context.getBean(BinderFactory.class).getBinder("binder1");
|
Binder binder1 = context.getBean(BinderFactory.class).getBinder("binder1");
|
||||||
assertThat(binder1, instanceOf(StubBinder1.class));
|
assertThat(binder1).isInstanceOf(StubBinder1.class);
|
||||||
Binder binder2 = context.getBean(BinderFactory.class).getBinder("binder2");
|
Binder binder2 = context.getBean(BinderFactory.class).getBinder("binder2");
|
||||||
assertThat(binder2, instanceOf(StubBinder2.class));
|
assertThat(binder2).isInstanceOf(StubBinder2.class);
|
||||||
|
CompositeHealthIndicator bindersHealthIndicator = context.getBean("bindersHealthIndicator",
|
||||||
CompositeHealthIndicator bindersHealthIndicator = context
|
CompositeHealthIndicator.class);
|
||||||
.getBean("bindersHealthIndicator", CompositeHealthIndicator.class);
|
DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(bindersHealthIndicator);
|
||||||
|
assertThat(bindersHealthIndicator).isNotNull();
|
||||||
DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(
|
assertThat(context.getBean("testHealthIndicator1", CompositeHealthIndicator.class)).isNotNull();
|
||||||
bindersHealthIndicator);
|
assertThat(context.getBean("testHealthIndicator2", CompositeHealthIndicator.class)).isNotNull();
|
||||||
assertNotNull(bindersHealthIndicator);
|
|
||||||
assertNotNull(
|
|
||||||
context.getBean("testHealthIndicator1", CompositeHealthIndicator.class));
|
|
||||||
assertNotNull(
|
|
||||||
context.getBean("testHealthIndicator2", CompositeHealthIndicator.class));
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, HealthIndicator> healthIndicators = (Map<String, HealthIndicator>) directFieldAccessor
|
Map<String, HealthIndicator> healthIndicators = (Map<String, HealthIndicator>) directFieldAccessor
|
||||||
.getPropertyValue("indicators");
|
.getPropertyValue("indicators");
|
||||||
assertThat(healthIndicators, IsMapContaining.hasKey("binder1"));
|
assertThat(healthIndicators).containsKey("binder1");
|
||||||
assertThat(healthIndicators.get("binder1").health().getStatus(),
|
assertThat(healthIndicators.get("binder1").health().getStatus()).isEqualTo(Status.UP);
|
||||||
CoreMatchers.equalTo(Status.UP));
|
assertThat(healthIndicators).containsKey("binder2");
|
||||||
assertThat(healthIndicators, IsMapContaining.hasKey("binder2"));
|
assertThat(healthIndicators.get("binder2").health().getStatus()).isEqualTo(Status.UNKNOWN);
|
||||||
assertThat(healthIndicators.get("binder2").health().getStatus(),
|
|
||||||
CoreMatchers.equalTo(Status.UNKNOWN));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -94,20 +81,17 @@ public class HealthIndicatorsConfigurationTests {
|
|||||||
"management.health.binders.enabled:false");
|
"management.health.binders.enabled:false");
|
||||||
|
|
||||||
Binder binder1 = context.getBean(BinderFactory.class).getBinder("binder1");
|
Binder binder1 = context.getBean(BinderFactory.class).getBinder("binder1");
|
||||||
assertThat(binder1, instanceOf(StubBinder1.class));
|
assertThat(binder1).isInstanceOf(StubBinder1.class);
|
||||||
Binder binder2 = context.getBean(BinderFactory.class).getBinder("binder2");
|
Binder binder2 = context.getBean(BinderFactory.class).getBinder("binder2");
|
||||||
assertThat(binder2, instanceOf(StubBinder2.class));
|
assertThat(binder2).isInstanceOf(StubBinder2.class);
|
||||||
boolean exceptionThrown = false;
|
|
||||||
try {
|
try {
|
||||||
context.getBean("bindersHealthIndicator", CompositeHealthIndicator.class);
|
context.getBean("bindersHealthIndicator", CompositeHealthIndicator.class);
|
||||||
fail("The 'bindersHealthIndicator' bean should have not been defined");
|
fail("The 'bindersHealthIndicator' bean should have not been defined");
|
||||||
}
|
}
|
||||||
catch (NoSuchBeanDefinitionException e) {
|
catch (NoSuchBeanDefinitionException e) {
|
||||||
}
|
}
|
||||||
assertNotNull(
|
assertThat(context.getBean("testHealthIndicator1", CompositeHealthIndicator.class)).isNotNull();
|
||||||
context.getBean("testHealthIndicator1", CompositeHealthIndicator.class));
|
assertThat(context.getBean("testHealthIndicator2", CompositeHealthIndicator.class)).isNotNull();
|
||||||
assertNotNull(
|
|
||||||
context.getBean("testHealthIndicator2", CompositeHealthIndicator.class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConfigurableApplicationContext createBinderTestContext(
|
public static ConfigurableApplicationContext createBinderTestContext(
|
||||||
|
|||||||
@@ -30,8 +30,7 @@ import org.springframework.context.SmartLifecycle;
|
|||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.Matchers.anyString;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
@@ -52,9 +51,9 @@ public class InputOutputBindingOrderTest {
|
|||||||
// input is bound after the context has been started
|
// input is bound after the context has been started
|
||||||
verify(binder).bindConsumer(eq("input"), anyString(), eq(processor.input()), Mockito.<ConsumerProperties>any());
|
verify(binder).bindConsumer(eq("input"), anyString(), eq(processor.input()), Mockito.<ConsumerProperties>any());
|
||||||
SomeLifecycle someLifecycle = applicationContext.getBean(SomeLifecycle.class);
|
SomeLifecycle someLifecycle = applicationContext.getBean(SomeLifecycle.class);
|
||||||
assertTrue(someLifecycle.isRunning());
|
assertThat(someLifecycle.isRunning());
|
||||||
applicationContext.close();
|
applicationContext.close();
|
||||||
assertFalse(someLifecycle.isRunning());
|
assertThat(someLifecycle.isRunning()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EnableBinding(Processor.class)
|
@EnableBinding(Processor.class)
|
||||||
@@ -70,8 +69,6 @@ public class InputOutputBindingOrderTest {
|
|||||||
|
|
||||||
public static class SomeLifecycle implements SmartLifecycle {
|
public static class SomeLifecycle implements SmartLifecycle {
|
||||||
|
|
||||||
private boolean running;
|
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Autowired
|
@Autowired
|
||||||
private Binder binder;
|
private Binder binder;
|
||||||
@@ -79,6 +76,8 @@ public class InputOutputBindingOrderTest {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private Processor processor;
|
private Processor processor;
|
||||||
|
|
||||||
|
private boolean running;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public synchronized void start() {
|
public synchronized void start() {
|
||||||
|
|||||||
@@ -28,8 +28,7 @@ import org.springframework.context.Lifecycle;
|
|||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Marius Bogoevici
|
* @author Marius Bogoevici
|
||||||
@@ -40,9 +39,9 @@ public class LifecycleBinderTests {
|
|||||||
public void testNonSmartLifecyclesStarted() {
|
public void testNonSmartLifecyclesStarted() {
|
||||||
ConfigurableApplicationContext applicationContext = SpringApplication.run(TestSource.class, "--server.port=-1");
|
ConfigurableApplicationContext applicationContext = SpringApplication.run(TestSource.class, "--server.port=-1");
|
||||||
SimpleLifecycle simpleLifecycle = applicationContext.getBean(SimpleLifecycle.class);
|
SimpleLifecycle simpleLifecycle = applicationContext.getBean(SimpleLifecycle.class);
|
||||||
assertTrue(simpleLifecycle.isRunning());
|
assertThat(simpleLifecycle.isRunning());
|
||||||
applicationContext.close();
|
applicationContext.close();
|
||||||
assertFalse(simpleLifecycle.isRunning());
|
assertThat(simpleLifecycle.isRunning()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EnableBinding(Source.class)
|
@EnableBinding(Source.class)
|
||||||
|
|||||||
@@ -23,10 +23,7 @@ import org.springframework.integration.support.MessageBuilder;
|
|||||||
import org.springframework.messaging.Message;
|
import org.springframework.messaging.Message;
|
||||||
import org.springframework.messaging.support.GenericMessage;
|
import org.springframework.messaging.support.GenericMessage;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.Matchers.startsWith;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gary Russell
|
* @author Gary Russell
|
||||||
@@ -41,14 +38,14 @@ public class MessageConverterTests {
|
|||||||
Message<byte[]> message = MessageBuilder.withPayload("Hello".getBytes()).setHeader("foo", "bar")
|
Message<byte[]> message = MessageBuilder.withPayload("Hello".getBytes()).setHeader("foo", "bar")
|
||||||
.setHeader("baz", "quxx").build();
|
.setHeader("baz", "quxx").build();
|
||||||
byte[] embedded = converter.embedHeaders(new MessageValues(message), "foo", "baz");
|
byte[] embedded = converter.embedHeaders(new MessageValues(message), "foo", "baz");
|
||||||
assertEquals(0xff, embedded[0] & 0xff);
|
assertThat(embedded[0] & 0xff).isEqualTo(0xff);
|
||||||
assertEquals("\u0002\u0003foo\u0000\u0000\u0000\u0005\"bar\"\u0003baz\u0000\u0000\u0000\u0006\"quxx\"Hello",
|
assertThat(new String(embedded).substring(1)).isEqualTo(
|
||||||
new String(embedded).substring(1));
|
"\u0002\u0003foo\u0000\u0000\u0000\u0005\"bar\"\u0003baz\u0000\u0000\u0000\u0006\"quxx\"Hello");
|
||||||
|
|
||||||
MessageValues extracted = converter.extractHeaders(MessageBuilder.withPayload(embedded).build(), false);
|
MessageValues extracted = converter.extractHeaders(MessageBuilder.withPayload(embedded).build(), false);
|
||||||
assertEquals("Hello", new String((byte[]) extracted.getPayload()));
|
assertThat(new String((byte[]) extracted.getPayload())).isEqualTo("Hello");
|
||||||
assertEquals("bar", extracted.get("foo"));
|
assertThat(extracted.get("foo")).isEqualTo("bar");
|
||||||
assertEquals("quxx", extracted.get("baz"));
|
assertThat(extracted.get("baz")).isEqualTo("quxx");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -57,14 +54,14 @@ public class MessageConverterTests {
|
|||||||
Message<byte[]> message = MessageBuilder.withPayload("Hello".getBytes()).setHeader("foo", "bar")
|
Message<byte[]> message = MessageBuilder.withPayload("Hello".getBytes()).setHeader("foo", "bar")
|
||||||
.setHeader("baz", "ØØØØØØØØ").build();
|
.setHeader("baz", "ØØØØØØØØ").build();
|
||||||
byte[] embedded = converter.embedHeaders(new MessageValues(message), "foo", "baz");
|
byte[] embedded = converter.embedHeaders(new MessageValues(message), "foo", "baz");
|
||||||
assertEquals(0xff, embedded[0] & 0xff);
|
assertThat(embedded[0] & 0xff).isEqualTo(0xff);
|
||||||
assertEquals("\u0002\u0003foo\u0000\u0000\u0000\u0005\"bar\"\u0003baz\u0000\u0000\u0000\u0012\"ØØØØØØØØ\"Hello",
|
assertThat(new String(embedded, "UTF-8").substring(1)).isEqualTo(
|
||||||
new String(embedded, "UTF-8").substring(1));
|
"\u0002\u0003foo\u0000\u0000\u0000\u0005\"bar\"\u0003baz\u0000\u0000\u0000\u0012\"ØØØØØØØØ\"Hello");
|
||||||
|
|
||||||
MessageValues extracted = converter.extractHeaders(MessageBuilder.withPayload(embedded).build(), false);
|
MessageValues extracted = converter.extractHeaders(MessageBuilder.withPayload(embedded).build(), false);
|
||||||
assertEquals("Hello", new String((byte[]) extracted.getPayload()));
|
assertThat(new String((byte[]) extracted.getPayload())).isEqualTo("Hello");
|
||||||
assertEquals("bar", extracted.get("foo"));
|
assertThat(extracted.get("foo")).isEqualTo("bar");
|
||||||
assertEquals("ØØØØØØØØ", extracted.get("baz"));
|
assertThat(extracted.get("baz")).isEqualTo("ØØØØØØØØ");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -72,19 +69,19 @@ public class MessageConverterTests {
|
|||||||
EmbeddedHeadersMessageConverter converter = new EmbeddedHeadersMessageConverter();
|
EmbeddedHeadersMessageConverter converter = new EmbeddedHeadersMessageConverter();
|
||||||
Message<byte[]> message = MessageBuilder.withPayload("Hello".getBytes()).setHeader("foo", "bar").build();
|
Message<byte[]> message = MessageBuilder.withPayload("Hello".getBytes()).setHeader("foo", "bar").build();
|
||||||
byte[] embedded = converter.embedHeaders(new MessageValues(message), "foo", "baz");
|
byte[] embedded = converter.embedHeaders(new MessageValues(message), "foo", "baz");
|
||||||
assertEquals(0xff, embedded[0] & 0xff);
|
assertThat(embedded[0] & 0xff).isEqualTo(0xff);
|
||||||
assertEquals("\u0001\u0003foo\u0000\u0000\u0000\u0005\"bar\"Hello", new String(embedded).substring(1));
|
assertThat(new String(embedded).substring(1)).isEqualTo("\u0001\u0003foo\u0000\u0000\u0000\u0005\"bar\"Hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCanDecodeOldFormat() throws Exception {
|
public void testCanDecodeOldFormat() throws Exception {
|
||||||
EmbeddedHeadersMessageConverter converter = new EmbeddedHeadersMessageConverter();
|
EmbeddedHeadersMessageConverter converter = new EmbeddedHeadersMessageConverter();
|
||||||
byte[] bytes = "\u0002\u0003foo\u0003bar\u0003baz\u0004quxxHello".getBytes("UTF-8");
|
byte[] bytes = "\u0002\u0003foo\u0003bar\u0003baz\u0004quxxHello".getBytes("UTF-8");
|
||||||
Message<byte[]> message = new GenericMessage<byte[]>(bytes);
|
Message<byte[]> message = new GenericMessage<>(bytes);
|
||||||
MessageValues extracted = converter.extractHeaders(message, false);
|
MessageValues extracted = converter.extractHeaders(message, false);
|
||||||
assertEquals("Hello", new String((byte[]) extracted.getPayload()));
|
assertThat(new String((byte[]) extracted.getPayload())).isEqualTo("Hello");
|
||||||
assertEquals("bar", extracted.get("foo"));
|
assertThat(extracted.get("foo")).isEqualTo("bar");
|
||||||
assertEquals("quxx", extracted.get("baz"));
|
assertThat(extracted.get("baz")).isEqualTo("quxx");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -98,8 +95,8 @@ public class MessageConverterTests {
|
|||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
String s = EmbeddedHeadersMessageConverter.decodeExceptionMessage(message);
|
String s = EmbeddedHeadersMessageConverter.decodeExceptionMessage(message);
|
||||||
assertThat(e, instanceOf(StringIndexOutOfBoundsException.class));
|
assertThat(e).isInstanceOf(StringIndexOutOfBoundsException.class);
|
||||||
assertThat(s, startsWith("Could not convert message: 0203666F6F"));
|
assertThat(s).startsWith("Could not convert message: 0203666F6F");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,11 +47,7 @@ import org.springframework.integration.support.DefaultMessageBuilderFactory;
|
|||||||
import org.springframework.messaging.MessageChannel;
|
import org.springframework.messaging.MessageChannel;
|
||||||
import org.springframework.messaging.core.DestinationResolutionException;
|
import org.springframework.messaging.core.DestinationResolutionException;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.Matchers.is;
|
|
||||||
import static org.hamcrest.Matchers.sameInstance;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
@@ -94,9 +90,9 @@ public class ChannelBindingServiceTests {
|
|||||||
any(ConsumerProperties.class))).thenReturn(mockBinding);
|
any(ConsumerProperties.class))).thenReturn(mockBinding);
|
||||||
Collection<Binding<MessageChannel>> bindings = service.bindConsumer(inputChannel,
|
Collection<Binding<MessageChannel>> bindings = service.bindConsumer(inputChannel,
|
||||||
inputChannelName);
|
inputChannelName);
|
||||||
assertThat(bindings.size(), is(1));
|
assertThat(bindings).hasSize(1);
|
||||||
Binding<MessageChannel> binding = bindings.iterator().next();
|
Binding<MessageChannel> binding = bindings.iterator().next();
|
||||||
assertThat(binding, sameInstance(mockBinding));
|
assertThat(binding).isSameAs(mockBinding);
|
||||||
service.unbindConsumers(inputChannelName);
|
service.unbindConsumers(inputChannelName);
|
||||||
verify(binder).bindConsumer(eq("foo"), isNull(String.class), same(inputChannel),
|
verify(binder).bindConsumer(eq("foo"), isNull(String.class), same(inputChannel),
|
||||||
any(ConsumerProperties.class));
|
any(ConsumerProperties.class));
|
||||||
@@ -141,14 +137,14 @@ public class ChannelBindingServiceTests {
|
|||||||
|
|
||||||
Collection<Binding<MessageChannel>> bindings = service.bindConsumer(inputChannel,
|
Collection<Binding<MessageChannel>> bindings = service.bindConsumer(inputChannel,
|
||||||
"input");
|
"input");
|
||||||
assertThat(bindings.size(), is(2));
|
assertThat(bindings).hasSize(2);
|
||||||
|
|
||||||
Iterator<Binding<MessageChannel>> iterator = bindings.iterator();
|
Iterator<Binding<MessageChannel>> iterator = bindings.iterator();
|
||||||
Binding<MessageChannel> binding1 = iterator.next();
|
Binding<MessageChannel> binding1 = iterator.next();
|
||||||
Binding<MessageChannel> binding2 = iterator.next();
|
Binding<MessageChannel> binding2 = iterator.next();
|
||||||
|
|
||||||
assertThat(binding1, sameInstance(mockBinding1));
|
assertThat(binding1).isSameAs(mockBinding1);
|
||||||
assertThat(binding2, sameInstance(mockBinding2));
|
assertThat(binding2).isSameAs(mockBinding2);
|
||||||
|
|
||||||
service.unbindConsumers("input");
|
service.unbindConsumers("input");
|
||||||
|
|
||||||
@@ -190,9 +186,9 @@ public class ChannelBindingServiceTests {
|
|||||||
any(ConsumerProperties.class))).thenReturn(mockBinding);
|
any(ConsumerProperties.class))).thenReturn(mockBinding);
|
||||||
Collection<Binding<MessageChannel>> bindings = service.bindConsumer(inputChannel,
|
Collection<Binding<MessageChannel>> bindings = service.bindConsumer(inputChannel,
|
||||||
inputChannelName);
|
inputChannelName);
|
||||||
assertThat(bindings.size(), is(1));
|
assertThat(bindings).hasSize(1);
|
||||||
Binding<MessageChannel> binding = bindings.iterator().next();
|
Binding<MessageChannel> binding = bindings.iterator().next();
|
||||||
assertThat(binding, sameInstance(mockBinding));
|
assertThat(binding).isSameAs(mockBinding);
|
||||||
|
|
||||||
service.unbindConsumers(inputChannelName);
|
service.unbindConsumers(inputChannelName);
|
||||||
verify(binder).bindConsumer(eq("foo"), eq(props.getGroup()), same(inputChannel),
|
verify(binder).bindConsumer(eq("foo"), eq(props.getGroup()), same(inputChannel),
|
||||||
@@ -250,20 +246,19 @@ public class ChannelBindingServiceTests {
|
|||||||
}).when(beanFactory).initializeBean(any(MessageChannel.class), eq("foo"));
|
}).when(beanFactory).initializeBean(any(MessageChannel.class), eq("foo"));
|
||||||
resolver.setBeanFactory(beanFactory);
|
resolver.setBeanFactory(beanFactory);
|
||||||
MessageChannel resolved = resolver.resolveDestination("foo");
|
MessageChannel resolved = resolver.resolveDestination("foo");
|
||||||
assertThat(resolved, sameInstance(dynamic.get()));
|
assertThat(resolved).isSameAs(dynamic.get());
|
||||||
verify(binder).bindProducer(eq("foo"), eq(dynamic.get()),
|
verify(binder).bindProducer(eq("foo"), eq(dynamic.get()),
|
||||||
any(ProducerProperties.class));
|
any(ProducerProperties.class));
|
||||||
properties.setDynamicDestinations(new String[] { "foo" });
|
properties.setDynamicDestinations(new String[] { "foo" });
|
||||||
resolved = resolver.resolveDestination("foo");
|
resolved = resolver.resolveDestination("foo");
|
||||||
assertThat(resolved, sameInstance(dynamic.get()));
|
assertThat(resolved).isSameAs(dynamic.get());
|
||||||
properties.setDynamicDestinations(new String[] { "test" });
|
properties.setDynamicDestinations(new String[] { "test" });
|
||||||
try {
|
try {
|
||||||
resolved = resolver.resolveDestination("bar");
|
resolved = resolver.resolveDestination("bar");
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
catch (DestinationResolutionException e) {
|
catch (DestinationResolutionException e) {
|
||||||
assertThat(e.getMessage(), containsString(
|
assertThat(e).hasMessageContaining("Failed to find MessageChannel bean with name 'bar'");
|
||||||
"Failed to find MessageChannel bean with name 'bar'"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,7 +285,7 @@ public class ChannelBindingServiceTests {
|
|||||||
fail("Producer properties should be validated.");
|
fail("Producer properties should be validated.");
|
||||||
}
|
}
|
||||||
catch (IllegalStateException e) {
|
catch (IllegalStateException e) {
|
||||||
assertTrue(e.getMessage().contains("Partition count should be greater than zero."));
|
assertThat(e).hasMessageContaining("Partition count should be greater than zero.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,8 +317,7 @@ public class ChannelBindingServiceTests {
|
|||||||
fail("Consumer properties should be validated.");
|
fail("Consumer properties should be validated.");
|
||||||
}
|
}
|
||||||
catch (IllegalStateException e) {
|
catch (IllegalStateException e) {
|
||||||
assertTrue(
|
assertThat(e).hasMessageContaining("Concurrency should be greater than zero.");
|
||||||
e.getMessage().contains("Concurrency should be greater than zero."));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,7 @@ import org.springframework.context.annotation.Import;
|
|||||||
import org.springframework.expression.Expression;
|
import org.springframework.expression.Expression;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for SpelExpressionConverterConfiguration.
|
* Tests for SpelExpressionConverterConfiguration.
|
||||||
@@ -50,7 +49,7 @@ public class SpelExpressionConverterConfigurationTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void converterCorrectlyInstalled() {
|
public void converterCorrectlyInstalled() {
|
||||||
assertThat(pojo.getExpression().getValue("{\"a\": {\"b\": 5}}").toString(), is((Object) "5"));
|
assertThat(pojo.getExpression().getValue("{\"a\": {\"b\": 5}}").toString()).isEqualTo("5");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfigurationProperties
|
@ConfigurationProperties
|
||||||
|
|||||||
@@ -79,7 +79,8 @@
|
|||||||
<!-- Imports -->
|
<!-- Imports -->
|
||||||
<module name="AvoidStarImport"/>
|
<module name="AvoidStarImport"/>
|
||||||
<module name="AvoidStaticImport">
|
<module name="AvoidStaticImport">
|
||||||
<property name="excludes" value="org.junit.Assert.*,org.mockito.Mockito.*,org.mockito.Matchers.*,org.hamcrest.Matchers.*"/>
|
<property name="excludes"
|
||||||
|
value="org.junit.Assert.*,org.mockito.Mockito.*,org.mockito.Matchers.*,org.hamcrest.Matchers.*,org.assertj.core.api.Assertions.*"/>
|
||||||
</module>
|
</module>
|
||||||
<module name="FallThrough"/>
|
<module name="FallThrough"/>
|
||||||
<module name="ImportOrder">
|
<module name="ImportOrder">
|
||||||
@@ -128,6 +129,13 @@
|
|||||||
<property name="illegalPattern" value="true" />
|
<property name="illegalPattern" value="true" />
|
||||||
<property name="message" value="Trailing whitespace" />
|
<property name="message" value="Trailing whitespace" />
|
||||||
</module>
|
</module>
|
||||||
|
<module name="RegexpSinglelineJava">
|
||||||
|
<property name="maximum" value="0"/>
|
||||||
|
<property name="format" value="org\.junit\.Assert\.assert"/>
|
||||||
|
<property name="message"
|
||||||
|
value="Please use AssertJ imports."/>
|
||||||
|
<property name="ignoreComments" value="true"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
<!-- Whitespace -->
|
<!-- Whitespace -->
|
||||||
<module name="GenericWhitespace" />
|
<module name="GenericWhitespace" />
|
||||||
|
|||||||
Reference in New Issue
Block a user