Skip to content

Commit

Permalink
HDDS-10243. Replace GenericTestUtils temp dir in SCMTestUtils (apache…
Browse files Browse the repository at this point in the history
  • Loading branch information
adoroszlai authored Feb 6, 2024
1 parent 5dd14ac commit 296d571
Show file tree
Hide file tree
Showing 23 changed files with 83 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.net.InetSocketAddress;
import java.net.ServerSocket;

import org.apache.commons.io.FileUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdds.HddsConfigKeys;
import org.apache.hadoop.hdds.conf.ConfigurationSource;
Expand All @@ -40,12 +39,9 @@
import org.apache.hadoop.ozone.protocol.StorageContainerDatanodeProtocol;
import org.apache.hadoop.ozone.protocolPB.StorageContainerDatanodeProtocolPB;
import org.apache.hadoop.ozone.protocolPB.StorageContainerDatanodeProtocolServerSideTranslatorPB;
import org.apache.ozone.test.GenericTestUtils;

import com.google.protobuf.BlockingService;

import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric;
import static org.apache.logging.log4j.util.StackLocatorUtil.getCallerClass;
import static org.mockito.Mockito.mock;

/**
Expand Down Expand Up @@ -125,15 +121,6 @@ public static InetSocketAddress getReuseableAddress() throws IOException {
}
}

public static OzoneConfiguration getConf() {
String name = getCallerClass(2).getSimpleName()
+ "-" + randomAlphanumeric(10);
File testDir = GenericTestUtils.getTestDir(name);
Runtime.getRuntime().addShutdownHook(new Thread(
() -> FileUtils.deleteQuietly(testDir)));
return getConf(testDir);
}

public static OzoneConfiguration getConf(File testDir) {
OzoneConfiguration conf = new OzoneConfiguration();
conf.set(ScmConfigKeys.HDDS_DATANODE_DIR_KEY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

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.scm.ScmConfigKeys;
Expand All @@ -55,7 +54,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.hadoop.hdds.scm.ScmConfigKeys.HDDS_DATANODE_DIR_KEY;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_HEARTBEAT_RPC_TIMEOUT;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand All @@ -80,8 +78,8 @@ public class TestDatanodeStateMachine {
private File testRoot;

@BeforeEach
public void setUp() throws Exception {
conf = SCMTestUtils.getConf();
void setUp() throws Exception {
conf = SCMTestUtils.getConf(testRoot);
conf.setTimeDuration(OZONE_SCM_HEARTBEAT_RPC_TIMEOUT, 500,
TimeUnit.MILLISECONDS);
conf.setBoolean(OzoneConfigKeys.DFS_CONTAINER_RATIS_IPC_RANDOM_PORT, true);
Expand All @@ -106,15 +104,6 @@ public void setUp() throws Exception {
conf.setStrings(ScmConfigKeys.OZONE_SCM_NAMES,
serverAddresses.toArray(new String[0]));

File dataDir = new File(testRoot, "data");
conf.set(HDDS_DATANODE_DIR_KEY, dataDir.getAbsolutePath());
if (!dataDir.mkdirs()) {
LOG.info("Data dir create failed.");
}
conf.set(HddsConfigKeys.OZONE_METADATA_DIRS,
new File(testRoot, "scm").getAbsolutePath());
String path = new File(testRoot, "datanodeID").getAbsolutePath();
conf.set(ScmConfigKeys.OZONE_SCM_DATANODE_ID_DIR, path);
executorService = HadoopExecutors.newCachedThreadPool(
new ThreadFactoryBuilder().setDaemon(true)
.setNameFormat("TestDataNodeStateMachineThread-%d").build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
import org.apache.ozone.test.GenericTestUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -72,9 +74,9 @@ public class TestSCMCommonPlacementPolicy {
private OzoneConfiguration conf;

@BeforeEach
public void setup() {
void setup(@TempDir File testDir) {
nodeManager = new MockNodeManager(true, 10);
conf = SCMTestUtils.getConf();
conf = SCMTestUtils.getConf(testDir);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

package org.apache.hadoop.hdds.scm.block;

import java.io.File;
import java.io.IOException;
import java.time.Clock;
import java.time.ZoneId;
import java.nio.file.Path;
import java.time.ZoneOffset;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -114,14 +114,13 @@ public class TestBlockManager {
private ReplicationConfig replicationConfig;

@BeforeEach
public void setUp(@TempDir Path tempDir) throws Exception {
conf = SCMTestUtils.getConf();
void setUp(@TempDir File tempDir) throws Exception {
conf = SCMTestUtils.getConf(tempDir);
numContainerPerOwnerInPipeline = conf.getInt(
ScmConfigKeys.OZONE_SCM_PIPELINE_OWNER_CONTAINER_COUNT,
ScmConfigKeys.OZONE_SCM_PIPELINE_OWNER_CONTAINER_COUNT_DEFAULT);


conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, tempDir.toString());
conf.setBoolean(HddsConfigKeys.HDDS_SCM_SAFEMODE_PIPELINE_CREATION, false);
conf.setTimeDuration(HddsConfigKeys.HDDS_PIPELINE_REPORT_INTERVAL, 5,
TimeUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.List;
import java.util.concurrent.TimeoutException;

import org.apache.hadoop.hdds.HddsConfigKeys;
import org.apache.hadoop.hdds.client.ECReplicationConfig;
import org.apache.hadoop.hdds.client.RatisReplicationConfig;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
Expand Down Expand Up @@ -74,9 +73,8 @@ public class TestContainerManagerImpl {
private ContainerReplicaPendingOps pendingOpsMock;

@BeforeEach
public void setUp() throws Exception {
final OzoneConfiguration conf = SCMTestUtils.getConf();
conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, testDir.getAbsolutePath());
void setUp() throws Exception {
final OzoneConfiguration conf = SCMTestUtils.getConf(testDir);
dbStore = DBStoreBuilder.createDBStore(
conf, new SCMDBDefinition());
scmhaManager = SCMHAManagerStub.getInstance(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.hadoop.hdds.scm.container;

import org.apache.hadoop.hdds.HddsConfigKeys;
import org.apache.hadoop.hdds.client.ECReplicationConfig;
import org.apache.hadoop.hdds.client.RatisReplicationConfig;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
Expand Down Expand Up @@ -94,12 +93,10 @@ public class TestContainerReportHandler {
private PipelineManager pipelineManager;

@BeforeEach
public void setup() throws IOException, InvalidStateTransitionException,
TimeoutException {
final OzoneConfiguration conf = SCMTestUtils.getConf();
void setup() throws IOException, InvalidStateTransitionException {
final OzoneConfiguration conf = SCMTestUtils.getConf(testDir);
nodeManager = new MockNodeManager(true, 10);
containerManager = mock(ContainerManager.class);
conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, testDir.getAbsolutePath());
dbStore = DBStoreBuilder.createDBStore(
conf, new SCMDBDefinition());
scmhaManager = SCMHAManagerStub.getInstance(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.io.IOException;
import java.util.Iterator;

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.LifeCycleState;
Expand Down Expand Up @@ -76,10 +75,9 @@ public class TestUnknownContainerReport {

@BeforeEach
public void setup() throws IOException {
final OzoneConfiguration conf = SCMTestUtils.getConf();
final OzoneConfiguration conf = SCMTestUtils.getConf(testDir);
this.nodeManager = new MockNodeManager(true, 10);
this.containerManager = mock(ContainerManager.class);
conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, testDir.getAbsolutePath());
dbStore = DBStoreBuilder.createDBStore(
conf, new SCMDBDefinition());
scmhaManager = SCMHAManagerStub.getInstance(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
import org.apache.ratis.protocol.exceptions.NotLeaderException;
import org.junit.jupiter.api.BeforeEach;
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.ValueSource;

import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -62,10 +64,10 @@ public class TestECMisReplicationHandler extends TestMisReplicationHandler {


@BeforeEach
public void setup() throws NodeNotFoundException,
void setup(@TempDir File testDir) throws NodeNotFoundException,
CommandTargetOverloadedException, NotLeaderException {
ECReplicationConfig repConfig = new ECReplicationConfig(DATA, PARITY);
setup(repConfig);
setup(repConfig, testDir);
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@
import org.apache.ratis.protocol.exceptions.NotLeaderException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.stubbing.Answer;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -82,7 +84,7 @@ public class TestECOverReplicationHandler {
private Set<Pair<DatanodeDetails, SCMCommand<?>>> commandsSent;

@BeforeEach
public void setup() throws NodeNotFoundException, NotLeaderException,
void setup(@TempDir File testDir) throws NodeNotFoundException, NotLeaderException,
CommandTargetOverloadedException {
staleNode = null;

Expand All @@ -103,7 +105,7 @@ public void setup() throws NodeNotFoundException, NotLeaderException,
commandsSent);

NodeManager nodeManager = new MockNodeManager(true, 10);
OzoneConfiguration conf = SCMTestUtils.getConf();
OzoneConfiguration conf = SCMTestUtils.getConf(testDir);
ECReplicationConfig repConfig = new ECReplicationConfig(3, 2);
container = ReplicationTestUtil
.createContainer(HddsProtos.LifeCycleState.CLOSED, repConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@
import org.assertj.core.util.Lists;
import org.junit.jupiter.api.BeforeEach;
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.ValueSource;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -125,7 +127,7 @@ public class TestECUnderReplicationHandler {
= new AtomicBoolean(false);

@BeforeEach
public void setup() throws NodeNotFoundException,
void setup(@TempDir File testDir) throws NodeNotFoundException,
CommandTargetOverloadedException, NotLeaderException {
nodeManager = new MockNodeManager(true, 10) {
@Override
Expand Down Expand Up @@ -159,7 +161,7 @@ public NodeStatus getNodeStatus(DatanodeDetails dd) {
replicationManager, commandsSent,
throwOverloadedExceptionOnReconstruction);

conf = SCMTestUtils.getConf();
conf = SCMTestUtils.getConf(testDir);
repConfig = new ECReplicationConfig(DATA, PARITY);
container = createContainer(HddsProtos.LifeCycleState.CLOSED, repConfig);
policy = ReplicationTestUtil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
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.EnumSource;
import org.junit.jupiter.params.provider.ValueSource;

import java.io.File;
import java.io.IOException;
import java.time.Clock;
import java.time.Instant;
Expand Down Expand Up @@ -155,15 +157,18 @@ public class TestLegacyReplicationManager {
private DBStore dbStore;
private ContainerReplicaPendingOps containerReplicaPendingOps;

@TempDir
private File tempDir;

int getInflightCount(InflightType type) {
return replicationManager.getLegacyReplicationManager()
.getInflightCount(type);
}

@BeforeEach
void setup() throws IOException, InterruptedException,
void setup(@TempDir File testDir) throws IOException, InterruptedException,
NodeNotFoundException, InvalidStateTransitionException {
OzoneConfiguration conf = SCMTestUtils.getConf();
OzoneConfiguration conf = SCMTestUtils.getConf(testDir);
conf.setTimeDuration(
HddsConfigKeys.HDDS_SCM_WAIT_TIME_AFTER_SAFE_MODE_EXIT,
0, TimeUnit.SECONDS);
Expand Down Expand Up @@ -260,10 +265,10 @@ private void createReplicationManager(ReplicationManagerConfiguration rmConf)
createReplicationManager(rmConf, null);
}

void createReplicationManager(ReplicationManagerConfiguration rmConf,
private void createReplicationManager(ReplicationManagerConfiguration rmConf,
LegacyReplicationManagerConfiguration lrmConf)
throws InterruptedException, IOException {
OzoneConfiguration config = SCMTestUtils.getConf();
OzoneConfiguration config = SCMTestUtils.getConf(tempDir);
config.setTimeDuration(
HddsConfigKeys.HDDS_SCM_WAIT_TIME_AFTER_SAFE_MODE_EXIT,
0, TimeUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.hadoop.ozone.protocol.commands.SCMCommand;
import org.apache.ratis.protocol.exceptions.NotLeaderException;

import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -78,10 +79,10 @@ public abstract class TestMisReplicationHandler {
new AtomicBoolean(false);
private ReplicationManagerMetrics metrics;

protected void setup(ReplicationConfig repConfig)
protected void setup(ReplicationConfig repConfig, File testDir)
throws NodeNotFoundException, CommandTargetOverloadedException,
NotLeaderException {
conf = SCMTestUtils.getConf();
conf = SCMTestUtils.getConf(testDir);

replicationManager = mock(ReplicationManager.class);
when(replicationManager.getNodeStatus(any(DatanodeDetails.class)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
import org.apache.ratis.protocol.exceptions.NotLeaderException;
import org.junit.jupiter.api.BeforeEach;
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.ValueSource;

import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
Expand All @@ -59,11 +61,11 @@
public class TestRatisMisReplicationHandler extends TestMisReplicationHandler {

@BeforeEach
public void setup() throws NodeNotFoundException,
void setup(@TempDir File testDir) throws NodeNotFoundException,
CommandTargetOverloadedException, NotLeaderException {
RatisReplicationConfig repConfig = RatisReplicationConfig
.getInstance(ReplicationFactor.THREE);
setup(repConfig);
setup(repConfig, testDir);
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@
import org.apache.ratis.protocol.exceptions.NotLeaderException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.ArgumentCaptor;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -89,13 +91,13 @@ public class TestRatisUnderReplicationHandler {
private ReplicationManagerMetrics metrics;

@BeforeEach
public void setup() throws NodeNotFoundException,
void setup(@TempDir File testDir) throws NodeNotFoundException,
CommandTargetOverloadedException, NotLeaderException {
container = ReplicationTestUtil.createContainer(
HddsProtos.LifeCycleState.CLOSED, RATIS_REPLICATION_CONFIG);

nodeManager = mock(NodeManager.class);
conf = SCMTestUtils.getConf();
conf = SCMTestUtils.getConf(testDir);
policy = ReplicationTestUtil
.getSimpleTestPlacementPolicy(nodeManager, conf);
replicationManager = mock(ReplicationManager.class);
Expand Down
Loading

0 comments on commit 296d571

Please sign in to comment.