Search in sources :

Example 21 with AssumptionViolatedException

use of org.junit.internal.AssumptionViolatedException in project hadoop by apache.

the class ContractTestUtils method downgrade.

/**
   * downgrade a failure to a message and a warning, then an
   * exception for the Junit test runner to mark as failed.
   * @param message text message
   * @param failure what failed
   * @throws AssumptionViolatedException always
   */
public static void downgrade(String message, Throwable failure) {
    LOG.warn("Downgrading test " + message, failure);
    AssumptionViolatedException ave = new AssumptionViolatedException(failure, null);
    throw ave;
}
Also used : AssumptionViolatedException(org.junit.internal.AssumptionViolatedException)

Example 22 with AssumptionViolatedException

use of org.junit.internal.AssumptionViolatedException in project intellij-community by JetBrains.

the class GuiTestRunner method runChild.

@Override
protected void runChild(final FrameworkMethod method, RunNotifier notifier) {
    if (!canRunGuiTests()) {
        notifier.fireTestAssumptionFailed(new Failure(describeChild(method), new AssumptionViolatedException("Headless environment")));
        System.out.println(String.format("Skipping test '%1$s'. UI tests cannot run in a headless environment.", method.getName()));
    } else if (MethodInvoker.doesIdeHaveFatalErrors()) {
        // TODO: can we restart the IDE at this point, instead of giving up?
        notifier.fireTestIgnored(describeChild(method));
        System.out.println(String.format("Skipping test '%1$s': a fatal error has occurred in the IDE", method.getName()));
        notifier.pleaseStop();
    } else {
        printPerfStats();
        printTimestamp();
        super.runChild(method, notifier);
        printTimestamp();
        printPerfStats();
    }
}
Also used : AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) Failure(org.junit.runner.notification.Failure)

Example 23 with AssumptionViolatedException

use of org.junit.internal.AssumptionViolatedException in project robolectric by robolectric.

the class SandboxTestRunner method runChild.

@Override
protected void runChild(FrameworkMethod method, RunNotifier notifier) {
    Description description = describeChild(method);
    EachTestNotifier eachNotifier = new EachTestNotifier(notifier, description);
    if (shouldIgnore(method)) {
        eachNotifier.fireTestIgnored();
    } else {
        eachNotifier.fireTestStarted();
        try {
            methodBlock(method).evaluate();
        } catch (AssumptionViolatedException e) {
            eachNotifier.addFailedAssumption(e);
        } catch (Throwable e) {
            eachNotifier.addFailure(e);
        } finally {
            eachNotifier.fireTestFinished();
        }
    }
}
Also used : Description(org.junit.runner.Description) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) EachTestNotifier(org.junit.internal.runners.model.EachTestNotifier)

Example 24 with AssumptionViolatedException

use of org.junit.internal.AssumptionViolatedException in project lucene-solr by apache.

the class TestRuleSetupAndRestoreClassEnv method before.

