Exemple #1
0
        public virtual void Sampler()
        {
            long[] value = new long[1];
            Instrumentation.Variable <long> var     = new _Variable_238(value);
            InstrumentationService.Sampler  sampler = new InstrumentationService.Sampler();
            sampler.Init(4, var);
            NUnit.Framework.Assert.AreEqual(sampler.GetRate(), 0f, 0.0001);
            sampler.Sample();
            NUnit.Framework.Assert.AreEqual(sampler.GetRate(), 0f, 0.0001);
            value[0] = 1;
            sampler.Sample();
            NUnit.Framework.Assert.AreEqual(sampler.GetRate(), (0d + 1) / 2, 0.0001);
            value[0] = 2;
            sampler.Sample();
            NUnit.Framework.Assert.AreEqual(sampler.GetRate(), (0d + 1 + 2) / 3, 0.0001);
            value[0] = 3;
            sampler.Sample();
            NUnit.Framework.Assert.AreEqual(sampler.GetRate(), (0d + 1 + 2 + 3) / 4, 0.0001);
            value[0] = 4;
            sampler.Sample();
            NUnit.Framework.Assert.AreEqual(sampler.GetRate(), (4d + 1 + 2 + 3) / 4, 0.0001);
            JSONObject json = (JSONObject) new JSONParser().Parse(sampler.ToJSONString());

            NUnit.Framework.Assert.AreEqual(json.Count, 2);
            NUnit.Framework.Assert.AreEqual(json["sampler"], sampler.GetRate());
            NUnit.Framework.Assert.AreEqual(json["size"], 4L);
            StringWriter writer = new StringWriter();

            sampler.WriteJSONString(writer);
            writer.Close();
            json = (JSONObject) new JSONParser().Parse(writer.ToString());
            NUnit.Framework.Assert.AreEqual(json.Count, 2);
            NUnit.Framework.Assert.AreEqual(json["sampler"], sampler.GetRate());
            NUnit.Framework.Assert.AreEqual(json["size"], 4L);
        }
Exemple #2
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();
        }