Search in sources :

Example 1 with GreetMeLaterResponse

use of org.apache.hello_world_soap_http.types.GreetMeLaterResponse in project cxf by apache.

the class AsyncHTTPConduitTest method testTimeoutAsync.

@Test
public void testTimeoutAsync() throws Exception {
    updateAddressPort(g, PORT);
    HTTPConduit c = (HTTPConduit) ClientProxy.getClient(g).getConduit();
    c.getClient().setReceiveTimeout(3000);
    try {
        Response<GreetMeLaterResponse> future = g.greetMeLaterAsync(-5000L);
        future.get();
        fail();
    } catch (Exception ex) {
    // expected!!!
    }
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) GreetMeLaterResponse(org.apache.hello_world_soap_http.types.GreetMeLaterResponse) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 2 with GreetMeLaterResponse

use of org.apache.hello_world_soap_http.types.GreetMeLaterResponse in project cxf by apache.

the class AsyncHTTPConduitTest method testCallsAsync.

@Test
@Ignore("peformance test")
public void testCallsAsync() throws Exception {
    updateAddressPort(g, PORT);
    final int warmupIter = 5000;
    final int runIter = 5000;
    final CountDownLatch wlatch = new CountDownLatch(warmupIter);
    final boolean[] wdone = new boolean[warmupIter];
    @SuppressWarnings("unchecked") AsyncHandler<GreetMeLaterResponse>[] whandler = new AsyncHandler[warmupIter];
    for (int x = 0; x < warmupIter; x++) {
        final int c = x;
        whandler[x] = new AsyncHandler<GreetMeLaterResponse>() {

            public void handleResponse(Response<GreetMeLaterResponse> res) {
                try {
                    String s = res.get().getResponseType();
                    s = s.substring(s.lastIndexOf(' ') + 1);
                    if (c != Integer.parseInt(s)) {
                        System.out.println("Problem " + c + " != " + s);
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (ExecutionException e) {
                    e.printStackTrace();
                }
                wdone[c] = true;
                wlatch.countDown();
            }
        };
    }
    // warmup
    long start = System.currentTimeMillis();
    for (int x = 0; x < warmupIter; x++) {
        // builder.append("a");
        // long s1 = System.nanoTime();
        // System.out.println("aa1: " + s1);
        g.greetMeLaterAsync(x, whandler[x]);
    // long s2 = System.nanoTime();
    // System.out.println("aa2: " + s2 + " " + (s2 - s1));
    // System.out.println();
    }
    wlatch.await(30, TimeUnit.SECONDS);
    long end = System.currentTimeMillis();
    System.out.println("Warmup Total: " + (end - start) + " " + wlatch.getCount());
    for (int x = 0; x < warmupIter; x++) {
        if (!wdone[x]) {
            System.out.println("  " + x);
        }
    }
    if (wlatch.getCount() > 0) {
        Thread.sleep(1000000);
    }
    final CountDownLatch rlatch = new CountDownLatch(runIter);
    AsyncHandler<GreetMeLaterResponse> rhandler = new AsyncHandler<GreetMeLaterResponse>() {

        public void handleResponse(Response<GreetMeLaterResponse> res) {
            rlatch.countDown();
        }
    };
    start = System.currentTimeMillis();
    for (int x = 0; x < runIter; x++) {
        // builder.append("a");
        // long s1 = System.nanoTime();
        // System.out.println("aa1: " + s1);
        g.greetMeLaterAsync(x, rhandler);
    // long s2 = System.nanoTime();
    // System.out.println("aa2: " + s2 + " " + (s2 - s1));
    // System.out.println();
    }
    rlatch.await(30, TimeUnit.SECONDS);
    end = System.currentTimeMillis();
    System.out.println("Total: " + (end - start) + " " + rlatch.getCount());
}
Also used : AsyncHandler(javax.xml.ws.AsyncHandler) GreetMeLaterResponse(org.apache.hello_world_soap_http.types.GreetMeLaterResponse) CountDownLatch(java.util.concurrent.CountDownLatch) Endpoint(javax.xml.ws.Endpoint) GreetMeLaterResponse(org.apache.hello_world_soap_http.types.GreetMeLaterResponse) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) Response(javax.xml.ws.Response) ExecutionException(java.util.concurrent.ExecutionException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with GreetMeLaterResponse

use of org.apache.hello_world_soap_http.types.GreetMeLaterResponse in project cxf by apache.

the class ClientServerWebSocketTest method testAsyncSynchronousPolling.

@Test
public void testAsyncSynchronousPolling() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull(service);
    final String expectedString = new String("Hello, finally!");
    class Poller extends Thread {

        Response<GreetMeLaterResponse> response;

        int tid;

        Poller(Response<GreetMeLaterResponse> r, int t) {
            response = r;
            tid = t;
        }

        public void run() {
            if (tid % 2 > 0) {
                while (!response.isDone()) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException ex) {
                    // ignore
                    }
                }
            }
            GreetMeLaterResponse reply = null;
            try {
                reply = response.get();
            } catch (Exception ex) {
                fail("Poller " + tid + " failed with " + ex);
            }
            assertNotNull("Poller " + tid + ": no response received from service", reply);
            String s = reply.getResponseType();
            assertEquals(expectedString, s);
        }
    }
    Greeter greeter = service.getPort(portName, Greeter.class);
    updateGreeterAddress(greeter, PORT);
    long before = System.currentTimeMillis();
    long delay = 3000;
    Response<GreetMeLaterResponse> response = greeter.greetMeLaterAsync(delay);
    long after = System.currentTimeMillis();
    assertTrue("Duration of calls exceeded " + delay + " ms", after - before < delay);
    // first time round, responses should not be available yet
    assertFalse("Response already available.", response.isDone());
    Poller[] pollers = new Poller[4];
    for (int i = 0; i < pollers.length; i++) {
        pollers[i] = new Poller(response, i);
    }
    for (Poller p : pollers) {
        p.start();
    }
    for (Poller p : pollers) {
        p.join();
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) GreetMeLaterResponse(org.apache.hello_world_soap_http.types.GreetMeLaterResponse) URL(java.net.URL) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ExecutionException(java.util.concurrent.ExecutionException) GreetMeLaterResponse(org.apache.hello_world_soap_http.types.GreetMeLaterResponse) Response(javax.xml.ws.Response) Greeter(org.apache.hello_world_soap_http.Greeter) Test(org.junit.Test)

