Skip to content

Commit 478e8c4

Browse files
committed
Updating tests
1 parent 6d3baed commit 478e8c4

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public final class HttpRequestService implements RequestService, Runnable {
3636
private final PeriodicDelay periodicRetryDelay;
3737
private final AtomicBoolean retryModeEnabled = new AtomicBoolean(false);
3838
private final AtomicBoolean isRunning = new AtomicBoolean(false);
39+
private final AtomicBoolean hasStopped = new AtomicBoolean(false);
3940
private final RetryAfterParser retryAfterParser;
4041
@Nullable private Callback callback;
4142
@Nullable private Supplier<Request> requestSupplier;
@@ -85,6 +86,9 @@ public static HttpRequestService create(
8586

8687
@Override
8788
public void start(Callback callback, Supplier<Request> requestSupplier) {
89+
if (hasStopped.get()) {
90+
throw new IllegalStateException("HttpRequestService cannot start after it has been stopped.");
91+
}
8892
if (isRunning.compareAndSet(false, true)) {
8993
this.callback = callback;
9094
this.requestSupplier = requestSupplier;
@@ -97,6 +101,7 @@ public void start(Callback callback, Supplier<Request> requestSupplier) {
97101
@Override
98102
public void stop() {
99103
if (isRunning.compareAndSet(true, false)) {
104+
hasStopped.set(true);
100105
executor.executeNow();
101106
executor.stop();
102107
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ void whenTryingToStartAfterStopHasBeenCalled_throwException() {
112112
httpRequestService.stop();
113113
try {
114114
httpRequestService.start(callback, requestSupplier);
115+
fail();
115116
} catch (IllegalStateException e) {
116-
assertThat(e).hasMessage("RequestDispatcher has been stopped");
117+
assertThat(e).hasMessage("HttpRequestService cannot start after it has been stopped.");
117118
}
118119
}
119120

0 commit comments

Comments
 (0)