View Javadoc

1   /*
2    * $Id: XABridgeJmsJdbcTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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.test.integration.transaction;
12  
13  
14  import java.util.List;
15  
16  
17  public class XABridgeJmsJdbcTestCase extends AbstractDerbyTestCase
18  {
19      private static final int NUMBER_OF_MESSAGES = 1;
20      
21      protected String getConfigResources()
22      {
23          return "org/mule/test/integration/transaction/xabridge-jms-jdbc-mule.xml";
24      }
25  
26      @Override
27      protected void emptyTable() throws Exception
28      {
29          try
30          {
31              execSqlUpdate("DELETE FROM TEST");
32          }
33          catch (Exception e)
34          {
35              execSqlUpdate("CREATE TABLE TEST(ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 0) NOT NULL PRIMARY KEY,TYPE INTEGER,DATA VARCHAR(255),ACK TIMESTAMP,RESULT VARCHAR(255))");
36          }
37      }
38  
39      protected void doTestXaBridge(boolean rollback) throws Exception
40      {
41          XABridgeComponent.mayRollback = rollback;
42  
43          List results = execSqlQuery("SELECT * FROM TEST");
44          assertEquals(0, results.size());
45  
46          for (int i = 0; i < NUMBER_OF_MESSAGES; i++)
47          {
48              execSqlUpdate("INSERT INTO TEST(TYPE, DATA) VALUES (1, 'Test " + i + "')");
49          }
50          results = execSqlQuery("SELECT * FROM TEST WHERE TYPE = 1");
51          assertEquals(NUMBER_OF_MESSAGES, results.size());
52  
53          long t0 = System.currentTimeMillis();
54          while (true)
55          {
56              results = execSqlQuery("SELECT * FROM TEST WHERE TYPE = 2");
57              logger.info("Results found: " + results.size());
58              if (results.size() >= NUMBER_OF_MESSAGES)
59              {
60                  break;
61              }
62              System.out.println("Time elapsed: " + (System.currentTimeMillis() - t0));
63              assertTrue(System.currentTimeMillis() - t0 < 40000);
64              Thread.sleep(500);
65          }
66          
67          assertTrue(results.size() >= NUMBER_OF_MESSAGES);
68      }
69  
70      public void testXaBridgeWithoutRollbacks() throws Exception
71      {
72          doTestXaBridge(false);
73      }
74  
75      public void testXaBridgeWithRollbacks() throws Exception
76      {
77          doTestXaBridge(true);
78      }
79  }