Search in sources :

Example 1 with ClusterFactory

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);
}
Also used : RangeSet(com.google.common.collect.RangeSet) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServiceId(com.palantir.atlasdb.backup.api.ServiceId) ThreeNodeCassandraCluster(com.palantir.atlasdb.containers.ThreeNodeCassandraCluster) Blacklist(com.palantir.atlasdb.keyvalue.cassandra.Blacklist) ImmutableRangeSet.toImmutableRangeSet(com.google.common.collect.ImmutableRangeSet.toImmutableRangeSet) CqlMetadata(com.palantir.atlasdb.cassandra.backup.CqlMetadata) FullyBoundedTimestampRange(com.palantir.timestamp.FullyBoundedTimestampRange) LightweightOppToken(com.palantir.atlasdb.keyvalue.cassandra.LightweightOppToken) CassandraClientPoolMetrics(com.palantir.atlasdb.keyvalue.cassandra.pool.CassandraClientPoolMetrics) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CassandraKeyValueServiceImpl(com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueServiceImpl) Map(java.util.Map) After(org.junit.After) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) CassandraKeyValueService(com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueService) DefaultRetryPolicy(com.datastax.driver.core.policies.DefaultRetryPolicy) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) CassandraServersConfig(com.palantir.atlasdb.cassandra.CassandraServersConfigs.CassandraServersConfig) Refreshable(com.palantir.refreshable.Refreshable) CassandraServer(com.palantir.atlasdb.keyvalue.cassandra.pool.CassandraServer) ImmutableMap(com.google.common.collect.ImmutableMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell) KeyedStream(com.palantir.common.streams.KeyedStream) Predicate(java.util.function.Predicate) Range(com.google.common.collect.Range) Set(java.util.Set) RangesForRepair(com.palantir.atlasdb.cassandra.backup.RangesForRepair) InetSocketAddress(java.net.InetSocketAddress) MetricsManagers(com.palantir.atlasdb.util.MetricsManagers) List(java.util.List) Cluster(com.datastax.driver.core.Cluster) Optional(java.util.Optional) Transactions3TableInteraction(com.palantir.atlasdb.cassandra.backup.transaction.Transactions3TableInteraction) CassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig) CassandraRepairHelper(com.palantir.atlasdb.cassandra.backup.CassandraRepairHelper) CassandraKeyValueServiceRuntimeConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceRuntimeConfig) TransactionsTableInteraction(com.palantir.atlasdb.cassandra.backup.transaction.TransactionsTableInteraction) ClusterFactory(com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory) KvsRunner(com.palantir.atlasdb.backup.KvsRunner) CqlCluster(com.palantir.atlasdb.cassandra.backup.CqlCluster) HashMap(java.util.HashMap) Function(java.util.function.Function) PtBytes(com.palantir.atlasdb.encoding.PtBytes) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) Transactions1TableInteraction(com.palantir.atlasdb.cassandra.backup.transaction.Transactions1TableInteraction) TransactionTables(com.palantir.atlasdb.transaction.impl.TransactionTables) BiConsumer(java.util.function.BiConsumer) Before(org.junit.Before) CassandraService(com.palantir.atlasdb.keyvalue.cassandra.pool.CassandraService) Transactions2TableInteraction(com.palantir.atlasdb.cassandra.backup.transaction.Transactions2TableInteraction) CassandraClusterConfig(com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory.CassandraClusterConfig) Test(org.junit.Test) Namespace(com.palantir.atlasdb.timelock.api.Namespace) TransactionConstants(com.palantir.atlasdb.transaction.impl.TransactionConstants) RangeMap(com.google.common.collect.RangeMap) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) ClusterFactory(com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) CassandraRepairHelper(com.palantir.atlasdb.cassandra.backup.CassandraRepairHelper) CassandraClusterConfig(com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory.CassandraClusterConfig) ThreeNodeCassandraCluster(com.palantir.atlasdb.containers.ThreeNodeCassandraCluster) Cluster(com.datastax.driver.core.Cluster) CqlCluster(com.palantir.atlasdb.cassandra.backup.CqlCluster) Refreshable(com.palantir.refreshable.Refreshable) KvsRunner(com.palantir.atlasdb.backup.KvsRunner) CqlCluster(com.palantir.atlasdb.cassandra.backup.CqlCluster) CassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig) Before(org.junit.Before)

