Search in sources :

Example 6 with SimpleCompletionCallback

use of com.sun.xml.ws.api.pipe.EngineTest.SimpleCompletionCallback in project metro-jax-ws by eclipse-ee4j.

the class FiberTest method testSuspendNextRunnableResumeAndReturn.

public void testSuspendNextRunnableResumeAndReturn() throws InterruptedException {
    final Semaphore atSuspend = new Semaphore(0);
    final Semaphore checkCompleted = new Semaphore(0);
    final Semaphore atEnd = new Semaphore(0);
    final TestTube tubeC = new TestTube();
    final FilterTestTube tubeB = new FilterTestTube(tubeC) {

        @Override
        @NotNull
        public NextAction processRequest(@NotNull Packet request) {
            super.processRequest(request);
            return doSuspend(next, new Runnable() {

                @Override
                public void run() {
                    atSuspend.release();
                    try {
                        checkCompleted.acquire();
                    } catch (InterruptedException e) {
                    }
                }
            });
        }
    };
    final FilterTestTube tubeA = new FilterTestTube(tubeB);
    final Packet request = new Packet();
    final SimpleCompletionCallback callback = new SimpleCompletionCallback() {

        @Override
        public void onCompletion(@NotNull Packet response) {
            super.onCompletion(response);
            atEnd.release();
        }

        @Override
        public void onCompletion(@NotNull Throwable error) {
            super.onCompletion(error);
            atEnd.release();
        }
    };
    final Fiber fiber = threadPoolEngine.createFiber();
    assertNotNull(fiber);
    fiber.start(tubeA, request, callback);
    if (!atSuspend.tryAcquire(3, TimeUnit.MINUTES))
        fail("timeout");
    // ensure test thread really blocked
    assertEquals(0, atEnd.availablePermits());
    // thread is suspended
    assertNull(callback.response);
    assertNull(callback.error);
    List<TubeCall> calls = tubeA.getCalls();
    assertNotNull(calls);
    assertEquals(1, calls.size());
    TubeCall firstCall = calls.get(0);
    assertNotNull(firstCall);
    assertEquals(TubeCallType.REQUEST, firstCall.callType);
    assertEquals(testContainer, firstCall.container);
    calls = tubeB.getCalls();
    assertNotNull(calls);
    assertEquals(1, calls.size());
    firstCall = calls.get(0);
    assertNotNull(firstCall);
    assertEquals(TubeCallType.REQUEST, firstCall.callType);
    assertEquals(testContainer, firstCall.container);
    calls = tubeC.getCalls();
    assertNotNull(calls);
    assertEquals(0, calls.size());
    checkCompleted.release();
    fiber.resumeAndReturn(request, false);
    if (!atEnd.tryAcquire(3, TimeUnit.MINUTES))
        fail("timeout");
    assertEquals(request, callback.response);
    assertNull(callback.error);
    calls = tubeA.getCalls();
    assertNotNull(calls);
    assertEquals(2, calls.size());
    firstCall = calls.get(0);
    assertNotNull(firstCall);
    assertEquals(TubeCallType.REQUEST, firstCall.callType);
    assertEquals(testContainer, firstCall.container);
    TubeCall secondCall = calls.get(1);
    assertNotNull(secondCall);
    assertEquals(TubeCallType.RESPONSE, secondCall.callType);
    assertEquals(testContainer, secondCall.container);
    calls = tubeB.getCalls();
    assertNotNull(calls);
    assertEquals(2, calls.size());
    firstCall = calls.get(0);
    assertNotNull(firstCall);
    assertEquals(TubeCallType.REQUEST, firstCall.callType);
    assertEquals(testContainer, firstCall.container);
    secondCall = calls.get(1);
    assertNotNull(secondCall);
    assertEquals(TubeCallType.RESPONSE, secondCall.callType);
    assertEquals(testContainer, secondCall.container);
    calls = tubeC.getCalls();
    assertNotNull(calls);
    assertEquals(0, calls.size());
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) TubeCall(com.sun.xml.ws.api.pipe.EngineTest.TubeCall) Semaphore(java.util.concurrent.Semaphore) NotNull(com.sun.istack.NotNull) TestTube(com.sun.xml.ws.api.pipe.EngineTest.TestTube) SimpleCompletionCallback(com.sun.xml.ws.api.pipe.EngineTest.SimpleCompletionCallback)

