Search in sources :

Example 11 with BindingServiceProperties

use of org.springframework.cloud.stream.config.BindingServiceProperties in project spring-cloud-stream by spring-cloud.

the class BindingServiceTests method createBindingServiceProperties.

private BindingServiceProperties createBindingServiceProperties(HashMap<String, String> properties) {
    BindingServiceProperties bindingServiceProperties = new BindingServiceProperties();
    org.springframework.boot.context.properties.bind.Binder propertiesBinder = new org.springframework.boot.context.properties.bind.Binder(new MapConfigurationPropertySource(properties));
    propertiesBinder.bind("spring.cloud.stream", org.springframework.boot.context.properties.bind.Bindable.ofInstance(bindingServiceProperties));
    return bindingServiceProperties;
}
Also used : ExtendedPropertiesBinder(org.springframework.cloud.stream.binder.ExtendedPropertiesBinder) Binder(org.springframework.cloud.stream.binder.Binder) BindingServiceProperties(org.springframework.cloud.stream.config.BindingServiceProperties) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource)

Example 12 with BindingServiceProperties

use of org.springframework.cloud.stream.config.BindingServiceProperties in project spring-cloud-stream by spring-cloud.

the class BindingServiceTests method testUnknownBinderOnBindingFailure.

@Test
public void testUnknownBinderOnBindingFailure() {
    HashMap<String, String> properties = new HashMap<>();
    properties.put("spring.cloud.stream.bindings.input.destination", "fooInput");
    properties.put("spring.cloud.stream.bindings.input.binder", "mock");
    properties.put("spring.cloud.stream.bindings.output.destination", "fooOutput");
    properties.put("spring.cloud.stream.bindings.output.binder", "mockError");
    BindingServiceProperties bindingServiceProperties = createBindingServiceProperties(properties);
    BindingService bindingService = new BindingService(bindingServiceProperties, createMockBinderFactory());
    bindingService.bindConsumer(new DirectChannel(), "input");
    try {
        bindingService.bindProducer(new DirectChannel(), "output");
        fail("Expected 'Unknown binder configuration'");
    } catch (IllegalStateException e) {
        assertThat(e).hasMessageContaining("Unknown binder configuration: mockError");
    }
}
Also used : HashMap(java.util.HashMap) DirectChannel(org.springframework.integration.channel.DirectChannel) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) BindingServiceProperties(org.springframework.cloud.stream.config.BindingServiceProperties) Test(org.junit.Test)

Example 13 with BindingServiceProperties

use of org.springframework.cloud.stream.config.BindingServiceProperties in project spring-cloud-stream by spring-cloud.

the class BindingServiceTests method testUnrecognizedBinderAllowedIfNotUsed.

@Test
public void testUnrecognizedBinderAllowedIfNotUsed() {
    HashMap<String, String> properties = new HashMap<>();
    properties.put("spring.cloud.stream.bindings.input.destination", "fooInput");
    properties.put("spring.cloud.stream.bindings.output.destination", "fooOutput");
    properties.put("spring.cloud.stream.defaultBinder", "mock1");
    properties.put("spring.cloud.stream.binders.mock1.type", "mock");
    properties.put("spring.cloud.stream.binders.kafka1.type", "kafka");
    BindingServiceProperties bindingServiceProperties = createBindingServiceProperties(properties);
    DefaultBinderFactory binderFactory = new BinderFactoryConfiguration().binderFactory(createMockBinderTypeRegistry(), bindingServiceProperties);
    BindingService bindingService = new BindingService(bindingServiceProperties, binderFactory);
    bindingService.bindConsumer(new DirectChannel(), "input");
    bindingService.bindProducer(new DirectChannel(), "output");
}
Also used : HashMap(java.util.HashMap) DirectChannel(org.springframework.integration.channel.DirectChannel) BinderFactoryConfiguration(org.springframework.cloud.stream.config.BinderFactoryConfiguration) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) BindingServiceProperties(org.springframework.cloud.stream.config.BindingServiceProperties) DefaultBinderFactory(org.springframework.cloud.stream.binder.DefaultBinderFactory) Test(org.junit.Test)

Example 14 with BindingServiceProperties

use of org.springframework.cloud.stream.config.BindingServiceProperties in project spring-cloud-stream by spring-cloud.

