1 7 package org.jboss.test.remoting.stream; 8 9 import java.io.File ; 10 import java.io.FileInputStream ; 11 import java.net.URL ; 12 import org.jboss.remoting.Client; 13 import org.jboss.remoting.InvokerLocator; 14 15 import junit.framework.TestCase; 16 17 20 public class StreamingTestClient extends TestCase 21 { 22 private static String transport = "socket"; 24 private static String host = "localhost"; 25 private static int port = 5400; 26 27 private String locatorURI = transport + "://" + host + ":" + port; 28 private Client remotingClient = null; 29 private File testFile = null; 30 private FileInputStream fileInput = null; 31 32 public void testStream() throws Throwable 33 { 34 URL fileURL = this.getClass().getResource("test.txt"); 35 if(fileURL == null) 36 { 37 throw new Exception ("Can not find file test.txt"); 38 } 39 testFile = new File (fileURL.getFile()); 40 fileInput = new FileInputStream (testFile); 41 42 String param = "foobar"; 43 long fileLength = testFile.length(); 44 System.out.println("File size = " + fileLength); 45 Object ret = remotingClient.invoke(fileInput, param); 46 47 assertEquals(param, ret); 48 49 Object response = remotingClient.invoke("get_size"); 50 int returnedFileLength = ((Integer )response).intValue(); 51 System.out.println("Invocation response: " + response); 52 53 if(fileLength == returnedFileLength) 54 { 55 System.out.println("PASS"); 56 } 57 else 58 { 59 System.out.println("FAILED - returned file length was " + returnedFileLength); 60 } 61 assertEquals(fileLength, returnedFileLength); 62 } 63 64 public void setUp() throws Exception 65 { 66 InvokerLocator locator = new InvokerLocator(locatorURI); 67 System.out.println("Calling remoting server with locator uri of: " + locatorURI); 68 69 remotingClient = new Client(locator); 70 } 71 72 public void tearDown() throws Exception 73 { 74 if(remotingClient != null) 75 { 76 remotingClient.disconnect(); 77 } 78 if(fileInput != null) 79 { 80 fileInput.close(); 81 } 82 } 83 84 90 public static void main(String [] args) 91 { 92 if(args != null && args.length == 2) 93 { 94 transport = args[0]; 95 port = Integer.parseInt(args[1]); 96 } 97 String locatorURI = transport + "://" + host + ":" + port; 98 StreamingTestClient client = new StreamingTestClient(); 99 try 100 { 101 client.setUp(); 102 client.testStream(); 103 client.tearDown(); 104 } 105 catch(Throwable e) 106 { 107 e.printStackTrace(); 108 } 109 } 110 111 112 } | Popular Tags |