Example 7 with SimpleCompletionCallback

use of com.sun.xml.ws.api.pipe.EngineTest.SimpleCompletionCallback in project metro-jax-ws by eclipse-ee4j.

the class FiberTest method testCancel.

public void testCancel() throws InterruptedException {
    final Semaphore atResponse = new Semaphore(0);
    final Semaphore mayProceed = new Semaphore(0);
    TestTube tubeC = new TestTube();
    FilterTestTube tubeB = new FilterTestTube(tubeC) {

        @Override
        @NotNull
        public NextAction processResponse(@NotNull Packet response) {
            try {
                atResponse.release();
                mayProceed.acquire();
            } catch (InterruptedException e) {
                throw new WebServiceException(e);
            }
            return super.processResponse(response);
        }
    };
    final FilterTestTube tubeA = new FilterTestTube(tubeB);
    final Packet request = new Packet();
    final SimpleCompletionCallback callback = new SimpleCompletionCallback();
    final Fiber fiber = engine.createFiber();
    assertNotNull(fiber);
    Thread testThread = new Thread(new Runnable() {

        @Override
        public void run() {
            fiber.start(tubeA, request, callback, true);
        }
    });
    testThread.start();
    if (!atResponse.tryAcquire(3, TimeUnit.MINUTES))
        fail("timeout");
    fiber.cancel(false);
    mayProceed.release();
    testThread.join(3 * 60 * 1000);
    assertNull(callback.response);
    assertNull(callback.error);
    List<TubeCall> calls = tubeA.getCalls();
    assertNotNull(calls);
    assertEquals(1, calls.size());
    TubeCall firstCall = calls.get(0);
    assertNotNull(firstCall);
    assertEquals(TubeCallType.REQUEST, firstCall.callType);
    assertEquals(testContainer, firstCall.container);
    calls = tubeB.getCalls();
    assertNotNull(calls);
    assertEquals(2, calls.size());
    firstCall = calls.get(0);
    assertNotNull(firstCall);
    assertEquals(TubeCallType.REQUEST, firstCall.callType);
    assertEquals(testContainer, firstCall.container);
    TubeCall secondCall = calls.get(1);
    assertNotNull(secondCall);
    assertEquals(TubeCallType.RESPONSE, secondCall.callType);
    assertEquals(testContainer, secondCall.container);
    calls = tubeC.getCalls();
    assertNotNull(calls);
    assertEquals(1, calls.size());
    firstCall = calls.get(0);
    assertNotNull(firstCall);
    assertEquals(TubeCallType.REQUEST, firstCall.callType);
    assertEquals(testContainer, firstCall.container);
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) WebServiceException(jakarta.xml.ws.WebServiceException) TubeCall(com.sun.xml.ws.api.pipe.EngineTest.TubeCall) Semaphore(java.util.concurrent.Semaphore) NotNull(com.sun.istack.NotNull) TestTube(com.sun.xml.ws.api.pipe.EngineTest.TestTube) SimpleCompletionCallback(com.sun.xml.ws.api.pipe.EngineTest.SimpleCompletionCallback)

Example 8 with SimpleCompletionCallback

use of com.sun.xml.ws.api.pipe.EngineTest.SimpleCompletionCallback in project metro-jax-ws by eclipse-ee4j.

the class FiberTest method testSuspendNextRunnableResumeThrowable.

