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

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/transport/socket/raw/RawTestClient.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
 
package org.jboss.test.remoting.transport.socket.raw;
2
 
 
3
 
import junit.framework.TestCase;
4
 
 
5
 
import java.io.BufferedInputStream;
6
 
import java.io.BufferedOutputStream;
7
 
import java.io.IOException;
8
 
import java.io.InputStream;
9
 
import java.io.ObjectInputStream;
10
 
import java.io.ObjectOutputStream;
11
 
import java.io.OutputStream;
12
 
import java.net.Socket;
13
 
 
14
 
import org.jboss.remoting.Version;
15
 
 
16
 
/**
17
 
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
18
 
 */
19
 
public class RawTestClient extends TestCase
20
 
{
21
 
   protected String address = "localhost";
22
 
   protected int port = 6700;
23
 
 
24
 
   public boolean enableTcpNoDelay = false;
25
 
   public int timeout = 60000;
26
 
 
27
 
   private Socket socket = null;
28
 
 
29
 
   private OutputStream out;
30
 
   private InputStream in;
31
 
   private ObjectOutputStream oos;
32
 
   private ObjectInputStream objInputStream;
33
 
 
34
 
   public void testRawInvocation()
35
 
   {
36
 
      makeRawInvocation();
37
 
      makeRawInvocation();
38
 
   }
39
 
 
40
 
   public void makeRawInvocation()
41
 
   {
42
 
      // In response to JBREM-692 (Let marshallers/unmarshallers construct
43
 
      // their preferred streams.), some changes are necessary to make this
44
 
      // test work.  SerializableMarshaller and SerializableUnMarshaller now
45
 
      // implement the method getMarshallingStream(), which allows
46
 
      // ClientSocketWrapper and ServerSocketWrapper to get object streams
47
 
      // when they are created and cache them for future use, instead of
48
 
      // recreating them with each invocation.
49
 
      
50
 
         try
51
 
         {
52
 
            getSocket();
53
 
            
54
 
            // Write version.
55
 
//          out.write(1);
56
 
            oos.write(Version.getDefaultVersion());
57
 
            out.flush();
58
 
            
59
 
            // Write invocation.
60
 
//          oos = new ObjectOutputStream(out);
61
 
            oos.reset();
62
 
            oos.writeObject("This is the request");
63
 
            oos.flush();
64
 
 
65
 
            // Get response.
66
 
//          objInputStream = new ObjectInputStream(in);
67
 
            Object obj = objInputStream.readObject();
68
 
            System.out.println("response: " + obj);
69
 
            assertEquals(RawTestServer.RESPONSE, obj);
70
 
            System.out.println("PASSED");
71
 
         }
72
 
         catch(IOException e)
73
 
         {
74
 
            e.printStackTrace();
75
 
            fail();
76
 
         }
77
 
         catch(ClassNotFoundException e)
78
 
         {
79
 
            e.printStackTrace();
80
 
            fail();
81
 
         }
82
 
 
83
 
   }
84
 
 
85
 
   public void getSocket() throws IOException
86
 
   {
87
 
      if(socket == null)
88
 
      {
89
 
         try
90
 
         {
91
 
            socket = new Socket(address, port);
92
 
            socket.setTcpNoDelay(enableTcpNoDelay);
93
 
//            socket.setSoTimeout(timeout);
94
 
 
95
 
            out = new BufferedOutputStream(socket.getOutputStream());
96
 
            in = new BufferedInputStream(socket.getInputStream());
97
 
            oos = new ObjectOutputStream(out);
98
 
            objInputStream = new ObjectInputStream(in);
99
 
         }
100
 
         catch(IOException e)
101
 
         {
102
 
            e.printStackTrace();
103
 
         }
104
 
      }
105
 
      else
106
 
      {
107
 
//         oos.reset();
108
 
//         oos.writeByte(1);
109
 
//         oos.flush();
110
 
//         oos.reset();
111
 
//         objInputStream.readByte();
112
 
//         objInputStream.reset();
113
 
      }
114
 
   }
115
 
 
116
 
   public static void main(String[] args)
117
 
   {
118
 
      RawTestClient client = new RawTestClient();
119
 
      client.testRawInvocation();
120
 
   }
121
 
}