Check simple XD samples are working

This commit is contained in:
Dave Syer
2015-07-09 10:01:07 +01:00
parent 531de2d41e
commit fc2397b11d
9 changed files with 100 additions and 25 deletions

View File

@@ -31,9 +31,11 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include;
@JsonInclude(Include.NON_DEFAULT)
public class ChannelBindingProperties {
private String outputChannelName = "group.0";
public static final String DEFAULT_CHANNEL_NAME = "group.0";
private String inputChannelName = "group.0";
private String outputChannelName = DEFAULT_CHANNEL_NAME;
private String inputChannelName = DEFAULT_CHANNEL_NAME;
private Properties consumerProperties = new Properties();

View File

@@ -65,13 +65,28 @@ public class ModuleProperties extends ChannelBindingProperties {
this.index = index;
}
@Override
public String getOutputChannelName() {
String name = super.getOutputChannelName();
if (ChannelBindingProperties.DEFAULT_CHANNEL_NAME.equals(name)) {
return BusUtils.constructPipeName(this.group, this.index);
}
return name;
}
@Override
public String getInputChannelName() {
if (isTap()) {
return String.format("%s.%s.%s", BusUtils.constructTapPrefix(this.tap.getGroup()),
this.tap.getName(), this.tap.getIndex());
return String.format("%s.%s.%s",
BusUtils.constructTapPrefix(this.tap.getGroup()), this.tap.getName(),
this.tap.getIndex());
}
return super.getInputChannelName();
String name = super.getInputChannelName();
if (ChannelBindingProperties.DEFAULT_CHANNEL_NAME.equals(name)) {
return BusUtils.constructPipeName(this.group, this.index > 0 ? this.index - 1
: this.index);
}
return name;
}
@Override
@@ -81,10 +96,10 @@ public class ModuleProperties extends ChannelBindingProperties {
@Override
public String getTapChannelName(String prefix) {
Assert.isTrue(!this.type .equals("job"), "Job module type not supported.");
Assert.isTrue(!this.type.equals("job"), "Job module type not supported.");
// for Stream return channel name with indexed elements
return String
.format("%s.%s.%s", BusUtils.constructTapPrefix(prefix), this.name, this.index);
return String.format("%s.%s.%s", BusUtils.constructTapPrefix(prefix), this.name,
this.index);
}
public Tap getTap() {

View File

@@ -31,9 +31,9 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.cloud.streams.adapter.ChannelBinding;
import org.springframework.cloud.streams.adapter.ChannelBindingAdapter;
import org.springframework.cloud.streams.adapter.InputChannelBinding;
import org.springframework.cloud.streams.adapter.OutputChannelBinding;
import org.springframework.cloud.streams.config.ChannelBindingAdapterConfiguration;
import org.springframework.cloud.streams.config.ChannelBindingProperties;
import org.springframework.cloud.streams.xd.ChannelBindingAdapterConfigurationTests.Empty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -62,7 +62,7 @@ public class ChannelBindingAdapterConfigurationTests {
private ChannelBindingAdapterConfiguration configuration;
@Autowired
private ChannelBindingProperties module;
private ModuleProperties module;
@Before
public void init() {
@@ -72,15 +72,28 @@ public class ChannelBindingAdapterConfigurationTests {
public void oneOutput() throws Exception {
this.context.registerSingleton("output", new DirectChannel());
refresh();
Collection<OutputChannelBinding> channels = this.adapter.getChannelsMetadata().getOutputChannels();
Collection<OutputChannelBinding> channels = this.adapter.getChannelsMetadata()
.getOutputChannels();
assertEquals(1, channels.size());
assertEquals("group.0", channels.iterator().next().getRemoteName());
assertEquals("tap:stream:group.module.0", channels.iterator().next()
.getTapChannelName());
}
@Test
public void oneInput() throws Exception {
this.context.registerSingleton("input", new DirectChannel());
refresh();
Collection<InputChannelBinding> channels = this.adapter.getChannelsMetadata()
.getInputChannels();
assertEquals(1, channels.size());
assertEquals("group.0", channels.iterator().next().getRemoteName());
assertEquals("tap:stream:group.module.0", channels.iterator().next().getTapChannelName());
}
private void refresh() {
this.configuration.refresh();
Collection<OutputChannelBinding> channels = this.adapter.getChannelsMetadata().getOutputChannels();
Collection<OutputChannelBinding> channels = this.adapter.getChannelsMetadata()
.getOutputChannels();
for (OutputChannelBinding channel : channels) {
channel.setTapped(true);
}
@@ -92,10 +105,49 @@ public class ChannelBindingAdapterConfigurationTests {
public void oneOutputTopic() throws Exception {
this.context.registerSingleton("output.topic:", new DirectChannel());
refresh();
Collection<OutputChannelBinding> channels = this.adapter.getChannelsMetadata().getOutputChannels();
Collection<OutputChannelBinding> channels = this.adapter.getChannelsMetadata()
.getOutputChannels();
assertEquals(1, channels.size());
assertEquals("topic:group.0", channels.iterator().next().getRemoteName());
assertEquals("tap:stream:group.module.0", channels.iterator().next().getTapChannelName());
assertEquals("tap:stream:group.module.0", channels.iterator().next()
.getTapChannelName());
}
@Test
public void oneOutputOverrideName() throws Exception {
this.module.setGroup("mine");
this.module.setName("foo");
this.module.setIndex(2);
this.context.registerSingleton("output.topic:", new DirectChannel());
refresh();
Collection<OutputChannelBinding> channels = this.adapter.getChannelsMetadata()
.getOutputChannels();
assertEquals(1, channels.size());
assertEquals("topic:mine.2", channels.iterator().next().getRemoteName());
assertEquals("tap:stream:mine.foo.2", channels.iterator().next()
.getTapChannelName());
}
@Test
public void oneInputTopic() throws Exception {
this.context.registerSingleton("input.topic:", new DirectChannel());
refresh();
Collection<InputChannelBinding> channels = this.adapter.getChannelsMetadata()
.getInputChannels();
assertEquals(1, channels.size());
assertEquals("topic:group.0", channels.iterator().next().getRemoteName());
}
@Test
public void oneInputOverrideName() throws Exception {
this.module.setGroup("mine");
this.module.setIndex(2);
this.context.registerSingleton("input", new DirectChannel());
refresh();
Collection<InputChannelBinding> channels = this.adapter.getChannelsMetadata()
.getInputChannels();
assertEquals(1, channels.size());
assertEquals("mine.1", channels.iterator().next().getRemoteName());
}
@Test
@@ -103,7 +155,8 @@ public class ChannelBindingAdapterConfigurationTests {
this.context.registerSingleton("output", new DirectChannel());
this.context.registerSingleton("output.queue:foo", new DirectChannel());
refresh();
Collection<OutputChannelBinding> channels = this.adapter.getChannelsMetadata().getOutputChannels();
Collection<OutputChannelBinding> channels = this.adapter.getChannelsMetadata()
.getOutputChannels();
List<String> names = getChannelNames(channels);
assertEquals(2, channels.size());
assertTrue(names.contains("group.0"));
@@ -123,11 +176,13 @@ public class ChannelBindingAdapterConfigurationTests {
this.module.setOutputChannelName("bar");
this.context.registerSingleton("output.queue:foo", new DirectChannel());
refresh();
Collection<OutputChannelBinding> channels = this.adapter.getChannelsMetadata().getOutputChannels();
Collection<OutputChannelBinding> channels = this.adapter.getChannelsMetadata()
.getOutputChannels();
assertEquals(1, channels.size());
assertEquals("foo.bar", channels.iterator().next().getRemoteName());
// TODO: fix this. What should it be?
assertEquals("tap:stream:foo.bar.module.0", channels.iterator().next().getTapChannelName());
assertEquals("tap:stream:foo.bar.module.0", channels.iterator().next()
.getTapChannelName());
}
@Test
@@ -135,10 +190,12 @@ public class ChannelBindingAdapterConfigurationTests {
this.module.setOutputChannelName("queue:bar");
this.context.registerSingleton("output.topic:foo", new DirectChannel());
refresh();
Collection<OutputChannelBinding> channels = this.adapter.getChannelsMetadata().getOutputChannels();
Collection<OutputChannelBinding> channels = this.adapter.getChannelsMetadata()
.getOutputChannels();
assertEquals(1, channels.size());
assertEquals("topic:foo.bar", channels.iterator().next().getRemoteName());
assertEquals("tap:stream:foo.bar.module.0", channels.iterator().next().getTapChannelName());
assertEquals("tap:stream:foo.bar.module.0", channels.iterator().next()
.getTapChannelName());
}
@Configuration

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.xd.dirt.modules.metadata;
package config;
import org.hibernate.validator.constraints.NotBlank;

View File

@@ -1 +1,2 @@
options_class = config.LogSinkOptionsMetadata
base_packages = config

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.xd.dirt.modules.metadata;
package demo;
import org.springframework.xd.module.options.mixins.MaxMessagesDefaultOneMixin;
import org.springframework.xd.module.options.mixins.PeriodicTriggerMixin;

View File

@@ -1 +1 @@
options_class = org.springframework.xd.dirt.modules.metadata.TimeSourceOptionsMetadata
options_class = demo.TimeSourceOptionsMetadata

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.xd.dirt.modules.metadata;
package config;
import org.springframework.xd.module.options.mixins.MaxMessagesDefaultOneMixin;
import org.springframework.xd.module.options.mixins.PeriodicTriggerMixin;

View File

@@ -1,2 +1,2 @@
options_class = org.springframework.xd.dirt.modules.metadata.TimeSourceOptionsMetadata
options_class = config.TimeSourceOptionsMetadata
base_packages = config