counter.incrementCounters(Math.max(metric.totalValue().getValue().longValue(), 0L)); counters.getInvocationCounter().incrementCounters(1);
private EventMetricCounters createEventMetricCounters(String beanName, String metric, String metricDescription, Unit<?> unit) { MonitoredCounter metricCounter = createMetric(beanName, metric, metricDescription + " [" + beanName + "]", unit); MonitoredCounter totalCounter; totalCounter = totalCountersAcrossEvents.get(metric); if (totalCounter == null) { totalCounter = new MonitoredCounter(getTotalMetricName(metric), metricDescription + " [TOTAL]", registry, unit); totalCountersAcrossEvents.put(metric, totalCounter); } return new EventMetricCounters(metricCounter, totalCounter); }
public void testTotalMonitoredCounterSingletons() { metricFactory.registerTimeable(logonControl, "/Logon"); metricFactory.registerTimeable(workflowWizardControl, "/WorkflowWizard"); metricFactory.registerTimeable(attachmentControl, "/Attachments"); EventCounters wizardCounterSet = metricFactory.getCounterSetForEventGroup(workflowWizardControl); EventCounters logonCounterSet = metricFactory.getCounterSetForEventGroup(logonControl); EventCounters attachmentsCounterSet = metricFactory .getCounterSetForEventGroup(attachmentControl); assertNotNull("Couldnt obtain counter set for workflow wizard event", wizardCounterSet); assertNotNull("Couldnt obtain counter set for logon event", logonCounterSet); assertNotNull("Couldnt obtain counter set for attachments event", attachmentsCounterSet); for (ThreadMetric metric : wizardCounterSet.getMetrics().keySet()) { EventMetricCounters wizardCounter = wizardCounterSet.getMetrics().get(metric); assertNotNull("Couldnt obtain wizard counter for metric " + metric.getMetricName(), wizardCounter); EventMetricCounters logonCounter = logonCounterSet.getMetrics().get(metric); assertNotNull("Couldnt obtain logon counter for metric " + metric.getMetricName(), logonCounter); EventMetricCounters attachmentsCounter = attachmentsCounterSet.getMetrics() .get(metric); assertNotNull( "Couldnt obtain attachments counter for metric " + metric.getMetricName(), attachmentsCounter); assertEquals("Total counter for metric " + metric + " is not a singleton", wizardCounter.getTotalCounter(), logonCounter.getTotalCounter()); assertEquals("Total counter for metric " + metric + " is not a singleton", logonCounter .getTotalCounter(), attachmentsCounter.getTotalCounter()); } }
@Test public void itShouldIncrementCountersForSingleCollectors() { collector.startTiming(TOP_LEVEL_GROUP, "topLevelEvent"); collector.stopTiming(); verify(topLevelCounter).getCounterForMetric(any(ThreadMetric.class)); verify(topLevelMetricCounters).incrementCounters(anyLong()); }
@Test public void itShouldIncrementTopLevelCountersForNestedCollectors() { collector.startTiming(TOP_LEVEL_GROUP, "topLevelEvent"); collector.startTiming(NESTED_GROUP, "nestedEvent"); collector.stopTiming(); collector.stopTiming(); verify(topLevelCounter).getCounterForMetric(any(ThreadMetric.class)); verify(topLevelMetricCounters).incrementCounters(anyLong()); }