本文整理汇总了Java中org.apache.zookeeper.TestableZooKeeper.close方法的典型用法代码示例。如果您正苦于以下问题:Java TestableZooKeeper.close方法的具体用法?Java TestableZooKeeper.close怎么用?Java TestableZooKeeper.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.zookeeper.TestableZooKeeper
的用法示例。
在下文中一共展示了TestableZooKeeper.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createClient
import org.apache.zookeeper.TestableZooKeeper; //导入方法依赖的package包/类
protected TestableZooKeeper createClient(CountdownWatcher watcher,
String hp, int timeout)
throws IOException, InterruptedException
{
watcher.reset();
TestableZooKeeper zk = new TestableZooKeeper(hp, timeout, watcher);
if (!watcher.clientConnected.await(timeout, TimeUnit.MILLISECONDS))
{
Assert.fail("Unable to connect to server");
}
synchronized(this) {
if (!allClientsSetup) {
LOG.error("allClients never setup");
Assert.fail("allClients never setup");
}
if (allClients != null) {
allClients.add(zk);
} else {
// test done - close the zk, not needed
zk.close();
}
}
watcher.initializeWatchedClient(zk);
return zk;
}
示例2: testTestability
import org.apache.zookeeper.TestableZooKeeper; //导入方法依赖的package包/类
/** Exercise the testable functions, verify tostring, etc... */
@Test
public void testTestability() throws Exception {
TestableZooKeeper zk = createClient();
try {
LOG.info("{}",zk.testableLocalSocketAddress());
LOG.info("{}",zk.testableRemoteSocketAddress());
LOG.info("{}",zk.toString());
} finally {
zk.close();
zk.testableWaitForShutdown(CONNECTION_TIMEOUT);
LOG.info("{}",zk.testableLocalSocketAddress());
LOG.info("{}",zk.testableRemoteSocketAddress());
LOG.info("{}",zk.toString());
}
}
示例3: createClient
import org.apache.zookeeper.TestableZooKeeper; //导入方法依赖的package包/类
protected TestableZooKeeper createClient(CountdownWatcher watcher,
String hp, int timeout)
throws IOException, InterruptedException
{
watcher.reset();
TestableZooKeeper zk = new TestableZooKeeper(hp, timeout, watcher);
if (!watcher.clientConnected.await(timeout, TimeUnit.MILLISECONDS))
{
Assert.fail("Unable to connect to server");
}
synchronized(this) {
if (!allClientsSetup) {
LOG.error("allClients never setup");
Assert.fail("allClients never setup");
}
if (allClients != null) {
allClients.add(zk);
JMXEnv.ensureAll(getHexSessionId(zk.getSessionId()));
} else {
// test done - close the zk, not needed
zk.close();
}
}
return zk;
}
示例4: testAuth
import org.apache.zookeeper.TestableZooKeeper; //导入方法依赖的package包/类
@Test
public void testAuth() throws Exception {
// Cannot use createClient here because server may close session before
// JMXEnv.ensureAll is called which will fail the test case
CountdownWatcher watcher = new CountdownWatcher();
TestableZooKeeper zk = new TestableZooKeeper(hostPort, CONNECTION_TIMEOUT, watcher);
if (!watcher.clientConnected.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS))
{
Assert.fail("Unable to connect to server");
}
try {
zk.create("/path1", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT);
Assert.fail("Should have gotten exception.");
} catch (KeeperException e) {
// ok, exception as expected.
LOG.info("Got exception as expected: " + e);
}
finally {
zk.close();
}
}
示例5: testFollowerSendsLastZxid
import org.apache.zookeeper.TestableZooKeeper; //导入方法依赖的package包/类
/**
* Verify that the server is sending the proper zxid. See ZOOKEEPER-1412.
*/
@Test
public void testFollowerSendsLastZxid() throws Exception {
QuorumUtil qu = new QuorumUtil(1);
qu.startAll();
int index = 1;
while(qu.getPeer(index).peer.follower == null) {
index++;
}
LOG.info("Connecting to follower:" + index);
TestableZooKeeper zk =
createTestableClient("localhost:" + qu.getPeer(index).peer.getClientPort());
assertEquals(0L, zk.testableLastZxid());
zk.exists("/", false);
long lzxid = zk.testableLastZxid();
assertTrue("lzxid:" + lzxid + " > 0", lzxid > 0);
zk.close();
}
示例6: testFourLetterWordsAllDisabledByDefault
import org.apache.zookeeper.TestableZooKeeper; //导入方法依赖的package包/类
@Test(timeout=30000)
public void testFourLetterWordsAllDisabledByDefault() throws Exception {
stopServer();
ServerCnxn.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();
}
示例7: run
import org.apache.zookeeper.TestableZooKeeper; //导入方法依赖的package包/类
public void run() {
try {
for (; current < count; current++) {
TestableZooKeeper zk = createClient();
zk.close();
// we've asked to close, wait for it to finish closing
// all the sub-threads otw the selector may not be
// closed when we check (false positive on test Assert.failure
zk.testableWaitForShutdown(CONNECTION_TIMEOUT);
}
} catch (Throwable t) {
LOG.error("test Assert.failed", t);
}
}
示例8: testFollowerWatcherResync
import org.apache.zookeeper.TestableZooKeeper; //导入方法依赖的package包/类
/**
* Verify that the server is sending the proper zxid, and as a result
* the watch doesn't fire. See ZOOKEEPER-1412.
*/
@Test
public void testFollowerWatcherResync() throws Exception {
QuorumUtil qu = new QuorumUtil(1);
qu.startAll();
int index = 1;
while(qu.getPeer(index).peer.follower == null) {
index++;
}
LOG.info("Connecting to follower:" + index);
TestableZooKeeper zk1 = createTestableClient(
"localhost:" + qu.getPeer(index).peer.getClientPort());
zk1.create("/foo", "foo".getBytes(), Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
MyWatcher watcher = new MyWatcher();
TestableZooKeeper zk2 = createTestableClient(watcher,
"localhost:" + qu.getPeer(index).peer.getClientPort());
zk2.exists("/foo", true);
watcher.reset();
zk2.testableConnloss();
if (!watcher.clientConnected.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS))
{
fail("Unable to connect to server");
}
assertArrayEquals("foo".getBytes(), zk2.getData("/foo", false, null));
assertNull(watcher.events.poll(5, TimeUnit.SECONDS));
zk1.close();
zk2.close();
}
示例9: run
import org.apache.zookeeper.TestableZooKeeper; //导入方法依赖的package包/类
public void run() {
try {
for (; current < count; current++) {
TestableZooKeeper zk = createClient();
// we've asked to close, wait for it to finish closing
// all the sub-threads otw the selector may not be
// closed when we check (false positive on test Assert.failure
zk.close(CONNECTION_TIMEOUT);
}
} catch (Throwable t) {
LOG.error("test Assert.failed", t);
}
}
示例10: testFollowerWatcherResync
import org.apache.zookeeper.TestableZooKeeper; //导入方法依赖的package包/类
/**
* Verify that the server is sending the proper zxid, and as a result
* the watch doesn't fire. See ZOOKEEPER-1412.
*/
@Test
public void testFollowerWatcherResync() throws Exception {
QuorumUtil qu = new QuorumUtil(1);
qu.startAll();
int index = 1;
while(qu.getPeer(index).peer.follower == null) {
index++;
}
LOG.info("Connecting to follower: {}", index);
TestableZooKeeper zk1 = createTestableClient(
"localhost:" + qu.getPeer(index).peer.getClientPort());
zk1.create("/foo", "foo".getBytes(), Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
MyWatcher watcher = new MyWatcher();
TestableZooKeeper zk2 = createTestableClient(watcher,
"localhost:" + qu.getPeer(index).peer.getClientPort());
zk2.exists("/foo", true);
watcher.reset();
zk2.testableConnloss();
if (!watcher.clientConnected.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS))
{
fail("Unable to connect to server");
}
assertArrayEquals("foo".getBytes(), zk2.getData("/foo", false, null));
assertNull(watcher.events.poll(5, TimeUnit.SECONDS));
zk1.close();
zk2.close();
qu.shutdownAll();
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:41,代码来源:FollowerResyncConcurrencyTest.java
示例11: testFourLetterWords
import org.apache.zookeeper.TestableZooKeeper; //导入方法依赖的package包/类
/** Test the various four letter words */
@Test
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");
TestableZooKeeper zk = createClient();
String sid = getHexSessionId(zk.getSessionId());
verify("stat", "queued");
verify("srvr", "Outstanding");
verify("cons", sid);
verify("dump", sid);
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);
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");
}
示例12: testWatchAutoResetWithPending
import org.apache.zookeeper.TestableZooKeeper; //导入方法依赖的package包/类
/**
* This test checks that watches for pending requests do not get triggered,
* but watches set by previous requests do.
*
* @throws Exception
*/
@Test
public void testWatchAutoResetWithPending() throws Exception {
MyWatcher watches[] = new MyWatcher[COUNT];
MyStatCallback cbs[] = new MyStatCallback[COUNT];
MyWatcher watcher = new MyWatcher();
int count[] = new int[1];
TestableZooKeeper zk = createClient(watcher, hostPort, 6000);
ZooKeeper zk2 = createClient(watcher, hostPort, 5000);
zk2.create("/test", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
for(int i = 0; i < COUNT/2; i++) {
watches[i] = new MyWatcher();
cbs[i] = new MyStatCallback();
zk.exists("/test", watches[i], cbs[i], count);
}
zk.exists("/test", false);
Assert.assertTrue("Failed to pause the connection!", zk.pauseCnxn(3000));
zk2.close();
stopServer();
watches[0].waitForDisconnected(60000);
for(int i = COUNT/2; i < COUNT; i++) {
watches[i] = new MyWatcher();
cbs[i] = new MyStatCallback();
zk.exists("/test", watches[i], cbs[i], count);
}
startServer();
watches[COUNT/2-1].waitForConnected(60000);
Assert.assertEquals(null, zk.exists("/test", false));
Thread.sleep(10);
for(int i = 0; i < COUNT/2; i++) {
Assert.assertEquals("For " + i, 1, watches[i].events.size());
}
for(int i = COUNT/2; i < COUNT; i++) {
if (cbs[i].rc == 0) {
Assert.assertEquals("For " +i, 1, watches[i].events.size());
} else {
Assert.assertEquals("For " +i, 0, watches[i].events.size());
}
}
Assert.assertEquals(COUNT, count[0]);
zk.close();
}
示例13: testWatchAutoResetWithPending
import org.apache.zookeeper.TestableZooKeeper; //导入方法依赖的package包/类
/**
* This test checks that watches for pending requests do not get triggered,
* but watches set by previous requests do.
*
* @throws Exception
*/
@Test
public void testWatchAutoResetWithPending() throws Exception {
MyWatcher watches[] = new MyWatcher[COUNT];
MyStatCallback cbs[] = new MyStatCallback[COUNT];
MyWatcher watcher = new MyWatcher();
int count[] = new int[1];
TestableZooKeeper zk = createClient(watcher, hostPort, 6000);
ZooKeeper zk2 = createClient(watcher, hostPort, 5000);
zk2.create("/test", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
for(int i = 0; i < COUNT/2; i++) {
watches[i] = new MyWatcher();
cbs[i] = new MyStatCallback();
zk.exists("/test", watches[i], cbs[i], count);
}
zk.exists("/test", false);
Assert.assertTrue("Failed to pause the connection!", zk.pauseCnxn(3000));
zk2.close();
stopServer();
watches[0].waitForDisconnected(60000);
for(int i = COUNT/2; i < COUNT; i++) {
watches[i] = new MyWatcher();
cbs[i] = new MyStatCallback();
zk.exists("/test", watches[i], cbs[i], count);
}
startServer();
watches[COUNT/2-1].waitForConnected(60000);
Assert.assertEquals(null, zk.exists("/test", false));
waitForAllWatchers();
for(int i = 0; i < COUNT/2; i++) {
Assert.assertEquals("For " + i, 1, watches[i].events.size());
}
for(int i = COUNT/2; i < COUNT; i++) {
if (cbs[i].rc == 0) {
Assert.assertEquals("For " +i, 1, watches[i].events.size());
} else {
Assert.assertEquals("For " +i, 0, watches[i].events.size());
}
}
Assert.assertEquals(COUNT, count[0]);
zk.close();
}
示例14: testFourLetterWords
import org.apache.zookeeper.TestableZooKeeper; //导入方法依赖的package包/类
/** Test the various four letter words */
@Test
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");
}
示例15: verifyAllCommandsSuccess
import org.apache.zookeeper.TestableZooKeeper; //导入方法依赖的package包/类
private void verifyAllCommandsSuccess() throws Exception {
verifyExactMatch("ruok", "imok");
verifyFuzzyMatch("envi", "java.version");
verifyFuzzyMatch("conf", "clientPort");
verifyFuzzyMatch("stat", "Outstanding");
verifyFuzzyMatch("srvr", "Outstanding");
verifyFuzzyMatch("cons", "queued");
verifyFuzzyMatch("dump", "Session");
verifyFuzzyMatch("wchs", "watches");
verifyFuzzyMatch("wchp", "");
verifyFuzzyMatch("wchc", "");
verifyFuzzyMatch("srst", "reset");
verifyFuzzyMatch("crst", "reset");
verifyFuzzyMatch("stat", "Outstanding");
verifyFuzzyMatch("srvr", "Outstanding");
verifyFuzzyMatch("cons", "queued");
verifyFuzzyMatch("gtmk", "306");
verifyFuzzyMatch("isro", "rw");
TestableZooKeeper zk = createClient();
String sid = getHexSessionId(zk.getSessionId());
verifyFuzzyMatch("stat", "queued");
verifyFuzzyMatch("srvr", "Outstanding");
verifyFuzzyMatch("cons", sid);
verifyFuzzyMatch("dump", sid);
verifyFuzzyMatch("dirs", "size");
zk.getData("/", true, null);
verifyFuzzyMatch("stat", "queued");
verifyFuzzyMatch("srvr", "Outstanding");
verifyFuzzyMatch("cons", sid);
verifyFuzzyMatch("dump", sid);
verifyFuzzyMatch("wchs", "watching 1");
verifyFuzzyMatch("wchp", sid);
verifyFuzzyMatch("wchc", sid);
verifyFuzzyMatch("dirs", "size");
zk.close();
verifyExactMatch("ruok", "imok");
verifyFuzzyMatch("envi", "java.version");
verifyFuzzyMatch("conf", "clientPort");
verifyFuzzyMatch("stat", "Outstanding");
verifyFuzzyMatch("srvr", "Outstanding");
verifyFuzzyMatch("cons", "queued");
verifyFuzzyMatch("dump", "Session");
verifyFuzzyMatch("wchs", "watch");
verifyFuzzyMatch("wchp", "");
verifyFuzzyMatch("wchc", "");
verifyFuzzyMatch("srst", "reset");
verifyFuzzyMatch("crst", "reset");
verifyFuzzyMatch("stat", "Outstanding");
verifyFuzzyMatch("srvr", "Outstanding");
verifyFuzzyMatch("cons", "queued");
verifyFuzzyMatch("mntr", "zk_server_state\tstandalone");
verifyFuzzyMatch("mntr", "num_alive_connections");
verifyFuzzyMatch("stat", "Connections");
verifyFuzzyMatch("srvr", "Connections");
verifyFuzzyMatch("dirs", "size");
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:67,代码来源:FourLetterWordsWhiteListTest.java