Author: bvahdat
Date: Sat Dec  8 07:53:20 2012
New Revision: 1418616

URL: http://svn.apache.org/viewvc?rev=1418616&view=rev
Log:
CAMEL-5856: Fix and reenable the two JMS/JDBC Integration tests.

Removed:
    camel/trunk/tests/camel-itest/src/test/resources/sql/init2.sql
Modified:
    camel/trunk/tests/camel-itest/pom.xml
    
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsTest.java
    
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsXaTest.java
    
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsTest.xml
    
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsXaTest.xml

Modified: camel/trunk/tests/camel-itest/pom.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/pom.xml?rev=1418616&r1=1418615&r2=1418616&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/pom.xml (original)
+++ camel/trunk/tests/camel-itest/pom.xml Sat Dec  8 07:53:20 2012
@@ -357,11 +357,9 @@
         <configuration>
           <forkMode>pertest</forkMode>
           <forkedProcessTimeoutInSeconds>3000</forkedProcessTimeoutInSeconds>
-          <excludes>
-            <!-- TODO FIXME ASAP -->
-            <exclude>**/FromJmsToJdbcIdempotentConsumerToJmsTest.*</exclude>
-            <exclude>**/FromJmsToJdbcIdempotentConsumerToJmsXaTest.*</exclude>
-          </excludes>
+          <systemPropertyVariables>
+            <derby.stream.error.file>target/derby.log</derby.stream.error.file>
+          </systemPropertyVariables>
         </configuration>
       </plugin>
       <plugin>

Modified: 
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsTest.java?rev=1418616&r1=1418615&r2=1418616&view=diff
==============================================================================
--- 
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsTest.java
 (original)
+++ 
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsTest.java
 Sat Dec  8 07:53:20 2012
@@ -51,11 +51,15 @@ public class FromJmsToJdbcIdempotentCons
     public void setUp() throws Exception {
         super.setUp();
 
-        dataSource = context.getRegistry().lookup("myNonXADataSource", 
DataSource.class);
+        dataSource = context.getRegistry().lookup(getDatasourceName(), 
DataSource.class);
         jdbcTemplate = new JdbcTemplate(dataSource);
         jdbcTemplate.afterPropertiesSet();
     }
 
