@Before public void givenAnEventMetricCollector() { MockitoAnnotations.initMocks(this); Map<Object, EventCounters> perEventCounters = Maps.newHashMap(); perEventCounters.put(TOP_LEVEL_GROUP, topLevelCounter); perEventCounters.put(NESTED_GROUP, nestedCounter); collector = new EventMetricCollector(perEventCounters, newArrayList(stepMeasurementSink)); when(topLevelCounter.getEventGroupName()).thenReturn(TOP_LEVEL_GROUP); when(nestedCounter.getEventGroupName()).thenReturn(NESTED_GROUP); EventMetricCounters invocationCounter = mock(EventMetricCounters.class); when(topLevelCounter.getInvocationCounter()).thenReturn(invocationCounter); ThreadMetric threadMetric = mock(ThreadMetric.class); when(topLevelCounter.getMetricSources()).thenReturn(newArrayList(threadMetric)); when(topLevelCounter.getCounterForMetric(threadMetric)).thenReturn(topLevelMetricCounters); }
public void addMetric(ThreadMetric metric) { addMetric(metric, null); }
public void startTiming(Object eventGroup, String event) { StepMeasurements newTiming = new StepMeasurements(current, perEventCounters.get(eventGroup).getEventGroupName(), event); for (ThreadMetric metric : perEventCounters.get(eventGroup).getMetricSources()) { newTiming.addMetricInstance(new MetricMeasurement(metric, Thread.currentThread())); } current = newTiming; topLevelEvent.addFirst(eventGroup); depth++; if (top == null) { top = newTiming; } current.startAll(); }
EventMetricCounters counter = counters.getCounterForMetric(metric .getMetricSource()); if (counter != null) { counters.getInvocationCounter().incrementCounters(1);
@Test public void itShouldIncrementCountersForSingleCollectors() { collector.startTiming(TOP_LEVEL_GROUP, "topLevelEvent"); collector.stopTiming(); verify(topLevelCounter).getCounterForMetric(any(ThreadMetric.class)); verify(topLevelMetricCounters).incrementCounters(anyLong()); }
private EventCounters getCounterSet(String eventGroup) { EventMetricCounters invocationCounter = createEventMetricCounters(eventGroup, "count", "Total number of times the event was directly triggered", ONE); EventCounters counters = new EventCounters(invocationCounter, cleanName(eventGroup)); for (ThreadMetric metric : metricSuite.metrics()) { EventMetricCounters timingCounter = createEventMetricCounters(eventGroup, metric .getCounterSuffix(), metric.getDescription(), metric.getUnit()); counters.addMetric(metric, timingCounter); } return counters; }
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()); } }
public void testTotalMonitoredCounterSize() { metricFactory.registerTimeable(workflowWizardControl, "/WorkFlowWizard"); /** * This total value includes the invocation count counter, which is stored separately to the * other counters in the counter set object. So when comparing the number of counters for * each event, this should not be taken into consideration. */ Integer totalEventCounterSize = metricFactory.getNumberOfTotalEventCounters(); EventCounters wizardCounterSet = metricFactory .getCounterSetForEventGroup(workflowWizardControl); Integer numberOfMetricCounters = wizardCounterSet.numberOfTimerCounters(); assertEquals("Should be the same number of per event and total counters", --totalEventCounterSize, numberOfMetricCounters); metricFactory.registerTimeable(logonControl, "/Logon"); assertEquals( "Number of total event counters should not change after adding event", ++totalEventCounterSize, metricFactory.getNumberOfTotalEventCounters()); EventCounters logonCounterSet = metricFactory .getCounterSetForEventGroup(logonControl); assertEquals("Should be the same number of per event and total counters", --totalEventCounterSize, logonCounterSet.numberOfTimerCounters()); metricFactory.registerTimeable(attachmentControl, "/Attachments"); assertEquals( "Number of total event counters should not change after adding event", ++totalEventCounterSize, metricFactory.getNumberOfTotalEventCounters()); EventCounters attachmentCounterSet = metricFactory .getCounterSetForEventGroup(attachmentControl); assertEquals("Should be the same number of per event and total counters", --totalEventCounterSize, attachmentCounterSet.numberOfTimerCounters()); }
@Test public void itShouldNotIncrementNestedCountersForNestedCollectors() { collector.startTiming(TOP_LEVEL_GROUP, "topLevelEvent"); collector.startTiming(NESTED_GROUP, "nestedEvent"); collector.stopTiming(); collector.stopTiming(); verify(nestedCounter, never()).getCounterForMetric(any(ThreadMetric.class)); }
@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()); }