You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/09/04 09:36:18 UTC

[1/2] camel git commit: Producer no CQL Uri Param handling on doStart()

Repository: camel
Updated Branches:
  refs/heads/master 2051db4b4 -> 23456b66f


Producer no CQL Uri Param handling on doStart()

Problem:
- cql Uri param is not mandatory (default null)
- prepareStatements Uri param default true
Therefore creating a Producer like "cql://localhost/camel_ks" fails;
also, the error returned is misleading.

Details:
With the above premises, the top of the stacktrace is
"org.apache.camel.FailedToCreateProducerException: Failed to create
Producer for endpoint: Endpoint[cql://localhost/camel_ks]. Reason:
com.datastax.driver.core.exceptions.NoHostAvailableException: All
host(s) tried for query failed (tried: localhost/127.0.0.1:9042
(com.datastax.driver.core.TransportException: [localhost/127.0.0.1:9042]
Error writing))"
However this actually:
- is caused by the Producer doStart() trying to prepare a null cql
statement
- error looks like server/host is unreachable, but is actually the
failure of trying to prepare a null statement

Proposed solution:
Modify the the Producer's doStart() to invoke the Endpoint's
prepareStatement() method with additional condition that cql is not
null.
An additional unit test is provided to illustrate the scenario, for
instance a component earlier in the route would provide the actual cql
statement as part of the header, for example an EIP Translator.
Therefore in this scenario the cql is not unique and cannot be
configured in the Producer endpoint uri.

Aditional Notes:
On my machine maven test do fail on the master branch earlier than this
modification, and this modification does not solve those problems.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7fb272b0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7fb272b0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7fb272b0

Branch: refs/heads/master
Commit: 7fb272b0ace77d828e74bc2c1af4ebc66d849c4e
Parents: 2051db4
Author: tarilabs <ma...@gmail.com>
Authored: Mon Aug 31 12:09:11 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Sep 4 09:13:35 2015 +0200

----------------------------------------------------------------------
 .../component/cassandra/CassandraProducer.java  |  2 +-
 .../CassandraComponentProducerTest.java         | 42 ++++++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7fb272b0/components/camel-cassandraql/src/main/java/org/apache/camel/component/cassandra/CassandraProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-cassandraql/src/main/java/org/apache/camel/component/cassandra/CassandraProducer.java b/components/camel-cassandraql/src/main/java/org/apache/camel/component/cassandra/CassandraProducer.java
index 9ec9a25..be91c34 100644
--- a/components/camel-cassandraql/src/main/java/org/apache/camel/component/cassandra/CassandraProducer.java
+++ b/components/camel-cassandraql/src/main/java/org/apache/camel/component/cassandra/CassandraProducer.java
@@ -51,7 +51,7 @@ public class CassandraProducer extends DefaultProducer {
     @Override
     protected void doStart() throws Exception {
         super.doStart();
-        if (isPrepareStatements()) {
+        if (isPrepareStatements() && getEndpoint().getCql() != null) {
             this.preparedStatement = getEndpoint().prepareStatement();
         }
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/7fb272b0/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/CassandraComponentProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/CassandraComponentProducerTest.java b/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/CassandraComponentProducerTest.java
index 71f02e5..3bba78c 100644
--- a/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/CassandraComponentProducerTest.java
+++ b/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/CassandraComponentProducerTest.java
@@ -61,6 +61,9 @@ public class CassandraComponentProducerTest extends CamelTestSupport {
     
     @Produce(uri = "direct:loadBalancingPolicy")
     ProducerTemplate loadBalancingPolicyTemplate;
+    
+    @Produce(uri = "direct:inputNoEndpointCql")
+    ProducerTemplate producerTemplateNoEndpointCql;
 
     @BeforeClass
     public static void setUpClass() throws Exception {
@@ -85,6 +88,8 @@ public class CassandraComponentProducerTest extends CamelTestSupport {
                         .to("cql://localhost/camel_ks?cql=" + NO_PARAMETER_CQL + "&loadBalancingPolicy=RoundRobinPolicy");
                 from("direct:inputNotConsistent")
                         .to(NOT_CONSISTENT_URI);
+                from("direct:inputNoEndpointCql")
+                	.to("cql://localhost/camel_ks");
             }
         };
     }
@@ -176,6 +181,43 @@ public class CassandraComponentProducerTest extends CamelTestSupport {
         session.close();
         cluster.close();
     }
+    
+    /**
+     * Simulate different CQL statements in the incoming message containing a header with RegularStatement, justifying the cassandracql endpoint not containing a "cql" Uri parameter
+     */
+    @Test
+    public void testEndpointNoCqlParameter() throws Exception {
+        Update.Where updateFirstName = update("camel_user")
+                .with(set("first_name", bindMarker()))
+                .where(eq("login", bindMarker()));
+        @SuppressWarnings("unused")
+		Object response1 = producerTemplateNoEndpointCql.requestBodyAndHeader(new Object[]{"Claus 2", "c_ibsen"},
+                CassandraConstants.CQL_QUERY, updateFirstName);
+        
+        Cluster cluster = CassandraUnitUtils.cassandraCluster();
+        Session session = cluster.connect(CassandraUnitUtils.KEYSPACE);
+        ResultSet resultSet1 = session.execute("select login, first_name, last_name from camel_user where login = ?", "c_ibsen");
+        Row row1 = resultSet1.one();
+        assertNotNull(row1);
+        assertEquals("Claus 2", row1.getString("first_name"));
+        assertEquals("Ibsen", row1.getString("last_name"));
+        
+        Update.Where updateLastName = update("camel_user")
+                .with(set("last_name", bindMarker()))
+                .where(eq("login", bindMarker()));
+        @SuppressWarnings("unused")
+		Object response2 = producerTemplateNoEndpointCql.requestBodyAndHeader(new Object[]{"Ibsen 2", "c_ibsen"},
+                CassandraConstants.CQL_QUERY, updateLastName);
+        
+        ResultSet resultSet2 = session.execute("select login, first_name, last_name from camel_user where login = ?", "c_ibsen");
+        Row row2 = resultSet2.one();
+        assertNotNull(row2);
+        assertEquals("Claus 2", row2.getString("first_name"));
+        assertEquals("Ibsen 2", row2.getString("last_name"));
+
+        session.close();
+        cluster.close();
+    }
 
     @Test
     public void testRequestNotConsistent() throws Exception {


[2/2] camel git commit: Fixed CS. This closes #603.

Posted by da...@apache.org.
Fixed CS. This closes #603.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/23456b66
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/23456b66
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/23456b66

Branch: refs/heads/master
Commit: 23456b66fc11a58dcf6990bd6a266dc02410949e
Parents: 7fb272b
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Sep 4 09:37:01 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Sep 4 09:37:01 2015 +0200

----------------------------------------------------------------------
 .../CassandraComponentProducerTest.java         | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/23456b66/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/CassandraComponentProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/CassandraComponentProducerTest.java b/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/CassandraComponentProducerTest.java
index 3bba78c..798a008 100644
--- a/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/CassandraComponentProducerTest.java
+++ b/components/camel-cassandraql/src/test/java/org/apache/camel/component/cassandra/CassandraComponentProducerTest.java
@@ -58,10 +58,10 @@ public class CassandraComponentProducerTest extends CamelTestSupport {
 
     @Produce(uri = "direct:inputNotConsistent")
     ProducerTemplate notConsistentProducerTemplate;
-    
+
     @Produce(uri = "direct:loadBalancingPolicy")
     ProducerTemplate loadBalancingPolicyTemplate;
-    
+
     @Produce(uri = "direct:inputNoEndpointCql")
     ProducerTemplate producerTemplateNoEndpointCql;
 
@@ -89,7 +89,7 @@ public class CassandraComponentProducerTest extends CamelTestSupport {
                 from("direct:inputNotConsistent")
                         .to(NOT_CONSISTENT_URI);
                 from("direct:inputNoEndpointCql")
-                	.to("cql://localhost/camel_ks");
+                        .to("cql://localhost/camel_ks");
             }
         };
     }
@@ -142,7 +142,7 @@ public class CassandraComponentProducerTest extends CamelTestSupport {
         session.close();
         cluster.close();
     }
-    
+
     @Test
     public void testLoadBalancing() throws Exception {
         Object response = loadBalancingPolicyTemplate.requestBodyAndHeader(new Object[]{"Claus 2", "Ibsen 2", "c_ibsen"},
@@ -181,7 +181,7 @@ public class CassandraComponentProducerTest extends CamelTestSupport {
         session.close();
         cluster.close();
     }
-    
+
     /**
      * Simulate different CQL statements in the incoming message containing a header with RegularStatement, justifying the cassandracql endpoint not containing a "cql" Uri parameter
      */
@@ -191,9 +191,9 @@ public class CassandraComponentProducerTest extends CamelTestSupport {
                 .with(set("first_name", bindMarker()))
                 .where(eq("login", bindMarker()));
         @SuppressWarnings("unused")
-		Object response1 = producerTemplateNoEndpointCql.requestBodyAndHeader(new Object[]{"Claus 2", "c_ibsen"},
+        Object response1 = producerTemplateNoEndpointCql.requestBodyAndHeader(new Object[]{"Claus 2", "c_ibsen"},
                 CassandraConstants.CQL_QUERY, updateFirstName);
-        
+
         Cluster cluster = CassandraUnitUtils.cassandraCluster();
         Session session = cluster.connect(CassandraUnitUtils.KEYSPACE);
         ResultSet resultSet1 = session.execute("select login, first_name, last_name from camel_user where login = ?", "c_ibsen");
@@ -201,14 +201,14 @@ public class CassandraComponentProducerTest extends CamelTestSupport {
         assertNotNull(row1);
         assertEquals("Claus 2", row1.getString("first_name"));
         assertEquals("Ibsen", row1.getString("last_name"));
-        
+
         Update.Where updateLastName = update("camel_user")
                 .with(set("last_name", bindMarker()))
                 .where(eq("login", bindMarker()));
         @SuppressWarnings("unused")
-		Object response2 = producerTemplateNoEndpointCql.requestBodyAndHeader(new Object[]{"Ibsen 2", "c_ibsen"},
+        Object response2 = producerTemplateNoEndpointCql.requestBodyAndHeader(new Object[]{"Ibsen 2", "c_ibsen"},
                 CassandraConstants.CQL_QUERY, updateLastName);
-        
+
         ResultSet resultSet2 = session.execute("select login, first_name, last_name from camel_user where login = ?", "c_ibsen");
         Row row2 = resultSet2.one();
         assertNotNull(row2);