timmylicheng commented on a change in pull request #1019:
URL: https://github.com/apache/hadoop-ozone/pull/1019#discussion_r436437701



##########
File path: 
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/pipeline/TestPipelineManagerImpl.java
##########
@@ -0,0 +1,466 @@
+/**
+ * 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.hadoop.hdds.scm.pipeline;
+
+import com.google.common.base.Supplier;
+import org.apache.hadoop.fs.FileUtil;
+import org.apache.hadoop.hdds.HddsConfigKeys;
+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.scm.TestUtils;
+import org.apache.hadoop.hdds.scm.container.ContainerID;
+import org.apache.hadoop.hdds.scm.container.MockNodeManager;
+import org.apache.hadoop.hdds.scm.container.TestContainerManagerImpl;
+import org.apache.hadoop.hdds.scm.exceptions.SCMException;
+import org.apache.hadoop.hdds.scm.ha.MockSCMHAManager;
+import org.apache.hadoop.hdds.scm.metadata.SCMDBDefinition;
+import org.apache.hadoop.hdds.scm.safemode.SCMSafeModeManager;
+import org.apache.hadoop.hdds.scm.server.SCMDatanodeHeartbeatDispatcher;
+import org.apache.hadoop.hdds.server.events.EventQueue;
+import org.apache.hadoop.hdds.utils.db.DBStore;
+import org.apache.hadoop.hdds.utils.db.DBStoreBuilder;
+import org.apache.hadoop.metrics2.MetricsRecordBuilder;
+import org.apache.hadoop.ozone.container.common.SCMTestUtils;
+import org.apache.hadoop.test.GenericTestUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+
+import static 
org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_DATANODE_PIPELINE_LIMIT;
+import static 
org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_DATANODE_PIPELINE_LIMIT_DEFAULT;
+import static 
org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_PIPELINE_ALLOCATED_TIMEOUT;
+import static 
org.apache.hadoop.hdds.scm.pipeline.Pipeline.PipelineState.ALLOCATED;
+import static org.apache.hadoop.test.MetricsAsserts.getLongCounter;
+import static org.apache.hadoop.test.MetricsAsserts.getMetrics;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests for PipelineManagerImpl.
+ */
+public class TestPipelineManagerImpl {
+  private static OzoneConfiguration conf;
+  private static File testDir;
+  private DBStore dbStore;
+  private static MockNodeManager nodeManager;
+  private static int maxPipelineCount;
+  private static EventQueue eventQueue;
+
+  @Before
+  public void init() throws Exception {
+    conf = SCMTestUtils.getConf();
+    testDir = GenericTestUtils.getTestDir(
+        TestContainerManagerImpl.class.getSimpleName() + UUID.randomUUID());
+    conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, testDir.getAbsolutePath());
+    dbStore = DBStoreBuilder.createDBStore(conf, new SCMDBDefinition());
+    nodeManager = new MockNodeManager(true, 20);
+    eventQueue = new EventQueue();
+    maxPipelineCount = nodeManager.getNodeCount(HddsProtos.NodeState.HEALTHY) *
+        conf.getInt(OZONE_DATANODE_PIPELINE_LIMIT,
+            OZONE_DATANODE_PIPELINE_LIMIT_DEFAULT) /
+        HddsProtos.ReplicationFactor.THREE.getNumber();
+  }
+
+  @After
+  public void cleanup() throws Exception {
+    if (dbStore != null) {
+      dbStore.close();
+    }
+    FileUtil.fullyDelete(testDir);
+  }
+
+  private PipelineManagerV2Impl createPipelineManager()
+      throws IOException {
+    return PipelineManagerV2Impl.newPipelineManager(
+        conf, MockSCMHAManager.getInstance(),
+        nodeManager,
+        SCMDBDefinition.PIPELINES.getTable(dbStore), eventQueue);
+  }
+
+  @Test
+  public void testCreatePipeline() throws Exception {
+    List<Pipeline> pipelines = new ArrayList<>();
+    PipelineManagerV2Impl pipelineManager = createPipelineManager();
+    Assert.assertTrue(pipelineManager.getPipelines().isEmpty());
+    pipelineManager.allowPipelineCreation();
+    Pipeline pipeline1 = pipelineManager.createPipeline(
+        HddsProtos.ReplicationType.RATIS, HddsProtos.ReplicationFactor.THREE);
+    Assert.assertEquals(1, pipelineManager.getPipelines().size());
+    Assert.assertTrue(pipelineManager.containsPipeline(pipeline1.getId()));
+    pipelines.add(pipeline1);
+
+    Pipeline pipeline2 = pipelineManager.createPipeline(
+        HddsProtos.ReplicationType.RATIS, HddsProtos.ReplicationFactor.ONE);
+    Assert.assertEquals(2, pipelineManager.getPipelines().size());
+    Assert.assertTrue(pipelineManager.containsPipeline(pipeline2.getId()));
+    pipelines.add(pipeline2);
+    pipelineManager.close();
+
+    PipelineManagerV2Impl pipelineManager2 = createPipelineManager();
+    // Should be able to load previous pipelines.
+    Assert.assertFalse(pipelineManager.getPipelines().isEmpty());
+    Assert.assertEquals(2, pipelineManager.getPipelines().size());
+    pipelineManager.allowPipelineCreation();
+    Pipeline pipeline3 = pipelineManager.createPipeline(
+        HddsProtos.ReplicationType.RATIS, HddsProtos.ReplicationFactor.THREE);
+    Assert.assertEquals(3, pipelineManager.getPipelines().size());
+    Assert.assertTrue(pipelineManager.containsPipeline(pipeline3.getId()));
+    pipelines.add(pipeline3);
+
+    pipelineManager2.close();
+  }
+
+  @Test
+  public void testUpdatePipelineStates() throws Exception {
+    PipelineManagerV2Impl pipelineManager = createPipelineManager();
+    pipelineManager.allowPipelineCreation();
+    Pipeline pipeline = pipelineManager.createPipeline(
+        HddsProtos.ReplicationType.RATIS, HddsProtos.ReplicationFactor.THREE);
+    Assert.assertEquals(1, pipelineManager.getPipelines().size());
+    Assert.assertTrue(pipelineManager.containsPipeline(pipeline.getId()));
+    Assert.assertTrue(pipeline.getPipelineState() == ALLOCATED);

Review comment:
       These are copied from original TestSCMPipelineManager tests. I will 
update them.




----------------------------------------------------------------
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:
[email protected]



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

Reply via email to