From 54f023fa4abfb52a09f7b35ecde59e3758ac3f0d Mon Sep 17 00:00:00 2001 From: Benjamin Confino Date: Mon, 15 Apr 2024 12:19:13 +0100 Subject: [PATCH] code formating and cleanup --- tck/formatter.xml | 29 ++ tck/pom.xml | 251 ++++++++------- .../util/MetricDefinition.java | 44 +-- .../util/MetricGetterBackup.java | 295 ------------------ .../tck/metrics/util/MetricGetterTest.java | 1 - .../util/MetricGetterTest.java | 1 - 6 files changed, 176 insertions(+), 445 deletions(-) create mode 100644 tck/formatter.xml delete mode 100644 tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/telemetryMetrics/util/MetricGetterBackup.java diff --git a/tck/formatter.xml b/tck/formatter.xml new file mode 100644 index 00000000..8d902cf1 --- /dev/null +++ b/tck/formatter.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + diff --git a/tck/pom.xml b/tck/pom.xml index 5bd465bc..826bf7a0 100644 --- a/tck/pom.xml +++ b/tck/pom.xml @@ -1,126 +1,137 @@ + 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. --> - 4.0.0 - - - - org.eclipse.microprofile.fault-tolerance - microprofile-fault-tolerance-parent - 4.1-SNAPSHOT - - - org.eclipse.microprofile.fault-tolerance - microprofile-fault-tolerance-tck - 4.1-SNAPSHOT - - Fault Tolerance for MicroProfile :: TCK - - ^_?[a-z][a-zA-Z0-9_]*$ - 3.0 - 4.0 - - - - - - org.eclipse.microprofile - microprofile-tck-bom - ${version.microprofile.tck.bom} - pom - import - - - - - - - - org.eclipse.microprofile.fault-tolerance - microprofile-fault-tolerance-api - ${project.version} - provided - - - - io.opentelemetry - opentelemetry-api - 1.36.0 - - - - jakarta.enterprise - jakarta.enterprise.cdi-api - provided - - - - org.eclipse.microprofile.metrics - microprofile-metrics-api - ${microprofile-metrics-api.version} - provided - - - - org.eclipse.microprofile.config - microprofile-config-api - ${microprofile-config-api.version} - provided - - - - io.opentelemetry - opentelemetry-sdk-metrics - 1.36.0 - - - - io.opentelemetry - opentelemetry-sdk-extension-autoconfigure - 1.36.0 - - - - org.testng - testng - - - org.jboss.arquillian.testng - arquillian-testng-container - - - - org.hamcrest - hamcrest-all - 1.3 - compile - - - - org.jboss.shrinkwrap - shrinkwrap-api - compile - - - org.jboss.shrinkwrap.descriptors - shrinkwrap-descriptors-impl-javaee - compile - - - org.awaitility - awaitility - 4.0.3 - compile - - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + + + org.eclipse.microprofile.fault-tolerance + microprofile-fault-tolerance-parent + 4.1-SNAPSHOT + + + org.eclipse.microprofile.fault-tolerance + microprofile-fault-tolerance-tck + 4.1-SNAPSHOT + + Fault Tolerance for MicroProfile :: TCK + + ^_?[a-z][a-zA-Z0-9_]*$ + 3.0 + 4.0 + + + + + + org.eclipse.microprofile + microprofile-tck-bom + ${version.microprofile.tck.bom} + pom + import + + + + + + + + net.revelc.code.formatter + formatter-maven-plugin + + ${project.basedir}/formatter.xml + + + + + + + + org.eclipse.microprofile.fault-tolerance + microprofile-fault-tolerance-api + ${project.version} + provided + + + + io.opentelemetry + opentelemetry-api + 1.36.0 + + + + jakarta.enterprise + jakarta.enterprise.cdi-api + provided + + + + org.eclipse.microprofile.metrics + microprofile-metrics-api + ${microprofile-metrics-api.version} + provided + + + + org.eclipse.microprofile.config + microprofile-config-api + ${microprofile-config-api.version} + provided + + + + io.opentelemetry + opentelemetry-sdk-metrics + 1.36.0 + + + + io.opentelemetry + opentelemetry-sdk-extension-autoconfigure + 1.36.0 + + + + org.testng + testng + + + org.jboss.arquillian.testng + arquillian-testng-container + + + + org.hamcrest + hamcrest-all + 1.3 + compile + + + + org.jboss.shrinkwrap + shrinkwrap-api + compile + + + org.jboss.shrinkwrap.descriptors + shrinkwrap-descriptors-impl-javaee + compile + + + org.awaitility + awaitility + 4.0.3 + compile + + diff --git a/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/telemetryMetrics/util/MetricDefinition.java b/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/telemetryMetrics/util/MetricDefinition.java index 30e84140..0c9d2843 100644 --- a/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/telemetryMetrics/util/MetricDefinition.java +++ b/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/telemetryMetrics/util/MetricDefinition.java @@ -49,33 +49,20 @@ * {@link BulkheadResult#ACCEPTED} and {@link BulkheadResult#REJECTED}. */ public enum MetricDefinition { - INVOCATIONS("ft.invocations.total", Set.of(LongCounter.class), InvocationResult.class, - InvocationFallback.class), RETRY_CALLS("ft.retry.calls.total", Set.of(LongCounter.class), - RetryRetried.class, RetryResult.class), RETRY_RETRIES("ft.retry.retries.total", - Set.of(LongCounter.class)), TIMEOUT_CALLS("ft.timeout.calls.total", - Set.of(LongCounter.class), TimeoutTimedOut.class), TIMEOUT_EXECUTION_DURATION( - "ft.timeout.executionDuration", Set.of(LongHistogram.class), - "nanoseconds"), CIRCUITBREAKER_CALLS("ft.circuitbreaker.calls.total", - Set.of(LongCounter.class), - CircuitBreakerResult.class), CIRCUITBREAKER_STATE( - "ft.circuitbreaker.state.total", - Set.of(ObservableLongGauge.class), "nanoseconds", - CircuitBreakerState.class), CIRCUITBREAKER_OPENED( - "ft.circuitbreaker.opened.total", - Set.of(LongCounter.class)), BULKHEAD_CALLS( - "ft.bulkhead.calls.total", - Set.of(LongCounter.class), - BulkheadResult.class), BULKHEAD_EXECUTIONS_RUNNING( - "ft.bulkhead.executionsRunning", - Set.of(ObservableLongGauge.class)), BULKHEAD_EXECUTIONS_WAITING( - "ft.bulkhead.executionsWaiting", - Set.of(ObservableLongGauge.class)), BULKHEAD_RUNNING_DURATION( - "ft.bulkhead.runningDuration", - Set.of(LongHistogram.class), - "nanoseconds"), BULKHEAD_WAITING_DURATION( - "ft.bulkhead.waitingDuration", - Set.of(LongHistogram.class), - "nanoseconds"); + INVOCATIONS("ft.invocations.total", Set.of(LongCounter.class), InvocationResult.class, InvocationFallback.class), + RETRY_CALLS("ft.retry.calls.total", Set.of(LongCounter.class), RetryRetried.class, RetryResult.class), + RETRY_RETRIES("ft.retry.retries.total", Set.of(LongCounter.class)), + TIMEOUT_CALLS("ft.timeout.calls.total", Set.of(LongCounter.class), TimeoutTimedOut.class), + TIMEOUT_EXECUTION_DURATION("ft.timeout.executionDuration", Set.of(LongHistogram.class), "nanoseconds"), + CIRCUITBREAKER_CALLS("ft.circuitbreaker.calls.total", Set.of(LongCounter.class), CircuitBreakerResult.class), + CIRCUITBREAKER_STATE("ft.circuitbreaker.state.total", Set.of(ObservableLongGauge.class), "nanoseconds", + CircuitBreakerState.class), + CIRCUITBREAKER_OPENED("ft.circuitbreaker.opened.total", Set.of(LongCounter.class)), + BULKHEAD_CALLS("ft.bulkhead.calls.total", Set.of(LongCounter.class), BulkheadResult.class), + BULKHEAD_EXECUTIONS_RUNNING("ft.bulkhead.executionsRunning", Set.of(ObservableLongGauge.class)), + BULKHEAD_EXECUTIONS_WAITING("ft.bulkhead.executionsWaiting", Set.of(ObservableLongGauge.class)), + BULKHEAD_RUNNING_DURATION("ft.bulkhead.runningDuration", Set.of(LongHistogram.class), "nanoseconds"), + BULKHEAD_WAITING_DURATION("ft.bulkhead.waitingDuration", Set.of(LongHistogram.class), "nanoseconds"); private String name; private String unit; @@ -216,7 +203,8 @@ public Attributes getAttribute() { public enum RetryResult implements AttributeValue { VALUE_RETURNED("valueReturned"), EXCEPTION_NOT_RETRYABLE("exceptionNotRetryable"), MAX_RETRIES_REACHED( - "maxRetriesReached"), MAX_DURATION_REACHED("maxDurationReached"); + "maxRetriesReached"), + MAX_DURATION_REACHED("maxDurationReached"); private Attributes attribute; diff --git a/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/telemetryMetrics/util/MetricGetterBackup.java b/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/telemetryMetrics/util/MetricGetterBackup.java deleted file mode 100644 index 2577746d..00000000 --- a/tck/src/main/java/org/eclipse/microprofile/fault/tolerance/tck/telemetryMetrics/util/MetricGetterBackup.java +++ /dev/null @@ -1,295 +0,0 @@ -/// * -// ******************************************************************************* -// * Copyright (c) 2020 Contributors to the Eclipse Foundation -// * -// * See the NOTICE file(s) distributed with this work for additional -// * information regarding copyright ownership. -// * -// * 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 org.eclipse.microprofile.fault.tolerance.tck.telemetryMetrics.util; -// -// import static org.hamcrest.MatcherAssert.assertThat; -// import static org.hamcrest.Matchers.instanceOf; -// import static org.testng.Assert.fail; -// -// import java.lang.reflect.Method; -// import java.util.ArrayList; -// import java.util.Arrays; -// import java.util.Collections; -// import java.util.HashMap; -// import java.util.List; -// import java.util.Map; -// import java.util.Optional; -// -// import org.eclipse.microprofile.fault.tolerance.tck.telemetryMetrics.util.MetricDefinition.BulkheadResult; -// import org.eclipse.microprofile.fault.tolerance.tck.telemetryMetrics.util.MetricDefinition.CircuitBreakerResult; -// import org.eclipse.microprofile.fault.tolerance.tck.telemetryMetrics.util.MetricDefinition.CircuitBreakerState; -// import org.eclipse.microprofile.fault.tolerance.tck.telemetryMetrics.util.MetricDefinition.InvocationFallback; -// import org.eclipse.microprofile.fault.tolerance.tck.telemetryMetrics.util.MetricDefinition.InvocationResult; -// import org.eclipse.microprofile.fault.tolerance.tck.telemetryMetrics.util.MetricDefinition.RetryResult; -// import org.eclipse.microprofile.fault.tolerance.tck.telemetryMetrics.util.MetricDefinition.RetryRetried; -// import org.eclipse.microprofile.fault.tolerance.tck.telemetryMetrics.util.MetricDefinition.TagValue; -// import org.eclipse.microprofile.fault.tolerance.tck.telemetryMetrics.util.MetricDefinition.TimeoutTimedOut; -// import org.eclipse.microprofile.metrics.Counter; -// import org.eclipse.microprofile.metrics.Gauge; -// import org.eclipse.microprofile.metrics.Histogram; -// import org.eclipse.microprofile.metrics.Metric; -// import org.eclipse.microprofile.metrics.MetricID; -// import org.eclipse.microprofile.metrics.Tag; -// -// import jakarta.enterprise.inject.spi.CDI; -// -/// ** -// * Retrieves metrics for a specific method -// *

-// * The MetricGetter facilitates testing of metrics by providing helper methods for retrieving metrics defined by the -// * faulttolerance spec for a specific class and method name. -// *

-// * This class will never create a metric which does not already exist. -// */ -// public class MetricGetterBackup { -// -// private MetricRegistryProxy registry; -// private final Tag methodTag; -// -// private Map counterMetrics = new HashMap<>(); -// private Map gaugeMetrics = new HashMap<>(); -// -// public MetricGetterBackup(Class clazz, String methodName) { -// validateClassAndMethodName(clazz, methodName); -// methodTag = new Tag("method", clazz.getCanonicalName() + "." + methodName); -// registry = CDI.current().select(MetricRegistryProxy.class, RegistryTypeLiteral.BASE).get(); -// } -// -// public CounterMetric getInvocations(InvocationResult result, InvocationFallback fallbackUsed) { -// return getCounterMetric(getMetricId(MetricDefinition.INVOCATIONS, result, fallbackUsed)); -// } -// -// public CounterMetric getRetryCalls(RetryRetried retried, RetryResult result) { -// return getCounterMetric(getMetricId(MetricDefinition.RETRY_CALLS, retried, result)); -// } -// -// public CounterMetric getRetryRetries() { -// return getCounterMetric(getMetricId(MetricDefinition.RETRY_RETRIES)); -// } -// -// public CounterMetric getTimeoutCalls(TimeoutTimedOut timedOut) { -// return getCounterMetric(getMetricId(MetricDefinition.TIMEOUT_CALLS, timedOut)); -// } -// -// public Optional getTimeoutExecutionDuration() { -// return getMetric(getMetricId(MetricDefinition.TIMEOUT_EXECUTION_DURATION), Histogram.class); -// } -// -// public CounterMetric getCircuitBreakerCalls(CircuitBreakerResult cbResult) { -// return getCounterMetric(getMetricId(MetricDefinition.CIRCUITBREAKER_CALLS, cbResult)); -// } -// -// public CounterMetric getCircuitBreakerOpened() { -// return getCounterMetric(getMetricId(MetricDefinition.CIRCUITBREAKER_OPENED)); -// } -// -// public GaugeMetric getCircuitBreakerState(CircuitBreakerState cbState) { -// return getGaugeMetric(getMetricId(MetricDefinition.CIRCUITBREAKER_STATE, cbState)); -// } -// -// public CounterMetric getBulkheadCalls(BulkheadResult bulkheadResult) { -// return getCounterMetric(getMetricId(MetricDefinition.BULKHEAD_CALLS, bulkheadResult)); -// } -// -// public GaugeMetric getBulkheadExecutionsRunning() { -// return getGaugeMetric(getMetricId(MetricDefinition.BULKHEAD_EXECUTIONS_RUNNING)); -// } -// -// public GaugeMetric getBulkheadExecutionsWaiting() { -// return getGaugeMetric(getMetricId(MetricDefinition.BULKHEAD_EXECUTIONS_WAITING)); -// } -// -// public Optional getBulkheadRunningDuration() { -// return getMetric(getMetricId(MetricDefinition.BULKHEAD_RUNNING_DURATION), Histogram.class); -// } -// -// public Optional getBulkheadWaitingDuration() { -// return getMetric(getMetricId(MetricDefinition.BULKHEAD_WAITING_DURATION), Histogram.class); -// } -// -// /** -// * Calls {@code baseline()} on all relevant metrics. -// *

-// * Extracts all of the {@code Counter} and {@code Gauge} metrics from {@link MetricDefinition} and calls -// * {@link CounterMetric#baseline()} or {@link GaugeMetric#baseline()} on them. -// *

-// * This allows us to check how they've changed later in the test using the {@code CounterMetric.delta()} or -// * {@code GaugeMetric.delta()} methods, without having to explicitly baseline every metric ourselves up front. -// */ -// public void baselineMetrics() { -// for (MetricDefinition definition : MetricDefinition.values()) { -// for (TagValue[] tags : getTagCombinations(definition.getTagClasses())) { -// MetricID id = getMetricId(definition, tags); -// if (definition.getMetricClass() == Counter.class) { -// getCounterMetric(id).baseline(); -// } -// if (definition.getMetricClass() == Gauge.class) { -// getGaugeMetric(id).baseline(); -// } -// } -// } -// } -// -// // ----------------------- -// // Private methods -// // ----------------------- -// -// /** -// * Computes all possible values for a set of tags. -// *

-// * Given an array of TagValue enums, this method find every combination of values from across this set of tags. -// *

-// * For example, if we had two tags {@code foo=[a|b]} and {@code bar=[x|y]}, this method would return -// * -// *

-// * [[foo=a, bar=x],
-// * [foo=a, bar=y],
-// * [foo=b, bar=x],
-// * [foo=b, bar=y]]
-// * 
-// *

-// * We can use this to iterate across all of the {@link MetricID}s which could be created for a metric which has -// * multiple tags. -// *

-// * If called with no arguments, this method returns an array containing an empty array (indicating the only possible -// * combination the the one with no tag values at all). -// * -// * @param tagValueClazzes -// * the set of tags -// * @return every possible combination when taking one value for each of the given tags -// */ -// @SafeVarargs -// public static final TagValue[][] getTagCombinations(Class... tagValueClazzes) { -// int combinations = 1; -// for (Class clazz : tagValueClazzes) { -// combinations *= clazz.getEnumConstants().length; -// } -// -// TagValue[][] result = new TagValue[combinations][]; -// List> tagLists = getTagCombinations(Arrays.asList(tagValueClazzes)); -// for (int i = 0; i < tagLists.size(); i++) { -// List tagList = tagLists.get(i); -// result[i] = tagList.toArray(new TagValue[tagList.size()]); -// } -// return result; -// } -// -// private static List> getTagCombinations(List> tagValueClazzes) { -// if (tagValueClazzes.isEmpty()) { -// return Collections.singletonList(Collections.emptyList()); -// } -// -// List> result = new ArrayList<>(); -// Class firstClazz = tagValueClazzes.get(0); -// for (TagValue value : firstClazz.getEnumConstants()) { -// for (List tagList : getTagCombinations(tagValueClazzes.subList(1, tagValueClazzes.size()))) { -// ArrayList newList = new ArrayList<>(); -// newList.add(value); -// newList.addAll(tagList); -// result.add(newList); -// } -// } -// return result; -// } -// -// /** -// * Creates a {@link MetricID} for a {@link MetricDefinition} and a set of tag values. -// *

-// * This method will check that the {@code TagValue}s passed in match the value of -// * {@link MetricDefinition#getTagClasses()}. -// * -// * @param metricDefinition -// * the definition of the metric -// * @param metricTags -// * the values for the tags of the metric -// * @return the MetricID for {@code metricDefinition} with the tags in {@code metricTags} -// */ -// private MetricID getMetricId(MetricDefinition metricDefinition, TagValue... metricTags) { -// if (metricDefinition.getTagClasses().length != metricTags.length) { -// throw new IllegalArgumentException("Wrong number of arguments passed for " + metricDefinition); -// } -// -// Tag[] tags = new Tag[metricTags.length + 1]; -// -// tags[0] = methodTag; -// -// for (int i = 0; i < metricTags.length; i++) { -// Class argClazz = metricDefinition.getTagClasses()[i]; -// if (!argClazz.isInstance(metricTags[i])) { -// throw new IllegalArgumentException("Argument " + i + " has the wrong type. " -// + "Was " + metricTags[i].getClass() + " but expected " + argClazz); -// } -// -// tags[i + 1] = metricTags[i].getTag(); -// } -// -// return new MetricID(metricDefinition.getName(), tags); -// } -// -// /** -// * Get or create the {@link CounterMetric} for the given {@link MetricID} -// *

-// * Each created {@code CounterMetric} will be stored and calling this method twice with the same {@code MetricID} -// * will return the same {@code CounterMetric}. -// * -// * @param metricId -// * the {@code MetricID} -// * @return the {@code CounterMetric} for {@code metricId} -// */ -// private CounterMetric getCounterMetric(MetricID metricId) { -// return counterMetrics.computeIfAbsent(metricId, m -> new CounterMetric(registry, m)); -// } -// -// /** -// * Get or create the {@link GaugeMetric} for the given {@link MetricID} -// *

-// * Each created {@code GaugeMetric} will be stored and calling this method twice with the same {@code MetricID} will -// * return the same {@code GaugeMetric}. -// * -// * @param metricId -// * the {@code MetricID} -// * @return the {@code GaugeMetric} for {@code metricId} -// */ -// private GaugeMetric getGaugeMetric(MetricID metricId) { -// return gaugeMetrics.computeIfAbsent(metricId, m -> new GaugeMetric(registry, m)); -// } -// -// private Optional getMetric(MetricID id, Class metricType) { -// Metric m = registry.getMetrics().get(id); -// if (m != null) { -// assertThat("Metric " + id, m, instanceOf(metricType)); -// return Optional.of(metricType.cast(m)); -// } else { -// return Optional.empty(); -// } -// } -// -// private void validateClassAndMethodName(Class clazz, String methodName) { -// for (Method m : clazz.getDeclaredMethods()) { -// if (m.getName().equals(methodName)) { -// return; -// } -// } -// -// fail("Couldn't find method " + methodName + " on class " + clazz.getCanonicalName()); -// } -// -// } diff --git a/tck/src/test/java/org/eclipse/microprofile/fault/tolerance/tck/metrics/util/MetricGetterTest.java b/tck/src/test/java/org/eclipse/microprofile/fault/tolerance/tck/metrics/util/MetricGetterTest.java index e5e11fef..d1e1a717 100644 --- a/tck/src/test/java/org/eclipse/microprofile/fault/tolerance/tck/metrics/util/MetricGetterTest.java +++ b/tck/src/test/java/org/eclipse/microprofile/fault/tolerance/tck/metrics/util/MetricGetterTest.java @@ -54,4 +54,3 @@ public void testTagComboTwo() { } } - diff --git a/tck/src/test/java/org/eclipse/microprofile/fault/tolerance/tck/telemetryMetrics/util/MetricGetterTest.java b/tck/src/test/java/org/eclipse/microprofile/fault/tolerance/tck/telemetryMetrics/util/MetricGetterTest.java index 2dbf93b7..a9a96bc7 100644 --- a/tck/src/test/java/org/eclipse/microprofile/fault/tolerance/tck/telemetryMetrics/util/MetricGetterTest.java +++ b/tck/src/test/java/org/eclipse/microprofile/fault/tolerance/tck/telemetryMetrics/util/MetricGetterTest.java @@ -25,7 +25,6 @@ import org.eclipse.microprofile.fault.tolerance.tck.telemetryMetrics.util.MetricDefinition.AttributeValue; import org.eclipse.microprofile.fault.tolerance.tck.telemetryMetrics.util.MetricDefinition.InvocationResult; import org.eclipse.microprofile.fault.tolerance.tck.telemetryMetrics.util.MetricDefinition.TimeoutTimedOut; -import org.eclipse.microprofile.fault.tolerance.tck.telemetryMetrics.util.MetricGetter; import org.testng.annotations.Test; /**