Skip to content

Commit a22f84d

Browse files
committed
Allow explicit shutdown of the ProtocolAdapterManager for testing
1 parent e0f9d0e commit a22f84d

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

hivemq-edge/src/main/java/com/hivemq/HiveMQEdgeMain.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.jetbrains.annotations.NotNull;
3535
import org.jetbrains.annotations.Nullable;
3636
import com.hivemq.http.JaxrsHttpServer;
37+
import org.jetbrains.annotations.VisibleForTesting;
3738
import org.slf4j.Logger;
3839
import org.slf4j.LoggerFactory;
3940

@@ -174,6 +175,11 @@ public void start(final @Nullable EmbeddedExtension embeddedExtension)
174175

175176
public void stop() {
176177
stopGateway();
178+
}
179+
180+
@VisibleForTesting
181+
public void shutdownProtocolAdapters() {
182+
injector.protocolAdapterManager().shutdown();
177183
try {
178184
Runtime.getRuntime().removeShutdownHook(shutdownThread);
179185
} catch (final IllegalStateException ignored) {

hivemq-edge/src/main/java/com/hivemq/embedded/internal/EmbeddedHiveMQImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ private void performStop(
213213

214214
try {
215215
hiveMQServer.stop();
216+
hiveMQServer.shutdownProtocolAdapters();
216217
} catch (final Exception ex) {
217218
if (desiredState == State.CLOSED) {
218219
log.error("Exception during running shutdown hook.", ex);

hivemq-edge/src/main/java/com/hivemq/protocols/ProtocolAdapterManager.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ public void start() {
152152
protocolAdapterConfig.registerConsumer(this::refresh);
153153
}
154154

155+
@VisibleForTesting
156+
public void shutdown() {
157+
protocolAdapters.entrySet().stream().forEach(entry -> {
158+
try {
159+
entry.getValue().stopAsync(true).get();
160+
} catch (final InterruptedException | ExecutionException e) {
161+
log.error("Exception happened while shutting down adapter: ", e);
162+
throw new RuntimeException(e);
163+
}
164+
});
165+
}
166+
155167
public void refresh(final @NotNull List<ProtocolAdapterEntity> configs) {
156168
executorService.submit(() -> {
157169
log.info("Refreshing adapters");

0 commit comments

Comments
 (0)