use of org.eclipse.scout.rt.platform.util.FinalValue in project scout.rt by eclipse.
the class PlatformTestRunnerTransactionTest method runServerTestRunner.
protected static Result runServerTestRunner(String testMethod, boolean expectingTestFails, boolean expectingCommit) throws Exception {
final Class<?> testClass = PlatformTestRunnerTransactionTestFixture.class;
final FinalValue<PlatformTestRunnerTransactionTestFixture> testInstance = new FinalValue<PlatformTestRunnerTransactionTestFixture>();
final PlatformTestRunner serverTestRunner = new PlatformTestRunner(PlatformTestRunnerTransactionTestFixture.class) {
@Override
protected Object createTest() throws Exception {
Object test = super.createTest();
testInstance.set((PlatformTestRunnerTransactionTestFixture) test);
return test;
}
};
JUnitCore jUnitCore = new JUnitCore();
Request req = Request.runner(serverTestRunner).filterWith(Filter.matchMethodDescription(Description.createTestDescription(testClass, testMethod)));
Result result = jUnitCore.run(req);
assertEquals(0, result.getIgnoreCount());
assertEquals(1, result.getRunCount());
int expectedFailureCount = expectingTestFails ? 1 : 0;
if (result.getFailureCount() != expectedFailureCount) {
StringBuilder sb = new StringBuilder();
sb.append("expected ");
sb.append(expectedFailureCount);
sb.append(" but caught ");
sb.append(result.getFailureCount());
sb.append(":");
for (Failure f : result.getFailures()) {
sb.append("\n ");
sb.append("Description: '" + f.getDescription() + "'");
sb.append("\n ");
sb.append(f.getException());
sb.append(Arrays.asList(f.getException().getStackTrace()));
if (f.getException() != null && f.getException().getCause() != null) {
sb.append("Cause:");
sb.append(f.getException().getCause());
sb.append(Arrays.asList(f.getException().getCause().getStackTrace()));
}
}
Assert.fail(sb.toString());
}
final PlatformTestRunnerTransactionTestFixture fixture = testInstance.get();
assertNotNull(fixture);
fixture.verifyTransaction(expectingCommit);
return result;
}
use of org.eclipse.scout.rt.platform.util.FinalValue in project scout.rt by eclipse.
the class JmsMomImplementorTest method testRequestReplyCancellationInternal.
private void testRequestReplyCancellationInternal(final IBiDestination<String, String> destination) throws InterruptedException {
final CountDownLatch neverLatch = new CountDownLatch(1);
final CountDownLatch setupLatch = new CountDownLatch(1);
final CountDownLatch verifyLatch = new CountDownLatch(2);
final AtomicBoolean requestorInterrupted = new AtomicBoolean();
final AtomicBoolean replierInterrupted = new AtomicBoolean();
final AtomicBoolean replierCancelled = new AtomicBoolean();
// Subscribe for the destination
m_disposables.add(MOM.reply(JmsTestMom.class, destination, new IRequestListener<String, String>() {
@Override
public String onRequest(IMessage<String> request) {
setupLatch.countDown();
try {
neverLatch.await();
} catch (InterruptedException e) {
replierInterrupted.set(true);
} finally {
replierCancelled.set(RunMonitor.CURRENT.get().isCancelled());
verifyLatch.countDown();
}
return request.getTransferObject().toUpperCase();
}
}));
// Initiate 'request-reply' communication
final FinalValue<String> testee = new FinalValue<>();
IFuture<Void> requestFuture = Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
try {
String result = MOM.request(JmsTestMom.class, destination, "hello world");
testee.set(result);
} catch (ThreadInterruptedError e) {
requestorInterrupted.set(true);
} finally {
verifyLatch.countDown();
}
}
}, Jobs.newInput().withName("initiator").withExecutionHint(m_testJobExecutionHint));
// Wait until reply message processing started
setupLatch.await();
// Cancel the publishing thread
requestFuture.cancel(true);
// wait for request / reply interrupted
verifyLatch.await();
// Verify
assertTrue(requestorInterrupted.get());
assertTrue(replierInterrupted.get());
assertTrue(replierCancelled.get());
assertFalse(testee.isSet());
}
Aggregations