Пример #1
0
        public virtual void TestGetNextVolumeWithClosedVolume()
        {
            FsVolumeList volumeList = new FsVolumeList(Collections.EmptyList <VolumeFailureInfo
                                                                              >(), blockScanner, blockChooser);
            IList <FsVolumeImpl> volumes = new AList <FsVolumeImpl>();

            for (int i = 0; i < 3; i++)
            {
                FilePath curDir = new FilePath(baseDir, "nextvolume-" + i);
                curDir.Mkdirs();
                FsVolumeImpl volume = new FsVolumeImpl(dataset, "storage-id", curDir, conf, StorageType
                                                       .Default);
                volume.SetCapacityForTesting(1024 * 1024 * 1024);
                volumes.AddItem(volume);
                volumeList.AddVolume(volume.ObtainReference());
            }
            // Close the second volume.
            volumes[1].CloseAndWait();
            for (int i_1 = 0; i_1 < 10; i_1++)
            {
                using (FsVolumeReference @ref = volumeList.GetNextVolume(StorageType.Default, 128
                                                                         ))
                {
                    // volume No.2 will not be chosen.
                    Assert.AssertNotEquals(@ref.GetVolume(), volumes[1]);
                }
            }
        }
Пример #2
0
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestChangeVolumeWithRunningCheckDirs()
        {
            RoundRobinVolumeChoosingPolicy <FsVolumeImpl> blockChooser = new RoundRobinVolumeChoosingPolicy
                                                                         <FsVolumeImpl>();

            conf.SetLong(DFSConfigKeys.DfsDatanodeScanPeriodHoursKey, -1);
            BlockScanner blockScanner = new BlockScanner(datanode, conf);
            FsVolumeList volumeList   = new FsVolumeList(Sharpen.Collections.EmptyList <VolumeFailureInfo
                                                                                        >(), blockScanner, blockChooser);
            IList <FsVolumeImpl> oldVolumes = new AList <FsVolumeImpl>();
            // Initialize FsVolumeList with 5 mock volumes.
            int NumVolumes = 5;

            for (int i = 0; i < NumVolumes; i++)
            {
                FsVolumeImpl volume = Org.Mockito.Mockito.Mock <FsVolumeImpl>();
                oldVolumes.AddItem(volume);
                Org.Mockito.Mockito.When(volume.GetBasePath()).ThenReturn("data" + i);
                FsVolumeReference @ref = Org.Mockito.Mockito.Mock <FsVolumeReference>();
                Org.Mockito.Mockito.When(@ref.GetVolume()).ThenReturn(volume);
                volumeList.AddVolume(@ref);
            }
            // When call checkDirs() on the 2nd volume, anther "thread" removes the 5th
            // volume and add another volume. It does not affect checkDirs() running.
            FsVolumeImpl      newVolume = Org.Mockito.Mockito.Mock <FsVolumeImpl>();
            FsVolumeReference newRef    = Org.Mockito.Mockito.Mock <FsVolumeReference>();

            Org.Mockito.Mockito.When(newRef.GetVolume()).ThenReturn(newVolume);
            Org.Mockito.Mockito.When(newVolume.GetBasePath()).ThenReturn("data4");
            FsVolumeImpl blockedVolume = volumeList.GetVolumes()[1];

            Org.Mockito.Mockito.DoAnswer(new _Answer_295(volumeList, newRef)).When(blockedVolume
                                                                                   ).CheckDirs();
            FsVolumeImpl brokenVolume = volumeList.GetVolumes()[2];

            Org.Mockito.Mockito.DoThrow(new DiskChecker.DiskErrorException("broken")).When(brokenVolume
                                                                                           ).CheckDirs();
            volumeList.CheckDirs();
            // Since FsVolumeImpl#checkDirs() get a snapshot of the list of volumes
            // before running removeVolume(), it is supposed to run checkDirs() on all
            // the old volumes.
            foreach (FsVolumeImpl volume_1 in oldVolumes)
            {
                Org.Mockito.Mockito.Verify(volume_1).CheckDirs();
            }
            // New volume is not visible to checkDirs() process.
            Org.Mockito.Mockito.Verify(newVolume, Org.Mockito.Mockito.Never()).CheckDirs();
            NUnit.Framework.Assert.IsTrue(volumeList.GetVolumes().Contains(newVolume));
            NUnit.Framework.Assert.IsFalse(volumeList.GetVolumes().Contains(brokenVolume));
            NUnit.Framework.Assert.AreEqual(NumVolumes - 1, volumeList.GetVolumes().Count);
        }
Пример #3
0
        public virtual void TestCheckDirsWithClosedVolume()
        {
            FsVolumeList volumeList = new FsVolumeList(Sharpen.Collections.EmptyList <VolumeFailureInfo
                                                                                      >(), blockScanner, blockChooser);
            IList <FsVolumeImpl> volumes = new AList <FsVolumeImpl>();

            for (int i = 0; i < 3; i++)
            {
                FilePath curDir = new FilePath(baseDir, "volume-" + i);
                curDir.Mkdirs();
                FsVolumeImpl volume = new FsVolumeImpl(dataset, "storage-id", curDir, conf, StorageType
                                                       .Default);
                volumes.AddItem(volume);
                volumeList.AddVolume(volume.ObtainReference());
            }
            // Close the 2nd volume.
            volumes[1].CloseAndWait();
            // checkDirs() should ignore the 2nd volume since it is closed.
            volumeList.CheckDirs();
        }
Пример #4
0
        public virtual void TestReleaseVolumeRefIfNoBlockScanner()
        {
            FsVolumeList volumeList = new FsVolumeList(Sharpen.Collections.EmptyList <VolumeFailureInfo
                                                                                      >(), null, blockChooser);
            FilePath volDir = new FilePath(baseDir, "volume-0");

            volDir.Mkdirs();
            FsVolumeImpl volume = new FsVolumeImpl(dataset, "storage-id", volDir, conf, StorageType
                                                   .Default);
            FsVolumeReference @ref = volume.ObtainReference();

            volumeList.AddVolume(@ref);
            try
            {
                @ref.Close();
                NUnit.Framework.Assert.Fail("Should throw exception because the reference is closed in "
                                            + "VolumeList#addVolume().");
            }
            catch (InvalidOperationException)
            {
            }
        }
Пример #5
0
 public _Answer_295(FsVolumeList volumeList, FsVolumeReference newRef)
 {
     this.volumeList = volumeList;
     this.newRef     = newRef;
 }