Elffuss BraidHub

kikocis/java-driver public

Merge pull request #637 from datastax/java1095

JAVA-1095: Check protocol version for custom payload before sending the query.
Changesetced5ba920359fd411a751d3f2eb10907e0bc54a645e7547ad0a2cfc3e08044e4
AuthorOlivier Michallat <olim7t@users.noreply.github.com> · 2016-04-26 15:26 +02:00
CommitterOlivier Michallat <olim7t@users.noreply.github.com> · 2016-04-26 15:26 +02:00
Parentsb5b377402941, 663134961b64

Browse the files at this changeset

3 files changed

modified changelog/README.md +1 −0
@@ -14,6 +14,7 @@
1414 - [bug] JAVA-1140: Use same connection to check for schema agreement after a DDL query.
1515 - [improvement] JAVA-1113: Support Cassandra 3.4 LIKE operator in QueryBuilder.
1616 - [improvement] JAVA-1086: Support Cassandra 3.2 CAST function in QueryBuilder.
17+- [bug] JAVA-1095: Check protocol version for custom payload before sending the query.
1718
1819 Merged from 2.1 branch:
1920
modified driver-core/src/main/java/com/datastax/driver/core/SessionManager.java +3 −0
@@ -502,6 +502,9 @@
502502 } else if (serialConsistency == null)
503503 serialConsistency = configuration().getQueryOptions().getSerialConsistencyLevel();
504504
505+ if (statement.getOutgoingPayload() != null && protocolVersion.compareTo(ProtocolVersion.V4) < 0)
506+ throw new UnsupportedFeatureException(protocolVersion, "Custom payloads are only supported since native protocol V4");
507+
505508 long defaultTimestamp = Long.MIN_VALUE;
506509 if (protocolVersion.compareTo(ProtocolVersion.V3) >= 0) {
507510 defaultTimestamp = statement.getDefaultTimestamp();
modified driver-core/src/test/java/com/datastax/driver/core/CustomPayloadTest.java +3 −14
@@ -15,13 +15,10 @@
1515 */
1616 package com.datastax.driver.core;
1717
18-import com.datastax.driver.core.exceptions.NoHostAvailableException;
1918 import com.datastax.driver.core.exceptions.UnsupportedFeatureException;
2019 import com.datastax.driver.core.utils.CassandraVersion;
21-import com.google.common.base.Throwables;
2220 import com.google.common.collect.ImmutableMap;
2321 import org.apache.log4j.Logger;
24-import org.assertj.core.api.iterable.Extractor;
2522 import org.testng.annotations.BeforeMethod;
2623 import org.testng.annotations.Test;
2724
@@ -246,17 +243,9 @@
246243 statement.setOutgoingPayload(payload1);
247244 v3session.execute(statement);
248245 fail("Should not send custom payloads with protocol V3");
249- } catch (NoHostAvailableException nhae) {
250- assertThat(nhae.getErrors().values())
251- .extracting(new Extractor<Throwable, Throwable>() {
252- @Override
253- public Throwable extract(Throwable input) {
254- return Throwables.getRootCause(input);
255- }
256- })
257- .hasOnlyElementsOfType(UnsupportedFeatureException.class)
258- .extracting("message")
259- .containsOnly("Unsupported feature with the native protocol V3 (which is currently in use): Custom payloads are only supported since native protocol V4");
246+ } catch (UnsupportedFeatureException e) {
247+ assertThat(e.getMessage()).isEqualTo(
248+ "Unsupported feature with the native protocol V3 (which is currently in use): Custom payloads are only supported since native protocol V4");
260249 }
261250 }
262251