Search in sources :

Example 46 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project jacoco by jacoco.

the class InstrumenterTest method testInstrumentAll_Pack200.

@Test
public void testInstrumentAll_Pack200() throws IOException {
    try {
        Class.forName("java.util.jar.Pack200");
    } catch (ClassNotFoundException e) {
        throw new AssumptionViolatedException("this test requires JDK with Pack200");
    }
    ByteArrayOutputStream jarbuffer = new ByteArrayOutputStream();
    ZipOutputStream zipout = new ZipOutputStream(jarbuffer);
    zipout.putNextEntry(new ZipEntry("Test.class"));
    zipout.write(TargetLoader.getClassDataAsBytes(getClass()));
    zipout.finish();
    ByteArrayOutputStream pack200buffer = new ByteArrayOutputStream();
    GZIPOutputStream gzipOutput = new GZIPOutputStream(pack200buffer);
    Pack200Streams.pack(jarbuffer.toByteArray(), gzipOutput);
    gzipOutput.finish();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    int count = instrumenter.instrumentAll(new ByteArrayInputStream(pack200buffer.toByteArray()), out, "Test");
    assertEquals(1, count);
    ZipInputStream zipin = new ZipInputStream(Pack200Streams.unpack(new GZIPInputStream(new ByteArrayInputStream(out.toByteArray()))));
    assertEquals("Test.class", zipin.getNextEntry().getName());
    assertNull(zipin.getNextEntry());
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) ZipInputStream(java.util.zip.ZipInputStream) AssumptionViolatedException(org.junit.AssumptionViolatedException) GZIPOutputStream(java.util.zip.GZIPOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test) AnalyzerTest(org.jacoco.core.analysis.AnalyzerTest)

Example 47 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project jacoco by jacoco.

the class ContentTypeDetectorTest method testPack200File.

@Test
public void testPack200File() throws IOException {
    try {
        Class.forName("java.util.jar.Pack200");
    } catch (ClassNotFoundException e) {
        throw new AssumptionViolatedException("this test requires JDK with Pack200");
    }
    final ByteArrayOutputStream zipbuffer = new ByteArrayOutputStream();
    final ZipOutputStream zip = new ZipOutputStream(zipbuffer);
    zip.putNextEntry(new ZipEntry("hello.txt"));
    zip.write("Hello Zip!".getBytes());
    zip.close();
    final ByteArrayOutputStream pack200buffer = new ByteArrayOutputStream();
    Pack200Streams.pack(zipbuffer.toByteArray(), pack200buffer);
    initData(pack200buffer.toByteArray());
    assertEquals(ContentTypeDetector.PACK200FILE, detector.getType());
    assertContent();
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 48 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project ignite by apache.

the class GridAbstractTest method runTest.

/**
 * Runs test with the provided scenario.
 */
private void runTest(Statement testRoutine) throws Throwable {
    prepareTestEnviroment();
    try {
        final AtomicReference<Throwable> ex = new AtomicReference<>();
        Thread runner = new IgniteThread(getTestIgniteInstanceName(), "test-runner", new Runnable() {

            @Override
            public void run() {
                try {
                    testRoutine.evaluate();
                } catch (Throwable e) {
                    IgniteClosure<Throwable, Throwable> hnd = errorHandler();
                    ex.set(hnd != null ? hnd.apply(e) : e);
                }
            }
        });
        runner.start();
        runner.join(isDebug() ? 0 : getTestTimeout());
        if (runner.isAlive()) {
            U.error(log, "Test has been timed out and will be interrupted (threads dump will be taken before interruption) [" + "test=" + getName() + ", timeout=" + getTestTimeout() + ']');
            List<Ignite> nodes = IgnitionEx.allGridsx();
            for (Ignite node : nodes) ((IgniteKernal) node).dumpDebugInfo();
            // We dump threads to stdout, because we can loose logs in case
            // the build is cancelled on TeamCity.
            U.dumpThreads(null);
            U.dumpThreads(log);
            U.interrupt(runner);
            U.join(runner, log);
            throw new TimeoutException("Test has been timed out [test=" + getName() + ", timeout=" + getTestTimeout() + ']');
        }
        Throwable t = ex.get();
        if (t != null) {
            if (t instanceof AssumptionViolatedException)
                U.quietAndInfo(log, "Test ignored [test=" + testDescription() + ", msg=" + t.getMessage() + "]");
            else {
                U.error(log, "Test failed [test=" + testDescription() + ", duration=" + (System.currentTimeMillis() - ts) + "]", t);
            }
            throw t;
        }
        assert !stopGridErr : "Error occurred on grid stop (see log for more details).";
    } finally {
        try {
            cleanUpTestEnviroment();
        } catch (Exception e) {
            log.error("Failed to execute tear down after test (will ignore)", e);
        }
    }
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) AtomicReference(java.util.concurrent.atomic.AtomicReference) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) MalformedObjectNameException(javax.management.MalformedObjectNameException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) AssumptionViolatedException(org.junit.AssumptionViolatedException) BeansException(org.springframework.beans.BeansException) ObjectStreamException(java.io.ObjectStreamException) TimeoutException(java.util.concurrent.TimeoutException) IgniteException(org.apache.ignite.IgniteException) MalformedURLException(java.net.MalformedURLException) IgniteThread(org.apache.ignite.thread.IgniteThread) Ignite(org.apache.ignite.Ignite) IgniteThread(org.apache.ignite.thread.IgniteThread) TimeoutException(java.util.concurrent.TimeoutException)

Example 49 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project vert.x by eclipse.

the class FileSystemTest method testCopyFileAttributes.

