Search in sources :

Example 76 with Timeout

use of org.junit.jupiter.api.Timeout in project zookeeper by apache.

the class CreateContainerTest method testCreateWithStat.

@Test
@Timeout(value = 30)
public void testCreateWithStat() throws KeeperException, InterruptedException {
    Stat stat = createWithStatVerifyResult("/foo");
    Stat childStat = createWithStatVerifyResult("/foo/child");
    // Don't expect to get the same stats for different creates.
    assertFalse(stat.equals(childStat));
}
Also used : Stat(org.apache.zookeeper.data.Stat) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 77 with Timeout

use of org.junit.jupiter.api.Timeout in project zookeeper by apache.

the class X509UtilTest method testCreateSSLServerSocketWithPort.

@ParameterizedTest
@MethodSource("data")
@Timeout(value = 5)
public void testCreateSSLServerSocketWithPort(X509KeyType caKeyType, X509KeyType certKeyType, String keyPassword, Integer paramIndex) throws Exception {
    init(caKeyType, certKeyType, keyPassword, paramIndex);
    setCustomCipherSuites();
    int port = PortAssignment.unique();
    SSLServerSocket sslServerSocket = x509Util.createSSLServerSocket(port);
    assertEquals(sslServerSocket.getLocalPort(), port);
    assertArrayEquals(customCipherSuites, sslServerSocket.getEnabledCipherSuites());
    assertTrue(sslServerSocket.getNeedClientAuth());
}
Also used : SSLServerSocket(javax.net.ssl.SSLServerSocket) Timeout(org.junit.jupiter.api.Timeout) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 78 with Timeout

use of org.junit.jupiter.api.Timeout in project zookeeper by apache.

the class QuorumSSLTest method testQuorumSSL_withPasswordFromFile.

@Test
@Timeout(value = 5, unit = TimeUnit.MINUTES)
public void testQuorumSSL_withPasswordFromFile() throws Exception {
    final Path secretFile = SecretUtilsTest.createSecretFile(String.valueOf(PASSWORD));
    System.clearProperty(quorumX509Util.getSslKeystorePasswdProperty());
    System.setProperty(quorumX509Util.getSslKeystorePasswdPathProperty(), secretFile.toString());
    System.clearProperty(quorumX509Util.getSslTruststorePasswdProperty());
    System.setProperty(quorumX509Util.getSslTruststorePasswdPathProperty(), secretFile.toString());
    q1 = new MainThread(1, clientPortQp1, quorumConfiguration, SSL_QUORUM_ENABLED);
    q2 = new MainThread(2, clientPortQp2, quorumConfiguration, SSL_QUORUM_ENABLED);
    q3 = new MainThread(3, clientPortQp3, quorumConfiguration, SSL_QUORUM_ENABLED);
    q1.start();
    q2.start();
    q3.start();
    assertTrue(ClientBase.waitForServerUp("127.0.0.1:" + clientPortQp1, CONNECTION_TIMEOUT));
    assertTrue(ClientBase.waitForServerUp("127.0.0.1:" + clientPortQp2, CONNECTION_TIMEOUT));
    assertTrue(ClientBase.waitForServerUp("127.0.0.1:" + clientPortQp3, CONNECTION_TIMEOUT));
}
Also used : Path(java.nio.file.Path) SecretUtilsTest(org.apache.zookeeper.common.SecretUtilsTest) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 79 with Timeout

use of org.junit.jupiter.api.Timeout in project zookeeper by apache.

the class QuorumSSLTest method testHostnameVerificationWithInvalidIpAddressAndValidHostname.

@Test
@Timeout(value = 5, unit = TimeUnit.MINUTES)
public void testHostnameVerificationWithInvalidIpAddressAndValidHostname() throws Exception {
    String badhostnameKeystorePath = tmpDir + "/badhost.jks";
    X509Certificate badHostCert = buildEndEntityCert(defaultKeyPair, rootCertificate, rootKeyPair.getPrivate(), "localhost", "140.211.11.105", null, null);
    writeKeystore(badHostCert, defaultKeyPair, badhostnameKeystorePath);
    testHostnameVerification(badhostnameKeystorePath, true);
}
Also used : X509Certificate(java.security.cert.X509Certificate) SecretUtilsTest(org.apache.zookeeper.common.SecretUtilsTest) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 80 with Timeout

use of org.junit.jupiter.api.Timeout in project zookeeper by apache.

the class QuorumSSLTest method testOCSP.

