HDDS-1650. Fix Ozone tests leaking volume checker thread. Contributed by Xiaoyu Yao. (#915)

This commit is contained in:
Xiaoyu Yao 2019-06-06 11:20:04 -07:00 committed by Nanda kumar
parent 76c0183ae3
commit c7e6f076df
6 changed files with 37 additions and 12 deletions

View File

@ -73,13 +73,15 @@ public class TestHddsDispatcher {
public void testContainerCloseActionWhenFull() throws IOException { public void testContainerCloseActionWhenFull() throws IOException {
String testDir = GenericTestUtils.getTempPath( String testDir = GenericTestUtils.getTempPath(
TestHddsDispatcher.class.getSimpleName()); TestHddsDispatcher.class.getSimpleName());
OzoneConfiguration conf = new OzoneConfiguration();
DatanodeDetails dd = randomDatanodeDetails();
VolumeSet volumeSet = new VolumeSet(dd.getUuidString(), conf);
try { try {
UUID scmId = UUID.randomUUID(); UUID scmId = UUID.randomUUID();
OzoneConfiguration conf = new OzoneConfiguration();
conf.set(HDDS_DATANODE_DIR_KEY, testDir); conf.set(HDDS_DATANODE_DIR_KEY, testDir);
DatanodeDetails dd = randomDatanodeDetails();
ContainerSet containerSet = new ContainerSet(); ContainerSet containerSet = new ContainerSet();
VolumeSet volumeSet = new VolumeSet(dd.getUuidString(), conf);
DatanodeStateMachine stateMachine = Mockito.mock( DatanodeStateMachine stateMachine = Mockito.mock(
DatanodeStateMachine.class); DatanodeStateMachine.class);
StateContext context = Mockito.mock(StateContext.class); StateContext context = Mockito.mock(StateContext.class);
@ -118,6 +120,7 @@ public class TestHddsDispatcher {
.addContainerActionIfAbsent(Mockito.any(ContainerAction.class)); .addContainerActionIfAbsent(Mockito.any(ContainerAction.class));
} finally { } finally {
volumeSet.shutdown();
FileUtils.deleteDirectory(new File(testDir)); FileUtils.deleteDirectory(new File(testDir));
} }

View File

@ -24,6 +24,7 @@ import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.util.DiskChecker.DiskOutOfSpaceException; import org.apache.hadoop.util.DiskChecker.DiskOutOfSpaceException;
import org.apache.hadoop.util.ReflectionUtils; import org.apache.hadoop.util.ReflectionUtils;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -40,10 +41,12 @@ public class TestRoundRobinVolumeChoosingPolicy {
private RoundRobinVolumeChoosingPolicy policy; private RoundRobinVolumeChoosingPolicy policy;
private List<HddsVolume> volumes; private List<HddsVolume> volumes;
private VolumeSet volumeSet;
private final String baseDir = MiniDFSCluster.getBaseDirectory(); private final String baseDir = MiniDFSCluster.getBaseDirectory();
private final String volume1 = baseDir + "disk1"; private final String volume1 = baseDir + "disk1";
private final String volume2 = baseDir + "disk2"; private final String volume2 = baseDir + "disk2";
private static final String DUMMY_IP_ADDR = "0.0.0.0"; private static final String DUMMY_IP_ADDR = "0.0.0.0";
@Before @Before
@ -53,10 +56,18 @@ public class TestRoundRobinVolumeChoosingPolicy {
conf.set(DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY, dataDirKey); conf.set(DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY, dataDirKey);
policy = ReflectionUtils.newInstance( policy = ReflectionUtils.newInstance(
RoundRobinVolumeChoosingPolicy.class, null); RoundRobinVolumeChoosingPolicy.class, null);
VolumeSet volumeSet = new VolumeSet(UUID.randomUUID().toString(), conf); volumeSet = new VolumeSet(UUID.randomUUID().toString(), conf);
volumes = volumeSet.getVolumesList(); volumes = volumeSet.getVolumesList();
} }
@After
public void cleanUp() {
if (volumeSet != null) {
volumeSet.shutdown();
volumeSet = null;
}
}
@Test @Test
public void testRRVolumeChoosingPolicy() throws Exception { public void testRRVolumeChoosingPolicy() throws Exception {
HddsVolume hddsVolume1 = volumes.get(0); HddsVolume hddsVolume1 = volumes.get(0);

View File

@ -237,6 +237,7 @@ public class TestVolumeSet {
//Set back to writable //Set back to writable
try { try {
readOnlyVolumePath.setWritable(true); readOnlyVolumePath.setWritable(true);
volSet.shutdown();
} finally { } finally {
FileUtil.fullyDelete(volumePath); FileUtil.fullyDelete(volumePath);
} }

View File

@ -100,6 +100,7 @@ public class TestVolumeSetDiskChecks {
for (String d : dirs) { for (String d : dirs) {
assertTrue(new File(d).isDirectory()); assertTrue(new File(d).isDirectory());
} }
volumeSet.shutdown();
} }
/** /**
@ -124,6 +125,7 @@ public class TestVolumeSetDiskChecks {
assertThat(volumeSet.getFailedVolumesList().size(), is(numBadVolumes)); assertThat(volumeSet.getFailedVolumesList().size(), is(numBadVolumes));
assertThat(volumeSet.getVolumesList().size(), assertThat(volumeSet.getVolumesList().size(),
is(numVolumes - numBadVolumes)); is(numVolumes - numBadVolumes));
volumeSet.shutdown();
} }
/** /**
@ -146,6 +148,7 @@ public class TestVolumeSetDiskChecks {
assertEquals(volumeSet.getFailedVolumesList().size(), numVolumes); assertEquals(volumeSet.getFailedVolumesList().size(), numVolumes);
assertEquals(volumeSet.getVolumesList().size(), 0); assertEquals(volumeSet.getVolumesList().size(), 0);
volumeSet.shutdown();
} }
/** /**

View File

@ -229,14 +229,14 @@ public class TestKeyValueHandler {
@Test @Test
public void testVolumeSetInKeyValueHandler() throws Exception{ public void testVolumeSetInKeyValueHandler() throws Exception{
File path = GenericTestUtils.getRandomizedTestDir(); File path = GenericTestUtils.getRandomizedTestDir();
try {
Configuration conf = new OzoneConfiguration(); Configuration conf = new OzoneConfiguration();
conf.set(HDDS_DATANODE_DIR_KEY, path.getAbsolutePath()); conf.set(HDDS_DATANODE_DIR_KEY, path.getAbsolutePath());
VolumeSet volumeSet = new VolumeSet(UUID.randomUUID().toString(), conf);
try {
ContainerSet cset = new ContainerSet(); ContainerSet cset = new ContainerSet();
int[] interval = new int[1]; int[] interval = new int[1];
interval[0] = 2; interval[0] = 2;
ContainerMetrics metrics = new ContainerMetrics(interval); ContainerMetrics metrics = new ContainerMetrics(interval);
VolumeSet volumeSet = new VolumeSet(UUID.randomUUID().toString(), conf);
DatanodeDetails datanodeDetails = Mockito.mock(DatanodeDetails.class); DatanodeDetails datanodeDetails = Mockito.mock(DatanodeDetails.class);
DatanodeStateMachine stateMachine = Mockito.mock( DatanodeStateMachine stateMachine = Mockito.mock(
DatanodeStateMachine.class); DatanodeStateMachine.class);
@ -263,6 +263,7 @@ public class TestKeyValueHandler {
ex); ex);
} }
} finally { } finally {
volumeSet.shutdown();
FileUtil.fullyDelete(path); FileUtil.fullyDelete(path);
} }
} }

View File

@ -41,6 +41,7 @@ import org.apache.hadoop.ozone.container.common.volume.VolumeSet;
import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainer; import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainer;
import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainerData; import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainerData;
import org.apache.hadoop.ozone.container.keyvalue.helpers.BlockUtils; import org.apache.hadoop.ozone.container.keyvalue.helpers.BlockUtils;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -82,13 +83,20 @@ public class TestOzoneContainer {
conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, conf.set(HddsConfigKeys.OZONE_METADATA_DIRS,
folder.newFolder().getAbsolutePath()); folder.newFolder().getAbsolutePath());
commitSpaceMap = new HashMap<String, Long>(); commitSpaceMap = new HashMap<String, Long>();
volumeSet = new VolumeSet(datanodeDetails.getUuidString(), conf);
volumeChoosingPolicy = new RoundRobinVolumeChoosingPolicy();
}
@After
public void cleanUp() throws Exception {
if (volumeSet != null) {
volumeSet.shutdown();
volumeSet = null;
}
} }
@Test @Test
public void testBuildContainerMap() throws Exception { public void testBuildContainerMap() throws Exception {
volumeSet = new VolumeSet(datanodeDetails.getUuidString(), conf);
volumeChoosingPolicy = new RoundRobinVolumeChoosingPolicy();
// Format the volumes // Format the volumes
for (HddsVolume volume : volumeSet.getVolumesList()) { for (HddsVolume volume : volumeSet.getVolumesList()) {
volume.format(UUID.randomUUID().toString()); volume.format(UUID.randomUUID().toString());
@ -139,8 +147,6 @@ public class TestOzoneContainer {
@Test @Test
public void testContainerCreateDiskFull() throws Exception { public void testContainerCreateDiskFull() throws Exception {
volumeSet = new VolumeSet(datanodeDetails.getUuidString(), conf);
volumeChoosingPolicy = new RoundRobinVolumeChoosingPolicy();
long containerSize = (long) StorageUnit.MB.toBytes(100); long containerSize = (long) StorageUnit.MB.toBytes(100);
boolean diskSpaceException = false; boolean diskSpaceException = false;