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/12 09:04:07 UTC

incubator-sentry git commit: SENTRY-635: Improve test cases in TestPerDBConfiguration (Reviewed by Xiaomeng)

Repository: incubator-sentry
Updated Branches:
  refs/heads/master 3f9847128 -> a4ca17d57


SENTRY-635: Improve test cases in TestPerDBConfiguration (Reviewed by Xiaomeng)


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

Branch: refs/heads/master
Commit: a4ca17d57605ba33af4ed541d5f4b1b5ec01bdbd
Parents: 3f98471
Author: Colin Ma <co...@apache.org>
Authored: Thu Feb 12 15:46:01 2015 +0800
Committer: Colin Ma <co...@apache.org>
Committed: Thu Feb 12 15:46:01 2015 +0800

----------------------------------------------------------------------
 .../AbstractTestWithStaticConfiguration.java    |   6 +-
 .../tests/e2e/hive/TestPerDBConfiguration.java  | 273 +++++++------------
 .../e2e/hive/TestPrivilegesAtColumnScope.java   |  14 +-
 ...actMetastoreTestWithStaticConfiguration.java |   7 +-
 4 files changed, 107 insertions(+), 193 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/a4ca17d5/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithStaticConfiguration.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithStaticConfiguration.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithStaticConfiguration.java
index d08b4ee..c68873e 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithStaticConfiguration.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithStaticConfiguration.java
@@ -254,7 +254,7 @@ public abstract class AbstractTestWithStaticConfiguration {
         baseDir, confDir, logDir, policyFile, fileSystem);
   }
 
