本文整理汇总了Java中org.apache.zookeeper.test.ClientBase.CountdownWatcher类的典型用法代码示例。如果您正苦于以下问题:Java CountdownWatcher类的具体用法?Java CountdownWatcher怎么用?Java CountdownWatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CountdownWatcher类属于org.apache.zookeeper.test.ClientBase包,在下文中一共展示了CountdownWatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
LOG.info("STARTING " + getName());
// set the snap count to something low so that we force log rollover
// and verify that is working as part of the epoch rollover.
SyncRequestProcessor.setSnapCount(7);
qu = new QuorumUtil(1);
startAll();
for (int i = 0; i < zkClients.length; i++) {
zkClientWatchers[i] = new CountdownWatcher();
PeerStruct peer = qu.getPeer(i + 1);
zkClients[i] = new ZooKeeper(
"127.0.0.1:" + peer.clientPort,
ClientTest.CONNECTION_TIMEOUT, zkClientWatchers[i]);
}
waitForClientsConnected();
}
示例2: testSessionEstablishment
import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入依赖的package包/类
/**
* Tests a situation when client firstly connects to a read-only server and
* then connects to a majority server. Transition should be transparent for
* the user.
*/
@Test(timeout = 90000)
public void testSessionEstablishment() throws Exception {
qu.shutdown(2);
CountdownWatcher watcher = new CountdownWatcher();
ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT,
watcher, true);
watcher.waitForConnected(CONNECTION_TIMEOUT);
Assert.assertSame("should be in r/o mode", States.CONNECTEDREADONLY, zk
.getState());
long fakeId = zk.getSessionId();
watcher.reset();
qu.start(2);
Assert.assertTrue("waiting for server up", ClientBase.waitForServerUp(
"127.0.0.1:" + qu.getPeer(2).clientPort, CONNECTION_TIMEOUT));
watcher.waitForConnected(CONNECTION_TIMEOUT);
zk.create("/test", "test".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
Assert.assertFalse("fake session and real session have same id", zk
.getSessionId() == fakeId);
zk.close();
}
示例3: setUp
import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
System.setProperty("zookeeper.admin.enableServer", "false");
// set the snap count to something low so that we force log rollover
// and verify that is working as part of the epoch rollover.
SyncRequestProcessor.setSnapCount(7);
qu = new QuorumUtil(1);
startAll();
for (int i = 0; i < zkClients.length; i++) {
zkClientWatchers[i] = new CountdownWatcher();
PeerStruct peer = qu.getPeer(i + 1);
zkClients[i] = new ZooKeeper(
"127.0.0.1:" + peer.clientPort,
ClientTest.CONNECTION_TIMEOUT, zkClientWatchers[i]);
}
waitForClientsConnected();
}
示例4: testAuthLearnerServer
import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入依赖的package包/类
/**
* 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();
}
示例5: testValidCredentials
import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入依赖的package包/类
/**
* 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);
}
}
示例6: testSaslNotRequiredWithInvalidCredentials
import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入依赖的package包/类
/**
* 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);
}
}
示例7: testObserverWithValidCredentials
import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入依赖的package包/类
/**
* Test to verify that Observer server is able to join quorum.
*/
@Test(timeout = 30000)
public void testObserverWithValidCredentials() 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");
// Starting auth enabled 5-node cluster. 3-Participants and 2-Observers.
int totalServerCount = 5;
int observerCount = 2;
String connectStr = startQuorum(totalServerCount, observerCount,
authConfigs, totalServerCount);
CountdownWatcher watcher = new CountdownWatcher();
zk = new ZooKeeper(connectStr.toString(), ClientBase.CONNECTION_TIMEOUT,
watcher);
watcher.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
zk.create("/myTestRoot", new byte[0], Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
}
示例8: testValidCredentials
import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入依赖的package包/类
/**
* Test to verify that server is able to start with valid credentials
*/
@Test(timeout = 120000)
public void testValidCredentials() 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 = 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();
}
示例9: testValidCredentials
import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入依赖的package包/类
/**
* 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();
}
示例10: testSessionEstablishment
import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入依赖的package包/类
/**
* Tests a situation when client firstly connects to a read-only server and
* then connects to a majority server. Transition should be transparent for
* the user.
*/
@Test
public void testSessionEstablishment() throws Exception {
qu.shutdown(2);
CountdownWatcher watcher = new CountdownWatcher();
ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT,
watcher, true);
watcher.waitForConnected(CONNECTION_TIMEOUT);
Assert.assertSame("should be in r/o mode", States.CONNECTEDREADONLY, zk
.getState());
long fakeId = zk.getSessionId();
watcher.reset();
qu.start(2);
Assert.assertTrue("waiting for server up", ClientBase.waitForServerUp(
"127.0.0.1:" + qu.getPeer(2).clientPort, CONNECTION_TIMEOUT));
watcher.waitForConnected(CONNECTION_TIMEOUT);
zk.create("/test", "test".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
Assert.assertFalse("fake session and real session have same id", zk
.getSessionId() == fakeId);
zk.close();
}
示例11: setUp
import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
LOG.info("STARTING " + getName());
// set the snap count to something low so that we force log rollover
// and verify that is working as part of the epoch rollover.
SyncRequestProcessor.setSnapCount(7);
qu = new QuorumUtil(1);
startAll();
for (int i = 0; i < zkClients.length; i++) {
zkClientWatchers[i] = new CountdownWatcher();
int followerPort = qu.getPeer(i+1).peer.getClientPort();
zkClients[i] = new ZooKeeper(
"127.0.0.1:" + followerPort,
ClientTest.CONNECTION_TIMEOUT, zkClientWatchers[i]);
}
waitForClients();
}
示例12: createClient
import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入依赖的package包/类
private static DisconnectableZooKeeper createClient(int port,
CountdownWatcher watcher)
throws IOException, TimeoutException, InterruptedException
{
DisconnectableZooKeeper zk = new DisconnectableZooKeeper(
"127.0.0.1:" + port, ClientBase.CONNECTION_TIMEOUT, watcher);
watcher.waitForConnected(CONNECTION_TIMEOUT);
return zk;
}
示例13: createTestableClient
import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入依赖的package包/类
private static TestableZooKeeper createTestableClient(
CountdownWatcher watcher, String hp)
throws IOException, TimeoutException, InterruptedException
{
TestableZooKeeper zk = new TestableZooKeeper(
hp, ClientBase.CONNECTION_TIMEOUT, watcher);
watcher.waitForConnected(CONNECTION_TIMEOUT);
return zk;
}
示例14: testMultiTransaction
import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入依赖的package包/类
/**
* Test write operations using multi request.
*/
@Test(timeout = 90000)
public void testMultiTransaction() throws Exception {
CountdownWatcher watcher = new CountdownWatcher();
ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT,
watcher, true);
watcher.waitForConnected(CONNECTION_TIMEOUT); // ensure zk got connected
final String data = "Data to be read in RO mode";
final String node1 = "/tnode1";
final String node2 = "/tnode2";
zk.create(node1, data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
watcher.reset();
qu.shutdown(2);
watcher.waitForConnected(CONNECTION_TIMEOUT);
Assert.assertEquals("Should be in r-o mode", States.CONNECTEDREADONLY,
zk.getState());
// read operation during r/o mode
String remoteData = new String(zk.getData(node1, false, null));
Assert.assertEquals("Failed to read data in r-o mode", data, remoteData);
try {
Transaction transaction = zk.transaction();
transaction.setData(node1, "no way".getBytes(), -1);
transaction.create(node2, data.getBytes(),
ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
transaction.commit();
Assert.fail("Write operation using multi-transaction"
+ " api has succeeded during RO mode");
} catch (NotReadOnlyException e) {
// ok
}
Assert.assertNull("Should have created the znode:" + node2,
zk.exists(node2, false));
}
示例15: testReadOnlyClient
import org.apache.zookeeper.test.ClientBase.CountdownWatcher; //导入依赖的package包/类
/**
* Basic test of read-only client functionality. Tries to read and write
* during read-only mode, then regains a quorum and tries to write again.
*/
@Test(timeout = 90000)
public void testReadOnlyClient() throws Exception {
CountdownWatcher watcher = new CountdownWatcher();
ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT,
watcher, true);
watcher.waitForConnected(CONNECTION_TIMEOUT); // ensure zk got connected
final String data = "Data to be read in RO mode";
final String node = "/tnode";
zk.create(node, data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
watcher.reset();
qu.shutdown(2);
watcher.waitForConnected(CONNECTION_TIMEOUT);
// read operation during r/o mode
String remoteData = new String(zk.getData(node, false, null));
Assert.assertEquals(data, remoteData);
try {
zk.setData(node, "no way".getBytes(), -1);
Assert.fail("Write operation has succeeded during RO mode");
} catch (NotReadOnlyException e) {
// ok
}
watcher.reset();
qu.start(2);
Assert.assertTrue("waiting for server up", ClientBase.waitForServerUp(
"127.0.0.1:" + qu.getPeer(2).clientPort, CONNECTION_TIMEOUT));
watcher.waitForConnected(CONNECTION_TIMEOUT);
zk.setData(node, "We're in the quorum now".getBytes(), -1);
zk.close();
}