Search in sources :

Example 86 with Timeout

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

the class MiniKdcTest method testKerberosLogin.

@Test
@Timeout(value = 60)
public void testKerberosLogin() throws Exception {
    MiniKdc kdc = getKdc();
    File workDir = getWorkDir();
    LoginContext loginContext = null;
    try {
        String principal = "foo";
        File keytab = new File(workDir, "foo.keytab");
        kdc.createPrincipal(keytab, principal);
        Set<Principal> principals = new HashSet<Principal>();
        principals.add(new KerberosPrincipal(principal));
        // client login
        Subject subject = new Subject(false, principals, new HashSet<Object>(), new HashSet<Object>());
        loginContext = new LoginContext("", subject, null, KerberosConfiguration.createClientConfig(principal, keytab));
        loginContext.login();
        subject = loginContext.getSubject();
        assertEquals(1, subject.getPrincipals().size());
        assertEquals(KerberosPrincipal.class, subject.getPrincipals().iterator().next().getClass());
        assertEquals(principal + "@" + kdc.getRealm(), subject.getPrincipals().iterator().next().getName());
        loginContext.logout();
        // server login
        subject = new Subject(false, principals, new HashSet<Object>(), new HashSet<Object>());
        loginContext = new LoginContext("", subject, null, KerberosConfiguration.createServerConfig(principal, keytab));
        loginContext.login();
        subject = loginContext.getSubject();
        assertEquals(1, subject.getPrincipals().size());
        assertEquals(KerberosPrincipal.class, subject.getPrincipals().iterator().next().getClass());
        assertEquals(principal + "@" + kdc.getRealm(), subject.getPrincipals().iterator().next().getName());
        loginContext.logout();
    } finally {
        if (loginContext != null && loginContext.getSubject() != null && !loginContext.getSubject().getPrincipals().isEmpty()) {
            loginContext.logout();
        }
    }
}
Also used : KerberosPrincipal(javax.security.auth.kerberos.KerberosPrincipal) LoginContext(javax.security.auth.login.LoginContext) File(java.io.File) KerberosPrincipal(javax.security.auth.kerberos.KerberosPrincipal) Principal(java.security.Principal) Subject(javax.security.auth.Subject) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 87 with Timeout

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

the class QuorumAuthUpgradeTest method testAuthLearnerServer.

/**
 * Test to verify that servers are able to form quorum.
 * peer0 -&gt; quorum.auth.enableSasl=true, quorum.auth.learnerRequireSasl=true, quorum.auth.serverRequireSasl=true
 * peer1 -&gt; quorum.auth.enableSasl=true, quorum.auth.learnerRequireSasl=true, quorum.auth.serverRequireSasl=true
 */
@Test
@Timeout(value = 30)
public void testAuthLearnerServer() throws Exception {
    Map<String, String> authConfigs = new HashMap<String, String>();
    authConfigs.put(QuorumAuth.QUORUM_SASL_AUTH_ENABLED, "true");
    authConfigs.put(QuorumAuth.QUORUM_SERVER_SASL_AUTH_REQUIRED, "true");
    authConfigs.put(QuorumAuth.QUORUM_LEARNER_SASL_AUTH_REQUIRED, "true");
    String connectStr = startQuorum(2, authConfigs, 2);
    CountdownWatcher watcher = new CountdownWatcher();
    ZooKeeper zk = new ZooKeeper(connectStr, ClientBase.CONNECTION_TIMEOUT, watcher);
    watcher.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
    zk.create("/foo", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.close();
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) HashMap(java.util.HashMap) CountdownWatcher(org.apache.zookeeper.test.ClientBase.CountdownWatcher) ClientTest(org.apache.zookeeper.test.ClientTest) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 88 with Timeout

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

the class ReconfigLegacyTest method testRestartZooKeeperServer.

/**
 * Test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2244
 *
 * @throws Exception
 */
@Test
@Timeout(value = 120)
public void testRestartZooKeeperServer() throws Exception {
    final int[] clientPorts = new int[SERVER_COUNT];
    StringBuilder sb = new StringBuilder();
    String server;
    for (int i = 0; i < SERVER_COUNT; i++) {
        clientPorts[i] = PortAssignment.unique();
        server = "server." + i + "=127.0.0.1:" + PortAssignment.unique() + ":" + PortAssignment.unique() + ":participant;127.0.0.1:" + clientPorts[i];
        sb.append(server + "\n");
    }
    String currentQuorumCfgSection = sb.toString();
    MainThread[] mt = new MainThread[SERVER_COUNT];
    for (int i = 0; i < SERVER_COUNT; i++) {
        mt[i] = new MainThread(i, clientPorts[i], currentQuorumCfgSection, false);
        mt[i].start();
    }
    // ensure server started
    for (int i = 0; i < SERVER_COUNT; i++) {
        assertTrue(ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], CONNECTION_TIMEOUT), "waiting for server " + i + " being up");
    }
    ZooKeeper zk = ClientBase.createZKClient("127.0.0.1:" + clientPorts[0]);
    String zNodePath = "/serverRestartTest";
    String data = "originalData";
    zk.create(zNodePath, data.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.close();
    /**
     * stop two servers out of three and again start them
     */
    mt[0].shutdown();
    mt[1].shutdown();
    mt[0].start();
    mt[1].start();
    // ensure server started
    for (int i = 0; i < SERVER_COUNT; i++) {
        assertTrue(ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], CONNECTION_TIMEOUT), "waiting for server " + i + " being up");
    }
    zk = ClientBase.createZKClient("127.0.0.1:" + clientPorts[0]);
    byte[] dataBytes = zk.getData(zNodePath, null, null);
    String receivedData = new String(dataBytes);
    assertEquals(data, receivedData);
    for (int i = 0; i < SERVER_COUNT; i++) {
        mt[i].shutdown();
    }
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) Test(org.junit.jupiter.api.Test) ReconfigTest(org.apache.zookeeper.test.ReconfigTest) Timeout(org.junit.jupiter.api.Timeout)

