Skip to content

Commit 77ae328

Browse files
committed
Calling callback.onConnectionFailed
1 parent 478e8c4 commit 77ae328

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

opamp-client/src/main/java/io/opentelemetry/opamp/client/internal/request/service/HttpRequestService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,20 @@ private void doSendRequest() {
141141
CompletableFuture<HttpSender.Response> future =
142142
requestSender.send(outputStream -> outputStream.write(data), data.length);
143143
try (HttpSender.Response response = future.get(30, TimeUnit.SECONDS)) {
144+
getCallback().onConnectionSuccess();
144145
if (isSuccessful(response)) {
145146
handleSuccessResponse(
146147
Response.create(ServerToAgent.ADAPTER.decode(response.bodyInputStream())));
147148
} else {
148149
handleHttpError(response);
149150
}
150151
} catch (IOException | InterruptedException | TimeoutException e) {
151-
getCallback().onRequestFailed(e);
152+
getCallback().onConnectionFailed(e);
152153
} catch (ExecutionException e) {
153154
if (e.getCause() != null) {
154-
getCallback().onRequestFailed(e.getCause());
155+
getCallback().onConnectionFailed(e.getCause());
155156
} else {
156-
getCallback().onRequestFailed(e);
157+
getCallback().onConnectionFailed(e);
157158
}
158159
}
159160
}

opamp-client/src/main/java/io/opentelemetry/opamp/client/internal/request/service/RequestService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ interface Callback {
5050

5151
/**
5252
* For WebSocket implementations, this is called when the connection cannot be made or is lost.
53-
* For HTTP implementations, this is called on every HTTP request that fails.
53+
* For HTTP implementations, this is called on every HTTP request that cannot get a response.
5454
*
5555
* @param throwable The detailed error.
5656
*/

opamp-client/src/test/java/io/opentelemetry/opamp/client/internal/request/service/HttpRequestServiceTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ void verifySendingRequest_whenTheresAParsingError() {
142142
httpRequestService.run();
143143

144144
verify(requestSender).send(any(), eq(requestSize));
145-
verify(callback).onRequestFailed(any());
145+
verify(callback).onConnectionFailed(any());
146146
}
147147

148148
@Test
@@ -157,7 +157,7 @@ void verifySendingRequest_whenThereIsAnExecutionError()
157157
httpRequestService.run();
158158

159159
verify(requestSender).send(any(), eq(requestSize));
160-
verify(callback).onRequestFailed(myException);
160+
verify(callback).onConnectionFailed(myException);
161161
}
162162

163163
@Test
@@ -172,7 +172,7 @@ void verifySendingRequest_whenThereIsAnInterruptedException()
172172
httpRequestService.run();
173173

174174
verify(requestSender).send(any(), eq(requestSize));
175-
verify(callback).onRequestFailed(myException);
175+
verify(callback).onConnectionFailed(myException);
176176
}
177177

178178
@Test

0 commit comments

Comments
 (0)