org.jboss.arquillian.junit.InSequence Java Examples

The following examples show how to use org.jboss.arquillian.junit.InSequence. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MpMetricTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@RunAsClient
@InSequence(7)
public void testBaseAttributeJson() {
    Assume.assumeFalse(Boolean.getBoolean("skip.base.metric.tests"));
    Header wantJson = new Header("Accept", APPLICATION_JSON);
    
    Response resp = given().header(wantJson).get("/metrics/base/thread.max.count");
    JsonPath filteredJSONPath = new JsonPath(filterOutAppLabelJSON(resp.jsonPath().prettify()));
    ResponseBuilder responseBuilder = new ResponseBuilder();
    responseBuilder.clone(resp);
    responseBuilder.setBody(filteredJSONPath.prettify());
    resp = responseBuilder.build();
    resp.then().statusCode(200).and()
            .contentType(MpMetricTest.APPLICATION_JSON).and().body(containsString("thread.max.count;tier=integration"));
}
 
Example #2
Source File: TagsTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(3)
public void counterTagsTest() {
    
    Tag tagEarth = new Tag("planet", "earth");
    Tag tagRed = new Tag("colour", "red");
    Tag tagBlue = new Tag("colour", "blue");
    
    String counterName = "org.eclipse.microprofile.metrics.tck.TagTest.counterColour";
    
    Counter counterColour = registry.counter(counterName);
    Counter counterRed = registry.counter(counterName,tagEarth,tagRed);
    Counter counterBlue = registry.counter(counterName,tagEarth,tagBlue);
    
    MetricID counterColourMID = new MetricID(counterName);
    MetricID counterRedMID = new MetricID(counterName, tagEarth,tagRed);
    MetricID counterBlueMID = new MetricID(counterName, tagEarth,tagBlue);
    
    //check multi-dimensional metrics are registered
    assertThat("Counter is not registered correctly", registry.getCounter(counterColourMID), notNullValue());
    assertThat("Counter is not registered correctly", registry.getCounter(counterRedMID), notNullValue());
    assertThat("Counter is not registered correctly", registry.getCounter(counterBlueMID), notNullValue());
}
 
Example #3
Source File: MultipleMetricsMethodBeanTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(2)
public void callMetricsMethodOnce() {
    assertThat("Metrics are not registered correctly", registry.getMetricIDs(),
        is(equalTo(MetricsUtil.createMetricIDs(absoluteMetricNames()))));

    // Call the monitored method and assert it's been instrumented
    bean.metricsMethod();

    // Make sure that the metrics have been called
    assertThat("Counter count is incorrect", registry.getCounter(
            new MetricID(absoluteMetricName("counter"))).getCount(), is(equalTo(1L)));
    assertThat("Meter count is incorrect", registry.getMeter(
            new MetricID(absoluteMetricName("meter"))).getCount(), is(equalTo(1L)));
    assertThat("Timer count is incorrect", registry.getTimer(
            new MetricID(absoluteMetricName("timer"))).getCount(), is(equalTo(1L)));
    // Let's call the gauge at the end as Weld is intercepting the gauge
    // invocation while OWB not
    assertThat("Gauge value is incorrect", registry.getGauge(
            new MetricID(absoluteMetricName("gauge"))).getValue(), is(equalTo(1234L)));
}
 
Example #4
Source File: MpMetricTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@RunAsClient
@InSequence(31)
public void testOptionalBaseMetrics() {
    Assume.assumeFalse(Boolean.getBoolean("skip.base.metric.tests"));
    Header wantJson = new Header("Accept", APPLICATION_JSON);

    JsonPath jsonPath = given().header(wantJson).options("/metrics/base").jsonPath();

    Map<String, Object> elements = jsonPath.getMap(".");
    Map<String, MiniMeta> names = getExpectedMetadataFromXmlFile(MetricRegistry.Type.BASE);

    for (MiniMeta item : names.values()) {
        if (elements.containsKey(item.toJSONName()) && names.get(item.name).optional) {
            String prefix = names.get(item.name).name;
            String type = "'"+item.toJSONName()+"'"+".type";
            String unit= "'"+item.toJSONName()+"'"+".unit";

            given().header(wantJson).options("/metrics/base/"+prefix).then().statusCode(200)
            .body(type, equalTo(names.get(item.name).type))
            .body(unit, equalTo(names.get(item.name).unit));
        }
    }

}
 
