Skip to content

Commit c19f7a9

Browse files
committed
Merge pull request apache#637 from datastax/java1095
JAVA-1095: Check protocol version for custom payload before sending the query.
2 parents c9f36ea + 4342251 commit c19f7a9

3 files changed

Lines changed: 7 additions & 14 deletions

File tree

changelog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

driver-core/src/main/java/com/datastax/driver/core/SessionManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,9 @@ Message.Request makeRequestMessage(Statement statement, ByteBuffer pagingState)
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();

driver-core/src/test/java/com/datastax/driver/core/CustomPayloadTest.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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 @@ public void should_throw_ufe_when_protocol_version_lesser_than_4() throws Except
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

0 commit comments

Comments
 (0)