use of org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy in project spring-integration by spring-projects.
the class DirectChannelTests method testSend.
@Test
public void testSend() {
DirectChannel channel = new DirectChannel();
Log logger = spy(TestUtils.getPropertyValue(channel, "logger", Log.class));
when(logger.isDebugEnabled()).thenReturn(true);
new DirectFieldAccessor(channel).setPropertyValue("logger", logger);
ThreadNameExtractingTestTarget target = new ThreadNameExtractingTestTarget();
channel.subscribe(target);
GenericMessage<String> message = new GenericMessage<String>("test");
assertTrue(channel.send(message));
assertEquals(Thread.currentThread().getName(), target.threadName);
DirectFieldAccessor channelAccessor = new DirectFieldAccessor(channel);
UnicastingDispatcher dispatcher = (UnicastingDispatcher) channelAccessor.getPropertyValue("dispatcher");
DirectFieldAccessor dispatcherAccessor = new DirectFieldAccessor(dispatcher);
Object loadBalancingStrategy = dispatcherAccessor.getPropertyValue("loadBalancingStrategy");
assertTrue(loadBalancingStrategy instanceof RoundRobinLoadBalancingStrategy);
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(logger, times(2)).debug(captor.capture());
List<String> logs = captor.getAllValues();
assertEquals(2, logs.size());
assertThat(logs.get(0), startsWith("preSend"));
assertThat(logs.get(1), startsWith("postSend"));
}
use of org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy in project spring-integration by spring-projects.
the class DirectChannelParserTests method testReceivesMessageFromChannelWithSource.
@Test
public void testReceivesMessageFromChannelWithSource() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("directChannelParserTests.xml", DirectChannelParserTests.class);
Object channel = context.getBean("channel");
assertEquals(DirectChannel.class, channel.getClass());
DirectFieldAccessor dcAccessor = new DirectFieldAccessor(((DirectChannel) channel).getDispatcher());
assertTrue(dcAccessor.getPropertyValue("loadBalancingStrategy") instanceof RoundRobinLoadBalancingStrategy);
context.close();
}
use of org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy in project spring-integration by spring-projects.
the class SubscribableJmsChannel method configureDispatcher.
private void configureDispatcher(boolean isPubSub) {
if (isPubSub) {
BroadcastingDispatcher broadcastingDispatcher = new BroadcastingDispatcher(true);
broadcastingDispatcher.setBeanFactory(this.getBeanFactory());
this.dispatcher = broadcastingDispatcher;
} else {
UnicastingDispatcher unicastingDispatcher = new UnicastingDispatcher();
unicastingDispatcher.setLoadBalancingStrategy(new RoundRobinLoadBalancingStrategy());
this.dispatcher = unicastingDispatcher;
}
if (this.maxSubscribers == null) {
this.maxSubscribers = this.getIntegrationProperty(isPubSub ? IntegrationProperties.CHANNELS_MAX_BROADCAST_SUBSCRIBERS : IntegrationProperties.CHANNELS_MAX_UNICAST_SUBSCRIBERS, Integer.class);
}
this.dispatcher.setMaxSubscribers(this.maxSubscribers);
}
Aggregations