Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 92D09200B53 for ; Tue, 12 Jul 2016 22:06:16 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 913BD160A87; Tue, 12 Jul 2016 20:06:16 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B0AF8160A75 for ; Tue, 12 Jul 2016 22:06:15 +0200 (CEST) Received: (qmail 2585 invoked by uid 500); 12 Jul 2016 20:06:14 -0000 Mailing-List: contact commits-help@sentry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sentry.apache.org Delivered-To: mailing list commits@sentry.apache.org Received: (qmail 2502 invoked by uid 99); 12 Jul 2016 20:06:14 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Jul 2016 20:06:14 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B1C8EE2EF4; Tue, 12 Jul 2016 20:06:14 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sravya@apache.org To: commits@sentry.apache.org Date: Tue, 12 Jul 2016 20:06:16 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [3/4] sentry git commit: SENTRY-1317: Implement fencing required for active/standby (Colin P. McCabe , Reviewed by: Hao Hao and Sravya Tirukkovalur) archived-at: Tue, 12 Jul 2016 20:06:16 -0000 http://git-wip-us.apache.org/repos/asf/sentry/blob/ff7823b6/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStoreImportExport.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStoreImportExport.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStoreImportExport.java index 3ff97df..fc39658 100644 --- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStoreImportExport.java +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStoreImportExport.java @@ -28,6 +28,7 @@ import java.util.Set; import org.apache.commons.io.FileUtils; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.io.IOUtils; import org.apache.sentry.core.model.db.AccessConstants; import org.apache.sentry.provider.db.service.model.MSentryGroup; import org.apache.sentry.provider.db.service.model.MSentryPrivilege; @@ -37,6 +38,9 @@ import org.apache.sentry.provider.db.service.thrift.TSentryGrantOption; import org.apache.sentry.provider.db.service.thrift.TSentryMappingData; import org.apache.sentry.provider.db.service.thrift.TSentryPrivilege; import org.apache.sentry.provider.file.PolicyFile; +import org.apache.sentry.service.thrift.Activator; +import org.apache.sentry.service.thrift.Activators; +import org.apache.sentry.service.thrift.ServiceConstants; import org.apache.sentry.service.thrift.ServiceConstants.PrivilegeScope; import org.apache.sentry.service.thrift.ServiceConstants.ServerConfig; import org.junit.After; @@ -52,10 +56,11 @@ import com.google.common.io.Files; public class TestSentryStoreImportExport { private static File dataDir; - private static SentryStore sentryStore; private static String[] adminGroups = { "adminGroup1" }; private static PolicyFile policyFile; private static File policyFilePath; + private static Activator act; + private static SentryStore sentryStore; private TSentryPrivilege tSentryPrivilege1; private TSentryPrivilege tSentryPrivilege2; private TSentryPrivilege tSentryPrivilege3; @@ -79,6 +84,10 @@ public class TestSentryStoreImportExport { policyFilePath = new File(dataDir, "local_policy_file.ini"); conf.set(ServerConfig.SENTRY_STORE_GROUP_MAPPING_RESOURCE, policyFilePath.getPath()); policyFile = new PolicyFile(); + act = new Activator(conf); + conf.set(ServiceConstants.CURRENT_INCARNATION_ID_KEY, + act.getIncarnationId()); + Activators.INSTANCE.put(act); sentryStore = new SentryStore(conf); String adminUser = "g1"; @@ -129,12 +138,17 @@ public class TestSentryStoreImportExport { @AfterClass public static void teardown() { + IOUtils.cleanup(null, act); if (sentryStore != null) { sentryStore.stop(); } if (dataDir != null) { FileUtils.deleteQuietly(dataDir); } + if (act != null) { + Activators.INSTANCE.remove(act); + act = null; + } } protected static void addGroupsToUser(String user, String... groupNames) { http://git-wip-us.apache.org/repos/asf/sentry/blob/ff7823b6/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryVersion.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryVersion.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryVersion.java index a8e8a03..cf7ca8e 100644 --- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryVersion.java +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryVersion.java @@ -24,7 +24,11 @@ import java.io.File; import org.apache.hadoop.conf.Configuration; import org.apache.sentry.core.common.exception.SentryNoSuchObjectException; +import org.apache.sentry.service.thrift.Activator; +import org.apache.sentry.service.thrift.Activators; +import org.apache.sentry.service.thrift.ServiceConstants; import org.apache.sentry.service.thrift.ServiceConstants.ServerConfig; +import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -34,6 +38,7 @@ public class TestSentryVersion { private File dataDir; private Configuration conf; + private Activator act; @Before public void setup() throws Exception { @@ -42,6 +47,19 @@ public class TestSentryVersion { conf.set(ServerConfig.SENTRY_STORE_JDBC_URL, "jdbc:derby:;databaseName=" + dataDir.getPath() + ";create=true"); conf.set(ServerConfig.SENTRY_STORE_JDBC_PASS, "dummy"); + act = new Activator(conf); + conf.set(ServiceConstants.CURRENT_INCARNATION_ID_KEY, + act.getIncarnationId()); + Activators.INSTANCE.put(act); + } + + @After + public void shutdown() throws Exception { + if (act != null) { + act.close(); + Activators.INSTANCE.remove(act); + act = null; + } } /** http://git-wip-us.apache.org/repos/asf/sentry/blob/ff7823b6/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/service/thrift/SentryServiceIntegrationBase.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/service/thrift/SentryServiceIntegrationBase.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/service/thrift/SentryServiceIntegrationBase.java index cb2d9c9..4197e6d 100644 --- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/service/thrift/SentryServiceIntegrationBase.java +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/service/thrift/SentryServiceIntegrationBase.java @@ -31,7 +31,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.minikdc.MiniKdc; import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.security.UserGroupInformation; -import org.apache.sentry.provider.db.service.persistent.HAContext; import org.apache.sentry.provider.db.service.thrift.SentryMiniKdcTestcase; import org.apache.sentry.provider.db.service.thrift.SentryPolicyServiceClient; import org.apache.sentry.provider.db.service.thrift.TSentryRole; @@ -324,7 +323,7 @@ public abstract class SentryServiceIntegrationBase extends SentryMiniKdcTestcase JaasConfiguration.addEntryForKeytab("Server", ZK_SERVER_PRINCIPAL, ZKKeytabFile.getAbsolutePath()); // Here's where we add the "Client" to the jaas configuration, even though we'd like not to - JaasConfiguration.addEntryForKeytab(HAContext.SENTRY_ZK_JAAS_NAME, + JaasConfiguration.addEntryForKeytab(ServiceConstants.SENTRY_ZK_JAAS_NAME, SERVER_KERBEROS_NAME, serverKeytab.getAbsolutePath()); javax.security.auth.login.Configuration.setConfiguration(JaasConfiguration.getInstance()); http://git-wip-us.apache.org/repos/asf/sentry/blob/ff7823b6/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/service/thrift/TestLeaderStatus.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/service/thrift/TestLeaderStatus.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/service/thrift/TestLeaderStatus.java index 434ac41..6d408ff 100644 --- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/service/thrift/TestLeaderStatus.java +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/service/thrift/TestLeaderStatus.java @@ -26,6 +26,7 @@ import org.junit.Test; import java.io.Closeable; import java.io.IOException; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -216,4 +217,29 @@ final public class TestLeaderStatus { Assert.assertTrue(null == active.getError()); server.close(); } + + @Test(timeout = 60000) + public void testGenerateIncarnationIDs() throws Exception { + final int NUM_UNIQUE_IDS = 10000; + HashSet ids = new HashSet(); + for (int i = 0; i < NUM_UNIQUE_IDS; i++) { + ids.add(LeaderStatus.generateIncarnationId()); + } + + // Assert that there were no ID collisions + Assert.assertEquals(NUM_UNIQUE_IDS, ids.size()); + + // Assert that all IDs are 44 characters long and begin with a letter. + for (String id : ids) { + Assert.assertEquals(44, id.length()); + Assert.assertTrue(Character.isAlphabetic(id.charAt(0))); + } + + // Assert that IDs contain only alphanumeric characters + for (String id : ids) { + for (int i = 0; i < id.length(); i++) { + Assert.assertTrue(Character.isLetterOrDigit(id.charAt(i))); + } + } + } }