use of org.eclipse.scout.rt.platform.util.concurrent.TimedOutError in project scout.rt by eclipse.
the class FutureFinishedTest method testNotifyWaitingThreads.
@Test
public void testNotifyWaitingThreads() throws Throwable {
final String jobIdentifier = UUID.randomUUID().toString();
final BlockingCountDownLatch setupLatch = new BlockingCountDownLatch(1);
IFuture<Void> controller = Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
setupLatch.countDown();
try {
Jobs.getJobManager().awaitFinished(Jobs.newFutureFilterBuilder().andMatchExecutionHint(jobIdentifier).toFilter(), 10, TimeUnit.SECONDS);
} catch (TimedOutError e) {
fail("no timeout expected");
}
}
}, Jobs.newInput());
assertTrue(setupLatch.await());
// Wait some time, so that the listener in controller is installed
SleepUtil.sleepSafe(2, TimeUnit.SECONDS);
// Run the test
IFuture<Void> future = Jobs.schedule(mock(IRunnable.class), Jobs.newInput());
// verify
// no exception expected
future.awaitFinished(10, TimeUnit.SECONDS);
// no exception expected
controller.awaitDoneAndGet(10, TimeUnit.SECONDS);
}
use of org.eclipse.scout.rt.platform.util.concurrent.TimedOutError in project scout.rt by eclipse.
the class MutualExclusionTest method testAcquisition4.
/**
* Task1 acquires the mutex. Then, task2 tries to acquire the mutex and blocks until acquired. Once task1 releases the
* mutex, task2 does become the mutex owner.
*/
@Test(timeout = 5000)
public void testAcquisition4() {
final ExecutionSemaphore mutex = (ExecutionSemaphore) m_task1.getExecutionSemaphore();
assertEquals(0, mutex.getCompetitorCount());
// Make task1 to acquire the mutex
IPermitAcquiredCallback callbackTask1 = mock(IPermitAcquiredCallback.class);
assertTrue(mutex.compete(m_task1, QueuePosition.HEAD, callbackTask1));
verify(callbackTask1, times(1)).onPermitAcquired();
assertTrue(mutex.isPermitOwner(m_task1));
assertEquals(1, mutex.getCompetitorCount());
// Task2 tries to acquire the mutex, and blocks until acquired
IFuture<Void> future = Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
mutex.acquire(m_task2, QueuePosition.TAIL);
}
}, Jobs.newInput());
try {
future.awaitDone(1, TimeUnit.SECONDS);
fail("timeout expected");
} catch (TimedOutError e) {
// NOOP
}
assertTrue(mutex.isPermitOwner(m_task1));
assertEquals(2, mutex.getCompetitorCount());
mutex.release(m_task1);
assertTrue(mutex.isPermitOwner(m_task2));
assertEquals(1, mutex.getCompetitorCount());
mutex.release(m_task2);
assertFalse(mutex.isPermitOwner(m_task2));
assertEquals(0, mutex.getCompetitorCount());
}
use of org.eclipse.scout.rt.platform.util.concurrent.TimedOutError in project scout.rt by eclipse.
the class JobManagerLoadTest method testImmediateExecuting.
@Test(timeout = 20_000)
public void testImmediateExecuting() {
IFilter<IFuture<?>> filter = Jobs.newFutureFilterBuilder().andMatchExecutionHint(JOB_IDENTIFIER).toFilter();
final AtomicLong counter = new AtomicLong();
for (int i = 0; i < JOB_COUNT; i++) {
Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
counter.incrementAndGet();
}
}, Jobs.newInput().withExecutionHint(JOB_IDENTIFIER));
}
try {
Jobs.getJobManager().awaitDone(filter, 10, TimeUnit.SECONDS);
assertEquals(JOB_COUNT, counter.get());
} catch (TimedOutError e) {
Jobs.getJobManager().cancel(filter, true);
fail("Scheduling 25'000 jobs took longer than 10s");
}
}
use of org.eclipse.scout.rt.platform.util.concurrent.TimedOutError in project scout.rt by eclipse.
the class AwaitDoneTest method testAwaitFutureDone2.
@Test
public void testAwaitFutureDone2() {
// synchronized because modified/read by different threads.
final Set<String> protocol = Collections.synchronizedSet(new HashSet<String>());
final BlockingCountDownLatch latchJob2 = new BlockingCountDownLatch(1);
final IFuture<Void> future1 = Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
protocol.add("run-1");
}
}, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExecutionHint(JOB_IDENTIFIER));
Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
latchJob2.await();
protocol.add("run-2");
}
}, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExecutionHint(JOB_IDENTIFIER).withExceptionHandling(null, false));
Jobs.getJobManager().awaitDone(Jobs.newFutureFilterBuilder().andMatchFuture(future1).toFilter(), 30, TimeUnit.SECONDS);
assertTrue(Jobs.getJobManager().isDone(Jobs.newFutureFilterBuilder().andMatchFuture(future1).toFilter()));
assertFalse(Jobs.getJobManager().isDone(Jobs.newFutureFilterBuilder().andMatchExecutionHint(JOB_IDENTIFIER).toFilter()));
try {
Jobs.getJobManager().awaitDone(Jobs.newFutureFilterBuilder().andMatchExecutionHint(JOB_IDENTIFIER).toFilter(), 500, TimeUnit.MILLISECONDS);
fail("timeout expected");
} catch (TimedOutError e) {
// NOOP
}
assertEquals(CollectionUtility.hashSet("run-1"), protocol);
latchJob2.countDown();
Jobs.getJobManager().awaitDone(Jobs.newFutureFilterBuilder().andMatchExecutionHint(JOB_IDENTIFIER).toFilter(), 30, TimeUnit.SECONDS);
assertTrue(Jobs.getJobManager().isDone(Jobs.newFutureFilterBuilder().andMatchExecutionHint(JOB_IDENTIFIER).toFilter()));
assertEquals(CollectionUtility.hashSet("run-1", "run-2"), protocol);
}
use of org.eclipse.scout.rt.platform.util.concurrent.TimedOutError in project scout.rt by eclipse.
the class SessionStore method doHousekeeping.
/**
* Checks if the client session is still used by a UI session. If not, it is stopped and removed form the store.
*/
protected void doHousekeeping(final IClientSession clientSession) {
m_writeLock.lock();
try {
if (IFuture.CURRENT.get().isCancelled()) {
return;
}
m_housekeepingFutures.remove(clientSession.getId());
if (!clientSession.isActive() || clientSession.isStopping()) {
LOG.info("Session housekeeping: Client session {} is {}, removing it from store", clientSession.getId(), (!clientSession.isActive() ? "inactive" : "stopping"));
removeClientSession(clientSession);
return;
}
// Check if the client session is referenced by any UI session
Set<IUiSession> uiSessions = m_uiSessionsByClientSession.get(clientSession);
LOG.debug("Session housekeeping: Client session {} referenced by {} UI sessions", clientSession.getId(), (uiSessions == null ? 0 : uiSessions.size()));
if (uiSessions == null || uiSessions.isEmpty()) {
LOG.info("Session housekeeping: Shutting down client session with ID {} because it is not used anymore", clientSession.getId());
try {
final IFuture<Void> future = ModelJobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
forceClientSessionShutdown(clientSession);
}
}, ModelJobs.newInput(ClientRunContexts.empty().withSession(clientSession, true)).withName("Force shutting down client session {} by session housekeeping", clientSession.getId()));
int timeout = CONFIG.getPropertyValue(SessionStoreHousekeepingMaxWaitShutdownProperty.class).intValue();
try {
// NOSONAR
future.awaitDone(timeout, TimeUnit.SECONDS);
} catch (TimedOutError e) {
// NOSONAR
LOG.warn("Client session did no stop within {} seconds. Canceling shutdown job.", timeout);
future.cancel(true);
}
} catch (ThreadInterruptedError e) {
LOG.warn("Interruption encountered while waiting for client session {} to stop. Continuing anyway.", clientSession.getId(), e);
} finally {
removeClientSession(clientSession);
}
}
} finally {
m_writeLock.unlock();
}
}
Aggregations