Skip to content

Commit 5ad1072

Browse files
committed
Support skipping tests requiring metric registrar
1 parent 3efc897 commit 5ad1072

File tree

3 files changed

+91
-2
lines changed

3 files changed

+91
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ Name | Description
299299
`TEST_SKIPSSLVALIDATION` | _(Optional)_ Whether to skip SSL validation when connecting to the Cloud Foundry instance. Defaults to `false`.
300300
`UAA_API_REQUEST_LIMIT` | _(Optional)_ If your UAA server does rate limiting and returns 429 errors, set this variable to the smallest limit configured there. Whether your server limits UAA calls is shown in the log, together with the location of the configuration file on the server. Defaults to `0` (no limit).
301301
`SKIP_BROWSER_AUTH_TESTS` | _(Optional)_ Set to `true` to skip integration tests that require browser-based authentication (e.g., SSO tests). Useful when the Cloud Foundry instance does not support browser-based authentication or when running tests in a non-interactive environment. Defaults to `false`.
302+
`SKIP_METRIC_REGISTRAR_TESTS` | _(Optional)_ Set to `true` to skip integration tests that require the Metric Registrar service (e.g., MetricRegistrarTest). Useful when the Cloud Foundry instance does not have the Metric Registrar service available. Defaults to `false`.
302303
`SKIP_TCP_ROUTING_TESTS` | _(Optional)_ Set to `true` to skip TCP routing integration tests (TcpRoutesTest, RouterGroupsTest). Useful when the Cloud Foundry instance does not have TCP routing configured (i.e., no `routing_endpoint` in the info payload). Defaults to `false`.
303304
`SKIP_V2_TESTS` | _(Optional)_ Set to `true` to skip all V2 API integration tests. Useful when the Cloud Foundry V2 API is rate-limited or unavailable. When enabled, tests annotated with `@RequiresV2Api` will be skipped, including V3 tests that depend on V2 API calls (e.g., service broker creation). Defaults to `false`.
304305

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2026 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.cloudfoundry;
18+
19+
import java.lang.annotation.Documented;
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Inherited;
22+
import java.lang.annotation.Retention;
23+
import java.lang.annotation.RetentionPolicy;
24+
import java.lang.annotation.Target;
25+
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
26+
import org.junit.jupiter.api.extension.ExecutionCondition;
27+
import org.junit.jupiter.api.extension.ExtendWith;
28+
import org.junit.jupiter.api.extension.ExtensionContext;
29+
30+
/**
31+
* Annotation to mark tests that require the Metric Registrar service to be available.
32+
* Tests annotated with this will be skipped if the environment variable
33+
* {@code SKIP_METRIC_REGISTRAR_TESTS} is set to "true".
34+
*
35+
* <p>Usage:
36+
* <pre>
37+
* &#64;RequiresMetricRegistrar
38+
* public class MetricTest extends AbstractIntegrationTest {
39+
* // ...
40+
* }
41+
* </pre>
42+
*
43+
* <p>To skip metric registrar tests, set the environment variable:
44+
* <pre>
45+
* export SKIP_METRIC_REGISTRAR_TESTS=true
46+
* </pre>
47+
*/
48+
@Target({ElementType.METHOD, ElementType.TYPE})
49+
@Retention(RetentionPolicy.RUNTIME)
50+
@Documented
51+
@Inherited
52+
@ExtendWith(RequiresMetricRegistrar.RegistrarCondition.class)
53+
public @interface RequiresMetricRegistrar {
54+
55+
/**
56+
* JUnit 5 ExecutionCondition that checks if Metric Registrar tests should be skipped.
57+
*/
58+
class RegistrarCondition implements ExecutionCondition {
59+
60+
private static final String SKIP_REGISTRAR_ENV = "SKIP_METRIC_REGISTRAR_TESTS";
61+
62+
@Override
63+
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
64+
if ("true".equalsIgnoreCase(System.getenv(SKIP_REGISTRAR_ENV))) {
65+
return ConditionEvaluationResult.disabled(
66+
"Tests requiring Metric Registrar Service are disabled via "
67+
+ SKIP_REGISTRAR_ENV
68+
+ " environment variable.");
69+
}
70+
71+
return ConditionEvaluationResult.enabled("Metric Registrar tests are enabled");
72+
}
73+
}
74+
}

integration-test/src/test/java/org/cloudfoundry/logcache/v1/LogCacheTest.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.cloudfoundry.ApplicationUtils;
3030
import org.cloudfoundry.CloudFoundryVersion;
3131
import org.cloudfoundry.IfCloudFoundryVersion;
32+
import org.cloudfoundry.RequiresMetricRegistrar;
3233
import org.cloudfoundry.RequiresV2Api;
3334
import org.junit.jupiter.api.BeforeEach;
3435
import org.junit.jupiter.api.Disabled;
@@ -44,12 +45,23 @@ public class LogCacheTest extends AbstractIntegrationTest {
4445

4546
private ApplicationUtils.ApplicationMetadata testLogCacheAppMetadata;
4647

47-
@Autowired(required = false) private TestLogCacheEndpoints testLogCacheEndpoints;
48+
// Optional: only available when V2 API is enabled (requires deployed test app)
49+
@Autowired(required = false)
50+
private TestLogCacheEndpoints testLogCacheEndpoints;
4851

4952
private final Random random = new SecureRandom();
5053

54+
/**
55+
* Sets up the test log cache app metadata. The testLogCacheApp bean is optional
56+
* ({@code required = false}) because it depends on V2 API calls for app deployment.
57+
* When SKIP_V2_TESTS=true, this bean won't be available and setUp becomes a no-op.
58+
* Tests that need testLogCacheAppMetadata are annotated with {@code @RequiresV2Api}
59+
* and will be skipped in that case.
60+
*/
5161
@BeforeEach
52-
void setUp(@Autowired(required = false) Mono<ApplicationUtils.ApplicationMetadata> testLogCacheApp) {
62+
void setUp(
63+
@Autowired(required = false)
64+
Mono<ApplicationUtils.ApplicationMetadata> testLogCacheApp) {
5365
if (testLogCacheApp != null) {
5466
this.testLogCacheAppMetadata = testLogCacheApp.block();
5567
}
@@ -88,6 +100,7 @@ public void meta() {
88100

89101
@Test
90102
@RequiresV2Api
103+
@RequiresMetricRegistrar
91104
public void readCounter() {
92105
final String name = this.nameFactory.getName("counter-");
93106
final int delta = this.random.nextInt(1000);
@@ -108,6 +121,7 @@ public void readCounter() {
108121

109122
@Test
110123
@RequiresV2Api
124+
@RequiresMetricRegistrar
111125
public void readEvent() {
112126
final String title = this.nameFactory.getName("event-");
113127
final String body = "This is the body. " + new BigInteger(1024, this.random).toString(32);

0 commit comments

Comments
 (0)