public virtual void TestIsInSafemode() { // Check for the standby nn without client failover. NameNode nn2 = cluster.GetNameNode(1); NUnit.Framework.Assert.IsTrue("nn2 should be in standby state", nn2.IsStandbyState ()); IPEndPoint nameNodeAddress = nn2.GetNameNodeAddress(); Configuration conf = new Configuration(); DistributedFileSystem dfs = new DistributedFileSystem(); try { dfs.Initialize(URI.Create("hdfs://" + nameNodeAddress.GetHostName() + ":" + nameNodeAddress .Port), conf); dfs.IsInSafeMode(); NUnit.Framework.Assert.Fail("StandBy should throw exception for isInSafeMode"); } catch (IOException e) { if (e is RemoteException) { IOException sbExcpetion = ((RemoteException)e).UnwrapRemoteException(); NUnit.Framework.Assert.IsTrue("StandBy nn should not support isInSafeMode", sbExcpetion is StandbyException); } else { throw; } } finally { if (null != dfs) { dfs.Close(); } } // Check with Client FailOver cluster.TransitionToStandby(0); cluster.TransitionToActive(1); cluster.GetNameNodeRpc(1).SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter, false); DistributedFileSystem dfsWithFailOver = (DistributedFileSystem)fs; NUnit.Framework.Assert.IsTrue("ANN should be in SafeMode", dfsWithFailOver.IsInSafeMode ()); cluster.GetNameNodeRpc(1).SetSafeMode(HdfsConstants.SafeModeAction.SafemodeLeave, false); NUnit.Framework.Assert.IsFalse("ANN should be out of SafeMode", dfsWithFailOver.IsInSafeMode ()); }
/* * Tests some utility methods that surround the SafeMode's state. * @throws IOException when there's an issue connecting to the test DFS. */ /// <exception cref="System.IO.IOException"/> public virtual void TestSafeModeUtils() { dfs = cluster.GetFileSystem(); // Enter safemode. dfs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter); NUnit.Framework.Assert.IsTrue("State was expected to be in safemode.", dfs.IsInSafeMode ()); // Exit safemode. dfs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeLeave); NUnit.Framework.Assert.IsFalse("State was expected to be out of safemode.", dfs.IsInSafeMode ()); }
/// <exception cref="System.IO.IOException"/> private void VerifyNNIsInSafeMode(DistributedFileSystem dfs) { while (true) { try { if (dfs.IsInSafeMode()) { return; } else { throw new IOException("Expected to be in SafeMode"); } } catch (IOException) { } } }