sodonnel commented on a change in pull request #2973:
URL: https://github.com/apache/ozone/pull/2973#discussion_r782064171



##########
File path: 
hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/scm/container/common/helpers/TestExcludeList.java
##########
@@ -0,0 +1,68 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.hdds.scm.container.common.helpers;
+
+import org.apache.hadoop.hdds.protocol.DatanodeDetails;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.UUID;
+
+/**
+ * Tests the exclude nodes list behavior at client.
+ */
+public class TestExcludeList {
+
+  @Test
+  public void autoCleanerShouldCleanTheNodesWhichArePresentForLong()
+      throws InterruptedException {
+    ExcludeList list = new ExcludeList();
+    list.startAutoExcludeNodesCleaner(10, 5);
+    list.addDatanode(DatanodeDetails.newBuilder().setUuid(UUID.randomUUID())
+        .setIpAddress("127.0.0.1").setHostName("localhost").addPort(
+            DatanodeDetails.newPort(DatanodeDetails.Port.Name.STANDALONE, 
2001))
+        .build());
+    Assert.assertTrue(list.getDatanodes().size() == 1);
+    Thread.sleep(20);

Review comment:
       In general, we should try to avoid `sleep()` in tests, as it slows them 
down and can make them flaky. 
   
   Anytime we need to test a class that makes decisions based on the passage of 
time, we should consider "time" as a dependency that can be injected into the 
class and therefore can be mocked.
   
   In ReplicationManager, I modified it some time back to use the 
`java.time.Clock` interface. On construction, we pass an instance of 
`MonotonicClock` to it. Then anytime ReplicationManager needs to get the system 
time, it asks this clock for it. In general, its just a small indirection to 
getting the system time.
   
   In tests, we construct replicationManager with an instance of `TestClock`, 
which allows use to manipulate its view of time without any `sleep()` calls. 
The test clock can be set to an instant, and then advanceded or rewound by a 
number of ms making it perfect for this use case.




-- 
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]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to