use of com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory in project atlasdb by palantir.
the class CassandraRepairEteTest method setUp.
@Before
public void setUp() {
int replicationFactor = 2;
config = ThreeNodeCassandraCluster.getKvsConfig();
runtimeConfig = ThreeNodeCassandraCluster.getRuntimeConfig(replicationFactor);
kvs = CassandraKeyValueServiceImpl.createForTesting(config, runtimeConfig);
TransactionTables.createTables(kvs);
kvs.createTable(TABLE_REF, AtlasDbConstants.GENERIC_TABLE_METADATA);
kvs.putUnlessExists(TABLE_REF, ImmutableMap.of(NONEMPTY_CELL, CONTENTS));
KvsRunner kvsRunner = KvsRunner.create(_unused -> kvs);
Function<AtlasService, CassandraKeyValueServiceConfig> configFactory = _unused -> config;
Function<AtlasService, Refreshable<CassandraKeyValueServiceRuntimeConfig>> runtimeConfigFactory = _unused -> runtimeConfig;
Function<AtlasService, CassandraClusterConfig> cassandraClusterConfigFunction = atlasService -> CassandraClusterConfig.of(configFactory.apply(atlasService), runtimeConfigFactory.apply(atlasService).get());
Function<AtlasService, Refreshable<CassandraServersConfig>> cassandraServersConfigFactory = runtimeConfigFactory.andThen(runtimeConfig -> runtimeConfig.map(CassandraKeyValueServiceRuntimeConfig::servers));
cassandraRepairHelper = new CassandraRepairHelper(kvsRunner, cassandraClusterConfigFunction, cassandraServersConfigFactory);
cluster = new ClusterFactory(Cluster::builder).constructCluster(cassandraClusterConfigFunction.apply(ATLAS_SERVICE), cassandraServersConfigFactory.apply(ATLAS_SERVICE).get());
cqlCluster = new CqlCluster(cluster, cassandraServersConfigFactory.apply(ATLAS_SERVICE).get(), NAMESPACE);
}
use of com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory 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