use of com.datastax.driver.core.policies.ConstantReconnectionPolicy in project java-driver by datastax.
the class ReconnectionTest method should_keep_reconnecting_on_authentication_error.
@CCMConfig(dirtiesContext = true, config = "authenticator:PasswordAuthenticator", jvmArgs = "-Dcassandra.superuser_setup_delay_ms=0", createCluster = false)
@Test(groups = "long")
public void should_keep_reconnecting_on_authentication_error() throws InterruptedException {
// user being created.
if (ccm().getCassandraVersion().getMajor() < 2) {
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
}
CountingReconnectionPolicy reconnectionPolicy = new CountingReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis));
CountingAuthProvider authProvider = new CountingAuthProvider("cassandra", "cassandra");
Cluster cluster = register(Cluster.builder().addContactPoints(getContactPoints().get(0)).withPort(ccm().getBinaryPort()).withAuthProvider(authProvider).withReconnectionPolicy(reconnectionPolicy).build());
cluster.init();
assertThat(cluster).usesControlHost(1);
// Stop the server, set wrong credentials and restart
ccm().stop(1);
ccm().waitForDown(1);
authProvider.setPassword("wrongPassword");
ccm().start(1);
ccm().waitForUp(1);
// Wait a few iterations to ensure that our authProvider has returned the wrong credentials at least twice
// NB: authentication errors show up in the logs
int initialCount = authProvider.count.get();
long initialMetricCount = cluster.getMetrics().getErrorMetrics().getAuthenticationErrors().getCount();
// make sure we don't wait indefinitely
int iterations = 0, maxIterations = 12;
do {
iterations += 1;
TimeUnit.SECONDS.sleep(5);
} while (iterations < maxIterations && authProvider.count.get() <= initialCount + 1);
assertThat(iterations).isLessThan(maxIterations);
// Number of authentication errors should have increased.
assertThat(cluster.getMetrics().getErrorMetrics().getAuthenticationErrors().getCount()).isGreaterThan(initialMetricCount);
// Fix the credentials
authProvider.setPassword("cassandra");
// The driver should eventually reconnect to the node
assertThat(cluster).host(1).comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS * 2, SECONDS);
}
use of com.datastax.driver.core.policies.ConstantReconnectionPolicy in project cassandra-driver-mapping by valchkou.
the class SchemaSyncTest method init.
@BeforeClass
public static void init() {
String node = "127.0.0.1";
Builder builder = Cluster.builder();
builder.addContactPoint(node);
builder.withLoadBalancingPolicy(LatencyAwarePolicy.builder(new RoundRobinPolicy()).build());
builder.withReconnectionPolicy(new ConstantReconnectionPolicy(1000L));
cluster = builder.build();
session = cluster.connect();
Cache<String, PreparedStatement> cache = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.MILLISECONDS).maximumSize(1).concurrencyLevel(1).build();
MappingSession.setStatementCache(cache);
}
use of com.datastax.driver.core.policies.ConstantReconnectionPolicy in project cassandra-driver-mapping by valchkou.
the class MappingSessionAsyncTest method init.
@BeforeClass
public static void init() {
String node = "127.0.0.1";
Builder builder = Cluster.builder();
builder.addContactPoint(node);
builder.withLoadBalancingPolicy(LatencyAwarePolicy.builder(new RoundRobinPolicy()).build());
builder.withReconnectionPolicy(new ConstantReconnectionPolicy(1000L));
cluster = builder.build();
session = cluster.connect();
Cache<String, PreparedStatement> cache = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.MILLISECONDS).maximumSize(1).concurrencyLevel(1).build();
MappingSession.setStatementCache(cache);
}
use of com.datastax.driver.core.policies.ConstantReconnectionPolicy in project cassandra-driver-mapping by valchkou.
the class MappingSessionTest method init.
@BeforeClass
public static void init() {
String node = "127.0.0.1";
Builder builder = Cluster.builder();
builder.addContactPoint(node);
builder.withLoadBalancingPolicy(LatencyAwarePolicy.builder(new RoundRobinPolicy()).build());
builder.withReconnectionPolicy(new ConstantReconnectionPolicy(1000L));
cluster = builder.build();
session = cluster.connect();
Cache<String, PreparedStatement> cache = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.MILLISECONDS).maximumSize(1).concurrencyLevel(1).build();
MappingSession.setStatementCache(cache);
}
Aggregations