Skip to content

Commit 6396a93

Browse files
authored
Test APM Server client with configured proxy server_url (elastic#2253)
1 parent 34984e6 commit 6396a93

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

apm-agent-core/src/test/java/co/elastic/apm/agent/report/ApmServerClientTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ public class ApmServerClientTest {
7878
@Before
7979
public void setUp() throws IOException {
8080
URL url1 = new URL("http", "localhost", apmServer1.port(), "/");
81-
URL url2 = new URL("http", "localhost", apmServer2.port(), "/");
81+
URL url2 = new URL("http", "localhost", apmServer2.port(), "/proxy");
8282
// APM server 6.x style
8383
apmServer1.stubFor(get(urlEqualTo("/")).willReturn(okForJson(Map.of("ok", Map.of("version", "6.7.0-SNAPSHOT")))));
8484
apmServer1.stubFor(get(urlEqualTo("/test")).willReturn(notFound()));
8585
apmServer1.stubFor(get(urlEqualTo("/not-found")).willReturn(notFound()));
8686
// APM server 7+ style
87-
apmServer2.stubFor(get(urlEqualTo("/")).willReturn(okForJson(Map.of("version", "7.3.0-RC1"))));
88-
apmServer2.stubFor(get(urlEqualTo("/test")).willReturn(ok("hello from server 2")));
89-
apmServer2.stubFor(get(urlEqualTo("/not-found")).willReturn(notFound()));
87+
apmServer2.stubFor(get(urlEqualTo("/proxy/")).willReturn(okForJson(Map.of("version", "7.3.0-RC1"))));
88+
apmServer2.stubFor(get(urlEqualTo("/proxy/test")).willReturn(ok("hello from server 2")));
89+
apmServer2.stubFor(get(urlEqualTo("/proxy/not-found")).willReturn(notFound()));
9090

9191
config = SpyConfiguration.createSpyConfig();
9292
reporterConfiguration = config.getConfig(ReporterConfiguration.class);
@@ -176,7 +176,7 @@ public void testUseNextUrlOnError() throws Exception {
176176
apmServerClient.execute("/test", HttpURLConnection::getResponseCode);
177177

178178
apmServer1.verify(0, getRequestedFor(urlEqualTo("/test")));
179-
apmServer2.verify(1, getRequestedFor(urlEqualTo("/test")));
179+
apmServer2.verify(1, getRequestedFor(urlEqualTo("/proxy/test")));
180180
assertThat(apmServerClient.getErrorCount()).isEqualTo(1);
181181
}
182182

@@ -194,7 +194,7 @@ public void testRetry() throws Exception {
194194
assertThat(apmServerClient.<String>execute("/test", conn -> new String(conn.getInputStream().readAllBytes()))).isEqualTo("hello from server 2");
195195
assertThat(Objects.requireNonNull(apmServerClient.getCurrentUrl()).getPort()).isEqualTo(apmServer2.port());
196196
apmServer1.verify(1, getRequestedFor(urlEqualTo("/test")));
197-
apmServer2.verify(1, getRequestedFor(urlEqualTo("/test")));
197+
apmServer2.verify(1, getRequestedFor(urlEqualTo("/proxy/test")));
198198
assertThat(apmServerClient.getErrorCount()).isEqualTo(1);
199199
}
200200

@@ -204,7 +204,7 @@ public void testRetryFailure() {
204204
.isInstanceOf(FileNotFoundException.class)
205205
.matches(t -> t.getSuppressed().length == 1, "should have a suppressed exception");
206206
apmServer1.verify(1, getRequestedFor(urlEqualTo("/not-found")));
207-
apmServer2.verify(1, getRequestedFor(urlEqualTo("/not-found")));
207+
apmServer2.verify(1, getRequestedFor(urlEqualTo("/proxy/not-found")));
208208
// two failures -> urls wrap
209209
assertThat(Objects.requireNonNull(apmServerClient.getCurrentUrl()).getPort()).isEqualTo(apmServer1.port());
210210
assertThat(apmServerClient.getErrorCount()).isEqualTo(2);
@@ -217,7 +217,7 @@ public void testExecuteSuccessfullyForAllUrls() {
217217
return null;
218218
});
219219
apmServer1.verify(1, getRequestedFor(urlEqualTo("/not-found")));
220-
apmServer2.verify(1, getRequestedFor(urlEqualTo("/not-found")));
220+
apmServer2.verify(1, getRequestedFor(urlEqualTo("/proxy/not-found")));
221221
// no failures -> urls in initial state
222222
assertThat(Objects.requireNonNull(apmServerClient.getCurrentUrl()).getPort()).isEqualTo(apmServer1.port());
223223
assertThat(apmServerClient.getErrorCount()).isZero();
@@ -231,7 +231,7 @@ public void testExecuteFailureForAllUrls() {
231231
return null;
232232
});
233233
apmServer1.verify(1, getRequestedFor(urlEqualTo("/not-found")));
234-
apmServer2.verify(1, getRequestedFor(urlEqualTo("/not-found")));
234+
apmServer2.verify(1, getRequestedFor(urlEqualTo("/proxy/not-found")));
235235
assertThat(apmServerClient.getErrorCount()).isEqualTo(0);
236236
}
237237

0 commit comments

Comments
 (0)