use of org.junit.runners.model.TestTimedOutException in project scheduling by ow2-proactive.
the class TestNodeSourceThreadPool method testNodeSourceDeploymentThreadsDoNotLeakWithInfiniteRetry.
@Test
public /*
* This setup makes LOST nodes on one host and FREE nodes on another host.
* We use a configuration of two threads for the nodes deployment, and an
* infrastructure with infinite retry number for deploying. After cycling
* two redeployment phases thanks to the policy, we expect the situation
* to be:
* - one thread being always taken by the infinite retry on the fake host
* - one thread available to deploy with success/redeploy on the localhost
* A timeout is thrown if a thread leak prevents the redeployment to happen
*/
void testNodeSourceDeploymentThreadsDoNotLeakWithInfiniteRetry() throws Exception {
String rmConfig = new File(RMTHelper.class.getResource(SIX_THREADS_CONFIG_FILE_PATH).toURI()).getAbsolutePath();
this.rmHelper.startRM(rmConfig);
this.resourceManager = this.rmHelper.getResourceManager();
this.resourceManager.defineNodeSource(NODE_SOURCE_NAME, SSHInfrastructureV2.class.getName(), getInfiniteRetryInfrastructureParameters(), RestartDownNodesPolicy.class.getName(), getRestartDownNodesPolicyParameters(), NODES_NOT_RECOVERABLE);
this.resourceManager.deployNodeSource(NODE_SOURCE_NAME);
RMTHelper.log("Waiting for the RM to have one free node");
while (this.resourceManager.getState().getFreeNodesNumber() != ONE_NODE_PER_HOST) {
Thread.sleep(ACTIVE_WAITING_PERIOD);
}
assertEquals(1, this.resourceManager.getState().getAliveNodes().size());
for (int i = 0; i < 2; i++) {
String freeNodeUrl = this.resourceManager.getState().getFreeNodes().iterator().next();
RMTHelper.killRuntime(freeNodeUrl);
RMMonitorsHandler monitor = this.rmHelper.getMonitorsHandler();
monitor.flushEvents();
RMTHelper.log("Waiting for the RM to detect the down node");
RMNodeEvent nodeEvent = RMTHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, freeNodeUrl, NODE_STATE_CHANGED_TIMEOUT, monitor);
assertEquals(NodeState.DOWN, nodeEvent.getNodeState());
RMTHelper.log("Waiting for the RM to redeploy the down node");
int totalWaitingTime = 0;
while (this.resourceManager.getState().getFreeNodesNumber() != ONE_NODE_PER_HOST) {
Thread.sleep(ACTIVE_WAITING_PERIOD);
totalWaitingTime += ACTIVE_WAITING_PERIOD;
if (totalWaitingTime > NODE_STATE_CHANGED_TIMEOUT) {
throw new TestTimedOutException(NODE_STATE_CHANGED_TIMEOUT, TimeUnit.MILLISECONDS);
}
}
}
assertEquals(1, this.resourceManager.getState().getAliveNodes().size());
}
use of org.junit.runners.model.TestTimedOutException in project spf4j by zolyfarkas.
the class FailOnTimeout method createTimeoutException.
private Exception createTimeoutException(Thread thread) {
StackTraceElement[] stackTrace = thread.getStackTrace();
final Thread stuckThread = lookForStuckThread ? getStuckThread(thread) : null;
Exception currThreadException = new TestTimedOutException(timeout, timeUnit);
if (stackTrace != null) {
currThreadException.setStackTrace(stackTrace);
thread.interrupt();
}
if (stuckThread != null) {
Exception stuckThreadException = new Exception("Appears to be stuck in thread " + stuckThread.getName());
stuckThreadException.setStackTrace(getStackTrace(stuckThread));
return new MultipleFailureException(Arrays.<Throwable>asList(currThreadException, stuckThreadException));
} else {
return currThreadException;
}
}
use of org.junit.runners.model.TestTimedOutException in project indy by Commonjava.
the class ThreadDumper method timeoutRule.
public static TestRule timeoutRule(int timeout, TimeUnit units) {
return (base, description) -> new Statement() {
public void evaluate() throws Throwable {
System.out.printf("Setting up timeout: %d %s to wrap: %s\n", timeout, units, base);
AtomicReference<Throwable> error = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
FutureTask<Void> task = new FutureTask<>(() -> {
try {
latch.countDown();
base.evaluate();
} catch (Throwable t) {
error.set(t);
}
return null;
});
ThreadGroup tg = new ThreadGroup("Test Timeout Group");
Thread t = new Thread(tg, task, "Test Timeout Thread");
t.setDaemon(true);
t.start();
try {
System.out.println("Waiting for test to start.");
latch.await();
} catch (InterruptedException e) {
error.set(e);
}
if (error.get() == null) {
try {
System.out.println("Waiting for test to complete (or timeout)");
task.get(timeout, units);
} catch (InterruptedException e) {
error.set(e);
} catch (ExecutionException e) {
error.set(e.getCause());
} catch (TimeoutException e) {
System.out.printf("Test timeout %d %s expired!\n", timeout, units.name());
dumpThreads();
StackTraceElement[] stackTrace = t.getStackTrace();
Exception currThreadException = new TestTimedOutException(timeout, units);
if (stackTrace != null) {
currThreadException.setStackTrace(stackTrace);
t.interrupt();
}
throw currThreadException;
}
}
Throwable throwable = error.get();
if (throwable != null) {
throw throwable;
}
}
};
}
use of org.junit.runners.model.TestTimedOutException in project incubator-ratis by apache.
the class JUnitRunListener method main.
public static void main(String[] args) {
final JUnitRunListener listener = new JUnitRunListener();
listener.out.println("TIMEOUT_EXCEPTION_PREFIX = '" + TIMEOUT_EXCEPTION_PREFIX + "'");
TIMEOUT_EXCEPTION.printStackTrace(listener.out);
listener.testFailure(new Failure(null, new TestTimedOutException(999, TimeUnit.MILLISECONDS)));
}
use of org.junit.runners.model.TestTimedOutException in project robolectric by robolectric.
the class TimeLimitedStatement method evaluate.
@Override
public void evaluate() throws Throwable {
Thread testThread = Thread.currentThread();
Thread timeoutThread = new Thread(() -> {
try {
Thread.sleep(timeout);
testThread.interrupt();
} catch (InterruptedException e) {
// ok
}
}, "Robolectric time-limited test");
timeoutThread.start();
try {
delegate.evaluate();
} catch (InterruptedException e) {
Exception e2 = new TestTimedOutException(timeout, TimeUnit.MILLISECONDS);
e2.setStackTrace(e.getStackTrace());
throw e2;
} finally {
timeoutThread.interrupt();
timeoutThread.join();
}
}
Aggregations