public virtual void TestAddVolumeFailures() { StartDFSCluster(1, 1); string dataDir = cluster.GetDataDirectory(); DataNode dn = cluster.GetDataNodes()[0]; IList <string> newDirs = Lists.NewArrayList(); int NumNewDirs = 4; for (int i = 0; i < NumNewDirs; i++) { FilePath newVolume = new FilePath(dataDir, "new_vol" + i); newDirs.AddItem(newVolume.ToString()); if (i % 2 == 0) { // Make addVolume() fail. newVolume.CreateNewFile(); } } string newValue = dn.GetConf().Get(DFSConfigKeys.DfsDatanodeDataDirKey) + "," + Joiner .On(",").Join(newDirs); try { dn.ReconfigurePropertyImpl(DFSConfigKeys.DfsDatanodeDataDirKey, newValue); NUnit.Framework.Assert.Fail("Expect to throw IOException."); } catch (ReconfigurationException e) { string errorMessage = e.InnerException.Message; string[] messages = errorMessage.Split("\\r?\\n"); NUnit.Framework.Assert.AreEqual(2, messages.Length); Assert.AssertThat(messages[0], CoreMatchers.ContainsString("new_vol0")); Assert.AssertThat(messages[1], CoreMatchers.ContainsString("new_vol2")); } // Make sure that vol0 and vol2's metadata are not left in memory. FsDatasetSpi <object> dataset = dn.GetFSDataset(); foreach (FsVolumeSpi volume in dataset.GetVolumes()) { Assert.AssertThat(volume.GetBasePath(), IS.Is(CoreMatchers.Not(CoreMatchers.AnyOf (IS.Is(newDirs[0]), IS.Is(newDirs[2]))))); } DataStorage storage = dn.GetStorage(); for (int i_1 = 0; i_1 < storage.GetNumStorageDirs(); i_1++) { Storage.StorageDirectory sd = storage.GetStorageDir(i_1); Assert.AssertThat(sd.GetRoot().ToString(), IS.Is(CoreMatchers.Not(CoreMatchers.AnyOf (IS.Is(newDirs[0]), IS.Is(newDirs[2]))))); } // The newly effective conf does not have vol0 and vol2. string[] effectiveVolumes = dn.GetConf().Get(DFSConfigKeys.DfsDatanodeDataDirKey) .Split(","); NUnit.Framework.Assert.AreEqual(4, effectiveVolumes.Length); foreach (string ev in effectiveVolumes) { Assert.AssertThat(StorageLocation.Parse(ev).GetFile().GetCanonicalPath(), IS.Is(CoreMatchers.Not (CoreMatchers.AnyOf(IS.Is(newDirs[0]), IS.Is(newDirs[2]))))); } }
public virtual void TestAsyncReconfigure() { TestReconfiguration.AsyncReconfigurableDummy dummy = Org.Mockito.Mockito.Spy(new TestReconfiguration.AsyncReconfigurableDummy(conf1)); IList <ReconfigurationUtil.PropertyChange> changes = Lists.NewArrayList(); changes.AddItem(new ReconfigurationUtil.PropertyChange("name1", "new1", "old1")); changes.AddItem(new ReconfigurationUtil.PropertyChange("name2", "new2", "old2")); changes.AddItem(new ReconfigurationUtil.PropertyChange("name3", "new3", "old3")); Org.Mockito.Mockito.DoReturn(changes).When(dummy).GetChangedProperties(Matchers.Any <Configuration>(), Matchers.Any <Configuration>()); Org.Mockito.Mockito.DoReturn(true).When(dummy).IsPropertyReconfigurable(Matchers.Eq ("name1")); Org.Mockito.Mockito.DoReturn(false).When(dummy).IsPropertyReconfigurable(Matchers.Eq ("name2")); Org.Mockito.Mockito.DoReturn(true).When(dummy).IsPropertyReconfigurable(Matchers.Eq ("name3")); Org.Mockito.Mockito.DoNothing().When(dummy).ReconfigurePropertyImpl(Matchers.Eq("name1" ), Matchers.AnyString()); Org.Mockito.Mockito.DoNothing().When(dummy).ReconfigurePropertyImpl(Matchers.Eq("name2" ), Matchers.AnyString()); Org.Mockito.Mockito.DoThrow(new ReconfigurationException("NAME3", "NEW3", "OLD3", new IOException("io exception"))).When(dummy).ReconfigurePropertyImpl(Matchers.Eq ("name3"), Matchers.AnyString()); dummy.StartReconfigurationTask(); WaitAsyncReconfigureTaskFinish(dummy); ReconfigurationTaskStatus status = dummy.GetReconfigurationTaskStatus(); Assert.Equal(3, status.GetStatus().Count); foreach (KeyValuePair <ReconfigurationUtil.PropertyChange, Optional <string> > result in status.GetStatus()) { ReconfigurationUtil.PropertyChange change = result.Key; if (change.prop.Equals("name1")) { NUnit.Framework.Assert.IsFalse(result.Value.IsPresent()); } else { if (change.prop.Equals("name2")) { MatcherAssert.AssertThat(result.Value.Get(), CoreMatchers.ContainsString("Property name2 is not reconfigurable" )); } else { if (change.prop.Equals("name3")) { MatcherAssert.AssertThat(result.Value.Get(), CoreMatchers.ContainsString("io exception" )); } else { NUnit.Framework.Assert.Fail("Unknown property: " + change.prop); } } } } }
/// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> public virtual void TestGetReconfigureStatus() { ReconfigurationUtil ru = Org.Mockito.Mockito.Mock <ReconfigurationUtil>(); datanode.SetReconfigurationUtil(ru); IList <ReconfigurationUtil.PropertyChange> changes = new AList <ReconfigurationUtil.PropertyChange >(); FilePath newDir = new FilePath(cluster.GetDataDirectory(), "data_new"); newDir.Mkdirs(); changes.AddItem(new ReconfigurationUtil.PropertyChange(DFSConfigKeys.DfsDatanodeDataDirKey , newDir.ToString(), datanode.GetConf().Get(DFSConfigKeys.DfsDatanodeDataDirKey) )); changes.AddItem(new ReconfigurationUtil.PropertyChange("randomKey", "new123", "old456" )); Org.Mockito.Mockito.When(ru.ParseChangedProperties(Matchers.Any <Configuration>(), Matchers.Any <Configuration>())).ThenReturn(changes); int port = datanode.GetIpcPort(); string address = "localhost:" + port; Assert.AssertThat(admin.StartReconfiguration("datanode", address), CoreMatchers.Is (0)); IList <string> outputs = null; int count = 100; while (count > 0) { outputs = GetReconfigureStatus("datanode", address); if (!outputs.IsEmpty() && outputs[0].Contains("finished")) { break; } count--; Sharpen.Thread.Sleep(100); } NUnit.Framework.Assert.IsTrue(count > 0); Assert.AssertThat(outputs.Count, CoreMatchers.Is(8)); // 3 (SUCCESS) + 4 (FAILED) IList <StorageLocation> locations = DataNode.GetStorageLocations(datanode.GetConf( )); Assert.AssertThat(locations.Count, CoreMatchers.Is(1)); Assert.AssertThat(locations[0].GetFile(), CoreMatchers.Is(newDir)); // Verify the directory is appropriately formatted. NUnit.Framework.Assert.IsTrue(new FilePath(newDir, Storage.StorageDirCurrent).IsDirectory ()); int successOffset = outputs[1].StartsWith("SUCCESS:") ? 1 : 5; int failedOffset = outputs[1].StartsWith("FAILED:") ? 1 : 4; Assert.AssertThat(outputs[successOffset], CoreMatchers.ContainsString("Change property " + DFSConfigKeys.DfsDatanodeDataDirKey)); Assert.AssertThat(outputs[successOffset + 1], CoreMatchers.Is(CoreMatchers.AllOf( CoreMatchers.ContainsString("From:"), CoreMatchers.ContainsString("data1"), CoreMatchers.ContainsString ("data2")))); Assert.AssertThat(outputs[successOffset + 2], CoreMatchers.Is(CoreMatchers.Not(CoreMatchers.AnyOf (CoreMatchers.ContainsString("data1"), CoreMatchers.ContainsString("data2"))))); Assert.AssertThat(outputs[successOffset + 2], CoreMatchers.Is(CoreMatchers.AllOf( CoreMatchers.ContainsString("To"), CoreMatchers.ContainsString("data_new")))); Assert.AssertThat(outputs[failedOffset], CoreMatchers.ContainsString("Change property randomKey" )); Assert.AssertThat(outputs[failedOffset + 1], CoreMatchers.ContainsString("From: \"old456\"" )); Assert.AssertThat(outputs[failedOffset + 2], CoreMatchers.ContainsString("To: \"new123\"" )); }