Fix for DIRMINA-999
authorJeff MAURY <jeffmaury.github@jeffmaury.com>
Sun, 7 Dec 2014 21:34:55 +0000 (22:34 +0100)
committerJeff MAURY <jeffmaury.github@jeffmaury.com>
Sun, 7 Dec 2014 21:34:55 +0000 (22:34 +0100)
core/src/main/java/org/apache/mina/transport/nio/AbstractNioSession.java
core/src/test/java/org/apache/mina/transport/nio/NioTcpClientReleaseTest.java

index f2bc4c2..c66fd1f 100644 (file)
@@ -326,6 +326,7 @@ public abstract class AbstractNioSession extends AbstractIoSession {
 
                         // we was flushing writes, now we to the close
                         channelClose();
+                        processSessionClosed();
                     } else {
                         // no more write event needed
                         selectorLoop.modifyRegistration(false, !isReadSuspended(), false, (SelectorListener) this,
index fc13539..f3a0064 100644 (file)
@@ -80,4 +80,34 @@ public class NioTcpClientReleaseTest {
             closedLatch.countDown();
         }
     }
+    
+    /**
+     * Test added for DIRMINA-999
+     */
+    @Test
+    public void checkSessionCloseEventIsSentClientSideWhenImmediateIsFalse() throws IOException, InterruptedException,
+            ExecutionException {
+
+        NioTcpServer server = new NioTcpServer();
+        server.bind(0);
+
+        NioTcpClient client = new NioTcpClient();
+        final CountDownLatch closeCounter = new CountDownLatch(1);
+        client.setIoHandler(new AbstractIoHandler() {
+
+            @Override
+            public void sessionOpened(IoSession session) {
+                session.close(false);
+            }
+
+            @Override
+            public void sessionClosed(IoSession session) {
+                closeCounter.countDown();
+            }
+            
+        });
+        client.connect(new InetSocketAddress(server.getServerSocketChannel().socket().getLocalPort()));
+        assertTrue(closeCounter.await(WAIT_TIME, TimeUnit.MILLISECONDS));
+    }
+    
 }