use of com.datastax.driver.core.Cluster in project aroma-data-operations by RedRoma.
the class ModuleCassandraDevClusterTest method testProvideCQLBuilder.
@Test
public void testProvideCQLBuilder() {
ReconnectionPolicy policy = instance.provideReconnectPolicy();
Cluster cluster = instance.provideCassandraCluster(policy);
}
use of com.datastax.driver.core.Cluster in project aroma-data-operations by RedRoma.
the class ModuleCassandraDevClusterTest method testProvideCassandraSession.
@Test
public void testProvideCassandraSession() {
ReconnectionPolicy policy = instance.provideReconnectPolicy();
Cluster cluster = instance.provideCassandraCluster(policy);
Session session = instance.provideCassandraSession(cluster);
assertThat(session, notNullValue());
}
use of com.datastax.driver.core.Cluster in project aroma-data-operations by RedRoma.
the class ModuleCassandraDevClusterTest method testProvideCassandraCluster.
@Test
public void testProvideCassandraCluster() {
ReconnectionPolicy policy = instance.provideReconnectPolicy();
Cluster cluster = instance.provideCassandraCluster(policy);
assertThat(cluster, notNullValue());
}
use of com.datastax.driver.core.Cluster in project cas by apereo.
the class DefaultCassandraSessionFactory method initializeCassandraCluster.
private static Cluster initializeCassandraCluster(final BaseCassandraProperties cassandra) {
final Cluster cluster;
final PoolingOptions poolingOptions = new PoolingOptions().setMaxRequestsPerConnection(HostDistance.LOCAL, cassandra.getMaxRequestsPerConnection()).setConnectionsPerHost(HostDistance.LOCAL, cassandra.getCoreConnections(), cassandra.getMaxConnections());
final DCAwareRoundRobinPolicy.Builder dcPolicyBuilder = DCAwareRoundRobinPolicy.builder();
if (StringUtils.isNotBlank(cassandra.getLocalDc())) {
dcPolicyBuilder.withLocalDc(cassandra.getLocalDc());
}
final TokenAwarePolicy loadBalancingPolicy = new TokenAwarePolicy(dcPolicyBuilder.build(), cassandra.isShuffleReplicas());
final SocketOptions socketOptions = new SocketOptions().setConnectTimeoutMillis(cassandra.getConnectTimeoutMillis()).setReadTimeoutMillis(cassandra.getReadTimeoutMillis());
final QueryOptions queryOptions = new QueryOptions().setConsistencyLevel(ConsistencyLevel.valueOf(cassandra.getConsistencyLevel())).setSerialConsistencyLevel(ConsistencyLevel.valueOf(cassandra.getSerialConsistencyLevel()));
final RetryPolicy retryPolicy = RetryPolicyType.valueOf(cassandra.getRetryPolicy()).getRetryPolicy();
final Cluster.Builder builder = Cluster.builder().withCredentials(cassandra.getUsername(), cassandra.getPassword()).withPoolingOptions(poolingOptions).withProtocolVersion(ProtocolVersion.valueOf(cassandra.getProtocolVersion())).withLoadBalancingPolicy(loadBalancingPolicy).withSocketOptions(socketOptions).withRetryPolicy(new LoggingRetryPolicy(retryPolicy)).withCompression(ProtocolOptions.Compression.valueOf(cassandra.getCompression())).withPort(cassandra.getPort()).withQueryOptions(queryOptions);
Arrays.stream(StringUtils.split(cassandra.getContactPoints(), ',')).forEach(contactPoint -> builder.addContactPoint(StringUtils.trim(contactPoint)));
cluster = builder.build();
if (LOGGER.isDebugEnabled()) {
cluster.getMetadata().getAllHosts().forEach(clusterHost -> LOGGER.debug("Host [{}]:\n\n\tDC: [{}]\n\tRack: [{}]\n\tVersion: [{}]\n\tDistance: [{}]\n\tUp?: [{}]\n", clusterHost.getAddress(), clusterHost.getDatacenter(), clusterHost.getRack(), clusterHost.getCassandraVersion(), loadBalancingPolicy.distance(clusterHost), clusterHost.isUp()));
}
return cluster;
}
use of com.datastax.driver.core.Cluster in project ignite by apache.
the class CassandraSessionImplTest method executeFailureTest.
@SuppressWarnings("unchecked")
@Test
public void executeFailureTest() {
Session session1 = mock(Session.class);
Session session2 = mock(Session.class);
when(session1.prepare(any(String.class))).thenReturn(preparedStatement1);
when(session2.prepare(any(String.class))).thenReturn(preparedStatement2);
ResultSetFuture rsFuture = mock(ResultSetFuture.class);
ResultSet rs = mock(ResultSet.class);
Iterator it = mock(Iterator.class);
when(it.hasNext()).thenReturn(true);
when(it.next()).thenReturn(mock(Row.class));
when(rs.iterator()).thenReturn(it);
when(rsFuture.getUninterruptibly()).thenReturn(rs);
/* @formatter:off */
when(session1.executeAsync(any(Statement.class))).thenThrow(new InvalidQueryException("You may have used a PreparedStatement that was created with another Cluster instance")).thenThrow(new RuntimeException("this session should be refreshed / recreated"));
when(session2.executeAsync(boundStatement1)).thenThrow(new InvalidQueryException("You may have used a PreparedStatement that was created with another Cluster instance"));
when(session2.executeAsync(boundStatement2)).thenReturn(rsFuture);
/* @formatter:on */
Cluster cluster = mock(Cluster.class);
when(cluster.connect()).thenReturn(session1).thenReturn(session2);
when(session1.getCluster()).thenReturn(cluster);
when(session2.getCluster()).thenReturn(cluster);
Cluster.Builder builder = mock(Cluster.Builder.class);
when(builder.build()).thenReturn(cluster);
CassandraSessionImpl cassandraSession = new CassandraSessionImpl(builder, null, ConsistencyLevel.ONE, ConsistencyLevel.ONE, 0, mock(IgniteLogger.class));
BatchExecutionAssistant<String, String> batchExecutionAssistant = new MyBatchExecutionAssistant();
ArrayList<String> data = new ArrayList<>();
for (int i = 0; i < 10; i++) {
data.add(String.valueOf(i));
}
cassandraSession.execute(batchExecutionAssistant, data);
verify(cluster, times(2)).connect();
verify(session1, times(1)).prepare(any(String.class));
verify(session2, times(1)).prepare(any(String.class));
assertEquals(10, batchExecutionAssistant.processedCount());
}
Aggregations