~ubuntu-branches/ubuntu/raring/libjboss-remoting-java/raring

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/performance/raw/socket/MultiThreadedSocketPerformanceClient.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
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.
6
 
*
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.
11
 
*
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.
16
 
*
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.
21
 
*/
22
 
 
23
 
package org.jboss.test.remoting.performance.raw.socket;
24
 
 
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;
32
 
 
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;
40
 
import java.util.Map;
41
 
 
42
 
/**
43
 
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
44
 
 */
45
 
public class MultiThreadedSocketPerformanceClient extends MultiThreadedPerformanceClientTest
46
 
{
47
 
   private int port = 7600;
48
 
   private Socket socket = null;
49
 
   private ObjectOutputStream oos;
50
 
   private ObjectInputStream objInputStream;
51
 
   private int timeout = 20000;
52
 
 
53
 
   private String clientSessionId = new UID().toString();
54
 
 
55
 
   protected static final Logger log = Logger.getLogger(MultiThreadedSocketPerformanceClient.class);
56
 
 
57
 
   public static Test suite()
58
 
   {
59
 
      return new ThreadLocalDecorator(MultiThreadedSocketPerformanceClient.class, 1);
60
 
   }
61
 
 
62
 
   public void init()
63
 
   {
64
 
//      try
65
 
//      {
66
 
//         getSocket();
67
 
//      }
68
 
//      catch(IOException e)
69
 
//      {
70
 
//         e.printStackTrace();
71
 
//      }
72
 
   }
73
 
 
74
 
   /**
75
 
    * This will be used to create callback server
76
 
    *
77
 
    * @param port
78
 
    * @return
79
 
    * @throws Exception
80
 
    */
81
 
   protected InvokerLocator initServer(int port) throws Exception
82
 
   {
83
 
      return null;
84
 
   }
85
 
 
86
 
   protected PerformanceCallbackKeeper addCallbackListener(String sessionId, Latch serverDoneLock)
87
 
         throws Throwable
88
 
   {
89
 
      SocketCallbackServer callbackServer = new SocketCallbackServer(host, clientSessionId, serverDoneLock);
90
 
      callbackServer.start();
91
 
      makeInvocation("callbackserver", new Integer(callbackServer.getBindPort()));
92
 
      return callbackServer;
93
 
   }
94
 
 
95
 
   protected void populateMetadata(Map metadata)
96
 
   {
97
 
      super.populateMetadata(metadata);
98
 
      metadata.put("transport", "raw_socket");
99
 
      metadata.put("serialization", "java");
100
 
   }
101
 
 
102
 
   protected Object getBenchmarkAlias()
103
 
   {
104
 
      String config = System.getProperty("alias");
105
 
      if(config == null || config.length() == 0)
106
 
      {
107
 
         config = System.getProperty("jboss-junit-configuration");
108
 
         if(config == null || config.length() == 0)
109
 
         {
110
 
            config = "raw_socket" + "_" + getNumberOfCalls() + "_" + getPayloadSize() + "_" + "java";
111
 
         }
112
 
      }
113
 
      return config;
114
 
   }
115
 
 
116
 
 
117
 
   protected Object makeInvocation(String method, Object param) throws Throwable
118
 
   {
119
 
      Object obj = null;
120
 
 
121
 
      synchronized(host)
122
 
      {
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());
127
 
//
128
 
//      ObjectOutputStream oos = new ObjectOutputStream(out);
129
 
//      ObjectInputStream objInputStream = new ObjectInputStream(in);
130
 
 
131
 
 
132
 
         getSocket();
133
 
 
134
 
         SocketPayload payload = new SocketPayload(method, clientSessionId, param);
135
 
 
136
 
         oos.writeObject(payload);
137
 
         oos.reset();
138
 
         oos.writeObject(Boolean.TRUE);
139
 
         oos.flush();
140
 
         oos.reset();
141
 
 
142
 
         obj = objInputStream.readObject();
143
 
         objInputStream.readObject();
144
 
 
145
 
//      objInputStream.close();
146
 
//      oos.close();
147
 
//      socket.close();
148
 
      }
149
 
 
150
 
      return obj;
151
 
   }
152
 
 
153
 
   private void getSocket() throws IOException
154
 
   {
155
 
      if(socket == null)
156
 
      {
157
 
         try
158
 
         {
159
 
            socket = new Socket(host, port);
160
 
            socket.setSoTimeout(timeout);
161
 
            BufferedOutputStream out = new BufferedOutputStream(socket.getOutputStream());
162
 
            BufferedInputStream in = new BufferedInputStream(socket.getInputStream());
163
 
 
164
 
            oos = new ObjectOutputStream(out);
165
 
            objInputStream = new ObjectInputStream(in);
166
 
         }
167
 
         catch(IOException e)
168
 
         {
169
 
            e.printStackTrace();
170
 
            throw e;
171
 
         }
172
 
      }
173
 
      else
174
 
      {
175
 
         oos.reset();
176
 
         oos.writeByte(1);
177
 
         oos.flush();
178
 
         oos.reset();
179
 
         objInputStream.readByte();
180
 
      }
181
 
   }
182
 
 
183
 
   public static void main(String[] args)
184
 
   {
185
 
      MultiThreadedSocketPerformanceClient test = new MultiThreadedSocketPerformanceClient();
186
 
      try
187
 
      {
188
 
         test.setUp();
189
 
         test.testClientCalls();
190
 
         test.tearDown();
191
 
      }
192
 
      catch(Throwable throwable)
193
 
      {
194
 
         throwable.printStackTrace();
195
 
      }
196
 
   }
197
 
 
198
 
 
199
 
}
 
 
b'\\ No newline at end of file'