org.junit.runners.model.TestTimedOutException Java Examples
The following examples show how to use
org.junit.runners.model.TestTimedOutException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JUnitRunListener.java From incubator-ratis with Apache License 2.0 | 5 votes |
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))); }
Example #2
Source File: EtcdKeystoreTest.java From etcd4j with Apache License 2.0 | 5 votes |
@Ignore @Test(timeout = 1000) public void testCliAgainstSslEtcd() throws URISyntaxException, IOException, EtcdAuthenticationException, TimeoutException, EtcdException { expectedEx.expect(TestTimedOutException.class); EtcdClient etcd = new EtcdClient(new URI(SECURED_ETCD_SERVICE)); etcd.put("/test", "1234").send().get(); }
Example #3
Source File: GradingProblem.java From public with Apache License 2.0 | 5 votes |
private static String printException(final Throwable exception) { // If it's a test failure or a timeout, the stack trace is worthless if (exception instanceof AssertionError || exception instanceof TestTimedOutException) { return exception.getMessage().trim(); } // Same if it's an exception to say that the wrong kind of exception was thrown if (exception.getMessage() != null && exception.getMessage().startsWith("Unexpected exception")) { return exception.getMessage().trim(); } final StringBuilder result = new StringBuilder(); outer: for (final StackTraceElement element : exception.getStackTrace()) { final String elementString = element.toString().trim(); for (final String packageName : EXCEPTION_IGNORED_PACKAGES) { if (elementString.startsWith(packageName)) { break outer; } } result.append("at "); result.append(elementString); result.append(System.lineSeparator()); } return "[" + exception.getClass().getName() + "] " + (exception.getMessage() == null ? "" : exception.getMessage().trim()) + System.lineSeparator() + result.toString(); }
Example #4
Source File: GradingProblem.java From public with Apache License 2.0 | 5 votes |
private static String printException(final Throwable exception) { // If it's a test failure or a timeout, the stack trace is worthless if (exception instanceof AssertionError || exception instanceof TestTimedOutException) { return exception.getMessage().trim(); } // Same if it's an exception to say that the wrong kind of exception was thrown if (exception.getMessage() != null && exception.getMessage().startsWith("Unexpected exception")) { return exception.getMessage().trim(); } final StringBuilder result = new StringBuilder(); outer: for (final StackTraceElement element : exception.getStackTrace()) { for (final String packageName : EXCEPTION_IGNORED_PACKAGES) { if (element.getClassName().startsWith(packageName)) { break outer; } } result.append("at "); result.append(element.toString().trim()); result.append(System.lineSeparator()); } return "[" + exception.getClass().getName() + "] " + (exception.getMessage() == null ? "" : exception.getMessage().trim()) + System.lineSeparator() + result.toString(); }
Example #5
Source File: GradingProblem.java From public with Apache License 2.0 | 5 votes |
private static String printException(final Throwable exception) { // If it's a test failure or a timeout, the stack trace is worthless if (exception instanceof AssertionError || exception instanceof TestTimedOutException) { return exception.getMessage().trim(); } // Same if it's an exception to say that the wrong kind of exception was thrown if (exception.getMessage() != null && exception.getMessage().startsWith("Unexpected exception")) { return exception.getMessage().trim(); } final StringBuilder result = new StringBuilder(); outer: for (final StackTraceElement element : exception.getStackTrace()) { final String elementString = element.toString().trim(); for (final String packageName : EXCEPTION_IGNORED_PACKAGES) { if (elementString.startsWith(packageName)) { break outer; } } result.append("at "); result.append(elementString); result.append(System.lineSeparator()); } return "[" + exception.getClass().getName() + "] " + (exception.getMessage() == null ? "" : exception.getMessage().trim()) + System.lineSeparator() + result.toString(); }
Example #6
Source File: GradingProblem.java From public with Apache License 2.0 | 5 votes |
private static String printException(final Throwable exception) { // If it's a test failure or a timeout, the stack trace is worthless if (exception instanceof AssertionError || exception instanceof TestTimedOutException) { return exception.getMessage().trim(); } // Same if it's an exception to say that the wrong kind of exception was thrown if (exception.getMessage() != null && exception.getMessage().startsWith("Unexpected exception")) { return exception.getMessage().trim(); } final StringBuilder result = new StringBuilder(); outer: for (final StackTraceElement element : exception.getStackTrace()) { final String elementString = element.toString().trim(); for (final String packageName : EXCEPTION_IGNORED_PACKAGES) { if (elementString.startsWith(packageName)) { break outer; } } result.append("at "); result.append(elementString); result.append(System.lineSeparator()); } return "[" + exception.getClass().getName() + "] " + (exception.getMessage() == null ? "" : exception.getMessage().trim()) + System.lineSeparator() + result.toString(); }
Example #7
Source File: GradingProblem.java From public with Apache License 2.0 | 5 votes |
private static String printException(final Throwable exception) { // If it's a test failure or a timeout, the stack trace is worthless if (exception instanceof AssertionError || exception instanceof TestTimedOutException) { return exception.getMessage().trim(); } // Same if it's an exception to say that the wrong kind of exception was thrown if (exception.getMessage() != null && exception.getMessage().startsWith("Unexpected exception")) { return exception.getMessage().trim(); } final StringBuilder result = new StringBuilder(); outer: for (final StackTraceElement element : exception.getStackTrace()) { for (final String packageName : EXCEPTION_IGNORED_PACKAGES) { if (element.getClassName().startsWith(packageName)) { break outer; } } result.append("at "); result.append(element.toString().trim()); result.append(System.lineSeparator()); } return "[" + exception.getClass().getName() + "] " + (exception.getMessage() == null ? "" : exception.getMessage().trim()) + System.lineSeparator() + result.toString(); }
Example #8
Source File: ServiceTalkTestTimeout.java From servicetalk with Apache License 2.0 | 5 votes |
private Exception createTimeoutException(Thread thread) { StackTraceElement[] stackTrace = thread.getStackTrace(); Exception currThreadException = new TestTimedOutException(timeout, timeUnit); if (stackTrace != null) { currThreadException.setStackTrace(stackTrace); thread.interrupt(); } return currThreadException; }
Example #9
Source File: BCryptHighCostTest.java From bcrypt with Apache License 2.0 | 4 votes |
@Test(expected = TestTimedOutException.class) public void testHashWith24CostFactorAndTimeout() { BCrypt.withDefaults().hash(24, password); }
Example #10
Source File: BCryptHighCostTest.java From bcrypt with Apache License 2.0 | 4 votes |
@Test(expected = TestTimedOutException.class) public void testHashWith25CostFactorAndTimeout() { BCrypt.withDefaults().hash(25, password); }
Example #11
Source File: BCryptHighCostTest.java From bcrypt with Apache License 2.0 | 4 votes |
@Test(expected = TestTimedOutException.class) public void testHashWith26CostFactorAndTimeout() { BCrypt.withDefaults().hash(26, password); }
Example #12
Source File: BCryptHighCostTest.java From bcrypt with Apache License 2.0 | 4 votes |
@Test(expected = TestTimedOutException.class) public void testHashWith27CostFactorAndTimeout() { BCrypt.withDefaults().hash(27, password); }
Example #13
Source File: BCryptHighCostTest.java From bcrypt with Apache License 2.0 | 4 votes |
@Test(expected = TestTimedOutException.class) public void testHashWith28CostFactorAndTimeout() { BCrypt.withDefaults().hash(28, password); }
Example #14
Source File: BCryptHighCostTest.java From bcrypt with Apache License 2.0 | 4 votes |
@Test(expected = TestTimedOutException.class) public void testHashWith29CostFactorAndTimeout() { BCrypt.withDefaults().hash(29, password); }
Example #15
Source File: BCryptHighCostTest.java From bcrypt with Apache License 2.0 | 4 votes |
@Test(expected = TestTimedOutException.class) public void testHashWith30CostFactorAndTimeout() { BCrypt.withDefaults().hash(30, password); }
Example #16
Source File: JenkinsRule.java From jenkins-test-harness with MIT License | 4 votes |
public Statement apply(final Statement base, final Description description) { if (description.getAnnotation(WithoutJenkins.class) != null) { // request has been made to not create the instance for this test method return base; } Statement wrapped = new Statement() { @Override public void evaluate() throws Throwable { testDescription = description; Thread t = Thread.currentThread(); String o = t.getName(); t.setName("Executing "+ testDescription.getDisplayName()); System.out.println("=== Starting " + testDescription.getDisplayName()); before(); try { // so that test code has all the access to the system ACL.impersonate(ACL.SYSTEM); try { base.evaluate(); } catch (Throwable th) { // allow the late attachment of a debugger in case of a failure. Useful // for diagnosing a rare failure try { throw new BreakException(); } catch (BreakException e) {} RandomlyFails rf = testDescription.getAnnotation(RandomlyFails.class); if (rf != null) { System.err.println("Note: known to randomly fail: " + rf.value()); } throw th; } } finally { after(); testDescription = null; t.setName(o); } } }; final int testTimeout = getTestTimeoutOverride(description); if (testTimeout <= 0) { System.out.println("Test timeout disabled."); return wrapped; } else { final Statement timeoutStatement = Timeout.seconds(testTimeout).apply(wrapped, description); return new Statement() { @Override public void evaluate() throws Throwable { try { timeoutStatement.evaluate(); } catch (TestTimedOutException x) { // withLookingForStuckThread does not work well; better to just have a full thread dump. LOGGER.warning(String.format("Test timed out (after %d seconds).", testTimeout)); dumpThreads(); throw x; } } }; } }
Example #17
Source File: TestNodeSourceThreadPool.java From scheduling with GNU Affero General Public License v3.0 | 4 votes |
@Test /* * 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 */ public 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()); }
Example #18
Source File: BCryptHighCostTest.java From bcrypt with Apache License 2.0 | 4 votes |
@Test(expected = TestTimedOutException.class) public void testHashWithMaxCostFactorAndTimeout() { BCrypt.withDefaults().hash(31, password); }