View Javadoc

1   /*
2    * $Id: JmsXaTransactionConsumeAllMessagesTestCase.java 23154 2011-10-12 06:00:08Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.jms.integration;
12  
13  import org.hamcrest.core.IsNull;
14  import org.junit.Test;
15  import org.mule.api.MuleEventContext;
16  import org.mule.api.MuleMessage;
17  import org.mule.module.client.MuleClient;
18  import org.mule.tck.functional.EventCallback;
19  import org.mule.tck.functional.FunctionalTestComponent;
20  import org.mule.util.concurrent.Latch;
21  
22  import java.util.concurrent.CountDownLatch;
23  import java.util.concurrent.TimeUnit;
24  
25  import static org.junit.Assert.*;
26  import static org.junit.Assert.assertThat;
27  
28  /**
29   * Testing durable topic with XA transactions
30   */
31  public class JmsXaTransactionConsumeAllMessagesTestCase extends AbstractJmsFunctionalTestCase
32  {
33  
34      public static final String MESSAGE = "some message";
35      public static final int TOTAL_MESSAGES = 50;
36  
37      @Override
38      protected String getConfigResources()
39      {
40          return "integration/jms-consume-all-messages-tx-xa.xml";
41      }
42  
43      @Test
44      public void testSendSeveralMessagesAndRetrieveThemAll() throws Exception
45      {
46          MuleClient muleClient = new MuleClient(muleContext);
47          FunctionalTestComponent ftc = getFunctionalTestComponent("IncomingMessageConsumer");
48          final CountDownLatch allMessageReceived = new CountDownLatch(TOTAL_MESSAGES);
49          ftc.setEventCallback(new EventCallback()
50          {
51              public void eventReceived(MuleEventContext context, Object component) throws Exception
52              {
53                  allMessageReceived.countDown();
54              }
55          });
56          for (int i = 0; i < TOTAL_MESSAGES; i++) {
57              muleClient.dispatch("in", MESSAGE, null);
58          }
59          allMessageReceived.await(3000, TimeUnit.MILLISECONDS);
60          for (int i = 0; i < TOTAL_MESSAGES; i++) {
61              MuleMessage muleMessage = muleClient.request("out", 300);
62              assertThat(muleMessage, IsNull.<Object>notNullValue());
63          }
64      }
65  }