-  protected void writePolicyFile(PolicyFile policyFile) throws Exception {
+  protected static void writePolicyFile(PolicyFile policyFile) throws Exception {
     policyFile.write(context.getPolicyFile());
     if(policyOnHdfs) {
       dfs.writePolicyFile(context.getPolicyFile());
@@ -263,7 +263,7 @@ public abstract class AbstractTestWithStaticConfiguration {
     }
   }
 
-  private void grantPermissions(PolicyFile policyFile) throws Exception {
+  private static void grantPermissions(PolicyFile policyFile) throws Exception {
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
 
@@ -297,7 +297,7 @@ public abstract class AbstractTestWithStaticConfiguration {
     }
   }
 
-  private void addPrivilege(String roleName, String privileges, Statement statement)
+  private static void addPrivilege(String roleName, String privileges, Statement statement)
       throws IOException, SQLException{
     String serverName = null, dbName = null, tableName = null, uriPath = null, columnName = null;
     String action = "ALL";//AccessConstants.ALL;

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/a4ca17d5/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPerDBConfiguration.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPerDBConfiguration.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPerDBConfiguration.java
index 4452d9a..30541d9 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPerDBConfiguration.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPerDBConfiguration.java
@@ -30,6 +30,7 @@ import org.apache.sentry.policy.db.SimpleDBPolicyEngine;
 import org.apache.sentry.provider.file.PolicyFile;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import com.google.common.io.Resources;
@@ -38,24 +39,22 @@ import com.google.common.io.Resources;
  * Test privileges per database policy files
  */
 public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration {
+
   private static final String MULTI_TYPE_DATA_FILE_NAME = "emp.dat";
   private static final String DB2_POLICY_FILE = "db2-policy-file.ini";
 
-  private File dataFile;
+  private static File dataFile;
   private PolicyFile policyFile;
   private static String prefix;
 
+  @BeforeClass
+  public static void setupTestStaticConfiguration() throws Exception {
+    AbstractTestWithStaticConfiguration.setupTestStaticConfiguration();
+    prepareDBDataForTest();
+  }
+
   @Before
   public void setup() throws Exception {
-    policyFile = PolicyFile.setAdminOnServer1(ADMINGROUP);
-
-    File dataDir = context.getDataDir();
-    //copy data file to test dir
-    dataFile = new File(dataDir, MULTI_TYPE_DATA_FILE_NAME);
-    FileOutputStream to = new FileOutputStream(dataFile);
-    Resources.copy(Resources.getResource(MULTI_TYPE_DATA_FILE_NAME), to);
-    to.close();
-
     String hiveServer2 = System.getProperty("sentry.e2etest.hiveServer2Type", "InternalHiveServer2");
     String policyOnHDFS = System.getProperty("sentry.e2etest.hive.policyOnHDFS", "true");
     if(policyOnHDFS.trim().equalsIgnoreCase("true") && (hiveServer2.equals("UnmanagedHiveServer2") )){
@@ -65,13 +64,62 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
       prefix = "file://" + context.getPolicyFile().getParent() + "/";
     }
 
+    policyFile = PolicyFile.setAdminOnServer1(ADMINGROUP);
+  }
+
+  protected static void prepareDBDataForTest() throws Exception {
+    clearDbAfterPerTest = false;
+    PolicyFile policyFile = PolicyFile.setAdminOnServer1(ADMINGROUP).setUserGroupMapping(
+        StaticUserGroup.getStaticMapping());
+    writePolicyFile(policyFile);
+    // copy data file to test dir
+    dataDir = context.getDataDir();
+    dataFile = new File(dataDir, MULTI_TYPE_DATA_FILE_NAME);
+    FileOutputStream to = new FileOutputStream(dataFile);
+    Resources.copy(Resources.getResource(MULTI_TYPE_DATA_FILE_NAME), to);
+    to.close();
+
+    // setup db objects needed by the test
+    Connection connection = context.createConnection(ADMIN1);
+    Statement statement = context.createStatement(connection);
+
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
+    statement.execute("CREATE TABLE tbl1(B INT, A STRING) "
+        + " row format delimited fields terminated by '|'  stored as textfile");
+    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl1");
+
+    statement.execute("DROP DATABASE IF EXISTS " + DB2 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB2);
+    statement.execute("USE " + DB2);
+    statement.execute("CREATE TABLE tbl2(B INT, A STRING) "
+        + " row format delimited fields terminated by '|'  stored as textfile");
+    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl2");
+    statement.execute("CREATE TABLE tbl5(B INT, A STRING) "
+        + " row format delimited fields terminated by '|'  stored as textfile");
+
+    statement.execute("DROP DATABASE IF EXISTS db3 CASCADE");
+    statement.execute("CREATE DATABASE db3");
+    statement.execute("USE db3");
+    statement.execute("CREATE TABLE tbl3(B INT, A STRING) "
+        + " row format delimited fields terminated by '|'  stored as textfile");
+    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl3");
+
+    statement.execute("DROP DATABASE IF EXISTS db4 CASCADE");
+    statement.execute("CREATE DATABASE db4");
+    statement.execute("USE db4");
+    statement.execute("CREATE TABLE tbl4(B INT, A STRING) "
+        + " row format delimited fields terminated by '|'  stored as textfile");
+    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl4");
+    statement.close();
+    connection.close();
   }
 
   @After
   public void teardown() throws Exception {
     // one test turns this on so let's disable it in the teardown method
     System.setProperty(SimpleDBPolicyEngine.ACCESS_ALLOW_URI_PER_DB_POLICYFILE, "false");
-    clearDB();
   }
 
   @Test
@@ -91,36 +139,16 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
         .setUserGroupMapping(StaticUserGroup.getStaticMapping())
         .write(context.getPolicyFile());
 
-    // setup db objects needed by the test
-    Connection connection = context.createConnection(ADMIN1);
-    Statement statement = context.createStatement(connection);
-
-    statement.execute("DROP DATABASE IF EXISTS " + DB1 +" CASCADE");
-    statement.execute("DROP DATABASE IF EXISTS "  + DB2 + " CASCADE");
-    statement.execute("CREATE DATABASE "  + DB1);
-    statement.execute("USE "  + DB1);
-    statement.execute("CREATE TABLE tbl1(B INT, A STRING) " +
-                      " row format delimited fields terminated by '|'  stored as textfile");
-    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl1");
-    statement.execute("DROP DATABASE IF EXISTS "  + DB2 + " CASCADE");
-    statement.execute("CREATE DATABASE "  + DB2);
-    statement.execute("USE "  + DB2);
-    statement.execute("CREATE TABLE tbl2(B INT, A STRING) " +
-                      " row format delimited fields terminated by '|'  stored as textfile");
-    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl2");
-    statement.close();
-    connection.close();
-
     // test execution
-    connection = context.createConnection(USER1_1);
-    statement = context.createStatement(connection);
+    Connection connection = context.createConnection(USER1_1);
+    Statement statement = context.createStatement(connection);
     statement.execute("USE "  + DB1);
     // test user1 can execute query on tbl1
-    verifyCount(statement, "SELECT COUNT(*) FROM tbl1");
+    verifyCount(statement, "SELECT COUNT(*) FROM tbl1", 1, 12);
 
     // user1 cannot query db2.tbl2
     context.assertAuthzException(statement, "USE "  + DB2);
-    context.assertAuthzException(statement, "SELECT COUNT(*) FROM "  + DB2 + ".tbl2");
+    context.assertAuthzException(statement, "SELECT COUNT(*) FROM " + DB2 + ".tbl2");
     statement.close();
     connection.close();
 
@@ -130,22 +158,15 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     statement = context.createStatement(connection);
     statement.execute("USE "  + DB2);
     // test user2 can execute query on tbl2
-    verifyCount(statement, "SELECT COUNT(*) FROM tbl2");
+    verifyCount(statement, "SELECT COUNT(*) FROM tbl2", 1, 12);
 
     // user2 cannot query db1.tbl1
-    context.assertAuthzException(statement, "SELECT COUNT(*) FROM " + DB1 +".tbl1");
+    context.assertAuthzException(statement, "SELECT COUNT(*) FROM " + DB1 + ".tbl1");
     context.assertAuthzException(statement, "USE "  + DB1);
 
     statement.close();
     connection.close();
 
-    //test cleanup
-    connection = context.createConnection(ADMIN1);
-    statement = context.createStatement(connection);
-    statement.execute("DROP DATABASE " + DB1 +" CASCADE");
-    statement.execute("DROP DATABASE "  + DB2 + " CASCADE");
-    statement.close();
-    connection.close();
   }
 
   /**
@@ -188,54 +209,19 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
         .setUserGroupMapping(StaticUserGroup.getStaticMapping())
         .write(context.getPolicyFile());
 
-    // setup db objects needed by the test
-    Connection connection = context.createConnection(ADMIN1);
-    Statement statement = context.createStatement(connection);
-
-    statement.execute("DROP DATABASE IF EXISTS " + DB1 +" CASCADE");
-    statement.execute("CREATE DATABASE "  + DB1);
-    statement.execute("USE "  + DB1);
-    statement.execute("CREATE TABLE tbl1(B INT, A STRING) " +
-                      " row format delimited fields terminated by '|'  stored as textfile");
-    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl1");
-
-    statement.execute("DROP DATABASE IF EXISTS "  + DB2 + " CASCADE");
-    statement.execute("CREATE DATABASE "  + DB2);
-    statement.execute("USE "  + DB2);
-    statement.execute("CREATE TABLE tbl2(B INT, A STRING) " +
-                      " row format delimited fields terminated by '|'  stored as textfile");
-    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl2");
-
-    statement.execute("DROP DATABASE IF EXISTS db3 CASCADE");
-    statement.execute("CREATE DATABASE db3");
-    statement.execute("USE db3");
-    statement.execute("CREATE TABLE tbl3(B INT, A STRING) " +
-                      " row format delimited fields terminated by '|'  stored as textfile");
-    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl3");
-
-    statement.execute("DROP DATABASE IF EXISTS db4 CASCADE");
-    statement.execute("CREATE DATABASE db4");
-    statement.execute("USE db4");
-    statement.execute("CREATE TABLE tbl4(B INT, A STRING) " +
-                      " row format delimited fields terminated by '|'  stored as textfile");
-    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl4");
-
-    statement.close();
-    connection.close();
-
     // test execution
-    connection = context.createConnection(USER1_1);
-    statement = context.createStatement(connection);
+    Connection connection = context.createConnection(USER1_1);
+    Statement statement = context.createStatement(connection);
     statement.execute("USE "  + DB1);
     // test user1 can execute query on tbl1
-    verifyCount(statement, "SELECT COUNT(*) FROM tbl1");
+    verifyCount(statement, "SELECT COUNT(*) FROM tbl1", 1, 12);
     connection.close();
 
     connection = context.createConnection(USER2_1);
     statement = context.createStatement(connection);
     statement.execute("USE "  + DB2);
     // test user1 can execute query on tbl1
-    verifyCount(statement, "SELECT COUNT(*) FROM tbl2");
+    verifyCount(statement, "SELECT COUNT(*) FROM tbl2", 1, 12);
     connection.close();
 
     // verify no access to db3 due to badly formatted rule in db3 policy file
@@ -250,73 +236,45 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     statement = context.createStatement(connection);
     statement.execute("USE db4");
     // test user1 can execute query on tbl1
-    verifyCount(statement, "SELECT COUNT(*) FROM tbl4");
-    connection.close();
-
-    //test cleanup
-    connection = context.createConnection(ADMIN1);
-    statement = context.createStatement(connection);
-    statement.execute("DROP DATABASE " + DB1 +" CASCADE");
-    statement.execute("DROP DATABASE "  + DB2 + " CASCADE");
-    statement.execute("DROP DATABASE db3 CASCADE");
-    statement.execute("DROP DATABASE db4 CASCADE");
-    statement.close();
+    verifyCount(statement, "SELECT COUNT(*) FROM tbl4", 1, 12);
     connection.close();
   }
 
   @Test
   public void testPerDBPolicyFileWithURI() throws Exception {
     File db2PolicyFileHandle = new File(context.getPolicyFile().getParent(), DB2_POLICY_FILE);
+    PolicyFile db2PolicyFile = new PolicyFile();
+    db2PolicyFile
+        .addRolesToGroup(USERGROUP2, "select_tbl5", "data_read", "insert_tbl5")
+        .addPermissionsToRole("select_tbl5",
+            "server=server1->db=" + DB2 + "->table=tbl5->action=select")
+        .addPermissionsToRole("insert_tbl5",
+            "server=server1->db=" + DB2 + "->table=tbl5->action=insert")
+        .addPermissionsToRole("data_read", "server=server1->URI=file://" + dataFile)
+        .write(db2PolicyFileHandle);
 
     policyFile
         .addRolesToGroup(USERGROUP1, "select_tbl1")
-        .addRolesToGroup(USERGROUP2, "select_tbl2")
+        .addRolesToGroup(USERGROUP2, "select_tbl5")
         .addPermissionsToRole("select_tbl1", "server=server1->db=" + DB1 +"->table=tbl1->action=select")
         .addDatabase(DB2, prefix + db2PolicyFileHandle.getName())
         .setUserGroupMapping(StaticUserGroup.getStaticMapping())
         .write(context.getPolicyFile());
 
-    PolicyFile db2PolicyFile = new PolicyFile();
-    db2PolicyFile
-        .addRolesToGroup(USERGROUP2, "select_tbl2", "data_read", "insert_tbl2")
-        .addPermissionsToRole("select_tbl2", "server=server1->db="  + DB2 + "->table=tbl2->action=select")
-        .addPermissionsToRole("insert_tbl2", "server=server1->db="  + DB2 + "->table=tbl2->action=insert")
-        .addPermissionsToRole("data_read", "server=server1->URI=file://" + dataFile)
-        .write(db2PolicyFileHandle);
     // ugly hack: needs to go away once this becomes a config property. Note that this property
     // will not be set with external HS and this test will fail. Hope is this fix will go away
     // by then.
     System.setProperty(SimpleDBPolicyEngine.ACCESS_ALLOW_URI_PER_DB_POLICYFILE, "true");
-    // setup db objects needed by the test
-    Connection connection = context.createConnection(ADMIN1);
-    Statement statement = context.createStatement(connection);
-
-    statement.execute("DROP DATABASE IF EXISTS " + DB1 +" CASCADE");
-    statement.execute("DROP DATABASE IF EXISTS "  + DB2 + " CASCADE");
-    statement.execute("CREATE DATABASE "  + DB1);
-    statement.execute("USE "  + DB1);
-    statement.execute("CREATE TABLE tbl1(B INT, A STRING) " +
-                      " row format delimited fields terminated by '|'  stored as textfile");
-    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl1");
-    statement.execute("DROP DATABASE IF EXISTS "  + DB2 + " CASCADE");
-    statement.execute("CREATE DATABASE "  + DB2);
-    statement.execute("USE "  + DB2);
-    statement.execute("CREATE TABLE tbl2(B INT, A STRING) " +
-                      " row format delimited fields terminated by '|'  stored as textfile");
-    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl2");
-    statement.close();
-    connection.close();
-
     // test execution
-    connection = context.createConnection(USER1_1);
-    statement = context.createStatement(connection);
+    Connection connection = context.createConnection(USER1_1);
+    Statement statement = context.createStatement(connection);
     statement.execute("USE "  + DB1);
     // test user1 can execute query on tbl1
-    verifyCount(statement, "SELECT COUNT(*) FROM tbl1");
+    verifyCount(statement, "SELECT COUNT(*) FROM tbl1", 1, 12);
 
-    // user1 cannot query db2.tbl2
+    // user1 cannot query db2.tbl5
     context.assertAuthzException(statement, "USE "  + DB2);
-    context.assertAuthzException(statement, "SELECT COUNT(*) FROM "  + DB2 + ".tbl2");
+    context.assertAuthzException(statement, "SELECT COUNT(*) FROM " + DB2 + ".tbl5");
     statement.close();
     connection.close();
 
@@ -324,14 +282,14 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     connection = context.createConnection(USER2_1);
     statement = context.createStatement(connection);
     statement.execute("USE "  + DB2);
-    // test user2 can execute query on tbl2
-    verifyCount(statement, "SELECT COUNT(*) FROM tbl2");
+    // test user2 can execute query on tbl5
+    verifyCount(statement, "SELECT COUNT(*) FROM tbl5", 1, 0);
 
     // verify user2 can execute LOAD
-    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl2");
+    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl5");
 
     // user2 cannot query db1.tbl1
-    context.assertAuthzException(statement, "SELECT COUNT(*) FROM " + DB1 +".tbl1");
+    context.assertAuthzException(statement, "SELECT COUNT(*) FROM " + DB1 + ".tbl1");
     context.assertAuthzException(statement, "USE "  + DB1);
 
     // once we disable this property all queries should fail
@@ -343,14 +301,6 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
 
     statement.close();
     connection.close();
-
-    //test cleanup
-    connection = context.createConnection(ADMIN1);
-    statement = context.createStatement(connection);
-    statement.execute("DROP DATABASE " + DB1 +" CASCADE");
-    statement.execute("DROP DATABASE "  + DB2 + " CASCADE");
-    statement.close();
-    connection.close();
   }
 
   /**
@@ -365,24 +315,9 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
         .setUserGroupMapping(StaticUserGroup.getStaticMapping())
         .write(context.getPolicyFile());
 
-    // setup db objects needed by the test
-    Connection connection = context.createConnection(ADMIN1);
-    Statement statement = context.createStatement(connection);
-
-    statement.execute("USE default");
-
-    statement.execute("DROP DATABASE IF EXISTS " + DB1 +" CASCADE");
-    statement.execute("CREATE DATABASE "  + DB1);
-    statement.execute("USE "  + DB1);
-    statement.execute("CREATE TABLE tbl1(B INT, A STRING) " +
-                      " row format delimited fields terminated by '|'  stored as textfile");
-    statement.execute("DROP DATABASE IF EXISTS "  + DB2 + " CASCADE");
-    statement.close();
-    connection.close();
-
     // user_1 should be able to access default
-    connection = context.createConnection(USER1_1);
-    statement = context.createStatement(connection);
+    Connection connection = context.createConnection(USER1_1);
+    Statement statement = context.createStatement(connection);
     statement.execute("USE default");
     statement.close();
     connection.close();
@@ -427,23 +362,8 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     Statement statement = context.createStatement(connection);
     statement.execute("USE default");
     statement.execute("DROP TABLE IF EXISTS dtab");
-    statement.execute("CREATE TABLE dtab(B INT, A STRING) " +
-                      " row format delimited fields terminated by '|'  stored as textfile");
-
-    statement.execute("DROP DATABASE IF EXISTS " + DB1 +" CASCADE");
-    statement.execute("DROP DATABASE IF EXISTS "  + DB2 + " CASCADE");
-    statement.execute("CREATE DATABASE "  + DB1);
-    statement.execute("USE "  + DB1);
-    statement.execute("CREATE TABLE tbl1(B INT, A STRING) " +
-                      " row format delimited fields terminated by '|'  stored as textfile");
-    statement.execute("DROP DATABASE IF EXISTS "  + DB2 + " CASCADE");
-    statement.execute("CREATE DATABASE "  + DB2);
-    statement.execute("USE "  + DB2);
-    statement.execute("CREATE TABLE tbl2(B INT, A STRING) " +
-                      " row format delimited fields terminated by '|'  stored as textfile");
-    statement.close();
-    connection.close();
-
+    statement.execute("CREATE TABLE dtab(B INT, A STRING) "
+        + " row format delimited fields terminated by '|'  stored as textfile");
     // user_1 should be able to switch to default, but not the tables from default
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
@@ -475,7 +395,8 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     connection.close();
   }
 
-  private void verifyCount(Statement statement, String query) throws SQLException {
+  private void verifyCount(Statement statement, String query, int exceptedCountRows,
+      int exceptedCount) throws SQLException {
     ResultSet resultSet = statement.executeQuery(query);
     int count = 0;
     int countRows = 0;
@@ -484,7 +405,7 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
       count = resultSet.getInt(1);
       countRows++;
     }
-    assertTrue("Incorrect row count", countRows == 1);
-    assertTrue("Incorrect result", count == 12);
+    assertTrue("Incorrect row count:" + countRows, countRows == exceptedCountRows);
+    assertTrue("Incorrect result:" + count, count == exceptedCount);
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/a4ca17d5/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtColumnScope.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtColumnScope.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtColumnScope.java
index 1ccab46..9eeed60 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtColumnScope.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtColumnScope.java
@@ -39,14 +39,9 @@ public class TestPrivilegesAtColumnScope extends AbstractTestWithStaticConfigura
 
   private static PolicyFile policyFile;
   private final static String MULTI_TYPE_DATA_FILE_NAME = "emp.dat";
-  private static boolean isDBDataPrepared = false;
 
   @Before
   public void setup() throws Exception {
-    if (!isDBDataPrepared) {
-      prepareDBDataForTest();
-      isDBDataPrepared = true;
-    }
     if (useSentryService) {
       policyFile = new PolicyFile();
     } else {
@@ -56,12 +51,15 @@ public class TestPrivilegesAtColumnScope extends AbstractTestWithStaticConfigura
 
   @BeforeClass
   public static void setupTestStaticConfiguration() throws Exception {
-    clearDbAfterPerTest = false;
     AbstractTestWithStaticConfiguration.setupTestStaticConfiguration();
+    prepareDBDataForTest();
   }
 
-  private void prepareDBDataForTest() throws Exception {
-    policyFile = PolicyFile.setAdminOnServer1(ADMINGROUP).setUserGroupMapping(
+  private static void prepareDBDataForTest() throws Exception {
+    clearDbAfterPerTest = false;
+    // if use sentry service, need setup admin role first
+    setupAdmin();
+    PolicyFile policyFile = PolicyFile.setAdminOnServer1(ADMINGROUP).setUserGroupMapping(
         StaticUserGroup.getStaticMapping());
     writePolicyFile(policyFile);
     // copy data file to test dir

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/a4ca17d5/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/AbstractMetastoreTestWithStaticConfiguration.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/AbstractMetastoreTestWithStaticConfiguration.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/AbstractMetastoreTestWithStaticConfiguration.java
index 9d15c95..6bc1d33 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/AbstractMetastoreTestWithStaticConfiguration.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/AbstractMetastoreTestWithStaticConfiguration.java
@@ -37,13 +37,9 @@ import org.apache.hadoop.hive.ql.Driver;
 import org.apache.hadoop.hive.ql.processors.CommandProcessorResponse;
 import org.apache.hadoop.hive.ql.session.SessionState;
 import org.apache.hadoop.hive.serde.serdeConstants;
-import org.apache.hadoop.hive.shims.ShimLoader;
-import org.apache.hadoop.hive.shims.Utils;
 import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.pig.PigServer;
-import org.apache.sentry.provider.db.service.thrift.SentryPolicyServiceClient;
 import org.apache.sentry.provider.file.PolicyFile;
-import org.apache.sentry.service.thrift.SentryServiceClientFactory;
 import org.apache.sentry.tests.e2e.hive.AbstractTestWithStaticConfiguration;
 import org.apache.sentry.tests.e2e.hive.hiveserver.HiveServerFactory.HiveServer2Type;
 import org.junit.After;
@@ -65,8 +61,7 @@ public abstract class AbstractMetastoreTestWithStaticConfiguration extends
 
   }
 
-  @Override
-  protected void writePolicyFile(PolicyFile policyFile) throws Exception {
+  protected static void writePolicyFile(PolicyFile policyFile) throws Exception {
     policyFile.write(context.getPolicyFile());
   }