Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 53D6C10C4E for ; Fri, 4 Sep 2015 07:36:19 +0000 (UTC) Received: (qmail 97242 invoked by uid 500); 4 Sep 2015 07:36:19 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 97200 invoked by uid 500); 4 Sep 2015 07:36:19 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 97190 invoked by uid 99); 4 Sep 2015 07:36:19 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Sep 2015 07:36:19 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2C5A1DFB01; Fri, 4 Sep 2015 07:36:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Fri, 04 Sep 2015 07:36:18 -0000 Message-Id: <2ebab374e13e48c0891da769eee0f4b9@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [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 Authored: Mon Aug 31 12:09:11 2015 +0200 Committer: Claus Ibsen 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 {