本文整理汇总了Java中org.apache.zookeeper.TestableZooKeeper类的典型用法代码示例。如果您正苦于以下问题:Java TestableZooKeeper类的具体用法?Java TestableZooKeeper怎么用?Java TestableZooKeeper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TestableZooKeeper类属于org.apache.zookeeper包,在下文中一共展示了TestableZooKeeper类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: testNonExistingOpCode
import org.apache.zookeeper.TestableZooKeeper; //导入依赖的package包/类
/**
* We create a perfectly valid 'exists' request, except that the opcode is wrong.
* @return
* @throws Exception
*/
@Test
public void testNonExistingOpCode() throws Exception {
TestableZooKeeper zk = createClient();
final String path = "/m1";
RequestHeader h = new RequestHeader();
h.setType(888); // This code does not exists
ExistsRequest request = new ExistsRequest();
request.setPath(path);
request.setWatch(false);
ExistsResponse response = new ExistsResponse();
ReplyHeader r = zk.submitRequest(h, request, response, null);
Assert.assertEquals(r.getErr(), Code.UNIMPLEMENTED.intValue());
try {
zk.exists("/m1", false);
fail("The connection should have been closed");
} catch (KeeperException.ConnectionLossException expected) {
}
}
示例4: 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();
}
示例5: 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;
}
示例6: 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();
}
}
示例7: 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();
qu.shutdownAll();
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:25,代码来源:FollowerResyncConcurrencyTest.java
示例8: testFourLetterWordsAllDisabledByDefault
import org.apache.zookeeper.TestableZooKeeper; //导入依赖的package包/类
@Test(timeout=30000)
public void testFourLetterWordsAllDisabledByDefault() throws Exception {
stopServer();
FourLetterCommands.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();
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:24,代码来源:FourLetterWordsWhiteListTest.java
示例9: 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();
}
示例10: testNonExistingOpCode
import org.apache.zookeeper.TestableZooKeeper; //导入依赖的package包/类
/**
* We create a perfectly valid 'exists' request, except that the opcode is wrong.
* @return
* @throws Exception
*/
@Test
public void testNonExistingOpCode() throws Exception {
TestableZooKeeper zk = createClient();
final String path = "/m1";
RequestHeader h = new RequestHeader();
h.setType(888); // This code does not exists
ExistsRequest request = new ExistsRequest();
request.setPath(path);
request.setWatch(false);
ExistsResponse response = new ExistsResponse();
ReplyHeader r = zk.submitRequest(h, request, response, null);
Assert.assertEquals(r.getErr(), Code.UNIMPLEMENTED.intValue());
zk.testableWaitForShutdown(CONNECTION_TIMEOUT);
}
示例11: 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();
qu.shutdownAll();
}
示例12: 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);
}
}
示例13: createTestableClient
import org.apache.zookeeper.TestableZooKeeper; //导入依赖的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: 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();
}