You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2020/03/23 13:40:25 UTC

[GitHub] [hadoop-ozone] fapifta commented on a change in pull request #619: HDDS-3111. Add unit test for container replication behavior under dif…

fapifta commented on a change in pull request #619: HDDS-3111. Add unit test for container replication behavior under dif…
URL: https://github.com/apache/hadoop-ozone/pull/619#discussion_r396457495
 
 

 ##########
 File path: hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/TestContainerReplicationUnderPlacementPolicy.java
 ##########
 @@ -0,0 +1,178 @@
+/**
+ * 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;
+
+import static org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanodeDetails;
+import static org.apache.hadoop.hdds.scm.TestUtils.getContainer;
+import static org.apache.hadoop.hdds.scm.TestUtils.getReplicas;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.protocol.DatanodeDetails;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState;
+import org.apache.hadoop.hdds.protocol.proto
+    .StorageContainerDatanodeProtocolProtos.ContainerReplicaProto.State;
+import org.apache.hadoop.hdds.protocol.proto
+    .StorageContainerDatanodeProtocolProtos.SCMCommandProto;
+import org.apache.hadoop.hdds.scm.PlacementPolicy;
+import org.apache.hadoop.hdds.scm.container.ReplicationManager.ReplicationManagerConfiguration;
+import org.apache.hadoop.hdds.scm.container.TestReplicationManager.DatanodeCommandHandler;
+import org.apache.hadoop.hdds.scm.container.placement.algorithms.SCMContainerPlacementRandom;
+import org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeMetric;
+import org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeStat;
+import org.apache.hadoop.hdds.scm.events.SCMEvents;
+import org.apache.hadoop.hdds.scm.node.NodeManager;
+import org.apache.hadoop.hdds.server.events.EventQueue;
+import org.apache.hadoop.ozone.lock.LockManager;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ * Test container replication behaviors under different container
+ * placement policy.
+ */
+public class TestContainerReplicationUnderPlacementPolicy {
+
+  private ReplicationManager replicationManager;
+  private ContainerStateManager containerStateManager;
+  private NodeManager nodeManager;
+  private PlacementPolicy containerPlacementPolicy;
+  private EventQueue eventQueue;
+  private DatanodeCommandHandler datanodeCommandHandler;
+  private Configuration conf;
+  private ContainerManager containerManager;
+
+  @Test
+  public void testReplicationWithPlacementRandomPolicy()
+      throws Exception {
+    // In the test, we create 1 replica container and there still
+    // needs at least two nodes to do remaining replica replication.
+
+    // case1: provide only 1 healthy candidate node, it should
+    // be failed to do replication.
+    verifyReplicateCommandCount(1, 0, null);
+
+    // case2: provide 2 healthy candidate node but one is chosen node
+    // that already be used, it should be also failed since chosen node
+    // will be excluded.
+    List<DatanodeDetails> chosenNodes = new ArrayList<>();
+    chosenNodes.add(randomDatanodeDetails());
+    verifyReplicateCommandCount(2, 0, chosenNodes);
+
+    // case3: provide other 2 healthy candidate node, it should
+    // be succeed to do replication.
+    verifyReplicateCommandCount(2, 2, null);
 
 Review comment:
   Note: this comment is a style related comment, for which I have a few arguments.
   
   As we have case1 and case2 and case3 already as the comments suggest, why we do not have this as 3 separated test cases?
   pros:
   - the different cases can be named separately, which may give a better clue for someone who looks at this test when it starts to fail
   - the different cases can fail separately, and in case case1 and case 3 fails, but case2 does not (theoretical state), then the one who checks into the tests, based on better names and the failures potentially can understand the problem easier
   - setup and teardown related things can be refactored from the test easily by seeing the duplication into @Before and @After methods
   - separation of test setup and execution steps into methods makes the code more easy to understand as I view (though this is an objective argument :) )
   cons:
   - you name it :) (sorry)
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: ozone-issues-help@hadoop.apache.org