Search in sources :

Example 71 with AssumptionViolatedException

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

the class JdkSslEngineTest method testTlsExtensionNoCompatibleProtocolsClientHandshakeFailure.

@MethodSource("newJdkParams")
@ParameterizedTest
public void testTlsExtensionNoCompatibleProtocolsClientHandshakeFailure(JdkSSLEngineTestParam param) throws Exception {
    try {
        param.providerType.activate(this);
        if (param.providerType == ProviderType.NPN_JETTY) {
            ApplicationProtocolConfig clientApn = failingNegotiator(param.providerType.protocol(), PREFERRED_APPLICATION_LEVEL_PROTOCOL);
            ApplicationProtocolConfig serverApn = acceptingNegotiator(param.providerType.protocol(), APPLICATION_LEVEL_PROTOCOL_NOT_COMPATIBLE);
            setupHandlers(param, serverApn, clientApn);
            assertTrue(clientLatch.await(2, TimeUnit.SECONDS));
            assertTrue(clientException instanceof SSLHandshakeException);
        } else {
            // ALPN
            SelfSignedCertificate ssc = new SelfSignedCertificate();
            JdkApplicationProtocolNegotiator clientApn = new JdkAlpnApplicationProtocolNegotiator(true, true, PREFERRED_APPLICATION_LEVEL_PROTOCOL);
            JdkApplicationProtocolNegotiator serverApn = new JdkAlpnApplicationProtocolNegotiator(new ProtocolSelectorFactory() {

                @Override
                public ProtocolSelector newSelector(SSLEngine engine, Set<String> supportedProtocols) {
                    return new ProtocolSelector() {

                        @Override
                        public void unsupported() {
                        }

                        @Override
                        public String select(List<String> protocols) {
                            return APPLICATION_LEVEL_PROTOCOL_NOT_COMPATIBLE;
                        }
                    };
                }
            }, JdkBaseApplicationProtocolNegotiator.FAIL_SELECTION_LISTENER_FACTORY, APPLICATION_LEVEL_PROTOCOL_NOT_COMPATIBLE);
            SslContext serverSslCtx = new JdkSslServerContext(param.providerType.provider(), ssc.certificate(), ssc.privateKey(), null, null, IdentityCipherSuiteFilter.INSTANCE, serverApn, 0, 0, null);
            SslContext clientSslCtx = new JdkSslClientContext(param.providerType.provider(), null, InsecureTrustManagerFactory.INSTANCE, null, IdentityCipherSuiteFilter.INSTANCE, clientApn, 0, 0);
            setupHandlers(param.type(), param.delegate(), new TestDelegatingSslContext(param, serverSslCtx), new TestDelegatingSslContext(param, clientSslCtx));
            assertTrue(clientLatch.await(2, TimeUnit.SECONDS));
            // When using TLSv1.3 the handshake is NOT sent in an extra round trip which means there will be
            // no exception reported in this case but just the channel will be closed.
            assertTrue(clientException instanceof SSLHandshakeException || clientException == null);
        }
    } 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 : SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) AssumptionViolatedException(org.junit.AssumptionViolatedException) SSLEngine(javax.net.ssl.SSLEngine) ProtocolSelectorFactory(io.netty.handler.ssl.JdkApplicationProtocolNegotiator.ProtocolSelectorFactory) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) ProtocolSelector(io.netty.handler.ssl.JdkApplicationProtocolNegotiator.ProtocolSelector) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 72 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project java-sdk by watson-developer-cloud.

the class NaturalLanguageClassifierIT method bGetClassifier.

/**
 * Test get classifier.
 */
