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: import java.nio.BufferUnderflowException;
25:
26: import org.junit.Assert;
27: import org.junit.Test;
28:
29: import org.xsocket.connection.IServer;
30: import org.xsocket.connection.NonBlockingConnection;
31: import org.xsocket.connection.Server;
32: import org.xsocket.connection.ConnectionUtils;
33: import org.xsocket.connection.multiplexed.IMultiplexedConnection;
34: import org.xsocket.connection.multiplexed.INonBlockingPipeline;
35: import org.xsocket.connection.multiplexed.MultiplexedConnection;
36: import org.xsocket.connection.multiplexed.MultiplexedProtocolAdapter;
37:
38: /**
39: *
40: * @author grro@xsocket.org
41: */
42: public final class SuspendTest {
43:
44: @Test
45: public void testSimple() throws Exception {
46: IServer server = new Server(new MultiplexedProtocolAdapter(
47: new EchoHandler()));
48: ConnectionUtils.start(server);
49:
50: IMultiplexedConnection connection = new MultiplexedConnection(
51: new NonBlockingConnection(InetAddress
52: .getByName("localhost"), server.getLocalPort()));
53: String pipelineId = connection.createPipeline();
54: INonBlockingPipeline pipeline = connection
55: .getNonBlockingPipeline(pipelineId);
56:
57: pipeline.suspendRead();
58: pipeline.write("Hello echo" + EchoHandler.DELIMITER);
59:
60: QAUtil.sleep(250);
61:
62: try {
63: pipeline.readStringByDelimiter(EchoHandler.DELIMITER);
64: Assert
65: .fail("BufferUnderflow exception should have been thrown");
66: } catch (BufferUnderflowException expected) {
67: }
68:
69: pipeline.resumeRead();
70: String response = pipeline
71: .readStringByDelimiter(EchoHandler.DELIMITER);
72: Assert.assertEquals("Hello echo", response);
73:
74: pipeline.close();
75:
76: connection.close();
77: server.close();
78: }
79: }
|