Revision: f6a4165c3129
Author: Paul Smith <psm...@apache.org>
Date: Tue May 31 18:12:37 2011
Log: Apply patch by MarkJAconex that fixes a bug (with test) that the
nesti...
http://code.google.com/p/parfait/source/detail?r=f6a4165c3129
Revision: c6de9e0d601b
Author: Paul Smith <psm...@apache.org>
Date: Tue May 31 18:16:23 2011
Log: Add mockito dependency to this branch, tracking what trunk has,
used b...
http://code.google.com/p/parfait/source/detail?r=c6de9e0d601b
==============================================================================
Revision: f6a4165c3129
Author: Paul Smith <psm...@apache.org>
Date: Tue May 31 18:12:37 2011
Log: Apply patch by MarkJAconex that fixes a bug (with test) that the
nesting logic tracking in EventMetricCollector was buggy,
causing nested eventGroups to miss event tracking/accounting. (NOTE:
applied direct from trunk, but will not compile without adding mockito
dependencies which will come in a separate commit)
http://code.google.com/p/parfait/source/detail?r=f6a4165c3129
Added:
/parfait-core/src/test/java/com/custardsource/parfait/timing/EventMetricCollectorTest.java
Modified:
/parfait-core/src/main/java/com/custardsource/parfait/timing/EventMetricCollector.java
=======================================
--- /dev/null
+++
/parfait-core/src/test/java/com/custardsource/parfait/timing/EventMetricCollectorTest.java
Tue May 31 18:12:37 2011
@@ -0,0 +1,82 @@
+package com.custardsource.parfait.timing;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Map;
+
+import com.google.common.collect.Maps;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+public class EventMetricCollectorTest {
+
+ private static final String TOP_LEVEL_GROUP = "eventGroup1";
+ private static final String NESTED_GROUP = "eventGroup2";
+
+ private EventMetricCollector collector;
+ @Mock
+ private StepMeasurementSink stepMeasurementSink;
+ @Mock
+ private EventCounters topLevelCounter;
+ @Mock
+ private EventCounters nestedCounter;
+ @Mock
+ private EventMetricCounters topLevelMetricCounters;
+
+ @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);
+ }
+
+ @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());
+ }
+
+ @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));
+ }
+
+}
=======================================
---
/parfait-core/src/main/java/com/custardsource/parfait/timing/EventMetricCollector.java
Wed Sep 1 17:01:24 2010
+++
/parfait-core/src/main/java/com/custardsource/parfait/timing/EventMetricCollector.java
Tue May 31 18:12:37 2011
@@ -1,5 +1,7 @@
package com.custardsource.parfait.timing;
+import java.util.ArrayDeque;
+import java.util.Deque;
import java.util.List;
import java.util.Map;
@@ -24,7 +26,7 @@
* the top-level event requested by the user.
*/
private int depth = 0;
- private Object topLevelEvent;
+ private Deque<Object> topLevelEvent = new ArrayDeque<Object>();
private final Map<Object, EventCounters> perEventCounters;
private final List<StepMeasurementSink> sinks;
@@ -45,7 +47,7 @@
newTiming.addMetricInstance(new MetricMeasurement(metric,
Thread.currentThread()));
}
current = newTiming;
- topLevelEvent = eventGroup;
+ topLevelEvent.addFirst(eventGroup);
depth++;
if (top == null) {
top = newTiming;
@@ -56,14 +58,15 @@
public void stopTiming() {
current.stopAll();
depth--;
+ Object event = topLevelEvent.removeFirst();
for (StepMeasurementSink sink : sinks) {
sink.handle(current, depth);
}
- if (depth == 0 && perEventCounters.containsKey(topLevelEvent)) {
+ if (depth == 0 && perEventCounters.containsKey(event)) {
// We're at the top level, increment our event counters too
- EventCounters counters = perEventCounters.get(topLevelEvent);
+ EventCounters counters = perEventCounters.get(event);
for (MetricMeasurement metric : current.getMetricInstances()) {
EventMetricCounters counter =
counters.getCounterForMetric(metric
.getMetricSource());
==============================================================================
Revision: c6de9e0d601b
Author: Paul Smith <psm...@apache.org>
Date: Tue May 31 18:16:23 2011
Log: Add mockito dependency to this branch, tracking what trunk has,
used by previous commit on this branch for MarkJ's change
http://code.google.com/p/parfait/source/detail?r=c6de9e0d601b
Modified:
/parfait-core/pom.xml
/pom.xml
=======================================
--- /parfait-core/pom.xml Thu Mar 10 15:21:07 2011
+++ /parfait-core/pom.xml Tue May 31 18:16:23 2011
@@ -25,6 +25,11 @@
<scope>compile</scope>
</dependency>
<dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>javax.measure</groupId>
<artifactId>jsr-275</artifactId>
<version>1.0.0</version>
=======================================
--- /pom.xml Thu Mar 10 15:21:07 2011
+++ /pom.xml Tue May 31 18:16:23 2011
@@ -50,6 +50,11 @@
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.8.0</version>
+ </dependency>
</dependencies>
</dependencyManagement>
<dependencies>