@Test
public void testCopyFileAttributes() throws Exception {
    String source = "foo.txt";
    String target = "bar.txt";
    createFileWithJunk(source, 100);
    try {
        Files.setPosixFilePermissions(new File(testDir, source).toPath(), EnumSet.of(PosixFilePermission.OWNER_READ));
    } catch (UnsupportedOperationException e) {
        throw new AssumptionViolatedException("POSIX file perms unsupported");
    }
    FileSystem fs = vertx.fileSystem();
    String from = testDir + pathSep + source;
    String to = testDir + pathSep + target;
    CopyOptions options = new CopyOptions().setCopyAttributes(false);
    fs.copy(from, to, options, onSuccess(v -> {
        fs.props(from, onSuccess(expected -> {
            fs.props(from, onSuccess(actual -> {
                assertEquals(expected.creationTime(), actual.creationTime());
                assertEquals(expected.lastModifiedTime(), actual.lastModifiedTime());
                vertx.<Set<PosixFilePermission>>executeBlocking(fut -> {
                    try {
                        fut.complete(Files.getPosixFilePermissions(new File(testDir, target).toPath(), LinkOption.NOFOLLOW_LINKS));
                    } catch (IOException e) {
                        fut.fail(e);
                    }
                }, onSuccess(perms -> {
                    assertEquals(EnumSet.of(PosixFilePermission.OWNER_READ), perms);
                    complete();
                }));
            }));
        }));
    }));
    await();
}
Also used : AsyncFileImpl(io.vertx.core.file.impl.AsyncFileImpl) io.vertx.core(io.vertx.core) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) VertxTestBase(io.vertx.test.core.VertxTestBase) AtomicReference(java.util.concurrent.atomic.AtomicReference) Utils(io.vertx.core.impl.Utils) java.nio.file(java.nio.file) Unpooled(io.netty.buffer.Unpooled) HashSet(java.util.HashSet) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) ByteBuf(io.netty.buffer.ByteBuf) TestUtils(io.vertx.test.core.TestUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) WriteStream(io.vertx.core.streams.WriteStream) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ReadStream(io.vertx.core.streams.ReadStream) Pump(io.vertx.core.streams.Pump) JsonObject(io.vertx.core.json.JsonObject) Assume(org.junit.Assume) EnumSet(java.util.EnumSet) AssumptionViolatedException(org.junit.AssumptionViolatedException) Set(java.util.Set) Test(org.junit.Test) IOException(java.io.IOException) File(java.io.File) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Rule(org.junit.Rule) Buffer(io.vertx.core.buffer.Buffer) TemporaryFolder(org.junit.rules.TemporaryFolder) java.nio.file.attribute(java.nio.file.attribute) AssumptionViolatedException(org.junit.AssumptionViolatedException) IOException(java.io.IOException) File(java.io.File) Test(org.junit.Test)

Example 50 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project Payara by payara.

the class DirConfigSourceTest method testPropertyWatcher_RunFilesNewUpdate.

@Test
public void testPropertyWatcher_RunFilesNewUpdate() throws Exception {
    // given
    writeFile(subpath("watcher-files", "foobar"), "test");
    writeFile(subpath("watcher-files", ".hidden", "foobar"), "hidden");
    try {
        Files.createSymbolicLink(subpath("watcher-files", "revealed"), subpath("watcher-files", ".hidden", "foobar"));
    } catch (FileSystemException fileSystemException) {
        if (OS.isWindows() && fileSystemException.getReason().contains("A required privilege is not held by the client")) {
            throw new AssumptionViolatedException("Permissions to create Symbolic Links not granted", fileSystemException);
        }
    }
    DirConfigSource.DirPropertyWatcher watcher = source.createWatcher(subpath("watcher-files"));
    exec.scheduleWithFixedDelay(watcher, 0, 10, TimeUnit.MILLISECONDS);
    assertEquals("test", source.getValue("watcher-files.foobar"));
    assertEquals("hidden", source.getValue("watcher-files.revealed"));
    // when
    writeFile(subpath("watcher-files", "foobar"), "test2");
    writeFile(subpath("watcher-files", "example"), "test2");
    writeFile(subpath("watcher-files", "reveal", ".hidden"), "test2");
    writeFile(subpath("watcher-files", ".hidden", "foobar"), "showme");
    Files.delete(subpath("watcher-files", "revealed"));
    Files.createSymbolicLink(subpath("watcher-files", "revealed"), subpath("watcher-files", ".hidden", "foobar"));
    Thread.sleep(100);
    // then
    assertEquals("test2", source.getValue("watcher-files.foobar"));
    assertEquals("test2", source.getValue("watcher-files.example"));
    assertEquals("showme", source.getValue("watcher-files.revealed"));
    assertEquals(null, source.getValue("watcher-files.reveal.hidden"));
}
Also used : FileSystemException(java.nio.file.FileSystemException) AssumptionViolatedException(org.junit.AssumptionViolatedException) Test(org.junit.Test)

Aggregations

AssumptionViolatedException (org.junit.AssumptionViolatedException)79 Test (org.junit.Test)26 IOException (java.io.IOException)16 Statement (org.junit.runners.model.Statement)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Method (java.lang.reflect.Method)6 Set (java.util.Set)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 File (java.io.File)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 ZipEntry (java.util.zip.ZipEntry)5 ZipOutputStream (java.util.zip.ZipOutputStream)5 InputStream (java.io.InputStream)4 HashSet (java.util.HashSet)4 ZipInputStream (java.util.zip.ZipInputStream)4 FilterInputStream (java.io.FilterInputStream)3 UnknownHostException (java.net.UnknownHostException)3 JarInputStream (java.util.jar.JarInputStream)3 Configuration (org.apache.flink.configuration.Configuration)3 IInjectorProvider (org.eclipse.xtext.junit4.IInjectorProvider)3