sentry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject sentry git commit: SENTRY-1299: Add a test case to verify SentryStore#verifySentryStoreSchema works(Colin Ma, reviewed by Dapeng Sun)
Date Thu, 02 Jun 2016 01:49:19 GMT
Repository: sentry
Updated Branches:
  refs/heads/master e67bde0da -> 24f7c2d95


SENTRY-1299: Add a test case to verify SentryStore#verifySentryStoreSchema works(Colin Ma,
reviewed by Dapeng Sun)


Project: http://git-wip-us.apache.org/repos/asf/sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/24f7c2d9
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/24f7c2d9
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/24f7c2d9

Branch: refs/heads/master
Commit: 24f7c2d95184ec4cea9196574342159319f96533
Parents: e67bde0
Author: Colin Ma <colin@apache.org>
Authored: Thu Jun 2 10:29:41 2016 +0800
Committer: Colin Ma <colin@apache.org>
Committed: Thu Jun 2 10:29:41 2016 +0800

----------------------------------------------------------------------
 .../db/service/persistent/SentryStore.java      |  2 +-
 .../db/service/persistent/TestSentryStore.java  | 22 ++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sentry/blob/24f7c2d9/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java
b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java
index 49459bd..b7ef0e9 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java
@@ -193,7 +193,7 @@ public class SentryStore {
   }
 
   // ensure that the backend DB schema is set
-  private void verifySentryStoreSchema(boolean checkVersion)
+  public void verifySentryStoreSchema(boolean checkVersion)
           throws SentryNoSuchObjectException, SentryAccessDeniedException {
     if (!checkVersion) {
       setSentryVersion(SentryStoreSchemaInfo.getSentryVersion(),

http://git-wip-us.apache.org/repos/asf/sentry/blob/24f7c2d9/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStore.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStore.java
b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStore.java
index 5d17538..bc7fe12 100644
--- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStore.java
+++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStore.java
@@ -30,6 +30,7 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.security.alias.CredentialProvider;
 import org.apache.hadoop.security.alias.CredentialProviderFactory;
 import org.apache.hadoop.security.alias.UserProvider;
+import org.apache.sentry.core.common.exception.SentryAccessDeniedException;
 import org.apache.sentry.core.model.db.AccessConstants;
 import org.apache.sentry.core.common.exception.SentryAlreadyExistsException;
 import org.apache.sentry.core.common.exception.SentryGrantDeniedException;
@@ -2057,6 +2058,27 @@ public class TestSentryStore extends org.junit.Assert {
 
   }
 
+  @Test
+  public void testSentryVersionCheck() throws Exception {
+    // don't verify version, the current version willll be set in MSentryVersion
+    sentryStore.verifySentryStoreSchema(false);
+    assertEquals(sentryStore.getSentryVersion(),
+        SentryStoreSchemaInfo.getSentryVersion());
+
+    // verify the version with the same value
+    sentryStore.verifySentryStoreSchema(true);
+
+    // verify the version with the different value
+    sentryStore.setSentryVersion("test-version", "test-version");
+    try {
+      sentryStore.verifySentryStoreSchema(true);
+      fail("SentryAccessDeniedException should be thrown.");
+    } catch (SentryAccessDeniedException e) {
+      // the excepted exception, recover the version
+      sentryStore.verifySentryStoreSchema(false);
+    }
+  }
+
   protected static void addGroupsToUser(String user, String... groupNames) {
     policyFile.addGroupsToUser(user, groupNames);
   }


Mime
View raw message