@Test
public void bGetClassifier() {
    final Classifier classifier;
    try {
        GetClassifierOptions getOptions = new GetClassifierOptions.Builder().classifierId(classifierId).build();
        classifier = service.getClassifier(getOptions).execute();
    } catch (NotFoundException e) {
        // The build should not fail here, because this is out of our control.
        throw new AssumptionViolatedException(e.getMessage(), e);
    }
    assertNotNull(classifier);
    assertEquals(classifierId, classifier.getClassifierId());
    assertEquals(Classifier.Status.TRAINING, classifier.getStatus());
}
Also used : GetClassifierOptions(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.GetClassifierOptions) AssumptionViolatedException(org.junit.AssumptionViolatedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Classifier(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classifier) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 73 with AssumptionViolatedException

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

the class SocketClientSinkTest method testRetry.

@Test
public void testRetry() throws Exception {
    final ServerSocket[] serverSocket = new ServerSocket[1];
    final ExecutorService[] executor = new ExecutorService[1];
    try {
        serverSocket[0] = new ServerSocket(0);
        executor[0] = Executors.newCachedThreadPool();
        int port = serverSocket[0].getLocalPort();
        Callable<Void> serverTask = new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                Socket socket = NetUtils.acceptWithoutTimeout(serverSocket[0]);
                BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                String value = reader.readLine();
                assertEquals("0", value);
                socket.close();
                return null;
            }
        };
        Future<Void> serverFuture = executor[0].submit(serverTask);
        final SocketClientSink<String> sink = new SocketClientSink<>(host, serverSocket[0].getLocalPort(), simpleSchema, -1, true);
        // Create the connection
        sink.open(new Configuration());
        // Initial payload => this will be received by the server an then the socket will be
        // closed.
        sink.invoke("0\n", SinkContextUtil.forTimestamp(0));
        // Get future an make sure there was no problem. This will rethrow any Exceptions from
        // the server.
        serverFuture.get();
        // Shutdown the server socket
        serverSocket[0].close();
        assertTrue(serverSocket[0].isClosed());
        // No retries expected at this point
        assertEquals(0, sink.getCurrentNumberOfRetries());
        final CountDownLatch retryLatch = new CountDownLatch(1);
        final CountDownLatch again = new CountDownLatch(1);
        Callable<Void> sinkTask = new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                // connection.
                while (retryLatch.getCount() != 0) {
                    sink.invoke("1\n");
                }
                return null;
            }
        };
        Future<Void> sinkFuture = executor[0].submit(sinkTask);
        while (sink.getCurrentNumberOfRetries() == 0) {
            // Wait for a retry
            Thread.sleep(100);
        }
        // OK the poor guy retried to write
        retryLatch.countDown();
        // Restart the server
        try {
            serverSocket[0] = new ServerSocket(port);
        } catch (BindException be) {
            // some other process may be using this port now
            throw new AssumptionViolatedException("Could not bind server to previous port.", be);
        }
        Socket socket = NetUtils.acceptWithoutTimeout(serverSocket[0]);
        BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        // Wait for the reconnect
        String value = reader.readLine();
        assertEquals("1", value);
    // OK the sink re-connected. :)
    } finally {
        if (serverSocket[0] != null) {
            serverSocket[0].close();
        }
        if (executor[0] != null) {
            executor[0].shutdown();
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Configuration(org.apache.flink.configuration.Configuration) AssumptionViolatedException(org.junit.AssumptionViolatedException) BindException(java.net.BindException) ServerSocket(java.net.ServerSocket) CountDownLatch(java.util.concurrent.CountDownLatch) Callable(java.util.concurrent.Callable) ExecutorService(java.util.concurrent.ExecutorService) BufferedReader(java.io.BufferedReader) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Test(org.junit.Test)

Example 74 with AssumptionViolatedException

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

the class NettyEpollITCase method trySetUpCluster.

private MiniClusterWithClientResource trySetUpCluster() throws Exception {
    try {
        Configuration config = new Configuration();
        config.setString(NettyShuffleEnvironmentOptions.TRANSPORT_TYPE, "epoll");
        MiniClusterWithClientResource cluster = new MiniClusterWithClientResource(new MiniClusterResourceConfiguration.Builder().setConfiguration(config).setNumberTaskManagers(NUM_TASK_MANAGERS).setNumberSlotsPerTaskManager(1).build());
        cluster.before();
        return cluster;
    } catch (UnsatisfiedLinkError ex) {
        // If we failed to init netty because we are not on Linux platform, abort the test.
        if (findThrowableWithMessage(ex, "Only supported on Linux").isPresent()) {
            throw new AssumptionViolatedException("This test is only supported on linux");
        }
        throw ex;
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) AssumptionViolatedException(org.junit.AssumptionViolatedException) MiniClusterWithClientResource(org.apache.flink.test.util.MiniClusterWithClientResource) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration)

Example 75 with AssumptionViolatedException

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

the class IPv6HostnamesITCase method getConfiguration.

private Configuration getConfiguration() {
    final Inet6Address ipv6address = getLocalIPv6Address();
    if (ipv6address == null) {
        throw new AssumptionViolatedException("--- Cannot find a non-loopback local IPv6 address that Akka/Netty can bind to; skipping IPv6HostnamesITCase");
    }
    final String addressString = ipv6address.getHostAddress();
    log.info("Test will use IPv6 address " + addressString + " for connection tests");
    Configuration config = new Configuration();
    config.setString(JobManagerOptions.ADDRESS, addressString);
    config.setString(TaskManagerOptions.HOST, addressString);
    config.set(TaskManagerOptions.MANAGED_MEMORY_SIZE, MemorySize.parse("16m"));
    return config;
}
Also used : MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) Configuration(org.apache.flink.configuration.Configuration) AssumptionViolatedException(org.junit.AssumptionViolatedException) Inet6Address(java.net.Inet6Address)

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