本文整理汇总了Java中org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT属性的典型用法代码示例。如果您正苦于以下问题:Java ClientBase.CONNECTION_TIMEOUT属性的具体用法?Java ClientBase.CONNECTION_TIMEOUT怎么用?Java ClientBase.CONNECTION_TIMEOUT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.zookeeper.test.ClientBase
的用法示例。
在下文中一共展示了ClientBase.CONNECTION_TIMEOUT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: waitForAll
private void waitForAll(ZooKeeper[] zks, States state) throws InterruptedException {
int iterations = ClientBase.CONNECTION_TIMEOUT / 1000;
boolean someoneNotConnected = true;
while (someoneNotConnected) {
if (iterations-- == 0) {
ClientBase.logAllStackTraces();
throw new RuntimeException("Waiting too long");
}
someoneNotConnected = false;
for (ZooKeeper zk : zks) {
if (zk.getState() != state) {
someoneNotConnected = true;
break;
}
}
Thread.sleep(1000);
}
}
示例2: LaunchServers
/**
* This is a helper function for launching a set of servers
*
* @param numServers
* @return
* @throws IOException
* @throws InterruptedException
*/
private Servers LaunchServers(int numServers) throws IOException, InterruptedException {
int SERVER_COUNT = numServers;
Servers svrs = new Servers();
final int clientPorts[] = new int[SERVER_COUNT];
StringBuilder sb = new StringBuilder();
for (int i = 0; i < SERVER_COUNT; i++) {
clientPorts[i] = PortAssignment.unique();
sb.append("server."+i+"=127.0.0.1:"+PortAssignment.unique()+":"+PortAssignment.unique()+";"+clientPorts[i]+"\n");
}
String quorumCfgSection = sb.toString();
MainThread mt[] = new MainThread[SERVER_COUNT];
ZooKeeper zk[] = new ZooKeeper[SERVER_COUNT];
for (int i = 0; i < SERVER_COUNT; i++) {
mt[i] = new MainThread(i, clientPorts[i], quorumCfgSection);
mt[i].start();
zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], ClientBase.CONNECTION_TIMEOUT, this);
}
waitForAll(zk, States.CONNECTED);
svrs.mt = mt;
svrs.zk = zk;
return svrs;
}
示例3: testValidCredentials
/**
* Test to verify that server is able to start with valid credentials
*/
@Test(timeout = 30000)
public void testValidCredentials() 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(3, authConfigs, 3, false);
CountdownWatcher watcher = new CountdownWatcher();
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);
}
}
示例4: testSaslNotRequiredWithInvalidCredentials
/**
* Test to verify that server is able to start with invalid credentials if
* the configuration is set to quorum.auth.serverRequireSasl=false.
* Quorum will talk each other even if the authentication is not succeeded
*/
@Test(timeout = 30000)
public void testSaslNotRequiredWithInvalidCredentials() throws Exception {
Map<String, String> authConfigs = new HashMap<String, String>();
authConfigs.put(QuorumAuth.QUORUM_LEARNER_SASL_LOGIN_CONTEXT, "QuorumLearnerInvalid");
authConfigs.put(QuorumAuth.QUORUM_SASL_AUTH_ENABLED, "false");
authConfigs.put(QuorumAuth.QUORUM_SERVER_SASL_AUTH_REQUIRED, "false");
String connectStr = startQuorum(3, authConfigs, 3, false);
CountdownWatcher watcher = new CountdownWatcher();
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);
}
}
示例5: testAuthLearnerServer
/**
* Test to verify that servers are able to form quorum.
* peer0 -> quorum.auth.enableSasl=true, quorum.auth.learnerRequireSasl=true, quorum.auth.serverRequireSasl=true
* peer1 -> quorum.auth.enableSasl=true, quorum.auth.learnerRequireSasl=true, quorum.auth.serverRequireSasl=true
*/
@Test(timeout = 30000)
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, false);
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();
}
示例6: LaunchServers
/**
* This is a helper function for launching a set of servers
*
* @param numServers
* @return
* @throws IOException
* @throws InterruptedException
*/
private Servers LaunchServers(int numServers) throws IOException, InterruptedException {
int SERVER_COUNT = numServers;
Servers svrs = new Servers();
final int clientPorts[] = new int[SERVER_COUNT];
StringBuilder sb = new StringBuilder();
for(int i = 0; i < SERVER_COUNT; i++) {
clientPorts[i] = PortAssignment.unique();
sb.append("server."+i+"=127.0.0.1:"+PortAssignment.unique()+":"+PortAssignment.unique()+"\n");
}
String quorumCfgSection = sb.toString();
MainThread mt[] = new MainThread[SERVER_COUNT];
ZooKeeper zk[] = new ZooKeeper[SERVER_COUNT];
for(int i = 0; i < SERVER_COUNT; i++) {
mt[i] = new MainThread(i, clientPorts[i], quorumCfgSection);
mt[i].start();
zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], ClientBase.CONNECTION_TIMEOUT, this);
}
waitForAll(zk, States.CONNECTED);
svrs.mt = mt;
svrs.zk = zk;
return svrs;
}
示例7: testValidCredentials
/**
* Test to verify that server is able to start with valid credentials
*/
@Test(timeout = 120000)
public void testValidCredentials() throws Exception {
String serverPrincipal = KerberosTestUtils.getServerPrincipal();
serverPrincipal = serverPrincipal.substring(0, serverPrincipal.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 = startQuorum(3, authConfigs, 3, true);
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();
}
示例8: testStandalone
/**
* Verify the ability to start a standalone server instance.
*/
@Test
public void testStandalone() throws Exception {
ClientBase.setupTestEnv();
final int CLIENT_PORT = PortAssignment.unique();
MainThread main = new MainThread(CLIENT_PORT, true);
main.start();
Assert.assertTrue("waiting for server being up",
ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT,
CONNECTION_TIMEOUT));
ZooKeeper zk = new ZooKeeper("127.0.0.1:" + CLIENT_PORT,
ClientBase.CONNECTION_TIMEOUT, this);
zk.create("/foo", "foobar".getBytes(), Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
Assert.assertEquals(new String(zk.getData("/foo", null, null)), "foobar");
zk.close();
main.shutdown();
main.join();
main.deleteDirs();
Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT,
ClientBase.CONNECTION_TIMEOUT));
}
示例9: testAutoCreateDataLogDir
/**
* Test verifies the auto creation of data dir and data log dir.
*/
@Test(timeout = 30000)
public void testAutoCreateDataLogDir() throws Exception {
ClientBase.setupTestEnv();
final int CLIENT_PORT = PortAssignment.unique();
MainThread main = new MainThread(CLIENT_PORT, false);
String args[] = new String[1];
args[0] = main.confFile.toString();
main.start();
Assert.assertTrue("waiting for server being up",
ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT,
CONNECTION_TIMEOUT));
ZooKeeper zk = new ZooKeeper("127.0.0.1:" + CLIENT_PORT,
ClientBase.CONNECTION_TIMEOUT, this);
zk.create("/foo", "foobar".getBytes(), Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
Assert.assertEquals(new String(zk.getData("/foo", null, null)),
"foobar");
zk.close();
main.shutdown();
main.join();
main.deleteDirs();
Assert.assertTrue("waiting for server down", ClientBase
.waitForServerDown("127.0.0.1:" + CLIENT_PORT,
ClientBase.CONNECTION_TIMEOUT));
}
示例10: waitForOne
private void waitForOne(ZooKeeper zk, States state) throws InterruptedException {
int iterations = ClientBase.CONNECTION_TIMEOUT / 500;
while (zk.getState() != state) {
if (iterations-- == 0) {
throw new RuntimeException("Waiting too long");
}
Thread.sleep(500);
}
}
示例11: testStandalone
/**
* Verify the ability to start a standalone server instance.
*/
@Test
public void testStandalone() throws Exception {
ClientBase.setupTestEnv();
final int CLIENT_PORT = PortAssignment.unique();
MainThread main = new MainThread(CLIENT_PORT, true, null);
main.start();
Assert.assertTrue("waiting for server being up",
ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT,
CONNECTION_TIMEOUT));
clientConnected = new CountDownLatch(1);
ZooKeeper zk = new ZooKeeper("127.0.0.1:" + CLIENT_PORT,
ClientBase.CONNECTION_TIMEOUT, this);
Assert.assertTrue("Failed to establish zkclient connection!",
clientConnected.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS));
zk.create("/foo", "foobar".getBytes(), Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
Assert.assertEquals(new String(zk.getData("/foo", null, null)), "foobar");
zk.close();
main.shutdown();
main.join();
main.deleteDirs();
Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT,
ClientBase.CONNECTION_TIMEOUT));
}
示例12: testRelectionWithValidCredentials
/**
* Test to verify that server is able to reform quorum if the Leader goes
* down.
*/
@Test(timeout = 30000)
public void testRelectionWithValidCredentials() 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(3, authConfigs, 3, false);
CountdownWatcher watcher = new CountdownWatcher();
zk = new ZooKeeper(connectStr, ClientBase.CONNECTION_TIMEOUT, watcher);
watcher.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
zk.create("/myTestRoot", new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT_SEQUENTIAL);
watcher.reset();
// Shutdown Leader to trigger re-election
QuorumPeer leaderQP = getLeaderQuorumPeer(mt);
LOG.info("Shutdown Leader sid:{} to trigger quorum leader-election",
leaderQP.getId());
shutdownQP(leaderQP);
// Wait for quorum formation
QuorumPeer newLeaderQP = waitForLeader();
assertNotNull("New leader must have been elected by now", newLeaderQP);
watcher.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
zk.create("/myTestRoot", new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT_SEQUENTIAL);
}
示例13: testAuthLearnerAgainstNullAuthServer
/**
* 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=false, quorum.auth.learnerRequireSasl=false, quorum.auth.serverRequireSasl=false
*/
@Test(timeout = 30000)
public void testAuthLearnerAgainstNullAuthServer() throws Exception {
Map<String, String> authConfigs = new HashMap<String, String>();
authConfigs.put(QuorumAuth.QUORUM_SASL_AUTH_ENABLED, "true");
String connectStr = startQuorum(2, authConfigs, 1, false);
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();
}
示例14: testBadPackets
/**
* verify if bad packets are being handled properly
* at the quorum port
* @throws Exception
*/
@Test
public void testBadPackets() throws Exception {
ClientBase.setupTestEnv();
final int CLIENT_PORT_QP1 = PortAssignment.unique();
final int CLIENT_PORT_QP2 = PortAssignment.unique();
int electionPort1 = PortAssignment.unique();
int electionPort2 = PortAssignment.unique();
String quorumCfgSection =
"server.1=127.0.0.1:" + PortAssignment.unique()
+ ":" + electionPort1
+ "\nserver.2=127.0.0.1:" + PortAssignment.unique()
+ ":" + electionPort2;
MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection);
q1.start();
q2.start();
Assert.assertTrue("waiting for server 1 being up",
ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
CONNECTION_TIMEOUT));
Assert.assertTrue("waiting for server 2 being up",
ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2,
CONNECTION_TIMEOUT));
byte[] b = new byte[4];
int length = 1024*1024*1024;
ByteBuffer buff = ByteBuffer.wrap(b);
buff.putInt(length);
buff.position(0);
SocketChannel s = SocketChannel.open(new InetSocketAddress("127.0.0.1", electionPort1));
s.write(buff);
s.close();
buff.position(0);
s = SocketChannel.open(new InetSocketAddress("127.0.0.1", electionPort2));
s.write(buff);
s.close();
ZooKeeper zk = new ZooKeeper("127.0.0.1:" + CLIENT_PORT_QP1,
ClientBase.CONNECTION_TIMEOUT, this);
waitForOne(zk, States.CONNECTED);
zk.create("/foo_q1", "foobar1".getBytes(), Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
Assert.assertEquals(new String(zk.getData("/foo_q1", null, null)), "foobar1");
zk.close();
q1.shutdown();
q2.shutdown();
}
示例15: testNonRecoverableError
/**
* Test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2247.
* Test to verify that even after non recoverable error (error while
* writing transaction log) on ZooKeeper service will be available
*/
@Test(timeout = 30000)
public void testNonRecoverableError() throws Exception {
ClientBase.setupTestEnv();
final int CLIENT_PORT = PortAssignment.unique();
MainThread main = new MainThread(CLIENT_PORT, true);
main.start();
Assert.assertTrue("waiting for server being up",
ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT,
CONNECTION_TIMEOUT));
ZooKeeper zk = new ZooKeeper("127.0.0.1:" + CLIENT_PORT,
ClientBase.CONNECTION_TIMEOUT, this);
zk.create("/foo1", "foobar".getBytes(), Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
Assert.assertEquals(new String(zk.getData("/foo1", null, null)), "foobar");
// inject problem in server
ZooKeeperServer zooKeeperServer = main.getCnxnFactory()
.getZooKeeperServer();
FileTxnSnapLog snapLog = zooKeeperServer.getTxnLogFactory();
FileTxnSnapLog fileTxnSnapLogWithError = new FileTxnSnapLog(
snapLog.getDataDir(), snapLog.getSnapDir()) {
@Override
public void commit() throws IOException {
throw new IOException("Input/output error");
}
};
ZKDatabase newDB = new ZKDatabase(fileTxnSnapLogWithError);
zooKeeperServer.setZKDatabase(newDB);
try {
// do create operation, so that injected IOException is thrown
zk.create("/foo2", "foobar".getBytes(), Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
fail("IOException is expected as error is injected in transaction log commit funtionality");
} catch (Exception e) {
// do nothing
}
zk.close();
Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT,
ClientBase.CONNECTION_TIMEOUT));
fileTxnSnapLogWithError.close();
main.shutdown();
main.deleteDirs();
}