示例#1
0
        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());
        }