Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry policy configuration #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.datastax.driver.core.SocketOptions;
import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy;
import com.datastax.driver.core.policies.LoadBalancingPolicy;
import com.datastax.driver.core.policies.RetryPolicy;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -30,6 +31,8 @@ public class MapConfiguredCqlClientFactory extends CqlClientFactory {
public static final String TRIDENT_CASSANDRA_CONSISTENCY = "trident.cassandra.consistency";
public static final String TRIDENT_CASSANDRA_SERIAL_CONSISTENCY = "trident.cassandra.serial.consistency";
public static final String TRIDENT_CASSANDRA_QUERY_LOGGER_CONSTANT_THRESHOLD = "trident.cassandra.query.logger.constant.threshold";
public static final String TRIDENT_CASSANDRA_RETRY_POLICY_ENABLE = "trident.cassandra.retry.policy.enable";
public static final String TRIDENT_CASSANDRA_RETRY_POLICY = "trident.cassandra.retry.policy";

final Map<Object,Object> configuration;

Expand Down Expand Up @@ -103,6 +106,12 @@ private void configureOther() {
if (StringUtils.isNotEmpty(nameConfiguration)) {
builder = builder.withClusterName(nameConfiguration);
}

boolean retryPolicyEnabled = configuration.containsKey(TRIDENT_CASSANDRA_RETRY_POLICY_ENABLE) ? (boolean) configuration.get(TRIDENT_CASSANDRA_RETRY_POLICY_ENABLE) : false;
if (retryPolicyEnabled && configuration.containsKey(TRIDENT_CASSANDRA_RETRY_POLICY) && configuration.get(TRIDENT_CASSANDRA_RETRY_POLICY) != null) {
builder = builder.withRetryPolicy((RetryPolicy) configuration.get(TRIDENT_CASSANDRA_RETRY_POLICY));
}

}

private void configureLoadBalancingPolicy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.HashMap;
import java.util.Map;

import com.datastax.driver.core.policies.DefaultRetryPolicy;
import com.datastax.driver.core.policies.FallthroughRetryPolicy;
import junit.framework.Assert;

import org.junit.Test;
Expand All @@ -22,6 +24,8 @@ public void testGetClusterBuilder() throws Exception {
configuration.put(MapConfiguredCqlClientFactory.TRIDENT_CASSANDRA_LOCAL_DATA_CENTER_NAME, DATA_CENTER_NAME);
configuration.put(MapConfiguredCqlClientFactory.TRIDENT_CASSANDRA_CONSISTENCY, DEFAULT_CONSISTENCY_LEVEL.name());
configuration.put(MapConfiguredCqlClientFactory.TRIDENT_CASSANDRA_SERIAL_CONSISTENCY, DEFAULT_SERIAL_CONSISTENCY_LEVEL.name());
configuration.put(MapConfiguredCqlClientFactory.TRIDENT_CASSANDRA_RETRY_POLICY, FallthroughRetryPolicy.INSTANCE);
configuration.put(MapConfiguredCqlClientFactory.TRIDENT_CASSANDRA_RETRY_POLICY_ENABLE, true);

final CqlClientFactory factory =
new MapConfiguredCqlClientFactory(configuration);
Expand All @@ -39,6 +43,19 @@ public void testGetClusterBuilder() throws Exception {
Assert.assertEquals(DEFAULT_CONSISTENCY_LEVEL, clusterBuilder.getConfiguration().getQueryOptions().getConsistencyLevel());
Assert.assertEquals(DEFAULT_SERIAL_CONSISTENCY_LEVEL, clusterBuilder.getConfiguration().getQueryOptions().getSerialConsistencyLevel());
Assert.assertEquals(ProtocolOptions.Compression.NONE, clusterBuilder.getConfiguration().getProtocolOptions().getCompression());
Assert.assertTrue(clusterBuilder.getConfiguration().getPolicies().getRetryPolicy() instanceof FallthroughRetryPolicy);
}

@Test
public void testDisableRetryPolicy() {
final Map<Object, Object> configuration = new HashMap<Object,Object>();
configuration.put(MapConfiguredCqlClientFactory.TRIDENT_CASSANDRA_CQL_HOSTS, HOSTS);
configuration.put(MapConfiguredCqlClientFactory.TRIDENT_CASSANDRA_RETRY_POLICY, FallthroughRetryPolicy.INSTANCE);
final CqlClientFactory factory =
new MapConfiguredCqlClientFactory(configuration);

final Cluster.Builder clusterBuilder = factory.getClusterBuilder();
Assert.assertTrue(clusterBuilder.getConfiguration().getPolicies().getRetryPolicy() instanceof DefaultRetryPolicy);
}

@Test
Expand Down