use of org.apache.zookeeper.test.ClientBase.CountdownWatcher in project zookeeper by apache.
the class QuorumKerberosHostBasedAuthTest method testValidCredentialsWithMultiAddresses.
/**
* Test to verify that server is able to start with valid credentials
* when using multiple Quorum / Election addresses
*/
@Test
@Timeout(value = 120)
public void testValidCredentialsWithMultiAddresses() throws Exception {
String serverPrincipal = hostServerPrincipal.substring(0, hostServerPrincipal.lastIndexOf("@"));
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");
authConfigs.put(QuorumAuth.QUORUM_KERBEROS_SERVICE_PRINCIPAL, serverPrincipal);
String connectStr = startMultiAddressQuorum(3, authConfigs, 3);
CountdownWatcher watcher = new CountdownWatcher();
ZooKeeper zk = new ZooKeeper(connectStr, ClientBase.CONNECTION_TIMEOUT, watcher);
watcher.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
for (int i = 0; i < 10; i++) {
zk.create("/" + i, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
zk.close();
}
use of org.apache.zookeeper.test.ClientBase.CountdownWatcher in project zookeeper by apache.
the class QuorumAuthUpgradeTest method testRollingUpgrade.
/**
* Rolling upgrade should do in three steps:
*
* step-1) Stop the server and set the flags and restart the server.
* quorum.auth.enableSasl=true, quorum.auth.learnerRequireSasl=false and quorum.auth.serverRequireSasl=false
* Ensure that all the servers should complete this step. Now, move to next step.
*
* step-2) Stop the server one by one and change the flags and restart the server.
* quorum.auth.enableSasl=true, quorum.auth.learnerRequireSasl=true and quorum.auth.serverRequireSasl=false
* Ensure that all the servers should complete this step. Now, move to next step.
*
* step-3) Stop the server one by one and change the flags and restart the server.
* quorum.auth.enableSasl=true, quorum.auth.learnerRequireSasl=true and quorum.auth.serverRequireSasl=true
* Now, all the servers are fully upgraded and running in secured mode.
*/
@Test
@Timeout(value = 90)
public void testRollingUpgrade() throws Exception {
// Start peer0,1,2 servers with quorum.auth.enableSasl=false and
// quorum.auth.learnerRequireSasl=false, quorum.auth.serverRequireSasl=false
// Assume this is an existing cluster.
Map<String, String> authConfigs = new HashMap<String, String>();
authConfigs.put(QuorumAuth.QUORUM_SASL_AUTH_ENABLED, "false");
String connectStr = startQuorum(3, authConfigs, 0);
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_SEQUENTIAL);
// 1. Upgrade peer0,1,2 with quorum.auth.enableSasl=true and
// quorum.auth.learnerRequireSasl=false, quorum.auth.serverRequireSasl=false
authConfigs.put(QuorumAuth.QUORUM_SASL_AUTH_ENABLED, "true");
authConfigs.put(QuorumAuth.QUORUM_SERVER_SASL_AUTH_REQUIRED, "false");
authConfigs.put(QuorumAuth.QUORUM_LEARNER_SASL_AUTH_REQUIRED, "false");
restartServer(authConfigs, 0, zk, watcher);
restartServer(authConfigs, 1, zk, watcher);
restartServer(authConfigs, 2, zk, watcher);
// 2. Upgrade peer0,1,2 with quorum.auth.enableSasl=true and
// quorum.auth.learnerRequireSasl=true, quorum.auth.serverRequireSasl=false
authConfigs.put(QuorumAuth.QUORUM_SASL_AUTH_ENABLED, "true");
authConfigs.put(QuorumAuth.QUORUM_LEARNER_SASL_AUTH_REQUIRED, "true");
authConfigs.put(QuorumAuth.QUORUM_SERVER_SASL_AUTH_REQUIRED, "false");
restartServer(authConfigs, 0, zk, watcher);
restartServer(authConfigs, 1, zk, watcher);
restartServer(authConfigs, 2, zk, watcher);
// 3. Upgrade peer0,1,2 with quorum.auth.enableSasl=true and
// quorum.auth.learnerRequireSasl=true, quorum.auth.serverRequireSasl=true
authConfigs.put(QuorumAuth.QUORUM_SASL_AUTH_ENABLED, "true");
authConfigs.put(QuorumAuth.QUORUM_LEARNER_SASL_AUTH_REQUIRED, "true");
authConfigs.put(QuorumAuth.QUORUM_SERVER_SASL_AUTH_REQUIRED, "true");
restartServer(authConfigs, 0, zk, watcher);
restartServer(authConfigs, 1, zk, watcher);
restartServer(authConfigs, 2, zk, watcher);
// 4. Restart peer2 with quorum.auth.learnerEnableSasl=false and
// quorum.auth.serverRequireSasl=false. It should fail to join the
// quorum as this needs auth.
authConfigs.put(QuorumAuth.QUORUM_SASL_AUTH_ENABLED, "false");
MainThread m = shutdown(2);
startServer(m, authConfigs);
assertFalse(ClientBase.waitForServerUp("127.0.0.1:" + m.getClientPort(), 5000), "waiting for server 2 being up");
}
use of org.apache.zookeeper.test.ClientBase.CountdownWatcher in project zookeeper by apache.
the class QuorumAuthUpgradeTest method testAuthLearnerAgainstNoAuthRequiredServer.
/**
* Test to verify that servers are able to form quorum.
* peer0 -> quorum.auth.enableSasl=true, quorum.auth.learnerRequireSasl=false, quorum.auth.serverRequireSasl=false
* peer1 -> quorum.auth.enableSasl=true, quorum.auth.learnerRequireSasl=false, quorum.auth.serverRequireSasl=false
*/
@Test
@Timeout(value = 30)
public void testAuthLearnerAgainstNoAuthRequiredServer() throws Exception {
Map<String, String> authConfigs = new HashMap<String, String>();
authConfigs.put(QuorumAuth.QUORUM_SASL_AUTH_ENABLED, "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();
}
use of org.apache.zookeeper.test.ClientBase.CountdownWatcher in project zookeeper by apache.
the class QuorumAuthUpgradeTest method testNullAuthLearnerServer.
/**
* Test to verify that servers are able to start without any authentication.
* peer0 -> quorum.auth.enableSasl=false
* peer1 -> quorum.auth.enableSasl=false
*/
@Test
@Timeout(value = 30)
public void testNullAuthLearnerServer() throws Exception {
Map<String, String> authConfigs = new HashMap<String, String>();
authConfigs.put(QuorumAuth.QUORUM_SASL_AUTH_ENABLED, "false");
String connectStr = startQuorum(2, authConfigs, 0);
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();
}
use of org.apache.zookeeper.test.ClientBase.CountdownWatcher in project zookeeper by apache.
the class SessionUpgradeTest method testLocalSessionsWithoutEphemeral.
private void testLocalSessionsWithoutEphemeral(boolean testLeader) throws Exception {
String nodePrefix = "/testLocalSessions-" + (testLeader ? "leaderTest-" : "followerTest-");
int leaderIdx = qb.getLeaderIndex();
assertFalse(leaderIdx == -1, "No leader in quorum?");
int followerIdx = (leaderIdx + 1) % 5;
int otherFollowerIdx = (leaderIdx + 2) % 5;
int testPeerIdx = testLeader ? leaderIdx : followerIdx;
String[] hostPorts = qb.hostPort.split(",");
CountdownWatcher watcher = new CountdownWatcher();
DisconnectableZooKeeper zk = new DisconnectableZooKeeper(hostPorts[testPeerIdx], CONNECTION_TIMEOUT, watcher);
watcher.waitForConnected(CONNECTION_TIMEOUT);
// Try creating some data.
for (int i = 0; i < 5; i++) {
zk.create(nodePrefix + i, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
long localSessionId = zk.getSessionId();
byte[] localSessionPwd = zk.getSessionPasswd().clone();
// server. This should fail since it is a local sesion.
try {
watcher.reset();
DisconnectableZooKeeper zknew = new DisconnectableZooKeeper(hostPorts[otherFollowerIdx], CONNECTION_TIMEOUT, watcher, localSessionId, localSessionPwd);
zknew.create(nodePrefix + "5", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
fail("Connection on the same session ID should fail.");
} catch (KeeperException.SessionExpiredException e) {
} catch (KeeperException.ConnectionLossException e) {
}
// leader. This should also fail
if (!testLeader) {
try {
watcher.reset();
DisconnectableZooKeeper zknew = new DisconnectableZooKeeper(hostPorts[leaderIdx], CONNECTION_TIMEOUT, watcher, localSessionId, localSessionPwd);
zknew.create(nodePrefix + "5", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
fail("Connection on the same session ID should fail.");
} catch (KeeperException.SessionExpiredException e) {
} catch (KeeperException.ConnectionLossException e) {
}
}
// However, we should be able to disconnect and reconnect to the same
// server with the same session id (as long as we do it quickly
// before expiration).
zk.disconnect();
watcher.reset();
zk = new DisconnectableZooKeeper(hostPorts[testPeerIdx], CONNECTION_TIMEOUT, watcher, localSessionId, localSessionPwd);
watcher.waitForConnected(CONNECTION_TIMEOUT);
zk.create(nodePrefix + "6", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
// If we explicitly close the session, then the session id should no
// longer be valid.
zk.close();
try {
watcher.reset();
zk = new DisconnectableZooKeeper(hostPorts[testPeerIdx], CONNECTION_TIMEOUT, watcher, localSessionId, localSessionPwd);
zk.create(nodePrefix + "7", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
fail("Reconnecting to a closed session ID should fail.");
} catch (KeeperException.SessionExpiredException e) {
}
}
Aggregations