示例#1
0
  public void testSendTransactedRollback() throws Exception {
    final int countDownInitialCount = 2;
    final CountDownLatch countDown = new CountDownLatch(countDownInitialCount);

    // This exception strategy will be invoked when a message is redelivered
    // after a rollback

    // setup the component and start Mule
    UMODescriptor descriptor =
        getDescriptor("testComponent", FunctionalTestComponent.class.getName());

    EventCallback callback =
        new EventCallback() {
          public void eventReceived(UMOEventContext context, Object Component) throws Exception {
            callbackCalled = true;
            currentTx = context.getCurrentTransaction();
            assertNotNull(currentTx);
            assertTrue(currentTx.isBegun());
            System.out.println("@@@@ Rolling back transaction @@@@");
            currentTx.setRollbackOnly();
            countDown.countDown();
          }
        };

    initialiseComponent(descriptor, UMOTransactionConfig.ACTION_ALWAYS_BEGIN, callback);
    UMOManager manager = MuleManager.getInstance();
    addResultListener(getOutDest().getAddress(), countDown);

    UMOConnector umoCnn = manager.lookupConnector(CONNECTOR_NAME);
    // Set the test Exception strategy
    umoCnn.setExceptionListener(new RollbackExceptionListener(countDown));

    // Start the server
    manager.start();

    // Send a test message firstso that it is there when the component is
    // started
    send(DEFAULT_MESSAGE, false, Session.AUTO_ACKNOWLEDGE);

    afterInitialise();
    countDown.tryLock(LOCK_WAIT, TimeUnit.MILLISECONDS);
    assertTrue(
        "Only "
            + (countDownInitialCount - countDown.getCount())
            + " of "
            + countDownInitialCount
            + " checkpoints hit",
        countDown.tryLock());

    // Sleep a while to allow transaction to be rolled back
    afterInitialise();

    assertNull(currentMsg);
    assertTrue(callbackCalled);
    assertTrue(currentTx.isRolledBack());

    // Make sure the message isn't on the queue
    assertNull(receive(getInDest().getAddress(), 2000));
  }
示例#2
0
  public void testTransactedRedeliveryToDLDestination() throws Exception {
    // there are 2 check points for each message delivered, so
    // the message will be delivered twice before this countdown will release
    final int countDownInitialCount = 4;
    final CountDownLatch countDown = new CountDownLatch(countDownInitialCount);

    // setup the component and start Mule
    UMODescriptor descriptor =
        getDescriptor("testComponent", FunctionalTestComponent.class.getName());

    EventCallback callback =
        new EventCallback() {
          public void eventReceived(UMOEventContext context, Object Component) throws Exception {
            callbackCalled = true;
            currentTx = context.getCurrentTransaction();
            assertNotNull(currentTx);
            assertTrue(currentTx.isBegun());
            System.out.println("@@@@ Rolling back transaction @@@@");
            currentTx.setRollbackOnly();
            countDown.countDown();
          }
        };

    initialiseComponent(descriptor, UMOTransactionConfig.ACTION_ALWAYS_BEGIN, callback);
    UMOManager manager = MuleManager.getInstance();
    addResultListener(getDLDest().getAddress(), countDown);

    JmsConnector umoCnn = (JmsConnector) manager.lookupConnector(CONNECTOR_NAME);

    // After redelivery retry the message and then fail
    umoCnn.setMaxRedelivery(1);

    // Set the test Exception strategy
    umoCnn.setExceptionListener(new RollbackExceptionListener(countDown, getDLDest()));

    // Start the server
    manager.start();

    // Send a test message firstso that it is there when the component is
    // started
    send(DEFAULT_MESSAGE, false, Session.AUTO_ACKNOWLEDGE);

    afterInitialise();
    countDown.tryLock(LOCK_WAIT, TimeUnit.MILLISECONDS);
    assertTrue(
        "Only "
            + (countDownInitialCount - countDown.getCount())
            + " of "
            + countDownInitialCount
            + " checkpoints hit",
        countDown.tryLock());

    assertNotNull(currentMsg);
    System.out.println(currentMsg);
    String dest = currentMsg.getStringProperty(MuleProperties.MULE_ENDPOINT_PROPERTY);
    assertNotNull(dest);
    assertEquals(getDLDest().getUri().toString(), dest);
    assertTrue(callbackCalled);

    // Make sure the message isn't on the queue
    assertNull(receive(getInDest().getAddress(), 2000));
  }