use of com.palantir.atlasdb.keyvalue.cassandra.async.CassandraAsyncKeyValueServiceFactory in project atlasdb by palantir.
the class CassandraKvsAsyncFallbackMechanismsTests method getConfigWithAsyncFactoryUsingClosedSession.
private CassandraKeyValueServiceConfig getConfigWithAsyncFactoryUsingClosedSession(boolean useSpyPreparedStatement) {
CassandraKeyValueServiceConfig config = CASSANDRA_RESOURCE.getConfig();
Refreshable<CassandraKeyValueServiceRuntimeConfig> runtimeConfig = CASSANDRA_RESOURCE.getRuntimeConfig();
Cluster cluster = spy(new ClusterFactory(CASSANDRA_RESOURCE.getClusterBuilderWithProxy()).constructCluster(CassandraClusterConfig.of(config, runtimeConfig.get()), runtimeConfig.get().servers()));
Session session = spy(cluster.connect());
doReturn(session).when(cluster).connect();
if (useSpyPreparedStatement) {
// Need a real query that uses namespace and table that already exist, irrespective of what the test may
// create
PreparedStatement preparedStatement = spy(session.prepare("SELECT COUNT(*) FROM system.schema_columns;"));
BoundStatement boundStatement = spy(preparedStatement.bind());
// The prepared statement doesn't use any of the bindings that a normal query would use, so we ignore them.
doReturn(boundStatement).when(boundStatement).setBytes(any(), any());
doReturn(boundStatement).when(boundStatement).setLong(anyString(), anyLong());
doReturn(boundStatement).when(preparedStatement).bind();
doReturn(preparedStatement).when(session).prepare(anyString());
}
session.close();
CqlClient cqlClient = spy(CqlClientImpl.create(new DefaultTaggedMetricRegistry(), cluster, mock(CqlCapableConfigTuning.class), false));
doReturn(true).when(cqlClient).isValid();
CassandraAsyncKeyValueServiceFactory cassandraAsyncKeyValueServiceFactory = new DefaultCassandraAsyncKeyValueServiceFactory((_ignored1, _ignored2, _ignored3, _ignored4) -> ReloadingCloseableContainerImpl.of(Refreshable.only(0), _ignored -> cqlClient));
return ImmutableCassandraKeyValueServiceConfig.builder().from(CASSANDRA_RESOURCE.getConfig()).asyncKeyValueServiceFactory(cassandraAsyncKeyValueServiceFactory).build();
}
Aggregations