Example #5
Source File: TagsTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(5)
public void timerTagsTest() {
    
    Tag tagEarth = new Tag("planet", "earth");
    Tag tagRed = new Tag("colour", "red");
    Tag tagBlue = new Tag("colour", "blue");
    
    String timerName = "org.eclipse.microprofile.metrics.tck.TagTest.timerColour";
    
    Timer timerColour = registry.timer(timerName);
    Timer timerRed = registry.timer(timerName,tagEarth,tagRed);
    Timer timerBlue = registry.timer(timerName,tagEarth,tagBlue);
    
    MetricID timerColourMID = new MetricID(timerName);
    MetricID timerRedMID = new MetricID(timerName, tagEarth,tagRed);
    MetricID timerBlueMID = new MetricID(timerName, tagEarth,tagBlue);
    
    //check multi-dimensional metrics are registered
    assertThat("Timer is not registered correctly", registry.getTimer(timerColourMID), notNullValue());
    assertThat("Timer is not registered correctly", registry.getTimer(timerRedMID), notNullValue());
    assertThat("Timer is not registered correctly", registry.getTimer(timerBlueMID), notNullValue());
}
 
Example #6
Source File: CounterFieldTagBeanTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(2)
public void incrementCounterTagFields() {
    Counter counterOne = registry.getCounter(counterMID);
    assertThat("Counter is not registered correctly", counterOne, notNullValue());

    Counter counterTwo = registry.getCounter(counterTwoMID);
    assertThat("Counter is not registered correctly", counterTwo, notNullValue());

    Counter counterThree = registry.getCounter(counterThreeMID);
    assertThat("Counter is not registered correctly", counterThree, notNullValue());

    // Call the increment method and assert the counter is up-to-date
    long value = Math.round(Math.random() * Long.MAX_VALUE);
    bean.incrementOne(value);

    long valueTwo = Math.round(Math.random() * Long.MAX_VALUE);
    bean.incrementTwo(valueTwo);

    long valueThree = Math.round(Math.random() * Long.MAX_VALUE);
    bean.incrementThree(valueThree);

    assertThat("Counter value is incorrect", counterOne.getCount(), is(equalTo(value)));
    assertThat("Counter value is incorrect", counterTwo.getCount(), is(equalTo(valueTwo)));
    assertThat("Counter value is incorrect", counterThree.getCount(), is(equalTo(valueThree)));
}
 
Example #7
Source File: MetricTest.java    From smallrye-graphql with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(101)
public void verifyMetricsAreUpdated() {
    SimpleTimer metricForGetQuery = metricRegistry.getSimpleTimers().get(new MetricID("mp_graphql_Query_get"));
    Assert.assertEquals("The 'get' query was called three times, this should be reflected in metric value",
            3, metricForGetQuery.getCount());
    Assert.assertTrue("Total elapsed time for query should be greater than zero",
            metricForGetQuery.getElapsedTime().toNanos() > 0);

    SimpleTimer metricForMutation = metricRegistry.getSimpleTimers().get(new MetricID("mp_graphql_Mutation_mutate"));
    Assert.assertEquals("The query was called twice, this should be reflected in metric value",
            2, metricForMutation.getCount());
    Assert.assertTrue("Total elapsed time for query should be greater than zero",
            metricForMutation.getElapsedTime().toNanos() > 0);

    SimpleTimer metricForSource = metricRegistry.getSimpleTimers().get(new MetricID("mp_graphql_Foo_description"));
    Assert.assertEquals("The get{description} query was called once, this should be reflected in metric value",
            1, metricForSource.getCount());
    Assert.assertTrue("Total elapsed time for query should be greater than zero",
            metricForSource.getElapsedTime().toNanos() > 0);
}
 
