01: /*
02: * Copyright (c) xsocket.org, 2006-2008. All rights reserved.
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: * Please refer to the LGPL license at: http://www.gnu.org/copyleft/lesser.txt
19: * The latest copy of this software may be found on http://www.xsocket.org/
20: */
21: package org.xsocket.connection.multiplexed;
22:
23: import java.net.InetAddress;
24:
25: import org.junit.Assert;
26: import org.junit.Test;
27:
28: import org.xsocket.connection.IServer;
29: import org.xsocket.connection.NonBlockingConnection;
30: import org.xsocket.connection.Server;
31: import org.xsocket.connection.ConnectionUtils;
32: import org.xsocket.connection.multiplexed.IMultiplexedConnection;
33: import org.xsocket.connection.multiplexed.MultiplexedConnection;
34: import org.xsocket.connection.multiplexed.MultiplexedProtocolAdapter;
35:
36: /**
37: *
38: * @author grro@xsocket.org
39: */
40: public final class CloseTest {
41:
42: @Test
43: public void testIdleTimeoutBlockingConnection() throws Exception {
44:
45: IServer server = new Server(new MultiplexedProtocolAdapter(
46: new EchoHandler()));
47: ConnectionUtils.start(server);
48:
49: IMultiplexedConnection connection = new MultiplexedConnection(
50: new NonBlockingConnection(InetAddress
51: .getByName("localhost"), server.getLocalPort()));
52:
53: IBlockingPipeline p1 = connection
54: .getBlockingPipeline(connection.createPipeline());
55: IBlockingPipeline p2 = connection
56: .getBlockingPipeline(connection.createPipeline());
57: IBlockingPipeline p3 = connection
58: .getBlockingPipeline(connection.createPipeline());
59:
60: Assert.assertEquals(3, connection.listOpenPipelines().length);
61: connection.close();
62:
63: QAUtil.sleep(100);
64:
65: Assert.assertEquals(0, connection.listOpenPipelines().length);
66: Assert.assertFalse(p1.isOpen());
67: Assert.assertFalse(p2.isOpen());
68: Assert.assertFalse(p3.isOpen());
69:
70: server.close();
71: }
72:
73: }
|