|
@@ -28,6 +28,7 @@ import java.io.InputStream;
|
|
import java.io.OutputStream;
|
|
import java.io.OutputStream;
|
|
import java.net.InetSocketAddress;
|
|
import java.net.InetSocketAddress;
|
|
import java.net.SocketTimeoutException;
|
|
import java.net.SocketTimeoutException;
|
|
|
|
+import java.net.URI;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -542,9 +543,11 @@ public class TestDFSClientRetries extends TestCase {
|
|
conf, numDatanodes, true, null);
|
|
conf, numDatanodes, true, null);
|
|
try {
|
|
try {
|
|
cluster.waitActive();
|
|
cluster.waitActive();
|
|
|
|
+ final DistributedFileSystem dfs = (DistributedFileSystem)cluster.getFileSystem();
|
|
|
|
+ final URI uri = dfs.getUri();
|
|
|
|
+ assertTrue(DistributedFileSystem.isHealthy(uri));
|
|
|
|
|
|
//create a file
|
|
//create a file
|
|
- final DistributedFileSystem dfs = (DistributedFileSystem)cluster.getFileSystem();
|
|
|
|
final long length = 1L << 20;
|
|
final long length = 1L << 20;
|
|
final Path file1 = new Path(dir, "foo");
|
|
final Path file1 = new Path(dir, "foo");
|
|
DFSTestUtil.createFile(dfs, file1, length, numDatanodes, 20120406L);
|
|
DFSTestUtil.createFile(dfs, file1, length, numDatanodes, 20120406L);
|
|
@@ -554,7 +557,9 @@ public class TestDFSClientRetries extends TestCase {
|
|
assertEquals(length, s1.getLen());
|
|
assertEquals(length, s1.getLen());
|
|
|
|
|
|
//shutdown namenode
|
|
//shutdown namenode
|
|
|
|
+ assertTrue(DistributedFileSystem.isHealthy(uri));
|
|
cluster.shutdownNameNode();
|
|
cluster.shutdownNameNode();
|
|
|
|
+ assertFalse(DistributedFileSystem.isHealthy(uri));
|
|
|
|
|
|
//namenode is down, create another file in a thread
|
|
//namenode is down, create another file in a thread
|
|
final Path file3 = new Path(dir, "file");
|
|
final Path file3 = new Path(dir, "file");
|
|
@@ -579,8 +584,10 @@ public class TestDFSClientRetries extends TestCase {
|
|
try {
|
|
try {
|
|
//sleep, restart, and then wait active
|
|
//sleep, restart, and then wait active
|
|
TimeUnit.SECONDS.sleep(30);
|
|
TimeUnit.SECONDS.sleep(30);
|
|
|
|
+ assertFalse(DistributedFileSystem.isHealthy(uri));
|
|
cluster.restartNameNode(false, false);
|
|
cluster.restartNameNode(false, false);
|
|
cluster.waitActive();
|
|
cluster.waitActive();
|
|
|
|
+ assertTrue(DistributedFileSystem.isHealthy(uri));
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
exceptions.add(e);
|
|
exceptions.add(e);
|
|
}
|
|
}
|
|
@@ -596,7 +603,9 @@ public class TestDFSClientRetries extends TestCase {
|
|
assertEquals(dfs.getFileChecksum(file1), dfs.getFileChecksum(file3));
|
|
assertEquals(dfs.getFileChecksum(file1), dfs.getFileChecksum(file3));
|
|
|
|
|
|
//enter safe mode
|
|
//enter safe mode
|
|
|
|
+ assertTrue(DistributedFileSystem.isHealthy(uri));
|
|
dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
|
|
dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
|
|
|
|
+ assertFalse(DistributedFileSystem.isHealthy(uri));
|
|
|
|
|
|
//leave safe mode in a new thread
|
|
//leave safe mode in a new thread
|
|
new Thread(new Runnable() {
|
|
new Thread(new Runnable() {
|
|
@@ -605,7 +614,9 @@ public class TestDFSClientRetries extends TestCase {
|
|
try {
|
|
try {
|
|
//sleep and then leave safe mode
|
|
//sleep and then leave safe mode
|
|
TimeUnit.SECONDS.sleep(30);
|
|
TimeUnit.SECONDS.sleep(30);
|
|
|
|
+ assertFalse(DistributedFileSystem.isHealthy(uri));
|
|
dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
|
|
dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
|
|
|
|
+ assertTrue(DistributedFileSystem.isHealthy(uri));
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
exceptions.add(e);
|
|
exceptions.add(e);
|
|
}
|
|
}
|
|
@@ -616,6 +627,8 @@ public class TestDFSClientRetries extends TestCase {
|
|
final Path file2 = new Path(dir, "bar");
|
|
final Path file2 = new Path(dir, "bar");
|
|
DFSTestUtil.createFile(dfs, file2, length, numDatanodes, 20120406L);
|
|
DFSTestUtil.createFile(dfs, file2, length, numDatanodes, 20120406L);
|
|
assertEquals(dfs.getFileChecksum(file1), dfs.getFileChecksum(file2));
|
|
assertEquals(dfs.getFileChecksum(file1), dfs.getFileChecksum(file2));
|
|
|
|
+
|
|
|
|
+ assertTrue(DistributedFileSystem.isHealthy(uri));
|
|
|
|
|
|
//make sure it won't retry on exceptions like FileNotFoundException
|
|
//make sure it won't retry on exceptions like FileNotFoundException
|
|
final Path nonExisting = new Path(dir, "nonExisting");
|
|
final Path nonExisting = new Path(dir, "nonExisting");
|