Search in sources :

Example 1 with DefaultCassandraAsyncKeyValueServiceFactory

use of com.palantir.atlasdb.keyvalue.cassandra.async.DefaultCassandraAsyncKeyValueServiceFactory in project atlasdb by palantir.

the class CassandraContainer method getConfigWithProxy.

public CassandraKeyValueServiceConfig getConfigWithProxy(SocketAddress proxyAddress) {
    Preconditions.checkState(config.servers() instanceof CqlCapableConfig, "Has to be CqlCapableConfig");
    CqlCapableConfig cqlCapableConfig = (CqlCapableConfig) config.servers();
    return ImmutableCassandraKeyValueServiceConfig.builder().from(config).servers(ImmutableCqlCapableConfig.builder().from(cqlCapableConfig).build()).asyncKeyValueServiceFactory(new DefaultCassandraAsyncKeyValueServiceFactory(new DefaultCqlClientFactory(() -> Cluster.builder().withNettyOptions(new SocksProxyNettyOptions(proxyAddress))))).build();
}
Also used : DefaultCqlClientFactory(com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.DefaultCqlClientFactory) DefaultCassandraAsyncKeyValueServiceFactory(com.palantir.atlasdb.keyvalue.cassandra.async.DefaultCassandraAsyncKeyValueServiceFactory) CqlCapableConfig(com.palantir.atlasdb.cassandra.CassandraServersConfigs.CqlCapableConfig) ImmutableCqlCapableConfig(com.palantir.atlasdb.cassandra.ImmutableCqlCapableConfig)

Example 2 with DefaultCassandraAsyncKeyValueServiceFactory

use of com.palantir.atlasdb.keyvalue.cassandra.async.DefaultCassandraAsyncKeyValueServiceFactory 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

DefaultCassandraAsyncKeyValueServiceFactory (com.palantir.atlasdb.keyvalue.cassandra.async.DefaultCassandraAsyncKeyValueServiceFactory)2 BoundStatement (com.datastax.driver.core.BoundStatement)1 Cluster (com.datastax.driver.core.Cluster)1 PreparedStatement (com.datastax.driver.core.PreparedStatement)1 Session (com.datastax.driver.core.Session)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Futures (com.google.common.util.concurrent.Futures)1 AtlasDbConstants (com.palantir.atlasdb.AtlasDbConstants)1 CassandraKeyValueServiceConfig (com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig)1 CassandraKeyValueServiceRuntimeConfig (com.palantir.atlasdb.cassandra.CassandraKeyValueServiceRuntimeConfig)1 CqlCapableConfig (com.palantir.atlasdb.cassandra.CassandraServersConfigs.CqlCapableConfig)1 CqlCapableConfigTuning (com.palantir.atlasdb.cassandra.CassandraServersConfigs.CqlCapableConfigTuning)1 ImmutableCassandraKeyValueServiceConfig (com.palantir.atlasdb.cassandra.ImmutableCassandraKeyValueServiceConfig)1 ImmutableCqlCapableConfig (com.palantir.atlasdb.cassandra.ImmutableCqlCapableConfig)1 ReloadingCloseableContainerImpl (com.palantir.atlasdb.cassandra.ReloadingCloseableContainerImpl)1 CassandraResource (com.palantir.atlasdb.containers.CassandraResource)1 PtBytes (com.palantir.atlasdb.encoding.PtBytes)1 AsyncKeyValueService (com.palantir.atlasdb.keyvalue.api.AsyncKeyValueService)1 Cell (com.palantir.atlasdb.keyvalue.api.Cell)1