1 45 package org.exolab.jms.net.invoke; 46 47 import java.util.Map ; 48 49 import org.exolab.jms.net.Callback; 50 import org.exolab.jms.net.CallbackService; 51 import org.exolab.jms.net.CallbackServiceImpl; 52 import org.exolab.jms.net.orb.ORB; 53 import org.exolab.jms.net.proxy.Proxy; 54 import org.exolab.jms.net.registry.Registry; 55 56 57 63 public abstract class CallbackTestCase extends ORBTestCase { 64 65 68 private CallbackServiceImpl _service = new CallbackServiceImpl(); 69 70 73 private static final String CALLBACK_SERVICE = "callback"; 74 75 76 82 public CallbackTestCase(String name, String uri) { 83 super(name, uri); 84 } 85 86 93 public CallbackTestCase(String name, String uri, Map properties) { 94 super(name, uri, properties); 95 } 96 97 104 public CallbackTestCase(String name, String uri, String routeURI) { 105 super(name, uri, routeURI); 106 } 107 108 116 public CallbackTestCase(String name, String uri, String routeURI, 117 Map properties) { 118 super(name, uri, routeURI, properties); 119 } 120 121 130 public CallbackTestCase(String name, String uri, String routeURI, 131 Map connectionProps, Map acceptorProps) { 132 super(name, uri, routeURI, connectionProps, acceptorProps); 133 } 134 135 140 public void testCallback() throws Exception { 141 final int count = 10; 142 ORB client = getClientORB(); 143 Registry registry = client.getRegistry(getConnectionProperties()); 144 CallbackService service = 145 (CallbackService) registry.lookup(CALLBACK_SERVICE); 146 147 LoggingCallback callback = new LoggingCallback(); 148 Callback proxy = (Callback) client.exportObjectTo(callback, 149 getServerURI()); 150 service.addCallback(proxy); 151 152 for (int i = 0; i < count; ++i) { 153 _service.invoke(new Integer (i)); 154 } 155 156 Integer [] objects = (Integer []) callback.getObjects().toArray( 157 new Integer [0]); 158 assertEquals(count, objects.length); 159 for (int i = 0; i < count; ++i) { 160 assertEquals(i, objects[i].intValue()); 161 } 162 } 163 164 169 public void testRecursion() throws Exception { 170 final int count = 10; 171 final int depth = 4; 173 ORB client = getClientORB(); 174 Registry registry = client.getRegistry(getConnectionProperties()); 175 CallbackService service = 176 (CallbackService) registry.lookup(CALLBACK_SERVICE); 177 178 RecursiveCallback callback = new RecursiveCallback(service, depth); 179 Callback proxy = (Callback) client.exportObjectTo(callback, 180 getServerURI()); 181 service.addCallback(proxy); 182 183 for (int i = 0; i < count; ++i) { 184 _service.invoke(new Integer (i)); 185 } 186 187 Integer [] objects = (Integer []) callback.getObjects().toArray( 188 new Integer [0]); 189 assertEquals(count * depth, objects.length); 190 for (int i = 0, index = 0; i < count; ++i) { 191 for (int j = 0; j < depth; ++j, ++index) { 192 assertEquals(i, objects[index].intValue()); 193 } 194 } 195 } 196 197 202 protected void setUp() throws Exception { 203 super.setUp(); 204 205 ORB server = getORB(); 206 Proxy proxy = server.exportObject(_service); 207 server.getRegistry().bind(CALLBACK_SERVICE, proxy); 208 } 209 210 } 211 | Popular Tags |