@Override
protected void before() throws Exception {
    // we do this in beforeClass, because some tests currently disable it
    if (System.getProperty("solr.directoryFactory") == null) {
        System.setProperty("solr.directoryFactory", "org.apache.solr.core.MockDirectoryFactory");
    }
    // if verbose: print some debugging stuff about which codecs are loaded.
    if (VERBOSE) {
        System.out.println("Loaded codecs: " + Codec.availableCodecs());
        System.out.println("Loaded postingsFormats: " + PostingsFormat.availablePostingsFormats());
    }
    savedInfoStream = InfoStream.getDefault();
    final Random random = RandomizedContext.current().getRandom();
    final boolean v = random.nextBoolean();
    if (INFOSTREAM) {
        InfoStream.setDefault(new ThreadNameFixingPrintStreamInfoStream(System.out));
    } else if (v) {
        InfoStream.setDefault(new NullInfoStream());
    }
    Class<?> targetClass = RandomizedContext.current().getTargetClass();
    avoidCodecs = new HashSet<>();
    if (targetClass.isAnnotationPresent(SuppressCodecs.class)) {
        SuppressCodecs a = targetClass.getAnnotation(SuppressCodecs.class);
        avoidCodecs.addAll(Arrays.asList(a.value()));
    }
    savedCodec = Codec.getDefault();
    int randomVal = random.nextInt(11);
    if ("default".equals(TEST_CODEC)) {
        // just use the default, don't randomize
        codec = savedCodec;
    } else if (("random".equals(TEST_POSTINGSFORMAT) == false) || ("random".equals(TEST_DOCVALUESFORMAT) == false)) {
        // the user wired postings or DV: this is messy
        // refactor into RandomCodec....
        final PostingsFormat format;
        if ("random".equals(TEST_POSTINGSFORMAT)) {
            format = new AssertingPostingsFormat();
        } else if ("MockRandom".equals(TEST_POSTINGSFORMAT)) {
            format = new MockRandomPostingsFormat(new Random(random.nextLong()));
        } else {
            format = PostingsFormat.forName(TEST_POSTINGSFORMAT);
        }
        final DocValuesFormat dvFormat;
        if ("random".equals(TEST_DOCVALUESFORMAT)) {
            dvFormat = new AssertingDocValuesFormat();
        } else {
            dvFormat = DocValuesFormat.forName(TEST_DOCVALUESFORMAT);
        }
        codec = new AssertingCodec() {

            @Override
            public PostingsFormat getPostingsFormatForField(String field) {
                return format;
            }

            @Override
            public DocValuesFormat getDocValuesFormatForField(String field) {
                return dvFormat;
            }

            @Override
            public String toString() {
                return super.toString() + ": " + format.toString() + ", " + dvFormat.toString();
            }
        };
    } else if ("SimpleText".equals(TEST_CODEC) || ("random".equals(TEST_CODEC) && randomVal == 9 && LuceneTestCase.rarely(random) && !shouldAvoidCodec("SimpleText"))) {
        codec = new SimpleTextCodec();
    } else if ("CheapBastard".equals(TEST_CODEC) || ("random".equals(TEST_CODEC) && randomVal == 8 && !shouldAvoidCodec("CheapBastard") && !shouldAvoidCodec("Lucene41"))) {
        // we also avoid this codec if Lucene41 is avoided, since thats the postings format it uses.
        codec = new CheapBastardCodec();
    } else if ("Asserting".equals(TEST_CODEC) || ("random".equals(TEST_CODEC) && randomVal == 7 && !shouldAvoidCodec("Asserting"))) {
        codec = new AssertingCodec();
    } else if ("Compressing".equals(TEST_CODEC) || ("random".equals(TEST_CODEC) && randomVal == 6 && !shouldAvoidCodec("Compressing"))) {
        codec = CompressingCodec.randomInstance(random);
    } else if ("Lucene70".equals(TEST_CODEC) || ("random".equals(TEST_CODEC) && randomVal == 5 && !shouldAvoidCodec("Lucene70"))) {
        codec = new Lucene70Codec(RandomPicks.randomFrom(random, Lucene50StoredFieldsFormat.Mode.values()));
    } else if (!"random".equals(TEST_CODEC)) {
        codec = Codec.forName(TEST_CODEC);
    } else if ("random".equals(TEST_POSTINGSFORMAT)) {
        codec = new RandomCodec(random, avoidCodecs);
    } else {
        assert false;
    }
    Codec.setDefault(codec);
    // Initialize locale/ timezone.
    String testLocale = System.getProperty("tests.locale", "random");
    String testTimeZone = System.getProperty("tests.timezone", "random");
    // Always pick a random one for consistency (whether tests.locale was specified or not).
    savedLocale = Locale.getDefault();
    Locale randomLocale = randomLocale(random);
    locale = testLocale.equals("random") ? randomLocale : localeForLanguageTag(testLocale);
    Locale.setDefault(locale);
    savedTimeZone = TimeZone.getDefault();
    TimeZone randomTimeZone = randomTimeZone(random());
    timeZone = testTimeZone.equals("random") ? randomTimeZone : TimeZone.getTimeZone(testTimeZone);
    TimeZone.setDefault(timeZone);
    similarity = new RandomSimilarity(random());
    // Check codec restrictions once at class level.
    try {
        checkCodecRestrictions(codec);
    } catch (AssumptionViolatedException e) {
        System.err.println("NOTE: " + e.getMessage() + " Suppressed codecs: " + Arrays.toString(avoidCodecs.toArray()));
        throw e;
    }
    // We have "stickiness" so that sometimes all we do is vary the RAM buffer size, other times just the doc count to flush by, else both.
    // This way the assertMemory in DocumentsWriterFlushControl sometimes runs (when we always flush by RAM).
    LiveIWCFlushMode flushMode;
    switch(random().nextInt(3)) {
        case 0:
            flushMode = LiveIWCFlushMode.BY_RAM;
            break;
        case 1:
            flushMode = LiveIWCFlushMode.BY_DOCS;
            break;
        case 2:
            flushMode = LiveIWCFlushMode.EITHER;
            break;
        default:
            throw new AssertionError();
    }
    LuceneTestCase.setLiveIWCFlushMode(flushMode);
    initialized = true;
}
Also used : Locale(java.util.Locale) LuceneTestCase.randomLocale(org.apache.lucene.util.LuceneTestCase.randomLocale) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) CheapBastardCodec(org.apache.lucene.codecs.cheapbastard.CheapBastardCodec) DocValuesFormat(org.apache.lucene.codecs.DocValuesFormat) AssertingDocValuesFormat(org.apache.lucene.codecs.asserting.AssertingDocValuesFormat) AssertingPostingsFormat(org.apache.lucene.codecs.asserting.AssertingPostingsFormat) Random(java.util.Random) AssertingDocValuesFormat(org.apache.lucene.codecs.asserting.AssertingDocValuesFormat) RandomCodec(org.apache.lucene.index.RandomCodec) AssertingCodec(org.apache.lucene.codecs.asserting.AssertingCodec) LiveIWCFlushMode(org.apache.lucene.util.LuceneTestCase.LiveIWCFlushMode) RandomSimilarity(org.apache.lucene.search.similarities.RandomSimilarity) SimpleTextCodec(org.apache.lucene.codecs.simpletext.SimpleTextCodec) SuppressCodecs(org.apache.lucene.util.LuceneTestCase.SuppressCodecs) MockRandomPostingsFormat(org.apache.lucene.codecs.mockrandom.MockRandomPostingsFormat) LuceneTestCase.randomTimeZone(org.apache.lucene.util.LuceneTestCase.randomTimeZone) TimeZone(java.util.TimeZone) AssertingPostingsFormat(org.apache.lucene.codecs.asserting.AssertingPostingsFormat) MockRandomPostingsFormat(org.apache.lucene.codecs.mockrandom.MockRandomPostingsFormat) PostingsFormat(org.apache.lucene.codecs.PostingsFormat) Lucene70Codec(org.apache.lucene.codecs.lucene70.Lucene70Codec)

