Skip to content

Commit

Permalink
Stop client actors at the end of tests; do not wait for graceful shut…
Browse files Browse the repository at this point in the history
…down in client actor tests.

Signed-off-by: Yufei Cai <yufei.cai@bosch.io>
  • Loading branch information
yufei-cai committed Sep 28, 2022
1 parent 4fa0a91 commit 3258254
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public void retrieveConnectionStatus() {
clientActor.tell(RetrieveConnectionStatus.of(getConnectionId(), DittoHeaders.empty()), getRef());

expectMsgClass(ResourceStatus.class);
getActorSystem().stop(clientActor);
}};
}

Expand All @@ -131,6 +132,7 @@ public void resetConnectionMetrics() {
clientActor.tell(ResetConnectionMetrics.of(getConnectionId(), DittoHeaders.empty()), getRef());

expectNoMessage();
getActorSystem().stop(clientActor);
}};
}

Expand Down Expand Up @@ -206,6 +208,7 @@ public void enableConnectionLogs() {
clientActor.tell(EnableConnectionLogs.of(getConnectionId(), DittoHeaders.empty()), getRef());

expectNoMessage();
getActorSystem().stop(clientActor);
}};
}

Expand All @@ -216,6 +219,7 @@ public void resetConnectionLogs() {
clientActor.tell(ResetConnectionLogs.of(getConnectionId(), DittoHeaders.empty()), getRef());

expectNoMessage();
getActorSystem().stop(clientActor);
}};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ public static void beforeClass() {
@AfterClass
public static void tearDown() {
if (null != actorSystem) {
TestKit.shutdownActorSystem(actorSystem, scala.concurrent.duration.Duration.apply(5, TimeUnit.SECONDS),
false);
actorSystem.terminate();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ public void setUp() {

@After
public void tearDown() {
TestKit.shutdownActorSystem(actorSystem, scala.concurrent.duration.Duration.apply(5, TimeUnit.SECONDS),
false);
if (actorSystem != null) {
actorSystem.terminate();
}
}

@AfterClass
Expand Down Expand Up @@ -255,6 +256,7 @@ public void testExceptionDuringJMSConnectionCreation() {
assertThat(failure.cause()).isInstanceOf(ConnectionFailedException.class)
.hasMessage("Failed to %s:%s", "create JMS connection", JMS_EXCEPTION.getMessage())
.hasCause(JMS_EXCEPTION);
getActorSystem().stop(connectionActor);
}};
}

Expand All @@ -280,6 +282,7 @@ public void testConnectionHandling() {

amqpClientActor.tell(RetrieveConnectionStatus.of(CONNECTION_ID, DittoHeaders.empty()), aggregator.ref());
aggregator.expectMsgClass(ResourceStatus.class);
getActorSystem().stop(amqpClientActor);
}};
}

Expand All @@ -306,6 +309,7 @@ public void testReconnect() {

amqpClientActor.tell(CloseConnection.of(CONNECTION_ID, DittoHeaders.empty()), getRef());
expectMsg(DISCONNECTED_SUCCESS);
getActorSystem().stop(amqpClientActor);
}};
}

Expand Down Expand Up @@ -336,6 +340,7 @@ public void testReconnectAndVerifyConnectionStatus() {

amqpClientActor.tell(CloseConnection.of(CONNECTION_ID, DittoHeaders.empty()), getRef());
expectMsg(DISCONNECTED_SUCCESS);
getActorSystem().stop(amqpClientActor);
}};
}

Expand Down Expand Up @@ -398,6 +403,7 @@ public void sendDisconnectWhenAlreadyDisconnected() {
amqpClientActor.tell(CloseConnection.of(CONNECTION_ID, DittoHeaders.empty()), getRef());
expectMsg(DISCONNECTED_SUCCESS);
Mockito.verifyNoInteractions(mockConnection);
getActorSystem().stop(amqpClientActor);
}};
}

Expand All @@ -417,6 +423,7 @@ public void testStartConnectionFails() throws JMSException {
assertThat(failure.cause()).isInstanceOf(ConnectionFailedException.class)
.hasMessage("Failed to %s:%s", "connect JMS client", JMS_EXCEPTION.getMessage())
.hasCause(JMS_EXCEPTION);
getActorSystem().stop(amqpClientActor);
}};
}

Expand All @@ -436,6 +443,7 @@ public void testCreateSessionFails() throws JMSException {
assertThat(failure.cause()).isInstanceOf(ConnectionFailedException.class)
.hasMessage("Failed to %s:%s", "create session", JMS_EXCEPTION.getMessage())
.hasCause(JMS_EXCEPTION);
getActorSystem().stop(amqpClientActor);
}};
}

Expand All @@ -451,6 +459,7 @@ public void testCreateConsumerFails() throws JMSException {

amqpClientActor.tell(OpenConnection.of(CONNECTION_ID, DittoHeaders.empty()), getRef());
expectMsgClass(Status.Failure.class);
getActorSystem().stop(amqpClientActor);
}};
}

