Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove private gauges from TCK #770

Merged
merged 2 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2013, 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2013, 2023 Contributors to the Eclipse Foundation
* Copyright © 2013 Antonin Stefanutti (antonin.stefanutti@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -26,23 +26,12 @@ public class GaugeMethodBean {

private long gauge;

private long privateGauge;

@Gauge(name = "gaugeMethod", unit = MetricUnits.NONE)
public long getGauge() {
return gauge;
}

@Gauge(name = "privateGaugeMethod", unit = MetricUnits.NONE)
private long getPrivateGauge() {
return privateGauge;
}

public void setGauge(long gauge) {
this.gauge = gauge;
}

public void setPrivateGauge(long gauge) {
this.privateGauge = gauge;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2013, 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2013, 2023 Contributors to the Eclipse Foundation
* Copyright © 2013 Antonin Stefanutti (antonin.stefanutti@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -41,12 +41,8 @@ public class GaugeMethodBeanTest {

private final static String GAUGE_NAME = MetricRegistry.name(GaugeMethodBean.class, "gaugeMethod");

private final static String PRIVATE_GAUGE_NAME = MetricRegistry.name(GaugeMethodBean.class, "privateGaugeMethod");

private static MetricID gaugeMID;

private static MetricID privateGaugeMID;

@Deployment
public static Archive<?> createTestArchive() {
return ShrinkWrap.create(WebArchive.class)
Expand All @@ -67,16 +63,13 @@ public void instantiateApplicationScopedBeanAndTest() {
// Let's trigger the instantiation of the application scoped bean explicitly
// as only a proxy gets injected otherwise
bean.getGauge();

/*
* The MetricID relies on the MicroProfile Config API. Running a managed arquillian container will result with
* the MetricID being created in a client process that does not contain the MPConfig impl.
*
* This will cause client instantiated MetricIDs to throw an exception. (i.e the global MetricIDs)
*/
gaugeMID = new MetricID(GAUGE_NAME);

privateGaugeMID = new MetricID(PRIVATE_GAUGE_NAME);
}

@Test
Expand All @@ -102,28 +95,4 @@ public void callGaugeAfterSetterCall() {
bean.setGauge(value);
assertThat("Gauge value is incorrect", gauge.getValue(), is(equalTo(value)));
}

@Test
@InSequence(3)
public void privateGaugeCalledWithDefaultValue() {
@SuppressWarnings("unchecked")
Gauge<Long> gauge = (Gauge<Long>) registry.getGauge(privateGaugeMID);
assertThat("Gauge is not registered correctly", gauge, notNullValue());

// Make sure that the gauge has the expected value
assertThat("Gauge value is incorrect", gauge.getValue(), is(equalTo(0L)));
}

@Test
@InSequence(4)
public void callPrivateGaugeAfterSetterCall() {
@SuppressWarnings("unchecked")
Gauge<Long> gauge = (Gauge<Long>) registry.getGauge(privateGaugeMID);
assertThat("Gauge is not registered correctly", gauge, notNullValue());

// Call the setter method and assert the gauge is up-to-date
long value = Math.round(Math.random() * Long.MAX_VALUE);
bean.setPrivateGauge(value);
assertThat("Gauge value is incorrect", gauge.getValue(), is(equalTo(value)));
}
}