Search in sources :

Example 6 with RoundRobinLoadBalancingStrategy

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"));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) RoundRobinLoadBalancingStrategy(org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy) Log(org.apache.commons.logging.Log) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) UnicastingDispatcher(org.springframework.integration.dispatcher.UnicastingDispatcher) Test(org.junit.Test)

Example 7 with RoundRobinLoadBalancingStrategy

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();
}
Also used : RoundRobinLoadBalancingStrategy(org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 8 with RoundRobinLoadBalancingStrategy

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);
}
Also used : RoundRobinLoadBalancingStrategy(org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy) UnicastingDispatcher(org.springframework.integration.dispatcher.UnicastingDispatcher) BroadcastingDispatcher(org.springframework.integration.dispatcher.BroadcastingDispatcher)

Aggregations

RoundRobinLoadBalancingStrategy (org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy)8 Test (org.junit.Test)6 UnicastingDispatcher (org.springframework.integration.dispatcher.UnicastingDispatcher)4 CountDownLatch (java.util.concurrent.CountDownLatch)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 ConcurrentTaskExecutor (org.springframework.scheduling.concurrent.ConcurrentTaskExecutor)2 CustomizableThreadFactory (org.springframework.scheduling.concurrent.CustomizableThreadFactory)2 Log (org.apache.commons.logging.Log)1 InOrder (org.mockito.InOrder)1 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)1 MessageRejectedException (org.springframework.integration.MessageRejectedException)1 BroadcastingDispatcher (org.springframework.integration.dispatcher.BroadcastingDispatcher)1 MessageChannel (org.springframework.messaging.MessageChannel)1 GenericMessage (org.springframework.messaging.support.GenericMessage)1