Example #8
Source File: TagsTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(2)
public void lastTagValueTest() {
    
    Tag tagColour = new Tag("colour","red");
    Tag tagColourTwo = new Tag("colour","blue");
    
    String counterName = "org.eclipse.microprofile.metrics.tck.TagTest.counter";
    Counter counter = registry.counter(counterName, tagColour, tagColourTwo);
    
    //MetricID that only has colour=blue... the last tag value to be passed in
    MetricID counterMID = new MetricID(counterName, tagColourTwo);
    
    //check the metric is registered
    assertThat("Counter is not registered correctly", registry.getCounter(counterMID), notNullValue());
}
 
Example #9
Source File: TimedMethodBeanLookupTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(3)
public void removeTimerFromRegistry() throws InterruptedException {
    // Get a contextual instance of the bean
    TimedMethodBean1 bean = instance.get();

    Timer timer = registry.getTimer(timerMID);
    assertThat("Timer is not registered correctly", timer, notNullValue());

    // Remove the timer from metrics registry
    registry.remove(timerMID);

    try {
        // Call the timed method and assert an exception is thrown
        bean.timedMethod();
    }
    catch (RuntimeException cause) {
        assertThat(cause, is(instanceOf(IllegalStateException.class)));
        // Make sure that the timer hasn't been called
        assertThat("Timer count is incorrect", timer.getCount(), is(equalTo(TIMER_COUNT.get())));
        return;
    }

    fail("No exception has been re-thrown!");
}
 
Example #10
Source File: MetricProducerFieldBeanTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(2)
public void incrementCountersFromRegistry() {
    assertThat("Counters are not registered correctly", registry.getCounters(),
        allOf(
            hasKey(counter1MID),
            hasKey(counter2MID),
            not(hasKey(notRegMID))
        )
    );
    Counter counter1 = registry.getCounter(counter1MID);
    Counter counter2 = registry.getCounter(counter2MID);

    @SuppressWarnings("unchecked")
    Gauge<Double> gauge = (Gauge<Double>) registry.getGauge(ratioGaugeMID);
    assertThat("Gauge is not registered correctly", gauge, notNullValue());

    counter1.inc(Math.round(Math.random() * Integer.MAX_VALUE));
    counter2.inc(Math.round(Math.random() * Integer.MAX_VALUE));

    assertThat("Gauge value is incorrect", gauge.getValue(), is(equalTo(((double) counter1.getCount()) / ((double) counter2.getCount()))));
}
 
Example #11
Source File: MpMetricTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@RunAsClient
@InSequence(11)
public void testBaseMetadataSingluarItems() {
    Assume.assumeFalse(Boolean.getBoolean("skip.base.metric.tests"));
    Header wantJson = new Header("Accept", APPLICATION_JSON);

    JsonPath jsonPath = given().header(wantJson).options("/metrics/base").jsonPath();

    Map<String, Object> elements = jsonPath.getMap(".");
    List<String> missing = new ArrayList<>();

    Map<String, MiniMeta> baseNames = getExpectedMetadataFromXmlFile(MetricRegistry.Type.BASE);
    for (String item : baseNames.keySet()) {
        if (item.startsWith("gc.") || baseNames.get(item).optional) {
            continue;
        }
        if (!elements.containsKey(item)) {
            missing.add(item);
        }
    }

    assertTrue("Following base items are missing: " + Arrays.toString(missing.toArray()), missing.isEmpty());
}
 
