use of org.junit.jupiter.api.Timeout in project zookeeper by apache.
the class ReadOnlyModeTest method testSeekForRwServer.
/**
* Ensures that client seeks for r/w servers while it's connected to r/o
* server.
*/
@SuppressWarnings("deprecation")
@Test
@Timeout(value = 90)
public void testSeekForRwServer() throws Exception {
qu.enableLocalSession(true);
qu.startQuorum();
try (LoggerTestTool loggerTestTool = new LoggerTestTool("org.apache.zookeeper")) {
ByteArrayOutputStream os = loggerTestTool.getOutputStream();
qu.shutdown(2);
CountdownWatcher watcher = new CountdownWatcher();
ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT, watcher, true);
watcher.waitForConnected(CONNECTION_TIMEOUT);
// if we don't suspend a peer it will rejoin a quorum
qu.getPeer(1).peer.suspend();
// start two servers to form a quorum; client should detect this and
// connect to one of them
watcher.reset();
qu.start(2);
qu.start(3);
ClientBase.waitForServerUp(qu.getConnString(), 2000);
watcher.waitForConnected(CONNECTION_TIMEOUT);
zk.create("/test", "test".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
// resume poor fellow
qu.getPeer(1).peer.resume();
String log = os.toString();
assertFalse(StringUtils.isEmpty(log), "OutputStream doesn't have any log messages");
LineNumberReader r = new LineNumberReader(new StringReader(log));
String line;
Pattern p = Pattern.compile(".*Majority server found.*");
boolean found = false;
while ((line = r.readLine()) != null) {
if (p.matcher(line).matches()) {
found = true;
break;
}
}
assertTrue(found, "Majority server wasn't found while connected to r/o server");
}
}
use of org.junit.jupiter.api.Timeout in project zookeeper by apache.
the class ReconfigExceptionTest method testReconfigEnabledWithAuthAndWrongACL.
@Test
@Timeout(value = 10)
public void testReconfigEnabledWithAuthAndWrongACL() throws InterruptedException {
resetZKAdmin();
try {
zkAdmin.addAuthInfo("digest", "super:test".getBytes());
// There is ACL however the permission is wrong - need WRITE permission at leaste.
ArrayList<ACL> acls = new ArrayList<ACL>(Collections.singletonList(new ACL(ZooDefs.Perms.READ, new Id("digest", "user:tl+z3z0vO6PfPfEENfLF96E6pM0="))));
zkAdmin.setACL(ZooDefs.CONFIG_NODE, acls, -1);
resetZKAdmin();
zkAdmin.addAuthInfo("digest", "user:test".getBytes());
reconfigPort();
fail("Reconfig should fail with an ACL that is read only!");
} catch (KeeperException e) {
assertTrue(e.code() == KeeperException.Code.NOAUTH);
}
}
use of org.junit.jupiter.api.Timeout in project zookeeper by apache.
the class RemoveWatchesTest method testRemoveAllChildWatchesOnAPath.
/**
* Test verifies WatcherType.Children - removes only the configured child
* watcher function
*/
@ParameterizedTest
@ValueSource(booleans = { true, false })
@Timeout(value = 90)
public void testRemoveAllChildWatchesOnAPath(boolean useAsync) throws Exception {
zk1.create("/node1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
final CountDownLatch cWatchCount = new CountDownLatch(2);
final CountDownLatch rmWatchCount = new CountDownLatch(2);
Watcher w1 = event -> {
switch(event.getType()) {
case ChildWatchRemoved:
rmWatchCount.countDown();
break;
case NodeChildrenChanged:
cWatchCount.countDown();
break;
default:
break;
}
};
Watcher w2 = event -> {
switch(event.getType()) {
case ChildWatchRemoved:
rmWatchCount.countDown();
break;
case NodeChildrenChanged:
cWatchCount.countDown();
break;
default:
break;
}
};
// Add multiple child watches
LOG.info("Adding child watcher {} on path {}", w1, "/node1");
assertEquals(0, zk2.getChildren("/node1", w1).size(), "Didn't set child watches");
LOG.info("Adding child watcher {} on path {}", w2, "/node1");
assertEquals(0, zk2.getChildren("/node1", w2).size(), "Didn't set child watches");
assertTrue(isServerSessionWatcher(zk2.getSessionId(), "/node1", WatcherType.Children), "Server session is not a watcher");
removeAllWatches(zk2, "/node1", WatcherType.Children, false, Code.OK, useAsync);
assertTrue(rmWatchCount.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS), "Didn't remove child watcher");
assertFalse(isServerSessionWatcher(zk2.getSessionId(), "/node1", WatcherType.Children), "Server session is still a watcher after removal");
}
use of org.junit.jupiter.api.Timeout in project zookeeper by apache.
the class X509UtilTest method testCreateSSLContextWithCustomProtocol.
@ParameterizedTest
@MethodSource("data")
@Timeout(value = 5)
public void testCreateSSLContextWithCustomProtocol(X509KeyType caKeyType, X509KeyType certKeyType, String keyPassword, Integer paramIndex) throws Exception {
final String protocol = "TLSv1.1";
init(caKeyType, certKeyType, keyPassword, paramIndex);
System.setProperty(x509Util.getSslProtocolProperty(), protocol);
SSLContext sslContext = x509Util.getDefaultSSLContext();
assertEquals(protocol, sslContext.getProtocol());
}
use of org.junit.jupiter.api.Timeout in project zookeeper by apache.
the class X509UtilTest method testCreateSSLServerSocketWithoutPort.
@ParameterizedTest
@MethodSource("data")
@Timeout(value = 5)
public void testCreateSSLServerSocketWithoutPort(X509KeyType caKeyType, X509KeyType certKeyType, String keyPassword, Integer paramIndex) throws Exception {
init(caKeyType, certKeyType, keyPassword, paramIndex);
setCustomCipherSuites();
SSLServerSocket sslServerSocket = x509Util.createSSLServerSocket();
assertArrayEquals(customCipherSuites, sslServerSocket.getEnabledCipherSuites());
assertTrue(sslServerSocket.getNeedClientAuth());
}
Aggregations