001: package org.objectweb.celtix.systest.stress.concurrency;
002:
003: import java.net.URL;
004:
005: import javax.xml.namespace.QName;
006:
007: import junit.framework.Test;
008: import junit.framework.TestSuite;
009:
010: import org.objectweb.celtix.systest.common.ClientServerSetupBase;
011: import org.objectweb.celtix.systest.common.ClientServerTestBase;
012: import org.objectweb.hello_world_soap_http.BadRecordLitFault;
013: import org.objectweb.hello_world_soap_http.Greeter;
014: import org.objectweb.hello_world_soap_http.NoSuchCodeLitFault;
015: import org.objectweb.hello_world_soap_http.SOAPService;
016:
017: public class ConcurrentInvokerTest extends ClientServerTestBase {
018:
019: static final int INVOKER_COUNT = 5;
020: static final int INVOCATION_REPS = 50;
021: static final int EXPECTED_CALLS = INVOKER_COUNT * INVOCATION_REPS;
022:
023: Greeter greeter;
024: private final QName serviceName = new QName(
025: "http://objectweb.org/hello_world_soap_http",
026: "SOAPServiceConcurrencyTest");
027: private final QName portName = new QName(
028: "http://objectweb.org/hello_world_soap_http", "SoapPort");
029:
030: public static void main(String[] args) {
031: junit.textui.TestRunner.run(ConcurrentInvokerTest.class);
032: }
033:
034: public static Test suite() throws Exception {
035: TestSuite suite = new TestSuite(ConcurrentInvokerTest.class);
036: return new ClientServerSetupBase(suite) {
037: public void startServers() throws Exception {
038: assertTrue("server did not launch correctly",
039: launchServer(Server.class));
040: }
041: };
042: }
043:
044: public void setUp() throws Exception {
045: super .setUp();
046: URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
047: SOAPService service = new SOAPService(wsdl, serviceName);
048: greeter = service.getPort(portName, Greeter.class);
049: }
050:
051: public void testConcurrentInvocation() throws Exception {
052: waitFor(launch(populateInvokers()));
053: }
054:
055: private Thread[] populateInvokers() {
056: Thread[] invokers = new Thread[INVOKER_COUNT * 3];
057: for (int i = 0; i < INVOKER_COUNT * 3; i++) {
058: String s = "Invoker[" + i + "]";
059: switch (i / INVOKER_COUNT) {
060: case 0:
061: invokers[i] = new Thread(new TwoWayInvoker(), "TwoWay"
062: + s);
063: break;
064: case 1:
065: invokers[i] = new Thread(new OneWayInvoker(), "OneWay"
066: + s);
067: break;
068: case 2:
069: invokers[i] = new Thread(new FaultInvoker(), "Fault"
070: + s);
071: break;
072: default:
073: }
074: }
075: return invokers;
076: }
077:
078: private Thread[] launch(Thread[] invokers) {
079: for (int i = 0; i < invokers.length; i++) {
080: invokers[i].start();
081: }
082: return invokers;
083: }
084:
085: private void waitFor(Thread[] invokers) {
086: for (int i = 0; i < invokers.length; i++) {
087: try {
088: invokers[i].join();
089: } catch (InterruptedException ie) {
090: // ignore
091: }
092: }
093: // stop the server here, instead of relying on the shutdown hook
094: // installed by the base class, as this would be too late to assert
095: // via junit that server received the expected number of calls
096: //assertTrue("server failed, see log for details", stopAllServers());
097: }
098:
099: private class TwoWayInvoker implements Runnable {
100: public void run() {
101: String root = Thread.currentThread().getName() + " call: ";
102: for (int i = 0; i < INVOCATION_REPS; i++) {
103: String in = root + i;
104: String greeting = greeter.greetMe(in);
105: assertNotNull("no response received from service",
106: greeting);
107: assertEquals("Hello " + in, greeting);
108: String hi = greeter.sayHi();
109: assertNotNull("no response received from service", hi);
110: assertEquals("Hiya", hi);
111: }
112: }
113: }
114:
115: private class OneWayInvoker implements Runnable {
116: public void run() {
117: String root = Thread.currentThread().getName() + " call: ";
118: for (int i = 0; i < INVOCATION_REPS; i++) {
119: String in = root + i;
120: greeter.greetMeOneWay(in);
121: }
122: }
123: }
124:
125: private class FaultInvoker implements Runnable {
126: public void run() {
127: String fault = NoSuchCodeLitFault.class.getSimpleName();
128: for (int i = 0; i < INVOCATION_REPS; i++) {
129: try {
130: greeter.testDocLitFault(fault);
131: fail("Should have thrown NoSuchCodeLitFault exception");
132: } catch (NoSuchCodeLitFault nslf) {
133: assertNotNull(nslf.getFaultInfo());
134: assertNotNull(nslf.getFaultInfo().getCode());
135: } catch (BadRecordLitFault brlf) {
136: fail("unexpected fault: " + brlf);
137: }
138: }
139: }
140: }
141: }
|