1 7 package org.jboss.test.remoting.oneway; 8 9 import java.rmi.server.UID ; 10 import org.jboss.logging.Logger; 11 import org.jboss.remoting.Client; 12 import org.jboss.remoting.InvokerLocator; 13 import org.jboss.remoting.invocation.NameBasedInvocation; 14 15 import junit.framework.TestCase; 16 17 22 public class OnewayInvokerClientTest extends TestCase 23 { 24 private static final Logger log = Logger.getLogger(OnewayInvokerClientTest.class); 25 26 private String transport = "socket"; 27 private int port = 8081; 28 29 private String sessionId = new UID ().toString(); 30 31 private Client client; 32 33 public void init() 34 { 35 try 36 { 37 InvokerLocator locator = new InvokerLocator(transport + "://localhost:" + port); 38 client = new Client(locator, "test"); 39 client.connect(); 40 } 41 catch(Exception e) 42 { 43 log.error(e.getMessage(), e); 44 } 45 } 46 47 public void setUp() throws Exception 48 { 49 init(); 50 } 51 52 public void tearDown() throws Exception 53 { 54 if(client != null) 55 { 56 client.disconnect(); 57 } 58 } 59 60 65 public void testOnewayServerInvocation() throws Throwable 66 { 67 log.debug("running testOnewayClientCallback()"); 68 69 sessionId = client.getSessionId(); 70 71 log.debug("client.getInvoker().getLocator()" + client.getInvoker().getLocator()); 72 73 String param = "bar"; 75 makeServerOnewayInvocation("saveInvocationParameter", param); 76 Thread.currentThread().sleep(1000); 77 Object obj = makeInvocation("getLastInvocationParameter", null); 78 79 checkAssertion(param, obj); 80 } 81 82 protected void checkAssertion(String param, Object obj) 83 { 84 assertEquals(param, obj); 85 } 86 87 protected void makeServerOnewayInvocation(String method, String param) throws Throwable 88 { 89 client.invokeOneway(new NameBasedInvocation(method, 90 new Object []{param}, 91 new String []{String .class.getName()}), 92 null, 93 false); 94 95 } 96 97 102 public void testOnewayClientInvocation() throws Throwable 103 { 104 log.debug("running testOnewayClientCallback()"); 105 106 sessionId = client.getSessionId(); 107 108 log.debug("client.getInvoker().getLocator()" + client.getInvoker().getLocator()); 109 110 111 String param = "bar"; 113 makeClientOnewayInvocation("saveInvocationParameter", param); 114 Thread.currentThread().sleep(1000); 115 Object obj = makeInvocation("getLastInvocationParameter", null); 116 117 checkAssertion(param, obj); 118 119 } 120 121 126 public void testClientInvocation() throws Throwable 127 { 128 log.debug("running testInvocation()"); 129 130 sessionId = client.getSessionId(); 131 132 log.debug("client.getInvoker().getLocator()" + client.getInvoker().getLocator()); 133 134 String param = "bar"; 136 Object resp = makeClientInvocation("saveInvocationParameter", param); 137 138 Object obj = makeInvocation("getLastInvocationParameter", null); 139 Thread.currentThread().sleep(1000); 140 checkAssertion(param, obj); 141 142 } 143 144 protected void makeClientOnewayInvocation(String method, String param) throws Throwable 145 { 146 client.invokeOneway(new NameBasedInvocation(method, 147 new Object []{param}, 148 new String []{String .class.getName()}), 149 null, 150 true); 151 152 } 153 154 protected Object makeClientInvocation(String method, String param) throws Throwable 155 { 156 Object ret = client.invoke(new NameBasedInvocation(method, 157 new Object []{param}, 158 new String []{String .class.getName()}), 159 null); 160 161 return ret; 162 } 163 164 165 protected Object makeInvocation(String method, String param) throws Throwable 166 { 167 Object ret = client.invoke(new NameBasedInvocation(method, 168 new Object []{param}, 169 new String []{String .class.getName()}), 170 null); 171 172 return ret; 173 } 174 175 176 } 177 | Popular Tags |