Skip to content

Commit cfcc178

Browse files
committed
changed IoSessionResponder to use session log
1 parent 441ee59 commit cfcc178

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121

2222
import org.apache.mina.core.future.WriteFuture;
2323
import org.apache.mina.core.session.IoSession;
24-
import org.slf4j.Logger;
25-
import org.slf4j.LoggerFactory;
24+
import quickfix.LogUtil;
2625
import quickfix.Responder;
2726
import quickfix.Session;
2827

@@ -34,7 +33,6 @@
3433
* the MINA networking code.
3534
*/
3635
public class IoSessionResponder implements Responder {
37-
private final Logger log = LoggerFactory.getLogger(getClass());
3836
private final IoSession ioSession;
3937
private final boolean synchronousWrites;
4038
private final long synchronousWriteTimeout;
@@ -50,8 +48,8 @@ public IoSessionResponder(IoSession session, boolean synchronousWrites, long syn
5048
@Override
5149
public boolean send(String data) {
5250
// Check for and disconnect slow consumers.
51+
Session qfjSession = (Session) ioSession.getAttribute(SessionConnector.QF_SESSION);
5352
if (maxScheduledWriteRequests > 0 && ioSession.getScheduledWriteMessages() >= maxScheduledWriteRequests) {
54-
Session qfjSession = (Session) ioSession.getAttribute(SessionConnector.QF_SESSION);
5553
try {
5654
qfjSession.disconnect("Slow consumer", true);
5755
} catch (IOException e) {
@@ -64,11 +62,11 @@ public boolean send(String data) {
6462
if (synchronousWrites) {
6563
try {
6664
if (!future.awaitUninterruptibly(synchronousWriteTimeout)) {
67-
log.error("Synchronous write timed out after {}ms", synchronousWriteTimeout);
65+
qfjSession.getLog().onErrorEvent("Synchronous write timed out after " + synchronousWriteTimeout + "ms.");
6866
return false;
6967
}
7068
} catch (RuntimeException e) {
71-
log.error("Synchronous write failed: {}", e.getMessage());
69+
LogUtil.logThrowable(qfjSession.getSessionID(), "Synchronous write failed.", e);
7270
return false;
7371
}
7472
}

quickfixj-core/src/test/java/quickfix/mina/IoSessionResponderTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,14 @@
3434
import static org.mockito.Mockito.verifyNoMoreInteractions;
3535
import static org.mockito.Mockito.when;
3636

37+
import quickfix.Log;
38+
import quickfix.Session;
39+
import quickfix.SessionID;
3740

3841
public class IoSessionResponderTest {
3942

43+
private final SessionID sessionID = new SessionID("FIX.4.4:SENDER->TARGET");
44+
4045
@Test
4146
public void testAsynchronousSend() throws Exception {
4247
IoSession mockIoSession = mock(IoSession.class);
@@ -48,6 +53,7 @@ public void testAsynchronousSend() throws Exception {
4853
boolean result = responder.send("abcd");
4954

5055
assertTrue(result);
56+
verify(mockIoSession).getAttribute(SessionConnector.QF_SESSION);
5157
verify(mockIoSession).write("abcd");
5258
verifyNoMoreInteractions(mockWriteFuture);
5359
verifyNoMoreInteractions(mockIoSession);
@@ -65,6 +71,7 @@ public void testSynchronousSend() throws Exception {
6571
boolean result = responder.send("abcd");
6672

6773
assertTrue(result);
74+
verify(mockIoSession).getAttribute(SessionConnector.QF_SESSION);
6875
verify(mockIoSession).write("abcd");
6976
verify(mockWriteFuture).awaitUninterruptibly(timeout);
7077
verifyNoMoreInteractions(mockWriteFuture);
@@ -75,7 +82,10 @@ public void testSynchronousSend() throws Exception {
7582
public void testSynchronousSendWithJoinException() throws Exception {
7683
int timeout = 123;
7784
IoSession mockIoSession = mock(IoSession.class);
78-
85+
Session mockSession = mock(Session.class);
86+
when(mockIoSession.getAttribute(SessionConnector.QF_SESSION)).thenReturn(mockSession);
87+
when(mockSession.getSessionID()).thenReturn(sessionID);
88+
7989
WriteFuture mockWriteFuture = mock(WriteFuture.class);
8090
when(mockIoSession.write("abcd")).thenReturn(mockWriteFuture);
8191
doThrow(new RuntimeException("TEST")).when(mockWriteFuture).awaitUninterruptibly(timeout);
@@ -84,6 +94,7 @@ public void testSynchronousSendWithJoinException() throws Exception {
8494
boolean result = responder.send("abcd");
8595

8696
assertFalse(result);
97+
verify(mockIoSession).getAttribute(SessionConnector.QF_SESSION);
8798
verify(mockIoSession).write("abcd");
8899
verify(mockWriteFuture).awaitUninterruptibly(timeout);
89100
verifyNoMoreInteractions(mockWriteFuture);
@@ -94,6 +105,11 @@ public void testSynchronousSendWithJoinException() throws Exception {
94105
public void testSynchronousSendWithJoinTimeout() throws Exception {
95106
int timeout = 123;
96107
IoSession mockIoSession = mock(IoSession.class);
108+
Session mockSession = mock(Session.class);
109+
Log log = mock(Log.class);
110+
when(mockIoSession.getAttribute(SessionConnector.QF_SESSION)).thenReturn(mockSession);
111+
when(mockSession.getSessionID()).thenReturn(sessionID);
112+
when(mockSession.getLog()).thenReturn(log);
97113

98114
WriteFuture mockWriteFuture = mock(WriteFuture.class);
99115
when(mockIoSession.write("abcd")).thenReturn(mockWriteFuture);
@@ -103,6 +119,7 @@ public void testSynchronousSendWithJoinTimeout() throws Exception {
103119
boolean result = responder.send("abcd");
104120

105121
assertFalse(result);
122+
verify(mockIoSession).getAttribute(SessionConnector.QF_SESSION);
106123
verify(mockIoSession).write("abcd");
107124
verify(mockWriteFuture).awaitUninterruptibly(timeout);
108125
verifyNoMoreInteractions(mockWriteFuture);

0 commit comments

Comments
 (0)