Example 2 with ClusterFactory

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();
}
Also used : ClusterFactory(com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) AsyncKeyValueService(com.palantir.atlasdb.keyvalue.api.AsyncKeyValueService) CassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig) CqlCapableConfigTuning(com.palantir.atlasdb.cassandra.CassandraServersConfigs.CqlCapableConfigTuning) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) CassandraKeyValueServiceRuntimeConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceRuntimeConfig) ClusterFactory(com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory) CqlClient(com.palantir.atlasdb.keyvalue.cassandra.async.CqlClient) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Mockito.spy(org.mockito.Mockito.spy) ReloadingCloseableContainerImpl(com.palantir.atlasdb.cassandra.ReloadingCloseableContainerImpl) PtBytes(com.palantir.atlasdb.encoding.PtBytes) ImmutableCassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.ImmutableCassandraKeyValueServiceConfig) PreparedStatement(com.datastax.driver.core.PreparedStatement) BoundStatement(com.datastax.driver.core.BoundStatement) CassandraAsyncKeyValueServiceFactory(com.palantir.atlasdb.keyvalue.cassandra.async.CassandraAsyncKeyValueServiceFactory) Session(com.datastax.driver.core.Session) Map(java.util.Map) After(org.junit.After) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) ClassRule(org.junit.ClassRule) Mockito.doReturn(org.mockito.Mockito.doReturn) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) Refreshable(com.palantir.refreshable.Refreshable) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell) CassandraClusterConfig(com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory.CassandraClusterConfig) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) DefaultCassandraAsyncKeyValueServiceFactory(com.palantir.atlasdb.keyvalue.cassandra.async.DefaultCassandraAsyncKeyValueServiceFactory) DefaultTaggedMetricRegistry(com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) Mockito.never(org.mockito.Mockito.never) Futures(com.google.common.util.concurrent.Futures) CassandraResource(com.palantir.atlasdb.containers.CassandraResource) Cluster(com.datastax.driver.core.Cluster) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) CqlClientImpl(com.palantir.atlasdb.keyvalue.cassandra.async.CqlClientImpl) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) CassandraKeyValueServiceRuntimeConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceRuntimeConfig) Cluster(com.datastax.driver.core.Cluster) DefaultCassandraAsyncKeyValueServiceFactory(com.palantir.atlasdb.keyvalue.cassandra.async.DefaultCassandraAsyncKeyValueServiceFactory) PreparedStatement(com.datastax.driver.core.PreparedStatement) CqlClient(com.palantir.atlasdb.keyvalue.cassandra.async.CqlClient) DefaultTaggedMetricRegistry(com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry) BoundStatement(com.datastax.driver.core.BoundStatement) CassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig) ImmutableCassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.ImmutableCassandraKeyValueServiceConfig) CassandraAsyncKeyValueServiceFactory(com.palantir.atlasdb.keyvalue.cassandra.async.CassandraAsyncKeyValueServiceFactory) DefaultCassandraAsyncKeyValueServiceFactory(com.palantir.atlasdb.keyvalue.cassandra.async.DefaultCassandraAsyncKeyValueServiceFactory) Session(com.datastax.driver.core.Session)

Aggregations

Cluster (com.datastax.driver.core.Cluster)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 AtlasDbConstants (com.palantir.atlasdb.AtlasDbConstants)2 CassandraKeyValueServiceConfig (com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig)2 CassandraKeyValueServiceRuntimeConfig (com.palantir.atlasdb.cassandra.CassandraKeyValueServiceRuntimeConfig)2 PtBytes (com.palantir.atlasdb.encoding.PtBytes)2 Cell (com.palantir.atlasdb.keyvalue.api.Cell)2 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)2 ClusterFactory (com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory)2 CassandraClusterConfig (com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory.CassandraClusterConfig)2 BoundStatement (com.datastax.driver.core.BoundStatement)1 PreparedStatement (com.datastax.driver.core.PreparedStatement)1 Session (com.datastax.driver.core.Session)1 DefaultRetryPolicy (com.datastax.driver.core.policies.DefaultRetryPolicy)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableRangeSet.toImmutableRangeSet (com.google.common.collect.ImmutableRangeSet.toImmutableRangeSet)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Range (com.google.common.collect.Range)1 RangeMap (com.google.common.collect.RangeMap)1 RangeSet (com.google.common.collect.RangeSet)1