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

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/stream/StreamingTestClient.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.stream;
24
 
 
25
 
import junit.framework.TestCase;
26
 
 
27
 
import org.apache.log4j.Logger;
28
 
import org.jboss.remoting.Client;
29
 
import org.jboss.remoting.InvokerLocator;
30
 
 
31
 
import java.io.File;
32
 
import java.io.FileInputStream;
33
 
import java.net.URL;
34
 
import java.util.Map;
35
 
 
36
 
/**
37
 
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
38
 
 */
39
 
public class StreamingTestClient extends TestCase
40
 
{
41
 
   private static Logger log = Logger.getLogger(StreamingTestClient.class);
42
 
   
43
 
   // Default locator values
44
 
   private static String transport = "socket";
45
 
   private static String host = "localhost";
46
 
   private static int port = 5400;
47
 
 
48
 
   private String locatorURI;
49
 
   private Client remotingClient = null;
50
 
   private File testFile = null;
51
 
   private FileInputStream fileInput = null;
52
 
 
53
 
   private boolean error = false;
54
 
 
55
 
   public void testStream() throws Throwable
56
 
   {
57
 
      for(int x = 0; x < 5; x++)
58
 
      {
59
 
//         new Thread(new Runnable() {
60
 
//            public void run()
61
 
//            {
62
 
//               try
63
 
//               {
64
 
                  sendStream();
65
 
//               }
66
 
//               catch (Throwable throwable)
67
 
//               {
68
 
//                  throwable.printStackTrace();
69
 
//                  error = true;
70
 
//               }
71
 
//            }
72
 
//         }).start();
73
 
      }
74
 
 
75
 
//      Thread.sleep(5000);
76
 
//      assertFalse(error);
77
 
      
78
 
      log.info("Waiting to give server a chance to send ");
79
 
      log.info("org.jboss.remoting.stream.StreamHandler.CLOSE message");
80
 
      Thread.sleep(5000);
81
 
   }
82
 
 
83
 
   public void sendStream() throws Throwable
84
 
   {
85
 
      URL fileURL = this.getClass().getResource("test.txt");
86
 
      if(fileURL == null)
87
 
      {
88
 
         throw new Exception("Can not find file test.txt");
89
 
      }
90
 
      testFile = new File(fileURL.getFile());
91
 
      fileInput = new FileInputStream(testFile);
92
 
 
93
 
      String param = "foobar";
94
 
      long fileLength = testFile.length();
95
 
      log.info("File size = " + fileLength);
96
 
      Object ret = remotingClient.invoke(fileInput, param);
97
 
 
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");
102
 
 
103
 
      assertEquals("test_stream".toUpperCase(), subSys);
104
 
      assertEquals(remotingClient.getSessionId(), clientId);
105
 
      assertEquals("foobar", paramVal);
106
 
 
107
 
      Object response = remotingClient.invoke("get_size");
108
 
      int returnedFileLength = ((Integer) response).intValue();
109
 
      log.info("Invocation response: " + response);
110
 
 
111
 
      if(fileLength == returnedFileLength)
112
 
      {
113
 
         log.info("PASS");
114
 
      }
115
 
      else
116
 
      {
117
 
         log.info("FAILED - returned file length was " + returnedFileLength);
118
 
      }
119
 
      assertEquals(fileLength, returnedFileLength);
120
 
   }
121
 
 
122
 
   public void setUp() throws Exception
123
 
   {
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);
128
 
 
129
 
      remotingClient = new Client(locator, "test_stream");
130
 
      remotingClient.connect();
131
 
   }
132
 
 
133
 
   public void tearDown() throws Exception
134
 
   {
135
 
      if(remotingClient != null)
136
 
      {
137
 
         remotingClient.disconnect();
138
 
      }
139
 
      if(fileInput != null)
140
 
      {
141
 
         fileInput.close();
142
 
      }
143
 
   }
144
 
 
145
 
   /**
146
 
    * Can pass transport and port to be used as parameters.
147
 
    * Valid transports are 'rmi' and 'socket'.
148
 
    *
149
 
    * @param args
150
 
    */
151
 
   public static void main(String[] args)
152
 
   {
153
 
      if(args != null && args.length == 2)
154
 
      {
155
 
         transport = args[0];
156
 
         port = Integer.parseInt(args[1]);
157
 
      }
158
 
      String locatorURI = transport + "://" + host + ":" + port;
159
 
      StreamingTestClient client = new StreamingTestClient();
160
 
      try
161
 
      {
162
 
         client.setUp();
163
 
         client.testStream();
164
 
         client.tearDown();
165
 
      }
166
 
      catch(Throwable e)
167
 
      {
168
 
         e.printStackTrace();
169
 
      }
170
 
   }
171
 
 
172
 
 
173
 
}
 
 
b'\\ No newline at end of file'