SzyWilliam commented on code in PR #14866:
URL: https://github.com/apache/iotdb/pull/14866#discussion_r1974612210


##########
iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/manager/load/cache/detector/DetectorTest.java:
##########
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.confignode.manager.load.cache.detector;
+
+import org.apache.iotdb.commons.cluster.NodeStatus;
+import org.apache.iotdb.confignode.manager.load.cache.AbstractHeartbeatSample;
+import org.apache.iotdb.confignode.manager.load.cache.node.NodeHeartbeatSample;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+public class DetectorTest {
+
+  final long sec = 1_000_000_000L;
+  final FixedDetector fixedDetector = new FixedDetector(20 * sec);
+  final PhiAccrualDetector phiAccrualDetector =
+      new PhiAccrualDetector(30, 10 * sec, (long) (0.2 * sec), 0, 
fixedDetector);
+
+  private double getPhi(long elapsed, double[] intervals, long minStd, long 
pause) {
+    final PhiAccrualDetector.PhiAccrual p =
+        new PhiAccrualDetector.PhiAccrual(intervals, elapsed, minStd, pause);
+    return p.phi();
+  }
+
+  private void assertInRange(double value, double start, double end) {
+    Assert.assertTrue(value > start);
+    Assert.assertTrue(value < end);
+  }
+
+  @Test
+  public void testFixedDetector() {
+    final long lastHeartbeatTs = System.nanoTime() - 21 * sec;
+    final List<AbstractHeartbeatSample> history =
+        Collections.singletonList(new NodeHeartbeatSample(lastHeartbeatTs, 
NodeStatus.Running));
+    Assert.assertFalse(fixedDetector.isAvailable(history));
+  }
+
+  @Test
+  public void testPhiCalculation1() {
+    /* (min, std, acceptable_pause) = (1000, 200, 0) */
+    final double[] heartbeatIntervals = {1000, 1000, 1000, 1000, 1000};
+    final long minStd = 200;
+    final long pause = 0;
+
+    assertInRange(getPhi(1000, heartbeatIntervals, minStd, pause), 0, 1);
+    assertInRange(getPhi(2000, heartbeatIntervals, minStd, pause), 5, 10);
+    assertInRange(getPhi(3000, heartbeatIntervals, minStd, pause), 35, 50);
+  }
+
+  @Test
+  public void testPhiCalculation2() {
+    /* (min, std, acceptable_pause) = (1000, 300, 0) */
+    final double[] heartbeatIntervals = {1000, 1000, 1000, 1000, 1000};
+    final long minStd = 300;
+    final long pause = 0;
+
+    assertInRange(getPhi(1000, heartbeatIntervals, minStd, pause), 0, 1);
+    assertInRange(getPhi(2000, heartbeatIntervals, minStd, pause), 1, 5);
+    assertInRange(getPhi(3000, heartbeatIntervals, minStd, pause), 10, 15);
+  }
+
+  @Test
+  public void testPhiCalculation3() {
+    /* (min, std, acceptable_pause) = (1000, 200, 3000) */
+    final double[] heartbeatIntervals = {1000, 1000, 1000, 1000, 1000};
+    final long minStd = 200;
+    final long pause = 3000;
+
+    assertInRange(getPhi(1000 + pause, heartbeatIntervals, minStd, pause), 0, 
1);
+    assertInRange(getPhi(2000 + pause, heartbeatIntervals, minStd, pause), 5, 
10);
+    assertInRange(getPhi(3000 + pause, heartbeatIntervals, minStd, pause), 35, 
50);
+  }
+
+  @Test
+  public void testComparisonQuickFailureDetection() {
+    // When a node hasn't responded with interval longer than accepted GC pause

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to