use of org.apache.zookeeper.common.ClientX509Util in project zookeeper by apache.
the class NettyServerCnxnTest method runEnableDisableThrottling.
private void runEnableDisableThrottling(boolean secure, boolean randomDisableEnable) throws Exception {
ClientX509Util x509Util = null;
if (secure) {
x509Util = SSLAuthTest.setUpSecure();
}
try {
NettyServerCnxnFactory factory = (NettyServerCnxnFactory) serverFactory;
factory.setAdvancedFlowControlEnabled(true);
if (secure) {
factory.setSecure(true);
}
final String path = "/testEnableDisableThrottling";
try (ZooKeeper zk = createClient()) {
zk.create(path, new byte[1], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
// meanwhile start another thread to enable and disable recv
AtomicBoolean stopped = new AtomicBoolean(false);
Random random = new Random();
Thread enableDisableThread = null;
if (randomDisableEnable) {
enableDisableThread = new Thread() {
@Override
public void run() {
while (!stopped.get()) {
for (final ServerCnxn cnxn : serverFactory.cnxns) {
boolean shouldDisableEnable = random.nextBoolean();
if (shouldDisableEnable) {
cnxn.disableRecv();
} else {
cnxn.enableRecv();
}
}
try {
Thread.sleep(10);
} catch (InterruptedException e) {
/* ignore */
}
}
// always enable the recv at end
for (final ServerCnxn cnxn : serverFactory.cnxns) {
cnxn.enableRecv();
}
}
};
} else {
enableDisableThread = new Thread() {
@Override
public void run() {
while (!stopped.get()) {
for (final ServerCnxn cnxn : serverFactory.cnxns) {
try {
cnxn.disableRecv();
Thread.sleep(10);
cnxn.enableRecv();
Thread.sleep(10);
} catch (InterruptedException e) {
/* ignore */
}
}
}
}
};
}
enableDisableThread.start();
LOG.info("started thread to enable and disable recv");
// start a thread to keep sending requests
int totalRequestsNum = 100000;
AtomicInteger successResponse = new AtomicInteger();
CountDownLatch responseReceivedLatch = new CountDownLatch(totalRequestsNum);
Thread clientThread = new Thread() {
@Override
public void run() {
int requestIssued = 0;
while (requestIssued++ < totalRequestsNum) {
zk.getData(path, null, new DataCallback() {
@Override
public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
if (rc == KeeperException.Code.OK.intValue()) {
successResponse.addAndGet(1);
} else {
LOG.info("failed response is {}", rc);
}
responseReceivedLatch.countDown();
}
}, null);
}
}
};
clientThread.start();
LOG.info("started thread to issue {} async requests", totalRequestsNum);
// and verify the response received is same as what we issued
assertTrue(responseReceivedLatch.await(60, TimeUnit.SECONDS));
LOG.info("received all {} responses", totalRequestsNum);
stopped.set(true);
enableDisableThread.join();
LOG.info("enable and disable recv thread exited");
// wait another second for the left requests to finish
LOG.info("waiting another 1s for the requests to go through");
Thread.sleep(1000);
assertEquals(successResponse.get(), totalRequestsNum);
}
} finally {
if (secure) {
SSLAuthTest.clearSecureSetting(x509Util);
}
}
}
use of org.apache.zookeeper.common.ClientX509Util in project zookeeper by apache.
the class SaslDigestAuthOverSSLTest method setUpSSLWithNoAuth.
public ClientX509Util setUpSSLWithNoAuth() {
String testDataPath = System.getProperty("test.data.dir", "src/test/resources/data");
System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, "org.apache.zookeeper.server.NettyServerCnxnFactory");
System.setProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET, "org.apache.zookeeper.ClientCnxnSocketNetty");
System.setProperty(ZKClientConfig.SECURE_CLIENT, "true");
System.setProperty("zookeeper.ssl.clientAuth", "none");
System.setProperty("zookeeper.ssl.quorum.clientAuth", "none");
ClientX509Util x509Util = new ClientX509Util();
System.setProperty(x509Util.getSslTruststoreLocationProperty(), testDataPath + "/ssl/testTrustStore.jks");
System.setProperty(x509Util.getSslTruststorePasswdProperty(), "testpass");
System.setProperty(x509Util.getSslKeystoreLocationProperty(), testDataPath + "/ssl/testKeyStore.jks");
System.setProperty(x509Util.getSslKeystorePasswdProperty(), "testpass");
return x509Util;
}
Aggregations