You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sentry.apache.org by sr...@apache.org on 2016/07/12 20:06:16 UTC

[3/4] sentry git commit: SENTRY-1317: Implement fencing required for active/standby (Colin P. McCabe , Reviewed by: Hao Hao and Sravya Tirukkovalur)

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<String> ids = new HashSet<String>();
+    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)));
+      }
+    }
+  }
 }