Esempio n. 1
0
        public virtual void Sampling()
        {
            string dir      = TestDirHelper.GetTestDir().GetAbsolutePath();
            string services = StringUtils.Join(",", Arrays.AsList(typeof(InstrumentationService
                                                                         ).FullName, typeof(SchedulerService).FullName));
            Configuration conf = new Configuration(false);

            conf.Set("server.services", services);
            Org.Apache.Hadoop.Lib.Server.Server server = new Org.Apache.Hadoop.Lib.Server.Server
                                                             ("server", dir, dir, dir, dir, conf);
            server.Init();
            Org.Apache.Hadoop.Lib.Service.Instrumentation instrumentation = server.Get <Org.Apache.Hadoop.Lib.Service.Instrumentation
                                                                                        >();
            AtomicInteger count = new AtomicInteger();

            Instrumentation.Variable <long> varToSample = new _Variable_389(count);
            instrumentation.AddSampler("g", "s", 10, varToSample);
            Sleep(2000);
            int i = count.Get();

            NUnit.Framework.Assert.IsTrue(i > 0);
            IDictionary <string, IDictionary <string, object> > snapshot = instrumentation.GetSnapshot
                                                                               ();
            IDictionary <string, IDictionary <string, object> > samplers = (IDictionary <string,
                                                                                         IDictionary <string, object> >)snapshot["samplers"];

            InstrumentationService.Sampler sampler = (InstrumentationService.Sampler)samplers
                                                     ["g"]["s"];
            NUnit.Framework.Assert.IsTrue(sampler.GetRate() > 0);
            server.Destroy();
        }
Esempio n. 2
0
        public virtual void Service()
        {
            string dir      = TestDirHelper.GetTestDir().GetAbsolutePath();
            string services = StringUtils.Join(",", Arrays.AsList(typeof(InstrumentationService
                                                                         ).FullName));
            Configuration conf = new Configuration(false);

            conf.Set("server.services", services);
            Org.Apache.Hadoop.Lib.Server.Server server = new Org.Apache.Hadoop.Lib.Server.Server
                                                             ("server", dir, dir, dir, dir, conf);
            server.Init();
            Org.Apache.Hadoop.Lib.Service.Instrumentation instrumentation = server.Get <Org.Apache.Hadoop.Lib.Service.Instrumentation
                                                                                        >();
            NUnit.Framework.Assert.IsNotNull(instrumentation);
            instrumentation.Incr("g", "c", 1);
            instrumentation.Incr("g", "c", 2);
            instrumentation.Incr("g", "c1", 2);
            Instrumentation.Cron cron = instrumentation.CreateCron();
            cron.Start();
            Sleep(100);
            cron.Stop();
            instrumentation.AddCron("g", "t", cron);
            cron = instrumentation.CreateCron();
            cron.Start();
            Sleep(200);
            cron.Stop();
            instrumentation.AddCron("g", "t", cron);
            Instrumentation.Variable <string> var = new _Variable_329();
            instrumentation.AddVariable("g", "v", var);
            Instrumentation.Variable <long> varToSample = new _Variable_337();
            instrumentation.AddSampler("g", "s", 10, varToSample);
            IDictionary <string, object> snapshot = instrumentation.GetSnapshot();

            NUnit.Framework.Assert.IsNotNull(snapshot["os-env"]);
            NUnit.Framework.Assert.IsNotNull(snapshot["sys-props"]);
            NUnit.Framework.Assert.IsNotNull(snapshot["jvm"]);
            NUnit.Framework.Assert.IsNotNull(snapshot["counters"]);
            NUnit.Framework.Assert.IsNotNull(snapshot["timers"]);
            NUnit.Framework.Assert.IsNotNull(snapshot["variables"]);
            NUnit.Framework.Assert.IsNotNull(snapshot["samplers"]);
            NUnit.Framework.Assert.IsNotNull(((IDictionary <string, string>)snapshot["os-env"]
                                              )["PATH"]);
            NUnit.Framework.Assert.IsNotNull(((IDictionary <string, string>)snapshot["sys-props"
                                              ])["java.version"]);
            NUnit.Framework.Assert.IsNotNull(((IDictionary <string, object>)snapshot["jvm"])["free.memory"
                                             ]);
            NUnit.Framework.Assert.IsNotNull(((IDictionary <string, object>)snapshot["jvm"])["max.memory"
                                             ]);
            NUnit.Framework.Assert.IsNotNull(((IDictionary <string, object>)snapshot["jvm"])["total.memory"
                                             ]);
            NUnit.Framework.Assert.IsNotNull(((IDictionary <string, IDictionary <string, object
                                                                                 > >)snapshot["counters"])["g"]);
            NUnit.Framework.Assert.IsNotNull(((IDictionary <string, IDictionary <string, object
                                                                                 > >)snapshot["timers"])["g"]);
            NUnit.Framework.Assert.IsNotNull(((IDictionary <string, IDictionary <string, object
                                                                                 > >)snapshot["variables"])["g"]);
            NUnit.Framework.Assert.IsNotNull(((IDictionary <string, IDictionary <string, object
                                                                                 > >)snapshot["samplers"])["g"]);
            NUnit.Framework.Assert.IsNotNull(((IDictionary <string, IDictionary <string, object
                                                                                 > >)snapshot["counters"])["g"]["c"]);
            NUnit.Framework.Assert.IsNotNull(((IDictionary <string, IDictionary <string, object
                                                                                 > >)snapshot["counters"])["g"]["c1"]);
            NUnit.Framework.Assert.IsNotNull(((IDictionary <string, IDictionary <string, object
                                                                                 > >)snapshot["timers"])["g"]["t"]);
            NUnit.Framework.Assert.IsNotNull(((IDictionary <string, IDictionary <string, object
                                                                                 > >)snapshot["variables"])["g"]["v"]);
            NUnit.Framework.Assert.IsNotNull(((IDictionary <string, IDictionary <string, object
                                                                                 > >)snapshot["samplers"])["g"]["s"]);
            StringWriter writer = new StringWriter();

            JSONObject.WriteJSONString(snapshot, writer);
            writer.Close();
            server.Destroy();
        }