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.performance.raw.socket;
25
import EDU.oswego.cs.dl.util.concurrent.Latch;
26
import junit.framework.Test;
27
import org.jboss.jrunit.decorators.ThreadLocalDecorator;
28
import org.jboss.logging.Logger;
29
import org.jboss.remoting.InvokerLocator;
30
import org.jboss.test.remoting.performance.synchronous.MultiThreadedPerformanceClientTest;
31
import org.jboss.test.remoting.performance.synchronous.PerformanceCallbackKeeper;
33
import java.io.BufferedInputStream;
34
import java.io.BufferedOutputStream;
35
import java.io.IOException;
36
import java.io.ObjectInputStream;
37
import java.io.ObjectOutputStream;
38
import java.net.Socket;
39
import java.rmi.server.UID;
43
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
45
public class MultiThreadedSocketPerformanceClient extends MultiThreadedPerformanceClientTest
47
private int port = 7600;
48
private Socket socket = null;
49
private ObjectOutputStream oos;
50
private ObjectInputStream objInputStream;
51
private int timeout = 20000;
53
private String clientSessionId = new UID().toString();
55
protected static final Logger log = Logger.getLogger(MultiThreadedSocketPerformanceClient.class);
57
public static Test suite()
59
return new ThreadLocalDecorator(MultiThreadedSocketPerformanceClient.class, 1);
68
// catch(IOException e)
70
// e.printStackTrace();
75
* This will be used to create callback server
81
protected InvokerLocator initServer(int port) throws Exception
86
protected PerformanceCallbackKeeper addCallbackListener(String sessionId, Latch serverDoneLock)
89
SocketCallbackServer callbackServer = new SocketCallbackServer(host, clientSessionId, serverDoneLock);
90
callbackServer.start();
91
makeInvocation("callbackserver", new Integer(callbackServer.getBindPort()));
92
return callbackServer;
95
protected void populateMetadata(Map metadata)
97
super.populateMetadata(metadata);
98
metadata.put("transport", "raw_socket");
99
metadata.put("serialization", "java");
102
protected Object getBenchmarkAlias()
104
String config = System.getProperty("alias");
105
if(config == null || config.length() == 0)
107
config = System.getProperty("jboss-junit-configuration");
108
if(config == null || config.length() == 0)
110
config = "raw_socket" + "_" + getNumberOfCalls() + "_" + getPayloadSize() + "_" + "java";
117
protected Object makeInvocation(String method, Object param) throws Throwable
123
// Socket socket = new Socket(address, port);
124
// socket.setSoTimeout(timeout);
125
// BufferedOutputStream out = new BufferedOutputStream(socket.getOutputStream());
126
// BufferedInputStream in = new BufferedInputStream(socket.getInputStream());
128
// ObjectOutputStream oos = new ObjectOutputStream(out);
129
// ObjectInputStream objInputStream = new ObjectInputStream(in);
134
SocketPayload payload = new SocketPayload(method, clientSessionId, param);
136
oos.writeObject(payload);
138
oos.writeObject(Boolean.TRUE);
142
obj = objInputStream.readObject();
143
objInputStream.readObject();
145
// objInputStream.close();
153
private void getSocket() throws IOException
159
socket = new Socket(host, port);
160
socket.setSoTimeout(timeout);
161
BufferedOutputStream out = new BufferedOutputStream(socket.getOutputStream());
162
BufferedInputStream in = new BufferedInputStream(socket.getInputStream());
164
oos = new ObjectOutputStream(out);
165
objInputStream = new ObjectInputStream(in);
179
objInputStream.readByte();
183
public static void main(String[] args)
185
MultiThreadedSocketPerformanceClient test = new MultiThreadedSocketPerformanceClient();
189
test.testClientCalls();
192
catch(Throwable throwable)
194
throwable.printStackTrace();
b'\\ No newline at end of file'