public virtual void TestAddVolumeFailureReleasesInUseLock() { FsDatasetImpl spyDataset = Org.Mockito.Mockito.Spy(dataset); FsVolumeImpl mockVolume = Org.Mockito.Mockito.Mock <FsVolumeImpl>(); FilePath badDir = new FilePath(BaseDir, "bad"); badDir.Mkdirs(); Org.Mockito.Mockito.DoReturn(mockVolume).When(spyDataset).CreateFsVolume(Matchers.AnyString (), Matchers.Any <FilePath>(), Matchers.Any <StorageType>()); Org.Mockito.Mockito.DoThrow(new IOException("Failed to getVolumeMap()")).When(mockVolume ).GetVolumeMap(Matchers.AnyString(), Matchers.Any <ReplicaMap>(), Matchers.Any <RamDiskReplicaLruTracker >()); Storage.StorageDirectory sd = CreateStorageDirectory(badDir); sd.Lock(); DataStorage.VolumeBuilder builder = new DataStorage.VolumeBuilder(storage, sd); Org.Mockito.Mockito.When(storage.PrepareVolume(Matchers.Eq(datanode), Matchers.Eq (badDir.GetAbsoluteFile()), Matchers.Any <IList <NamespaceInfo> >())).ThenReturn(builder ); StorageLocation location = StorageLocation.Parse(badDir.ToString()); IList <NamespaceInfo> nsInfos = Lists.NewArrayList(); foreach (string bpid in BlockPoolIds) { nsInfos.AddItem(new NamespaceInfo(0, ClusterId, bpid, 1)); } try { spyDataset.AddVolume(location, nsInfos); NUnit.Framework.Assert.Fail("Expect to throw MultipleIOException"); } catch (MultipleIOException) { } FsDatasetTestUtil.AssertFileLockReleased(badDir.ToString()); }
public virtual void TestAddVolumes() { int numNewVolumes = 3; int numExistingVolumes = dataset.GetVolumes().Count; int totalVolumes = numNewVolumes + numExistingVolumes; ICollection <string> expectedVolumes = new HashSet <string>(); IList <NamespaceInfo> nsInfos = Lists.NewArrayList(); foreach (string bpid in BlockPoolIds) { nsInfos.AddItem(new NamespaceInfo(0, ClusterId, bpid, 1)); } for (int i = 0; i < numNewVolumes; i++) { string path = BaseDir + "/newData" + i; string pathUri = new Path(path).ToUri().ToString(); expectedVolumes.AddItem(new FilePath(pathUri).ToString()); StorageLocation loc = StorageLocation.Parse(pathUri); Storage.StorageDirectory sd = CreateStorageDirectory(new FilePath(path)); DataStorage.VolumeBuilder builder = new DataStorage.VolumeBuilder(storage, sd); Org.Mockito.Mockito.When(storage.PrepareVolume(Matchers.Eq(datanode), Matchers.Eq (loc.GetFile()), Matchers.AnyListOf <NamespaceInfo>())).ThenReturn(builder); dataset.AddVolume(loc, nsInfos); } NUnit.Framework.Assert.AreEqual(totalVolumes, dataset.GetVolumes().Count); NUnit.Framework.Assert.AreEqual(totalVolumes, dataset.storageMap.Count); ICollection <string> actualVolumes = new HashSet <string>(); for (int i_1 = 0; i_1 < numNewVolumes; i_1++) { actualVolumes.AddItem(dataset.GetVolumes()[numExistingVolumes + i_1].GetBasePath( )); } NUnit.Framework.Assert.AreEqual(actualVolumes.Count, expectedVolumes.Count); NUnit.Framework.Assert.IsTrue(actualVolumes.ContainsAll(expectedVolumes)); }