Example #12
Source File: GaugeTagMethodBeanTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(2)
public void callGaugeTagAfterSetterCall() {
    @SuppressWarnings("unchecked")
    Gauge<Long> gaugeOne = (Gauge<Long>) registry.getGauge(gaugeOneMID);
    @SuppressWarnings("unchecked")
    Gauge<Long> gaugeTwo = (Gauge<Long>) registry.getGauge(gaugeTwoMID);
    assertThat("Gauge is not registered correctly", gaugeOne, notNullValue());
    assertThat("Gauge is not registered correctly", gaugeTwo, notNullValue());

    // Call the setter method and assert the gauge is up-to-date
    long value = Math.round(Math.random() * Long.MAX_VALUE);
    bean.setGaugeOne(value);
    
    long secondValue = Math.round(Math.random() * Long.MAX_VALUE);
    bean.setGaugeTwo(secondValue);
    
    assertThat("Gauge value is incorrect", gaugeOne.getValue(), is(equalTo(value)));
    assertThat("Gauge value is incorrect", gaugeTwo.getValue(), is(equalTo(secondValue)));
}
 
Example #13
Source File: MetricProducerFieldBeanTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(1)
public void countersNotIncrementedYet() {
    assertThat("Counters are not registered correctly", registry.getCounters(),
        allOf(
            hasKey(counter1MID),
            hasKey(counter2MID),
            not(hasKey(notRegMID))
        )
    );
    Counter counter1 = registry.getCounter(counter1MID);
    Counter counter2 = registry.getCounter(counter2MID);

    @SuppressWarnings("unchecked")
    Gauge<Double> gauge = (Gauge<Double>) registry.getGauge(ratioGaugeMID);
    assertThat("Gauge is not registered correctly", gauge, notNullValue());

    assertThat("Gauge value is incorrect", gauge.getValue(), is(equalTo(((double) counter1.getCount()) / ((double) counter2.getCount()))));
}
 
Example #14
Source File: MpMetricTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
/**
 * Test that semicolons `;` in tag values are translated to underscores `_`
 * in the JSON output
 */
@Test
@RunAsClient
@InSequence(46)
public void testTranslateSemiColonToUnderScoreJSON() {
    Header wantJson = new Header("Accept", APPLICATION_JSON);
    Response resp = given().header(wantJson).get("/metrics/application");
    JsonPath filteredJSONPath = new JsonPath(filterOutAppLabelJSON(resp.jsonPath().prettify()));
    ResponseBuilder responseBuilder = new ResponseBuilder();
    responseBuilder.clone(resp);
    responseBuilder.setBody(filteredJSONPath.prettify());
    resp = responseBuilder.build();
    
    resp.then().statusCode(200)
        .body("'org.eclipse.microprofile.metrics.test.MetricAppBean.semiColonTaggedCounter;"
                + "scTag=semi_colons_are_bad;tier=integration'", equalTo(0));
}
 
Example #15
Source File: MpMetricTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@RunAsClient
@InSequence(19)
public void testApplicationMetadataItems() {
    Header wantJson = new Header("Accept", APPLICATION_JSON);

    JsonPath jsonPath = given().header(wantJson).options("/metrics/application").jsonPath();

    Map<String, Object> elements = jsonPath.getMap(".");
    
    List<String> missing = new ArrayList<>();

    Map<String, MiniMeta> names = getExpectedMetadataFromXmlFile(MetricRegistry.Type.APPLICATION);
    for (String item : names.keySet()) {
        if (!elements.containsKey(item)) {
            missing.add(item);
        }
    }
    assertTrue("Following application items are missing: " + Arrays.toString(missing.toArray()), missing.isEmpty());
}
 
