Added checkstyle
This commit is contained in:
@@ -63,8 +63,6 @@ import org.springframework.util.MimeTypeUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Gary Russell
|
||||
@@ -76,20 +74,18 @@ import static org.junit.Assert.assertTrue;
|
||||
* @author Jacob Severson
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
// @checkstyle:off
|
||||
@SuppressWarnings("unchecked")
|
||||
public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends AbstractBinder<MessageChannel, CP, PP>, CP, PP>, CP extends ConsumerProperties, PP extends ProducerProperties> {
|
||||
|
||||
// @checkstyle:on
|
||||
|
||||
protected final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
protected B testBinder;
|
||||
|
||||
protected SmartMessageConverter messageConverter;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
this.messageConverter = new CompositeMessageConverterFactory().getMessageConverterForAllRegistered();
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses may override this default value to have tests wait longer for a message
|
||||
* receive, for example if running in an environment that is known to be slow (e.g.
|
||||
@@ -97,6 +93,12 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
*/
|
||||
protected double timeoutMultiplier = 1.0D;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
this.messageConverter = new CompositeMessageConverterFactory()
|
||||
.getMessageConverterForAllRegistered();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to receive a message on the given channel, waiting up to 1s (times the
|
||||
* {@link #timeoutMultiplier}).
|
||||
@@ -114,9 +116,9 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
protected Message<?> receive(PollableChannel channel, int additionalMultiplier) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
Message<?> receive = channel
|
||||
.receive((int) (1000 * timeoutMultiplier * additionalMultiplier));
|
||||
.receive((int) (1000 * this.timeoutMultiplier * additionalMultiplier));
|
||||
long elapsed = System.currentTimeMillis() - startTime;
|
||||
logger.debug("receive() took " + elapsed / 1000 + " seconds");
|
||||
this.logger.debug("receive() took " + elapsed / 1000 + " seconds");
|
||||
return receive;
|
||||
}
|
||||
|
||||
@@ -124,20 +126,25 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testClean() throws Exception {
|
||||
Binder binder = getBinder();
|
||||
Binding<MessageChannel> foo0ProducerBinding = binder.bindProducer(String.format("foo%s0",
|
||||
getDestinationNameDelimiter()), this.createBindableChannel("output", new BindingProperties()),
|
||||
Binding<MessageChannel> foo0ProducerBinding = binder.bindProducer(
|
||||
String.format("foo%s0", getDestinationNameDelimiter()),
|
||||
this.createBindableChannel("output", new BindingProperties()),
|
||||
createProducerProperties());
|
||||
Binding<MessageChannel> foo0ConsumerBinding = binder.bindConsumer(String.format("foo%s0",
|
||||
getDestinationNameDelimiter()), "testClean", this.createBindableChannel("input",
|
||||
new BindingProperties()), createConsumerProperties());
|
||||
Binding<MessageChannel> foo1ProducerBinding = binder.bindProducer(String.format("foo%s1",
|
||||
getDestinationNameDelimiter()), this.createBindableChannel("output", new BindingProperties()),
|
||||
Binding<MessageChannel> foo0ConsumerBinding = binder.bindConsumer(
|
||||
String.format("foo%s0", getDestinationNameDelimiter()), "testClean",
|
||||
this.createBindableChannel("input", new BindingProperties()),
|
||||
createConsumerProperties());
|
||||
Binding<MessageChannel> foo1ProducerBinding = binder.bindProducer(
|
||||
String.format("foo%s1", getDestinationNameDelimiter()),
|
||||
this.createBindableChannel("output", new BindingProperties()),
|
||||
createProducerProperties());
|
||||
Binding<MessageChannel> foo1ConsumerBinding = binder.bindConsumer(String.format("foo%s1",
|
||||
getDestinationNameDelimiter()), "testClean", this.createBindableChannel("input",
|
||||
new BindingProperties()), createConsumerProperties());
|
||||
Binding<MessageChannel> foo2ProducerBinding = binder.bindProducer(String.format("foo%s2",
|
||||
getDestinationNameDelimiter()), this.createBindableChannel("output", new BindingProperties()),
|
||||
Binding<MessageChannel> foo1ConsumerBinding = binder.bindConsumer(
|
||||
String.format("foo%s1", getDestinationNameDelimiter()), "testClean",
|
||||
this.createBindableChannel("input", new BindingProperties()),
|
||||
createConsumerProperties());
|
||||
Binding<MessageChannel> foo2ProducerBinding = binder.bindProducer(
|
||||
String.format("foo%s2", getDestinationNameDelimiter()),
|
||||
this.createBindableChannel("output", new BindingProperties()),
|
||||
createProducerProperties());
|
||||
foo0ProducerBinding.unbind();
|
||||
assertThat(TestUtils
|
||||
@@ -165,18 +172,25 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
@Test
|
||||
public void testSendAndReceive() throws Exception {
|
||||
Binder binder = getBinder();
|
||||
BindingProperties outputBindingProperties = createProducerBindingProperties(createProducerProperties());
|
||||
DirectChannel moduleOutputChannel = createBindableChannel("output", outputBindingProperties);
|
||||
BindingProperties outputBindingProperties = createProducerBindingProperties(
|
||||
createProducerProperties());
|
||||
DirectChannel moduleOutputChannel = createBindableChannel("output",
|
||||
outputBindingProperties);
|
||||
|
||||
BindingProperties inputBindingProperties = createConsumerBindingProperties(createConsumerProperties());
|
||||
DirectChannel moduleInputChannel = createBindableChannel("input", inputBindingProperties);
|
||||
BindingProperties inputBindingProperties = createConsumerBindingProperties(
|
||||
createConsumerProperties());
|
||||
DirectChannel moduleInputChannel = createBindableChannel("input",
|
||||
inputBindingProperties);
|
||||
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(String.format("foo%s0",
|
||||
getDestinationNameDelimiter()), moduleOutputChannel, outputBindingProperties.getProducer());
|
||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(String.format("foo%s0",
|
||||
getDestinationNameDelimiter()), "testSendAndReceive", moduleInputChannel, inputBindingProperties.getConsumer());
|
||||
Message<?> message = MessageBuilder.withPayload("foo").setHeader(MessageHeaders.CONTENT_TYPE, "text/plain")
|
||||
.build();
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(
|
||||
String.format("foo%s0", getDestinationNameDelimiter()),
|
||||
moduleOutputChannel, outputBindingProperties.getProducer());
|
||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(
|
||||
String.format("foo%s0", getDestinationNameDelimiter()),
|
||||
"testSendAndReceive", moduleInputChannel,
|
||||
inputBindingProperties.getConsumer());
|
||||
Message<?> message = MessageBuilder.withPayload("foo")
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, "text/plain").build();
|
||||
// Let the consumer actually bind to the producer before sending a msg
|
||||
binderBindUnbindLatency();
|
||||
|
||||
@@ -195,44 +209,39 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
Assert.isTrue(latch.await(5, TimeUnit.SECONDS), "Failed to receive message");
|
||||
|
||||
assertThat(inboundMessageRef.get().getPayload()).isEqualTo("foo".getBytes());
|
||||
assertThat(inboundMessageRef.get().getHeaders().get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)).isNull();
|
||||
assertThat(inboundMessageRef.get().getHeaders().get(MessageHeaders.CONTENT_TYPE).toString()).isEqualTo("text/plain");
|
||||
assertThat(inboundMessageRef.get().getHeaders()
|
||||
.get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)).isNull();
|
||||
assertThat(inboundMessageRef.get().getHeaders().get(MessageHeaders.CONTENT_TYPE)
|
||||
.toString()).isEqualTo("text/plain");
|
||||
producerBinding.unbind();
|
||||
consumerBinding.unbind();
|
||||
}
|
||||
|
||||
private class Foo {
|
||||
|
||||
private String name;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({"rawtypes","deprecation"})
|
||||
@SuppressWarnings({ "rawtypes", "deprecation" })
|
||||
public void testSendAndReceiveKryo() throws Exception {
|
||||
Binder binder = getBinder();
|
||||
BindingProperties outputBindingProperties = createProducerBindingProperties(createProducerProperties());
|
||||
DirectChannel moduleOutputChannel = createBindableChannel("output", outputBindingProperties);
|
||||
BindingProperties outputBindingProperties = createProducerBindingProperties(
|
||||
createProducerProperties());
|
||||
DirectChannel moduleOutputChannel = createBindableChannel("output",
|
||||
outputBindingProperties);
|
||||
|
||||
BindingProperties inputBindingProperties = createConsumerBindingProperties(createConsumerProperties());
|
||||
DirectChannel moduleInputChannel = createBindableChannel("input", inputBindingProperties);
|
||||
BindingProperties inputBindingProperties = createConsumerBindingProperties(
|
||||
createConsumerProperties());
|
||||
DirectChannel moduleInputChannel = createBindableChannel("input",
|
||||
inputBindingProperties);
|
||||
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(String.format("foo%s0x",
|
||||
getDestinationNameDelimiter()), moduleOutputChannel, outputBindingProperties.getProducer());
|
||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(String.format("foo%s0x",
|
||||
getDestinationNameDelimiter()), "testSendAndReceiveKryo", moduleInputChannel, inputBindingProperties.getConsumer());
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(
|
||||
String.format("foo%s0x", getDestinationNameDelimiter()),
|
||||
moduleOutputChannel, outputBindingProperties.getProducer());
|
||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(
|
||||
String.format("foo%s0x", getDestinationNameDelimiter()),
|
||||
"testSendAndReceiveKryo", moduleInputChannel,
|
||||
inputBindingProperties.getConsumer());
|
||||
Foo foo = new Foo();
|
||||
foo.setName("Bill");
|
||||
Message<?> message = MessageBuilder.withPayload(foo).setHeader(MessageHeaders.CONTENT_TYPE, MessageConverterUtils.X_JAVA_OBJECT)
|
||||
.build();
|
||||
Message<?> message = MessageBuilder.withPayload(foo).setHeader(
|
||||
MessageHeaders.CONTENT_TYPE, MessageConverterUtils.X_JAVA_OBJECT).build();
|
||||
// Let the consumer actually bind to the producer before sending a msg
|
||||
binderBindUnbindLatency();
|
||||
|
||||
@@ -252,34 +261,41 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
|
||||
KryoMessageConverter kryo = new KryoMessageConverter(null, true);
|
||||
Foo fooPayload = (Foo) kryo.fromMessage(inboundMessageRef.get(), Foo.class);
|
||||
assertNotNull(fooPayload);
|
||||
assertThat(inboundMessageRef.get().getHeaders().get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)).isNull();
|
||||
assertThat(fooPayload).isNotNull();
|
||||
assertThat(inboundMessageRef.get().getHeaders()
|
||||
.get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)).isNull();
|
||||
producerBinding.unbind();
|
||||
consumerBinding.unbind();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({"rawtypes","deprecation"})
|
||||
@SuppressWarnings({ "rawtypes", "deprecation" })
|
||||
public void testSendAndReceiveJavaSerialization() throws Exception {
|
||||
Binder binder = getBinder();
|
||||
BindingProperties outputBindingProperties = createProducerBindingProperties(createProducerProperties());
|
||||
BindingProperties outputBindingProperties = createProducerBindingProperties(
|
||||
createProducerProperties());
|
||||
|
||||
DirectChannel moduleOutputChannel = createBindableChannel("output", outputBindingProperties);
|
||||
DirectChannel moduleOutputChannel = createBindableChannel("output",
|
||||
outputBindingProperties);
|
||||
|
||||
BindingProperties inputBindingProperties = createConsumerBindingProperties(createConsumerProperties());
|
||||
DirectChannel moduleInputChannel = createBindableChannel("input", inputBindingProperties);
|
||||
BindingProperties inputBindingProperties = createConsumerBindingProperties(
|
||||
createConsumerProperties());
|
||||
DirectChannel moduleInputChannel = createBindableChannel("input",
|
||||
inputBindingProperties);
|
||||
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(String.format("foo%s0y",
|
||||
getDestinationNameDelimiter()), moduleOutputChannel, outputBindingProperties.getProducer());
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(
|
||||
String.format("foo%s0y", getDestinationNameDelimiter()),
|
||||
moduleOutputChannel, outputBindingProperties.getProducer());
|
||||
|
||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(String.format("foo%s0y",
|
||||
getDestinationNameDelimiter()), "testSendAndReceiveJavaSerialization", moduleInputChannel,
|
||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(
|
||||
String.format("foo%s0y", getDestinationNameDelimiter()),
|
||||
"testSendAndReceiveJavaSerialization", moduleInputChannel,
|
||||
inputBindingProperties.getConsumer());
|
||||
SerializableFoo foo = new SerializableFoo();
|
||||
Message<?> message =
|
||||
MessageBuilder.withPayload(foo)
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, MessageConverterUtils.X_JAVA_SERIALIZED_OBJECT)
|
||||
.build();
|
||||
Message<?> message = MessageBuilder.withPayload(foo)
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE,
|
||||
MessageConverterUtils.X_JAVA_SERIALIZED_OBJECT)
|
||||
.build();
|
||||
// Let the consumer actually bind to the producer before sending a msg
|
||||
binderBindUnbindLatency();
|
||||
|
||||
@@ -298,10 +314,13 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
Assert.isTrue(latch.await(5, TimeUnit.SECONDS), "Failed to receive message");
|
||||
|
||||
JavaSerializationMessageConverter converter = new JavaSerializationMessageConverter();
|
||||
SerializableFoo serializableFoo = (SerializableFoo) converter.convertFromInternal(inboundMessageRef.get(), SerializableFoo.class, null);
|
||||
assertNotNull(serializableFoo);
|
||||
assertThat(inboundMessageRef.get().getHeaders().get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)).isNull();
|
||||
assertThat(inboundMessageRef.get().getHeaders().get(MessageHeaders.CONTENT_TYPE)).isEqualTo(MessageConverterUtils.X_JAVA_SERIALIZED_OBJECT);
|
||||
SerializableFoo serializableFoo = (SerializableFoo) converter.convertFromInternal(
|
||||
inboundMessageRef.get(), SerializableFoo.class, null);
|
||||
assertThat(serializableFoo).isNotNull();
|
||||
assertThat(inboundMessageRef.get().getHeaders()
|
||||
.get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)).isNull();
|
||||
assertThat(inboundMessageRef.get().getHeaders().get(MessageHeaders.CONTENT_TYPE))
|
||||
.isEqualTo(MessageConverterUtils.X_JAVA_SERIALIZED_OBJECT);
|
||||
producerBinding.unbind();
|
||||
consumerBinding.unbind();
|
||||
}
|
||||
@@ -311,25 +330,33 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
public void testSendAndReceiveMultipleTopics() throws Exception {
|
||||
Binder binder = getBinder();
|
||||
|
||||
BindingProperties producerBindingProperties = createProducerBindingProperties(createProducerProperties());
|
||||
BindingProperties producerBindingProperties = createProducerBindingProperties(
|
||||
createProducerProperties());
|
||||
|
||||
DirectChannel moduleOutputChannel1 = createBindableChannel("output1", producerBindingProperties);
|
||||
DirectChannel moduleOutputChannel1 = createBindableChannel("output1",
|
||||
producerBindingProperties);
|
||||
|
||||
DirectChannel moduleOutputChannel2 = createBindableChannel("output2", producerBindingProperties);
|
||||
DirectChannel moduleOutputChannel2 = createBindableChannel("output2",
|
||||
producerBindingProperties);
|
||||
|
||||
QueueChannel moduleInputChannel = new QueueChannel();
|
||||
|
||||
Binding<MessageChannel> producerBinding1 = binder.bindProducer(String.format("foo%sxy",
|
||||
getDestinationNameDelimiter()), moduleOutputChannel1, producerBindingProperties.getProducer());
|
||||
Binding<MessageChannel> producerBinding2 = binder.bindProducer(String.format("foo%syz",
|
||||
Binding<MessageChannel> producerBinding1 = binder.bindProducer(
|
||||
String.format("foo%sxy", getDestinationNameDelimiter()),
|
||||
moduleOutputChannel1, producerBindingProperties.getProducer());
|
||||
Binding<MessageChannel> producerBinding2 = binder.bindProducer(
|
||||
String.format("foo%syz",
|
||||
|
||||
getDestinationNameDelimiter()), moduleOutputChannel2, producerBindingProperties.getProducer());
|
||||
getDestinationNameDelimiter()),
|
||||
moduleOutputChannel2, producerBindingProperties.getProducer());
|
||||
|
||||
Binding<MessageChannel> consumerBinding1 = binder.bindConsumer(String.format("foo%sxy",
|
||||
getDestinationNameDelimiter()), "testSendAndReceiveMultipleTopics", moduleInputChannel,
|
||||
Binding<MessageChannel> consumerBinding1 = binder.bindConsumer(
|
||||
String.format("foo%sxy", getDestinationNameDelimiter()),
|
||||
"testSendAndReceiveMultipleTopics", moduleInputChannel,
|
||||
createConsumerProperties());
|
||||
Binding<MessageChannel> consumerBinding2 = binder.bindConsumer(String.format("foo%syz",
|
||||
getDestinationNameDelimiter()), "testSendAndReceiveMultipleTopics", moduleInputChannel,
|
||||
Binding<MessageChannel> consumerBinding2 = binder.bindConsumer(
|
||||
String.format("foo%syz", getDestinationNameDelimiter()),
|
||||
"testSendAndReceiveMultipleTopics", moduleInputChannel,
|
||||
createConsumerProperties());
|
||||
|
||||
String testPayload1 = "foo" + UUID.randomUUID().toString();
|
||||
@@ -373,12 +400,16 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
createProducerProperties());
|
||||
DirectChannel moduleOutputChannel = createBindableChannel("output",
|
||||
producerBindingProperties);
|
||||
BindingProperties inputBindingProperties = createConsumerBindingProperties(createConsumerProperties());
|
||||
DirectChannel moduleInputChannel = createBindableChannel("input", inputBindingProperties);
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(String.format("bar%s0",
|
||||
getDestinationNameDelimiter()), moduleOutputChannel, producerBindingProperties.getProducer());
|
||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(String.format("bar%s0",
|
||||
getDestinationNameDelimiter()), "testSendAndReceiveNoOriginalContentType", moduleInputChannel,
|
||||
BindingProperties inputBindingProperties = createConsumerBindingProperties(
|
||||
createConsumerProperties());
|
||||
DirectChannel moduleInputChannel = createBindableChannel("input",
|
||||
inputBindingProperties);
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(
|
||||
String.format("bar%s0", getDestinationNameDelimiter()),
|
||||
moduleOutputChannel, producerBindingProperties.getProducer());
|
||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(
|
||||
String.format("bar%s0", getDestinationNameDelimiter()),
|
||||
"testSendAndReceiveNoOriginalContentType", moduleInputChannel,
|
||||
createConsumerProperties());
|
||||
binderBindUnbindLatency();
|
||||
|
||||
@@ -400,8 +431,8 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
Assert.isTrue(latch.await(5, TimeUnit.SECONDS), "Failed to receive message");
|
||||
assertThat(inboundMessageRef.get()).isNotNull();
|
||||
assertThat(inboundMessageRef.get().getPayload()).isEqualTo("foo".getBytes());
|
||||
assertThat(inboundMessageRef.get().getHeaders().get(MessageHeaders.CONTENT_TYPE).toString())
|
||||
.isEqualTo(MimeTypeUtils.TEXT_PLAIN_VALUE);
|
||||
assertThat(inboundMessageRef.get().getHeaders().get(MessageHeaders.CONTENT_TYPE)
|
||||
.toString()).isEqualTo(MimeTypeUtils.TEXT_PLAIN_VALUE);
|
||||
producerBinding.unbind();
|
||||
consumerBinding.unbind();
|
||||
}
|
||||
@@ -412,7 +443,8 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
|
||||
protected abstract PP createProducerProperties();
|
||||
|
||||
protected final BindingProperties createConsumerBindingProperties(CP consumerProperties) {
|
||||
protected final BindingProperties createConsumerBindingProperties(
|
||||
CP consumerProperties) {
|
||||
BindingProperties bindingProperties = new BindingProperties();
|
||||
bindingProperties.setConsumer(consumerProperties);
|
||||
return bindingProperties;
|
||||
@@ -426,14 +458,16 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
|
||||
protected DirectChannel createBindableChannel(String channelName,
|
||||
BindingProperties bindingProperties) throws Exception {
|
||||
// The 'channelName.contains("input")' is strictly for convenience to avoid modifications in multiple tests
|
||||
return this.createBindableChannel(channelName, bindingProperties, channelName.contains("input"));
|
||||
// The 'channelName.contains("input")' is strictly for convenience to avoid
|
||||
// modifications in multiple tests
|
||||
return this.createBindableChannel(channelName, bindingProperties,
|
||||
channelName.contains("input"));
|
||||
}
|
||||
|
||||
protected DirectChannel createBindableChannel(String channelName,
|
||||
BindingProperties bindingProperties, boolean inputChannel) throws Exception {
|
||||
MessageConverterConfigurer messageConverterConfigurer = createConverterConfigurer(channelName,
|
||||
bindingProperties);
|
||||
MessageConverterConfigurer messageConverterConfigurer = createConverterConfigurer(
|
||||
channelName, bindingProperties);
|
||||
DirectChannel channel = new DirectChannel();
|
||||
channel.setBeanName(channelName);
|
||||
if (inputChannel) {
|
||||
@@ -447,8 +481,11 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
|
||||
protected DefaultPollableMessageSource createBindableMessageSource(String bindingName,
|
||||
BindingProperties bindingProperties) throws Exception {
|
||||
DefaultPollableMessageSource source = new DefaultPollableMessageSource(new CompositeMessageConverterFactory().getMessageConverterForAllRegistered());
|
||||
createConverterConfigurer(bindingName, bindingProperties).configurePolledMessageSource(source, bindingName);
|
||||
DefaultPollableMessageSource source = new DefaultPollableMessageSource(
|
||||
new CompositeMessageConverterFactory()
|
||||
.getMessageConverterForAllRegistered());
|
||||
createConverterConfigurer(bindingName, bindingProperties)
|
||||
.configurePolledMessageSource(source, bindingName);
|
||||
return source;
|
||||
}
|
||||
|
||||
@@ -470,8 +507,8 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
|
||||
@After
|
||||
public void cleanup() {
|
||||
if (testBinder != null) {
|
||||
testBinder.cleanup();
|
||||
if (this.testBinder != null) {
|
||||
this.testBinder.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -488,7 +525,7 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
* the 'connection' from its actual usage, which may be needed by some implementations
|
||||
* to see messages sent after connection creation.
|
||||
*/
|
||||
public abstract Spy spyOn(final String name);
|
||||
public abstract Spy spyOn(String name);
|
||||
|
||||
/**
|
||||
* Set the delimiter that will be used in the message source/target name. Some brokers
|
||||
@@ -508,19 +545,25 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
|
||||
Binder binder = getBinder();
|
||||
|
||||
BindingProperties producerBindingProperties = createProducerBindingProperties(createProducerProperties());
|
||||
BindingProperties producerBindingProperties = createProducerBindingProperties(
|
||||
createProducerProperties());
|
||||
|
||||
DirectChannel moduleOutputChannel = createBindableChannel("output", producerBindingProperties);
|
||||
DirectChannel moduleOutputChannel = createBindableChannel("output",
|
||||
producerBindingProperties);
|
||||
|
||||
BindingProperties consumerBindingProperties = createConsumerBindingProperties(createConsumerProperties());
|
||||
BindingProperties consumerBindingProperties = createConsumerBindingProperties(
|
||||
createConsumerProperties());
|
||||
|
||||
DirectChannel moduleInputChannel = createBindableChannel("input", consumerBindingProperties);
|
||||
DirectChannel moduleInputChannel = createBindableChannel("input",
|
||||
consumerBindingProperties);
|
||||
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(String.format("bad%s0a",
|
||||
getDestinationNameDelimiter()), moduleOutputChannel, producerBindingProperties.getProducer());
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(
|
||||
String.format("bad%s0a", getDestinationNameDelimiter()),
|
||||
moduleOutputChannel, producerBindingProperties.getProducer());
|
||||
|
||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(String.format("bad%s0a",
|
||||
getDestinationNameDelimiter()), "test-1", moduleInputChannel, consumerBindingProperties.getConsumer());
|
||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(
|
||||
String.format("bad%s0a", getDestinationNameDelimiter()), "test-1",
|
||||
moduleInputChannel, consumerBindingProperties.getConsumer());
|
||||
|
||||
Station station = new Station();
|
||||
Message<?> message = MessageBuilder.withPayload(station).build();
|
||||
@@ -530,7 +573,7 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
QueueChannel replyChannel = (QueueChannel) handler.getOutputChannel();
|
||||
|
||||
Message<?> replyMessage = replyChannel.receive(5000);
|
||||
assertTrue(replyMessage.getPayload() instanceof Station);
|
||||
assertThat(replyMessage.getPayload() instanceof Station).isTrue();
|
||||
producerBinding.unbind();
|
||||
consumerBinding.unbind();
|
||||
}
|
||||
@@ -543,19 +586,25 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
|
||||
Binder binder = getBinder();
|
||||
|
||||
BindingProperties producerBindingProperties = createProducerBindingProperties(createProducerProperties());
|
||||
BindingProperties producerBindingProperties = createProducerBindingProperties(
|
||||
createProducerProperties());
|
||||
|
||||
DirectChannel moduleOutputChannel = createBindableChannel("output", producerBindingProperties);
|
||||
DirectChannel moduleOutputChannel = createBindableChannel("output",
|
||||
producerBindingProperties);
|
||||
|
||||
BindingProperties consumerBindingProperties = createConsumerBindingProperties(createConsumerProperties());
|
||||
BindingProperties consumerBindingProperties = createConsumerBindingProperties(
|
||||
createConsumerProperties());
|
||||
|
||||
DirectChannel moduleInputChannel = createBindableChannel("input", consumerBindingProperties);
|
||||
DirectChannel moduleInputChannel = createBindableChannel("input",
|
||||
consumerBindingProperties);
|
||||
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(String.format("bad%s0b",
|
||||
getDestinationNameDelimiter()), moduleOutputChannel, producerBindingProperties.getProducer());
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(
|
||||
String.format("bad%s0b", getDestinationNameDelimiter()),
|
||||
moduleOutputChannel, producerBindingProperties.getProducer());
|
||||
|
||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(String.format("bad%s0b",
|
||||
getDestinationNameDelimiter()), "test-2", moduleInputChannel, consumerBindingProperties.getConsumer());
|
||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(
|
||||
String.format("bad%s0b", getDestinationNameDelimiter()), "test-2",
|
||||
moduleInputChannel, consumerBindingProperties.getConsumer());
|
||||
|
||||
Station station = new Station();
|
||||
Message<?> message = MessageBuilder.withPayload(station).setHeader(
|
||||
@@ -566,7 +615,7 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
QueueChannel replyChannel = (QueueChannel) handler.getOutputChannel();
|
||||
|
||||
Message<?> replyMessage = replyChannel.receive(5000);
|
||||
assertTrue(replyMessage.getPayload() instanceof Station);
|
||||
assertThat(replyMessage.getPayload() instanceof Station).isTrue();
|
||||
producerBinding.unbind();
|
||||
consumerBinding.unbind();
|
||||
}
|
||||
@@ -576,19 +625,25 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
public void testStreamListenerJavaSerializationNonSerializable() throws Exception {
|
||||
Binder binder = getBinder();
|
||||
|
||||
BindingProperties producerBindingProperties = createProducerBindingProperties(createProducerProperties());
|
||||
BindingProperties producerBindingProperties = createProducerBindingProperties(
|
||||
createProducerProperties());
|
||||
|
||||
DirectChannel moduleOutputChannel = createBindableChannel("output", producerBindingProperties);
|
||||
DirectChannel moduleOutputChannel = createBindableChannel("output",
|
||||
producerBindingProperties);
|
||||
|
||||
BindingProperties consumerBindingProperties = createConsumerBindingProperties(createConsumerProperties());
|
||||
BindingProperties consumerBindingProperties = createConsumerBindingProperties(
|
||||
createConsumerProperties());
|
||||
|
||||
DirectChannel moduleInputChannel = createBindableChannel("input", consumerBindingProperties);
|
||||
DirectChannel moduleInputChannel = createBindableChannel("input",
|
||||
consumerBindingProperties);
|
||||
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(String.format("bad%s0c",
|
||||
getDestinationNameDelimiter()), moduleOutputChannel, producerBindingProperties.getProducer());
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(
|
||||
String.format("bad%s0c", getDestinationNameDelimiter()),
|
||||
moduleOutputChannel, producerBindingProperties.getProducer());
|
||||
|
||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(String.format("bad%s0c",
|
||||
getDestinationNameDelimiter()), "test-3", moduleInputChannel, consumerBindingProperties.getConsumer());
|
||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(
|
||||
String.format("bad%s0c", getDestinationNameDelimiter()), "test-3",
|
||||
moduleInputChannel, consumerBindingProperties.getConsumer());
|
||||
try {
|
||||
Station station = new Station();
|
||||
Message<?> message = MessageBuilder.withPayload(station)
|
||||
@@ -610,22 +665,29 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
AbstractBinderTests.class, "echoStation", Station.class);
|
||||
Binder binder = getBinder();
|
||||
|
||||
BindingProperties producerBindingProperties = createProducerBindingProperties(createProducerProperties());
|
||||
BindingProperties producerBindingProperties = createProducerBindingProperties(
|
||||
createProducerProperties());
|
||||
|
||||
DirectChannel moduleOutputChannel = createBindableChannel("output", producerBindingProperties);
|
||||
DirectChannel moduleOutputChannel = createBindableChannel("output",
|
||||
producerBindingProperties);
|
||||
|
||||
BindingProperties consumerBindingProperties = createConsumerBindingProperties(createConsumerProperties());
|
||||
BindingProperties consumerBindingProperties = createConsumerBindingProperties(
|
||||
createConsumerProperties());
|
||||
|
||||
DirectChannel moduleInputChannel = createBindableChannel("input", consumerBindingProperties);
|
||||
DirectChannel moduleInputChannel = createBindableChannel("input",
|
||||
consumerBindingProperties);
|
||||
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(String.format("bad%s0d",
|
||||
getDestinationNameDelimiter()), moduleOutputChannel, producerBindingProperties.getProducer());
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(
|
||||
String.format("bad%s0d", getDestinationNameDelimiter()),
|
||||
moduleOutputChannel, producerBindingProperties.getProducer());
|
||||
|
||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(String.format("bad%s0d",
|
||||
getDestinationNameDelimiter()), "test-4", moduleInputChannel, consumerBindingProperties.getConsumer());
|
||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(
|
||||
String.format("bad%s0d", getDestinationNameDelimiter()), "test-4",
|
||||
moduleInputChannel, consumerBindingProperties.getConsumer());
|
||||
|
||||
String value = "{\"readings\":[{\"stationid\":\"fgh\","
|
||||
+ "\"customerid\":\"12345\",\"timestamp\":null},{\"stationid\":\"hjk\",\"customerid\":\"222\",\"timestamp\":null}]}";
|
||||
+ "\"customerid\":\"12345\",\"timestamp\":null},"
|
||||
+ "{\"stationid\":\"hjk\",\"customerid\":\"222\",\"timestamp\":null}]}";
|
||||
|
||||
Message<?> message = MessageBuilder.withPayload(value)
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON)
|
||||
@@ -637,8 +699,8 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
|
||||
Message<Station> reply = (Message<Station>) channel.receive(5000);
|
||||
|
||||
assertNotNull(reply);
|
||||
assertTrue(reply.getPayload() instanceof Station);
|
||||
assertThat(reply).isNotNull();
|
||||
assertThat(reply.getPayload() instanceof Station).isTrue();
|
||||
producerBinding.unbind();
|
||||
consumerBinding.unbind();
|
||||
}
|
||||
@@ -650,22 +712,29 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
AbstractBinderTests.class, "echoStationString", String.class);
|
||||
Binder binder = getBinder();
|
||||
|
||||
BindingProperties producerBindingProperties = createProducerBindingProperties(createProducerProperties());
|
||||
BindingProperties producerBindingProperties = createProducerBindingProperties(
|
||||
createProducerProperties());
|
||||
|
||||
DirectChannel moduleOutputChannel = createBindableChannel("output", producerBindingProperties);
|
||||
DirectChannel moduleOutputChannel = createBindableChannel("output",
|
||||
producerBindingProperties);
|
||||
|
||||
BindingProperties consumerBindingProperties = createConsumerBindingProperties(createConsumerProperties());
|
||||
BindingProperties consumerBindingProperties = createConsumerBindingProperties(
|
||||
createConsumerProperties());
|
||||
|
||||
DirectChannel moduleInputChannel = createBindableChannel("input", consumerBindingProperties);
|
||||
DirectChannel moduleInputChannel = createBindableChannel("input",
|
||||
consumerBindingProperties);
|
||||
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(String.format("bad%s0e",
|
||||
getDestinationNameDelimiter()), moduleOutputChannel, producerBindingProperties.getProducer());
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(
|
||||
String.format("bad%s0e", getDestinationNameDelimiter()),
|
||||
moduleOutputChannel, producerBindingProperties.getProducer());
|
||||
|
||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(String.format("bad%s0e",
|
||||
getDestinationNameDelimiter()), "test-5", moduleInputChannel, consumerBindingProperties.getConsumer());
|
||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(
|
||||
String.format("bad%s0e", getDestinationNameDelimiter()), "test-5",
|
||||
moduleInputChannel, consumerBindingProperties.getConsumer());
|
||||
|
||||
String value = "{\"readings\":[{\"stationid\":\"fgh\","
|
||||
+ "\"customerid\":\"12345\",\"timestamp\":null},{\"stationid\":\"hjk\",\"customerid\":\"222\",\"timestamp\":null}]}";
|
||||
+ "\"customerid\":\"12345\",\"timestamp\":null},"
|
||||
+ "{\"stationid\":\"hjk\",\"customerid\":\"222\",\"timestamp\":null}]}";
|
||||
|
||||
Message<?> message = MessageBuilder.withPayload(value)
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON)
|
||||
@@ -677,8 +746,8 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
|
||||
Message<String> reply = (Message<String>) channel.receive(5000);
|
||||
|
||||
assertNotNull(reply);
|
||||
assertTrue(reply.getPayload() instanceof String);
|
||||
assertThat(reply).isNotNull();
|
||||
assertThat(reply.getPayload() instanceof String).isTrue();
|
||||
producerBinding.unbind();
|
||||
consumerBinding.unbind();
|
||||
}
|
||||
@@ -690,19 +759,25 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
AbstractBinderTests.class, "echoStation", Station.class);
|
||||
Binder binder = getBinder();
|
||||
|
||||
BindingProperties producerBindingProperties = createProducerBindingProperties(createProducerProperties());
|
||||
BindingProperties producerBindingProperties = createProducerBindingProperties(
|
||||
createProducerProperties());
|
||||
|
||||
DirectChannel moduleOutputChannel = createBindableChannel("output", producerBindingProperties);
|
||||
DirectChannel moduleOutputChannel = createBindableChannel("output",
|
||||
producerBindingProperties);
|
||||
|
||||
BindingProperties consumerBindingProperties = createConsumerBindingProperties(createConsumerProperties());
|
||||
BindingProperties consumerBindingProperties = createConsumerBindingProperties(
|
||||
createConsumerProperties());
|
||||
|
||||
DirectChannel moduleInputChannel = createBindableChannel("input", consumerBindingProperties);
|
||||
DirectChannel moduleInputChannel = createBindableChannel("input",
|
||||
consumerBindingProperties);
|
||||
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(String.format("bad%s0f",
|
||||
getDestinationNameDelimiter()), moduleOutputChannel, producerBindingProperties.getProducer());
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(
|
||||
String.format("bad%s0f", getDestinationNameDelimiter()),
|
||||
moduleOutputChannel, producerBindingProperties.getProducer());
|
||||
|
||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(String.format("bad%s0f",
|
||||
getDestinationNameDelimiter()), "test-6", moduleInputChannel, consumerBindingProperties.getConsumer());
|
||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(
|
||||
String.format("bad%s0f", getDestinationNameDelimiter()), "test-6",
|
||||
moduleInputChannel, consumerBindingProperties.getConsumer());
|
||||
|
||||
Readings r1 = new Readings();
|
||||
r1.setCustomerid("123");
|
||||
@@ -722,8 +797,8 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
|
||||
Message<Station> reply = (Message<Station>) channel.receive(5000);
|
||||
|
||||
assertNotNull(reply);
|
||||
assertTrue(reply.getPayload() instanceof Station);
|
||||
assertThat(reply).isNotNull();
|
||||
assertThat(reply.getPayload() instanceof Station).isTrue();
|
||||
producerBinding.unbind();
|
||||
consumerBinding.unbind();
|
||||
}
|
||||
@@ -756,7 +831,7 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
StreamListenerMessageHandler.class, InvocableHandlerMethod.class,
|
||||
boolean.class, String[].class);
|
||||
StreamListenerMessageHandler handler = (StreamListenerMessageHandler) c
|
||||
.newInstance(method, false, new String[] { });
|
||||
.newInstance(method, false, new String[] {});
|
||||
handler.setOutputChannelName(channelName);
|
||||
handler.setBeanFactory(context);
|
||||
handler.afterPropertiesSet();
|
||||
@@ -769,7 +844,7 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
List<Readings> readings = new ArrayList<>();
|
||||
|
||||
public List<Readings> getReadings() {
|
||||
return readings;
|
||||
return this.readings;
|
||||
}
|
||||
|
||||
public void setReadings(List<Readings> readings) {
|
||||
@@ -786,7 +861,7 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
public String timestamp;
|
||||
|
||||
public String getStationid() {
|
||||
return stationid;
|
||||
return this.stationid;
|
||||
}
|
||||
|
||||
public void setStationid(String stationid) {
|
||||
@@ -794,7 +869,7 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
}
|
||||
|
||||
public String getCustomerid() {
|
||||
return customerid;
|
||||
return this.customerid;
|
||||
}
|
||||
|
||||
public void setCustomerid(String customerid) {
|
||||
@@ -802,12 +877,30 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
|
||||
}
|
||||
|
||||
public String getTimestamp() {
|
||||
return timestamp;
|
||||
return this.timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(String timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class Foo {
|
||||
|
||||
private String name;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
* Copyright 2018-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,26 +20,34 @@ import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
|
||||
/**
|
||||
* @param <C> binder type
|
||||
* @param <CP> consumer properties type
|
||||
* @param <PP> producer properties type
|
||||
* @author Gary Russell
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractPollableConsumerTestBinder<C extends AbstractBinder<MessageChannel, CP, PP>,
|
||||
CP extends ConsumerProperties, PP extends ProducerProperties> extends AbstractTestBinder<C, CP, PP>
|
||||
implements PollableConsumerBinder<MessageHandler, CP>{
|
||||
// @checkstyle:off
|
||||
public abstract class AbstractPollableConsumerTestBinder<C extends AbstractBinder<MessageChannel, CP, PP>, CP extends ConsumerProperties, PP extends ProducerProperties>
|
||||
extends AbstractTestBinder<C, CP, PP>
|
||||
implements PollableConsumerBinder<MessageHandler, CP> {
|
||||
|
||||
// @checkstyle:on
|
||||
|
||||
private PollableConsumerBinder<MessageHandler, CP> binder;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setPollableConsumerBinder(PollableConsumerBinder<MessageHandler, CP> binder) {
|
||||
public void setPollableConsumerBinder(
|
||||
PollableConsumerBinder<MessageHandler, CP> binder) {
|
||||
super.setBinder((C) binder);
|
||||
this.binder = binder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Binding<PollableSource<MessageHandler>> bindPollableConsumer(String name, String group,
|
||||
PollableSource<MessageHandler> inboundBindTarget, CP consumerProperties) {
|
||||
return this.binder.bindPollableConsumer(name, group, inboundBindTarget, consumerProperties);
|
||||
public Binding<PollableSource<MessageHandler>> bindPollableConsumer(String name,
|
||||
String group, PollableSource<MessageHandler> inboundBindTarget,
|
||||
CP consumerProperties) {
|
||||
return this.binder.bindPollableConsumer(name, group, inboundBindTarget,
|
||||
consumerProperties);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.stream.binder;
|
||||
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -28,34 +27,41 @@ import org.springframework.util.CollectionUtils;
|
||||
/**
|
||||
* Abstract class that adds test support for {@link Binder}.
|
||||
*
|
||||
* @param <C> binder type
|
||||
* @param <CP> consumer properties type
|
||||
* @param <PP> producer properties type
|
||||
* @author Ilayaperumal Gopinathan
|
||||
* @author Gary Russell
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
// @checkstyle:off
|
||||
public abstract class AbstractTestBinder<C extends AbstractBinder<MessageChannel, CP, PP>, CP extends ConsumerProperties, PP extends ProducerProperties>
|
||||
implements Binder<MessageChannel, CP, PP> {
|
||||
|
||||
// @checkstyle:on
|
||||
|
||||
protected Set<String> queues = new HashSet<String>();
|
||||
|
||||
private C binder;
|
||||
|
||||
@Override
|
||||
public Binding<MessageChannel> bindConsumer(String name, String group, MessageChannel moduleInputChannel,
|
||||
CP properties) {
|
||||
public Binding<MessageChannel> bindConsumer(String name, String group,
|
||||
MessageChannel moduleInputChannel, CP properties) {
|
||||
this.checkChannelIsConfigured(moduleInputChannel, properties);
|
||||
queues.add(name);
|
||||
return binder.bindConsumer(name, group, moduleInputChannel, properties);
|
||||
this.queues.add(name);
|
||||
return this.binder.bindConsumer(name, group, moduleInputChannel, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Binding<MessageChannel> bindProducer(String name, MessageChannel moduleOutputChannel, PP properties) {
|
||||
queues.add(name);
|
||||
return binder.bindProducer(name, moduleOutputChannel, properties);
|
||||
public Binding<MessageChannel> bindProducer(String name,
|
||||
MessageChannel moduleOutputChannel, PP properties) {
|
||||
this.queues.add(name);
|
||||
return this.binder.bindProducer(name, moduleOutputChannel, properties);
|
||||
}
|
||||
|
||||
public C getCoreBinder() {
|
||||
return binder;
|
||||
return this.binder;
|
||||
}
|
||||
|
||||
public abstract void cleanup();
|
||||
@@ -76,13 +82,19 @@ public abstract class AbstractTestBinder<C extends AbstractBinder<MessageChannel
|
||||
|
||||
/*
|
||||
* This will ensure that any MessageChannel that was passed to one of the bind*()
|
||||
* methods was properly configured (i.e., interceptors, converters etc).
|
||||
* see org.springframework.cloud.stream.binding.MessageConverterConfigurer
|
||||
* methods was properly configured (i.e., interceptors, converters etc). see
|
||||
* org.springframework.cloud.stream.binding.MessageConverterConfigurer
|
||||
*/
|
||||
private void checkChannelIsConfigured(MessageChannel messageChannel, CP properties) {
|
||||
if (messageChannel instanceof AbstractSubscribableChannel && !properties.isUseNativeDecoding()){
|
||||
Assert.isTrue(!CollectionUtils.isEmpty(((AbstractSubscribableChannel)messageChannel).getChannelInterceptors()),
|
||||
"'messageChannel' appears to be misconfigured. Consider creating channel via AbstractBinderTest.createBindableChannel(..)");
|
||||
if (messageChannel instanceof AbstractSubscribableChannel
|
||||
&& !properties.isUseNativeDecoding()) {
|
||||
Assert.isTrue(
|
||||
!CollectionUtils
|
||||
.isEmpty(((AbstractSubscribableChannel) messageChannel)
|
||||
.getChannelInterceptors()),
|
||||
"'messageChannel' appears to be misconfigured. "
|
||||
+ "Consider creating channel via AbstractBinderTest.createBindableChannel(..)");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,10 +33,14 @@ import org.springframework.core.env.MapPropertySource;
|
||||
public class BinderTestEnvironmentPostProcessor implements EnvironmentPostProcessor {
|
||||
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment,
|
||||
SpringApplication application) {
|
||||
Map<String, Object> propertiesToAdd = new HashMap<>();
|
||||
propertiesToAdd.put("logging.pattern.console", "%d{ISO8601} %5p %t %c{2}:%L - %m%n");
|
||||
propertiesToAdd.put("logging.pattern.console",
|
||||
"%d{ISO8601} %5p %t %c{2}:%L - %m%n");
|
||||
propertiesToAdd.put("logging.level.root", "WARN");
|
||||
environment.getPropertySources().addLast(new MapPropertySource("binderTestPropertiesConfig", propertiesToAdd));
|
||||
environment.getPropertySources().addLast(
|
||||
new MapPropertySource("binderTestPropertiesConfig", propertiesToAdd));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,21 +26,30 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Gary Russell
|
||||
*/
|
||||
public abstract class BinderTestUtils {
|
||||
|
||||
public static final AbstractApplicationContext MOCK_AC = mock(AbstractApplicationContext.class);
|
||||
/**
|
||||
* Mocked application context.
|
||||
*/
|
||||
public static final AbstractApplicationContext MOCK_AC = mock(
|
||||
AbstractApplicationContext.class);
|
||||
|
||||
public static final ConfigurableListableBeanFactory MOCK_BF = mock(ConfigurableListableBeanFactory.class);
|
||||
/**
|
||||
* Mocked application bean factory.
|
||||
*/
|
||||
public static final ConfigurableListableBeanFactory MOCK_BF = mock(
|
||||
ConfigurableListableBeanFactory.class);
|
||||
|
||||
private static final MessageBuilderFactory mbf = new MutableMessageBuilderFactory();
|
||||
|
||||
static {
|
||||
when(MOCK_BF.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME,
|
||||
when(MOCK_BF.getBean(
|
||||
IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME,
|
||||
MessageBuilderFactory.class)).thenReturn(mbf);
|
||||
when(MOCK_AC.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME,
|
||||
when(MOCK_AC.getBean(
|
||||
IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME,
|
||||
MessageBuilderFactory.class)).thenReturn(mbf);
|
||||
when(MOCK_AC.getBeanFactory()).thenReturn(MOCK_BF);
|
||||
}
|
||||
|
||||
@@ -46,30 +46,39 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Marius Bogoevici
|
||||
* @author Vinicius Carvalho
|
||||
*/
|
||||
// @checkstyle:off
|
||||
public abstract class PartitionCapableBinderTests<B extends AbstractTestBinder<? extends AbstractBinder<MessageChannel, CP, PP>, CP, PP>, CP extends ConsumerProperties, PP extends ProducerProperties>
|
||||
extends AbstractBinderTests<B, CP, PP> {
|
||||
|
||||
// @checkstyle:on
|
||||
|
||||
protected static final SpelExpressionParser spelExpressionParser = new SpelExpressionParser();
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testAnonymousGroup() throws Exception {
|
||||
B binder = getBinder();
|
||||
BindingProperties producerBindingProperties = createProducerBindingProperties(createProducerProperties());
|
||||
BindingProperties producerBindingProperties = createProducerBindingProperties(
|
||||
createProducerProperties());
|
||||
DirectChannel output = createBindableChannel("output", producerBindingProperties);
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(String.format("defaultGroup%s0",
|
||||
getDestinationNameDelimiter()), output, (PP) producerBindingProperties.getProducer());
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(
|
||||
String.format("defaultGroup%s0", getDestinationNameDelimiter()), output,
|
||||
(PP) producerBindingProperties.getProducer());
|
||||
|
||||
QueueChannel input1 = new QueueChannel();
|
||||
Binding<MessageChannel> binding1 = binder.bindConsumer(String.format("defaultGroup%s0",
|
||||
getDestinationNameDelimiter()), null, input1, createConsumerProperties());
|
||||
Binding<MessageChannel> binding1 = binder.bindConsumer(
|
||||
String.format("defaultGroup%s0", getDestinationNameDelimiter()), null,
|
||||
input1, createConsumerProperties());
|
||||
|
||||
QueueChannel input2 = new QueueChannel();
|
||||
Binding<MessageChannel> binding2 = binder.bindConsumer(String.format("defaultGroup%s0",
|
||||
getDestinationNameDelimiter()), null, input2, createConsumerProperties());
|
||||
Binding<MessageChannel> binding2 = binder.bindConsumer(
|
||||
String.format("defaultGroup%s0", getDestinationNameDelimiter()), null,
|
||||
input2, createConsumerProperties());
|
||||
|
||||
String testPayload1 = "foo-" + UUID.randomUUID().toString();
|
||||
output.send(MessageBuilder.withPayload(testPayload1).setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN).build());
|
||||
output.send(MessageBuilder.withPayload(testPayload1)
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN)
|
||||
.build());
|
||||
|
||||
Message<byte[]> receivedMessage1 = (Message<byte[]>) receive(input1);
|
||||
assertThat(receivedMessage1).isNotNull();
|
||||
@@ -82,12 +91,17 @@ public abstract class PartitionCapableBinderTests<B extends AbstractTestBinder<?
|
||||
binding2.unbind();
|
||||
|
||||
String testPayload2 = "foo-" + UUID.randomUUID().toString();
|
||||
output.send(MessageBuilder.withPayload(testPayload2).setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN).build());
|
||||
output.send(MessageBuilder.withPayload(testPayload2)
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN)
|
||||
.build());
|
||||
|
||||
binding2 = binder.bindConsumer(String.format("defaultGroup%s0", getDestinationNameDelimiter()), null, input2,
|
||||
createConsumerProperties());
|
||||
binding2 = binder.bindConsumer(
|
||||
String.format("defaultGroup%s0", getDestinationNameDelimiter()), null,
|
||||
input2, createConsumerProperties());
|
||||
String testPayload3 = "foo-" + UUID.randomUUID().toString();
|
||||
output.send(MessageBuilder.withPayload(testPayload3).setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN).build());
|
||||
output.send(MessageBuilder.withPayload(testPayload3)
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN)
|
||||
.build());
|
||||
|
||||
receivedMessage1 = (Message<byte[]>) receive(input1);
|
||||
assertThat(receivedMessage1).isNotNull();
|
||||
@@ -109,23 +123,29 @@ public abstract class PartitionCapableBinderTests<B extends AbstractTestBinder<?
|
||||
public void testOneRequiredGroup() throws Exception {
|
||||
B binder = getBinder();
|
||||
PP producerProperties = createProducerProperties();
|
||||
DirectChannel output = createBindableChannel("output", createProducerBindingProperties(producerProperties));
|
||||
DirectChannel output = createBindableChannel("output",
|
||||
createProducerBindingProperties(producerProperties));
|
||||
|
||||
String testDestination = "testDestination" + UUID.randomUUID().toString().replace("-", "");
|
||||
String testDestination = "testDestination"
|
||||
+ UUID.randomUUID().toString().replace("-", "");
|
||||
|
||||
producerProperties.setRequiredGroups("test1");
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(testDestination, output, producerProperties);
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(testDestination,
|
||||
output, producerProperties);
|
||||
|
||||
String testPayload = "foo-" + UUID.randomUUID().toString();
|
||||
output.send(MessageBuilder.withPayload(testPayload).setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN).build());
|
||||
output.send(MessageBuilder.withPayload(testPayload)
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN)
|
||||
.build());
|
||||
|
||||
QueueChannel inbound1 = new QueueChannel();
|
||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(testDestination, "test1", inbound1,
|
||||
createConsumerProperties());
|
||||
Binding<MessageChannel> consumerBinding = binder.bindConsumer(testDestination,
|
||||
"test1", inbound1, createConsumerProperties());
|
||||
|
||||
Message<?> receivedMessage1 = receive(inbound1);
|
||||
assertThat(receivedMessage1).isNotNull();
|
||||
assertThat(new String((byte[]) receivedMessage1.getPayload())).isEqualTo(testPayload);
|
||||
assertThat(new String((byte[]) receivedMessage1.getPayload()))
|
||||
.isEqualTo(testPayload);
|
||||
|
||||
producerBinding.unbind();
|
||||
consumerBinding.unbind();
|
||||
@@ -136,29 +156,36 @@ public abstract class PartitionCapableBinderTests<B extends AbstractTestBinder<?
|
||||
B binder = getBinder();
|
||||
PP producerProperties = createProducerProperties();
|
||||
|
||||
DirectChannel output = createBindableChannel("output", createProducerBindingProperties(producerProperties));
|
||||
DirectChannel output = createBindableChannel("output",
|
||||
createProducerBindingProperties(producerProperties));
|
||||
|
||||
String testDestination = "testDestination" + UUID.randomUUID().toString().replace("-", "");
|
||||
String testDestination = "testDestination"
|
||||
+ UUID.randomUUID().toString().replace("-", "");
|
||||
|
||||
producerProperties.setRequiredGroups("test1", "test2");
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(testDestination, output, producerProperties);
|
||||
Binding<MessageChannel> producerBinding = binder.bindProducer(testDestination,
|
||||
output, producerProperties);
|
||||
|
||||
String testPayload = "foo-" + UUID.randomUUID().toString();
|
||||
output.send(MessageBuilder.withPayload(testPayload).setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN).build());
|
||||
output.send(MessageBuilder.withPayload(testPayload)
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN)
|
||||
.build());
|
||||
|
||||
QueueChannel inbound1 = new QueueChannel();
|
||||
Binding<MessageChannel> consumerBinding1 = binder.bindConsumer(testDestination, "test1", inbound1,
|
||||
createConsumerProperties());
|
||||
Binding<MessageChannel> consumerBinding1 = binder.bindConsumer(testDestination,
|
||||
"test1", inbound1, createConsumerProperties());
|
||||
QueueChannel inbound2 = new QueueChannel();
|
||||
Binding<MessageChannel> consumerBinding2 = binder.bindConsumer(testDestination, "test2", inbound2,
|
||||
createConsumerProperties());
|
||||
Binding<MessageChannel> consumerBinding2 = binder.bindConsumer(testDestination,
|
||||
"test2", inbound2, createConsumerProperties());
|
||||
|
||||
Message<?> receivedMessage1 = receive(inbound1);
|
||||
assertThat(receivedMessage1).isNotNull();
|
||||
assertThat(new String((byte[]) receivedMessage1.getPayload())).isEqualTo(testPayload);
|
||||
assertThat(new String((byte[]) receivedMessage1.getPayload()))
|
||||
.isEqualTo(testPayload);
|
||||
Message<?> receivedMessage2 = receive(inbound2);
|
||||
assertThat(receivedMessage2).isNotNull();
|
||||
assertThat(new String((byte[]) receivedMessage2.getPayload())).isEqualTo(testPayload);
|
||||
assertThat(new String((byte[]) receivedMessage2.getPayload()))
|
||||
.isEqualTo(testPayload);
|
||||
|
||||
consumerBinding1.unbind();
|
||||
consumerBinding2.unbind();
|
||||
@@ -176,28 +203,35 @@ public abstract class PartitionCapableBinderTests<B extends AbstractTestBinder<?
|
||||
consumerProperties.setPartitioned(true);
|
||||
QueueChannel input0 = new QueueChannel();
|
||||
input0.setBeanName("test.input0S");
|
||||
Binding<MessageChannel> input0Binding = binder.bindConsumer(String.format("part%s0",
|
||||
getDestinationNameDelimiter()), "testPartitionedModuleSpEL", input0, consumerProperties);
|
||||
Binding<MessageChannel> input0Binding = binder.bindConsumer(
|
||||
String.format("part%s0", getDestinationNameDelimiter()),
|
||||
"testPartitionedModuleSpEL", input0, consumerProperties);
|
||||
consumerProperties.setInstanceIndex(1);
|
||||
QueueChannel input1 = new QueueChannel();
|
||||
input1.setBeanName("test.input1S");
|
||||
Binding<MessageChannel> input1Binding = binder.bindConsumer(String.format("part%s0",
|
||||
getDestinationNameDelimiter()), "testPartitionedModuleSpEL", input1, consumerProperties);
|
||||
Binding<MessageChannel> input1Binding = binder.bindConsumer(
|
||||
String.format("part%s0", getDestinationNameDelimiter()),
|
||||
"testPartitionedModuleSpEL", input1, consumerProperties);
|
||||
consumerProperties.setInstanceIndex(2);
|
||||
QueueChannel input2 = new QueueChannel();
|
||||
input2.setBeanName("test.input2S");
|
||||
Binding<MessageChannel> input2Binding = binder.bindConsumer(String.format("part%s0",
|
||||
getDestinationNameDelimiter()), "testPartitionedModuleSpEL", input2, consumerProperties);
|
||||
Binding<MessageChannel> input2Binding = binder.bindConsumer(
|
||||
String.format("part%s0", getDestinationNameDelimiter()),
|
||||
"testPartitionedModuleSpEL", input2, consumerProperties);
|
||||
|
||||
PP producerProperties = createProducerProperties();
|
||||
producerProperties.setPartitionKeyExpression(spelExpressionParser.parseExpression("payload"));
|
||||
producerProperties.setPartitionSelectorExpression(spelExpressionParser.parseExpression("hashCode()"));
|
||||
producerProperties.setPartitionKeyExpression(
|
||||
spelExpressionParser.parseExpression("payload"));
|
||||
producerProperties.setPartitionSelectorExpression(
|
||||
spelExpressionParser.parseExpression("hashCode()"));
|
||||
producerProperties.setPartitionCount(3);
|
||||
|
||||
DirectChannel output = createBindableChannel("output", createProducerBindingProperties(producerProperties));
|
||||
DirectChannel output = createBindableChannel("output",
|
||||
createProducerBindingProperties(producerProperties));
|
||||
output.setBeanName("test.output");
|
||||
Binding<MessageChannel> outputBinding = binder.bindProducer(String.format("part%s0",
|
||||
getDestinationNameDelimiter()), output, producerProperties);
|
||||
Binding<MessageChannel> outputBinding = binder.bindProducer(
|
||||
String.format("part%s0", getDestinationNameDelimiter()), output,
|
||||
producerProperties);
|
||||
try {
|
||||
Object endpoint = extractEndpoint(outputBinding);
|
||||
checkRkExpressionForPartitionedModuleSpEL(endpoint);
|
||||
@@ -207,12 +241,16 @@ public abstract class PartitionCapableBinderTests<B extends AbstractTestBinder<?
|
||||
|
||||
Message<String> message2 = MessageBuilder.withPayload("2")
|
||||
.setHeader(IntegrationMessageHeaderAccessor.CORRELATION_ID, "foo")
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE,MimeTypeUtils.TEXT_PLAIN)
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN)
|
||||
.setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, 42)
|
||||
.setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE, 43).build();
|
||||
output.send(message2);
|
||||
output.send(MessageBuilder.withPayload("1").setHeader(MessageHeaders.CONTENT_TYPE,MimeTypeUtils.TEXT_PLAIN).build());
|
||||
output.send(MessageBuilder.withPayload("0").setHeader(MessageHeaders.CONTENT_TYPE,MimeTypeUtils.TEXT_PLAIN).build());
|
||||
output.send(MessageBuilder.withPayload("1")
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN)
|
||||
.build());
|
||||
output.send(MessageBuilder.withPayload("0")
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN)
|
||||
.build());
|
||||
|
||||
Message<?> receive0 = receive(input0);
|
||||
assertThat(receive0).isNotNull();
|
||||
@@ -224,8 +262,10 @@ public abstract class PartitionCapableBinderTests<B extends AbstractTestBinder<?
|
||||
Condition<Message<?>> correlationHeadersForPayload2 = new Condition<Message<?>>() {
|
||||
@Override
|
||||
public boolean matches(Message<?> value) {
|
||||
IntegrationMessageHeaderAccessor accessor = new IntegrationMessageHeaderAccessor(value);
|
||||
return "foo".equals(accessor.getCorrelationId()) && 42 == accessor.getSequenceNumber()
|
||||
IntegrationMessageHeaderAccessor accessor = new IntegrationMessageHeaderAccessor(
|
||||
value);
|
||||
return "foo".equals(accessor.getCorrelationId())
|
||||
&& 42 == accessor.getSequenceNumber()
|
||||
&& 43 == accessor.getSequenceSize();
|
||||
}
|
||||
};
|
||||
@@ -237,8 +277,10 @@ public abstract class PartitionCapableBinderTests<B extends AbstractTestBinder<?
|
||||
assertThat(receive2).has(correlationHeadersForPayload2);
|
||||
}
|
||||
else {
|
||||
List<Message<?>> receivedMessages = Arrays.asList(receive0, receive1, receive2);
|
||||
assertThat(receivedMessages).extracting("payload").containsExactlyInAnyOrder("0".getBytes(), "1".getBytes(), "2".getBytes());
|
||||
List<Message<?>> receivedMessages = Arrays.asList(receive0, receive1,
|
||||
receive2);
|
||||
assertThat(receivedMessages).extracting("payload").containsExactlyInAnyOrder(
|
||||
"0".getBytes(), "1".getBytes(), "2".getBytes());
|
||||
Condition<Message<?>> payloadIs2 = new Condition<Message<?>>() {
|
||||
|
||||
@Override
|
||||
@@ -246,7 +288,8 @@ public abstract class PartitionCapableBinderTests<B extends AbstractTestBinder<?
|
||||
return value.getPayload().equals("2".getBytes());
|
||||
}
|
||||
};
|
||||
assertThat(receivedMessages).filteredOn(payloadIs2).areExactly(1, correlationHeadersForPayload2);
|
||||
assertThat(receivedMessages).filteredOn(payloadIs2).areExactly(1,
|
||||
correlationHeadersForPayload2);
|
||||
|
||||
}
|
||||
input0Binding.unbind();
|
||||
@@ -257,8 +300,9 @@ public abstract class PartitionCapableBinderTests<B extends AbstractTestBinder<?
|
||||
|
||||
protected void checkRkExpressionForPartitionedModuleSpEL(Object endpoint) {
|
||||
assertThat(getEndpointRouting(endpoint))
|
||||
.contains(getExpectedRoutingBaseDestination(String.format("part%s0", getDestinationNameDelimiter()),
|
||||
"test") + "-' + headers['partition']");
|
||||
.contains(getExpectedRoutingBaseDestination(
|
||||
String.format("part%s0", getDestinationNameDelimiter()), "test")
|
||||
+ "-' + headers['partition']");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -273,36 +317,49 @@ public abstract class PartitionCapableBinderTests<B extends AbstractTestBinder<?
|
||||
consumerProperties.setPartitioned(true);
|
||||
QueueChannel input0 = new QueueChannel();
|
||||
input0.setBeanName("test.input0J");
|
||||
Binding<MessageChannel> input0Binding = binder.bindConsumer(String.format("partJ%s0",
|
||||
getDestinationNameDelimiter()), "testPartitionedModuleJava", input0, consumerProperties);
|
||||
Binding<MessageChannel> input0Binding = binder.bindConsumer(
|
||||
String.format("partJ%s0", getDestinationNameDelimiter()),
|
||||
"testPartitionedModuleJava", input0, consumerProperties);
|
||||
consumerProperties.setInstanceIndex(1);
|
||||
QueueChannel input1 = new QueueChannel();
|
||||
input1.setBeanName("test.input1J");
|
||||
Binding<MessageChannel> input1Binding = binder.bindConsumer(String.format("partJ%s0",
|
||||
getDestinationNameDelimiter()), "testPartitionedModuleJava", input1, consumerProperties);
|
||||
Binding<MessageChannel> input1Binding = binder.bindConsumer(
|
||||
String.format("partJ%s0", getDestinationNameDelimiter()),
|
||||
"testPartitionedModuleJava", input1, consumerProperties);
|
||||
consumerProperties.setInstanceIndex(2);
|
||||
QueueChannel input2 = new QueueChannel();
|
||||
input2.setBeanName("test.input2J");
|
||||
Binding<MessageChannel> input2Binding = binder.bindConsumer(String.format("partJ%s0",
|
||||
getDestinationNameDelimiter()), "testPartitionedModuleJava", input2, consumerProperties);
|
||||
Binding<MessageChannel> input2Binding = binder.bindConsumer(
|
||||
String.format("partJ%s0", getDestinationNameDelimiter()),
|
||||
"testPartitionedModuleJava", input2, consumerProperties);
|
||||
|
||||
PP producerProperties = createProducerProperties();
|
||||
producerProperties.setPartitionKeyExtractorClass(PartitionTestSupport.class);
|
||||
producerProperties.setPartitionSelectorClass(PartitionTestSupport.class);
|
||||
producerProperties.setPartitionCount(3);
|
||||
DirectChannel output = createBindableChannel("output", createProducerBindingProperties(producerProperties));
|
||||
DirectChannel output = createBindableChannel("output",
|
||||
createProducerBindingProperties(producerProperties));
|
||||
output.setBeanName("test.output");
|
||||
Binding<MessageChannel> outputBinding = binder.bindProducer("partJ.0", output, producerProperties);
|
||||
Binding<MessageChannel> outputBinding = binder.bindProducer("partJ.0", output,
|
||||
producerProperties);
|
||||
if (usesExplicitRouting()) {
|
||||
Object endpoint = extractEndpoint(outputBinding);
|
||||
assertThat(getEndpointRouting(endpoint)).contains(getExpectedRoutingBaseDestination(
|
||||
String.format("partJ%s0", getDestinationNameDelimiter()), "testPartitionedModuleJava")
|
||||
+ "-' + headers['" + BinderHeaders.PARTITION_HEADER + "']");
|
||||
assertThat(getEndpointRouting(endpoint))
|
||||
.contains(getExpectedRoutingBaseDestination(
|
||||
String.format("partJ%s0", getDestinationNameDelimiter()),
|
||||
"testPartitionedModuleJava") + "-' + headers['"
|
||||
+ BinderHeaders.PARTITION_HEADER + "']");
|
||||
}
|
||||
|
||||
output.send(MessageBuilder.withPayload("2").setHeader(MessageHeaders.CONTENT_TYPE,MimeTypeUtils.TEXT_PLAIN).build());
|
||||
output.send(MessageBuilder.withPayload("1").setHeader(MessageHeaders.CONTENT_TYPE,MimeTypeUtils.TEXT_PLAIN).build());
|
||||
output.send(MessageBuilder.withPayload("0").setHeader(MessageHeaders.CONTENT_TYPE,MimeTypeUtils.TEXT_PLAIN).build());
|
||||
output.send(MessageBuilder.withPayload("2")
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN)
|
||||
.build());
|
||||
output.send(MessageBuilder.withPayload("1")
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN)
|
||||
.build());
|
||||
output.send(MessageBuilder.withPayload("0")
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN)
|
||||
.build());
|
||||
|
||||
Message<?> receive0 = receive(input0);
|
||||
assertThat(receive0).isNotNull();
|
||||
@@ -317,8 +374,10 @@ public abstract class PartitionCapableBinderTests<B extends AbstractTestBinder<?
|
||||
assertThat(receive2.getPayload()).isEqualTo("2".getBytes());
|
||||
}
|
||||
else {
|
||||
List<Message<?>> receivedMessages = Arrays.asList(receive0, receive1, receive2);
|
||||
assertThat(receivedMessages).extracting("payload").containsExactlyInAnyOrder("0".getBytes(), "1".getBytes(), "2".getBytes());
|
||||
List<Message<?>> receivedMessages = Arrays.asList(receive0, receive1,
|
||||
receive2);
|
||||
assertThat(receivedMessages).extracting("payload").containsExactlyInAnyOrder(
|
||||
"0".getBytes(), "1".getBytes(), "2".getBytes());
|
||||
}
|
||||
|
||||
input0Binding.unbind();
|
||||
@@ -358,4 +417,5 @@ public abstract class PartitionCapableBinderTests<B extends AbstractTestBinder<?
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(binding);
|
||||
return (Lifecycle) accessor.getPropertyValue("lifecycle");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,7 +21,8 @@ import org.springframework.messaging.Message;
|
||||
/**
|
||||
* @author Gary Russell
|
||||
*/
|
||||
public class PartitionTestSupport implements PartitionKeyExtractorStrategy, PartitionSelectorStrategy {
|
||||
public class PartitionTestSupport
|
||||
implements PartitionKeyExtractorStrategy, PartitionSelectorStrategy {
|
||||
|
||||
@Override
|
||||
public int selectPartition(Object key, int divisor) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
* Copyright 2017-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,15 +16,13 @@
|
||||
|
||||
package org.springframework.cloud.stream.binder;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
public class SerializableFoo implements Serializable{
|
||||
public class SerializableFoo implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,4 +25,5 @@ package org.springframework.cloud.stream.binder;
|
||||
public interface Spy {
|
||||
|
||||
Object receive(boolean expectNull) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,7 +20,10 @@ import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Copy of class in org.springframework.amqp.utils.test to avoid dependency on spring-amqp
|
||||
* Copy of class in org.springframework.amqp.utils.test to avoid dependency on
|
||||
* spring-amqp.
|
||||
*
|
||||
* @author David Turanski
|
||||
*/
|
||||
public abstract class TestUtils {
|
||||
|
||||
@@ -61,4 +64,5 @@ public abstract class TestUtils {
|
||||
}
|
||||
return (T) value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user