|
@@ -41,6 +41,7 @@ import org.apache.hadoop.test.GenericTestUtils;
|
|
|
import org.apache.zookeeper.ZooDefs;
|
|
|
import org.apache.zookeeper.data.ACL;
|
|
|
import org.apache.zookeeper.data.Id;
|
|
|
+import org.apache.zookeeper.data.Stat;
|
|
|
import org.apache.zookeeper.server.auth.DigestAuthenticationProvider;
|
|
|
import org.junit.After;
|
|
|
import org.junit.Assert;
|
|
@@ -507,4 +508,32 @@ public class TestZKDelegationTokenSecretManager {
|
|
|
}
|
|
|
}, 1000, 5000);
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testCreatingParentContainersIfNeeded() throws Exception {
|
|
|
+
|
|
|
+ String connectString = zkServer.getConnectString();
|
|
|
+ RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
|
|
|
+ Configuration conf = getSecretConf(connectString);
|
|
|
+ CuratorFramework curatorFramework =
|
|
|
+ CuratorFrameworkFactory.builder()
|
|
|
+ .connectString(connectString)
|
|
|
+ .retryPolicy(retryPolicy)
|
|
|
+ .build();
|
|
|
+ curatorFramework.start();
|
|
|
+ ZKDelegationTokenSecretManager.setCurator(curatorFramework);
|
|
|
+ DelegationTokenManager tm1 = new DelegationTokenManager(conf, new Text("foo"));
|
|
|
+
|
|
|
+ // When the init method is called,
|
|
|
+ // the ZKDelegationTokenSecretManager#startThread method will be called,
|
|
|
+ // and the creatingParentContainersIfNeeded will be called to create the nameSpace.
|
|
|
+ tm1.init();
|
|
|
+
|
|
|
+ String workingPath = "/" + conf.get(ZKDelegationTokenSecretManager.ZK_DTSM_ZNODE_WORKING_PATH,
|
|
|
+ ZKDelegationTokenSecretManager.ZK_DTSM_ZNODE_WORKING_PATH_DEAFULT) + "/ZKDTSMRoot";
|
|
|
+
|
|
|
+ // Check if the created NameSpace exists.
|
|
|
+ Stat stat = curatorFramework.checkExists().forPath(workingPath);
|
|
|
+ Assert.assertNotNull(stat);
|
|
|
+ }
|
|
|
}
|