Ejemplo n.º 1
0
        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])))));
            }
        }
Ejemplo n.º 2
0
        /// <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\""
                                                                                     ));
        }