Skip to content

Commit

Permalink
#266: Fix NoHostAvailableException when connecting to YugaByte YCQL s…
Browse files Browse the repository at this point in the history
…ervice 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
  • Loading branch information
robertpang committed May 2, 2018
1 parent eb2a6d3 commit 4e315a9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
14 changes: 12 additions & 2 deletions java/yb-cql/src/test/java/org/yb/cql/TestBasicStatements.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
}
}
4 changes: 2 additions & 2 deletions src/yb/yql/cql/cqlserver/cql_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 4 additions & 3 deletions src/yb/yql/cql/cqlserver/cqlserver-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 4e315a9

Please sign in to comment.