|
27 | 27 | import org.apache.curator.framework.CuratorFramework; |
28 | 28 | import org.apache.curator.framework.CuratorFrameworkFactory; |
29 | 29 | import org.apache.curator.framework.api.ACLProvider; |
| 30 | +import org.apache.curator.framework.api.CreateBuilder; |
| 31 | +import org.apache.curator.framework.api.ProtectACLCreateModeStatPathAndBytesable; |
30 | 32 | import org.apache.curator.retry.ExponentialBackoffRetry; |
31 | 33 | import org.apache.curator.test.TestingServer; |
32 | 34 | import org.apache.hadoop.conf.Configuration; |
|
37 | 39 | import org.apache.hadoop.security.token.delegation.web.DelegationTokenIdentifier; |
38 | 40 | import org.apache.hadoop.security.token.delegation.web.DelegationTokenManager; |
39 | 41 | import org.apache.hadoop.test.GenericTestUtils; |
| 42 | +import org.apache.hadoop.test.LambdaTestUtils; |
| 43 | +import org.apache.zookeeper.KeeperException; |
40 | 44 | import org.apache.zookeeper.ZooDefs; |
41 | 45 | import org.apache.zookeeper.data.ACL; |
42 | 46 | import org.apache.zookeeper.data.Id; |
@@ -534,5 +538,38 @@ public void testCreatingParentContainersIfNeeded() throws Exception { |
534 | 538 | // Check if the created NameSpace exists. |
535 | 539 | Stat stat = curatorFramework.checkExists().forPath(workingPath); |
536 | 540 | Assert.assertNotNull(stat); |
| 541 | + |
| 542 | + tm1.destroy(); |
| 543 | + curatorFramework.close(); |
| 544 | + } |
| 545 | + |
| 546 | + @Test |
| 547 | + public void testCreateNameSpaceRepeatedly() throws Exception { |
| 548 | + |
| 549 | + String connectString = zkServer.getConnectString(); |
| 550 | + RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); |
| 551 | + Configuration conf = getSecretConf(connectString); |
| 552 | + CuratorFramework curatorFramework = |
| 553 | + CuratorFrameworkFactory.builder(). |
| 554 | + connectString(connectString). |
| 555 | + retryPolicy(retryPolicy). |
| 556 | + build(); |
| 557 | + curatorFramework.start(); |
| 558 | + |
| 559 | + String workingPath = "/" + conf.get(ZKDelegationTokenSecretManager.ZK_DTSM_ZNODE_WORKING_PATH, |
| 560 | + ZKDelegationTokenSecretManager.ZK_DTSM_ZNODE_WORKING_PATH_DEAFULT) + "/ZKDTSMRoot-Test"; |
| 561 | + CreateBuilder createBuilder = curatorFramework.create(); |
| 562 | + ProtectACLCreateModeStatPathAndBytesable<String> createModeStat = |
| 563 | + createBuilder.creatingParentContainersIfNeeded(); |
| 564 | + createModeStat.forPath(workingPath); |
| 565 | + |
| 566 | + // Check if the created NameSpace exists. |
| 567 | + Stat stat = curatorFramework.checkExists().forPath(workingPath); |
| 568 | + Assert.assertNotNull(stat); |
| 569 | + |
| 570 | + // Repeated creation will throw NodeExists exception |
| 571 | + LambdaTestUtils.intercept(KeeperException.class, |
| 572 | + "KeeperErrorCode = NodeExists for "+workingPath, |
| 573 | + () -> createModeStat.forPath(workingPath)); |
537 | 574 | } |
538 | 575 | } |
0 commit comments