Exemplo n.º 1
0
  public void testMessageResequencer() throws Exception {
    MuleSession session = getTestSession(getTestService(), muleContext);
    Service testService = getTestService("test", Apple.class);
    assertNotNull(testService);

    SimpleEventResequencer router = new SimpleEventResequencer(3);
    router.setMuleContext(muleContext);
    router.initialise();

    MuleMessage message1 = new DefaultMuleMessage("test event A");
    MuleMessage message2 = new DefaultMuleMessage("test event B");
    MuleMessage message3 = new DefaultMuleMessage("test event C");
    message1.setCorrelationId(message1.getUniqueId());
    message2.setCorrelationId(message1.getUniqueId());
    message3.setCorrelationId(message1.getUniqueId());

    ImmutableEndpoint endpoint = getTestOutboundEndpoint("Test1Provider");
    MuleEvent event1 = new DefaultMuleEvent(message1, endpoint, session, false);
    MuleEvent event2 = new DefaultMuleEvent(message2, endpoint, session, false);
    MuleEvent event3 = new DefaultMuleEvent(message3, endpoint, session, false);
    assertTrue(router.isMatch(event1));
    assertTrue(router.isMatch(event2));
    assertTrue(router.isMatch(event3));

    assertNull(router.process(event2));
    assertNull(router.process(event3));

    MuleEvent[] results = router.process(event1);
    assertNotNull(results);
    assertEquals(3, results.length);

    assertEquals("test event B", results[0].getMessageAsString());
    assertEquals("test event C", results[1].getMessageAsString());
    assertEquals("test event A", results[2].getMessageAsString());

    // set a resequencing comparator. We need to reset the router since it will not process the same
    // event group
    // twice
    router = new SimpleEventResequencer(3);
    router.setMuleContext(muleContext);
    router.setEventComparator(new EventPayloadComparator());
    router.initialise();

    assertNull(router.process(event2));
    assertNull(router.process(event3));

    results = router.process(event1);
    assertNotNull(results);
    assertEquals(3, results.length);

    assertEquals("test event A", results[0].getMessageAsString());
    assertEquals("test event B", results[1].getMessageAsString());
    assertEquals("test event C", results[2].getMessageAsString());
  }
Exemplo n.º 2
0
  public void testMessageResequencer() throws Exception {
    Mock session = MuleTestUtils.getMockSession();
    UMOComponent testComponent = getTestComponent(getTestDescriptor("test", Apple.class.getName()));
    assertNotNull(testComponent);

    UMOInboundRouterCollection messageRouter = new InboundRouterCollection();
    SimpleEventResequencer router = new SimpleEventResequencer(3);
    messageRouter.addRouter(router);
    messageRouter.setCatchAllStrategy(new LoggingCatchAllStrategy());

    UMOMessage message1 = new MuleMessage("test event A");
    UMOMessage message2 = new MuleMessage("test event B");
    UMOMessage message3 = new MuleMessage("test event C");

    UMOEndpoint endpoint = getTestEndpoint("Test1Provider", UMOEndpoint.ENDPOINT_TYPE_SENDER);
    UMOEvent event1 = new MuleEvent(message1, endpoint, (UMOSession) session.proxy(), false);
    UMOEvent event2 = new MuleEvent(message2, endpoint, (UMOSession) session.proxy(), false);
    UMOEvent event3 = new MuleEvent(message3, endpoint, (UMOSession) session.proxy(), false);
    assertTrue(router.isMatch(event1));
    assertTrue(router.isMatch(event2));
    assertTrue(router.isMatch(event3));

    assertNull(router.process(event2));
    assertNull(router.process(event3));

    UMOEvent[] results = router.process(event1);
    assertNotNull(results);
    assertEquals(3, results.length);

    assertEquals("test event B", results[0].getMessageAsString());
    assertEquals("test event C", results[1].getMessageAsString());
    assertEquals("test event A", results[2].getMessageAsString());

    // set a resequencing comparator
    router.setComparator(new EventPayloadComparator());

    assertNull(router.process(event2));
    assertNull(router.process(event3));

    results = router.process(event1);
    assertNotNull(results);
    assertEquals(3, results.length);

    assertEquals("test event A", results[0].getMessageAsString());
    assertEquals("test event B", results[1].getMessageAsString());
    assertEquals("test event C", results[2].getMessageAsString());
  }