Repository: incubator-sentry Updated Branches: refs/heads/master fd31d2cd4 -> 244876100
SENTRY-698: Uncaught OutOfMemoryError (Colin Ma, reviewed by Guoquan Shen) Project: http://git-wip-us.apache.org/repos/asf/incubator-sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-sentry/commit/24487610 Tree: http://git-wip-us.apache.org/repos/asf/incubator-sentry/tree/24487610 Diff: http://git-wip-us.apache.org/repos/asf/incubator-sentry/diff/24487610 Branch: refs/heads/master Commit: 24487610038e4be8eec0f320a0e20d2b79a2b035 Parents: fd31d2c Author: Colin Ma <[email protected]> Authored: Mon Apr 20 09:58:00 2015 +0800 Committer: Colin Ma <[email protected]> Committed: Mon Apr 20 09:58:00 2015 +0800 ---------------------------------------------------------------------- .../e2e/dbprovider/TestDbJDBCInterface.java | 40 ++++ .../sentry/tests/e2e/hive/TestCrossDbOps.java | 162 +------------- .../tests/e2e/hive/TestJDBCInterface.java | 214 +++++++++++++++++++ 3 files changed, 255 insertions(+), 161 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/24487610/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbJDBCInterface.java ---------------------------------------------------------------------- diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbJDBCInterface.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbJDBCInterface.java new file mode 100644 index 0000000..27897f4 --- /dev/null +++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbJDBCInterface.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.sentry.tests.e2e.dbprovider; + +import org.apache.sentry.tests.e2e.hive.AbstractTestWithStaticConfiguration; +import org.apache.sentry.tests.e2e.hive.TestJDBCInterface; +import org.junit.Before; +import org.junit.BeforeClass; + +public class TestDbJDBCInterface extends TestJDBCInterface { + + @Override + @Before + public void setup() throws Exception { + super.setupAdmin(); + super.setup(); + } + + @BeforeClass + public static void setupTestStaticConfiguration() throws Exception { + useSentryService = true; + AbstractTestWithStaticConfiguration.setupTestStaticConfiguration(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/24487610/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestCrossDbOps.java ---------------------------------------------------------------------- diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestCrossDbOps.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestCrossDbOps.java index 5d3a4f1..38c361c 100644 --- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestCrossDbOps.java +++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestCrossDbOps.java @@ -17,15 +17,12 @@ package org.apache.sentry.tests.e2e.hive; -import org.apache.sentry.provider.file.PolicyFile; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.File; import java.io.FileOutputStream; import java.sql.Connection; import java.sql.ResultSet; -import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; @@ -33,6 +30,7 @@ import java.util.List; import junit.framework.Assert; +import org.apache.sentry.provider.file.PolicyFile; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -182,165 +180,7 @@ public class TestCrossDbOps extends AbstractTestWithStaticConfiguration { context.close(); } - /* - * Admin creates DB_1, DB2, tables (tab_1 ) and (tab_2, tab_3) in DB_1 and - * DB_2 respectively. User user1 has select on DB_1.tab_1, insert on - * DB2.tab_2 User user2 has select on DB2.tab_3 Test show database and show - * tables for both user1 and user2 - */ - @Test - public void testJDBCGetSchemasAndGetTables() throws Exception { - // edit policy file - policyFile.addRolesToGroup(USERGROUP1, "select_tab1", "insert_tab2") - .addRolesToGroup(USERGROUP2, "select_tab3") - .addPermissionsToRole("select_tab1", "server=server1->db=" + DB1 + "->table=tab1->action=select") - .addPermissionsToRole("select_tab3", "server=server1->db=" + DB2 + "->table=tab3->action=select") - .addPermissionsToRole("insert_tab2", "server=server1->db=" + DB2 + "->table=tab2->action=insert") - .setUserGroupMapping(StaticUserGroup.getStaticMapping()); - writePolicyFile(policyFile); - - - // admin create two databases - Connection connection = context.createConnection(ADMIN1); - Statement statement = context.createStatement(connection); - statement.execute("DROP DATABASE IF EXISTS DB_1 CASCADE"); - statement.execute("DROP DATABASE IF EXISTS DB_2 CASCADE"); - statement.execute("DROP DATABASE IF EXISTS DB1 CASCADE"); - statement.execute("DROP DATABASE IF EXISTS DB2 CASCADE"); - - statement.execute("CREATE DATABASE " + DB1); - statement.execute("CREATE DATABASE " + DB2); - statement.execute("USE " + DB1); - statement.execute("CREATE TABLE TAB1(id int)"); - statement.executeQuery("SHOW TABLES"); - statement.execute("USE " + DB2); - statement.execute("CREATE TABLE TAB2(id int)"); - statement.execute("CREATE TABLE TAB3(id int)"); - - // test show databases - // show databases shouldn't filter any of the dbs from the resultset - Connection conn = context.createConnection(USER1_1); - List<String> result = new ArrayList<String>(); - - // test direct JDBC metadata API - ResultSet res = conn.getMetaData().getSchemas(); - ResultSetMetaData resMeta = res.getMetaData(); - assertEquals(2, resMeta.getColumnCount()); - assertEquals("TABLE_SCHEM", resMeta.getColumnName(1)); - assertEquals("TABLE_CATALOG", resMeta.getColumnName(2)); - - result.add(DB1); - result.add(DB2); - result.add("default"); - - while (res.next()) { - String dbName = res.getString(1); - assertTrue(dbName, result.remove(dbName)); - } - assertTrue(result.toString(), result.isEmpty()); - res.close(); - - // test direct JDBC metadata API - res = conn.getMetaData().getTables(null, DB1, "tab%", null); - result.add("tab1"); - - while (res.next()) { - String tableName = res.getString(3); - assertTrue(tableName, result.remove(tableName)); - } - assertTrue(result.toString(), result.isEmpty()); - res.close(); - - // test direct JDBC metadata API - res = conn.getMetaData().getTables(null, DB2, "tab%", null); - result.add("tab2"); - - while (res.next()) { - String tableName = res.getString(3); - assertTrue(tableName, result.remove(tableName)); - } - assertTrue(result.toString(), result.isEmpty()); - res.close(); - - res = conn.getMetaData().getTables(null, "DB%", "tab%", null); - result.add("tab2"); - result.add("tab1"); - - while (res.next()) { - String tableName = res.getString(3); - assertTrue(tableName, result.remove(tableName)); - } - assertTrue(result.toString(), result.isEmpty()); - res.close(); - - //test show columns - res = conn.getMetaData().getColumns(null, "DB%", "tab%","i%" ); - result.add("id"); - result.add("id"); - - while (res.next()) { - String columnName = res.getString(4); - assertTrue(columnName, result.remove(columnName)); - } - assertTrue(result.toString(), result.isEmpty()); - res.close(); - - conn.close(); - - // test show databases and show tables for user2 - conn = context.createConnection(USER2_1); - - // test direct JDBC metadata API - res = conn.getMetaData().getSchemas(); - resMeta = res.getMetaData(); - assertEquals(2, resMeta.getColumnCount()); - assertEquals("TABLE_SCHEM", resMeta.getColumnName(1)); - assertEquals("TABLE_CATALOG", resMeta.getColumnName(2)); - - result.add(DB2); - result.add("default"); - while (res.next()) { - String dbName = res.getString(1); - assertTrue(dbName, result.remove(dbName)); - } - assertTrue(result.toString(), result.isEmpty()); - res.close(); - - // test JDBC direct API - res = conn.getMetaData().getTables(null, "DB%", "tab%", null); - result.add("tab3"); - - while (res.next()) { - String tableName = res.getString(3); - assertTrue(tableName, result.remove(tableName)); - } - assertTrue(result.toString(), result.isEmpty()); - res.close(); - - //test show columns - res = conn.getMetaData().getColumns(null, "DB%", "tab%","i%" ); - result.add("id"); - - while (res.next()) { - String columnName = res.getString(4); - assertTrue(columnName, result.remove(columnName)); - } - assertTrue(result.toString(), result.isEmpty()); - res.close(); - - //test show columns - res = conn.getMetaData().getColumns(null, DB1, "tab%","i%" ); - - while (res.next()) { - String columnName = res.getString(4); - assertTrue(columnName, result.remove(columnName)); - } - assertTrue(result.toString(), result.isEmpty()); - res.close(); - - context.close(); - } /** * 2.8 admin user create two database, DB_1, DB_2 admin grant all to USER1_1, http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/24487610/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestJDBCInterface.java ---------------------------------------------------------------------- diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestJDBCInterface.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestJDBCInterface.java new file mode 100644 index 0000000..6a9ae5c --- /dev/null +++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestJDBCInterface.java @@ -0,0 +1,214 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.sentry.tests.e2e.hive; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +import org.apache.sentry.provider.file.PolicyFile; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +public class TestJDBCInterface extends AbstractTestWithStaticConfiguration { + + private static PolicyFile policyFile; + + @BeforeClass + public static void setupTestStaticConfiguration() throws Exception { + policyOnHdfs = true; + AbstractTestWithStaticConfiguration.setupTestStaticConfiguration(); + + } + + @Before + public void setup() throws Exception { + policyFile = PolicyFile.setAdminOnServer1(ADMINGROUP); + } + + /* + * Admin creates DB_1, DB2, tables (tab_1 ) and (tab_2, tab_3) in DB_1 and + * DB_2 respectively. User user1 has select on DB_1.tab_1, insert on + * DB2.tab_2 User user2 has select on DB2.tab_3 Test show database and show + * tables for both user1 and user2 + */ + @Test + public void testJDBCGetSchemasAndGetTables() throws Exception { + // edit policy file + policyFile + .addRolesToGroup(USERGROUP1, "select_tab1", "insert_tab2") + .addRolesToGroup(USERGROUP2, "select_tab3") + .addPermissionsToRole("select_tab1", + "server=server1->db=" + DB1 + "->table=tab1->action=select") + .addPermissionsToRole("select_tab3", + "server=server1->db=" + DB2 + "->table=tab3->action=select") + .addPermissionsToRole("insert_tab2", + "server=server1->db=" + DB2 + "->table=tab2->action=insert") + .setUserGroupMapping(StaticUserGroup.getStaticMapping()); + writePolicyFile(policyFile); + + // admin create two databases + Connection connection = context.createConnection(ADMIN1); + Statement statement = context.createStatement(connection); + statement.execute("DROP DATABASE IF EXISTS DB_1 CASCADE"); + statement.execute("DROP DATABASE IF EXISTS DB_2 CASCADE"); + statement.execute("DROP DATABASE IF EXISTS DB1 CASCADE"); + statement.execute("DROP DATABASE IF EXISTS DB2 CASCADE"); + + statement.execute("CREATE DATABASE " + DB1); + statement.execute("CREATE DATABASE " + DB2); + statement.execute("USE " + DB1); + statement.execute("CREATE TABLE TAB1(id int)"); + statement.executeQuery("SHOW TABLES"); + statement.execute("USE " + DB2); + statement.execute("CREATE TABLE TAB2(id int)"); + statement.execute("CREATE TABLE TAB3(id int)"); + + // test show databases + // show databases shouldn't filter any of the dbs from the resultset + Connection conn = context.createConnection(USER1_1); + List<String> result = new ArrayList<String>(); + + // test direct JDBC metadata API + ResultSet res = conn.getMetaData().getSchemas(); + ResultSetMetaData resMeta = res.getMetaData(); + assertEquals(2, resMeta.getColumnCount()); + assertEquals("TABLE_SCHEM", resMeta.getColumnName(1)); + assertEquals("TABLE_CATALOG", resMeta.getColumnName(2)); + + result.add(DB1); + result.add(DB2); + result.add("default"); + + while (res.next()) { + String dbName = res.getString(1); + assertTrue(dbName, result.remove(dbName)); + } + assertTrue(result.toString(), result.isEmpty()); + res.close(); + + // test direct JDBC metadata API + res = conn.getMetaData().getTables(null, DB1, "tab%", null); + result.add("tab1"); + + while (res.next()) { + String tableName = res.getString(3); + assertTrue(tableName, result.remove(tableName)); + } + assertTrue(result.toString(), result.isEmpty()); + res.close(); + + // test direct JDBC metadata API + res = conn.getMetaData().getTables(null, DB2, "tab%", null); + result.add("tab2"); + + while (res.next()) { + String tableName = res.getString(3); + assertTrue(tableName, result.remove(tableName)); + } + assertTrue(result.toString(), result.isEmpty()); + res.close(); + + res = conn.getMetaData().getTables(null, "DB%", "tab%", null); + result.add("tab2"); + result.add("tab1"); + + while (res.next()) { + String tableName = res.getString(3); + assertTrue(tableName, result.remove(tableName)); + } + assertTrue(result.toString(), result.isEmpty()); + res.close(); + + // test show columns + res = conn.getMetaData().getColumns(null, "DB%", "tab%", "i%"); + result.add("id"); + result.add("id"); + + while (res.next()) { + String columnName = res.getString(4); + assertTrue(columnName, result.remove(columnName)); + } + assertTrue(result.toString(), result.isEmpty()); + res.close(); + + conn.close(); + + // test show databases and show tables for user2 + conn = context.createConnection(USER2_1); + + // test direct JDBC metadata API + res = conn.getMetaData().getSchemas(); + resMeta = res.getMetaData(); + assertEquals(2, resMeta.getColumnCount()); + assertEquals("TABLE_SCHEM", resMeta.getColumnName(1)); + assertEquals("TABLE_CATALOG", resMeta.getColumnName(2)); + + result.add(DB2); + result.add("default"); + + while (res.next()) { + String dbName = res.getString(1); + assertTrue(dbName, result.remove(dbName)); + } + assertTrue(result.toString(), result.isEmpty()); + res.close(); + + // test JDBC direct API + res = conn.getMetaData().getTables(null, "DB%", "tab%", null); + result.add("tab3"); + + while (res.next()) { + String tableName = res.getString(3); + assertTrue(tableName, result.remove(tableName)); + } + assertTrue(result.toString(), result.isEmpty()); + res.close(); + + // test show columns + res = conn.getMetaData().getColumns(null, "DB%", "tab%", "i%"); + result.add("id"); + + while (res.next()) { + String columnName = res.getString(4); + assertTrue(columnName, result.remove(columnName)); + } + assertTrue(result.toString(), result.isEmpty()); + res.close(); + + // test show columns + res = conn.getMetaData().getColumns(null, DB1, "tab%", "i%"); + + while (res.next()) { + String columnName = res.getString(4); + assertTrue(columnName, result.remove(columnName)); + } + assertTrue(result.toString(), result.isEmpty()); + res.close(); + + context.close(); + } + +}
