1 package org.objectweb.celtix.systest.stress.concurrency; 2 3 import java.net.URL ; 4 5 import javax.xml.namespace.QName ; 6 7 import junit.framework.Test; 8 import junit.framework.TestSuite; 9 10 import org.objectweb.celtix.systest.common.ClientServerSetupBase; 11 import org.objectweb.celtix.systest.common.ClientServerTestBase; 12 import org.objectweb.hello_world_soap_http.BadRecordLitFault; 13 import org.objectweb.hello_world_soap_http.Greeter; 14 import org.objectweb.hello_world_soap_http.NoSuchCodeLitFault; 15 import org.objectweb.hello_world_soap_http.SOAPService; 16 17 public class ConcurrentInvokerTest extends ClientServerTestBase { 18 19 static final int INVOKER_COUNT = 5; 20 static final int INVOCATION_REPS = 50; 21 static final int EXPECTED_CALLS = INVOKER_COUNT * INVOCATION_REPS; 22 23 Greeter greeter; 24 private final QName serviceName = new QName ("http://objectweb.org/hello_world_soap_http", 25 "SOAPServiceConcurrencyTest"); 26 private final QName portName = new QName ("http://objectweb.org/hello_world_soap_http", "SoapPort"); 27 28 public static void main(String [] args) { 29 junit.textui.TestRunner.run(ConcurrentInvokerTest.class); 30 } 31 public static Test suite() throws Exception { 32 TestSuite suite = new TestSuite(ConcurrentInvokerTest.class); 33 return new ClientServerSetupBase(suite) { 34 public void startServers() throws Exception { 35 assertTrue("server did not launch correctly", launchServer(Server.class)); 36 } 37 }; 38 } 39 40 public void setUp() throws Exception { 41 super.setUp(); 42 URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl"); 43 SOAPService service = new SOAPService(wsdl, serviceName); 44 greeter = service.getPort(portName, Greeter.class); 45 } 46 47 public void testConcurrentInvocation() throws Exception { 48 waitFor(launch(populateInvokers())); 49 } 50 51 private Thread [] populateInvokers() { 52 Thread [] invokers = new Thread [INVOKER_COUNT * 3]; 53 for (int i = 0; i < INVOKER_COUNT * 3; i++) { 54 String s = "Invoker[" + i + "]"; 55 switch (i / INVOKER_COUNT) { 56 case 0: 57 invokers[i] = new Thread (new TwoWayInvoker(), "TwoWay" + s); 58 break; 59 case 1: 60 invokers[i] = new Thread (new OneWayInvoker(), "OneWay" + s); 61 break; 62 case 2: 63 invokers[i] = new Thread (new FaultInvoker(), "Fault" + s); 64 break; 65 default: 66 } 67 } 68 return invokers; 69 } 70 71 private Thread [] launch(Thread [] invokers) { 72 for (int i = 0; i < invokers.length; i++) { 73 invokers[i].start(); 74 } 75 return invokers; 76 } 77 78 private void waitFor(Thread [] invokers) { 79 for (int i = 0; i < invokers.length; i++) { 80 try { 81 invokers[i].join(); 82 } catch (InterruptedException ie) { 83 } 85 } 86 } 91 92 private class TwoWayInvoker implements Runnable { 93 public void run() { 94 String root = Thread.currentThread().getName() + " call: "; 95 for (int i = 0; i < INVOCATION_REPS; i++) { 96 String in = root + i; 97 String greeting = greeter.greetMe(in); 98 assertNotNull("no response received from service", greeting); 99 assertEquals("Hello " + in, greeting); 100 String hi = greeter.sayHi(); 101 assertNotNull("no response received from service", hi); 102 assertEquals("Hiya", hi); 103 } 104 } 105 } 106 107 private class OneWayInvoker implements Runnable { 108 public void run() { 109 String root = Thread.currentThread().getName() + " call: "; 110 for (int i = 0; i < INVOCATION_REPS; i++) { 111 String in = root + i; 112 greeter.greetMeOneWay(in); 113 } 114 } 115 } 116 117 private class FaultInvoker implements Runnable { 118 public void run() { 119 String fault = NoSuchCodeLitFault.class.getSimpleName(); 120 for (int i = 0; i < INVOCATION_REPS; i++) { 121 try { 122 greeter.testDocLitFault(fault); 123 fail("Should have thrown NoSuchCodeLitFault exception"); 124 } catch (NoSuchCodeLitFault nslf) { 125 assertNotNull(nslf.getFaultInfo()); 126 assertNotNull(nslf.getFaultInfo().getCode()); 127 } catch (BadRecordLitFault brlf) { 128 fail("unexpected fault: " + brlf); 129 } 130 } 131 } 132 } 133 } 134 | Popular Tags |