Ejemplo n.º 1
0
  public void testSendingAMessageUsingMulticastReceivesItsOwnExchangeParallel() throws Exception {
    MockEndpoint resultEndpoint = getMockEndpoint("mock:result");

    resultEndpoint.expectsNoDuplicates(body());
    resultEndpoint.expectedMessageCount(4);

    // InOnly
    template.send(
        "direct:parallel",
        new Processor() {
          public void process(Exchange exchange) {
            Message in = exchange.getIn();
            in.setBody("James,Guillaume,Hiram,Rob");
            in.setHeader("foo", "bar");
          }
        });

    assertMockEndpointsSatisfied();

    List<Exchange> list = resultEndpoint.getReceivedExchanges();
    Set<Integer> numbersFound = new TreeSet<Integer>();
    final String[] names = {"James", "Guillaume", "Hiram", "Rob"};

    for (int i = 0; i < 4; i++) {
      Exchange exchange = list.get(i);
      Message in = exchange.getIn();
      Integer splitCounter = exchange.getProperty(Exchange.SPLIT_INDEX, Integer.class);
      numbersFound.add(splitCounter);
      assertEquals(names[splitCounter], in.getBody());
      assertProperty(exchange, Exchange.SPLIT_SIZE, 4);
    }

    assertEquals(4, numbersFound.size());
  }
  public void testXPathSplitStream() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:splitted");
    mock.expectedMessageCount(size);
    mock.expectsNoDuplicates().body();

    assertMockEndpointsSatisfied();
  }
  public void testConcurrentPipeline() throws Exception {
    int total = 200;
    final int group = total / 20;
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(total);

    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(20);
    executor.afterPropertiesSet();
    for (int i = 0; i < 20; i++) {
      final int threadCount = i;
      executor.execute(
          new Runnable() {
            public void run() {
              int start = threadCount * group;
              for (int i = 0; i < group; i++) {
                try {
                  // do some random sleep to simulate spread in user activity
                  Thread.sleep(new Random().nextInt(10));
                } catch (InterruptedException e) {
                  // ignore
                }
                template.sendBody(uri, "" + (start + i));
              }
            }
          });
    }

    mock.assertIsSatisfied();
    mock.expectsNoDuplicates(body());
    executor.shutdown();
  }