public void testSuspendNextRunnableResumeThrowable() throws InterruptedException {
    final Semaphore atSuspend = new Semaphore(0);
    final Semaphore checkCompleted = new Semaphore(0);
    final Semaphore atEnd = new Semaphore(0);
    final TestTube tubeC = new TestTube();
    final FilterTestTube tubeB = new FilterTestTube(tubeC) {

        @Override
        @NotNull
        public NextAction processRequest(@NotNull Packet request) {
            super.processRequest(request);
            return doSuspend(next, new Runnable() {

                @Override
                public void run() {
                    atSuspend.release();
                    try {
                        checkCompleted.acquire();
                    } catch (InterruptedException e) {
                    }
                }
            });
        }
    };
    final FilterTestTube tubeA = new FilterTestTube(tubeB);
    final Packet request = new Packet();
    final SimpleCompletionCallback callback = new SimpleCompletionCallback() {

        @Override
        public void onCompletion(@NotNull Packet response) {
            super.onCompletion(response);
            atEnd.release();
        }

        @Override
        public void onCompletion(@NotNull Throwable error) {
            super.onCompletion(error);
            atEnd.release();
        }
    };
    final Fiber fiber = threadPoolEngine.createFiber();
    assertNotNull(fiber);
    fiber.start(tubeA, request, callback);
    if (!atSuspend.tryAcquire(3, TimeUnit.MINUTES))
        fail("timeout");
    // ensure test thread really blocked
    assertEquals(0, atEnd.availablePermits());
    // thread is suspended
    assertNull(callback.response);
    assertNull(callback.error);
    List<TubeCall> calls = tubeA.getCalls();
    assertNotNull(calls);
    assertEquals(1, calls.size());
    TubeCall firstCall = calls.get(0);
    assertNotNull(firstCall);
    assertEquals(TubeCallType.REQUEST, firstCall.callType);
    assertEquals(testContainer, firstCall.container);
    calls = tubeB.getCalls();
    assertNotNull(calls);
    assertEquals(1, calls.size());
    firstCall = calls.get(0);
    assertNotNull(firstCall);
    assertEquals(TubeCallType.REQUEST, firstCall.callType);
    assertEquals(testContainer, firstCall.container);
    calls = tubeC.getCalls();
    assertNotNull(calls);
    assertEquals(0, calls.size());
    checkCompleted.release();
    fiber.resume(new RuntimeException());
    if (!atEnd.tryAcquire(3, TimeUnit.MINUTES))
        fail("timeout");
    assertNull(callback.response);
    assertTrue(callback.error instanceof RuntimeException);
    calls = tubeA.getCalls();
    assertNotNull(calls);
    assertEquals(2, calls.size());
    firstCall = calls.get(0);
    assertNotNull(firstCall);
    assertEquals(TubeCallType.REQUEST, firstCall.callType);
    assertEquals(testContainer, firstCall.container);
    TubeCall secondCall = calls.get(1);
    assertNotNull(secondCall);
    assertEquals(TubeCallType.EXCEPTION, secondCall.callType);
    assertEquals(testContainer, secondCall.container);
    calls = tubeB.getCalls();
    assertNotNull(calls);
    assertEquals(2, calls.size());
    firstCall = calls.get(0);
    assertNotNull(firstCall);
    assertEquals(TubeCallType.REQUEST, firstCall.callType);
    assertEquals(testContainer, firstCall.container);
    secondCall = calls.get(1);
    assertNotNull(secondCall);
    assertEquals(TubeCallType.EXCEPTION, secondCall.callType);
    assertEquals(testContainer, secondCall.container);
    calls = tubeC.getCalls();
    assertNotNull(calls);
    assertEquals(0, calls.size());
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) TubeCall(com.sun.xml.ws.api.pipe.EngineTest.TubeCall) Semaphore(java.util.concurrent.Semaphore) NotNull(com.sun.istack.NotNull) TestTube(com.sun.xml.ws.api.pipe.EngineTest.TestTube) SimpleCompletionCallback(com.sun.xml.ws.api.pipe.EngineTest.SimpleCompletionCallback)

Example 9 with SimpleCompletionCallback

use of com.sun.xml.ws.api.pipe.EngineTest.SimpleCompletionCallback in project metro-jax-ws by eclipse-ee4j.

the class FiberTest method testNextActionThrowAbortResponse.

