@Override public void testFailure(Failure failure) throws Exception { // Ignore assumptions. if (failure.getException() instanceof AssumptionViolatedException) { return; } final StringBuilder b = new StringBuilder("REPRODUCE WITH: gradle "); String task = System.getProperty("tests.task"); // TODO: enforce (intellij still runs the runner?) or use default "test" but that won't work for integ b.append(task); GradleMessageBuilder gradleMessageBuilder = new GradleMessageBuilder(b); gradleMessageBuilder.appendAllOpts(failure.getDescription()); // Client yaml suite tests are a special case as they allow for additional parameters if (ESClientYamlSuiteTestCase.class.isAssignableFrom(failure.getDescription().getTestClass())) { gradleMessageBuilder.appendClientYamlSuiteProperties(); } System.err.println(b.toString()); }
@Override protected void afterAlways(List<Throwable> errors) throws Throwable { if (errors != null && errors.isEmpty() == false) { boolean allAssumption = true; for (Throwable error : errors) { if (false == error instanceof AssumptionViolatedException) { allAssumption = false; break; } } if (false == allAssumption) { ESTestCase.this.afterIfFailed(errors); } } super.afterAlways(errors); }
public static S3AFileSystem createTestFileSystem(Configuration conf) throws IOException { String fsname = conf.getTrimmed(TestS3AFileSystemContract.TEST_FS_S3A_NAME, ""); boolean liveTest = !StringUtils.isEmpty(fsname); URI testURI = null; if (liveTest) { testURI = URI.create(fsname); liveTest = testURI.getScheme().equals(Constants.FS_S3A); } if (!liveTest) { // This doesn't work with our JUnit 3 style test cases, so instead we'll // make this whole class not run by default throw new AssumptionViolatedException( "No test filesystem in " + TestS3AFileSystemContract.TEST_FS_S3A_NAME); } S3AFileSystem fs1 = new S3AFileSystem(); //enable purging in tests conf.setBoolean(Constants.PURGE_EXISTING_MULTIPART, true); conf.setInt(Constants.PURGE_EXISTING_MULTIPART_AGE, 0); fs1.initialize(testURI, conf); return fs1; }
private Object runTestStep(final Object obj, final Method method, final Object[] args, final MethodProxy proxy) throws Throwable { LOGGER.debug("STARTING STEP: {}", method.getName()); Object result = null; try { result = executeTestStepMethod(obj, method, args, proxy, result); LOGGER.debug("STEP DONE: {}", method.getName()); } catch (AssertionError failedAssertion) { error = failedAssertion; logStepFailure(method, args, failedAssertion); return appropriateReturnObject(obj, method); } catch (AssumptionViolatedException assumptionFailed) { return appropriateReturnObject(obj, method); } catch (Throwable testErrorException) { error = testErrorException; logStepFailure(method, args, forError(error).convertToAssertion()); return appropriateReturnObject(obj, method); } return result; }
private Object executeTestStepMethod(Object obj, Method method, Object[] args, MethodProxy proxy, Object result) throws Throwable { try { result = invokeMethod(obj, args, proxy); notifyStepFinishedFor(method, args); } catch (PendingStepException pendingStep) { notifyStepPending(pendingStep.getMessage()); } catch (IgnoredStepException ignoredStep) { notifyStepIgnored(ignoredStep.getMessage()); } catch (AssumptionViolatedException assumptionViolated) { notifyAssumptionViolated(assumptionViolated.getMessage()); } Preconditions.checkArgument(true); return result; }
@Test public void testUnsafe() { int m = 42; long addr1 = createBuffer(); long addr2 = createBuffer(); try { ResolvedJavaMethod method = getResolvedJavaMethod("readWriteReadUnsafe"); Object receiver = method.isStatic() ? null : this; Result expect = executeExpected(method, receiver, addr1, m); if (getCodeCache() == null) { return; } testAgainstExpected(method, expect, receiver, addr2, m); } catch (AssumptionViolatedException e) { // Suppress so that subsequent calls to this method within the // same Junit @Test annotated method can proceed. } finally { disposeBuffer(addr1); disposeBuffer(addr2); } }
@Test public void testByteBuffer() { int m = 42; try { ResolvedJavaMethod method = getResolvedJavaMethod("readWriteReadByteBuffer"); Object receiver = method.isStatic() ? null : this; Result expect = executeExpected(method, receiver, ByteBuffer.allocateDirect(32), m); if (getCodeCache() == null) { return; } ByteBuffer warmupBuffer = ByteBuffer.allocateDirect(32); for (int i = 0; i < 10000; ++i) { readWriteReadByteBuffer(warmupBuffer, (i % 50) + 1); warmupBuffer.putInt(0, 0); } testAgainstExpected(method, expect, receiver, ByteBuffer.allocateDirect(32), m); } catch (AssumptionViolatedException e) { // Suppress so that subsequent calls to this method within the // same Junit @Test annotated method can proceed. } }
@Override public void runChild(final FrameworkMethod method, final RunNotifier notifier) { final Description description = describeChild(method); if (this.isIgnored(method)) { notifier.fireTestIgnored(description); } else { EachTestNotifier eachNotifier = new EachTestNotifier(notifier, description); eachNotifier.fireTestStarted(); boolean ignored = false; try { this.methodBlock(method).evaluate(); } catch (AssumptionViolatedException ave) { eachNotifier.addFailedAssumption(ave); } catch (Throwable e) { if (validateForGraphComputer(e)) { eachNotifier.fireTestIgnored(); logger.info(e.getMessage()); ignored = true; } else eachNotifier.addFailure(e); } finally { if (!ignored) eachNotifier.fireTestFinished(); } } }
/** * Implementation based on {@link TestWatcher}. */ @Override public Statement apply(final Statement base, final Description description) { return new Statement() { @Override public void evaluate() throws Throwable { List<Throwable> errors = new ArrayList<>(); startingQuietly(description, errors); try { base.evaluate(); succeededQuietly(description, errors); } catch (AssumptionViolatedException e) { errors.add(e); skippedQuietly(e, description, errors); } catch (Throwable t) { errors.add(t); failedQuietly(t, description, errors); } finally { finishedQuietly(description, errors); } MultipleFailureException.assertEmpty(errors); } }; }
/** * Implementation based on {@link TestWatcher}. */ @Override public Statement apply(final Statement base, final Description description) { return new Statement() { @Override public void evaluate() throws Throwable { List<Throwable> errors = new ArrayList<>(); startingQuietly(description, errors); try { base.evaluate(); succeededQuietly(description, errors); } catch (AssumptionViolatedException e) { errors.add(e); skippedQuietly(e, description, errors); } catch (Throwable t) { errors.add(t); failedQuietly(t, description, errors); } MultipleFailureException.assertEmpty(errors); } }; }
/** * Implementation based on {@link TestWatcher}. */ @Override public Statement apply(final Statement base, final Description description) { return new Statement() { @Override public void evaluate() throws Throwable { List<Throwable> errors = new ArrayList<Throwable>(); startingQuietly(description, errors); try { base.evaluate(); succeededQuietly(description, errors); } catch (AssumptionViolatedException e) { errors.add(e); skippedQuietly(e, description, errors); } catch (Throwable t) { errors.add(t); failedQuietly(t, description, errors); } finally { finishedQuietly(description, errors); } MultipleFailureException.assertEmpty(errors); } }; }
public static S3AFileSystem createTestFileSystem(Configuration conf) throws IOException { String fsname = conf.getTrimmed(TestS3AFileSystemContract.TEST_FS_S3A_NAME, ""); boolean liveTest = !StringUtils.isEmpty(fsname); URI testURI = null; if (liveTest) { testURI = URI.create(fsname); liveTest = testURI.getScheme().equals(Constants.FS_S3A); } if (!liveTest) { // This doesn't work with our JUnit 3 style test cases, so instead we'll // make this whole class not run by default throw new AssumptionViolatedException( "No test filesystem in " + TestS3AFileSystemContract.TEST_FS_S3A_NAME); } S3AFileSystem fs1 = new S3AFileSystem(); fs1.initialize(testURI, conf); return fs1; }
@Override public Statement apply(final Statement base, final Description description, final Object[] params) { return new Statement() { public void evaluate() throws Throwable { ArrayList<Throwable> errors = new ArrayList<Throwable>(); ParameterizedTestWatcher.this.startingQuietly(description, errors, params); try { base.evaluate(); ParameterizedTestWatcher.this.succeededQuietly(description, errors, params); } catch (AssumptionViolatedException var7) { errors.add(var7); ParameterizedTestWatcher.this.skippedQuietly(var7, description, errors, params); } catch (Throwable var8) { errors.add(var8); ParameterizedTestWatcher.this.failedQuietly(var8, description, errors, params); } finally { ParameterizedTestWatcher.this.finishedQuietly(description, errors, params); } MultipleFailureException.assertEmpty(errors); } }; }
/** * Test xml schema validation */ @Test public void testXmlSchemaGood() throws BuildException { try { buildRule.executeTarget("testSchemaGood"); } catch (BuildException e) { if (e.getMessage().endsWith( " doesn't recognize feature http://apache.org/xml/features/validation/schema") || e.getMessage().endsWith( " doesn't support feature http://apache.org/xml/features/validation/schema")) { throw new AssumptionViolatedException("parser doesn't support schema"); } else { throw e; } } }
/** * Test xml schema validation */ @Test public void testXmlSchemaBad() { try { buildRule.executeTarget("testSchemaBad"); fail("Should throw BuildException because 'Bad Schema Validation'"); } catch (BuildException e) { if (e.getMessage().endsWith( " doesn't recognize feature http://apache.org/xml/features/validation/schema") || e.getMessage().endsWith( " doesn't support feature http://apache.org/xml/features/validation/schema")) { throw new AssumptionViolatedException("parser doesn't support schema"); } else { assertTrue( e.getMessage().indexOf("not a valid XML document") > -1); } } }
public void shutdown() { if (!done) { System.out.println("shutting down TestProcess"); run = false; synchronized (this) { while (!done) { try { wait(); } catch (InterruptedException ie) { throw new AssumptionViolatedException("Thread interrupted", ie); } } } System.out.println("TestProcess shut down"); } }
public void run() { for (int i = 0; i < 5 && run; i++) { System.out.println(Thread.currentThread().getName()); try { Thread.sleep(2000); } catch (InterruptedException ie) { throw new AssumptionViolatedException("Thread interrupted", ie); } } synchronized (this) { done = true; notifyAll(); } }
@Override public Statement apply( final Statement base, final FrameworkMethod method, final Object target ) { return new Statement() { @Override public void evaluate() throws Throwable { starting( base, method, target ); try { base.evaluate(); succeeded(); } catch( AssumptionViolatedException e ) { throw e; } catch( Throwable t ) { failed( t ); throw t; } } }; }
public Statement apply(final Statement base, final FrameworkMethod method, Object target) { return new Statement() { @Override public void evaluate() throws Throwable { starting(method); try { base.evaluate(); succeeded(method); } catch (AssumptionViolatedException e) { throw e; } catch (Throwable t) { failed(t, method); throw t; } finally { finished(method); } } }; }
public Statement apply(final Statement base, final Description description) { return new Statement() { @Override public void evaluate() throws Throwable { List<Throwable> errors = new ArrayList<Throwable>(); startingQuietly(description, errors); try { base.evaluate(); succeededQuietly(description, errors); } catch (AssumptionViolatedException e) { errors.add(e); skippedQuietly(e, description, errors); } catch (Throwable t) { errors.add(t); failedQuietly(t, description, errors); } finally { finishedQuietly(description, errors); } MultipleFailureException.assertEmpty(errors); } }; }
@Override public Statement apply(final Statement base, final FrameworkMethod method, Object target) { return new Statement() { @Override public void evaluate() throws Throwable { logger.info("{} starting...", testName(method)); try { base.evaluate(); logger.debug("{} SUCCESS", testName(method)); } catch (AssumptionViolatedException e) { logger.info("{} Ignored: {}", testName(method), e.getMessage()); throw e; } catch (Throwable t) { logger.warn("{} FAILED: {}", testName(method), t.getMessage()); throw t; } } }; }
/** * Needs to be implemented by tests to provide the correct backend. Backend needs to be properly initialised. * * @return */ @Override protected LDCachingBackend createBackend() { final File storageDir = Files.createTempDir(); LDCachingBackend backend = null; try { backend = new LDCachingFileBackend(storageDir) { @Override public void shutdown() { super.shutdown(); try { FileUtils.deleteDirectory(storageDir); } catch (IOException e) { } } }; backend.initialize(); return backend; } catch (RepositoryException e) { throw new AssumptionViolatedException("could not initialise backend",e); } }
@Override protected void succeeded(Description description) { try { if (!this.actionExecutedAlready) { doAction(); } StrutsAction strutsActionAnnotation = getStrutsActionAnnotation(description); this.springMockStrutsTestCase.verifyForward(strutsActionAnnotation.expectedForward(), strutsActionAnnotation.expectedForwardPath()); } catch (Throwable e) { Class<? extends Throwable> expected = description.getAnnotation(Test.class).expected(); if (e.getClass().equals(expected)) { throw new AssumptionViolatedException("Expected exception on the struts"); } throw new IllegalStateException(e); } }
public void fireTestCaseFailure(Throwable throwable) { if (throwable instanceof AssumptionViolatedException) { getLifecycle().fire(new TestCaseCanceledEvent().withThrowable(throwable)); } else { getLifecycle().fire(new TestCaseFailureEvent().withThrowable(throwable)); } }
@Override protected void skipped(final AssumptionViolatedException e, final Description description) { super.skipped(e, description); LOGGER.warn("skipped test {} due to assumption violation", description); LOGGER.warn("assumption violation", e); }
private void verify(SentinelsAvailable verificationMode) { int failed = 0; for (RedisNode node : sentinelConfig.getSentinels()) { if (!isAvailable(node)) { failed++; } } if (failed > 0) { if (SentinelsAvailable.ALL_ACTIVE.equals(verificationMode)) { throw new AssumptionViolatedException(String.format( "Expected all Redis Sentinels to respone but %s of %s did not responde", failed, sentinelConfig .getSentinels().size())); } if (SentinelsAvailable.ONE_ACTIVE.equals(verificationMode) && sentinelConfig.getSentinels().size() - 1 < failed) { throw new AssumptionViolatedException( "Expected at least one sentinel to respond but it seems all are offline - Game Over!"); } } if (SentinelsAvailable.NONE_ACTIVE.equals(verificationMode) && failed != sentinelConfig.getSentinels().size()) { throw new AssumptionViolatedException(String.format( "Expected to have no sentinels online but found that %s are still alive.", (sentinelConfig.getSentinels() .size() - failed))); } }
private void checkServerRunning() { try (CloseableHttpClient client = HttpClientBuilder.create().build()) { CloseableHttpResponse response = client.execute(new HttpGet(baseUrl + PING_PATH)); if (response != null && response.getStatusLine() != null) { Assume.assumeThat(response.getStatusLine().getStatusCode(), Is.is(200)); } } catch (IOException e) { throw new AssumptionViolatedException("SolrServer does not seem to be running", e); } }