|
23 | 23 | import java.util.Collections; |
24 | 24 | import java.util.List; |
25 | 25 | import java.util.UUID; |
| 26 | +import java.util.concurrent.TimeUnit; |
26 | 27 |
|
27 | 28 | import org.junit.BeforeClass; |
28 | 29 | import org.junit.Test; |
29 | 30 |
|
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.IPartitioner; |
|
38 | 40 | import org.apache.cassandra.service.StorageService; |
39 | 41 |
|
40 | 42 | import static org.apache.cassandra.config.CassandraRelevantProperties.MAX_LOCAL_PAUSE_IN_MS; |
| 43 | +import static org.junit.Assert.assertEquals; |
41 | 44 | import static org.junit.Assert.assertFalse; |
42 | 45 |
|
43 | 46 | public class FailureDetectorTest |
@@ -87,4 +90,36 @@ public void testConvictAfterLeft() throws UnknownHostException |
87 | 90 | FailureDetector.instance.interpret(leftHost); |
88 | 91 | assertFalse("Left endpoint not convicted", FailureDetector.instance.isAlive(leftHost)); |
89 | 92 | } |
| 93 | + |
| 94 | + @Test |
| 95 | + public void testMaxIntervalCalculation() |
| 96 | + { |
| 97 | + // Default value for ArrivalWindow.MAX_INTERVAL_IN_NANO, which is supplied by |
| 98 | + // ArrivalWindow::getMaxInterval should be 2000000000ns/2 seconds. |
| 99 | + Long initialPropertyValue = CassandraRelevantProperties.FD_MAX_INTERVAL_MS.isPresent() |
| 100 | + ? CassandraRelevantProperties.FD_MAX_INTERVAL_MS.getLong() |
| 101 | + : null; |
| 102 | + try |
| 103 | + { |
| 104 | + // verify that max interval isn't being set directly using system property |
| 105 | + CassandraRelevantProperties.FD_MAX_INTERVAL_MS.reset(); |
| 106 | + assertFalse(CassandraRelevantProperties.FD_MAX_INTERVAL_MS.isPresent()); |
| 107 | + // in which case, max interval should default to INITIAL_VALUE_NANOS |
| 108 | + assertEquals(FailureDetector.INITIAL_VALUE_NANOS, FailureDetector.calculateMaxInterval()); |
| 109 | + |
| 110 | + // max interval can be overridden, but it's value should be supplied in millis |
| 111 | + long overrideMillis = TimeUnit.NANOSECONDS.toMillis(FailureDetector.INITIAL_VALUE_NANOS * 2); |
| 112 | + CassandraRelevantProperties.FD_MAX_INTERVAL_MS.setLong(overrideMillis); |
| 113 | + // max interval is a nanos value, so convert the override to get the expected value |
| 114 | + long expectedNanos = TimeUnit.NANOSECONDS.convert(overrideMillis, TimeUnit.MILLISECONDS); |
| 115 | + assertEquals(expectedNanos, FailureDetector.calculateMaxInterval()); |
| 116 | + } |
| 117 | + finally |
| 118 | + { |
| 119 | + if (initialPropertyValue == null) |
| 120 | + CassandraRelevantProperties.FD_MAX_INTERVAL_MS.reset(); |
| 121 | + else |
| 122 | + CassandraRelevantProperties.FD_MAX_INTERVAL_MS.setLong(initialPropertyValue); |
| 123 | + } |
| 124 | + } |
90 | 125 | } |
0 commit comments