From 4e315a950a919991150d88bf3d19ce51adedc981 Mon Sep 17 00:00:00 2001 From: Robert Pang Date: Wed, 2 May 2018 00:39:03 -0700 Subject: [PATCH] #266: Fix NoHostAvailableException when connecting to YugaByte YCQL service using DataStax DSE driver Summary: Apache Cassandra Java driver and the like rely on the unsupported protocol error response to contain the specific error message "Invalid or unsupported protocol version" to recognize the unspported protocol version error. So this revision changes YCQL service to return the specific error message so that the client driver will handle the unsupported protocol version properly. Test Plan: TestBasicStatements.testUnsupportedProtocol Reviewers: mihnea Reviewed By: mihnea Subscribers: yql Differential Revision: https://phabricator.dev.yugabyte.com/D4739 --- .../test/java/org/yb/cql/TestBasicStatements.java | 14 ++++++++++++-- src/yb/yql/cql/cqlserver/cql_message.cc | 4 ++-- src/yb/yql/cql/cqlserver/cqlserver-test.cc | 7 ++++--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/java/yb-cql/src/test/java/org/yb/cql/TestBasicStatements.java b/java/yb-cql/src/test/java/org/yb/cql/TestBasicStatements.java index b9eaa3623873..dc73bc0ac6ed 100644 --- a/java/yb-cql/src/test/java/org/yb/cql/TestBasicStatements.java +++ b/java/yb-cql/src/test/java/org/yb/cql/TestBasicStatements.java @@ -15,6 +15,8 @@ import org.junit.Ignore; import org.junit.Test; +import com.datastax.driver.core.Session; + public class TestBasicStatements extends BaseCQLTest { @Test public void testCreateTable() throws Exception { @@ -23,12 +25,20 @@ public void testCreateTable() throws Exception { } // We need to work on reporting error from SQL before activating this test. - @Ignore + @Test public void testInvalidStatement() throws Exception { LOG.info("Execute nothing ..."); thrown.expect(com.datastax.driver.core.exceptions.SyntaxError.class); - thrown.expectMessage("unknown statement"); + thrown.expectMessage("Invalid SQL Statement"); session.execute("NOTHING"); } + @Test + public void testUnsupportedProtocol() throws Exception { + thrown.expect(com.datastax.driver.core.exceptions.UnsupportedProtocolVersionException.class); + Session s = getDefaultClusterBuilder() + .allowBetaProtocolVersion() + .build() + .connect(); + } } diff --git a/src/yb/yql/cql/cqlserver/cql_message.cc b/src/yb/yql/cql/cqlserver/cql_message.cc index a724cc190e8d..3927fb270068 100644 --- a/src/yb/yql/cql/cqlserver/cql_message.cc +++ b/src/yb/yql/cql/cqlserver/cql_message.cc @@ -218,8 +218,8 @@ bool CQLRequest::ParseRequest( error_response->reset( new ErrorResponse( header.stream_id, ErrorResponse::Code::PROTOCOL_ERROR, - Substitute("Protocol version $0 not supported. Supported versions are between " - "$1 and $2.", header.version, kMinimumVersion, kCurrentVersion))); + Substitute("Invalid or unsupported protocol version $0. Supported versions are between " + "$1 and $2.", header.version, kMinimumVersion, kCurrentVersion))); return false; } diff --git a/src/yb/yql/cql/cqlserver/cqlserver-test.cc b/src/yb/yql/cql/cqlserver/cqlserver-test.cc index 7c329e237875..45d2ef4ef7a5 100644 --- a/src/yb/yql/cql/cqlserver/cqlserver-test.cc +++ b/src/yb/yql/cql/cqlserver/cqlserver-test.cc @@ -159,9 +159,10 @@ TEST_F(TestCQLService, StartupRequest) { BINARY_STRING("\x05\x00\x00\x00\x01" "\x00\x00\x00\x16" "\x00\x01" "\x00\x0b" "CQL_VERSION" "\x00\x05" "3.0.0"), - BINARY_STRING("\x84\x00\x00\x00\x00" "\x00\x00\x00\x4f" - "\x00\x00\x00\x0a" "\x00\x49" - "Protocol version 5 not supported. Supported versions are between 3 and 4.")); + BINARY_STRING("\x84\x00\x00\x00\x00" "\x00\x00\x00\x58" + "\x00\x00\x00\x0a" "\x00\x52" + "Invalid or unsupported protocol version 5. " + "Supported versions are between 3 and 4.")); // Send STARTUP request with compression SendRequestAndExpectResponse(