+    protected String getDatasourceName() {
+        return "myNonXADataSource";
+    }
+
     @Test
     public void testJmsToJdbcJmsCommit() throws Exception {
         checkInitialState();
@@ -74,7 +78,7 @@ public class FromJmsToJdbcIdempotentCons
         assertTrue("Should complete 1 message", notify.matchesMockWaitTime());
 
         // check that there is a message in the database and JMS queue
-        assertEquals(1, jdbcTemplate.queryForInt("select count(*) from  
CAMEL_MESSAGEPROCESSED"));
+        assertEquals(1, jdbcTemplate.queryForInt("select count(*) from 
CAMEL_MESSAGEPROCESSED"));
         Object out = consumer.receiveBody("activemq:queue:outbox", 3000);
         assertEquals("DONE-A", out);
     }
@@ -86,6 +90,7 @@ public class FromJmsToJdbcIdempotentCons
         // use a notify to know that after 1+6 (1 original + 6 redelivery) 
attempts from AcitveMQ
         NotifyBuilder notify = new NotifyBuilder(context).whenDone(7).create();
 
+        // TODO: occasionally we get only 6 instead of 7 expected exchanges 
which's most probably an issue in AcitveMQ itself
         getMockEndpoint("mock:a").expectedMessageCount(7);
         // force exception to occur at mock a
         getMockEndpoint("mock:a").whenAnyExchangeReceived(new Processor() {
@@ -103,7 +108,7 @@ public class FromJmsToJdbcIdempotentCons
         assertTrue("Should complete 7 message", notify.matchesMockWaitTime());
 
         // check that there is a message in the database and JMS queue
-        assertEquals(0, jdbcTemplate.queryForInt("select count(*) from  
CAMEL_MESSAGEPROCESSED"));
+        assertEquals(0, jdbcTemplate.queryForInt("select count(*) from 
CAMEL_MESSAGEPROCESSED"));
         assertNull(consumer.receiveBody("activemq:queue:outbox", 3000));
 
         // the message should have been moved to the AMQ DLQ queue
@@ -134,7 +139,7 @@ public class FromJmsToJdbcIdempotentCons
         assertTrue("Should complete 7 messages", notify.matchesMockWaitTime());
 
         // check that there is a message in the database and JMS queue
-        assertEquals(0, jdbcTemplate.queryForInt("select count(*) from  
CAMEL_MESSAGEPROCESSED"));
+        assertEquals(0, jdbcTemplate.queryForInt("select count(*) from 
CAMEL_MESSAGEPROCESSED"));
         assertNull(consumer.receiveBody("activemq:queue:outbox", 3000));
 
         // the message should have been moved to the AMQ DLQ queue
@@ -162,17 +167,17 @@ public class FromJmsToJdbcIdempotentCons
         assertTrue("Should complete 3 messages", notify.matchesMockWaitTime());
 
         // check that there is two messages in the database and JMS queue
-        assertEquals(2, jdbcTemplate.queryForInt("select count(*) from  
CAMEL_MESSAGEPROCESSED"));
+        assertEquals(2, jdbcTemplate.queryForInt("select count(*) from 
CAMEL_MESSAGEPROCESSED"));
         assertEquals("DONE-D", consumer.receiveBody("activemq:queue:outbox", 
3000));
         assertEquals("DONE-E", consumer.receiveBody("activemq:queue:outbox", 
3000));
     }
-    
+
     @Test
     public void testRetryAfterException() throws Exception {
         checkInitialState();
-        
+
         final AtomicInteger counter = new AtomicInteger();
-        
+
         // use a notify to know when the message is done
         NotifyBuilder notify = new NotifyBuilder(context).whenDone(4).create();
 
@@ -198,25 +203,24 @@ public class FromJmsToJdbcIdempotentCons
         assertTrue("Should complete 4 messages", notify.matchesMockWaitTime());
 
         // check that there is two messages in the database and JMS queue
-        assertEquals(3, jdbcTemplate.queryForInt("select count(*) from  
CAMEL_MESSAGEPROCESSED"));
+        assertEquals(3, jdbcTemplate.queryForInt("select count(*) from 
CAMEL_MESSAGEPROCESSED"));
         assertEquals("DONE-D", consumer.receiveBody("activemq:queue:outbox", 
3000));
         assertEquals("DONE-E", consumer.receiveBody("activemq:queue:outbox", 
3000));
         assertEquals("DONE-F", consumer.receiveBody("activemq:queue:outbox", 
3000));
     }
-    
+
     protected void checkInitialState() {
         // check there are no messages in the database and JMS queue
-        assertEquals(0, jdbcTemplate.queryForInt("select count(*) from  
CAMEL_MESSAGEPROCESSED"));
+        assertEquals(0, jdbcTemplate.queryForInt("select count(*) from 
CAMEL_MESSAGEPROCESSED"));
         assertNull(consumer.receiveBody("activemq:queue:outbox", 2000));
     }
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
-            @SuppressWarnings("unchecked")
             @Override
             public void configure() throws Exception {
-                IdempotentRepository<String> repository = 
context.getRegistry().lookup("messageIdRepository", IdempotentRepository.class);
+                IdempotentRepository<?> repository = 
context.getRegistry().lookup("messageIdRepository", IdempotentRepository.class);
 
                 from("activemq:queue:inbox")
                     .transacted("required")

Modified: 
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsXaTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsXaTest.java?rev=1418616&r1=1418615&r2=1418616&view=diff
==============================================================================
--- 
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsXaTest.java
 (original)
+++ 
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsXaTest.java
 Sat Dec  8 07:53:20 2012
@@ -16,15 +16,47 @@
  */
 package org.apache.camel.itest.sql;
 
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import org.junit.After;
+import org.junit.Before;
+
 import org.springframework.context.support.AbstractApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 /**
- * Jms with JDBC idempotent consumer using XA test.
+ * Jms with JDBC idempotent consumer test using XA.
  */
 public class FromJmsToJdbcIdempotentConsumerToJmsXaTest extends 
FromJmsToJdbcIdempotentConsumerToJmsTest {
 
     @Override
+    @Before
+    public void setUp() throws Exception {
+        deleteDirectory("target/testdb");
+
+        super.setUp();
+    }
+
+    @Override
+    @After
+    public void tearDown() throws Exception {
+        super.tearDown();
+
+        // shutdown the embedded Derby database so that the next test becomes 
a clean initial state 
+        try {
+            
DriverManager.getConnection("jdbc:derby:target/testdb;shutdown=true");
+        } catch (SQLException e) {
+            // a successful shutdown always results in an SQLException to 
indicate that Derby has shut down and that there is no other exception.
+        }
+    }
+
+    @Override
+    protected String getDatasourceName() {
+        return "myXADataSource";
+    }
+
+    @Override
     protected AbstractApplicationContext createApplicationContext() {
         return new 
ClassPathXmlApplicationContext("org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsXaTest.xml");
     }

Modified: 
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsTest.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsTest.xml?rev=1418616&r1=1418615&r2=1418616&view=diff
==============================================================================
--- 
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsTest.xml
 (original)
+++ 
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsTest.xml
 Sat Dec  8 07:53:20 2012
@@ -24,9 +24,9 @@
            http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
            http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
            http://www.springframework.org/schema/jdbc 
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
-           http://activemq.apache.org/schema/core 
http://activemq.apache.org/schema/core/activemq-core-5.5.0.xsd";>
+           http://activemq.apache.org/schema/core 
http://activemq.apache.org/schema/core/activemq-core.xsd";>
 
-    <!-- jdbc idempotent repository -->
+    <!-- jdbc idempotent repository, per default creates the table 
CAMEL_MESSAGEPROCESSED if not already existing -->
     <bean id="messageIdRepository" 
class="org.apache.camel.processor.idempotent.jdbc.JdbcMessageIdRepository">
         <constructor-arg index="0" ref="myNonXADataSource"/>
         <constructor-arg index="1" value="myProcessor"/>
@@ -67,7 +67,5 @@
     </broker:broker>
 
     <!-- datasource used to create the database tables -->
-    <jdbc:embedded-database id="myNonXADataSource" type="DERBY">
-       <jdbc:script location="classpath:sql/init2.sql" />
-    </jdbc:embedded-database>
+    <jdbc:embedded-database id="myNonXADataSource" type="DERBY"/>
 </beans>
\ No newline at end of file

Modified: 
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsXaTest.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsXaTest.xml?rev=1418616&r1=1418615&r2=1418616&view=diff
==============================================================================
--- 
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsXaTest.xml
 (original)
+++ 
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/sql/FromJmsToJdbcIdempotentConsumerToJmsXaTest.xml
 Sat Dec  8 07:53:20 2012
@@ -24,11 +24,11 @@
            http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
            http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
            http://www.springframework.org/schema/jdbc 
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
-           http://activemq.apache.org/schema/core 
http://activemq.apache.org/schema/core/activemq-core-5.5.0.xsd";>
+           http://activemq.apache.org/schema/core 
http://activemq.apache.org/schema/core/activemq-core.xsd";>
 
-    <!-- jdbc idempotent repository -->
+    <!-- jdbc idempotent repository, per default creates the table 
CAMEL_MESSAGEPROCESSED if not already existing -->
     <bean id="messageIdRepository" 
class="org.apache.camel.processor.idempotent.jdbc.JdbcMessageIdRepository">
-        <constructor-arg index="0" ref="myDataSource"/>
+        <constructor-arg index="0" ref="myXADataSource"/>
         <constructor-arg index="1" ref="requiredTemplate"/>
         <constructor-arg index="2" value="myProcessor"/>
     </bean>
@@ -89,17 +89,10 @@
             <broker:transportConnector uri="tcp://localhost:61616"/>
         </broker:transportConnectors>
     </broker:broker>
-    
-    <!-- datasource used to create the database tables -->
-    <jdbc:embedded-database id="myNonXADataSource" type="DERBY">
-       <jdbc:script location="classpath:sql/init.sql" />
-    </jdbc:embedded-database>
-
-    <!-- define the datasource to the database - in this example we use an in 
memory database using Derby -->
-    <bean id="myDataSource" class="org.apache.derby.jdbc.EmbeddedXADataSource" 
depends-on="myNonXADataSource">
-        <property name="databaseName" value="testdb"/>
-        <property name="createDatabase" value="true"/>
-        <property name="shutdownDatabase" value="true"/>
+
+    <!-- XA datasource used to create the database tables -->
+    <bean id="myXADataSource" 
class="org.apache.derby.jdbc.EmbeddedXADataSource">
+        <property name="databaseName" value="target/testdb;create=true"/>
         <property name="user" value="sa"/>
         <property name="password" value=""/>
     </bean>


Reply via email to