Repository: knox Updated Branches: refs/heads/master 9e412e536 -> 058d7463d
KNOX-1460 - Zookeeper tests should call close() instead of stop() Signed-off-by: Kevin Risden <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/knox/repo Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/058d7463 Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/058d7463 Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/058d7463 Branch: refs/heads/master Commit: 058d7463df9bbc5b6520e16f6e856c5580ca7a5c Parents: 9e412e5 Author: Kevin Risden <[email protected]> Authored: Wed Sep 26 15:15:07 2018 -0400 Committer: Kevin Risden <[email protected]> Committed: Wed Sep 26 15:15:10 2018 -0400 ---------------------------------------------------------------------- .../impl/AtlasZookeeperURLManagerTest.java | 4 +- .../impl/HBaseZookeeperURLManagerTest.java | 4 +- .../impl/HS2ZookeeperURLManagerTest.java | 4 +- .../impl/KafkaZookeeperURLManagerTest.java | 4 +- .../impl/SOLRZookeeperURLManagerTest.java | 4 +- ...eConfigurationRegistryClientServiceTest.java | 68 ++++++++------------ 6 files changed, 41 insertions(+), 47 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/knox/blob/058d7463/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/AtlasZookeeperURLManagerTest.java ---------------------------------------------------------------------- diff --git a/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/AtlasZookeeperURLManagerTest.java b/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/AtlasZookeeperURLManagerTest.java index 7b99c6a..8fd26b2 100644 --- a/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/AtlasZookeeperURLManagerTest.java +++ b/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/AtlasZookeeperURLManagerTest.java @@ -71,7 +71,9 @@ public class AtlasZookeeperURLManagerTest { @After public void teardown() throws IOException { - cluster.stop(); + if(cluster != null) { + cluster.close(); + } } @Test http://git-wip-us.apache.org/repos/asf/knox/blob/058d7463/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/HBaseZookeeperURLManagerTest.java ---------------------------------------------------------------------- diff --git a/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/HBaseZookeeperURLManagerTest.java b/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/HBaseZookeeperURLManagerTest.java index 57192b3..231dc3c 100644 --- a/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/HBaseZookeeperURLManagerTest.java +++ b/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/HBaseZookeeperURLManagerTest.java @@ -53,7 +53,9 @@ public class HBaseZookeeperURLManagerTest { @After public void teardown() throws IOException { - cluster.stop(); + if(cluster != null) { + cluster.close(); + } } @Test http://git-wip-us.apache.org/repos/asf/knox/blob/058d7463/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/HS2ZookeeperURLManagerTest.java ---------------------------------------------------------------------- diff --git a/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/HS2ZookeeperURLManagerTest.java b/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/HS2ZookeeperURLManagerTest.java index abf5af1..f880528 100644 --- a/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/HS2ZookeeperURLManagerTest.java +++ b/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/HS2ZookeeperURLManagerTest.java @@ -75,7 +75,9 @@ public class HS2ZookeeperURLManagerTest { @After public void teardown() throws IOException { - cluster.stop(); + if(cluster != null) { + cluster.close(); + } } @Test http://git-wip-us.apache.org/repos/asf/knox/blob/058d7463/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/KafkaZookeeperURLManagerTest.java ---------------------------------------------------------------------- diff --git a/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/KafkaZookeeperURLManagerTest.java b/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/KafkaZookeeperURLManagerTest.java index a5a389b..b14145f 100644 --- a/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/KafkaZookeeperURLManagerTest.java +++ b/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/KafkaZookeeperURLManagerTest.java @@ -56,7 +56,9 @@ public class KafkaZookeeperURLManagerTest { @After public void teardown() throws IOException { - cluster.stop(); + if(cluster != null) { + cluster.close(); + } } @Test http://git-wip-us.apache.org/repos/asf/knox/blob/058d7463/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/SOLRZookeeperURLManagerTest.java ---------------------------------------------------------------------- diff --git a/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/SOLRZookeeperURLManagerTest.java b/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/SOLRZookeeperURLManagerTest.java index fe2ad5c..257ae64 100644 --- a/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/SOLRZookeeperURLManagerTest.java +++ b/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/SOLRZookeeperURLManagerTest.java @@ -70,7 +70,9 @@ public class SOLRZookeeperURLManagerTest { @After public void teardown() throws IOException { - cluster.stop(); + if(cluster != null) { + cluster.close(); + } } @Test http://git-wip-us.apache.org/repos/asf/knox/blob/058d7463/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/zk/RemoteConfigurationRegistryClientServiceTest.java ---------------------------------------------------------------------- diff --git a/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/zk/RemoteConfigurationRegistryClientServiceTest.java b/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/zk/RemoteConfigurationRegistryClientServiceTest.java index 5828c1c..958d2dd 100644 --- a/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/zk/RemoteConfigurationRegistryClientServiceTest.java +++ b/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/zk/RemoteConfigurationRegistryClientServiceTest.java @@ -64,27 +64,23 @@ public class RemoteConfigurationRegistryClientServiceTest { final String CRED_ALIAS = null; // Configure and start a secure ZK cluster - TestingCluster zkCluster = setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD); - - try { + try (TestingCluster zkCluster = setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD)) { // Create the setup client for the test cluster, and initialize the test znodes CuratorFramework setupClient = initializeTestClientAndZNodes(zkCluster, PRINCIPAL); // Mock configuration GatewayConfig config = EasyMock.createNiceMock(GatewayConfig.class); final String registryConfigValue = - GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" + ZooKeeperClientService.TYPE + ";" + - GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" + zkCluster.getConnectString(); + GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" + ZooKeeperClientService.TYPE + ";" + + GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" + zkCluster.getConnectString(); EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME)) - .andReturn(registryConfigValue) - .anyTimes(); + .andReturn(registryConfigValue) + .anyTimes(); EasyMock.expect(config.getRemoteRegistryConfigurationNames()) - .andReturn(Collections.singletonList(REGISTRY_CLIENT_NAME)).anyTimes(); + .andReturn(Collections.singletonList(REGISTRY_CLIENT_NAME)).anyTimes(); EasyMock.replay(config); doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME, config, CRED_ALIAS, PWD); - } finally { - zkCluster.stop(); } } @@ -100,31 +96,29 @@ public class RemoteConfigurationRegistryClientServiceTest { final String CRED_ALIAS = null; // Configure and start a secure ZK cluster - TestingCluster zkCluster = setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD); - - try { + try (TestingCluster zkCluster = setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD)) { // Create the setup client for the test cluster, and initialize the test znodes CuratorFramework setupClient = initializeTestClientAndZNodes(zkCluster, PRINCIPAL); // Mock configuration GatewayConfig config = EasyMock.createNiceMock(GatewayConfig.class); final String registryConfigValue1 = - GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" + ZooKeeperClientService.TYPE + ";" + - GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" + zkCluster.getConnectString(); + GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" + ZooKeeperClientService.TYPE + ";" + + GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" + zkCluster.getConnectString(); EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME_1)) - .andReturn(registryConfigValue1).anyTimes(); + .andReturn(registryConfigValue1).anyTimes(); final String registryConfigValue2 = - GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" + ZooKeeperClientService.TYPE + ";" + - GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" + zkCluster.getConnectString(); + GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" + ZooKeeperClientService.TYPE + ";" + + GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" + zkCluster.getConnectString(); EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME_2)) - .andReturn(registryConfigValue2).anyTimes(); + .andReturn(registryConfigValue2).anyTimes(); EasyMock.expect(config.getRemoteRegistryConfigurationNames()) - .andReturn(Arrays.asList(REGISTRY_CLIENT_NAME_1, REGISTRY_CLIENT_NAME_2)).anyTimes(); + .andReturn(Arrays.asList(REGISTRY_CLIENT_NAME_1, REGISTRY_CLIENT_NAME_2)).anyTimes(); EasyMock.replay(config); // Create the client service instance RemoteConfigurationRegistryClientService clientService = - RemoteConfigurationRegistryClientServiceFactory.newInstance(config); + RemoteConfigurationRegistryClientServiceFactory.newInstance(config); assertEquals("Wrong registry client service type.", clientService.getClass(), CuratorClientService.class); clientService.setAliasService(null); clientService.init(config, null); @@ -138,8 +132,6 @@ public class RemoteConfigurationRegistryClientServiceTest { doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME_1, clientService, false); doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME_2, clientService, false); - } finally { - zkCluster.stop(); } } @@ -155,30 +147,26 @@ public class RemoteConfigurationRegistryClientServiceTest { final String CRED_ALIAS = "zkCredential"; // Configure and start a secure ZK cluster - TestingCluster zkCluster = setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD); - - try { + try (TestingCluster zkCluster = setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD)) { // Create the setup client for the test cluster, and initialize the test znodes CuratorFramework setupClient = initializeTestClientAndZNodes(zkCluster, PRINCIPAL); // Mock configuration GatewayConfig config = EasyMock.createNiceMock(GatewayConfig.class); final String registryConfigValue = - GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" + ZooKeeperClientService.TYPE + ";" + - GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" + zkCluster.getConnectString() + ";" + - GatewayConfig.REMOTE_CONFIG_REGISTRY_AUTH_TYPE + "=" + AUTH_TYPE + ";" + - GatewayConfig.REMOTE_CONFIG_REGISTRY_PRINCIPAL + "=" + PRINCIPAL + ";" + - GatewayConfig.REMOTE_CONFIG_REGISTRY_CREDENTIAL_ALIAS + "=" + CRED_ALIAS; + GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" + ZooKeeperClientService.TYPE + ";" + + GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" + zkCluster.getConnectString() + ";" + + GatewayConfig.REMOTE_CONFIG_REGISTRY_AUTH_TYPE + "=" + AUTH_TYPE + ";" + + GatewayConfig.REMOTE_CONFIG_REGISTRY_PRINCIPAL + "=" + PRINCIPAL + ";" + + GatewayConfig.REMOTE_CONFIG_REGISTRY_CREDENTIAL_ALIAS + "=" + CRED_ALIAS; EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME)) - .andReturn(registryConfigValue) - .anyTimes(); + .andReturn(registryConfigValue) + .anyTimes(); EasyMock.expect(config.getRemoteRegistryConfigurationNames()) - .andReturn(Collections.singletonList(REGISTRY_CLIENT_NAME)).anyTimes(); + .andReturn(Collections.singletonList(REGISTRY_CLIENT_NAME)).anyTimes(); EasyMock.replay(config); doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME, config, CRED_ALIAS, PWD); - } finally { - zkCluster.stop(); } } @@ -195,11 +183,8 @@ public class RemoteConfigurationRegistryClientServiceTest { final String CRED_ALIAS = "zkCredential"; // Configure and start a secure ZK cluster - TestingCluster zkCluster = setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD); - File tmpRegConfigFile = null; - - try { + try (TestingCluster zkCluster = setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD)) { // Create the setup client for the test cluster, and initialize the test znodes CuratorFramework setupClient = initializeTestClientAndZNodes(zkCluster, PRINCIPAL); @@ -213,7 +198,7 @@ public class RemoteConfigurationRegistryClientServiceTest { registryConfigProps.put("principal", PRINCIPAL); registryConfigProps.put("credentialAlias", CRED_ALIAS); String registryConfigXML = - RemoteRegistryConfigTestUtils.createRemoteConfigRegistriesXML(Collections.singleton(registryConfigProps)); + RemoteRegistryConfigTestUtils.createRemoteConfigRegistriesXML(Collections.singleton(registryConfigProps)); tmpRegConfigFile = File.createTempFile("myRemoteRegistryConfig", "xml"); FileUtils.writeStringToFile(tmpRegConfigFile, registryConfigXML); @@ -224,7 +209,6 @@ public class RemoteConfigurationRegistryClientServiceTest { doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME, config, CRED_ALIAS, PWD); } finally { - zkCluster.stop(); if (tmpRegConfigFile != null && tmpRegConfigFile.exists()) { tmpRegConfigFile.delete(); }
