Search in sources :

Example 66 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project pinpoint by naver.

the class SocketAddressUtilsTest method setNameServiceFieldValue.

private static void setNameServiceFieldValue(String fieldName, Object nameService) {
    try {
        Field nameServiceField = InetAddress.class.getDeclaredField(fieldName);
        nameServiceField.setAccessible(true);
        nameServiceField.set(null, nameService);
    } catch (NoSuchFieldException e) {
        throw new IllegalStateException("Expected field : [" + fieldName + "] not found");
    } catch (Exception e) {
        LOGGER.error("[{}] {} - Unexpected error while setting field [{}], skipping test", JvmUtils.getType(), JvmUtils.getVersion(), fieldName, e);
        throw new AssumptionViolatedException("Unexpected reflection exception", e);
    }
}
Also used : Field(java.lang.reflect.Field) AssumptionViolatedException(org.junit.AssumptionViolatedException) AssumptionViolatedException(org.junit.AssumptionViolatedException) UnknownHostException(java.net.UnknownHostException)

Example 67 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project pinpoint by naver.

the class SocketAddressUtilsTest method getNameServiceFieldValue.

private static Object getNameServiceFieldValue(String fieldName) {
    try {
        Field nameServiceField = InetAddress.class.getDeclaredField(fieldName);
        nameServiceField.setAccessible(true);
        return nameServiceField.get(null);
    } catch (NoSuchFieldException e) {
        // This can happen depending on jvm
        return null;
    } catch (Exception e) {
        LOGGER.error("[{}] {} - Unexpected error while getting field [{}], skipping test", JvmUtils.getType(), JvmUtils.getVersion(), fieldName, e);
        throw new AssumptionViolatedException("Unexpected reflection exception", e);
    }
}
Also used : Field(java.lang.reflect.Field) AssumptionViolatedException(org.junit.AssumptionViolatedException) AssumptionViolatedException(org.junit.AssumptionViolatedException) UnknownHostException(java.net.UnknownHostException)

Example 68 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project instrumentation-java by census-instrumentation.

the class JaegerExporterHandlerIntegrationTest method startContainer.

/**
 * Starts a docker container optionally. For example, skips if Docker is unavailable.
 */
@SuppressWarnings("rawtypes")
@BeforeClass
public static void startContainer() {
    try {
        container = new GenericContainer(JAEGER_IMAGE).withExposedPorts(JAEGER_HTTP_PORT, JAEGER_HTTP_PORT_THRIFT).waitingFor(new HttpWaitStrategy());
        container.start();
    } catch (RuntimeException e) {
        throw new AssumptionViolatedException("could not start docker container", e);
    }
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) HttpWaitStrategy(org.testcontainers.containers.wait.strategy.HttpWaitStrategy) GenericContainer(org.testcontainers.containers.GenericContainer) BeforeClass(org.junit.BeforeClass)

Example 69 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project alluxio by Alluxio.

the class BaseIntegrationTest method logHandler.

private TestWatcher logHandler() {
    return new TestWatcher() {

        private String mLogPath;

        private Appender mAppender;

        @Override
        protected void starting(Description description) {
            try {
                mLogPath = logPath(description);
                // In case the file already exists, truncate it.
                new FileWriter(mLogPath).close();
                mAppender = new FileAppender(new PatternLayout("%d{ISO8601} [%t] %-5p %c{2} (%F:%M) - %m%n"), mLogPath);
                LogManager.getRootLogger().addAppender(mAppender);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        protected void succeeded(Description description) {
            try {
                Files.delete(Paths.get(mLogPath));
            } catch (Throwable t) {
                LOG.error("Failed to delete success log file {}", mLogPath);
            }
        }

        @Override
        protected void skipped(AssumptionViolatedException e, Description description) {
            succeeded(description);
        }

        @Override
        protected void finished(Description description) {
            LogManager.getRootLogger().removeAppender(mAppender);
        }

        private String logPath(Description description) {
            String basename = String.format("tests-%s-%s.log", description.getClassName(), description.getMethodName());
            return PathUtils.concatPath(Constants.TEST_LOG_DIR, basename);
        }
    };
}
Also used : Appender(org.apache.log4j.Appender) FileAppender(org.apache.log4j.FileAppender) FileAppender(org.apache.log4j.FileAppender) Description(org.junit.runner.Description) TestWatcher(org.junit.rules.TestWatcher) AssumptionViolatedException(org.junit.AssumptionViolatedException) FileWriter(java.io.FileWriter) PatternLayout(org.apache.log4j.PatternLayout) IOException(java.io.IOException)

Example 70 with AssumptionViolatedException

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

the class JdkSslEngineTest method testAlpnCompatibleProtocolsDifferentClientOrder.

@MethodSource("newJdkParams")
@ParameterizedTest
public void testAlpnCompatibleProtocolsDifferentClientOrder(JdkSSLEngineTestParam param) throws Exception {
    try {
        param.providerType.activate(this);
        if (param.providerType == ProviderType.NPN_JETTY) {
            // This test only applies to ALPN.
            throw tlsExtensionNotFound(param.providerType.protocol());
        }
        // Even the preferred application protocol appears second in the client's list, it will be picked
        // because it's the first one on server's list.
        ApplicationProtocolConfig clientApn = acceptingNegotiator(Protocol.ALPN, FALLBACK_APPLICATION_LEVEL_PROTOCOL, PREFERRED_APPLICATION_LEVEL_PROTOCOL);
        ApplicationProtocolConfig serverApn = failingNegotiator(Protocol.ALPN, PREFERRED_APPLICATION_LEVEL_PROTOCOL, FALLBACK_APPLICATION_LEVEL_PROTOCOL);
        setupHandlers(param, serverApn, clientApn);
        assertNull(serverException);
        runTest(PREFERRED_APPLICATION_LEVEL_PROTOCOL);
    } catch (SkipTestException e) {
        // java version incompatibility don't fail the test, but instead just skip the test
        throw new AssumptionViolatedException("Not expected", e);
    }
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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