Example 4 with GreetMeLaterResponse

use of org.apache.hello_world_soap_http.types.GreetMeLaterResponse in project cxf by apache.

the class ClientServerWebSocketTest method testAsyncPollingCall.

@Test
public void testAsyncPollingCall() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    Greeter greeter = service.getPort(portName, Greeter.class);
    updateGreeterAddress(greeter, PORT);
    long before = System.currentTimeMillis();
    long delay = 3000;
    Response<GreetMeLaterResponse> r1 = greeter.greetMeLaterAsync(delay);
    Response<GreetMeLaterResponse> r2 = greeter.greetMeLaterAsync(delay);
    long after = System.currentTimeMillis();
    assertTrue("Duration of calls exceeded " + (2 * delay) + " ms", after - before < (2 * delay));
    // first time round, responses should not be available yet
    assertFalse("Response already available.", r1.isDone());
    assertFalse("Response already available.", r2.isDone());
    // after three seconds responses should be available
    long waited = 0;
    while (waited < (delay + 1000)) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException ex) {
        // ignore
        }
        if (r1.isDone() && r2.isDone()) {
            break;
        }
        waited += 500;
    }
    assertTrue("Response is  not available.", r1.isDone());
    assertTrue("Response is  not available.", r2.isDone());
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) Greeter(org.apache.hello_world_soap_http.Greeter) GreetMeLaterResponse(org.apache.hello_world_soap_http.types.GreetMeLaterResponse) URL(java.net.URL) Test(org.junit.Test)

Example 5 with GreetMeLaterResponse

use of org.apache.hello_world_soap_http.types.GreetMeLaterResponse in project cxf by apache.

the class ClientServerTest method testAsyncPollingCall.

@Test
public void testAsyncPollingCall() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull(service);
    Greeter greeter = service.getPort(portName, Greeter.class);
    assertNotNull(service);
    updateAddressPort(greeter, PORT);
    long before = System.currentTimeMillis();
    long delay = 3000;
    Response<GreetMeLaterResponse> r1 = greeter.greetMeLaterAsync(delay);
    Response<GreetMeLaterResponse> r2 = greeter.greetMeLaterAsync(delay);
    long after = System.currentTimeMillis();
    assertTrue("Duration of calls exceeded " + (2 * delay) + " ms", after - before < (2 * delay));
    // first time round, responses should not be available yet
    assertFalse("Response already available.", r1.isDone());
    assertFalse("Response already available.", r2.isDone());
    // after three seconds responses should be available
    long waited = 0;
    while (waited < (delay + 1000)) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException ex) {
        // ignore
        }
        if (r1.isDone() && r2.isDone()) {
            break;
        }
        waited += 500;
    }
    assertTrue("Response is  not available.", r1.isDone());
    assertTrue("Response is  not available.", r2.isDone());
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) Greeter(org.apache.hello_world_soap_http.Greeter) GreetMeLaterResponse(org.apache.hello_world_soap_http.types.GreetMeLaterResponse) URL(java.net.URL) SOAPServiceMultiPortTypeTest(org.apache.hello_world_soap_http.SOAPServiceMultiPortTypeTest) SOAPServiceBogusAddressTest(org.apache.hello_world_soap_http.SOAPServiceBogusAddressTest) Test(org.junit.Test)

Aggregations

GreetMeLaterResponse (org.apache.hello_world_soap_http.types.GreetMeLaterResponse)8 Test (org.junit.Test)8 URL (java.net.URL)5 ExecutionException (java.util.concurrent.ExecutionException)5 Greeter (org.apache.hello_world_soap_http.Greeter)5 SOAPService (org.apache.hello_world_soap_http.SOAPService)5 Response (javax.xml.ws.Response)4 SOAPServiceBogusAddressTest (org.apache.hello_world_soap_http.SOAPServiceBogusAddressTest)3 SOAPServiceMultiPortTypeTest (org.apache.hello_world_soap_http.SOAPServiceMultiPortTypeTest)3 GreetMeResponse (org.apache.hello_world_soap_http.types.GreetMeResponse)3 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)2 AsyncHandler (javax.xml.ws.AsyncHandler)2 Endpoint (javax.xml.ws.Endpoint)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 WebServiceException (javax.xml.ws.WebServiceException)1 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)1 BareDocumentResponse (org.apache.hello_world_soap_http.types.BareDocumentResponse)1 Ignore (org.junit.Ignore)1