Search in sources :

Example 36 with IRunnable

use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.

the class JobScheduleTest method testErrorWithRunnable.

@Test()
public void testErrorWithRunnable() {
    final Error error = new Error("expected JUnit test exception");
    IFuture<Void> future = Jobs.getJobManager().schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            throw error;
        }
    }, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExceptionHandling(null, false));
    try {
        // test with timeout in case the error is not propagated
        future.awaitDoneAndGet(5, TimeUnit.SECONDS);
        fail("Exception expected");
    } catch (Error e) {
        assertSame(e, e);
        assertTrue(future.isDone());
    }
}
Also used : TimedOutError(org.eclipse.scout.rt.platform.util.concurrent.TimedOutError) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Test(org.junit.Test)

Example 37 with IRunnable

use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.

the class JobScheduleTest method testProcessingExceptionWithCallable.

@Test
public void testProcessingExceptionWithCallable() {
    final ProcessingException exception = new ProcessingException("expected JUnit test exception");
    IFuture<Void> future = Jobs.getJobManager().schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            throw exception;
        }
    }, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExceptionHandling(null, false));
    try {
        future.awaitDoneAndGet();
        fail("Exception expected");
    } catch (Exception e) {
        assertSame(exception, e);
        assertTrue(future.isDone());
    }
}
Also used : IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) Test(org.junit.Test)

Example 38 with IRunnable

use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.

the class JobScheduleTest method testExceptionExceptionWithCallable.

@Test
public void testExceptionExceptionWithCallable() {
    final Exception exception = new Exception("expected JUnit test exception");
    IFuture<Void> future = Jobs.getJobManager().schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            throw exception;
        }
    }, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExceptionHandling(null, false));
    try {
        future.awaitDoneAndGet();
        fail("PlatformException expected");
    } catch (PlatformException e) {
        assertSame(exception, e.getCause());
        assertTrue(future.isDone());
    }
}
Also used : PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Test(org.junit.Test)

Example 39 with IRunnable

use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.

the class JobScheduleTest method testParallelExecution.

@Test
public void testParallelExecution() throws Exception {
    final BlockingCountDownLatch barrier = new BlockingCountDownLatch(3);
    IFuture<Void> future1 = Jobs.getJobManager().schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            barrier.countDownAndBlock();
        }
    }, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExceptionHandling(null, false));
    IFuture<Void> future2 = Jobs.getJobManager().schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            barrier.countDownAndBlock();
        }
    }, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExceptionHandling(null, false));
    IFuture<Void> future3 = Jobs.getJobManager().schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            barrier.countDownAndBlock();
        }
    }, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExceptionHandling(null, false));
    assertTrue(barrier.await());
    barrier.unblock();
    // wait for all jobs to complete
    Jobs.getJobManager().awaitDone(Jobs.newFutureFilterBuilder().andMatchFuture(future1, future2, future3).toFilter(), 10, TimeUnit.SECONDS);
}
Also used : BlockingCountDownLatch(org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Test(org.junit.Test)

Example 40 with IRunnable

use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.

the class JobScheduleTest method testExpired.

@Test
public void testExpired() {
    final AtomicBoolean executed = new AtomicBoolean(false);
    IFuture<Void> future = Jobs.getJobManager().schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            executed.set(true);
        }
    }, Jobs.newInput().withExpirationTime(500, TimeUnit.MILLISECONDS).withRunContext(RunContexts.empty()).withExecutionTrigger(Jobs.newExecutionTrigger().withStartIn(1, TimeUnit.SECONDS)));
    future.awaitDone();
    assertTrue(future.isCancelled());
    assertFalse(executed.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Test(org.junit.Test)

Aggregations

IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)260 Test (org.junit.Test)210 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)82 BlockingCountDownLatch (org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch)68 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)40 ArrayList (java.util.ArrayList)36 PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)32 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)26 TimedOutError (org.eclipse.scout.rt.platform.util.concurrent.TimedOutError)21 IBlockingCondition (org.eclipse.scout.rt.platform.job.IBlockingCondition)20 IExecutionSemaphore (org.eclipse.scout.rt.platform.job.IExecutionSemaphore)20 ThreadInterruptedError (org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError)20 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)19 JobEvent (org.eclipse.scout.rt.platform.job.listener.JobEvent)17 VetoException (org.eclipse.scout.rt.platform.exception.VetoException)13 Times (org.eclipse.scout.rt.testing.platform.runner.Times)12 AtomicReference (java.util.concurrent.atomic.AtomicReference)11 IFuture (org.eclipse.scout.rt.platform.job.IFuture)10 IJobManager (org.eclipse.scout.rt.platform.job.IJobManager)10 JMSException (javax.jms.JMSException)9