Example #16
Source File: ReusedMetricsTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@RunAsClient
@InSequence(4)
public void testSharedCounterAgain() {

  Header acceptJson = new Header("Accept", APPLICATION_JSON);

  Response resp = given().header(acceptJson).get("/metrics/application");
  JsonPath filteredJSONPath = new JsonPath(resp.jsonPath().prettify().replaceAll(JSON_APP_LABEL_REGEX, JSON_APP_LABEL_REGEXS_SUB));
  ResponseBuilder responseBuilder = new ResponseBuilder();
  responseBuilder.clone(resp);
  responseBuilder.setBody(filteredJSONPath.prettify());
  resp = responseBuilder.build();

  resp.then()
  .assertThat().body("'countMe2;tier=integration'", equalTo(2))
  .assertThat().body("'org.eclipse.microprofile.metrics.test.MetricAppBean2.meterMe2'.'count;tier=integration'", equalTo(2))
  .assertThat().body("'timeMe2'.'count;tier=integration'", equalTo(2))
  .assertThat().body("'simplyTimeMe2'.'count;tier=integration'", equalTo(2));


}
 
Example #17
Source File: SimplyTimedMethodBeanLookupTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(2)
public void callSimplyTimedMethodOnce() throws InterruptedException {
    // Get a contextual instance of the bean
    SimplyTimedMethodBean1 bean = instance.get();

    SimpleTimer simpleTimer = registry.getSimpleTimer(simpleTimerMID);
    assertThat("SimplyTimed is not registered correctly", simpleTimer, notNullValue());

    // Call the simplyTimed method and assert it's been simplyTimed
    bean.simplyTimedMethod();

    // Make sure that the simpleTimer has been called
    assertThat("SimplyTimed count is incorrect", simpleTimer.getCount(), is(equalTo(SIMPLE_TIMER_COUNT.incrementAndGet())));
    TestUtils.assertEqualsWithTolerance(2000000000L,  simpleTimer.getElapsedTime().toNanos());
}
 
Example #18
Source File: BookingServiceTest.java    From monolith with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(10)
public void testPagination() {

    // Test pagination logic
    MultivaluedMap<String, String> queryParameters = new MultivaluedHashMap<String, String>();

    queryParameters.add("first", "2");
    queryParameters.add("maxResults", "1");

    List<Booking> bookings = bookingService.getAll(queryParameters);
    assertNotNull(bookings);
    assertEquals(1, bookings.size());
    assertEquals("Sydney Opera House", bookings.get(0).getPerformance().getShow().getVenue().getName());
    assertEquals("Rock concert of the decade", bookings.get(0).getPerformance().getShow().getEvent().getName());
}
 
Example #19
Source File: MetricProducerMethodBeanTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(2)
public void callCachedMethodMultipleTimes() {
    assertThat("Metrics are not registered correctly", registry.getMetricIDs(),
        contains(cacheHitsMID, callsMID, hitsMID));
    Timer calls = registry.getTimer(callsMID);
    Meter hits = registry.getMeter(hitsMID);
    @SuppressWarnings("unchecked")
    Gauge<Double> gauge = (Gauge<Double>) registry.getGauge(cacheHitsMID);

    long count = 10 + Math.round(Math.random() * 10);
    for (int i = 0; i < count; i++) {
        bean.cachedMethod((Math.random() < 0.5));
    }

    assertThat("Gauge value is incorrect", gauge.getValue(), is(equalTo((double) hits.getCount() / (double) calls.getCount())));
}
 
Example #20
Source File: MpMetricTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@RunAsClient
@InSequence(34)
public void testPromNoBadCharsInNames() {
    given().header("Accept", TEXT_PLAIN).when().get("/metrics/application")
        .then().statusCode(200)
        .and()
            // metrics.counter("pm_counter-with-dashes");
        .body(containsString("pm_counter_with_dashes"))
            // metrics.counter("pm_counter#hash_x'y_");
        .body(containsString("pm_counter_hash_x_y_"))
            // metrics.counter("pm_counter-umlaut-äöü");
        .body(containsString("pm_counter_umlaut_"))
            // metrics.counter("pm_counter+accent_ê_");
        .body(containsString("pm_counter_accent_"));
}
 
