use of com.sun.xml.ws.api.pipe.EngineTest.SimpleCompletionCallback in project metro-jax-ws by eclipse-ee4j.
the class FiberTest method testSuspendNextRunnableResume.
// ////////////////////////////
// Suspend / resume tests
public void testSuspendNextRunnableResume() 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(request);
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(1, calls.size());
firstCall = calls.get(0);
assertNotNull(firstCall);
assertEquals(TubeCallType.REQUEST, firstCall.callType);
assertEquals(testContainer, firstCall.container);
}
use of com.sun.xml.ws.api.pipe.EngineTest.SimpleCompletionCallback in project metro-jax-ws by eclipse-ee4j.
the class FiberTest method testAddInterceptorDuringSuspendResume.
public void testAddInterceptorDuringSuspendResume() 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(new Runnable() {
@Override
public void run() {
atSuspend.release();
try {
checkCompleted.acquire();
} catch (InterruptedException e) {
}
}
});
}
};
tubeB.setName("tubeB");
final FilterTestTube tubeA = new FilterTestTube(tubeB);
tubeA.setName("tubeA");
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);
TestFiberContextSwitchInterceptor interceptor1 = new TestFiberContextSwitchInterceptor("interceptor1");
fiber.addInterceptor(interceptor1);
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
assertEquals(1, interceptor1.getCallCount());
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();
TestFiberContextSwitchInterceptor interceptor2 = new TestFiberContextSwitchInterceptor("interceptor2");
fiber.addInterceptor(interceptor2);
fiber.resume(request);
if (!atEnd.tryAcquire(3, TimeUnit.MINUTES))
fail("timeout");
assertEquals(2, interceptor1.getCallCount());
assertEquals(1, interceptor2.getCallCount());
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());
}
use of com.sun.xml.ws.api.pipe.EngineTest.SimpleCompletionCallback in project metro-jax-ws by eclipse-ee4j.
the class FiberTest method testNextActionInvoke.
public void testNextActionInvoke() {
TestTube tubeC = new TestTube();
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);
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(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(1, calls.size());
firstCall = calls.get(0);
assertNotNull(firstCall);
assertEquals(TubeCallType.REQUEST, firstCall.callType);
assertEquals(testContainer, firstCall.container);
}
use of com.sun.xml.ws.api.pipe.EngineTest.SimpleCompletionCallback in project metro-jax-ws by eclipse-ee4j.
the class FiberTest method testNextActionReturn.
public void testNextActionReturn() {
TestTube tubeC = new TestTube();
FilterTestTube tubeB = new FilterTestTube(tubeC) {
@Override
@NotNull
public NextAction processRequest(@NotNull Packet request) {
super.processRequest(request);
return doReturnWith(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(0, calls.size());
}
use of com.sun.xml.ws.api.pipe.EngineTest.SimpleCompletionCallback in project metro-jax-ws by eclipse-ee4j.
the class FiberTest method testNextActionThrow.
public void testNextActionThrow() {
TestTube tubeC = new TestTube() {
@Override
@NotNull
public NextAction processRequest(@NotNull Packet request) {
super.processRequest(request);
throw new RuntimeException();
}
};
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(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.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(1, calls.size());
firstCall = calls.get(0);
assertNotNull(firstCall);
assertEquals(TubeCallType.REQUEST, firstCall.callType);
assertEquals(testContainer, firstCall.container);
}
Aggregations