Skip to content

Commit e4b9d58

Browse files
authored
More corrections for SocketInitiator/Acceptor tests (#425)
* More corrections for SocketInitiator/Acceptor tests - ensure connector is stopped when first assertion in `finally` block fails * Prevent NPE when `stop()` method is called prior to `start()`
1 parent a9307c9 commit e4b9d58

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

quickfixj-core/src/main/java/quickfix/mina/SingleThreadedEventHandlingStrategy.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ public void stopHandlingMessages(boolean join) {
194194
stopHandlingMessages();
195195
if (join) {
196196
try {
197-
messageProcessingThread.join();
197+
if (messageProcessingThread != null) {
198+
messageProcessingThread.join();
199+
}
198200
} catch (InterruptedException e) {
199201
sessionConnector.log.warn("{} interrupted.", MESSAGE_PROCESSOR_THREAD_NAME);
200202
Thread.currentThread().interrupt();

quickfixj-core/src/test/java/quickfix/SocketAcceptorTest.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,25 @@ public void testRestartOfAcceptor() throws Exception {
102102
assertTrue("acceptor should have logged on by now", acceptor.isLoggedOn());
103103
assertTrue("initiator should have logged on by now", initiator.isLoggedOn());
104104
} finally {
105-
if (initiator != null) {
106-
try {
107-
initiator.stop();
108-
} catch (RuntimeException e) {
109-
log.error(e.getMessage(), e);
105+
try {
106+
if (initiator != null) {
107+
try {
108+
initiator.stop();
109+
} catch (RuntimeException e) {
110+
log.error(e.getMessage(), e);
111+
}
110112
}
111-
}
112-
testAcceptorApplication.waitForLogout();
113-
if (acceptor != null) {
114-
try {
115-
acceptor.stop();
116-
} catch (RuntimeException e) {
117-
log.error(e.getMessage(), e);
113+
testAcceptorApplication.waitForLogout();
114+
} finally {
115+
if (acceptor != null) {
116+
try {
117+
acceptor.stop();
118+
} catch (RuntimeException e) {
119+
log.error(e.getMessage(), e);
120+
}
118121
}
122+
testInitiatorApplication.waitForLogout();
119123
}
120-
testInitiatorApplication.waitForLogout();
121124
}
122125
}
123126

0 commit comments

Comments
 (0)