Search in sources :

Example 1 with ConcurrentTaskExecutor

use of org.springframework.scheduling.concurrent.ConcurrentTaskExecutor in project iaf by ibissource.

the class ForEachChildElementPipeTest method testBulk2Parallel.

@Test
public void testBulk2Parallel() throws Exception, IOException {
    pipe.setSender(getElementRenderer());
    pipe.setTargetElement("XDOC");
    pipe.setBlockSize(4);
    pipe.setParallel(true);
    pipe.setTaskExecutor(new ConcurrentTaskExecutor());
    pipe.setMaxChildThreads(2);
    pipe.setRemoveNamespaces(false);
    configurePipe();
    pipe.start();
    String input = TestFileUtils.getTestFile("/ForEachChildElementPipe/bulk2.xml");
    String expected = TestFileUtils.getTestFile("/ForEachChildElementPipe/bulk2out.xml");
    PipeRunResult prr = doPipe(pipe, input, session);
    String actual = Message.asString(prr.getResult());
    assertEquals(expected, actual);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ConcurrentTaskExecutor(org.springframework.scheduling.concurrent.ConcurrentTaskExecutor) Test(org.junit.Test)

Example 2 with ConcurrentTaskExecutor

use of org.springframework.scheduling.concurrent.ConcurrentTaskExecutor in project spring-integration by spring-projects.

the class ExecutorChannelTests method verifyFailoverWithLoadBalancing.

@Test
public void verifyFailoverWithLoadBalancing() throws Exception {
    int numberOfMessages = 11;
    ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(new CustomizableThreadFactory("test-"));
    ConcurrentTaskExecutor taskExecutor = new ConcurrentTaskExecutor(exec);
    ExecutorChannel channel = new ExecutorChannel(taskExecutor, new RoundRobinLoadBalancingStrategy());
    CountDownLatch latch = new CountDownLatch(numberOfMessages);
    TestHandler handler1 = new TestHandler(latch);
    TestHandler handler2 = new TestHandler(latch);
    TestHandler handler3 = new TestHandler(latch);
    channel.subscribe(handler1);
    channel.subscribe(handler2);
    channel.subscribe(handler3);
    handler2.shouldFail = true;
    for (int i = 0; i < numberOfMessages; i++) {
        channel.send(new GenericMessage<String>("test-" + i));
    }
    latch.await(3000, TimeUnit.MILLISECONDS);
    assertEquals(0, latch.getCount());
    assertNotNull(handler1.thread);
    assertFalse(Thread.currentThread().equals(handler1.thread));
    assertTrue(handler1.thread.getName().startsWith("test-"));
    assertNotNull(handler2.thread);
    assertFalse(Thread.currentThread().equals(handler2.thread));
    assertTrue(handler2.thread.getName().startsWith("test-"));
    assertNotNull(handler3.thread);
    assertFalse(Thread.currentThread().equals(handler3.thread));
    assertTrue(handler3.thread.getName().startsWith("test-"));
    assertEquals(0, handler2.count.get());
    assertEquals(4, handler1.count.get());
    assertEquals(7, handler3.count.get());
    exec.shutdownNow();
}
Also used : CustomizableThreadFactory(org.springframework.scheduling.concurrent.CustomizableThreadFactory) RoundRobinLoadBalancingStrategy(org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ConcurrentTaskExecutor(org.springframework.scheduling.concurrent.ConcurrentTaskExecutor) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 3 with ConcurrentTaskExecutor

use of org.springframework.scheduling.concurrent.ConcurrentTaskExecutor in project spring-integration by spring-projects.

the class ExecutorChannelTests method roundRobinLoadBalancing.

@Test
public void roundRobinLoadBalancing() throws Exception {
    int numberOfMessages = 11;
    ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(new CustomizableThreadFactory("test-"));
    ConcurrentTaskExecutor taskExecutor = new ConcurrentTaskExecutor(exec);
    ExecutorChannel channel = new ExecutorChannel(taskExecutor, new RoundRobinLoadBalancingStrategy());
    CountDownLatch latch = new CountDownLatch(numberOfMessages);
    TestHandler handler1 = new TestHandler(latch);
    TestHandler handler2 = new TestHandler(latch);
    TestHandler handler3 = new TestHandler(latch);
    channel.subscribe(handler1);
    channel.subscribe(handler2);
    channel.subscribe(handler3);
    for (int i = 0; i < numberOfMessages; i++) {
        channel.send(new GenericMessage<String>("test-" + i));
    }
    latch.await(3000, TimeUnit.MILLISECONDS);
    assertEquals(0, latch.getCount());
    assertNotNull(handler1.thread);
    assertFalse(Thread.currentThread().equals(handler1.thread));
    assertTrue(handler1.thread.getName().startsWith("test-"));
    assertNotNull(handler2.thread);
    assertFalse(Thread.currentThread().equals(handler2.thread));
    assertTrue(handler2.thread.getName().startsWith("test-"));
    assertNotNull(handler3.thread);
    assertFalse(Thread.currentThread().equals(handler3.thread));
    assertTrue(handler3.thread.getName().startsWith("test-"));
    assertEquals(4, handler1.count.get());
    assertEquals(4, handler2.count.get());
    assertEquals(3, handler3.count.get());
    exec.shutdownNow();
}
Also used : CustomizableThreadFactory(org.springframework.scheduling.concurrent.CustomizableThreadFactory) RoundRobinLoadBalancingStrategy(org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ConcurrentTaskExecutor(org.springframework.scheduling.concurrent.ConcurrentTaskExecutor) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 4 with ConcurrentTaskExecutor

use of org.springframework.scheduling.concurrent.ConcurrentTaskExecutor in project spring-integration by spring-projects.

the class ExecutorChannelTests method verifyFailoverWithoutLoadBalancing.

@Test
public void verifyFailoverWithoutLoadBalancing() throws Exception {
    int numberOfMessages = 11;
    ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(new CustomizableThreadFactory("test-"));
    ConcurrentTaskExecutor taskExecutor = new ConcurrentTaskExecutor(exec);
    ExecutorChannel channel = new ExecutorChannel(taskExecutor, null);
    CountDownLatch latch = new CountDownLatch(numberOfMessages);
    TestHandler handler1 = new TestHandler(latch);
    TestHandler handler2 = new TestHandler(latch);
    TestHandler handler3 = new TestHandler(latch);
    channel.subscribe(handler1);
    channel.subscribe(handler2);
    channel.subscribe(handler3);
    handler1.shouldFail = true;
    for (int i = 0; i < numberOfMessages; i++) {
        channel.send(new GenericMessage<String>("test-" + i));
    }
    latch.await(3000, TimeUnit.MILLISECONDS);
    assertEquals(0, latch.getCount());
    assertNotNull(handler1.thread);
    assertFalse(Thread.currentThread().equals(handler1.thread));
    assertTrue(handler1.thread.getName().startsWith("test-"));
    assertNotNull(handler2.thread);
    assertFalse(Thread.currentThread().equals(handler2.thread));
    assertTrue(handler2.thread.getName().startsWith("test-"));
    assertNull(handler3.thread);
    assertEquals(0, handler1.count.get());
    assertEquals(0, handler3.count.get());
    assertEquals(numberOfMessages, handler2.count.get());
    exec.shutdownNow();
}
Also used : CustomizableThreadFactory(org.springframework.scheduling.concurrent.CustomizableThreadFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ConcurrentTaskExecutor(org.springframework.scheduling.concurrent.ConcurrentTaskExecutor) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 5 with ConcurrentTaskExecutor

use of org.springframework.scheduling.concurrent.ConcurrentTaskExecutor in project iaf by ibissource.

the class IteratingPipeTest method testParallel.

@Test
public void testParallel() throws Exception {
    pipe.setSender(getElementRenderer(false));
    pipe.setParallel(true);
    pipe.setMaxChildThreads(1);
    pipe.setTaskExecutor(new ConcurrentTaskExecutor());
    configurePipe();
    pipe.start();
    testTenLines();
    String expectedRenderResult = TestFileUtils.getTestFile("/IteratingPipe/TenLinesLogPlain.txt");
    assertEquals(expectedRenderResult, resultLog.toString().trim());
}
Also used : ConcurrentTaskExecutor(org.springframework.scheduling.concurrent.ConcurrentTaskExecutor) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 ConcurrentTaskExecutor (org.springframework.scheduling.concurrent.ConcurrentTaskExecutor)5 CountDownLatch (java.util.concurrent.CountDownLatch)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 CustomizableThreadFactory (org.springframework.scheduling.concurrent.CustomizableThreadFactory)3 RoundRobinLoadBalancingStrategy (org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy)2 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)1