public static Counters ToYarn(Counters counters) { if (counters == null) { return(null); } Counters yCntrs = recordFactory.NewRecordInstance <Counters>(); yCntrs.AddAllCounterGroups(new Dictionary <string, CounterGroup>()); foreach (CounterGroup grp in counters) { CounterGroup yGrp = recordFactory.NewRecordInstance <CounterGroup>(); yGrp.SetName(grp.GetName()); yGrp.SetDisplayName(grp.GetDisplayName()); yGrp.AddAllCounters(new Dictionary <string, Counter>()); foreach (Counter cntr in grp) { Counter yCntr = recordFactory.NewRecordInstance <Counter>(); yCntr.SetName(cntr.GetName()); yCntr.SetDisplayName(cntr.GetDisplayName()); yCntr.SetValue(cntr.GetValue()); yGrp.SetCounter(yCntr.GetName(), yCntr); } yCntrs.SetCounterGroup(yGrp.GetName(), yGrp); } return(yCntrs); }
public virtual void TestCountersIncrement() { Counters fCounters = new Counters(); Counter fCounter = fCounters.FindCounter(FrameworkCounter); fCounter.SetValue(100); Counter gCounter = fCounters.FindCounter("test", "foo"); gCounter.SetValue(200); Counters counters = new Counters(); counters.IncrAllCounters(fCounters); Counter counter; foreach (CounterGroup cg in fCounters) { CounterGroup group = counters.GetGroup(cg.GetName()); if (group.GetName().Equals("test")) { counter = counters.FindCounter("test", "foo"); NUnit.Framework.Assert.AreEqual(200, counter.GetValue()); } else { counter = counters.FindCounter(FrameworkCounter); NUnit.Framework.Assert.AreEqual(100, counter.GetValue()); } } }