2
* JBoss, Home of Professional Open Source
3
* Copyright 2005, JBoss Inc., and individual contributors as indicated
4
* by the @authors tag. See the copyright.txt in the distribution for a
5
* full listing of individual contributors.
7
* This is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU Lesser General Public License as
9
* published by the Free Software Foundation; either version 2.1 of
10
* the License, or (at your option) any later version.
12
* This software is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this software; if not, write to the Free
19
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23
package org.jboss.test.remoting.stream;
25
import junit.framework.TestCase;
27
import org.apache.log4j.Logger;
28
import org.jboss.remoting.Client;
29
import org.jboss.remoting.InvokerLocator;
32
import java.io.FileInputStream;
37
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
39
public class StreamingTestClient extends TestCase
41
private static Logger log = Logger.getLogger(StreamingTestClient.class);
43
// Default locator values
44
private static String transport = "socket";
45
private static String host = "localhost";
46
private static int port = 5400;
48
private String locatorURI;
49
private Client remotingClient = null;
50
private File testFile = null;
51
private FileInputStream fileInput = null;
53
private boolean error = false;
55
public void testStream() throws Throwable
57
for(int x = 0; x < 5; x++)
59
// new Thread(new Runnable() {
66
// catch (Throwable throwable)
68
// throwable.printStackTrace();
75
// Thread.sleep(5000);
76
// assertFalse(error);
78
log.info("Waiting to give server a chance to send ");
79
log.info("org.jboss.remoting.stream.StreamHandler.CLOSE message");
83
public void sendStream() throws Throwable
85
URL fileURL = this.getClass().getResource("test.txt");
88
throw new Exception("Can not find file test.txt");
90
testFile = new File(fileURL.getFile());
91
fileInput = new FileInputStream(testFile);
93
String param = "foobar";
94
long fileLength = testFile.length();
95
log.info("File size = " + fileLength);
96
Object ret = remotingClient.invoke(fileInput, param);
98
Map responseMap = (Map)ret;
99
String subSys = (String)responseMap.get("subsystem");
100
String clientId = (String)responseMap.get("clientid");
101
String paramVal = (String)responseMap.get("paramval");
103
assertEquals("test_stream".toUpperCase(), subSys);
104
assertEquals(remotingClient.getSessionId(), clientId);
105
assertEquals("foobar", paramVal);
107
Object response = remotingClient.invoke("get_size");
108
int returnedFileLength = ((Integer) response).intValue();
109
log.info("Invocation response: " + response);
111
if(fileLength == returnedFileLength)
117
log.info("FAILED - returned file length was " + returnedFileLength);
119
assertEquals(fileLength, returnedFileLength);
122
public void setUp() throws Exception
124
String bindAddr = System.getProperty("jrunit.bind_addr", host);
125
locatorURI = transport + "://" + bindAddr + ":" + port;
126
InvokerLocator locator = new InvokerLocator(locatorURI);
127
log.info("Calling remoting server with locator uri of: " + locatorURI);
129
remotingClient = new Client(locator, "test_stream");
130
remotingClient.connect();
133
public void tearDown() throws Exception
135
if(remotingClient != null)
137
remotingClient.disconnect();
139
if(fileInput != null)
146
* Can pass transport and port to be used as parameters.
147
* Valid transports are 'rmi' and 'socket'.
151
public static void main(String[] args)
153
if(args != null && args.length == 2)
156
port = Integer.parseInt(args[1]);
158
String locatorURI = transport + "://" + host + ":" + port;
159
StreamingTestClient client = new StreamingTestClient();
b'\\ No newline at end of file'