You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sentry.apache.org by co...@apache.org on 2015/02/26 07:28:27 UTC
incubator-sentry git commit: SENTRY-638: Improve test cases in
TestSentryStore (Reviewed by Dapeng Sun)
Repository: incubator-sentry
Updated Branches:
refs/heads/master 124b6f5ca -> 0f8e5e452
SENTRY-638: Improve test cases in TestSentryStore (Reviewed by Dapeng Sun)
Project: http://git-wip-us.apache.org/repos/asf/incubator-sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-sentry/commit/0f8e5e45
Tree: http://git-wip-us.apache.org/repos/asf/incubator-sentry/tree/0f8e5e45
Diff: http://git-wip-us.apache.org/repos/asf/incubator-sentry/diff/0f8e5e45
Branch: refs/heads/master
Commit: 0f8e5e452572c4f6afbcd6a26733d2d682f178a9
Parents: 124b6f5
Author: Colin Ma <co...@apache.org>
Authored: Thu Feb 26 14:05:28 2015 +0800
Committer: Colin Ma <co...@apache.org>
Committed: Thu Feb 26 14:05:28 2015 +0800
----------------------------------------------------------------------
.../db/service/persistent/SentryStore.java | 18 +++++++++++
.../db/service/persistent/TestSentryStore.java | 34 ++++++++++++--------
2 files changed, 39 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/0f8e5e45/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 136dab6..d7d3475 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
@@ -367,6 +367,24 @@ public class SentryStore {
return getCount(MSentryPrivilege.class);
}
+ @VisibleForTesting
+ void clearAllTables() {
+ boolean rollbackTransaction = true;
+ PersistenceManager pm = null;
+ try {
+ pm = openTransaction();
+ pm.newQuery(MSentryRole.class).deletePersistentAll();
+ pm.newQuery(MSentryGroup.class).deletePersistentAll();
+ pm.newQuery(MSentryPrivilege.class).deletePersistentAll();
+ commitUpdateTransaction(pm);
+ rollbackTransaction = false;
+ } finally {
+ if (rollbackTransaction) {
+ rollbackTransaction(pm);
+ }
+ }
+ }
+
public CommitContext alterSentryRoleGrantPrivilege(String grantorPrincipal,
String roleName, TSentryPrivilege privilege)
throws SentryUserException {
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/0f8e5e45/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 8fbe3f4..35319db 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
@@ -45,7 +45,9 @@ import org.apache.sentry.provider.db.service.thrift.TSentryPrivilege;
import org.apache.sentry.provider.file.PolicyFile;
import org.apache.sentry.service.thrift.ServiceConstants.ServerConfig;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
@@ -55,15 +57,15 @@ import com.google.common.io.Files;
public class TestSentryStore {
- private File dataDir;
- private SentryStore sentryStore;
- private String[] adminGroups = {"adminGroup1"};
- private PolicyFile policyFile;
- private File policyFilePath;
+ private static File dataDir;
+ private static SentryStore sentryStore;
+ private static String[] adminGroups = { "adminGroup1" };
+ private static PolicyFile policyFile;
+ private static File policyFilePath;
final long NUM_PRIVS = 60; // > SentryStore.PrivCleaner.NOTIFY_THRESHOLD
- @Before
- public void setup() throws Exception {
+ @BeforeClass
+ public static void setup() throws Exception {
dataDir = new File(Files.createTempDir(), "sentry_policy_db");
Configuration conf = new Configuration(false);
conf.set(ServerConfig.SENTRY_VERIFY_SCHEM_VERSION, "false");
@@ -75,16 +77,24 @@ public class TestSentryStore {
policyFilePath = new File(dataDir, "local_policy_file.ini");
conf.set(ServerConfig.SENTRY_STORE_GROUP_MAPPING_RESOURCE,
policyFilePath.getPath());
- policyFile = new PolicyFile();
sentryStore = new SentryStore(conf);
+ }
+ @Before
+ public void before() throws Exception {
+ policyFile = new PolicyFile();
String adminUser = "g1";
addGroupsToUser(adminUser, adminGroups);
writePolicyFile();
}
@After
- public void teardown() {
+ public void after() {
+ sentryStore.clearAllTables();
+ }
+
+ @AfterClass
+ public static void teardown() {
if (sentryStore != null) {
sentryStore.stop();
}
@@ -150,7 +160,6 @@ public class TestSentryStore {
@Test
public void testCreateDuplicateRole() throws Exception {
String roleName = "test-dup-role";
- String grantor = "g1";
sentryStore.createSentryRole(roleName);
try {
sentryStore.createSentryRole(roleName);
@@ -172,7 +181,6 @@ public class TestSentryStore {
@Test
public void testCreateDropRole() throws Exception {
String roleName = "test-drop-role";
- String grantor = "g1";
long seqId = sentryStore.createSentryRole(roleName).getSequenceId();
assertEquals(seqId + 1, sentryStore.dropSentryRole(roleName).getSequenceId());
}
@@ -1631,11 +1639,11 @@ public class TestSentryStore {
assertEquals(1, privilegeSet.size());
}
- protected void addGroupsToUser(String user, String... groupNames) {
+ protected static void addGroupsToUser(String user, String... groupNames) {
policyFile.addGroupsToUser(user, groupNames);
}
- protected void writePolicyFile() throws Exception {
+ protected static void writePolicyFile() throws Exception {
policyFile.write(policyFilePath);
}