@Test
@Timeout(value = 5, unit = TimeUnit.MINUTES)
public void testOCSP() throws Exception {
    Integer ocspPort = PortAssignment.unique();
    q1 = new MainThread(1, clientPortQp1, quorumConfiguration, SSL_QUORUM_ENABLED);
    q2 = new MainThread(2, clientPortQp2, quorumConfiguration, SSL_QUORUM_ENABLED);
    q1.start();
    q2.start();
    assertTrue(ClientBase.waitForServerUp("127.0.0.1:" + clientPortQp1, CONNECTION_TIMEOUT));
    assertTrue(ClientBase.waitForServerUp("127.0.0.1:" + clientPortQp2, CONNECTION_TIMEOUT));
    String revokedInOCSPKeystorePath = tmpDir + "/ocsp_revoked.jks";
    X509Certificate revokedInOCSPCert = buildEndEntityCert(defaultKeyPair, rootCertificate, rootKeyPair.getPrivate(), HOSTNAME, null, null, ocspPort);
    writeKeystore(revokedInOCSPCert, defaultKeyPair, revokedInOCSPKeystorePath);
    HttpServer ocspServer = HttpServer.create(new InetSocketAddress(ocspPort), 0);
    try {
        ocspServer.createContext("/", new OCSPHandler(revokedInOCSPCert));
        ocspServer.start();
        System.setProperty(quorumX509Util.getSslKeystoreLocationProperty(), revokedInOCSPKeystorePath);
        // This server should join successfully
        q3 = new MainThread(3, clientPortQp3, quorumConfiguration, SSL_QUORUM_ENABLED);
        q3.start();
        assertTrue(ClientBase.waitForServerUp("127.0.0.1:" + clientPortQp3, CONNECTION_TIMEOUT));
        q1.shutdown();
        q2.shutdown();
        q3.shutdown();
        assertTrue(ClientBase.waitForServerDown("127.0.0.1:" + clientPortQp1, CONNECTION_TIMEOUT));
        assertTrue(ClientBase.waitForServerDown("127.0.0.1:" + clientPortQp2, CONNECTION_TIMEOUT));
        assertTrue(ClientBase.waitForServerDown("127.0.0.1:" + clientPortQp3, CONNECTION_TIMEOUT));
        setSSLSystemProperties();
        System.setProperty(quorumX509Util.getSslOcspEnabledProperty(), "true");
        X509Certificate validCertificate = buildEndEntityCert(defaultKeyPair, rootCertificate, rootKeyPair.getPrivate(), HOSTNAME, null, null, ocspPort);
        writeKeystore(validCertificate, defaultKeyPair, validKeystorePath);
        q1.start();
        q2.start();
        assertTrue(ClientBase.waitForServerUp("127.0.0.1:" + clientPortQp1, CONNECTION_TIMEOUT));
        assertTrue(ClientBase.waitForServerUp("127.0.0.1:" + clientPortQp2, CONNECTION_TIMEOUT));
        System.setProperty(quorumX509Util.getSslKeystoreLocationProperty(), revokedInOCSPKeystorePath);
        q3.start();
        assertFalse(ClientBase.waitForServerUp("127.0.0.1:" + clientPortQp3, CONNECTION_TIMEOUT));
    } finally {
        ocspServer.stop(0);
    }
}
Also used : BigInteger(java.math.BigInteger) InetSocketAddress(java.net.InetSocketAddress) HttpServer(com.sun.net.httpserver.HttpServer) X509Certificate(java.security.cert.X509Certificate) SecretUtilsTest(org.apache.zookeeper.common.SecretUtilsTest) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Aggregations

Timeout (org.junit.jupiter.api.Timeout)291 Test (org.junit.jupiter.api.Test)235 CountDownLatch (java.util.concurrent.CountDownLatch)71 ZooKeeper (org.apache.zookeeper.ZooKeeper)33 AtomicReference (java.util.concurrent.atomic.AtomicReference)32 ArrayList (java.util.ArrayList)31 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)29 RepeatedTest (org.junit.jupiter.api.RepeatedTest)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)29 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)28 LocalChannel (io.netty.channel.local.LocalChannel)27 CountdownWatcher (org.apache.zookeeper.test.ClientBase.CountdownWatcher)26 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)25 IOException (java.io.IOException)25 Bootstrap (io.netty.bootstrap.Bootstrap)24 MethodSource (org.junit.jupiter.params.provider.MethodSource)24 Channel (io.netty.channel.Channel)23 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)21 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)19 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)19