Skip to content

Commit 309cd27

Browse files
committed
Updating client impl tests to avoid service mock
1 parent 31f3372 commit 309cd27

File tree

5 files changed

+272
-174
lines changed

5 files changed

+272
-174
lines changed

dependencyManagement/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies {
1717
api(enforcedPlatform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:${otelInstrumentationVersion}"))
1818
api(enforcedPlatform("com.fasterxml.jackson:jackson-bom:2.19.1"))
1919
api(enforcedPlatform("com.google.protobuf:protobuf-bom:4.31.1"))
20+
api(enforcedPlatform("com.squareup.okhttp3:okhttp-bom:5.1.0"))
2021

2122
constraints {
2223
api("io.opentelemetry.semconv:opentelemetry-semconv:${semconvVersion}")
@@ -44,7 +45,6 @@ dependencies {
4445

4546
api("com.google.code.findbugs:annotations:3.0.1u2")
4647
api("com.google.code.findbugs:jsr305:3.0.2")
47-
api("com.squareup.okhttp3:okhttp:5.0.0")
4848
api("com.uber.nullaway:nullaway:0.12.7")
4949
api("org.assertj:assertj-core:3.27.3")
5050
api("org.awaitility:awaitility:4.3.0")

opamp-client/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ dependencies {
1818
compileOnly("com.google.auto.value:auto-value-annotations")
1919
testImplementation("org.mockito:mockito-inline")
2020
testImplementation("com.google.protobuf:protobuf-java-util")
21+
testImplementation("com.squareup.okhttp3:mockwebserver3")
22+
testImplementation("com.squareup.okhttp3:mockwebserver3-junit5")
2123
}
2224

2325
val opampProtos = tasks.register<DownloadOpampProtos>("opampProtoDownload", download)

opamp-client/src/main/java/io/opentelemetry/opamp/client/internal/connectivity/http/OkHttpSender.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
import java.io.IOException;
99
import java.io.InputStream;
1010
import java.util.concurrent.CompletableFuture;
11+
import javax.annotation.Nonnull;
12+
import javax.annotation.Nullable;
1113
import okhttp3.Call;
1214
import okhttp3.Callback;
1315
import okhttp3.MediaType;
1416
import okhttp3.OkHttpClient;
1517
import okhttp3.RequestBody;
1618
import okio.BufferedSink;
17-
import org.jetbrains.annotations.NotNull;
18-
import org.jetbrains.annotations.Nullable;
1919

2020
public final class OkHttpSender implements HttpSender {
2121
private final OkHttpClient client;
@@ -51,17 +51,12 @@ public CompletableFuture<Response> send(BodyWriter writer, int contentLength) {
5151
.enqueue(
5252
new Callback() {
5353
@Override
54-
public void onResponse(@NotNull Call call, @NotNull okhttp3.Response response) {
55-
if (response.isSuccessful() && response.body() != null) {
56-
future.complete(new OkHttpResponse(response));
57-
} else {
58-
future.completeExceptionally(
59-
new HttpErrorException(response.code(), response.message()));
60-
}
54+
public void onResponse(@Nonnull Call call, @Nonnull okhttp3.Response response) {
55+
future.complete(new OkHttpResponse(response));
6156
}
6257

6358
@Override
64-
public void onFailure(@NotNull Call call, @NotNull IOException e) {
59+
public void onFailure(@Nonnull Call call, @Nonnull IOException e) {
6560
future.completeExceptionally(e);
6661
}
6762
});
@@ -73,9 +68,6 @@ private static class OkHttpResponse implements Response {
7368
private final okhttp3.Response response;
7469

7570
private OkHttpResponse(okhttp3.Response response) {
76-
if (response.body() == null) {
77-
throw new IllegalStateException("null response body not expected");
78-
}
7971
this.response = response;
8072
}
8173

@@ -128,7 +120,7 @@ public long contentLength() {
128120
}
129121

130122
@Override
131-
public void writeTo(@NotNull BufferedSink bufferedSink) throws IOException {
123+
public void writeTo(@Nonnull BufferedSink bufferedSink) throws IOException {
132124
writer.writeTo(bufferedSink.outputStream());
133125
}
134126
}

opamp-client/src/main/java/io/opentelemetry/opamp/client/internal/impl/OpampClientImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private OpampClientImpl(
111111
}
112112

113113
@Override
114-
public void start(Callbacks callbacks) {
114+
public void start(@Nonnull Callbacks callbacks) {
115115
if (hasStopped.get()) {
116116
throw new IllegalStateException("The client cannot start after it has been stopped.");
117117
}
@@ -137,15 +137,15 @@ public void stop() {
137137
}
138138

139139
@Override
140-
public void setAgentDescription(AgentDescription agentDescription) {
140+
public void setAgentDescription(@Nonnull AgentDescription agentDescription) {
141141
if (!state.agentDescription.get().equals(agentDescription)) {
142142
state.agentDescription.set(agentDescription);
143143
addFieldAndSend(Field.AGENT_DESCRIPTION);
144144
}
145145
}
146146

147147
@Override
148-
public void setRemoteConfigStatus(RemoteConfigStatus remoteConfigStatus) {
148+
public void setRemoteConfigStatus(@Nonnull RemoteConfigStatus remoteConfigStatus) {
149149
if (!state.remoteConfigStatus.get().equals(remoteConfigStatus)) {
150150
state.remoteConfigStatus.set(remoteConfigStatus);
151151
addFieldAndSend(Field.REMOTE_CONFIG_STATUS);

0 commit comments

Comments
 (0)