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; }
@Test public void testRejection() throws Exception { String testDataPath = System.getProperty("test.data.dir", "src/test/resources/data"); // Replace trusted keys with a valid key that is not trusted by the server System.setProperty(clientX509Util.getSslKeystoreLocationProperty(), testDataPath + "/ssl/testUntrustedKeyStore.jks"); System.setProperty(clientX509Util.getSslKeystorePasswdProperty(), "testpass"); CountdownWatcher watcher = new CountdownWatcher(); // Handshake will take place, and then X509AuthenticationProvider should reject the untrusted cert new TestableZooKeeper(hostPort, CONNECTION_TIMEOUT, watcher); Assert.assertFalse("Untrusted certificate should not result in successful connection", watcher.clientConnected.await(1000, TimeUnit.MILLISECONDS)); }
@Test public void testMisconfiguration() throws Exception { System.clearProperty(clientX509Util.getSslAuthProviderProperty()); System.clearProperty(clientX509Util.getSslKeystoreLocationProperty()); System.clearProperty(clientX509Util.getSslKeystorePasswdProperty()); System.clearProperty(clientX509Util.getSslTruststoreLocationProperty()); System.clearProperty(clientX509Util.getSslTruststorePasswdProperty()); CountdownWatcher watcher = new CountdownWatcher(); new TestableZooKeeper(hostPort, CONNECTION_TIMEOUT, watcher); Assert.assertFalse("Missing SSL configuration should not result in successful connection", watcher.clientConnected.await(1000, TimeUnit.MILLISECONDS)); } }
public void run() { try { CountdownWatcher watcher = new CountdownWatcher(); zk = new TestableZooKeeper(qb.hostPort, CONNECTION_TIMEOUT, watcher); watcher.waitForConnected(CONNECTION_TIMEOUT);
@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(); } } }
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; }
TestableZooKeeper zk = new TestableZooKeeper(hostPort, CONNECTION_TIMEOUT, watcher);
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; }
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; }