/*
* Test the ConstantReconnectionPolicy.
*/
@Test(groups = "long")
public void constantReconnectionPolicyTest() throws Throwable {
Cluster.Builder builder = Cluster.builder().withReconnectionPolicy(new ConstantReconnectionPolicy(10 * 1000));
// Ensure that ConstantReconnectionPolicy is what we should be testing
if (!(builder.getConfiguration().getPolicies().getReconnectionPolicy() instanceof ConstantReconnectionPolicy)) {
fail("Set policy does not match retrieved policy.");
}
// Test basic getters
ConstantReconnectionPolicy reconnectionPolicy = (ConstantReconnectionPolicy) builder.getConfiguration().getPolicies().getReconnectionPolicy();
assertTrue(reconnectionPolicy.getConstantDelayMs() == 10 * 1000);
// Test erroneous instantiations
try {
new ConstantReconnectionPolicy(-1);
fail();
} catch (IllegalArgumentException e) {}
// Test nextDelays()
ReconnectionPolicy.ReconnectionSchedule schedule = new ConstantReconnectionPolicy(10 * 1000).newSchedule();
assertTrue(schedule.nextDelayMs() == 10000);
assertTrue(schedule.nextDelayMs() == 10000);
assertTrue(schedule.nextDelayMs() == 10000);
assertTrue(schedule.nextDelayMs() == 10000);
assertTrue(schedule.nextDelayMs() == 10000);