Updated Branches: refs/heads/trunk 7c81b67ea -> 0bbd30640
Clients connections where never disconnected when client.disconnect was called Project: http://git-wip-us.apache.org/repos/asf/mina/repo Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/0bbd3064 Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/0bbd3064 Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/0bbd3064 Branch: refs/heads/trunk Commit: 0bbd30640f289e7fe8594657bdfb7f5d2179cfcf Parents: 7c81b67 Author: Jeff MAURY <[email protected]> Authored: Fri Jan 25 23:34:07 2013 +0100 Committer: Jeff MAURY <[email protected]> Committed: Fri Jan 25 23:34:07 2013 +0100 ---------------------------------------------------------------------- .../org/apache/mina/session/AbstractIoSession.java | 2 + .../transport/tcp/NioTcpClientReleaseTest.java | 82 +++++++++++++++ 2 files changed, 84 insertions(+), 0 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mina/blob/0bbd3064/core/src/main/java/org/apache/mina/session/AbstractIoSession.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/mina/session/AbstractIoSession.java b/core/src/main/java/org/apache/mina/session/AbstractIoSession.java index 56eccca..afa6829 100644 --- a/core/src/main/java/org/apache/mina/session/AbstractIoSession.java +++ b/core/src/main/java/org/apache/mina/session/AbstractIoSession.java @@ -155,6 +155,7 @@ public abstract class AbstractIoSession implements IoSession, ReadFilterChainCon LOG.debug("Created new session with id : {}", id); this.state = SessionState.CREATED; + service.getManagedSessions().put(id, this); } // ------------------------------------------------------------------------ @@ -756,6 +757,7 @@ public abstract class AbstractIoSession implements IoSession, ReadFilterChainCon } catch (final RuntimeException e) { processException(e); } + service.getManagedSessions().remove(id); } /** http://git-wip-us.apache.org/repos/asf/mina/blob/0bbd3064/core/src/test/java/org/apache/mina/transport/tcp/NioTcpClientReleaseTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/mina/transport/tcp/NioTcpClientReleaseTest.java b/core/src/test/java/org/apache/mina/transport/tcp/NioTcpClientReleaseTest.java new file mode 100644 index 0000000..37c8e78 --- /dev/null +++ b/core/src/test/java/org/apache/mina/transport/tcp/NioTcpClientReleaseTest.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.mina.transport.tcp; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +import org.apache.mina.api.AbstractIoHandler; +import org.apache.mina.api.IoSession; +import org.apache.mina.transport.nio.NioTcpClient; +import org.apache.mina.transport.nio.NioTcpServer; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This class test the resource management of {@link NioTcpClient}. + * + * @author <a href="http://mina.apache.org">Apache MINA Project</a> + */ +public class NioTcpClientReleaseTest { + + private static final Logger LOG = LoggerFactory.getLogger(NioTcpClientReleaseTest.class); + + private static final int CLIENT_COUNT = 10; + + private static final int WAIT_TIME = 30000; + + private final CountDownLatch closedLatch = new CountDownLatch(CLIENT_COUNT); + + /** + * Create an old IO server and use a bunch of MINA client on it. Test if the events occurs correctly in the + * different IoFilters. + */ + @Test + public void checkSessionsAreClosedWhenClientIsDisconnected() throws IOException, InterruptedException, ExecutionException { + + NioTcpServer server = new NioTcpServer(); + server.setIoHandler(new Handler()); + server.bind(0); + + NioTcpClient client = new NioTcpClient(); + client.setIoHandler(new AbstractIoHandler() { + }); + for(int i=0; i < CLIENT_COUNT;++i) { + client.connect(new InetSocketAddress(server.getServerSocketChannel().socket().getLocalPort())).get(); + } + client.disconnect(); + assertTrue(closedLatch.await(WAIT_TIME, TimeUnit.MILLISECONDS)); + } + + private class Handler extends AbstractIoHandler { + + @Override + public void sessionClosed(final IoSession session) { + LOG.info("** session closed"); + closedLatch.countDown(); + } + } +}