the class BindingServiceTests method testMultipleConsumerBindings.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testMultipleConsumerBindings() throws Exception {
    BindingServiceProperties properties = new BindingServiceProperties();
    Map<String, BindingProperties> bindingProperties = new HashMap<>();
    BindingProperties props = new BindingProperties();
    props.setDestination("foo,bar");
    final String inputChannelName = "input";
    bindingProperties.put(inputChannelName, props);
    properties.setBindings(bindingProperties);
    DefaultBinderFactory binderFactory = createMockBinderFactory();
    Binder binder = binderFactory.getBinder("mock", MessageChannel.class);
    BindingService service = new BindingService(properties, binderFactory);
    MessageChannel inputChannel = new DirectChannel();
    Binding<MessageChannel> mockBinding1 = Mockito.mock(Binding.class);
    Binding<MessageChannel> mockBinding2 = Mockito.mock(Binding.class);
    when(binder.bindConsumer(eq("foo"), isNull(), same(inputChannel), any(ConsumerProperties.class))).thenReturn(mockBinding1);
    when(binder.bindConsumer(eq("bar"), isNull(), same(inputChannel), any(ConsumerProperties.class))).thenReturn(mockBinding2);
    Collection<Binding<MessageChannel>> bindings = service.bindConsumer(inputChannel, "input");
    assertThat(bindings).hasSize(2);
    Iterator<Binding<MessageChannel>> iterator = bindings.iterator();
    Binding<MessageChannel> binding1 = iterator.next();
    Binding<MessageChannel> binding2 = iterator.next();
    assertThat(binding1).isSameAs(mockBinding1);
    assertThat(binding2).isSameAs(mockBinding2);
    service.unbindConsumers("input");
    verify(binder).bindConsumer(eq("foo"), isNull(), same(inputChannel), any(ConsumerProperties.class));
    verify(binder).bindConsumer(eq("bar"), isNull(), same(inputChannel), any(ConsumerProperties.class));
    verify(binding1).unbind();
    verify(binding2).unbind();
    binderFactory.destroy();
}
Also used : Binding(org.springframework.cloud.stream.binder.Binding) HashMap(java.util.HashMap) DirectChannel(org.springframework.integration.channel.DirectChannel) BindingProperties(org.springframework.cloud.stream.config.BindingProperties) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ConsumerProperties(org.springframework.cloud.stream.binder.ConsumerProperties) DefaultBinderFactory(org.springframework.cloud.stream.binder.DefaultBinderFactory) ExtendedPropertiesBinder(org.springframework.cloud.stream.binder.ExtendedPropertiesBinder) Binder(org.springframework.cloud.stream.binder.Binder) MessageChannel(org.springframework.messaging.MessageChannel) BindingServiceProperties(org.springframework.cloud.stream.config.BindingServiceProperties) Test(org.junit.Test)

Example 15 with BindingServiceProperties

use of org.springframework.cloud.stream.config.BindingServiceProperties in project spring-cloud-stream by spring-cloud.

the class BindingServiceTests method testProducerPropertiesValidation.

@Test
public void testProducerPropertiesValidation() {
    BindingServiceProperties serviceProperties = new BindingServiceProperties();
    Map<String, BindingProperties> bindingProperties = new HashMap<>();
    BindingProperties props = new BindingProperties();
    ProducerProperties producerProperties = new ProducerProperties();
    producerProperties.setPartitionCount(0);
    props.setDestination("foo");
    props.setProducer(producerProperties);
    final String outputChannelName = "output";
    bindingProperties.put(outputChannelName, props);
    serviceProperties.setBindings(bindingProperties);
    DefaultBinderFactory binderFactory = createMockBinderFactory();
    BindingService service = new BindingService(serviceProperties, binderFactory);
    MessageChannel outputChannel = new DirectChannel();
    try {
        service.bindProducer(outputChannel, outputChannelName);
        fail("Producer properties should be validated.");
    } catch (IllegalStateException e) {
        assertThat(e).hasMessageContaining("Partition count should be greater than zero.");
    }
}
Also used : ProducerProperties(org.springframework.cloud.stream.binder.ProducerProperties) ExtendedProducerProperties(org.springframework.cloud.stream.binder.ExtendedProducerProperties) MessageChannel(org.springframework.messaging.MessageChannel) HashMap(java.util.HashMap) DirectChannel(org.springframework.integration.channel.DirectChannel) BindingProperties(org.springframework.cloud.stream.config.BindingProperties) BindingServiceProperties(org.springframework.cloud.stream.config.BindingServiceProperties) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DefaultBinderFactory(org.springframework.cloud.stream.binder.DefaultBinderFactory) Test(org.junit.Test)

Aggregations

BindingServiceProperties (org.springframework.cloud.stream.config.BindingServiceProperties)18 Test (org.junit.Test)14 BindingProperties (org.springframework.cloud.stream.config.BindingProperties)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)11 DirectChannel (org.springframework.integration.channel.DirectChannel)11 HashMap (java.util.HashMap)10 DefaultBinderFactory (org.springframework.cloud.stream.binder.DefaultBinderFactory)10 MessageChannel (org.springframework.messaging.MessageChannel)9 ExtendedPropertiesBinder (org.springframework.cloud.stream.binder.ExtendedPropertiesBinder)7 Binder (org.springframework.cloud.stream.binder.Binder)6 ConsumerProperties (org.springframework.cloud.stream.binder.ConsumerProperties)6 Binding (org.springframework.cloud.stream.binder.Binding)5 CompositeMessageConverterFactory (org.springframework.cloud.stream.converter.CompositeMessageConverterFactory)5 ProducerProperties (org.springframework.cloud.stream.binder.ProducerProperties)4 ExtendedProducerProperties (org.springframework.cloud.stream.binder.ExtendedProducerProperties)3 QueueChannel (org.springframework.integration.channel.QueueChannel)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Ignore (org.junit.Ignore)2 MessageConverterConfigurer (org.springframework.cloud.stream.binding.MessageConverterConfigurer)2