Navigation Menu

Skip to content
This repository has been archived by the owner on Dec 14, 2017. It is now read-only.

Commit

Permalink
Fixed existing unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
gorzell committed Mar 21, 2012
1 parent 83b1907 commit ce346ba
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
Expand Up @@ -36,17 +36,11 @@
*/
public final class JmxMetric implements DynamicMBean {

private static final Logger LOGGER =
LoggerFactory.getLogger(JmxMetric.class);

private static final Logger LOGGER = LoggerFactory.getLogger(JmxMetric.class);
private final Metric object;

private final ObjectName name;

private final MBeanInfo beanInfo;

private final Map<String, PublishedAttribute> attrs = new HashMap<String, PublishedAttribute>();

private final MetadataMBean metadataMBean;

public JmxMetric(String registryName, MetricName metricName, Metric obj) throws Exception {
Expand All @@ -64,7 +58,7 @@ public JmxMetric(String registryName, MetricName metricName, Metric obj) throws

for (int i = 0; i < annotatedMetricAttrs.size(); ++i) {
AnnotatedMetricAttribute annotatedMetricAttribute = annotatedMetricAttrs.get(i);
PublishedAttribute attr = new PublishedAttribute(annotatedMetricAttribute);
PublishedAttribute attr = new PublishedAttribute(metricName, annotatedMetricAttribute);
Publish m = attr.getAnnotation();
builder.put(annotatedMetricAttribute.getName(), attr);
attributes[i] = attr.getValueAttributeInfo();
Expand Down
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.yammer.metrics.reporting.jmx;

import com.yammer.metrics.annotation.AnnotatedMetricAttribute;
Expand Down
Expand Up @@ -19,7 +19,7 @@ public class CounterTest {

@Before
public void setUp() throws Exception {
this.registry = new MetricsRegistry();
this.registry = new MetricsRegistry("testRegistry");
this.counter = registry.newCounter(CounterTest.class, "counter");
}

Expand Down
Expand Up @@ -21,7 +21,7 @@ public class HistogramTest {

@Before
public void setUp() throws Exception {
this.registry = new MetricsRegistry();
this.registry = new MetricsRegistry("testRegistry");
this.histogram = registry.newHistogram(HistogramTest.class, "histogram", false);
}

Expand Down
Expand Up @@ -18,7 +18,7 @@ public class MeterTest {

@Before
public void setUp() throws Exception {
this.registry = new MetricsRegistry();
this.registry = new MetricsRegistry("testRegistry");
this.meter = registry.newMeter(MeterTest.class, "things", "thing", TimeUnit.SECONDS);
}

Expand Down
Expand Up @@ -20,7 +20,7 @@ public class MetricsRegistryTest {

@Before
public void setUp() throws Exception {
this.registry = new MetricsRegistry();
this.registry = new MetricsRegistry("testRegistry");
}

@After
Expand Down Expand Up @@ -67,15 +67,15 @@ public void listenersRegisterNewMetrics() throws Exception {
TimeUnit.SECONDS);
final Timer timer = registry.newTimer(MetricsRegistryTest.class, "timer");

verify(listener).onMetricAdded(new MetricName(MetricsRegistryTest.class, "gauge"), gauge);
verify(listener).onMetricAdded(registry, new MetricName(MetricsRegistryTest.class, "gauge"), gauge);

verify(listener).onMetricAdded(new MetricName(MetricsRegistryTest.class, "counter"), counter);
verify(listener).onMetricAdded(registry, new MetricName(MetricsRegistryTest.class, "counter"), counter);

verify(listener).onMetricAdded(new MetricName(MetricsRegistryTest.class, "histogram"), histogram);
verify(listener).onMetricAdded(registry, new MetricName(MetricsRegistryTest.class, "histogram"), histogram);

verify(listener).onMetricAdded(new MetricName(MetricsRegistryTest.class, "meter"), meter);
verify(listener).onMetricAdded(registry, new MetricName(MetricsRegistryTest.class, "meter"), meter);

verify(listener).onMetricAdded(new MetricName(MetricsRegistryTest.class, "timer"), timer);
verify(listener).onMetricAdded(registry, new MetricName(MetricsRegistryTest.class, "timer"), timer);
}

@Test
Expand All @@ -89,9 +89,9 @@ public void removedListenersDoNotReceiveEvents() throws Exception {

final Counter counter2 = registry.newCounter(MetricsRegistryTest.class, "counter2");

verify(listener).onMetricAdded(new MetricName(MetricsRegistryTest.class, "counter1"), counter1);
verify(listener).onMetricAdded(registry, new MetricName(MetricsRegistryTest.class, "counter1"), counter1);

verify(listener, never()).onMetricAdded(new MetricName(MetricsRegistryTest.class, "counter2"), counter2);
verify(listener, never()).onMetricAdded(registry, new MetricName(MetricsRegistryTest.class, "counter2"), counter2);
}

@Test
Expand All @@ -105,8 +105,8 @@ public void metricsCanBeRemoved() throws Exception {
registry.removeMetric(MetricsRegistryTest.class, "counter1");

final InOrder inOrder = inOrder(listener);
inOrder.verify(listener).onMetricAdded(name, counter1);
inOrder.verify(listener).onMetricRemoved(name);
inOrder.verify(listener).onMetricAdded(registry, name, counter1);
inOrder.verify(listener).onMetricRemoved(registry, name);
}

@Test
Expand Down
Expand Up @@ -28,7 +28,7 @@ public void setUp() throws Exception {
public long tick() {
return val += 50000000;
}
});
}, "testRegistry");
this.timer = registry.newTimer(TimerTest.class, "timer");
}

Expand Down
Expand Up @@ -37,6 +37,11 @@ public void init() throws Exception {
}

protected static class TestMetricsRegistry extends MetricsRegistry {

TestMetricsRegistry() {
super("testRegistry");
}

public <T extends Metric> T add(MetricName name, T metric) {
return getOrAdd(name, metric);
}
Expand All @@ -54,7 +59,7 @@ protected <T extends Metric> void assertReporterOutput(Callable<T> action, Strin
// Assertions: first check that the line count matches then compare line by line ignoring leading and trailing whitespace
assertEquals("Line count mismatch, was:\n" + Arrays.toString(lines) + "\nexpected:\n" + Arrays
.toString(expected) + "\n", expected.length,
lines.length);
lines.length);
for (int i = 0; i < lines.length; i++) {
if (!expected[i].trim().equals(lines[i].trim())) {
System.err.println("Failure comparing line " + (1 + i));
Expand Down Expand Up @@ -155,7 +160,7 @@ void delegateToProcessor(MetricProcessor<Object> processor, MetricName name, Obj
}));
}


static Gauge<String> createGauge() throws Exception {
@SuppressWarnings("unchecked")
final Gauge<String> mock = mock(Gauge.class);
Expand Down

0 comments on commit ce346ba

Please sign in to comment.