use of com.datastax.driver.core.policies.ConstantReconnectionPolicy in project ASAP by salmant.
the class DM method Fetch_AVG_response_time_metric.
// ///////////////////////////////////////////
public static double Fetch_AVG_response_time_metric(String metric_name, String haproxy_agentid, String event_date) {
Cluster cluster;
Session session;
cluster = Cluster.builder().addContactPoints("194.249.1.175").withCredentials("catascopia_user", "catascopia_pass").withPort(9042).withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE).withReconnectionPolicy(new ConstantReconnectionPolicy(1000L)).build();
session = cluster.connect("jcatascopiadb");
haproxy_agentid = haproxy_agentid + ":" + metric_name;
ResultSet results = session.execute("select value from jcatascopiadb.metric_value_table where metricid=\'" + haproxy_agentid + "\' and event_date=\'" + event_date + "\' ORDER BY event_timestamp DESC LIMIT 1");
double AVG_response_time_metric = 0.0;
for (Row row : results) {
AVG_response_time_metric = Double.parseDouble(row.getString("value"));
}
return Math.abs(AVG_response_time_metric);
}
use of com.datastax.driver.core.policies.ConstantReconnectionPolicy in project ASAP by salmant.
the class Run_a_Container method add_to_cluster_in_cassandra.
// ///////////////////////////////////////////////////////////
public void add_to_cluster_in_cassandra() {
Cluster cluster;
Session session;
cluster = Cluster.builder().addContactPoints("194.249.1.175").withCredentials("catascopia_user", "catascopia_pass").withPort(9042).withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE).withReconnectionPolicy(new ConstantReconnectionPolicy(1000L)).build();
session = cluster.connect("jcatascopiadb");
ResultSet results = session.execute("select * from jcatascopiadb.agent_table;");
for (Row row : results) {
if ((new_IP.equals(row.getString("agentip"))) && (row.getString("status").equals("UP"))) {
String new_agentid = row.getString("agentid");
ResultSet results2 = session.execute("INSERT INTO jcatascopiadb.subscription_agents_table (subid, agentid, agentip) VALUES (\'" + subid + "\', \'" + new_agentid + "\', \'" + new_IP + "\');");
}
}
}
use of com.datastax.driver.core.policies.ConstantReconnectionPolicy in project java-driver by datastax.
the class ThreadingOptionsTest method should_use_provided_threading_options.
/**
* Validates that when using a provided {@link ThreadingOptions} that its methods are used for creating
* executors and that its {@link ThreadingOptions#createThreadFactory(String, String)} is used for initializing
* netty resources.
*
* @test_category configuration
*/
@Test(groups = "short")
public void should_use_provided_threading_options() {
ThreadingOptions spy = Mockito.spy(threadingOptions);
Cluster cluster = createClusterBuilder().withPoolingOptions(new PoolingOptions().setConnectionsPerHost(HostDistance.LOCAL, 1, 1)).withReconnectionPolicy(new ConstantReconnectionPolicy(100)).withThreadingOptions(spy).build();
try {
String clusterName = cluster.getClusterName();
cluster.init();
// Ensure each method was invoked appropriately:
// 1) 1 time for each create*Executor.
// 2) createThreadFactory for netty executor group and timeouter.
verify(spy).createExecutor(clusterName);
verify(spy).createBlockingExecutor(clusterName);
verify(spy).createReconnectionExecutor(clusterName);
verify(spy).createScheduledTasksExecutor(clusterName);
verify(spy).createReaperExecutor(clusterName);
verify(spy).createThreadFactory(clusterName, "nio-worker");
verify(spy).createThreadFactory(clusterName, "timeouter");
cluster.connect();
// Close all connections bringing the host down, this should cause some activity on
// executor and reconnection executor.
currentClient.disableListener();
currentClient.closeConnections(CLOSE);
TestUtils.waitForDown(TestUtils.IP_PREFIX + "1", cluster);
currentClient.enableListener();
TestUtils.waitForUp(TestUtils.IP_PREFIX + "1", cluster);
Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) {
// all threads should use the custom factory and thus be marked daemon
if (thread.getName().startsWith(clusterName + "-" + customPrefix)) {
// all created threads should be daemon this should indicate that our custom thread factory was
// used.
assertThat(thread.isDaemon()).isTrue();
}
}
final Pattern threadNamePattern = Pattern.compile(clusterName + "-" + customPrefix + "-(.*)-0");
// Custom executor threads should be present.
// NOTE: we don't validate blocking executor since it is hard to deterministically cause it to be used.
assertThat(threads).extracting(new Extractor<Thread, String>() {
@Override
public String extract(Thread thread) {
Matcher matcher = threadNamePattern.matcher(thread.getName());
if (matcher.matches()) {
return matcher.group(1);
} else {
return thread.getName();
}
}
}).contains("nio-worker", "timeouter", "myExecutor", "myReconnection", "myScheduled-task-worker", "myConnection-reaper");
} finally {
cluster.close();
}
}
use of com.datastax.driver.core.policies.ConstantReconnectionPolicy in project java-driver by datastax.
the class TimeoutStressTest method createClusterBuilder.
@Override
public Cluster.Builder createClusterBuilder() {
channelMonitor = register(new SocketChannelMonitor());
PoolingOptions poolingOptions = new PoolingOptions().setConnectionsPerHost(HostDistance.LOCAL, 8, 8);
return Cluster.builder().withPoolingOptions(poolingOptions).withNettyOptions(channelMonitor.nettyOptions()).withReconnectionPolicy(new ConstantReconnectionPolicy(1000));
}
use of com.datastax.driver.core.policies.ConstantReconnectionPolicy in project java-driver by datastax.
the class ReconnectionTest method should_trigger_one_time_reconnect.
@CCMConfig(dirtiesContext = true, createCluster = false)
@Test(groups = "long")
public void should_trigger_one_time_reconnect() throws InterruptedException, IOException {
TogglabePolicy loadBalancingPolicy = new TogglabePolicy(new RoundRobinPolicy());
Cluster cluster = register(Cluster.builder().addContactPointsWithPorts(ccm().addressOfNode(1)).withPort(ccm().getBinaryPort()).withLoadBalancingPolicy(loadBalancingPolicy).withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis)).build());
cluster.connect();
// Tweak the LBP so that the control connection never reconnects, otherwise
// it would interfere with the rest of the test (this is a bit of a hack)
loadBalancingPolicy.returnEmptyQueryPlan = true;
// Stop the node, ignore it and cancel reconnection attempts to it
ccm().stop(1);
ccm().waitForDown(1);
assertThat(cluster).host(1).goesDownWithin(20, SECONDS);
Host host1 = TestUtils.findHost(cluster, 1);
loadBalancingPolicy.setDistance(TestUtils.findHost(cluster, 1), HostDistance.IGNORED);
ListenableFuture<?> reconnectionAttemptFuture = host1.getReconnectionAttemptFuture();
if (reconnectionAttemptFuture != null)
reconnectionAttemptFuture.cancel(false);
// Trigger a one-time reconnection attempt (this will fail)
host1.tryReconnectOnce();
// Wait for a few reconnection cycles before checking
TimeUnit.MILLISECONDS.sleep(reconnectionDelayMillis * 2);
assertThat(cluster).host(1).hasState(State.DOWN);
// Restart the node (this will not trigger an UP notification thanks to our
// hack to disable the control connection reconnects). The host should stay
// down for the driver.
ccm().start(1);
ccm().waitForUp(1);
assertThat(cluster).host(1).hasState(State.DOWN);
TimeUnit.SECONDS.sleep(Cluster.NEW_NODE_DELAY_SECONDS);
assertThat(cluster).host(1).hasState(State.DOWN);
// Trigger another one-time reconnection attempt (this will succeed). The
// host should be back up.
host1.tryReconnectOnce();
assertThat(cluster).host(1).comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS * 2, SECONDS);
}
Aggregations