Ejemplo n.º 1
0
        public virtual void TestDeletingBlocks()
        {
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(new HdfsConfiguration()).Build
                                         ();

            try
            {
                cluster.WaitActive();
                DataNode      dn  = cluster.GetDataNodes()[0];
                FsDatasetImpl ds  = (FsDatasetImpl)DataNodeTestUtils.GetFSDataset(dn);
                FsVolumeImpl  vol = ds.GetVolumes()[0];
                ExtendedBlock eb;
                ReplicaInfo   info;
                IList <Block> blockList = new AList <Block>();
                for (int i = 1; i <= 63; i++)
                {
                    eb   = new ExtendedBlock(Blockpool, i, 1, 1000 + i);
                    info = new FinalizedReplica(eb.GetLocalBlock(), vol, vol.GetCurrentDir().GetParentFile
                                                    ());
                    ds.volumeMap.Add(Blockpool, info);
                    info.GetBlockFile().CreateNewFile();
                    info.GetMetaFile().CreateNewFile();
                    blockList.AddItem(info);
                }
                ds.Invalidate(Blockpool, Sharpen.Collections.ToArray(blockList, new Block[0]));
                try
                {
                    Sharpen.Thread.Sleep(1000);
                }
                catch (Exception)
                {
                }
                // Nothing to do
                NUnit.Framework.Assert.IsTrue(ds.IsDeletingBlock(Blockpool, blockList[0].GetBlockId
                                                                     ()));
                blockList.Clear();
                eb   = new ExtendedBlock(Blockpool, 64, 1, 1064);
                info = new FinalizedReplica(eb.GetLocalBlock(), vol, vol.GetCurrentDir().GetParentFile
                                                ());
                ds.volumeMap.Add(Blockpool, info);
                info.GetBlockFile().CreateNewFile();
                info.GetMetaFile().CreateNewFile();
                blockList.AddItem(info);
                ds.Invalidate(Blockpool, Sharpen.Collections.ToArray(blockList, new Block[0]));
                try
                {
                    Sharpen.Thread.Sleep(1000);
                }
                catch (Exception)
                {
                }
                // Nothing to do
                NUnit.Framework.Assert.IsFalse(ds.IsDeletingBlock(Blockpool, blockList[0].GetBlockId
                                                                      ()));
            }
            finally
            {
                cluster.Shutdown();
            }
        }
Ejemplo n.º 2
0
        public virtual void SetUp()
        {
            datanode  = Org.Mockito.Mockito.Mock <DataNode>();
            storage   = Org.Mockito.Mockito.Mock <DataStorage>();
            this.conf = new Configuration();
            this.conf.SetLong(DFSConfigKeys.DfsDatanodeScanPeriodHoursKey, 0);
            DNConf dnConf = new DNConf(conf);

            Org.Mockito.Mockito.When(datanode.GetConf()).ThenReturn(conf);
            Org.Mockito.Mockito.When(datanode.GetDnConf()).ThenReturn(dnConf);
            BlockScanner disabledBlockScanner = new BlockScanner(datanode, conf);

            Org.Mockito.Mockito.When(datanode.GetBlockScanner()).ThenReturn(disabledBlockScanner
                                                                            );
            ShortCircuitRegistry shortCircuitRegistry = new ShortCircuitRegistry(conf);

            Org.Mockito.Mockito.When(datanode.GetShortCircuitRegistry()).ThenReturn(shortCircuitRegistry
                                                                                    );
            CreateStorageDirs(storage, conf, NumInitVolumes);
            dataset = new FsDatasetImpl(datanode, storage, conf);
            foreach (string bpid in BlockPoolIds)
            {
                dataset.AddBlockPool(bpid, conf);
            }
            NUnit.Framework.Assert.AreEqual(NumInitVolumes, dataset.GetVolumes().Count);
            NUnit.Framework.Assert.AreEqual(0, dataset.GetNumFailedVolumes());
        }
Ejemplo n.º 3
0
        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));
        }