Expand Down Expand Up @@ -489,6 +498,8 @@ public void testSetMessageListenerOnConsumerFails() throws JMSException {
return false;
});
});

getActorSystem().stop(amqpClientActor);
}};
}

Expand All @@ -506,6 +517,7 @@ public void testCloseConnectionFails() throws JMSException {

amqpClientActor.tell(CloseConnection.of(CONNECTION_ID, DittoHeaders.empty()), getRef());
expectMsg(DISCONNECTED_SUCCESS);
getActorSystem().stop(amqpClientActor);
}};
}

Expand Down Expand Up @@ -640,6 +652,7 @@ private void testConsumeMessageAndExpectForwardToProxyActor(final Connection con
if (postStep != null) {
postStep.accept(amqpClientActor);
}
getActorSystem().stop(amqpClientActor);
}};
}

Expand Down Expand Up @@ -811,6 +824,7 @@ public void testConsumerRecreationFailureWhenConnected() throws JMSException {
// THEN: recreated connection is working
messageListener.onMessage(mockMessage());
expectMsgClass(Command.class);
getActorSystem().stop(amqpClientActorRef);
}};
}

Expand Down Expand Up @@ -899,6 +913,7 @@ public void testTestConnection() {

amqpClientActor.tell(TestConnection.of(connection, DittoHeaders.empty()), getRef());
expectMsgClass(Status.Success.class);
getActorSystem().stop(amqpClientActor);
}};
}

Expand All @@ -917,6 +932,7 @@ public void testTestConnectionFailsOnTimeout() throws JMSException {
amqpClientActor.tell(TestConnection.of(connection, DittoHeaders.empty()), getRef());
amqpClientActor.tell(FSM.StateTimeout$.MODULE$, amqpClientActor);
expectMsgClass(Status.Failure.class);
getActorSystem().stop(amqpClientActor);
}};
} finally {
latch.countDown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void createActorSystem() {
@After
public void stopActorSystem() {
if (actorSystem != null) {
TestKit.shutdownActorSystem(actorSystem);
actorSystem.terminate();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ private static void startMockServer() {

@AfterClass
public static void tearDown() {
TestKit.shutdownActorSystem(actorSystem, scala.concurrent.duration.Duration.apply(5, TimeUnit.SECONDS),
false);
actorSystem.terminate();
stopMockServer();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import java.io.IOException;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.stream.Stream;

Expand Down Expand Up @@ -106,7 +105,7 @@ public void setUp() {

@After
public void tearDown() {
TestKit.shutdownActorSystem(actorSystem, scala.concurrent.duration.Duration.apply(5, TimeUnit.SECONDS), false);
actorSystem.terminate();
}

@Before
Expand All @@ -122,7 +121,7 @@ public void init() throws IOException, TimeoutException {
@Test
public void invalidTargetFormatThrowsConnectionConfigurationInvalidException() {
final Connection connection = ConnectivityModelFactory.newConnectionBuilder(CONNECTION_ID,
ConnectionType.AMQP_091, ConnectivityStatus.OPEN, TestConstants.getUriOfNewMockServer())
ConnectionType.AMQP_091, ConnectivityStatus.OPEN, TestConstants.getUriOfNewMockServer())
.targets(Collections.singletonList(ConnectivityModelFactory.newTargetBuilder()
.address("exchangeOnly")
.authorizationContext(TestConstants.Authorization.AUTHORIZATION_CONTEXT)
Expand Down Expand Up @@ -150,7 +149,7 @@ public void testExceptionDuringConnectionFactoryCreation() {
new TestKit(actorSystem) {{
final Props props =
RabbitMQClientActor.propsForTests(connection, getRef(),
getRef(), (con, exHandler, connectionLogger) -> { throw CUSTOM_EXCEPTION; })
getRef(), (con, exHandler, connectionLogger) -> {throw CUSTOM_EXCEPTION;})
.withDispatcher(CallingThreadDispatcher.Id());
final ActorRef connectionActor = actorSystem.actorOf(props);

Expand Down Expand Up @@ -250,7 +249,7 @@ public void testConnectionWithoutPublisherHandling() {
TestConstants.createConnection(randomConnectionId, new Target[0]);
final Props props =
RabbitMQClientActor.propsForTests(connectionWithoutTargets, getRef(), getRef(),
(con, exHandler, connectionLogger) -> mockConnectionFactory)
(con, exHandler, connectionLogger) -> mockConnectionFactory)
.withDispatcher(CallingThreadDispatcher.Id());
final ActorRef rabbitClientActor = actorSystem.actorOf(props);
watch(rabbitClientActor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void stopActor(final ActorRef actorRef) {

@Override
protected void after() {
TestKit.shutdownActorSystem(actorSystem, Duration.apply(5, TimeUnit.SECONDS), false);
actorSystem.terminate();
actorSystemName = null;
super.after();
}
Expand Down

0 comments on commit 3258254

Please sign in to comment.