Skip to content

Commit

Permalink
Fixed merge
Browse files Browse the repository at this point in the history
Signed-off-by: Arjun-Sharma1 <arjun.a.sharma@ibm.com>
  • Loading branch information
Arjun-Sharma1 committed Oct 30, 2017
1 parent af1f5d4 commit 086172f
Show file tree
Hide file tree
Showing 23 changed files with 272 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.junit.Assert.assertThat;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.everyItem;
import java.util.Set;

import javax.inject.Inject;
Expand Down Expand Up @@ -67,17 +69,16 @@ static Archive<?> createTestArchive() {
@Test
@InSequence(1)
public void countedMethodsNotCalledYet() {
Assert.assertTrue("Counters are not registered correctly", registry.getCounters().keySet().containsAll(COUNTER_NAMES));

assertThat("Counters are not registered correctly", registry.getCounters().keySet(), is(equalTo(COUNTER_NAMES)));
// Make sure that the counters haven't been incremented
assertThat("Counter counts are incorrect", registry.getCounters().values(), hasItem(Matchers.<Counter> hasProperty("count", equalTo(0L))));
assertThat("Counter counts are incorrect", registry.getCounters().values(), everyItem(Matchers.<Counter>hasProperty("count", equalTo(0L))));
}

@Test
@InSequence(2)
public void callCountedMethodsOnce() {
Assert.assertTrue("Counters are not registered correctly", registry.getCounters().keySet().containsAll(COUNTER_NAMES));

assertThat("Counters are not registered correctly", registry.getCounters().keySet(), is(equalTo(COUNTER_NAMES)));
// Call the counted methods and assert they're back to zero
bean.countedMethodOne();
bean.countedMethodTwo();
Expand All @@ -86,6 +87,6 @@ public void callCountedMethodsOnce() {
bean.countedMethodPackagedPrivate();

// Make sure that the counters are back to zero
assertThat("Counter counts are incorrect", registry.getCounters().values(), hasItem(Matchers.<Counter> hasProperty("count", equalTo(0L))));
assertThat("Counter counts are incorrect", registry.getCounters().values(), everyItem(Matchers.<Counter>hasProperty("count", equalTo(0L))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

import java.util.Arrays;
import java.util.Set;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import javax.inject.Inject;

import org.eclipse.microprofile.metrics.MetricRegistry;
Expand Down Expand Up @@ -64,6 +65,6 @@ public static Archive<?> createTestArchive() {

@Test
public void metricMethodsWithDefaultNamingConvention() {
Assert.assertTrue("Metrics are not registered correctly", registry.getMetrics().keySet().containsAll(metricNames()));
assertThat("Metrics are not registered correctly", registry.getMetrics().keySet(), is(equalTo(metricNames())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void gaugesCalledWithDefaultValues() {
@Test
@InSequence(2)
public void callGaugesAfterSetterCalls() {
Assert.assertThat("Gauges are not registered correctly", registry.getGauges(), allOf(hasKey(PARENT_GAUGE_NAME), hasKey(CHILD_GAUGE_NAME)));
assertThat("Gauges are not registered correctly", registry.getGauges(), allOf(hasKey(PARENT_GAUGE_NAME), hasKey(CHILD_GAUGE_NAME)));
@SuppressWarnings("unchecked")
Gauge<Long> parentGauge = registry.getGauges().get(PARENT_GAUGE_NAME);
@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
package io.astefanutti.metrics.cdi.se;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.everyItem;

import static org.junit.Assert.assertThat;

import java.util.Set;
Expand All @@ -33,7 +35,6 @@
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

Expand Down Expand Up @@ -69,16 +70,16 @@ static Archive<?> createTestArchive() {
@Test
@InSequence(1)
public void timedMethodsNotCalledYet() {
Assert.assertTrue("Timers are not registered correctly", registry.getTimers().keySet().containsAll(absoluteMetricNames()));
assertThat("Timers are not registered correctly", registry.getTimers().keySet(), is(equalTo(absoluteMetricNames())));

// Make sure that all the timers haven't been called yet
assertThat("Timer counts are incorrect", registry.getTimers().values(), hasItem(Matchers.<Timer>hasProperty("count", equalTo(0L))));
assertThat("Timer counts are incorrect", registry.getTimers().values(), everyItem(Matchers.<Timer>hasProperty("count", equalTo(0L))));
}

@Test
@InSequence(2)
public void callTimedMethodsOnce() {
Assert.assertTrue("Timers are not registered correctly", registry.getTimers().keySet().containsAll(absoluteMetricNames()));
assertThat("Timers are not registered correctly", registry.getTimers().keySet(), is(equalTo(absoluteMetricNames())));

// Call the timed methods and assert they've all been timed once
bean.publicTimedMethod();
Expand All @@ -91,6 +92,6 @@ public void callTimedMethodsOnce() {
bean.timedMethodProtected();
bean.timedMethodPackagedPrivate();

assertThat("Timer counts are incorrect", registry.getTimers().values(), hasItem(Matchers.<Timer>hasProperty("count", equalTo(1L))));
assertThat("Timer counts are incorrect", registry.getTimers().values(), everyItem(Matchers.<Timer>hasProperty("count", equalTo(1L))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ public class MeterInjectionBeanTest {
static Archive<?> createTestArchive() {
return ShrinkWrap.create(JavaArchive.class)
// Test bean
.addClass(MeteredMethodBean.class)
.addClass(MeteredMethodBean2.class)
// Bean archive deployment descriptor
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}

@Inject
private MeteredMethodBean bean;
private MeteredMethodBean2 bean;

@Inject
@Metric(absolute = true, name = "io.astefanutti.metrics.cdi.se.MeteredMethodBean.meteredMethod")
@Metric(absolute = true, name = "io.astefanutti.metrics.cdi.se.MeteredMethodBean2.meteredMethod")
private Meter meter;

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,22 @@ static Archive<?> createTestArchive() {
@Test
@InSequence(1)
public void meteredMethodsNotCalledYet() {
Assert.assertTrue("Meters are not registered correctly", registry.getMeters().keySet().containsAll(METER_NAMES));
assertThat("Meters are not registered correctly", registry.getMeters().keySet(), is(equalTo(METER_NAMES)));

assertThat("Constructor meter count is incorrect", registry.getMeters().get(CONSTRUCTOR_METER_NAME).getCount(),
assertThat("Constructor meter count is incorrect", registry.getMeters().get(CONSTRUCTOR_METER_NAME).getCount(),
is(equalTo(CONSTRUCTOR_COUNT.incrementAndGet())));

// Make sure that the method meters haven't been marked yet
assertThat("Method meter counts are incorrect", registry.getMeters(METHOD_METERS).values(),
everyItem(Matchers.<Meter> hasProperty("count", equalTo(METHOD_COUNT.get()))));
assertThat("Method meter counts are incorrect", registry.getMeters(METHOD_METERS).values(),
everyItem(Matchers.<Meter>hasProperty("count", equalTo(METHOD_COUNT.get()))));

}

@Test
@InSequence(2)
public void callMeteredMethodsOnce() {
Assert.assertTrue("Meters are not registered correctly", registry.getMeters().keySet().containsAll(METER_NAMES));

assertThat("Meters are not registered correctly", registry.getMeters().keySet(), is(equalTo(METER_NAMES)));
assertThat("Constructor meter count is incorrect", registry.getMeters().get(CONSTRUCTOR_METER_NAME).getCount(),
is(equalTo(CONSTRUCTOR_COUNT.incrementAndGet())));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import org.eclipse.microprofile.metrics.annotation.Metered;

public class MeteredMethodBean {
public class MeteredMethodBean1 {

@Metered(name = "meteredMethod")
public void meteredMethod() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright © 2013 Antonin Stefanutti (antonin.stefanutti@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.astefanutti.metrics.cdi.se;

import org.eclipse.microprofile.metrics.annotation.Metered;

public class MeteredMethodBean2 {

@Metered(name = "meteredMethod")
public void meteredMethod() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright © 2013 Antonin Stefanutti (antonin.stefanutti@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.astefanutti.metrics.cdi.se;

import org.eclipse.microprofile.metrics.annotation.Metered;

public class MeteredMethodBean3 {

@Metered(name = "meteredMethod")
public void meteredMethod() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
@RunWith(Arquillian.class)
public class MeteredMethodBeanTest {

private final static String METER_NAME = MetricRegistry.name(MeteredMethodBean.class, "meteredMethod");
private final static String METER_NAME = MetricRegistry.name(MeteredMethodBean1.class, "meteredMethod");

private final static AtomicLong METER_COUNT = new AtomicLong();

@Deployment
static Archive<?> createTestArchive() {
return ShrinkWrap.create(JavaArchive.class)
// Test bean
.addClass(MeteredMethodBean.class)
.addClass(MeteredMethodBean1.class)
// Bean archive deployment descriptor
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
Expand All @@ -58,7 +58,7 @@ static Archive<?> createTestArchive() {
private MetricRegistry registry;

@Inject
private MeteredMethodBean bean;
private MeteredMethodBean1 bean;

@Test
@InSequence(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static Archive<?> createTestArchive() {
@Test
@InSequence(1)
public void countedMethodsNotCalledYet() {
Assert.assertTrue("Counters are not registered correctly", registry.getCounters().keySet().containsAll(COUNTER_NAMES));
assertThat("Counters are not registered correctly", registry.getCounters().keySet(), is(equalTo(COUNTER_NAMES)));

assertThat("Constructor timer count is incorrect", registry.getCounters().get(CONSTRUCTOR_COUNTER_NAME).getCount(),
is(equalTo(CONSTRUCTOR_COUNT.incrementAndGet())));
Expand All @@ -99,8 +99,8 @@ public void countedMethodsNotCalledYet() {
@Test
@InSequence(2)
public void callCountedMethodsOnce() {
Assert.assertTrue("Counters are not registered correctly", registry.getCounters().keySet().containsAll(COUNTER_NAMES));

assertThat("Counters are not registered correctly", registry.getCounters().keySet(), is(equalTo(COUNTER_NAMES)));
assertThat("Constructor timer count is incorrect", registry.getCounters().get(CONSTRUCTOR_COUNTER_NAME).getCount(),
is(equalTo(CONSTRUCTOR_COUNT.incrementAndGet())));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ public void instantiateApplicationScopedBean() {
@Test
@InSequence(1)
public void metricsMethodNotCalledYet() {
Assert.assertTrue("Metrics are not registered correctly", registry.getMetrics().keySet().containsAll(absoluteMetricNames()));
assertThat("Metrics are not registered correctly", registry.getMetrics().keySet(), is(equalTo(absoluteMetricNames())));
}

@Test
@InSequence(2)
public void callMetricsMethodOnce() {
Assert.assertTrue("Metrics are not registered correctly", registry.getMetrics().keySet().containsAll(absoluteMetricNames()));
assertThat("Metrics are not registered correctly", registry.getMetrics().keySet(), is(equalTo(absoluteMetricNames())));

// Call the monitored method and assert it's been instrumented
bean.metricsMethod();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public void instantiateApplicationScopedBean() {
@Test
@InSequence(1)
public void timedMethodsNotCalledYet() {
Assert.assertTrue("Timers are not registered correctly", registry.getTimers().keySet().containsAll(TIMER_NAMES));

assertThat("Timers are not registered correctly", registry.getTimers().keySet(), is(equalTo(TIMER_NAMES)));
assertThat("Constructor timer count is incorrect", registry.getTimers().get(CONSTRUCTOR_TIMER_NAME).getCount(), is(equalTo(1L)));

// Make sure that the method timers haven't been timed yet
Expand All @@ -105,8 +105,8 @@ public void timedMethodsNotCalledYet() {
@Test
@InSequence(2)
public void callTimedMethodsOnce() {
Assert.assertTrue("Timers are not registered correctly", registry.getTimers().keySet().containsAll(TIMER_NAMES));

assertThat("Timers are not registered correctly", registry.getTimers().keySet(), is(equalTo(TIMER_NAMES)));
assertThat("Constructor timer count is incorrect", registry.getTimers().get(CONSTRUCTOR_TIMER_NAME).getCount(), is(equalTo(1L)));

// Call the timed methods and assert they've been timed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import org.eclipse.microprofile.metrics.annotation.Timed;

public class TimedMethodBean {
public class TimedMethodBean1 {

@Timed(name = "timedMethod")
public void timedMethod() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright © 2013 Antonin Stefanutti (antonin.stefanutti@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.astefanutti.metrics.cdi.se;

import org.eclipse.microprofile.metrics.annotation.Timed;

public class TimedMethodBean2 {

@Timed(name = "timedMethod")
public void timedMethod() {

}

public void selfInvocationTimedMethod() {
timedMethod();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright © 2013 Antonin Stefanutti (antonin.stefanutti@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.astefanutti.metrics.cdi.se;

import org.eclipse.microprofile.metrics.annotation.Timed;

public class TimedMethodBean3 {

@Timed(name = "timedMethod")
public void timedMethod() {

}

public void selfInvocationTimedMethod() {
timedMethod();
}
}
Loading

0 comments on commit 086172f

Please sign in to comment.