442 Thread.sleep(sleepTime); 443 } catch (InterruptedException e) { 444 Thread.currentThread().interrupt(); 445 throw new Error(e); 446 } 447 } 448 return condition.getAsBoolean(); 449 } 450 451 /** 452 * Adjusts the provided timeout value for the TIMEOUT_FACTOR 453 * @param tOut the timeout value to be adjusted 454 * @return The timeout value adjusted for the value of "test.timeout.factor" 455 * system property 456 */ 457 public static long adjustTimeout(long tOut) { 458 return Math.round(tOut * Utils.TIMEOUT_FACTOR); 459 } 460 461 /** 462 * Runs runnable and checks that it throws expected exception. If exceptionException is null it means 463 * that we expect no exception to be thrown. 464 * @param runnable what we run 465 * @param expectedException expected exception 466 */ 467 public static void runAndCheckException(Runnable runnable, Class<? extends Throwable> expectedException) { 468 boolean expectedExceptionWasNotThrown = false; 469 try { 470 runnable.run(); 471 if (expectedException != null) { 472 expectedExceptionWasNotThrown = true; 473 } 474 } catch (Throwable t) { 475 if (expectedException == null) { 476 throw new AssertionError("Got unexpected exception ", t); 477 } 478 if (!expectedException.isAssignableFrom(t.getClass())) { 479 throw new AssertionError(String.format("Got unexpected exception %s instead of %s", 480 t.getClass().getSimpleName(), expectedException.getSimpleName()), t); 481 } | 442 Thread.sleep(sleepTime); 443 } catch (InterruptedException e) { 444 Thread.currentThread().interrupt(); 445 throw new Error(e); 446 } 447 } 448 return condition.getAsBoolean(); 449 } 450 451 /** 452 * Adjusts the provided timeout value for the TIMEOUT_FACTOR 453 * @param tOut the timeout value to be adjusted 454 * @return The timeout value adjusted for the value of "test.timeout.factor" 455 * system property 456 */ 457 public static long adjustTimeout(long tOut) { 458 return Math.round(tOut * Utils.TIMEOUT_FACTOR); 459 } 460 461 /** 462 * Ensures a requested class is loaded 463 * @param aClass class to load 464 */ 465 public static void ensureClassIsLoaded(Class<?> aClass) { 466 if (aClass == null) { 467 throw new Error("Requested null class"); 468 } 469 try { 470 Class.forName(aClass.getName(), /* initialize = */ true, 471 ClassLoader.getSystemClassLoader()); 472 } catch (ClassNotFoundException e) { 473 throw new Error("Class not found", e); 474 } 475 } 476 /** 477 * Runs runnable and checks that it throws expected exception. If exceptionException is null it means 478 * that we expect no exception to be thrown. 479 * @param runnable what we run 480 * @param expectedException expected exception 481 */ 482 public static void runAndCheckException(Runnable runnable, Class<? extends Throwable> expectedException) { 483 boolean expectedExceptionWasNotThrown = false; 484 try { 485 runnable.run(); 486 if (expectedException != null) { 487 expectedExceptionWasNotThrown = true; 488 } 489 } catch (Throwable t) { 490 if (expectedException == null) { 491 throw new AssertionError("Got unexpected exception ", t); 492 } 493 if (!expectedException.isAssignableFrom(t.getClass())) { 494 throw new AssertionError(String.format("Got unexpected exception %s instead of %s", 495 t.getClass().getSimpleName(), expectedException.getSimpleName()), t); 496 } |