|
@@ -17,6 +17,7 @@
|
|
*/
|
|
*/
|
|
package org.apache.hadoop.hdfs.server.datanode.fsdataset.impl;
|
|
package org.apache.hadoop.hdfs.server.datanode.fsdataset.impl;
|
|
|
|
|
|
|
|
+import com.google.common.base.Supplier;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.fs.FileSystemTestHelper;
|
|
import org.apache.hadoop.fs.FileSystemTestHelper;
|
|
import org.apache.hadoop.fs.StorageType;
|
|
import org.apache.hadoop.fs.StorageType;
|
|
@@ -25,6 +26,7 @@ import org.apache.hadoop.hdfs.server.datanode.BlockScanner;
|
|
import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsVolumeReference;
|
|
import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsVolumeReference;
|
|
import org.apache.hadoop.hdfs.server.datanode.fsdataset.RoundRobinVolumeChoosingPolicy;
|
|
import org.apache.hadoop.hdfs.server.datanode.fsdataset.RoundRobinVolumeChoosingPolicy;
|
|
import org.apache.hadoop.hdfs.server.datanode.fsdataset.VolumeChoosingPolicy;
|
|
import org.apache.hadoop.hdfs.server.datanode.fsdataset.VolumeChoosingPolicy;
|
|
|
|
+import org.apache.hadoop.test.GenericTestUtils;
|
|
import org.junit.Before;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
|
|
@@ -33,9 +35,11 @@ import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.concurrent.TimeoutException;
|
|
|
|
|
|
import static org.junit.Assert.assertNotEquals;
|
|
import static org.junit.Assert.assertNotEquals;
|
|
import static org.junit.Assert.assertNull;
|
|
import static org.junit.Assert.assertNull;
|
|
|
|
+import static org.junit.Assert.fail;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
|
|
public class TestFsVolumeList {
|
|
public class TestFsVolumeList {
|
|
@@ -57,11 +61,11 @@ public class TestFsVolumeList {
|
|
blockScanner = new BlockScanner(null, blockScannerConf);
|
|
blockScanner = new BlockScanner(null, blockScannerConf);
|
|
}
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
|
|
|
+ @Test(timeout=30000)
|
|
public void testGetNextVolumeWithClosedVolume() throws IOException {
|
|
public void testGetNextVolumeWithClosedVolume() throws IOException {
|
|
FsVolumeList volumeList = new FsVolumeList(
|
|
FsVolumeList volumeList = new FsVolumeList(
|
|
Collections.<VolumeFailureInfo>emptyList(), blockScanner, blockChooser);
|
|
Collections.<VolumeFailureInfo>emptyList(), blockScanner, blockChooser);
|
|
- List<FsVolumeImpl> volumes = new ArrayList<>();
|
|
|
|
|
|
+ final List<FsVolumeImpl> volumes = new ArrayList<>();
|
|
for (int i = 0; i < 3; i++) {
|
|
for (int i = 0; i < 3; i++) {
|
|
File curDir = new File(baseDir, "nextvolume-" + i);
|
|
File curDir = new File(baseDir, "nextvolume-" + i);
|
|
curDir.mkdirs();
|
|
curDir.mkdirs();
|
|
@@ -73,7 +77,19 @@ public class TestFsVolumeList {
|
|
}
|
|
}
|
|
|
|
|
|
// Close the second volume.
|
|
// Close the second volume.
|
|
- volumes.get(1).closeAndWait();
|
|
|
|
|
|
+ volumes.get(1).setClosed();
|
|
|
|
+ try {
|
|
|
|
+ GenericTestUtils.waitFor(new Supplier<Boolean>() {
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean get() {
|
|
|
|
+ return volumes.get(1).checkClosed();
|
|
|
|
+ }
|
|
|
|
+ }, 100, 3000);
|
|
|
|
+ } catch (TimeoutException e) {
|
|
|
|
+ fail("timed out while waiting for volume to be removed.");
|
|
|
|
+ } catch (InterruptedException ie) {
|
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
|
+ }
|
|
for (int i = 0; i < 10; i++) {
|
|
for (int i = 0; i < 10; i++) {
|
|
try (FsVolumeReference ref =
|
|
try (FsVolumeReference ref =
|
|
volumeList.getNextVolume(StorageType.DEFAULT, 128)) {
|
|
volumeList.getNextVolume(StorageType.DEFAULT, 128)) {
|
|
@@ -83,11 +99,11 @@ public class TestFsVolumeList {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
|
|
|
+ @Test(timeout=30000)
|
|
public void testCheckDirsWithClosedVolume() throws IOException {
|
|
public void testCheckDirsWithClosedVolume() throws IOException {
|
|
FsVolumeList volumeList = new FsVolumeList(
|
|
FsVolumeList volumeList = new FsVolumeList(
|
|
Collections.<VolumeFailureInfo>emptyList(), blockScanner, blockChooser);
|
|
Collections.<VolumeFailureInfo>emptyList(), blockScanner, blockChooser);
|
|
- List<FsVolumeImpl> volumes = new ArrayList<>();
|
|
|
|
|
|
+ final List<FsVolumeImpl> volumes = new ArrayList<>();
|
|
for (int i = 0; i < 3; i++) {
|
|
for (int i = 0; i < 3; i++) {
|
|
File curDir = new File(baseDir, "volume-" + i);
|
|
File curDir = new File(baseDir, "volume-" + i);
|
|
curDir.mkdirs();
|
|
curDir.mkdirs();
|
|
@@ -98,12 +114,24 @@ public class TestFsVolumeList {
|
|
}
|
|
}
|
|
|
|
|
|
// Close the 2nd volume.
|
|
// Close the 2nd volume.
|
|
- volumes.get(1).closeAndWait();
|
|
|
|
|
|
+ volumes.get(1).setClosed();
|
|
|
|
+ try {
|
|
|
|
+ GenericTestUtils.waitFor(new Supplier<Boolean>() {
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean get() {
|
|
|
|
+ return volumes.get(1).checkClosed();
|
|
|
|
+ }
|
|
|
|
+ }, 100, 3000);
|
|
|
|
+ } catch (TimeoutException e) {
|
|
|
|
+ fail("timed out while waiting for volume to be removed.");
|
|
|
|
+ } catch (InterruptedException ie) {
|
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
|
+ }
|
|
// checkDirs() should ignore the 2nd volume since it is closed.
|
|
// checkDirs() should ignore the 2nd volume since it is closed.
|
|
volumeList.checkDirs();
|
|
volumeList.checkDirs();
|
|
}
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
|
|
|
+ @Test(timeout=30000)
|
|
public void testReleaseVolumeRefIfNoBlockScanner() throws IOException {
|
|
public void testReleaseVolumeRefIfNoBlockScanner() throws IOException {
|
|
FsVolumeList volumeList = new FsVolumeList(
|
|
FsVolumeList volumeList = new FsVolumeList(
|
|
Collections.<VolumeFailureInfo>emptyList(), null, blockChooser);
|
|
Collections.<VolumeFailureInfo>emptyList(), null, blockChooser);
|