|
22 | 22 | import java.util.ArrayList; |
23 | 23 | import java.util.List; |
24 | 24 | import java.util.UUID; |
| 25 | +import java.util.concurrent.TimeUnit; |
25 | 26 |
|
26 | 27 | import org.junit.BeforeClass; |
27 | 28 | import org.junit.Test; |
28 | 29 |
|
29 | 30 | import org.apache.cassandra.ServerTestUtils; |
30 | 31 | import org.apache.cassandra.Util; |
| 32 | +import org.apache.cassandra.config.CassandraRelevantProperties; |
31 | 33 | import org.apache.cassandra.config.DatabaseDescriptor; |
32 | 34 | import org.apache.cassandra.db.commitlog.CommitLog; |
33 | 35 | import org.apache.cassandra.dht.RandomPartitioner; |
|
37 | 39 | import org.apache.cassandra.tcm.ClusterMetadata; |
38 | 40 |
|
39 | 41 | import static org.apache.cassandra.config.CassandraRelevantProperties.MAX_LOCAL_PAUSE_IN_MS; |
| 42 | +import static org.junit.Assert.assertEquals; |
40 | 43 | import static org.junit.Assert.assertFalse; |
41 | 44 |
|
42 | 45 | public class FailureDetectorTest |
@@ -79,4 +82,36 @@ public void testConvictAfterLeft() throws UnknownHostException |
79 | 82 | FailureDetector.instance.interpret(leftHost); |
80 | 83 | assertFalse("Left endpoint not convicted", FailureDetector.instance.isAlive(leftHost)); |
81 | 84 | } |
| 85 | + |
| 86 | + @Test |
| 87 | + public void testMaxIntervalCalculation() |
| 88 | + { |
| 89 | + // Default value for ArrivalWindow.MAX_INTERVAL_IN_NANO, which is supplied by |
| 90 | + // ArrivalWindow::getMaxInterval should be 2000000000ns/2 seconds. |
| 91 | + Long initialPropertyValue = CassandraRelevantProperties.FD_MAX_INTERVAL_MS.isPresent() |
| 92 | + ? CassandraRelevantProperties.FD_MAX_INTERVAL_MS.getLong() |
| 93 | + : null; |
| 94 | + try |
| 95 | + { |
| 96 | + // verify that max interval isn't being set directly using system property |
| 97 | + CassandraRelevantProperties.FD_MAX_INTERVAL_MS.reset(); |
| 98 | + assertFalse(CassandraRelevantProperties.FD_MAX_INTERVAL_MS.isPresent()); |
| 99 | + // in which case, max interval should default to INITIAL_VALUE_NANOS |
| 100 | + assertEquals(FailureDetector.INITIAL_VALUE_NANOS, FailureDetector.calculateMaxInterval()); |
| 101 | + |
| 102 | + // max interval can be overridden, but it's value should be supplied in millis |
| 103 | + long overrideMillis = TimeUnit.NANOSECONDS.toMillis(FailureDetector.INITIAL_VALUE_NANOS * 2); |
| 104 | + CassandraRelevantProperties.FD_MAX_INTERVAL_MS.setLong(overrideMillis); |
| 105 | + // max interval is a nanos value, so convert the override to get the expected value |
| 106 | + long expectedNanos = TimeUnit.NANOSECONDS.convert(overrideMillis, TimeUnit.MILLISECONDS); |
| 107 | + assertEquals(expectedNanos, FailureDetector.calculateMaxInterval()); |
| 108 | + } |
| 109 | + finally |
| 110 | + { |
| 111 | + if (initialPropertyValue == null) |
| 112 | + CassandraRelevantProperties.FD_MAX_INTERVAL_MS.reset(); |
| 113 | + else |
| 114 | + CassandraRelevantProperties.FD_MAX_INTERVAL_MS.setLong(initialPropertyValue); |
| 115 | + } |
| 116 | + } |
82 | 117 | } |
0 commit comments