static int serializedSize(ProtocolVersion version) { return version.compareTo(ProtocolVersion.V5) >= 0 ? 4 : 1; } }
/** * Determines whether or not the input version supports ths feature. * * @param version the version to test against. * @return true if supported, false otherwise. */ boolean isSupportedBy(ProtocolVersion version) { switch (this) { case PREPARED_METADATA_CHANGES: return version == ProtocolVersion.V5; case CUSTOM_PAYLOADS: return version.compareTo(ProtocolVersion.V4) >= 0; case CLIENT_TIMESTAMPS: return version.compareTo(ProtocolVersion.V3) >= 0; default: return false; } } }
private void checkRequestsPerConnectionRange( int value, String description, HostDistance distance) { // If we don't know the protocol version yet, use the highest possible upper bound, this will // get checked again when possible int max = (protocolVersion == null || protocolVersion.compareTo(ProtocolVersion.V3) >= 0) ? StreamIdGenerator.MAX_STREAM_PER_CONNECTION_V3 : StreamIdGenerator.MAX_STREAM_PER_CONNECTION_V2; if (value < 0 || value > max) throw new IllegalArgumentException( String.format( "%s for %s hosts must be in the range (0, %d)", description, distance, max)); }
static void serialize(EnumSet<QueryFlag> flags, ByteBuf dest, ProtocolVersion version) { int i = 0; for (QueryFlag flag : flags) i |= 1 << flag.ordinal(); if (version.compareTo(ProtocolVersion.V5) >= 0) { dest.writeInt(i); } else { dest.writeByte((byte) i); } }
public void ensurePoolsSizing() { if (protocolVersion().compareTo(ProtocolVersion.V3) >= 0) return; for (SessionManager session : sessions) { for (HostConnectionPool pool : session.pools.values()) pool.ensureCoreConnections(); } }
throw new IllegalStateException( "Can not set the version explicitly if `allowBetaProtocolVersion` was used."); if (version.compareTo(ProtocolVersion.NEWEST_SUPPORTED) > 0) throw new IllegalArgumentException( "Can not use "
if (protocolVersion().compareTo(ProtocolVersion.V4) < 0) { final SettableFuture<?> future = SettableFuture.create(); scheduledTasksExecutor.schedule(
@Override public ProtocolVersion getProtocolVersion(ProtocolVersion maximumAllowed) { ProtocolVersion versionToUse = getProtocolVersion(); return versionToUse.compareTo(maximumAllowed) > 0 ? maximumAllowed : versionToUse; }
@Override public boolean apply(DataType dataType) { return protocolVersion.compareTo(dataType.getName().minProtocolVersion) >= 0; } });
if (flags.contains(QueryFlag.VALUES)) { if (flags.contains(QueryFlag.VALUE_NAMES)) { assert version.compareTo(ProtocolVersion.V3) >= 0; CBUtil.writeNamedValueList(namedValues, dest); } else { if (flags.contains(QueryFlag.SERIAL_CONSISTENCY)) CBUtil.writeConsistencyLevel(serialConsistency, dest); if (version.compareTo(ProtocolVersion.V3) >= 0 && flags.contains(QueryFlag.DEFAULT_TIMESTAMP)) dest.writeLong(defaultTimestamp); break;
if (flags.contains(QueryFlag.VALUES)) { if (flags.contains(QueryFlag.VALUE_NAMES)) { assert version.compareTo(ProtocolVersion.V3) >= 0; size += CBUtil.sizeOfNamedValueList(namedValues); } else { if (flags.contains(QueryFlag.SERIAL_CONSISTENCY)) size += CBUtil.sizeOfConsistencyLevel(serialConsistency); if (version.compareTo(ProtocolVersion.V3) >= 0 && flags.contains(QueryFlag.DEFAULT_TIMESTAMP)) size += 8; return size;
Map<String, ByteBuffer> customPayload = request.getCustomPayload(); if (customPayload != null) { if (protocolVersion.compareTo(ProtocolVersion.V4) < 0) throw new UnsupportedFeatureException( protocolVersion, "Custom payloads are only supported since native protocol V4");
/** @jira_ticket JAVA-1367 */ @Test(groups = "short") @CCMConfig(version = "2.1.16", createCluster = false) public void should_negotiate_when_no_version_provided() throws Exception { if (protocolVersion.compareTo(ProtocolVersion.NEWEST_SUPPORTED) >= 0) { throw new SkipException("Server supports newest protocol version driver supports"); } Cluster cluster = connectWithoutVersion(); assertThat(actualProtocolVersion(cluster)).isEqualTo(protocolVersion); }
if (key.compareTo(actualVersion) > 0) break; else referenceVersion = key;
@Test(groups = "short") public void prepareStatementInheritPropertiesTest() { RegularStatement toPrepare = new SimpleStatement("SELECT * FROM test WHERE k=?"); toPrepare.setConsistencyLevel(ConsistencyLevel.QUORUM); toPrepare.setSerialConsistencyLevel(ConsistencyLevel.LOCAL_SERIAL); toPrepare.setRetryPolicy(FallthroughRetryPolicy.INSTANCE); if (protocolVersion.compareTo(V4) >= 0) toPrepare.setOutgoingPayload(ImmutableMap.of("foo", Bytes.fromHexString("0xcafebabe"))); toPrepare.setIdempotent(true); toPrepare.enableTracing(); PreparedStatement prepared = session().prepare(toPrepare); assertThat(prepared.getConsistencyLevel()).isEqualTo(ConsistencyLevel.QUORUM); assertThat(prepared.getSerialConsistencyLevel()).isEqualTo(ConsistencyLevel.LOCAL_SERIAL); assertThat(prepared.getRetryPolicy()).isEqualTo(FallthroughRetryPolicy.INSTANCE); if (protocolVersion.compareTo(V4) >= 0) assertThat(prepared.getOutgoingPayload()) .isEqualTo(ImmutableMap.of("foo", Bytes.fromHexString("0xcafebabe"))); assertThat(prepared.isIdempotent()).isTrue(); assertThat(prepared.isTracing()).isTrue(); BoundStatement bs = prepared.bind("someValue"); assertThat(bs.getConsistencyLevel()).isEqualTo(ConsistencyLevel.QUORUM); assertThat(bs.getSerialConsistencyLevel()).isEqualTo(ConsistencyLevel.LOCAL_SERIAL); assertThat(bs.getRetryPolicy()).isEqualTo(FallthroughRetryPolicy.INSTANCE); if (protocolVersion.compareTo(V4) >= 0) assertThat(bs.getOutgoingPayload()) .isEqualTo(ImmutableMap.of("foo", Bytes.fromHexString("0xcafebabe"))); assertThat(bs.isIdempotent()).isTrue(); assertThat(bs.isTracing()).isTrue(); }
.getProtocolOptions() .getProtocolVersion() .compareTo(ProtocolVersion.V5) >= 0) { assertThat(e.getFailuresMap()).hasSize(1).containsValue(0);
private void checkRequestsPerConnectionRange(int value, String description, HostDistance distance) { // If we don't know the protocol version yet, use the highest possible upper bound, this will get checked again when possible int max = (protocolVersion == null || protocolVersion.compareTo(ProtocolVersion.V3) >= 0) ? StreamIdGenerator.MAX_STREAM_PER_CONNECTION_V3 : StreamIdGenerator.MAX_STREAM_PER_CONNECTION_V2; if (value < 0 || value > max) throw new IllegalArgumentException(String.format("%s for %s hosts must be in the range (0, %d)", description, distance, max)); }
static DefaultPreparedStatement fromMessage( Responses.Result.Prepared msg, Cluster cluster, String query, String queryKeyspace) { assert msg.metadata.columns != null; ColumnDefinitions defs = msg.metadata.columns; ProtocolVersion protocolVersion = cluster.getConfiguration().getProtocolOptions().getProtocolVersion(); PreparedId.PreparedMetadata boundValuesMetadata = new PreparedId.PreparedMetadata(msg.statementId, defs); PreparedId.PreparedMetadata resultSetMetadata = new PreparedId.PreparedMetadata(msg.resultMetadataId, msg.resultMetadata.columns); int[] pkIndices = null; if (defs.size() > 0) { pkIndices = (protocolVersion.compareTo(V4) >= 0) ? msg.metadata.pkIndices : computePkIndices(cluster.getMetadata(), defs); } PreparedId preparedId = new PreparedId(boundValuesMetadata, resultSetMetadata, pkIndices, protocolVersion); return new DefaultPreparedStatement( preparedId, query, queryKeyspace, msg.getCustomPayload(), cluster); }
if (protocolVersion.compareTo(ProtocolVersion.V3) < 0 && statement instanceof BatchStatement) { if (serialConsistency != null) throw new UnsupportedFeatureException( serialConsistency = configuration().getQueryOptions().getSerialConsistencyLevel(); if (statement.getOutgoingPayload() != null && protocolVersion.compareTo(ProtocolVersion.V4) < 0) throw new UnsupportedFeatureException( protocolVersion, "Custom payloads are only supported since native protocol V4"); if (protocolVersion.compareTo(ProtocolVersion.V3) >= 0) { defaultTimestamp = statement.getDefaultTimestamp(); if (defaultTimestamp == Long.MIN_VALUE) bs.statement.getPreparedId().boundValuesMetadata.id)); if (protocolVersion.compareTo(ProtocolVersion.V4) < 0) bs.ensureAllSet(); if (protocolVersion.compareTo(ProtocolVersion.V4) < 0) bs.ensureAllSet(); BatchStatement.IdAndValues idAndVals = bs.getIdAndValues(protocolVersion, codecRegistry); Requests.BatchProtocolOptions options =
.getProtocolOptions() .getProtocolVersion() .compareTo(ProtocolVersion.V5) >= 0) { assertThat(e.getFailuresMap()).hasSize(1).containsValue(1);