public void testNextActionThrowAbortResponse() {
    TestTube tubeC = new TestTube() {

        @Override
        @NotNull
        public NextAction processRequest(@NotNull Packet request) {
            super.processRequest(request);
            NextAction na = new NextAction();
            na.throwExceptionAbortResponse(new RuntimeException());
            return na;
        }
    };
    FilterTestTube tubeB = new FilterTestTube(tubeC);
    FilterTestTube tubeA = new FilterTestTube(tubeB);
    Packet request = new Packet();
    SimpleCompletionCallback callback = new SimpleCompletionCallback();
    Fiber fiber = engine.createFiber();
    assertNotNull(fiber);
    fiber.start(tubeA, request, callback, true);
    assertNull(callback.response);
    assertTrue(callback.error instanceof RuntimeException);
    List<TubeCall> calls = tubeA.getCalls();
    assertNotNull(calls);
    assertEquals(1, calls.size());
    TubeCall firstCall = calls.get(0);
    assertNotNull(firstCall);
    assertEquals(TubeCallType.REQUEST, firstCall.callType);
    assertEquals(testContainer, firstCall.container);
    calls = tubeB.getCalls();
    assertNotNull(calls);
    assertEquals(1, calls.size());
    firstCall = calls.get(0);
    assertNotNull(firstCall);
    assertEquals(TubeCallType.REQUEST, firstCall.callType);
    assertEquals(testContainer, firstCall.container);
    calls = tubeC.getCalls();
    assertNotNull(calls);
    assertEquals(1, calls.size());
    firstCall = calls.get(0);
    assertNotNull(firstCall);
    assertEquals(TubeCallType.REQUEST, firstCall.callType);
    assertEquals(testContainer, firstCall.container);
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) TestTube(com.sun.xml.ws.api.pipe.EngineTest.TestTube) TubeCall(com.sun.xml.ws.api.pipe.EngineTest.TubeCall) SimpleCompletionCallback(com.sun.xml.ws.api.pipe.EngineTest.SimpleCompletionCallback) NotNull(com.sun.istack.NotNull)

Example 10 with SimpleCompletionCallback

use of com.sun.xml.ws.api.pipe.EngineTest.SimpleCompletionCallback in project metro-jax-ws by eclipse-ee4j.

the class FiberTest method testNextActionInvokeAndForget.

public void testNextActionInvokeAndForget() {
    TestTube tubeC = new TestTube();
    FilterTestTube tubeB = new FilterTestTube(tubeC) {

        @Override
        @NotNull
        public NextAction processRequest(@NotNull Packet request) {
            super.processRequest(request);
            return doInvokeAndForget(next, request);
        }
    };
    FilterTestTube tubeA = new FilterTestTube(tubeB);
    Packet request = new Packet();
    SimpleCompletionCallback callback = new SimpleCompletionCallback();
    Fiber fiber = engine.createFiber();
    assertNotNull(fiber);
    fiber.start(tubeA, request, callback, true);
    assertEquals(request, callback.response);
    assertNull(callback.error);
    List<TubeCall> calls = tubeA.getCalls();
    assertNotNull(calls);
    assertEquals(2, calls.size());
    TubeCall firstCall = calls.get(0);
    assertNotNull(firstCall);
    assertEquals(TubeCallType.REQUEST, firstCall.callType);
    assertEquals(testContainer, firstCall.container);
    TubeCall secondCall = calls.get(1);
    assertNotNull(secondCall);
    assertEquals(TubeCallType.RESPONSE, secondCall.callType);
    assertEquals(testContainer, secondCall.container);
    calls = tubeB.getCalls();
    assertNotNull(calls);
    assertEquals(1, calls.size());
    firstCall = calls.get(0);
    assertNotNull(firstCall);
    assertEquals(TubeCallType.REQUEST, firstCall.callType);
    assertEquals(testContainer, firstCall.container);
    calls = tubeC.getCalls();
    assertNotNull(calls);
    assertEquals(1, calls.size());
    firstCall = calls.get(0);
    assertNotNull(firstCall);
    assertEquals(TubeCallType.REQUEST, firstCall.callType);
    assertEquals(testContainer, firstCall.container);
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) TestTube(com.sun.xml.ws.api.pipe.EngineTest.TestTube) TubeCall(com.sun.xml.ws.api.pipe.EngineTest.TubeCall) SimpleCompletionCallback(com.sun.xml.ws.api.pipe.EngineTest.SimpleCompletionCallback) NotNull(com.sun.istack.NotNull)

Aggregations

Packet (com.sun.xml.ws.api.message.Packet)15 SimpleCompletionCallback (com.sun.xml.ws.api.pipe.EngineTest.SimpleCompletionCallback)15 TestTube (com.sun.xml.ws.api.pipe.EngineTest.TestTube)15 TubeCall (com.sun.xml.ws.api.pipe.EngineTest.TubeCall)15 NotNull (com.sun.istack.NotNull)14 Semaphore (java.util.concurrent.Semaphore)7 Holder (jakarta.xml.ws.Holder)2 WebServiceException (jakarta.xml.ws.WebServiceException)1