|
@@ -19,7 +19,13 @@
|
|
|
package org.apache.hadoop.hdds.scm;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
+import org.apache.hadoop.hdds.HddsConfigKeys;
|
|
|
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
|
|
|
+import org.apache.hadoop.hdds.server.ServerUtils;
|
|
|
+import org.apache.hadoop.test.PathUtils;
|
|
|
+
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+import static org.junit.Assert.assertTrue;
|
|
|
import org.junit.Rule;
|
|
|
import org.junit.Test;
|
|
|
import org.junit.rules.ExpectedException;
|
|
@@ -27,12 +33,15 @@ import org.junit.rules.Timeout;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.net.InetSocketAddress;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_CLIENT_ADDRESS_KEY;
|
|
|
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_DATANODE_ADDRESS_KEY;
|
|
|
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_DATANODE_PORT_DEFAULT;
|
|
|
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_NAMES;
|
|
|
+import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_STALENODE_INTERVAL;
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
|
/**
|
|
@@ -154,4 +163,67 @@ public class TestHddsServerUtils {
|
|
|
HddsServerUtil.getScmAddressForDataNodes(conf);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Test {@link ServerUtils#getScmDbDir}.
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testGetScmDbDir() {
|
|
|
+ final File testDir = PathUtils.getTestDir(TestHddsServerUtils.class);
|
|
|
+ final File dbDir = new File(testDir, "scmDbDir");
|
|
|
+ final File metaDir = new File(testDir, "metaDir"); // should be ignored.
|
|
|
+ final Configuration conf = new OzoneConfiguration();
|
|
|
+ conf.set(ScmConfigKeys.OZONE_SCM_DB_DIRS, dbDir.getPath());
|
|
|
+ conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, metaDir.getPath());
|
|
|
+
|
|
|
+ try {
|
|
|
+ assertEquals(dbDir, ServerUtils.getScmDbDir(conf));
|
|
|
+ assertTrue(dbDir.exists()); // should have been created.
|
|
|
+ } finally {
|
|
|
+ FileUtils.deleteQuietly(dbDir);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Test {@link ServerUtils#getScmDbDir} with fallback to OZONE_METADATA_DIRS
|
|
|
+ * when OZONE_SCM_DB_DIRS is undefined.
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testGetScmDbDirWithFallback() {
|
|
|
+ final File testDir = PathUtils.getTestDir(TestHddsServerUtils.class);
|
|
|
+ final File metaDir = new File(testDir, "metaDir");
|
|
|
+ final Configuration conf = new OzoneConfiguration();
|
|
|
+ conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, metaDir.getPath());
|
|
|
+ try {
|
|
|
+ assertEquals(metaDir, ServerUtils.getScmDbDir(conf));
|
|
|
+ assertTrue(metaDir.exists()); // should have been created.
|
|
|
+ } finally {
|
|
|
+ FileUtils.deleteQuietly(metaDir);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testNoScmDbDirConfigured() {
|
|
|
+ thrown.expect(IllegalArgumentException.class);
|
|
|
+ ServerUtils.getScmDbDir(new OzoneConfiguration());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testGetStaleNodeInterval() {
|
|
|
+ final Configuration conf = new OzoneConfiguration();
|
|
|
+
|
|
|
+ // Reset OZONE_SCM_STALENODE_INTERVAL to 300s that
|
|
|
+ // larger than max limit value.
|
|
|
+ conf.setTimeDuration(OZONE_SCM_STALENODE_INTERVAL, 300, TimeUnit.SECONDS);
|
|
|
+ conf.setInt(ScmConfigKeys.OZONE_SCM_HEARTBEAT_PROCESS_INTERVAL, 100);
|
|
|
+ // the max limit value will be returned
|
|
|
+ assertEquals(100000, HddsServerUtil.getStaleNodeInterval(conf));
|
|
|
+
|
|
|
+ // Reset OZONE_SCM_STALENODE_INTERVAL to 10ms that
|
|
|
+ // smaller than min limit value.
|
|
|
+ conf.setTimeDuration(OZONE_SCM_STALENODE_INTERVAL, 10,
|
|
|
+ TimeUnit.MILLISECONDS);
|
|
|
+ conf.setInt(ScmConfigKeys.OZONE_SCM_HEARTBEAT_PROCESS_INTERVAL, 100);
|
|
|
+ // the min limit value will be returned
|
|
|
+ assertEquals(90000, HddsServerUtil.getStaleNodeInterval(conf));
|
|
|
+ }
|
|
|
}
|