Skip to content

Commit fc48b56

Browse files
committed
Tests
1 parent b8216e7 commit fc48b56

File tree

6 files changed

+165
-0
lines changed

6 files changed

+165
-0
lines changed

Diff for: dev/io.openliberty.microprofile.telemetry.1.0.internal_fat/bnd.bnd

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ tested.features:\
3838
mpconfig-1.3,\
3939
mpconfig-2.0,\
4040
mpConfig-3.1,\
41+
mpMetrics-1.1,\
42+
mpMetrics-3.0,\
43+
mpMetrics-4.0,\
44+
mpHealth-1.0,\
45+
mpHealth-3.1,\
4146
cdi-1.2,\
4247
cdi-2.0,\
4348
cdi-4.1,\

Diff for: dev/io.openliberty.microprofile.telemetry.1.0.internal_fat/fat/src/io/openliberty/microprofile/telemetry/internal_fat/FATSuite.java

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
TelemetryWithSpanErrorTest.class,
5454
TelemetryAttributesTest.class,
5555
TelemetryRuntimeInstanceTest.class,
56+
TelemetrySdkDisabledTrueWarningTest.class
5657

5758
})
5859
public class FATSuite {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 IBM Corporation and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*******************************************************************************/
10+
package io.openliberty.microprofile.telemetry.internal_fat;
11+
12+
import java.io.BufferedReader;
13+
import java.io.IOException;
14+
import java.io.InputStreamReader;
15+
import java.net.HttpURLConnection;
16+
import java.net.URI;
17+
import java.net.URL;
18+
import java.util.HashSet;
19+
import java.util.Set;
20+
21+
import javax.ws.rs.HttpMethod;
22+
23+
import org.junit.AfterClass;
24+
import org.junit.BeforeClass;
25+
import org.junit.ClassRule;
26+
import org.junit.Test;
27+
import org.junit.runner.RunWith;
28+
29+
import com.ibm.websphere.simplicity.log.Log;
30+
31+
import componenttest.annotation.Server;
32+
import componenttest.custom.junit.runner.FATRunner;
33+
import componenttest.rules.repeater.RepeatTests;
34+
import componenttest.topology.impl.LibertyServer;
35+
import componenttest.topology.utils.FATServletClient;
36+
import io.openliberty.microprofile.telemetry.internal_fat.shared.TelemetryActions;
37+
import junit.framework.Assert;
38+
39+
/**
40+
* Test to verify that only a singular CWMOT5100I is emitted for each unique internal WAB/application
41+
* i.e. health, metrics, rest handler ,etc.
42+
*
43+
* This issue only affects mpTelemetry-2.0 when used with HTTP Metrics (supported only in mpTelemetry-2.0)
44+
*/
45+
@RunWith(FATRunner.class)
46+
public class TelemetrySdkDisabledTrueWarningTest extends FATServletClient {
47+
48+
private static final String CLASS_NAME = TelemetrySdkDisabledTrueWarningTest.class.getName();
49+
50+
private static final String CWMOT5100I = "CWMOT5100I";
51+
52+
public static final String SERVER_NAME = "Telemetry10sdkDisbledTrueWarning";
53+
54+
@Server(SERVER_NAME)
55+
public static LibertyServer server;
56+
57+
@ClassRule
58+
public static RepeatTests r = TelemetryActions.telemetry20Repeats(SERVER_NAME);
59+
60+
@BeforeClass
61+
public static void setUp() throws Exception {
62+
server.startServer();
63+
}
64+
65+
@AfterClass
66+
public static void tearDown() throws Exception {
67+
server.stopServer();
68+
}
69+
70+
@Test
71+
public void uniqeCWMOT5100ITest() throws Exception {
72+
Assert.assertTrue(server.isStarted());
73+
74+
//Startup check.
75+
validateCWMOT5100Iwarning();
76+
77+
//hit health
78+
requestHttpServlet("/metrics");
79+
//hit metrics
80+
requestHttpServlet("/health");
81+
82+
//runtime check after hitting endpoints
83+
validateCWMOT5100Iwarning();
84+
85+
}
86+
87+
private void validateCWMOT5100Iwarning() throws Exception {
88+
Set<String> warningsIssued = new HashSet<String>();
89+
for (String warning : server.findStringsInLogs(CWMOT5100I)) {
90+
91+
//returns false if string already exists in set
92+
if (!warningsIssued.add(warning.split(CWMOT5100I)[1])) {
93+
Assert.fail(String.format("Detected duplciate %s warning: %s", CWMOT5100I, warning));
94+
}
95+
}
96+
}
97+
98+
protected String requestHttpServlet(String servletPath) {
99+
HttpURLConnection con = null;
100+
try {
101+
String path = "http://" + server.getHostname() + ":"
102+
+ server.getHttpDefaultPort() + servletPath;
103+
104+
URI theURI = new URI(path);
105+
106+
URL theURL = theURI.toURL();
107+
con = (HttpURLConnection) theURL.openConnection();
108+
con.setDoInput(true);
109+
con.setDoOutput(true);
110+
con.setUseCaches(false);
111+
con.setRequestMethod(HttpMethod.GET);
112+
String sep = System.getProperty("line.separator");
113+
String line = null;
114+
StringBuilder lines = new StringBuilder();
115+
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
116+
117+
while ((line = br.readLine()) != null && line.length() > 0) {
118+
lines.append(line).append(sep);
119+
}
120+
121+
Assert.assertEquals("Did not recieve 200 response code while connecting to " + path, 200, con.getResponseCode());
122+
123+
return lines.toString();
124+
} catch (IOException e) {
125+
Log.info(this.getClass(), "requestHttpServlet", "Encountered IO exception " + e);
126+
return null;
127+
} catch (Exception e) {
128+
Log.info(this.getClass(), "requestHttpServlet", "Encountered an exception " + e);
129+
return null;
130+
} finally {
131+
if (con != null)
132+
con.disconnect();
133+
}
134+
135+
}
136+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bootstrap.include=../testports.properties
2+
otel.service.name=overrideThisBootstrapProperty
3+
otel.sdk.disabled=true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Dio.opentelemetry.context.enableStrictContext=true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<server description="Server for testing Telemetry10">
2+
3+
<include location="../fatTestPorts.xml" />
4+
5+
<featureManager>
6+
<feature>mpHealth-4.0</feature>
7+
<feature>mpMetrics-5.1</feature>
8+
<feature>mpTelemetry-2.0</feature>
9+
<feature>restfulWS-3.1</feature>
10+
<feature>cdi-4.0</feature>
11+
<feature>componentTest-2.0</feature>
12+
</featureManager>
13+
14+
<mpMetrics authentication="false"/>
15+
16+
<!-- For the ExecutorService in SpanCurrentServlet.java -->
17+
<javaPermission className="java.lang.RuntimePermission" name="modifyThread" />
18+
19+
</server>

0 commit comments

Comments
 (0)