private void primeAndExecuteQueries(String[] primed, String[] queries) throws Exception { SuccessResult result = getSampleSuccessResult(); for (String primeQuery : primed) { server.prime(when(primeQuery).then(result)); } try (com.datastax.driver.core.Cluster driverCluster = defaultBuilder(server.getCluster()) .withRetryPolicy(FallthroughRetryPolicy.INSTANCE) .build()) { Session session = driverCluster.connect(); server.getCluster().clearLogs(); for (String executeQuery : queries) { SimpleStatement stmt = new SimpleStatement(executeQuery); stmt.setDefaultTimestamp(100); session.execute(stmt); } } }
@Test public void testShouldMarkPeerQueriesAsNonPrimed() throws Exception { server.getCluster().clearLogs(); try (com.datastax.driver.core.Cluster driverCluster = defaultBuilder(server.getCluster()) .withRetryPolicy(FallthroughRetryPolicy.INSTANCE) .build()) { driverCluster.init(); } // verify for node level filter: primed. This should be empty as no primed queries were made // other than internal. List<QueryLog> queryLogs = getAllQueryLogs(server.getLogs(server.getCluster().getName() + "?filter=primed")); assertThat(queryLogs).isEmpty(); // non primed should have the internal peer queries. queryLogs = getAllQueryLogs(server.getLogs(server.getCluster().getName() + "?filter=nonprimed")); assertThat(queryLogs).isNotEmpty(); }
public HintsPollerCQLSession cqlSessionForHintsPoller(CassandraConfiguration configuration) { // Nodes can register themselves in ZooKeeper to help figure out which hosts are in this data center. configuration.withZooKeeperHostDiscovery(_curator); // Hints Poller only need 1 connection per host since all this is used for is single-threaded polling of the hints table. // We could also have a new property in the CassandraConfiguration yaml's just for the HintsPoller sake. CqlCluster cqlCluster = configuration.cql() .metricRegistry(_metricRegistry) .disableClusterMetrics() .maxConnectionsPerHost(1) .coreConnectionsPerHost(1) .loadBalancingPolicy(new SelectedHostLoadBalancingPolicy()) .retryPolicy(FallthroughRetryPolicy.INSTANCE) .cluster(); _lifeCycle.manage(cqlCluster); return new HintsPollerCQLSession(_lifeCycle, cqlCluster); }
@Test public void testRetryPolicyParsing() throws Exception { String retryPolicyStr = "DefaultRetryPolicy"; System.out.println(retryPolicyStr); assertTrue(Utils.parseRetryPolicy(retryPolicyStr) instanceof DefaultRetryPolicy); System.out.println("===================="); retryPolicyStr = "DowngradingConsistencyRetryPolicy"; System.out.println(retryPolicyStr); assertTrue(Utils.parseRetryPolicy(retryPolicyStr) instanceof DowngradingConsistencyRetryPolicy); System.out.println("===================="); retryPolicyStr = "FallthroughRetryPolicy"; System.out.println(retryPolicyStr); assertTrue(Utils.parseRetryPolicy(retryPolicyStr) instanceof FallthroughRetryPolicy); System.out.println("===================="); }
/** * Derive the retry policy from the given string to the implementation. Defaults to {@link DefaultRetryPolicy}. * * @param retryPolicy * The name of the retry policy to use. Can be "downgrading" {@link DowngradingConsistencyRetryPolicy} or * "fallthrough" {@link FallthroughRetryPolicy}. Everything else defaults to * Policies.defaultRetryPolicy() */ public void setRetryPolicy(String retryPolicy) { switch(retryPolicy) { case "downgrading": setRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); break; case "fallthrough": setRetryPolicy(FallthroughRetryPolicy.INSTANCE); break; default: setRetryPolicy(Policies.defaultRetryPolicy()); break; } }
private Builder populateRetrytPolicy(Map<String, String> properties, Builder builder) throws DataServiceFault { String retryPolicy = properties.get(DBConstants.Cassandra.RETRY_POLICY); if (retryPolicy != null) { if ("DefaultRetryPolicy".equals(retryPolicy)) { builder = builder.withRetryPolicy(DefaultRetryPolicy.INSTANCE); } else if ("DowngradingConsistencyRetryPolicy".equals(retryPolicy)) { builder = builder.withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); } else if ("FallthroughRetryPolicy".equals(retryPolicy)) { builder = builder.withRetryPolicy(FallthroughRetryPolicy.INSTANCE); } else if ("LoggingDefaultRetryPolicy".equals(retryPolicy)) { builder = builder.withRetryPolicy(new LoggingRetryPolicy(DefaultRetryPolicy.INSTANCE)); } else if ("LoggingDowngradingConsistencyRetryPolicy".equals(retryPolicy)) { builder = builder.withRetryPolicy(new LoggingRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE)); } else if ("LoggingFallthroughRetryPolicy".equals(retryPolicy)) { builder = builder.withRetryPolicy(new LoggingRetryPolicy(FallthroughRetryPolicy.INSTANCE)); } else { throw new DataServiceFault("Invalid Cassandra retry policy: " + retryPolicy); } } return builder; }
private void query(String statement, ClusterSpec cluster) throws Exception { try (com.datastax.driver.core.Cluster driverCluster = com.datastax.driver.core.Cluster.builder() .addContactPointsWithPorts(cluster.node(0).inetSocketAddress()) .withNettyOptions(SimulacronDriverSupport.nonQuietClusterCloseOptions) .withRetryPolicy(FallthroughRetryPolicy.INSTANCE) .build()) { driverCluster.connect().execute(statement); } }
private PreparedStatement prepare() throws Exception { try (com.datastax.driver.core.Cluster driverCluster = defaultBuilder(server.getCluster()) .withRetryPolicy(FallthroughRetryPolicy.INSTANCE) .build()) { return driverCluster.connect().prepare(query); } }
private ResultSet prepareAndQuery() throws Exception { try (com.datastax.driver.core.Cluster driverCluster = defaultBuilder(server.getCluster()) .withRetryPolicy(FallthroughRetryPolicy.INSTANCE) .build()) { Session session = driverCluster.connect(); PreparedStatement prepared = session.prepare(query); return session.execute(prepared.bind()); } }
private ResultSet query(Statement statement) throws Exception { try (com.datastax.driver.core.Cluster driverCluster = defaultBuilder(server.getCluster()) .withRetryPolicy(FallthroughRetryPolicy.INSTANCE) .build()) { return driverCluster.connect().execute(statement); } }
@Test public void returnsFallthroughRetryPolicyInstance() throws Exception { final FallthroughRetryPolicyFactory factory = new FallthroughRetryPolicyFactory(); final FallthroughRetryPolicy policy = (FallthroughRetryPolicy) factory.build(); assertThat(policy).isSameAs(FallthroughRetryPolicy.INSTANCE); }
private Cluster.Builder populateRetrytPolicy(Properties properties, Cluster.Builder builder) { String retryPolicy = properties.getProperty(CassandraStoreParameters.RETRY_POLICY); if (retryPolicy != null) { switch (retryPolicy) { case "DefaultRetryPolicy": builder = builder.withRetryPolicy(DefaultRetryPolicy.INSTANCE); break; case "DowngradingConsistencyRetryPolicy": builder = builder.withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); break; case "FallthroughRetryPolicy": builder = builder.withRetryPolicy(FallthroughRetryPolicy.INSTANCE); break; case "LoggingDefaultRetryPolicy": builder = builder.withRetryPolicy(new LoggingRetryPolicy(DefaultRetryPolicy.INSTANCE)); break; case "LoggingDowngradingConsistencyRetryPolicy": builder = builder.withRetryPolicy(new LoggingRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE)); break; case "LoggingFallthroughRetryPolicy": builder = builder.withRetryPolicy(new LoggingRetryPolicy(FallthroughRetryPolicy.INSTANCE)); break; default: LOG.error("Unsupported retry policy : {} ", retryPolicy); break; } } return builder; }
@Override public RetryPolicy build() { return FallthroughRetryPolicy.INSTANCE; }