ChenSammi commented on code in PR #4358:
URL: https://github.com/apache/ozone/pull/4358#discussion_r1138224396


##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/ha/SCMHAManagerImplTest.java:
##########
@@ -0,0 +1,196 @@
+/*
+ * 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.ha;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.hadoop.hdds.HddsConfigKeys;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.scm.AddSCMRequest;
+import org.apache.hadoop.hdds.scm.RemoveSCMRequest;
+import org.apache.hadoop.hdds.scm.ScmConfigKeys;
+import org.apache.hadoop.hdds.scm.block.BlockManager;
+import org.apache.hadoop.hdds.scm.block.DeletedBlockLog;
+import org.apache.hadoop.hdds.scm.block.DeletedBlockLogImpl;
+import org.apache.hadoop.hdds.scm.metadata.SCMMetadataStore;
+import org.apache.hadoop.hdds.scm.node.NodeDecommissionManager;
+import org.apache.hadoop.hdds.scm.safemode.SCMSafeModeManager;
+import org.apache.hadoop.hdds.scm.server.SCMDatanodeProtocolServer;
+import org.apache.hadoop.hdds.scm.server.StorageContainerManager;
+import org.apache.hadoop.hdds.scm.server.upgrade.FinalizationManager;
+import org.apache.hadoop.hdds.security.x509.certificate.client
+    .CertificateClient;
+import org.apache.hadoop.hdds.utils.TransactionInfo;
+import org.apache.hadoop.hdds.utils.db.BatchOperation;
+import org.apache.hadoop.hdds.utils.db.DBStore;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.ozone.test.GenericTestUtils;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.UUID;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+
+/**
+ * Test cases to verify {@link org.apache.hadoop.hdds.scm.ha.SCMHAManagerImpl}.
+ */
+class SCMHAManagerImplTest {
+
+  private String storageBaseDir;
+  private String clusterID;
+  private SCMHAManager primarySCMHAManager;
+
+  @BeforeEach
+  public void setup() throws IOException, InterruptedException {
+    storageBaseDir = GenericTestUtils.getTempPath(
+        SCMHAManagerImplTest.class.getSimpleName() + "-" +
+            UUID.randomUUID());
+    clusterID = UUID.randomUUID().toString();
+    OzoneConfiguration conf = getConfig("scm1", 9894);
+    final StorageContainerManager scm = getMockStorageContainerManager(conf);
+    SCMRatisServerImpl.initialize(clusterID, scm.getScmId(),
+        scm.getScmNodeDetails(), conf);
+    scm.getScmHAManager().start();
+    primarySCMHAManager = scm.getScmHAManager();
+    // Wait for Ratis Server to be ready
+    Thread.sleep(5000);
+  }
+
+  private OzoneConfiguration getConfig(String scmId, int ratisPort) {
+    OzoneConfiguration conf = new OzoneConfiguration();
+    conf.set(ScmConfigKeys.OZONE_SCM_HA_RATIS_STORAGE_DIR, storageBaseDir
+        + File.separator + scmId + File.separator + "ratis");
+    conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, storageBaseDir
+        + File.separator + scmId + File.separator + "metadata");
+    conf.set(ScmConfigKeys.OZONE_SCM_RATIS_PORT_KEY, 
String.valueOf(ratisPort));
+    return conf;
+  }
+
+  @AfterEach
+  public void cleanup() throws IOException {
+    primarySCMHAManager.stop();
+    FileUtils.deleteDirectory(new File(storageBaseDir));
+  }
+
+  @Test
+  public void testAddSCM() throws IOException, InterruptedException {
+    Assertions.assertEquals(1, primarySCMHAManager.getRatisServer()
+        .getDivision().getGroup().getPeers().size());
+
+    final StorageContainerManager scm2 = getMockStorageContainerManager(
+        getConfig("scm2", 9898));
+    scm2.getScmHAManager().getRatisServer().start();
+    // Wait for Ratis Server to be ready
+    Thread.sleep(5000);
+    final AddSCMRequest request = new AddSCMRequest(
+        clusterID, scm2.getScmId(),
+        "localhost:" + scm2.getScmHAManager().getRatisServer().getDivision()
+            .getRaftServer().getServerRpc().getInetSocketAddress().getPort());
+    primarySCMHAManager.addSCM(request);
+    Assertions.assertEquals(2, primarySCMHAManager.getRatisServer()
+        .getDivision().getGroup().getPeers().size());
+    scm2.getScmHAManager().getRatisServer().stop();

Review Comment:
   Please use try to capture the possible exception from addSCM, and close the 
ratis server in this 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