Example 89 with Timeout

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

the class FourLetterWordsTest method testFourLetterWords.

/**
 * Test the various four letter words
 */
@Test
@Timeout(value = 30)
public void testFourLetterWords() throws Exception {
    verify("ruok", "imok");
    verify("envi", "java.version");
    verify("conf", "clientPort");
    verify("stat", "Outstanding");
    verify("srvr", "Outstanding");
    verify("cons", "queued");
    verify("dump", "Session");
    verify("wchs", "watches");
    verify("wchp", "");
    verify("wchc", "");
    verify("srst", "reset");
    verify("crst", "reset");
    verify("stat", "Outstanding");
    verify("srvr", "Outstanding");
    verify("cons", "queued");
    verify("gtmk", "306");
    verify("isro", "rw");
    TestableZooKeeper zk = createClient();
    String sid = getHexSessionId(zk.getSessionId());
    verify("stat", "queued");
    verify("srvr", "Outstanding");
    verify("cons", sid);
    verify("dump", sid);
    verify("dirs", "size");
    zk.getData("/", true, null);
    verify("stat", "queued");
    verify("srvr", "Outstanding");
    verify("cons", sid);
    verify("dump", sid);
    verify("wchs", "watching 1");
    verify("wchp", sid);
    verify("wchc", sid);
    verify("dirs", "size");
    zk.close();
    verify("ruok", "imok");
    verify("envi", "java.version");
    verify("conf", "clientPort");
    verify("stat", "Outstanding");
    verify("srvr", "Outstanding");
    verify("cons", "queued");
    verify("dump", "Session");
    verify("wchs", "watch");
    verify("wchp", "");
    verify("wchc", "");
    verify("srst", "reset");
    verify("crst", "reset");
    verify("stat", "Outstanding");
    verify("srvr", "Outstanding");
    verify("cons", "queued");
    verify("mntr", "zk_server_state\tstandalone");
    verify("mntr", "num_alive_connections");
    verify("stat", "Connections");
    verify("srvr", "Connections");
    verify("dirs", "size");
}
Also used : TestableZooKeeper(org.apache.zookeeper.TestableZooKeeper) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 90 with Timeout

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

the class FourLetterWordsWhiteListTest method testFourLetterWordsAllDisabledByDefault.

/*
     * ZOOKEEPER-2693: test white list of four letter words.
     * For 3.5.x default white list is empty. Verify that is
     * the case (except 'stat' command which is enabled in ClientBase
     * which other tests depend on.).
     */
@Test
@Timeout(value = 30)
public void testFourLetterWordsAllDisabledByDefault() throws Exception {
    stopServer();
    FourLetterCommands.resetWhiteList();
    System.setProperty("zookeeper.4lw.commands.whitelist", "stat");
    startServer();
    // Default white list for 3.5.x is empty, so all command should fail.
    verifyAllCommandsFail();
    TestableZooKeeper zk = createClient();
    verifyAllCommandsFail();
    zk.getData("/", true, null);
    verifyAllCommandsFail();
    zk.close();
    verifyFuzzyMatch("stat", "Outstanding");
    verifyAllCommandsFail();
}
Also used : TestableZooKeeper(org.apache.zookeeper.TestableZooKeeper) 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