Example 25 with AssumptionViolatedException

use of org.junit.internal.AssumptionViolatedException in project hadoop by apache.

the class S3ATestUtils method createTestFileContext.

/**
   * Create a file context for tests.
   *
   * If the test.fs.s3a.name property is not set, this will
   * trigger a JUnit failure.
   *
   * Multipart purging is enabled.
   * @param conf configuration
   * @return the FS
   * @throws IOException IO Problems
   * @throws AssumptionViolatedException if the FS is not named
   */
public static FileContext createTestFileContext(Configuration conf) throws IOException {
    String fsname = conf.getTrimmed(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) {
        // make this whole class not run by default
        throw new AssumptionViolatedException("No test filesystem in " + TEST_FS_S3A_NAME);
    }
    FileContext fc = FileContext.getFileContext(testURI, conf);
    return fc;
}
Also used : AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) URI(java.net.URI) FileContext(org.apache.hadoop.fs.FileContext)

Aggregations

AssumptionViolatedException (org.junit.internal.AssumptionViolatedException)29 Test (org.junit.Test)7 EachTestNotifier (org.junit.internal.runners.model.EachTestNotifier)6 Statement (org.junit.runners.model.Statement)6 Description (org.junit.runner.Description)4 URI (java.net.URI)3 Failure (org.junit.runner.notification.Failure)3 MultipleFailureException (org.junit.runners.model.MultipleFailureException)3 FileStatus (org.apache.hadoop.fs.FileStatus)2 Path (org.apache.hadoop.fs.Path)2 SuppressForbidden (com.carrotsearch.randomizedtesting.annotations.SuppressForbidden)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1