SENTRY-748: Improve test coverage of Sentry + Hive using complex views ( Anne Yu, Reviewed by: Sravya Tirukkovalur)
Project: http://git-wip-us.apache.org/repos/asf/incubator-sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-sentry/commit/5c41715e Tree: http://git-wip-us.apache.org/repos/asf/incubator-sentry/tree/5c41715e Diff: http://git-wip-us.apache.org/repos/asf/incubator-sentry/diff/5c41715e Branch: refs/heads/hive_plugin_v2 Commit: 5c41715e7d11f2301763f99058f453216e315888 Parents: eb6ee63 Author: Sravya Tirukkovalur <[email protected]> Authored: Fri Oct 23 15:47:56 2015 -0700 Committer: Sun Dapeng <[email protected]> Committed: Mon Nov 2 16:37:28 2015 +0800 ---------------------------------------------------------------------- sentry-tests/sentry-tests-hive/pom.xml | 1 + .../AbstractTestWithStaticConfiguration.java | 49 ++++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/5c41715e/sentry-tests/sentry-tests-hive/pom.xml ---------------------------------------------------------------------- diff --git a/sentry-tests/sentry-tests-hive/pom.xml b/sentry-tests/sentry-tests-hive/pom.xml index 7744da1..b70fe60 100644 --- a/sentry-tests/sentry-tests-hive/pom.xml +++ b/sentry-tests/sentry-tests-hive/pom.xml @@ -500,6 +500,7 @@ limitations under the License. <include>**/TestPrivilegeWithGrantOption.java</include> <include>**/TestDbPrivilegesAtColumnScope.java</include> <include>**/TestColumnEndToEnd.java</include> + <include>**/TestDbComplexView.java</include> </includes> <argLine>-Dsentry.e2etest.hiveServer2Type=UnmanagedHiveServer2 -Dsentry.e2etest.DFSType=ClusterDFS -Dsentry.e2etest.external.sentry=true</argLine> </configuration> http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/5c41715e/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 cc5daef..dc8c1eb 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 @@ -461,7 +461,7 @@ public abstract class AbstractTestWithStaticConfiguration { if (clearDbPerTest) { LOGGER.info("After per test run clean up"); clearAll(true); - } + } } protected static void clearAll(boolean clearDb) throws Exception { @@ -479,14 +479,18 @@ public abstract class AbstractTestWithStaticConfiguration { } for (String db : dbs) { if(!db.equalsIgnoreCase("default")) { - statement.execute("DROP DATABASE if exists " + db + " CASCADE"); + String sql = "DROP DATABASE if exists " + db + " CASCADE"; + LOGGER.info("Running [" + sql + "]"); + statement.execute(sql); } } statement.execute("USE default"); resultSet = statement.executeQuery("SHOW tables"); while (resultSet.next()) { Statement statement2 = context.createStatement(connection); - statement2.execute("DROP table " + resultSet.getString(1)); + String sql = "DROP table " + resultSet.getString(1); + LOGGER.info("Running [" + sql + "]"); + statement2.execute(sql); statement2.close(); } } @@ -502,7 +506,9 @@ public abstract class AbstractTestWithStaticConfiguration { } } for (String role : roles) { - statement.execute("DROP Role " + role); + String sql = "DROP Role " + role; + LOGGER.info("Running [" + sql + "]"); + statement.execute(sql); } } statement.close(); @@ -587,4 +593,39 @@ public abstract class AbstractTestWithStaticConfiguration { } } + /** + * A convenient function to run a sequence of sql commands + * @param user + * @param sqls + * @throws Exception + */ + protected void execBatch(String user, List<String> sqls) throws Exception { + Connection conn = context.createConnection(user); + Statement stmt = context.createStatement(conn); + for (String sql : sqls) { + exec(stmt, sql); + } + if (stmt != null) { + stmt.close(); + } + if (conn != null) { + conn.close(); + } + } + + /** + * A convenient funciton to run one sql with log + * @param stmt + * @param sql + * @throws Exception + */ + protected void exec(Statement stmt, String sql) throws Exception { + if (stmt == null) { + LOGGER.error("Statement is null"); + return; + } + LOGGER.info("Running [" + sql + "]"); + stmt.execute(sql); + } + }
