Skip to content

Commit 12acf64

Browse files
committed
implement test based on scraper logs
1 parent 614ce54 commit 12acf64

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/JmxConnectionTest.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import java.nio.file.Path;
1111
import java.security.cert.X509Certificate;
12+
import java.util.UUID;
1213
import java.util.concurrent.TimeUnit;
1314
import java.util.function.Function;
1415
import org.junit.jupiter.api.AfterAll;
@@ -131,7 +132,7 @@ private void testServerSsl(
131132
}
132133

133134
@ParameterizedTest
134-
@EnumSource(value = JmxScraperContainer.ConfigSource.class)
135+
@EnumSource
135136
void serverSslClientSsl(JmxScraperContainer.ConfigSource configSource) {
136137
// Note: this could have been made simpler by relying on the fact that keystore could be used
137138
// as a trust store, but having clear split provides also some extra clarity
@@ -175,6 +176,39 @@ void serverSslClientSsl(JmxScraperContainer.ConfigSource configSource) {
175176
.withConfigSource(configSource));
176177
}
177178

179+
@Test
180+
void stableServiceInstanceServiceId() {
181+
UUID expectedServiceId = null;
182+
183+
// start a single app, connect twice to it and check that the service id is the same
184+
try (TestAppContainer app = appContainer().withJmxPort(JMX_PORT)) {
185+
app.start();
186+
for (int i = 0; i < 2; i++) {
187+
try (JmxScraperContainer scraper =
188+
scraperContainer()
189+
.withRmiServiceUrl(APP_HOST, JMX_PORT)
190+
// does not need to be tested on all config sources
191+
.withConfigSource(JmxScraperContainer.ConfigSource.SYSTEM_PROPERTIES)) {
192+
scraper.start();
193+
waitTerminated(scraper);
194+
String[] logLines = scraper.getLogs().split("\n");
195+
UUID serviceId = null;
196+
for (String logLine : logLines) {
197+
if (logLine.contains("remote service instance ID")) {
198+
serviceId = UUID.fromString(logLine.substring(logLine.lastIndexOf(":") + 1).trim());
199+
}
200+
}
201+
assertThat(serviceId).isNotNull();
202+
if (expectedServiceId == null) {
203+
expectedServiceId = serviceId;
204+
} else {
205+
assertThat(serviceId).isEqualTo(expectedServiceId);
206+
}
207+
}
208+
}
209+
}
210+
}
211+
178212
private static void connectionTest(
179213
Function<TestAppContainer, TestAppContainer> customizeApp,
180214
Function<JmxScraperContainer, JmxScraperContainer> customizeScraper) {

0 commit comments

Comments
 (0)