Exemplo n.º 1
0
        // List containing nc1 and nc2.
        /// <summary>
        /// Initializes, for testing, two NoEmitMetricsContext's, and adds one value
        /// to the first of them.
        /// </summary>
        /// <exception cref="System.IO.IOException"/>
        protected override void SetUp()
        {
            nc1 = new NoEmitMetricsContext();
            nc1.Init("test1", ContextFactory.GetFactory());
            nc2 = new NoEmitMetricsContext();
            nc2.Init("test2", ContextFactory.GetFactory());
            contexts = new AList <MetricsContext>();
            contexts.AddItem(nc1);
            contexts.AddItem(nc2);
            MetricsRecord r = nc1.CreateRecord("testRecord");

            r.SetTag("testTag1", "testTagValue1");
            r.SetTag("testTag2", "testTagValue2");
            r.SetMetric("testMetric1", 1);
            r.SetMetric("testMetric2", 33);
            r.Update();
            IDictionary <string, ICollection <OutputRecord> > m = nc1.GetAllRecords();

            Assert.Equal(1, m.Count);
            Assert.Equal(1, m.Values.Count);
            ICollection <OutputRecord> outputRecords = m.Values.GetEnumerator().Next();

            Assert.Equal(1, outputRecords.Count);
            outputRecord = outputRecords.GetEnumerator().Next();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Returns the named MetricsContext instance, constructing it if necessary
 /// using the factory's current configuration attributes.
 /// </summary>
 /// <remarks>
 /// Returns the named MetricsContext instance, constructing it if necessary
 /// using the factory's current configuration attributes. <p/>
 /// When constructing the instance, if the factory property
 /// <i>contextName</i>.class</code> exists,
 /// its value is taken to be the name of the class to instantiate.  Otherwise,
 /// the default is to create an instance of
 /// <code>org.apache.hadoop.metrics.spi.NullContext</code>, which is a
 /// dummy "no-op" context which will cause all metric data to be discarded.
 /// </remarks>
 /// <param name="contextName">the name of the context</param>
 /// <returns>the named MetricsContext</returns>
 /// <exception cref="System.IO.IOException"/>
 /// <exception cref="System.TypeLoadException"/>
 /// <exception cref="InstantiationException"/>
 /// <exception cref="System.MemberAccessException"/>
 public virtual MetricsContext GetContext(string refName, string contextName)
 {
     lock (this)
     {
         MetricsContext metricsContext = contextMap[refName];
         if (metricsContext == null)
         {
             string classNameAttribute = refName + ContextClassSuffix;
             string className          = (string)GetAttribute(classNameAttribute);
             if (className == null)
             {
                 className = DefaultContextClassname;
             }
             Type contextClass = Runtime.GetType(className);
             metricsContext = (MetricsContext)System.Activator.CreateInstance(contextClass);
             metricsContext.Init(contextName, this);
             contextMap[contextName] = metricsContext;
         }
         return(metricsContext);
     }
 }