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