Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package org.apache.hadoop.ozone.om;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -33,7 +33,6 @@
import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.RandomUtils;
import org.apache.hadoop.hdds.HddsConfigKeys;
import org.apache.hadoop.hdds.client.BlockID;
Expand Down Expand Up @@ -69,7 +68,6 @@
import org.apache.hadoop.ozone.om.helpers.OzoneFileStatus;
import org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol;
import org.apache.hadoop.ozone.om.request.OMRequestTestUtils;
import org.apache.ozone.test.GenericTestUtils;

import org.apache.hadoop.util.Time;
import org.apache.ozone.test.OzoneTestBase;
Expand All @@ -78,6 +76,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
Expand Down Expand Up @@ -112,20 +111,16 @@ class TestKeyManagerUnit extends OzoneTestBase {
private KeyManagerImpl keyManager;

private Instant startDate;
private File testDir;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep and annotate it, instead of adding parameter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not used anywhere else hence added as a parameter instead of keeping as instance variable. It is also removed from the method cleanup.

private ScmBlockLocationProtocol blockClient;

private OzoneManagerProtocol writeClient;
private OzoneManager om;

@BeforeAll
void setup() throws Exception {
void setup(@TempDir Path testDir) throws Exception {
ExitUtils.disableSystemExit();

configuration = new OzoneConfiguration();
testDir = GenericTestUtils.getRandomizedTestDir();
configuration.set(HddsConfigKeys.OZONE_METADATA_DIRS,
testDir.toString());
configuration.set(HddsConfigKeys.OZONE_METADATA_DIRS, testDir.toString());
containerClient = mock(StorageContainerLocationProtocol.class);
blockClient = mock(ScmBlockLocationProtocol.class);

Expand All @@ -146,7 +141,6 @@ void init() {
@AfterAll
public void cleanup() throws Exception {
om.stop();
FileUtils.deleteDirectory(testDir);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.net.InetSocketAddress;
import java.net.URL;
import java.net.URLConnection;
import java.util.Arrays;
import java.util.Collection;

import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.server.http.BaseHttpServer;
import org.apache.hadoop.hdfs.web.URLConnectionFactory;
Expand All @@ -36,20 +36,18 @@
import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.ozone.OzoneConfigKeys;
import org.apache.hadoop.security.ssl.KeyStoreTestUtil;
import org.apache.ozone.test.GenericTestUtils;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

/**
* Test http server of OM with various HTTP option.
*/
public class TestOzoneManagerHttpServer {
private static final String BASEDIR = GenericTestUtils
.getTempPath(TestOzoneManagerHttpServer.class.getSimpleName());
private static String keystoresDir;
private static String sslConfDir;
private static OzoneConfiguration conf;
Expand All @@ -63,17 +61,15 @@ public static Collection<Object[]> policy() {
return Arrays.asList(params);
}

@BeforeAll public static void setUp() throws Exception {
File base = new File(BASEDIR);
FileUtil.fullyDelete(base);
@BeforeAll public static void setUp(@TempDir File baseDir) throws Exception {

// Create metadata directory
ozoneMetadataDirectory = new File(BASEDIR, "metadata");
ozoneMetadataDirectory = new File(baseDir.getPath(), "metadata");
ozoneMetadataDirectory.mkdirs();

// Initialize the OzoneConfiguration
conf = new OzoneConfiguration();
keystoresDir = new File(BASEDIR).getAbsolutePath();
keystoresDir = baseDir.getAbsolutePath();
sslConfDir = KeyStoreTestUtil.getClasspathDir(
TestOzoneManagerHttpServer.class);
KeyStoreTestUtil.setupSSLConfig(keystoresDir, sslConfDir, conf, false);
Expand All @@ -95,7 +91,6 @@ public static Collection<Object[]> policy() {

@AfterAll public static void tearDown() throws Exception {
connectionFactory.destroy();
FileUtil.fullyDelete(new File(BASEDIR));
KeyStoreTestUtil.cleanupSSLConfig(keystoresDir, sslConfDir);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -91,11 +90,9 @@ public static void setup() {
}

@BeforeEach
public void init() throws Exception {
public void init(@TempDir Path metaDirPath) throws Exception {
conf = new OzoneConfiguration();
omID = UUID.randomUUID().toString();
final String path = GenericTestUtils.getTempPath(omID);
Path metaDirPath = Paths.get(path, "om-meta");
conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, metaDirPath.toString());
conf.setTimeDuration(OMConfigKeys.OZONE_OM_RATIS_MINIMUM_TIMEOUT_KEY,
RATIS_RPC_TIMEOUT, TimeUnit.MILLISECONDS);
Expand Down Expand Up @@ -215,13 +212,11 @@ public void verifyRaftGroupIdGenerationWithDefaultOmServiceId() throws
}

@Test
public void verifyRaftGroupIdGenerationWithCustomOmServiceId() throws
public void verifyRaftGroupIdGenerationWithCustomOmServiceId(@TempDir Path metaDirPath) throws
Exception {
String customOmServiceId = "omSIdCustom123";
OzoneConfiguration newConf = new OzoneConfiguration();
String newOmId = UUID.randomUUID().toString();
String path = GenericTestUtils.getTempPath(newOmId);
Path metaDirPath = Paths.get(path, "om-meta");
newConf.set(HddsConfigKeys.OZONE_METADATA_DIRS, metaDirPath.toString());
newConf.setTimeDuration(OMConfigKeys.OZONE_OM_RATIS_MINIMUM_TIMEOUT_KEY,
RATIS_RPC_TIMEOUT, TimeUnit.MILLISECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
import org.apache.hadoop.ozone.om.helpers.SnapshotDiffJob;
import org.apache.hadoop.ozone.snapshot.SnapshotDiffReportOzone;
import org.apache.hadoop.ozone.snapshot.SnapshotDiffResponse.JobStatus;
import org.apache.ozone.test.GenericTestUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.rocksdb.ColumnFamilyDescriptor;
Expand All @@ -44,6 +44,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.ArrayList;
Expand Down Expand Up @@ -72,7 +73,8 @@
* Tests SnapshotDiffCleanupService.
*/
public class TestSnapshotDiffCleanupService {
private static File file;
@TempDir
private static Path tempDir;
private static ManagedRocksDB db;
private static ManagedDBOptions dbOptions;
private static ManagedColumnFamilyOptions columnFamilyOptions;
Expand Down Expand Up @@ -102,7 +104,7 @@ public static void staticInit() throws RocksDBException {
dbOptions.setCreateIfMissing(true);
columnFamilyOptions = new ManagedColumnFamilyOptions();

file = new File("./test-snap-diff-clean-up");
File file = tempDir.resolve("./test-snap-diff-clean-up").toFile();
if (!file.mkdirs() && !file.exists()) {
throw new IllegalArgumentException("Unable to create directory " +
file);
Expand Down Expand Up @@ -133,8 +135,6 @@ public static void staticTearDown() {
if (db != null) {
db.close();
}

GenericTestUtils.deleteDirectory(file);
}

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
import org.apache.hadoop.ozone.om.service.SnapshotDeletingService;
import org.apache.ozone.test.GenericTestUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -82,7 +81,6 @@ public void testLinkFiles(@TempDir File tempDir) throws Exception {
map(Path::toString).collect(Collectors.toSet());

assertEquals(tree1Files, tree2Files);
GenericTestUtils.deleteDirectory(tempDir);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -29,10 +30,10 @@
import org.apache.hadoop.hdds.utils.db.managed.ManagedDBOptions;
import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksDB;
import org.apache.hadoop.util.ClosableIterator;
import org.apache.ozone.test.GenericTestUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.rocksdb.ColumnFamilyDescriptor;
import org.rocksdb.ColumnFamilyHandle;
import org.rocksdb.RocksDBException;
Expand All @@ -44,7 +45,8 @@
* Test persistent list backed by RocksDB.
*/
public class TestRocksDbPersistentList {
private static File file;
@TempDir
private static Path tempDir;
private static ManagedRocksDB db;
private static ManagedDBOptions dbOptions;
private static ManagedColumnFamilyOptions columnFamilyOptions;
Expand All @@ -55,7 +57,7 @@ public static void staticInit() throws RocksDBException {
dbOptions.setCreateIfMissing(true);
columnFamilyOptions = new ManagedColumnFamilyOptions();

file = new File("./test-persistent-list");
File file = tempDir.resolve("./test-persistent-list").toFile();
if (!file.mkdirs() && !file.exists()) {
throw new IllegalArgumentException("Unable to create directory " +
file);
Expand Down Expand Up @@ -86,8 +88,6 @@ public static void staticTearDown() {
if (db != null) {
db.close();
}

GenericTestUtils.deleteDirectory(file);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -38,10 +39,10 @@
import org.apache.hadoop.hdds.utils.db.managed.ManagedDBOptions;
import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksDB;
import org.apache.hadoop.util.ClosableIterator;
import org.apache.ozone.test.GenericTestUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand All @@ -56,7 +57,8 @@
* Test persistent map backed by RocksDB.
*/
public class TestRocksDbPersistentMap {
private static File file;
@TempDir
private static Path tempDir;
private static ManagedRocksDB db;
private static ManagedDBOptions dbOptions;
private static ManagedColumnFamilyOptions columnFamilyOptions;
Expand All @@ -69,7 +71,7 @@ public static void staticInit() throws RocksDBException {
dbOptions.setCreateIfMissing(true);
columnFamilyOptions = new ManagedColumnFamilyOptions();

file = new File("./test-persistent-map");
File file = tempDir.resolve("./test-persistent-map").toFile();
if (!file.mkdirs() && !file.exists()) {
throw new IllegalArgumentException("Unable to create directory " +
file);
Expand Down Expand Up @@ -101,8 +103,6 @@ public static void teardown() throws RocksDBException {
if (db != null) {
db.close();
}

GenericTestUtils.deleteDirectory(file);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -32,10 +33,10 @@
import org.apache.hadoop.hdds.utils.db.managed.ManagedDBOptions;
import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksDB;
import org.apache.hadoop.util.ClosableIterator;
import org.apache.ozone.test.GenericTestUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.rocksdb.ColumnFamilyDescriptor;
import org.rocksdb.ColumnFamilyHandle;
import org.rocksdb.RocksDBException;
Expand All @@ -48,7 +49,8 @@
* Test persistent set backed by RocksDB.
*/
public class TestRocksDbPersistentSet {
private static File file;
@TempDir
private static Path tempDir;
private static ManagedRocksDB db;
private static ManagedDBOptions dbOptions;
private static ManagedColumnFamilyOptions columnFamilyOptions;
Expand All @@ -59,7 +61,7 @@ public static void staticInit() throws RocksDBException {
dbOptions.setCreateIfMissing(true);
columnFamilyOptions = new ManagedColumnFamilyOptions();

file = new File("./test-persistent-set");
File file = tempDir.resolve("./test-persistent-set").toFile();
if (!file.mkdirs() && !file.exists()) {
throw new IllegalArgumentException("Unable to create directory " +
file);
Expand Down Expand Up @@ -91,8 +93,6 @@ public static void staticTearDown() {
if (db != null) {
db.close();
}

GenericTestUtils.deleteDirectory(file);
}

@Test
Expand Down
Loading