com.datastax.driver.core.policies.LatencyAwarePolicy Java Examples

The following examples show how to use com.datastax.driver.core.policies.LatencyAwarePolicy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LatencyAwarePolicyFactory.java    From dropwizard-cassandra with Apache License 2.0 6 votes vote down vote up
@Override
public LoadBalancingPolicy build() {
    LatencyAwarePolicy.Builder builder = LatencyAwarePolicy.builder(subPolicy.build());

    if (exclusionThreshold != null) {
        builder.withExclusionThreshold(exclusionThreshold);
    }

    if (minimumMeasurements != null) {
        builder.withMininumMeasurements(minimumMeasurements);
    }

    if (retryPeriod != null) {
        builder.withRetryPeriod(retryPeriod.getQuantity(), retryPeriod.getUnit());
    }

    if (scale != null) {
        builder.withScale(scale.getQuantity(), scale.getUnit());
    }

    if (updateRate != null) {
        builder.withUpdateRate(updateRate.getQuantity(), updateRate.getUnit());
    }

    return builder.build();
}
 
Example #2
Source File: UtilsUnitTest.java    From cassandra-jdbc-wrapper with Apache License 2.0 5 votes vote down vote up
@Test
public void testLoadBalancingPolicyParsing() throws Exception
{
	String lbPolicyStr = "RoundRobinPolicy()";
	System.out.println(lbPolicyStr);
	assertTrue(Utils.parseLbPolicy(lbPolicyStr) instanceof RoundRobinPolicy);
	System.out.println("====================");
	lbPolicyStr = "TokenAwarePolicy(RoundRobinPolicy())";
	System.out.println(lbPolicyStr);
	assertTrue(Utils.parseLbPolicy(lbPolicyStr) instanceof TokenAwarePolicy);
	System.out.println("====================");
	lbPolicyStr = "DCAwareRoundRobinPolicy(\"dc1\")";
	System.out.println(lbPolicyStr);
	assertTrue(Utils.parseLbPolicy(lbPolicyStr) instanceof DCAwareRoundRobinPolicy);
	System.out.println("====================");
	lbPolicyStr = "TokenAwarePolicy(DCAwareRoundRobinPolicy(\"dc1\"))";
	System.out.println(lbPolicyStr);
	assertTrue(Utils.parseLbPolicy(lbPolicyStr) instanceof TokenAwarePolicy);    	
	System.out.println("====================");
	lbPolicyStr = "TokenAwarePolicy";
	System.out.println(lbPolicyStr);
	assertTrue(Utils.parseLbPolicy(lbPolicyStr)==null);
	System.out.println("====================");
	lbPolicyStr = "LatencyAwarePolicy(TokenAwarePolicy(RoundRobinPolicy()),(double) 10.5,(long) 1,(long) 10,(long)1,10)";    	
	System.out.println(lbPolicyStr);
	assertTrue(Utils.parseLbPolicy(lbPolicyStr) instanceof LatencyAwarePolicy);
	System.out.println("====================");    	    	
	
}
 
Example #3
Source File: LatencyAwarePolicyFactoryTest.java    From dropwizard-cassandra with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    when(subPolicyFactory.build()).thenReturn(subPolicy);
    mockStatic(LatencyAwarePolicy.class);
    when(LatencyAwarePolicy.builder(subPolicy)).thenReturn(policyBuilder);
    when(policyBuilder.build()).thenReturn(resultingPolicy);
}