本文整理了Java中com.datastax.driver.core.Configuration.getProtocolOptions()
方法的一些代码示例,展示了Configuration.getProtocolOptions()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration.getProtocolOptions()
方法的具体详情如下:
包路径:com.datastax.driver.core.Configuration
类名称:Configuration
方法名:getProtocolOptions
[英]Returns the Cassandra binary protocol level configuration (compression).
[中]返回Cassandra二进制协议级别的配置(压缩)。
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
int getPort() {
return configuration.getProtocolOptions().getPort();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
private ProtocolVersion protocolVersion() {
// Since the QueryLogger can be registered before the Cluster was initialized, we can't retrieve
// it at construction time. Cache it field at first use (a volatile field is good enough since
// we
// don't need mutual exclusion).
if (protocolVersion == null) {
protocolVersion = cluster.getConfiguration().getProtocolOptions().getProtocolVersion();
// At least one connection was established when QueryLogger is invoked
assert protocolVersion != null : "protocol version should be defined";
}
return protocolVersion;
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
static boolean waitForSchemaAgreement(Connection connection, Cluster.Manager cluster)
throws ConnectionException, BusyConnectionException, ExecutionException,
InterruptedException {
long start = System.nanoTime();
long elapsed = 0;
int maxSchemaAgreementWaitSeconds =
cluster.configuration.getProtocolOptions().getMaxSchemaAgreementWaitSeconds();
while (elapsed < maxSchemaAgreementWaitSeconds * 1000) {
if (checkSchemaAgreement(connection, cluster)) return true;
// let's not flood the node too much
Thread.sleep(200);
elapsed = Cluster.timeSince(start, TimeUnit.MILLISECONDS);
}
return false;
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@BeforeMethod(groups = "unit")
public void setUpQueryBuilder() throws Exception {
CodecRegistry codecRegistry = new CodecRegistry();
cluster = mock(Cluster.class);
Configuration configuration = mock(Configuration.class);
ProtocolOptions protocolOptions = mock(ProtocolOptions.class);
when(cluster.getConfiguration()).thenReturn(configuration);
when(configuration.getCodecRegistry()).thenReturn(codecRegistry);
when(configuration.getProtocolOptions()).thenReturn(protocolOptions);
when(protocolOptions.getProtocolVersion()).thenReturn(ProtocolVersion.NEWEST_SUPPORTED);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
private static List<DataType> parseTypes(
KeyspaceMetadata ksm, List<String> types, VersionNumber version, Cluster cluster) {
if (types.isEmpty()) return Collections.emptyList();
CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry();
ProtocolVersion protocolVersion =
cluster.getConfiguration().getProtocolOptions().getProtocolVersion();
ImmutableList.Builder<DataType> builder = ImmutableList.builder();
for (String name : types) {
DataType type;
if (version.getMajor() >= 3) {
type =
DataTypeCqlNameParser.parse(
name, cluster, ksm.getName(), ksm.userTypes, null, false, false);
} else {
type = DataTypeClassNameParser.parseOne(name, protocolVersion, codecRegistry);
}
builder.add(type);
}
return builder.build();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
ResultSetFuture executeQuery(Message.Request msg, Statement statement) {
DefaultResultSetFuture future =
new DefaultResultSetFuture(
this, configuration().getProtocolOptions().getProtocolVersion(), msg);
execute(future, statement);
return future;
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void should_set_flag_on_successful_agreement() {
ProtocolOptions protocolOptions = cluster().getConfiguration().getProtocolOptions();
protocolOptions.maxSchemaAgreementWaitSeconds = 10;
ResultSet rs = session().execute(String.format(CREATE_TABLE, COUNTER.getAndIncrement()));
assertThat(rs.getExecutionInfo().isSchemaInAgreement()).isTrue();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short", priority = 1)
public void should_unset_flag_on_failed_agreement() {
// Setting to 0 results in no query being set, so agreement fails
ProtocolOptions protocolOptions = cluster().getConfiguration().getProtocolOptions();
protocolOptions.maxSchemaAgreementWaitSeconds = 0;
ResultSet rs = session().execute(String.format(CREATE_TABLE, COUNTER.getAndIncrement()));
assertThat(rs.getExecutionInfo().isSchemaInAgreement()).isFalse();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
private ProtocolVersion actualProtocolVersion(Cluster cluster) {
return cluster.getConfiguration().getProtocolOptions().getProtocolVersion();
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void should_set_flag_on_non_schema_altering_statement() {
ProtocolOptions protocolOptions = cluster().getConfiguration().getProtocolOptions();
protocolOptions.maxSchemaAgreementWaitSeconds = 10;
ResultSet rs = session().execute("select release_version from system.local");
assertThat(rs.getExecutionInfo().isSchemaInAgreement()).isTrue();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Override
public void init(Cluster cluster, Collection<Host> hosts) {
clusterMetadata = cluster.getMetadata();
protocolVersion = cluster.getConfiguration().getProtocolOptions().getProtocolVersion();
codecRegistry = cluster.getConfiguration().getCodecRegistry();
childPolicy.init(cluster, hosts);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/** @jira_ticket JAVA-1209 */
@Test(groups = "short")
public void getProtocolVersion_should_return_version() throws InterruptedException {
ProtocolVersion version =
cluster().getConfiguration().getProtocolOptions().getProtocolVersion();
assertThat(version).isNotNull();
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* Copy constructor.
*
* @param toCopy the object to copy from.
*/
protected Configuration(Configuration toCopy) {
this(
toCopy.getPolicies(),
toCopy.getProtocolOptions(),
toCopy.getPoolingOptions(),
toCopy.getSocketOptions(),
toCopy.getMetricsOptions(),
toCopy.getQueryOptions(),
toCopy.getThreadingOptions(),
toCopy.getNettyOptions(),
toCopy.getCodecRegistry());
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/** @jira_ticket JAVA-1209 */
@Test(groups = "unit")
public void getProtocolVersion_should_return_null_if_not_connected() {
Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
assertThat(cluster.getConfiguration().getProtocolOptions().getProtocolVersion()).isNull();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void textRoutingKeyTest() throws Exception {
BuiltStatement query;
TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable(TABLE_TEXT);
assertNotNull(table);
ProtocolVersion protocolVersion =
cluster().getConfiguration().getProtocolOptions().getProtocolVersion();
CodecRegistry codecRegistry = CodecRegistry.DEFAULT_INSTANCE;
String txt = "If she weighs the same as a duck... she's made of wood.";
query = insertInto(table).values(new String[] {"k", "a", "b"}, new Object[] {txt, 1, 2});
assertEquals(
query.getRoutingKey(protocolVersion, codecRegistry), ByteBuffer.wrap(txt.getBytes()));
session().execute(query);
query = select().from(table).where(eq("k", txt));
assertEquals(
query.getRoutingKey(protocolVersion, codecRegistry), ByteBuffer.wrap(txt.getBytes()));
Row row = session().execute(query).one();
assertEquals(row.getString("k"), txt);
assertEquals(row.getInt("a"), 1);
assertEquals(row.getInt("b"), 2);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void should_create_token_from_partition_key() {
Metadata metadata = cluster().getMetadata();
Row row = session().execute("SELECT token(i) FROM foo WHERE i = 1").one();
Token expected = row.getToken(0);
ProtocolVersion protocolVersion =
cluster().getConfiguration().getProtocolOptions().getProtocolVersion();
assertThat(metadata.newToken(TypeCodec.cint().serialize(1, protocolVersion)))
.isEqualTo(expected);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void intRoutingKeyTest() throws Exception {
BuiltStatement query;
TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable(TABLE_INT);
assertNotNull(table);
ProtocolVersion protocolVersion =
cluster().getConfiguration().getProtocolOptions().getProtocolVersion();
CodecRegistry codecRegistry = CodecRegistry.DEFAULT_INSTANCE;
query = insertInto(table).values(new String[] {"k", "a", "b"}, new Object[] {42, 1, 2});
ByteBuffer bb = ByteBuffer.allocate(4);
bb.putInt(0, 42);
assertEquals(query.getRoutingKey(protocolVersion, codecRegistry), bb);
session().execute(query);
query = select().from(table).where(eq("k", 42));
assertEquals(query.getRoutingKey(protocolVersion, codecRegistry), bb);
Row row = session().execute(query).one();
assertEquals(row.getInt("k"), 42);
assertEquals(row.getInt("a"), 1);
assertEquals(row.getInt("b"), 2);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
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);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* Verifies that the driver can connect to 3.10 with the following combination of options: Version
* UNSET Flag SET Expected version: V5
*
* @jira_ticket JAVA-1248
*/
@Test(groups = "short")
public void should_connect_with_beta_when_no_version_explicitly_required_and_flag_set()
throws Exception {
// Note: when the driver's ProtocolVersion.NEWEST_SUPPORTED will be incremented to V6 or higher
// a renegotiation will start taking place here and will downgrade the version from V6 to V5,
// but the test should remain valid since it's executed against 3.10 exclusively
Cluster cluster =
Cluster.builder()
.addContactPoints(getContactPoints())
.withPort(ccm().getBinaryPort())
.allowBetaProtocolVersion()
.build();
cluster.connect();
assertThat(cluster.getConfiguration().getProtocolOptions().getProtocolVersion()).isEqualTo(V5);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Override
public PreparedStatement apply(PreparedStatement prepared) {
ProtocolVersion protocolVersion =
getCluster().getConfiguration().getProtocolOptions().getProtocolVersion();
ByteBuffer routingKey = statement.getRoutingKey(protocolVersion, codecRegistry);
if (routingKey != null) prepared.setRoutingKey(routingKey);
if (statement.getConsistencyLevel() != null)
prepared.setConsistencyLevel(statement.getConsistencyLevel());
if (statement.getSerialConsistencyLevel() != null)
prepared.setSerialConsistencyLevel(statement.getSerialConsistencyLevel());
if (statement.isTracing()) prepared.enableTracing();
prepared.setRetryPolicy(statement.getRetryPolicy());
prepared.setOutgoingPayload(statement.getOutgoingPayload());
prepared.setIdempotent(statement.isIdempotent());
return prepared;
}
});
内容来源于网络,如有侵权,请联系作者删除!