Example #1
0
        public virtual void TestNameNode()
        {
            int numDatanodes = 2;

            cluster = new MiniDFSCluster.Builder(config).NumDataNodes(numDatanodes).Build();
            cluster.WaitActive();
            WriteFile(cluster.GetFileSystem(), new Path("/test1"), 2);
            JMXGet jmx         = new JMXGet();
            string serviceName = "NameNode";

            jmx.SetService(serviceName);
            jmx.Init();
            // default lists namenode mbeans only
            NUnit.Framework.Assert.IsTrue("error printAllValues", CheckPrintAllValues(jmx));
            //get some data from different source
            NUnit.Framework.Assert.AreEqual(numDatanodes, System.Convert.ToInt32(jmx.GetValue
                                                                                     ("NumLiveDataNodes")));
            MetricsAsserts.AssertGauge("CorruptBlocks", long.Parse(jmx.GetValue("CorruptBlocks"
                                                                                )), MetricsAsserts.GetMetrics("FSNamesystem"));
            NUnit.Framework.Assert.AreEqual(numDatanodes, System.Convert.ToInt32(jmx.GetValue
                                                                                     ("NumOpenConnections")));
            cluster.Shutdown();
            MBeanServerConnection    mbsc  = ManagementFactory.GetPlatformMBeanServer();
            ObjectName               query = new ObjectName("Hadoop:service=" + serviceName + ",*");
            ICollection <ObjectName> names = mbsc.QueryNames(query, null);

            NUnit.Framework.Assert.IsTrue("No beans should be registered for " + serviceName,
                                          names.IsEmpty());
        }
Example #2
0
        /// <exception cref="System.Exception"/>
        private JMXGet InitJMX()
        {
            JMXGet jmx = new JMXGet();

            jmx.SetService(JmxServiceName);
            jmx.Init();
            return(jmx);
        }
Example #3
0
        /// <summary>
        /// If ramDiskStorageLimit is &gt;=0, then RAM_DISK capacity is artificially
        /// capped.
        /// </summary>
        /// <remarks>
        /// If ramDiskStorageLimit is &gt;=0, then RAM_DISK capacity is artificially
        /// capped. If ramDiskStorageLimit &lt; 0 then it is ignored.
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        protected internal void StartUpCluster(bool hasTransientStorage, int ramDiskReplicaCapacity
                                               , bool useSCR, bool useLegacyBlockReaderLocal)
        {
            Configuration conf = new Configuration();

            conf.SetLong(DfsBlockSizeKey, BlockSize);
            conf.SetInt(DfsNamenodeLazyPersistFileScrubIntervalSec, LazyWriteFileScrubberIntervalSec
                        );
            conf.SetLong(DfsHeartbeatIntervalKey, HeartbeatIntervalSec);
            conf.SetInt(DfsNamenodeHeartbeatRecheckIntervalKey, HeartbeatRecheckIntervalMsec);
            conf.SetInt(DfsDatanodeLazyWriterIntervalSec, LazyWriterIntervalSec);
            conf.SetInt(DfsDatanodeRamDiskLowWatermarkBytes, EvictionLowWatermark * BlockSize
                        );
            if (useSCR)
            {
                conf.SetBoolean(DfsClientReadShortcircuitKey, true);
                // Do not share a client context across tests.
                conf.Set(DfsClientContext, UUID.RandomUUID().ToString());
                if (useLegacyBlockReaderLocal)
                {
                    conf.SetBoolean(DfsClientUseLegacyBlockreaderlocal, true);
                    conf.Set(DfsBlockLocalPathAccessUserKey, UserGroupInformation.GetCurrentUser().GetShortUserName
                                 ());
                }
                else
                {
                    sockDir = new TemporarySocketDirectory();
                    conf.Set(DfsDomainSocketPathKey, new FilePath(sockDir.GetDir(), this.GetType().Name
                                                                  + "._PORT.sock").GetAbsolutePath());
                }
            }
            long[] capacities = null;
            if (hasTransientStorage && ramDiskReplicaCapacity >= 0)
            {
                // Convert replica count to byte count, add some delta for .meta and
                // VERSION files.
                long ramDiskStorageLimit = ((long)ramDiskReplicaCapacity * BlockSize) + (BlockSize
                                                                                         - 1);
                capacities = new long[] { ramDiskStorageLimit, -1 };
            }
            cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(ReplFactor).StorageCapacities
                          (capacities).StorageTypes(hasTransientStorage ? new StorageType[] { StorageType.
                                                                                              RamDisk, StorageType.Default } : null).Build();
            fs     = cluster.GetFileSystem();
            client = fs.GetClient();
            try
            {
                jmx = InitJMX();
            }
            catch (Exception e)
            {
                NUnit.Framework.Assert.Fail("Failed initialize JMX for testing: " + e);
            }
            Log.Info("Cluster startup complete");
        }
Example #4
0
 private static void ExpectJMXGetExit(string[] args)
 {
     try
     {
         JMXGet.Main(args);
         NUnit.Framework.Assert.Fail("should call exit");
     }
     catch (ExitUtil.ExitException)
     {
         ExitUtil.ResetFirstExitException();
     }
     catch (Exception ex)
     {
         NUnit.Framework.Assert.Fail("expectJMXGetExit ex error " + ex);
     }
 }
Example #5
0
        /// <exception cref="System.Exception"/>
        private static bool CheckPrintAllValues(JMXGet jmx)
        {
            int size = 0;

            byte[]            bytes   = null;
            string            pattern = "List of all the available keys:";
            PipedOutputStream pipeOut = new PipedOutputStream();
            PipedInputStream  pipeIn  = new PipedInputStream(pipeOut);

            Runtime.SetErr(new TextWriter(pipeOut));
            jmx.PrintAllValues();
            if ((size = pipeIn.Available()) != 0)
            {
                bytes = new byte[size];
                pipeIn.Read(bytes, 0, bytes.Length);
            }
            pipeOut.Close();
            pipeIn.Close();
            return(bytes != null?Sharpen.Runtime.GetStringForBytes(bytes).Contains(pattern)
                       : false);
        }
Example #6
0
        public virtual void TestDataNode()
        {
            int numDatanodes = 2;

            cluster = new MiniDFSCluster.Builder(config).NumDataNodes(numDatanodes).Build();
            cluster.WaitActive();
            WriteFile(cluster.GetFileSystem(), new Path("/test"), 2);
            JMXGet jmx         = new JMXGet();
            string serviceName = "DataNode";

            jmx.SetService(serviceName);
            jmx.Init();
            NUnit.Framework.Assert.AreEqual(fileSize, System.Convert.ToInt32(jmx.GetValue("BytesWritten"
                                                                                          )));
            cluster.Shutdown();
            MBeanServerConnection    mbsc  = ManagementFactory.GetPlatformMBeanServer();
            ObjectName               query = new ObjectName("Hadoop:service=" + serviceName + ",*");
            ICollection <ObjectName> names = mbsc.QueryNames(query, null);

            NUnit.Framework.Assert.IsTrue("No beans should be registered for " + serviceName,
                                          names.IsEmpty());
        }
Example #7
0
 public virtual void ShutDownCluster()
 {
     // Dump all RamDisk JMX metrics before shutdown the cluster
     PrintRamDiskJMXMetrics();
     if (fs != null)
     {
         fs.Close();
         fs     = null;
         client = null;
     }
     if (cluster != null)
     {
         cluster.ShutdownDataNodes();
         cluster.Shutdown();
         cluster = null;
     }
     if (jmx != null)
     {
         jmx = null;
     }
     IOUtils.CloseQuietly(sockDir);
     sockDir = null;
 }