Search in sources :

Example 1 with MainThread

use of org.apache.zookeeper.server.quorum.QuorumPeerTestBase.MainThread in project zookeeper by apache.

the class QuorumAuthTestBase method startServer.

private void startServer(Map<String, String> authConfigs, final int[] clientPorts, String quorumCfg, int i) throws IOException {
    MainThread mthread = new MainThread(i, clientPorts[i], quorumCfg, authConfigs);
    mt.add(mthread);
    mthread.start();
}
Also used : MainThread(org.apache.zookeeper.server.quorum.QuorumPeerTestBase.MainThread)

Example 2 with MainThread

use of org.apache.zookeeper.server.quorum.QuorumPeerTestBase.MainThread in project zookeeper by apache.

the class QuorumAuthTestBase method startServer.

protected void startServer(MainThread restartPeer, Map<String, String> authConfigs) throws IOException {
    MainThread mthread = new MainThread(restartPeer.getMyid(), restartPeer.getClientPort(), restartPeer.getQuorumCfgSection(), authConfigs);
    mt.add(mthread);
    mthread.start();
}
Also used : MainThread(org.apache.zookeeper.server.quorum.QuorumPeerTestBase.MainThread)

Example 3 with MainThread

use of org.apache.zookeeper.server.quorum.QuorumPeerTestBase.MainThread in project zookeeper by apache.

the class QuorumAuthTestBase method startQuorum.

protected int[] startQuorum(final int serverCount, StringBuilder connectStr, Map<String, String> authConfigs, int authServerCount) throws IOException {
    final int[] clientPorts = new int[serverCount];
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < serverCount; i++) {
        clientPorts[i] = PortAssignment.unique();
        String server = String.format("server.%d=localhost:%d:%d:participant", i, PortAssignment.unique(), PortAssignment.unique());
        sb.append(server + "\n");
        connectStr.append("127.0.0.1:" + clientPorts[i]);
        if (i < serverCount - 1) {
            connectStr.append(",");
        }
    }
    String quorumCfg = sb.toString();
    // servers with authentication interfaces configured
    int i = 0;
    for (; i < authServerCount; i++) {
        startServer(authConfigs, clientPorts, quorumCfg, i);
    }
    // servers without any authentication configured
    for (int j = 0; j < serverCount - authServerCount; j++, i++) {
        MainThread mthread = new MainThread(i, clientPorts[i], quorumCfg);
        mt.add(mthread);
        mthread.start();
    }
    return clientPorts;
}
Also used : MainThread(org.apache.zookeeper.server.quorum.QuorumPeerTestBase.MainThread)

Example 4 with MainThread

use of org.apache.zookeeper.server.quorum.QuorumPeerTestBase.MainThread in project zookeeper by apache.

the class QuorumAuthUpgradeTest method restartServer.

private void restartServer(Map<String, String> authConfigs, int index, ZooKeeper zk, CountdownWatcher watcher) throws IOException, KeeperException, InterruptedException, TimeoutException {
    LOG.info("Restarting server myid=" + index);
    MainThread m = shutdown(index);
    startServer(m, authConfigs);
    Assert.assertTrue("waiting for server" + index + "being up", ClientBase.waitForServerUp("127.0.0.1:" + m.getClientPort(), ClientBase.CONNECTION_TIMEOUT));
    watcher.waitForConnected(ClientTest.CONNECTION_TIMEOUT);
    zk.create("/foo", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
}
Also used : MainThread(org.apache.zookeeper.server.quorum.QuorumPeerTestBase.MainThread)

Example 5 with MainThread

use of org.apache.zookeeper.server.quorum.QuorumPeerTestBase.MainThread in project zookeeper by apache.

the class QuorumDigestAuthTest method testEnableQuorumServerRequireSaslWithoutQuorumLearnerRequireSasl.

/**
 * If quorumpeer learner is not auth enabled then self won't be able to join
 * quorum. So this test is ensuring that the quorumpeer learner is also auth
 * enabled while enabling quorum server require sasl.
 */
@Test(timeout = 10000)
public void testEnableQuorumServerRequireSaslWithoutQuorumLearnerRequireSasl() throws Exception {
    Map<String, String> authConfigs = new HashMap<String, String>();
    authConfigs.put(QuorumAuth.QUORUM_LEARNER_SASL_LOGIN_CONTEXT, "QuorumLearner");
    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, "false");
    MainThread mthread = new MainThread(1, PortAssignment.unique(), "", authConfigs);
    String[] args = new String[1];
    args[0] = mthread.getConfFile().toString();
    try {
        new QuorumPeerMain() {

            @Override
            protected void initializeAndRun(String[] args) throws ConfigException, IOException, AdminServer.AdminServerException {
                super.initializeAndRun(args);
            }
        }.initializeAndRun(args);
        Assert.fail("Must throw exception as quorumpeer learner is not enabled!");
    } catch (ConfigException e) {
    // expected
    }
}
Also used : MainThread(org.apache.zookeeper.server.quorum.QuorumPeerTestBase.MainThread) QuorumPeerMain(org.apache.zookeeper.server.quorum.QuorumPeerMain) HashMap(java.util.HashMap) ConfigException(org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

MainThread (org.apache.zookeeper.server.quorum.QuorumPeerTestBase.MainThread)12 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 After (org.junit.After)3 IOException (java.io.IOException)2 ZooKeeper (org.apache.zookeeper.ZooKeeper)2 ConfigException (org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException)2 QuorumPeerMain (org.apache.zookeeper.server.quorum.QuorumPeerMain)2 CountdownWatcher (org.apache.zookeeper.test.ClientBase.CountdownWatcher)2 TimeoutException (java.util.concurrent.TimeoutException)1 ClientTest (org.apache.zookeeper.test.ClientTest)1