public virtual void Teardown()
 {
     if (zkServer != null)
     {
         zkServer.Stop();
         zkServer.Close();
     }
 }
예제 #2
0
        public virtual void TestMultipleKMSInstancesWithZKSigner()
        {
            FilePath      testDir  = TestKMS.GetTestDir();
            Configuration conf     = CreateBaseKMSConf(testDir);
            TestingServer zkServer = new TestingServer();

            zkServer.Start();
            MiniKMS kms1 = null;
            MiniKMS kms2 = null;

            conf.Set(KMSAuthenticationFilter.ConfigPrefix + AuthenticationFilter.SignerSecretProvider
                     , "zookeeper");
            conf.Set(KMSAuthenticationFilter.ConfigPrefix + ZKSignerSecretProvider.ZookeeperConnectionString
                     , zkServer.GetConnectString());
            conf.Set(KMSAuthenticationFilter.ConfigPrefix + ZKSignerSecretProvider.ZookeeperPath
                     , "/secret");
            TestKMS.WriteConf(testDir, conf);
            try
            {
                kms1 = new MiniKMS.Builder().SetKmsConfDir(testDir).SetLog4jConfFile("log4j.properties"
                                                                                     ).Build();
                kms1.Start();
                kms2 = new MiniKMS.Builder().SetKmsConfDir(testDir).SetLog4jConfFile("log4j.properties"
                                                                                     ).Build();
                kms2.Start();
                Uri url1 = new Uri(kms1.GetKMSUrl().ToExternalForm() + KMSRESTConstants.ServiceVersion
                                   + "/" + KMSRESTConstants.KeysNamesResource);
                Uri url2 = new Uri(kms2.GetKMSUrl().ToExternalForm() + KMSRESTConstants.ServiceVersion
                                   + "/" + KMSRESTConstants.KeysNamesResource);
                DelegationTokenAuthenticatedURL.Token token = new DelegationTokenAuthenticatedURL.Token
                                                                  ();
                DelegationTokenAuthenticatedURL aUrl   = new DelegationTokenAuthenticatedURL();
                UserGroupInformation            ugiFoo = UserGroupInformation.CreateUserForTesting("foo", new
                                                                                                   string[] { "gfoo" });
                UserGroupInformation ugiBar = UserGroupInformation.CreateUserForTesting("bar", new
                                                                                        string[] { "gBar" });
                ugiFoo.DoAs(new _PrivilegedExceptionAction_135(aUrl, url1, token));
                ugiBar.DoAs(new _PrivilegedExceptionAction_145(aUrl, url2, token));
                ugiBar.DoAs(new _PrivilegedExceptionAction_155(aUrl, url2));
            }
            finally
            {
                if (kms2 != null)
                {
                    kms2.Stop();
                }
                if (kms1 != null)
                {
                    kms1.Stop();
                }
                zkServer.Stop();
            }
        }