public virtual void TestNNRestart() { MiniDFSCluster cluster = null; FileSystem localFileSys; Path hostsFile; Path excludeFile; int HeartbeatInterval = 1; // heartbeat interval in seconds // Set up the hosts/exclude files. localFileSys = FileSystem.GetLocal(config); Path workingDir = localFileSys.GetWorkingDirectory(); Path dir = new Path(workingDir, "build/test/data/work-dir/restartnn"); hostsFile = new Path(dir, "hosts"); excludeFile = new Path(dir, "exclude"); // Setup conf config.Set(DFSConfigKeys.DfsHostsExclude, excludeFile.ToUri().GetPath()); WriteConfigFile(localFileSys, excludeFile, null); config.Set(DFSConfigKeys.DfsHosts, hostsFile.ToUri().GetPath()); // write into hosts file AList <string> list = new AList <string>(); byte[] b = new byte[] { 127, 0, 0, 1 }; IPAddress inetAddress = IPAddress.GetByAddress(b); list.AddItem(inetAddress.GetHostName()); WriteConfigFile(localFileSys, hostsFile, list); int numDatanodes = 1; try { cluster = new MiniDFSCluster.Builder(config).NumDataNodes(numDatanodes).SetupHostsFile (true).Build(); cluster.WaitActive(); cluster.RestartNameNode(); NamenodeProtocols nn = cluster.GetNameNodeRpc(); NUnit.Framework.Assert.IsNotNull(nn); NUnit.Framework.Assert.IsTrue(cluster.IsDataNodeUp()); DatanodeInfo[] info = nn.GetDatanodeReport(HdfsConstants.DatanodeReportType.Live); for (int i = 0; i < 5 && info.Length != numDatanodes; i++) { Sharpen.Thread.Sleep(HeartbeatInterval * 1000); info = nn.GetDatanodeReport(HdfsConstants.DatanodeReportType.Live); } NUnit.Framework.Assert.AreEqual("Number of live nodes should be " + numDatanodes, numDatanodes, info.Length); } catch (IOException e) { NUnit.Framework.Assert.Fail(StringUtils.StringifyException(e)); throw; } finally { CleanupFile(localFileSys, excludeFile.GetParent()); if (cluster != null) { cluster.Shutdown(); } } }
/// <exception cref="System.Exception"/> public virtual void TestInvalidNetworkTopologiesNotCachedInHdfs() { // start a cluster Configuration conf = new HdfsConfiguration(); MiniDFSCluster cluster = null; try { // bad rack topology string[] racks = new string[] { "/a/b", "/c" }; string[] hosts = new string[] { "foo1.example.com", "foo2.example.com" }; cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(2).Racks(racks).Hosts(hosts ).Build(); cluster.WaitActive(); NamenodeProtocols nn = cluster.GetNameNodeRpc(); NUnit.Framework.Assert.IsNotNull(nn); // Wait for one DataNode to register. // The other DataNode will not be able to register up because of the rack mismatch. DatanodeInfo[] info; while (true) { info = nn.GetDatanodeReport(HdfsConstants.DatanodeReportType.Live); NUnit.Framework.Assert.IsFalse(info.Length == 2); if (info.Length == 1) { break; } Sharpen.Thread.Sleep(1000); } // Set the network topology of the other node to the match the network // topology of the node that came up. int validIdx = info[0].GetHostName().Equals(hosts[0]) ? 0 : 1; int invalidIdx = validIdx == 1 ? 0 : 1; StaticMapping.AddNodeToRack(hosts[invalidIdx], racks[validIdx]); Log.Info("datanode " + validIdx + " came up with network location " + info[0].GetNetworkLocation ()); // Restart the DN with the invalid topology and wait for it to register. cluster.RestartDataNode(invalidIdx); Sharpen.Thread.Sleep(5000); while (true) { info = nn.GetDatanodeReport(HdfsConstants.DatanodeReportType.Live); if (info.Length == 2) { break; } if (info.Length == 0) { Log.Info("got no valid DNs"); } else { if (info.Length == 1) { Log.Info("got one valid DN: " + info[0].GetHostName() + " (at " + info[0].GetNetworkLocation () + ")"); } } Sharpen.Thread.Sleep(1000); } NUnit.Framework.Assert.AreEqual(info[0].GetNetworkLocation(), info[1].GetNetworkLocation ()); } finally { if (cluster != null) { cluster.Shutdown(); } } }