Example #21
Source File: TimerTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(3)
public void testTimerRegistry() throws Exception {
    String timerLongName = "test.longData.timer";
    String timerTimeName = "testTime";

    MetricID timerLongNameMetricID = new MetricID(timerLongName);
    MetricID timerTimeNameMetricID = new MetricID(timerTimeName);

    Timer timerLong = registry.getTimer(timerLongNameMetricID);
    Timer timerTime = registry.getTimer(timerTimeNameMetricID);

    assertNotNull(timerLong);
    assertNotNull(timerTime);

    TestUtils.assertEqualsWithTolerance(480, timerLong.getSnapshot().getValue(0.5));
}
 
Example #22
Source File: TagsTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(1)
public void simpleTagTest() {
    Tag one = new Tag("hello", "world");
    Tag two = new Tag("goodbye", "friend");
    MetricID metricID = new MetricID("metricName", one, two);
    
    assertThat(metricID.getTags(), hasKey("hello"));
    assertThat(metricID.getTags(), hasValue("world"));
    
    assertThat(metricID.getTags(), hasKey("goodbye"));
    assertThat(metricID.getTags(), hasValue("friend"));
    
    //MP_METRICS_TAGS=tier=integration
    assertThat("Counter's Global Tag not set properly", metricID.getTags(), hasKey("tier"));
    assertThat("Counter's Global Tag not set properly", metricID.getTags(), hasValue("integration"));
}
 
Example #23
Source File: TimedClassBeanTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(2)
public void callTimedMethodsOnce() {
    assertThat("Timers are not registered correctly", registry.getTimers().keySet(), is(equalTo(timerMIDsIncludingToString)));
    
    assertThat("Constructor timer count is incorrect", registry.getTimer(constructorMID).getCount(), is(equalTo(1L)));

    // Call the timed methods and assert they've been timed
    bean.timedMethodOne();
    bean.timedMethodTwo();
    // Let's call the non-public methods as well
    bean.timedMethodProtected();
    bean.timedMethodPackagedPrivate();

    // Make sure that the method timers have been timed
    assertThat("Method timer counts are incorrect", registry.getTimers(METHOD_TIMERS).values(),
            everyItem(Matchers.<Timer> hasProperty("count", equalTo(METHOD_COUNT.incrementAndGet()))));
}
 
Example #24
Source File: InheritedTimedMethodBeanTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(2)
public void callTimedMethodsOnce() { 
    assertThat("Timers are not registered correctly", registry.getTimers().keySet(),
        is(equalTo(MetricsUtil.createMetricIDs(absoluteMetricNames()))));

    // Call the timed methods and assert they've all been timed once
    bean.publicTimedMethod();
    bean.protectedTimedMethod();
    bean.packagePrivateTimedMethod();

    // Call the methods of the parent and assert they've also been timed once
    bean.timedMethodOne();
    bean.timedMethodTwo();
    bean.timedMethodProtected();
    bean.timedMethodPackagedPrivate();

    assertThat("Timer counts are incorrect", registry.getTimers().values(), everyItem(Matchers.<Timer>hasProperty("count", equalTo(1L))));
}
 
Example #25
Source File: BookingServiceTest.java    From monolith with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(10)
public void testPagination() {

    // Test pagination logic
    MultivaluedMap<String, String> queryParameters = new MultivaluedHashMap<String, String>();

    queryParameters.add("first", "2");
    queryParameters.add("maxResults", "1");

    List<Booking> bookings = bookingService.getAll(queryParameters);
    assertNotNull(bookings);
    assertEquals(1, bookings.size());
    assertEquals("Sydney Opera House", bookings.get(0).getPerformance().getShow().getVenue().getName());
    assertEquals("Rock concert of the decade", bookings.get(0).getPerformance().getShow().getEvent().getName());
}
 
Example #26
Source File: TimedMethodBeanTest.java    From microprofile-metrics with Apache License 2.0 6 votes vote down vote up
@Test
@InSequence(3)
public void removeTimerFromRegistry() throws InterruptedException {
    Timer timer = registry.getTimer(timerMID);
    assertThat("Timer is not registered correctly", timer, notNullValue());

    // Remove the timer from metrics registry
    registry.remove(timerMID);

    try {
        // Call the timed method and assert an exception is thrown
        bean.timedMethod();
    }
    catch (RuntimeException cause) {
        assertThat(cause, is(instanceOf(IllegalStateException.class)));
        // Make sure that the timer hasn't been called
        assertThat("Timer count is incorrect", timer.getCount(), is(equalTo(TIMER_COUNT.get())));
        return;
    }

    fail("No exception has been re-thrown!");
}
 
Example #27
Source File: MpMetricTest.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@Test
@InSequence(17)
public void testSetupApplicationMetrics() {

    metricAppBean.countMe();
    metricAppBean.countMeA();
    metricAppBean.countMeB();
    
    metricAppBean.gaugeMe();
    metricAppBean.gaugeMeA();
    metricAppBean.gaugeMeB();
    metricAppBean.gaugeMeTagged();
    metricAppBean.gaugeMeTaggedOne();
    metricAppBean.gaugeMeTaggedTwo();
    
    metricAppBean.histogramMe();

    metricAppBean.meterMe();
    metricAppBean.meterMeA();

    metricAppBean.timeMe();
    metricAppBean.timeMeA();
    
    metricAppBean.simpleTimeMe();
    metricAppBean.simpleTimeMeA();
    
    metricAppBean.concGaugeMeA();

}
 
Example #28
Source File: MpMetricTest.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@Test
@RunAsClient
@InSequence(12)
public void testBaseMetadataTypeAndUnit() {
    Assume.assumeFalse(Boolean.getBoolean("skip.base.metric.tests"));
    Header wantJson = new Header("Accept", APPLICATION_JSON);

    JsonPath jsonPath = given().header(wantJson).options("/metrics/base").jsonPath();

    Map<String, Map<String, Object>> elements = jsonPath.getMap(".");

    Map<String, MiniMeta> expectedMetadata = getExpectedMetadataFromXmlFile(MetricRegistry.Type.BASE);
          checkMetadataPresent(elements, expectedMetadata);

}
 
Example #29
Source File: ConcreteTimedBeanTest.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@Test
@InSequence(2)
public void extendedTimedMethodNotCalledYet(MetricRegistry registry) {
    Timer timer = registry.getTimer(extendedTimedMID);
    assertThat("Timer is not registered correctly on the methods on the abstract class", timer, notNullValue());

    // Make sure that the timer hasn't been called yet
    assertThat("Timer count is incorrect", timer.getCount(), is(equalTo(0L)));
}
 
Example #30
Source File: MpMetricOptionalTest.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@Test
@RunAsClient
@InSequence(3)
public void testSimpleRESTOptions() throws InterruptedException {
    Header acceptHeader = new Header("Accept", TEXT_PLAIN);

    given().
         header(acceptHeader).
         port(applicationPort).
    when().
         options(contextRoot+"/options-noparam").
    then().
        statusCode(200);

    Response resp = given().header(acceptHeader).when().get(RESTREQUEST_METRIC_ENDPOINT);
    ResponseBuilder responseBuilder = new ResponseBuilder();
    responseBuilder.clone(resp);
    responseBuilder.setBody(filterOutAppLabelOpenMetrics(resp.getBody().asString()));
    resp = responseBuilder.build();
    resp.then().
        statusCode(200).
        contentType(TEXT_PLAIN).
        body(containsString(OM_BASE_REQUEST_COUNT_START + "optionsNoParam" + OM_BASE_REQUEST_END)
                , containsString(OM_BASE_REQUEST_TIME_START + "optionsNoParam" + OM_BASE_REQUEST_END)
                , containsString(OM_BASE_MAX_TIME_START + "optionsNoParam" + OM_BASE_REQUEST_END)
                , containsString(OM_BASE_MIN_TIME_START + "optionsNoParam" + OM_BASE_REQUEST_END));

}