This is an automated email from the ASF dual-hosted git repository. amansinha pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/drill.git
commit 9a47d555b00052115016fbe35cad5a4147d42ad5 Author: Arina Ielchiieva <[email protected]> AuthorDate: Sat May 5 15:31:10 2018 +0300 DRILL-6363: Upgrade jmockit and mockito libs --- .../test/java/org/apache/drill/test/TestTools.java | 2 +- .../drill/TestTpchDistributedConcurrent.java | 3 +- .../drill/exec/coord/zk/TestZookeeperClient.java | 2 +- .../rpc/user/TemporaryTablesAutomaticDropTest.java | 42 ++- .../java/org/apache/drill/exec/sql/TestCTTAS.java | 315 +++++++-------------- .../exec/vector/complex/TestEmptyPopulation.java | 3 - pom.xml | 7 +- 7 files changed, 134 insertions(+), 240 deletions(-) diff --git a/common/src/test/java/org/apache/drill/test/TestTools.java b/common/src/test/java/org/apache/drill/test/TestTools.java index 8cf7ca7..2735c54 100644 --- a/common/src/test/java/org/apache/drill/test/TestTools.java +++ b/common/src/test/java/org/apache/drill/test/TestTools.java @@ -47,7 +47,7 @@ public class TestTools { .indexOf("-agentlib:jdwp") > 0; public static TestRule getTimeoutRule(int timeout) { - return IS_DEBUG ? new TestName() : new Timeout(timeout); + return IS_DEBUG ? new TestName() : Timeout.millis(timeout); } /** diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestTpchDistributedConcurrent.java b/exec/java-exec/src/test/java/org/apache/drill/TestTpchDistributedConcurrent.java index 8991b8b..74b9a5c 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/TestTpchDistributedConcurrent.java +++ b/exec/java-exec/src/test/java/org/apache/drill/TestTpchDistributedConcurrent.java @@ -33,6 +33,7 @@ import org.apache.drill.exec.rpc.user.UserResultsListener; import org.apache.drill.test.BaseTestQuery; import org.apache.drill.test.QueryTestUtil; import org.junit.Rule; +import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.rules.TestRule; @@ -176,7 +177,7 @@ public class TestTpchDistributedConcurrent extends BaseTestQuery { } } - //@Test + @Test public void testConcurrentQueries() throws Exception { QueryTestUtil.testRunAndPrint(client, UserBitShared.QueryType.SQL, alterSession); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/coord/zk/TestZookeeperClient.java b/exec/java-exec/src/test/java/org/apache/drill/exec/coord/zk/TestZookeeperClient.java index 87cf72d..e0e6c79 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/coord/zk/TestZookeeperClient.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/coord/zk/TestZookeeperClient.java @@ -125,7 +125,7 @@ public class TestZookeeperClient { Mockito .when(client.getCache().getCurrentData(absPath)) - .thenThrow(Exception.class); + .thenThrow(RuntimeException.class); client.hasPath(path); } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/TemporaryTablesAutomaticDropTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/TemporaryTablesAutomaticDropTest.java index 5553519..5aef6f7 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/TemporaryTablesAutomaticDropTest.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/TemporaryTablesAutomaticDropTest.java @@ -19,39 +19,40 @@ package org.apache.drill.exec.rpc.user; import mockit.Mock; import mockit.MockUp; +import org.apache.drill.exec.store.StorageStrategy; import org.apache.drill.test.BaseTestQuery; import org.apache.drill.common.config.DrillConfig; -import org.apache.drill.exec.ExecConstants; import org.apache.drill.exec.store.StoragePluginRegistry; import org.apache.drill.exec.util.StoragePluginTestUtils; import org.apache.drill.test.DirTestWatcher; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.LocatedFileStatus; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.RemoteIterator; import org.junit.Before; import org.junit.Test; import java.io.File; -import java.util.Properties; import java.util.UUID; import static org.apache.drill.exec.util.StoragePluginTestUtils.DFS_TMP_SCHEMA; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; public class TemporaryTablesAutomaticDropTest extends BaseTestQuery { - private static final String session_id = "sessionId"; + private static final UUID SESSION_UUID = UUID.randomUUID(); @Before - public void setup() throws Exception { + public void setup() { new MockUp<UUID>() { @Mock public UUID randomUUID() { - return UUID.nameUUIDFromBytes(session_id.getBytes()); + return SESSION_UUID; } }; - - Properties testConfigurations = cloneDefaultTestConfigProperties(); - testConfigurations.put(ExecConstants.DEFAULT_TEMPORARY_WORKSPACE, DFS_TMP_SCHEMA); - updateTestCluster(1, DrillConfig.create(testConfigurations)); + updateTestCluster(1, DrillConfig.create(cloneDefaultTestConfigProperties())); } @Test @@ -90,14 +91,25 @@ public class TemporaryTablesAutomaticDropTest extends BaseTestQuery { } private File createAndCheckSessionTemporaryLocation(String suffix, File schemaLocation) throws Exception { - final String temporaryTableName = "temporary_table_automatic_drop_" + suffix; - final File sessionTemporaryLocation = schemaLocation - .toPath() - .resolve(UUID.nameUUIDFromBytes(session_id.getBytes()).toString()) - .toFile(); + String temporaryTableName = "temporary_table_automatic_drop_" + suffix; + File sessionTemporaryLocation = schemaLocation.toPath().resolve(SESSION_UUID.toString()).toFile(); test("create TEMPORARY table %s.%s as select 'A' as c1 from (values(1))", DFS_TMP_SCHEMA, temporaryTableName); - assertTrue("Session temporary location should exist", sessionTemporaryLocation.exists()); + + FileSystem fs = getLocalFileSystem(); + Path sessionPath = new Path(sessionTemporaryLocation.getAbsolutePath()); + assertTrue("Session temporary location should exist", fs.exists(sessionPath)); + assertEquals("Directory permission should match", + StorageStrategy.TEMPORARY.getFolderPermission(), fs.getFileStatus(sessionPath).getPermission()); + Path tempTablePath = new Path(sessionPath, SESSION_UUID.toString()); + assertTrue("Temporary table location should exist", fs.exists(tempTablePath)); + assertEquals("Directory permission should match", + StorageStrategy.TEMPORARY.getFolderPermission(), fs.getFileStatus(tempTablePath).getPermission()); + RemoteIterator<LocatedFileStatus> fileIterator = fs.listFiles(tempTablePath, false); + while (fileIterator.hasNext()) { + LocatedFileStatus file = fileIterator.next(); + assertEquals("File permission should match", StorageStrategy.TEMPORARY.getFilePermission(), file.getPermission()); + } return sessionTemporaryLocation; } } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestCTTAS.java b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestCTTAS.java index 318e4c9..f2c0c82 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestCTTAS.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestCTTAS.java @@ -18,78 +18,42 @@ package org.apache.drill.exec.sql; import com.google.common.collect.Lists; -import mockit.Mock; -import mockit.MockUp; import org.apache.drill.exec.store.StoragePluginRegistry; import org.apache.drill.exec.store.dfs.FileSystemConfig; import org.apache.drill.exec.store.dfs.WorkspaceConfig; import org.apache.drill.test.BaseTestQuery; import org.apache.drill.categories.SqlTest; -import org.apache.drill.common.config.DrillConfig; import org.apache.drill.common.exceptions.UserRemoteException; -import org.apache.drill.exec.ExecConstants; -import org.apache.drill.exec.store.StorageStrategy; -import org.apache.hadoop.fs.FileSystem; -import org.apache.hadoop.fs.LocatedFileStatus; -import org.apache.hadoop.fs.Path; -import org.apache.hadoop.fs.RemoteIterator; -import org.apache.hadoop.fs.permission.FsPermission; import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.junit.rules.ExpectedException; import java.io.File; -import java.io.IOException; import java.nio.file.Paths; import java.util.List; -import java.util.Properties; -import java.util.UUID; import static org.apache.drill.exec.util.StoragePluginTestUtils.DFS_PLUGIN_NAME; import static org.apache.drill.exec.util.StoragePluginTestUtils.DFS_TMP_SCHEMA; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; @Category(SqlTest.class) public class TestCTTAS extends BaseTestQuery { - private static final UUID session_id = UUID.nameUUIDFromBytes("sessionId".getBytes()); private static final String temp2_wk = "tmp2"; private static final String temp2_schema = String.format("%s.%s", DFS_PLUGIN_NAME, temp2_wk); - private static FileSystem fs; - private static FsPermission expectedFolderPermission; - private static FsPermission expectedFilePermission; + @Rule + public ExpectedException thrown = ExpectedException.none(); @BeforeClass public static void init() throws Exception { - MockUp<UUID> uuidMockUp = mockRandomUUID(session_id); - Properties testConfigurations = cloneDefaultTestConfigProperties(); - testConfigurations.put(ExecConstants.DEFAULT_TEMPORARY_WORKSPACE, DFS_TMP_SCHEMA); - updateTestCluster(1, DrillConfig.create(testConfigurations)); - uuidMockUp.tearDown(); - File tmp2 = dirTestWatcher.makeSubDir(Paths.get("tmp2")); - StoragePluginRegistry pluginRegistry = getDrillbitContext().getStorage(); FileSystemConfig pluginConfig = (FileSystemConfig) pluginRegistry.getPlugin(DFS_PLUGIN_NAME).getConfig(); pluginConfig.workspaces.put(temp2_wk, new WorkspaceConfig(tmp2.getAbsolutePath(), true, null, false)); pluginRegistry.createOrUpdate(DFS_PLUGIN_NAME, pluginConfig, true); - - fs = getLocalFileSystem(); - expectedFolderPermission = new FsPermission(StorageStrategy.TEMPORARY.getFolderPermission()); - expectedFilePermission = new FsPermission(StorageStrategy.TEMPORARY.getFilePermission()); - } - - private static MockUp<UUID> mockRandomUUID(final UUID uuid) { - return new MockUp<UUID>() { - @Mock - public UUID randomUUID() { - return uuid; - } - }; } @Test @@ -105,10 +69,8 @@ public class TestCTTAS extends BaseTestQuery { try { for (String storageFormat : storageFormats) { String temporaryTableName = "temp_" + storageFormat; - mockRandomUUID(UUID.nameUUIDFromBytes(temporaryTableName.getBytes())); test("alter session set `store.format`='%s'", storageFormat); test("create TEMPORARY table %s as select 'A' as c1 from (values(1))", temporaryTableName); - checkPermission(temporaryTableName); testBuilder() .sqlQuery("select * from %s", temporaryTableName) @@ -164,121 +126,91 @@ public class TestCTTAS extends BaseTestQuery { @Test public void testPartitionByWithTemporaryTables() throws Exception { String temporaryTableName = "temporary_table_with_partitions"; - mockRandomUUID(UUID.nameUUIDFromBytes(temporaryTableName.getBytes())); test("create TEMPORARY table %s partition by (c1) as select * from (" + "select 'A' as c1 from (values(1)) union all select 'B' as c1 from (values(1))) t", temporaryTableName); - checkPermission(temporaryTableName); } - @Test(expected = UserRemoteException.class) + @Test public void testCreationOutsideOfDefaultTemporaryWorkspace() throws Exception { - try { - String temporaryTableName = "temporary_table_outside_of_default_workspace"; - test("create TEMPORARY table %s.%s as select 'A' as c1 from (values(1))", temp2_schema, temporaryTableName); - } catch (UserRemoteException e) { - assertThat(e.getMessage(), containsString(String.format( - "VALIDATION ERROR: Temporary tables are not allowed to be created / dropped " + - "outside of default temporary workspace [%s].", DFS_TMP_SCHEMA))); - throw e; - } + String temporaryTableName = "temporary_table_outside_of_default_workspace"; + + expectUserRemoteExceptionWithMessage(String.format( + "VALIDATION ERROR: Temporary tables are not allowed to be created / dropped " + + "outside of default temporary workspace [%s].", DFS_TMP_SCHEMA)); + + test("create TEMPORARY table %s.%s as select 'A' as c1 from (values(1))", temp2_schema, temporaryTableName); } - @Test(expected = UserRemoteException.class) + @Test public void testCreateWhenTemporaryTableExistsWithoutSchema() throws Exception { String temporaryTableName = "temporary_table_exists_without_schema"; - try { - test("create TEMPORARY table %s as select 'A' as c1 from (values(1))", temporaryTableName); - test("create TEMPORARY table %s as select 'A' as c1 from (values(1))", temporaryTableName); - } catch (UserRemoteException e) { - assertThat(e.getMessage(), containsString(String.format( - "VALIDATION ERROR: A table or view with given name [%s]" + - " already exists in schema [%s]", temporaryTableName, DFS_TMP_SCHEMA))); - throw e; - } + test("create TEMPORARY table %s as select 'A' as c1 from (values(1))", temporaryTableName); + + expectUserRemoteExceptionWithTableExistsMessage(temporaryTableName, DFS_TMP_SCHEMA); + + test("create TEMPORARY table %s as select 'A' as c1 from (values(1))", temporaryTableName); } - @Test(expected = UserRemoteException.class) + @Test public void testCreateWhenTemporaryTableExistsCaseInsensitive() throws Exception { - String temporaryTableName = "temporary_table_exists_without_schema"; - try { - test("create TEMPORARY table %s as select 'A' as c1 from (values(1))", temporaryTableName); - test("create TEMPORARY table %s as select 'A' as c1 from (values(1))", temporaryTableName.toUpperCase()); - } catch (UserRemoteException e) { - assertThat(e.getMessage(), containsString(String.format( - "VALIDATION ERROR: A table or view with given name [%s]" + - " already exists in schema [%s]", temporaryTableName.toUpperCase(), DFS_TMP_SCHEMA))); - throw e; - } + String temporaryTableName = "temporary_table_exists_case_insensitive"; + test("create TEMPORARY table %s as select 'A' as c1 from (values(1))", temporaryTableName); + + expectUserRemoteExceptionWithTableExistsMessage(temporaryTableName.toUpperCase(), DFS_TMP_SCHEMA); + + test("create TEMPORARY table %s as select 'A' as c1 from (values(1))", temporaryTableName.toUpperCase()); } - @Test(expected = UserRemoteException.class) + @Test public void testCreateWhenTemporaryTableExistsWithSchema() throws Exception { String temporaryTableName = "temporary_table_exists_with_schema"; - try { - test("create TEMPORARY table %s.%s as select 'A' as c1 from (values(1))", DFS_TMP_SCHEMA, temporaryTableName); - test("create TEMPORARY table %s.%s as select 'A' as c1 from (values(1))", DFS_TMP_SCHEMA, temporaryTableName); - } catch (UserRemoteException e) { - assertThat(e.getMessage(), containsString(String.format( - "VALIDATION ERROR: A table or view with given name [%s]" + - " already exists in schema [%s]", temporaryTableName, DFS_TMP_SCHEMA))); - throw e; - } + test("create TEMPORARY table %s.%s as select 'A' as c1 from (values(1))", DFS_TMP_SCHEMA, temporaryTableName); + + expectUserRemoteExceptionWithTableExistsMessage(temporaryTableName, DFS_TMP_SCHEMA); + + test("create TEMPORARY table %s.%s as select 'A' as c1 from (values(1))", DFS_TMP_SCHEMA, temporaryTableName); } - @Test(expected = UserRemoteException.class) + @Test public void testCreateWhenPersistentTableExists() throws Exception { String persistentTableName = "persistent_table_exists"; - try { - test("create table %s.%s as select 'A' as c1 from (values(1))", DFS_TMP_SCHEMA, persistentTableName); - test("create TEMPORARY table %s as select 'A' as c1 from (values(1))", persistentTableName); - } catch (UserRemoteException e) { - assertThat(e.getMessage(), containsString(String.format( - "VALIDATION ERROR: A table or view with given name [%s]" + - " already exists in schema [%s]", persistentTableName, DFS_TMP_SCHEMA))); - throw e; - } + test("create table %s.%s as select 'A' as c1 from (values(1))", DFS_TMP_SCHEMA, persistentTableName); + + expectUserRemoteExceptionWithTableExistsMessage(persistentTableName, DFS_TMP_SCHEMA); + + test("create TEMPORARY table %s as select 'A' as c1 from (values(1))", persistentTableName); } - @Test(expected = UserRemoteException.class) + @Test public void testCreateWhenViewExists() throws Exception { String viewName = "view_exists"; - try { - test("create view %s.%s as select 'A' as c1 from (values(1))", DFS_TMP_SCHEMA, viewName); - test("create TEMPORARY table %s as select 'A' as c1 from (values(1))", viewName); - } catch (UserRemoteException e) { - assertThat(e.getMessage(), containsString(String.format( - "VALIDATION ERROR: A table or view with given name [%s]" + - " already exists in schema [%s]", viewName, DFS_TMP_SCHEMA))); - throw e; - } + test("create view %s.%s as select 'A' as c1 from (values(1))", DFS_TMP_SCHEMA, viewName); + + expectUserRemoteExceptionWithTableExistsMessage(viewName, DFS_TMP_SCHEMA); + + test("create TEMPORARY table %s as select 'A' as c1 from (values(1))", viewName); } - @Test(expected = UserRemoteException.class) + @Test public void testCreatePersistentTableWhenTemporaryTableExists() throws Exception { String temporaryTableName = "temporary_table_exists_before_persistent"; - try { - test("create TEMPORARY table %s as select 'A' as c1 from (values(1))", temporaryTableName); - test("create table %s.%s as select 'A' as c1 from (values(1))", DFS_TMP_SCHEMA, temporaryTableName); - } catch (UserRemoteException e) { - assertThat(e.getMessage(), containsString(String.format( - "VALIDATION ERROR: A table or view with given name [%s]" + - " already exists in schema [%s]", temporaryTableName, DFS_TMP_SCHEMA))); - throw e; - } + test("create TEMPORARY table %s as select 'A' as c1 from (values(1))", temporaryTableName); + + expectUserRemoteExceptionWithTableExistsMessage(temporaryTableName, DFS_TMP_SCHEMA); + + test("create table %s.%s as select 'A' as c1 from (values(1))", DFS_TMP_SCHEMA, temporaryTableName); } - @Test(expected = UserRemoteException.class) + @Test public void testCreateViewWhenTemporaryTableExists() throws Exception { String temporaryTableName = "temporary_table_exists_before_view"; - try { - test("create TEMPORARY table %s as select 'A' as c1 from (values(1))", temporaryTableName); - test("create view %s.%s as select 'A' as c1 from (values(1))", DFS_TMP_SCHEMA, temporaryTableName); - } catch (UserRemoteException e) { - assertThat(e.getMessage(), containsString(String.format( - "VALIDATION ERROR: A non-view table with given name [%s] already exists in schema [%s]", - temporaryTableName, DFS_TMP_SCHEMA))); - throw e; - } + test("create TEMPORARY table %s as select 'A' as c1 from (values(1))", temporaryTableName); + + expectUserRemoteExceptionWithMessage(String.format( + "VALIDATION ERROR: A non-view table with given name [%s] already exists in schema [%s]", + temporaryTableName, DFS_TMP_SCHEMA)); + + test("create view %s.%s as select 'A' as c1 from (values(1))", DFS_TMP_SCHEMA, temporaryTableName); } @Test @@ -358,21 +290,18 @@ public class TestCTTAS extends BaseTestQuery { .go(); } - @Test(expected = UserRemoteException.class) + @Test public void testTemporaryTablesInViewDefinitions() throws Exception { String temporaryTableName = "temporary_table_for_view_definition"; test("create TEMPORARY table %s as select 'A' as c1 from (values(1))", temporaryTableName); - try { - test("create view %s.view_with_temp_table as select * from %s", DFS_TMP_SCHEMA, temporaryTableName); - } catch (UserRemoteException e) { - assertThat(e.getMessage(), containsString(String.format( - "VALIDATION ERROR: Temporary tables usage is disallowed. Used temporary table name: [%s]", temporaryTableName))); - throw e; - } + expectUserRemoteExceptionWithMessage(String.format( + "VALIDATION ERROR: Temporary tables usage is disallowed. Used temporary table name: [%s]", temporaryTableName)); + + test("create view %s.view_with_temp_table as select * from %s", DFS_TMP_SCHEMA, temporaryTableName); } - @Test(expected = UserRemoteException.class) + @Test public void testTemporaryTablesInViewExpansionLogic() throws Exception { String tableName = "table_for_expansion_logic_test"; String viewName = "view_for_expansion_logic_test"; @@ -389,73 +318,48 @@ public class TestCTTAS extends BaseTestQuery { test("drop table %s", tableName); test("create temporary table %s as select 'TEMP' as c1 from (values(1))", tableName); - try { - test("select * from %s", viewName); - } catch (UserRemoteException e) { - assertThat(e.getMessage(), containsString(String.format( - "VALIDATION ERROR: Temporary tables usage is disallowed. Used temporary table name: [%s]", tableName))); - throw e; - } + + expectUserRemoteExceptionWithMessage(String.format( + "VALIDATION ERROR: Temporary tables usage is disallowed. Used temporary table name: [%s]", tableName)); + + test("select * from %s", viewName); } @Test // DRILL-5952 public void testCreateTemporaryTableIfNotExistsWhenTableWithSameNameAlreadyExists() throws Exception{ final String newTblName = "createTemporaryTableIfNotExistsWhenATableWithSameNameAlreadyExists"; + test("CREATE TEMPORARY TABLE %s.%s AS SELECT * from cp.`region.json`", DFS_TMP_SCHEMA, newTblName); - try { - String ctasQuery = String.format("CREATE TEMPORARY TABLE %s.%s AS SELECT * from cp.`region.json`", DFS_TMP_SCHEMA, newTblName); - - test(ctasQuery); - - ctasQuery = - String.format("CREATE TEMPORARY TABLE IF NOT EXISTS %s AS SELECT * FROM cp.`employee.json`", newTblName); + testBuilder() + .sqlQuery("CREATE TEMPORARY TABLE IF NOT EXISTS %s AS SELECT * FROM cp.`employee.json`", newTblName) + .unOrdered() + .baselineColumns("ok", "summary") + .baselineValues(false, String.format("A table or view with given name [%s] already exists in schema [%s]", newTblName, DFS_TMP_SCHEMA)) + .go(); - testBuilder() - .sqlQuery(ctasQuery) - .unOrdered() - .baselineColumns("ok", "summary") - .baselineValues(false, String.format("A table or view with given name [%s] already exists in schema [%s]", newTblName, DFS_TMP_SCHEMA)) - .go(); - } finally { - test(String.format("DROP TABLE IF EXISTS %s.%s", DFS_TMP_SCHEMA, newTblName)); - } + test("DROP TABLE IF EXISTS %s.%s", DFS_TMP_SCHEMA, newTblName); } @Test // DRILL-5952 public void testCreateTemporaryTableIfNotExistsWhenViewWithSameNameAlreadyExists() throws Exception{ final String newTblName = "createTemporaryTableIfNotExistsWhenAViewWithSameNameAlreadyExists"; + test("CREATE VIEW %s.%s AS SELECT * from cp.`region.json`", DFS_TMP_SCHEMA, newTblName); - try { - String ctasQuery = String.format("CREATE VIEW %s.%s AS SELECT * from cp.`region.json`", DFS_TMP_SCHEMA, newTblName); - - test(ctasQuery); - - ctasQuery = - String.format("CREATE TEMPORARY TABLE IF NOT EXISTS %s.%s AS SELECT * FROM cp.`employee.json`", DFS_TMP_SCHEMA, newTblName); + testBuilder() + .sqlQuery("CREATE TEMPORARY TABLE IF NOT EXISTS %s.%s AS SELECT * FROM cp.`employee.json`", DFS_TMP_SCHEMA, newTblName) + .unOrdered() + .baselineColumns("ok", "summary") + .baselineValues(false, String.format("A table or view with given name [%s] already exists in schema [%s]", newTblName, DFS_TMP_SCHEMA)) + .go(); - testBuilder() - .sqlQuery(ctasQuery) - .unOrdered() - .baselineColumns("ok", "summary") - .baselineValues(false, String.format("A table or view with given name [%s] already exists in schema [%s]", newTblName, DFS_TMP_SCHEMA)) - .go(); - } finally { - test(String.format("DROP VIEW IF EXISTS %s.%s", DFS_TMP_SCHEMA, newTblName)); - } + test("DROP VIEW IF EXISTS %s.%s", DFS_TMP_SCHEMA, newTblName); } @Test // DRILL-5952 public void testCreateTemporaryTableIfNotExistsWhenTableWithSameNameDoesNotExist() throws Exception{ final String newTblName = "createTemporaryTableIfNotExistsWhenATableWithSameNameDoesNotExist"; - - try { - String ctasQuery = String.format("CREATE TEMPORARY TABLE IF NOT EXISTS %s.%s AS SELECT * FROM cp.`employee.json`", DFS_TMP_SCHEMA, newTblName); - - test(ctasQuery); - - } finally { - test(String.format("DROP TABLE IF EXISTS %s.%s", DFS_TMP_SCHEMA, newTblName)); - } + test("CREATE TEMPORARY TABLE IF NOT EXISTS %s.%s AS SELECT * FROM cp.`employee.json`", DFS_TMP_SCHEMA, newTblName); + test("DROP TABLE IF EXISTS %s.%s", DFS_TMP_SCHEMA, newTblName); } @Test @@ -498,47 +402,26 @@ public class TestCTTAS extends BaseTestQuery { .go(); } - @Test(expected = UserRemoteException.class) + @Test public void testDropTemporaryTableAsViewWithException() throws Exception { String temporaryTableName = "temporary_table_to_drop_like_view_with_exception"; test("create TEMPORARY table %s as select 'A' as c1 from (values(1))", temporaryTableName); - try { - test("drop view %s.%s", DFS_TMP_SCHEMA, temporaryTableName); - } catch (UserRemoteException e) { - assertThat(e.getMessage(), containsString(String.format( - "VALIDATION ERROR: Unknown view [%s] in schema [%s]", temporaryTableName, DFS_TMP_SCHEMA))); - throw e; - } + expectUserRemoteExceptionWithMessage(String.format( + "VALIDATION ERROR: Unknown view [%s] in schema [%s]", temporaryTableName, DFS_TMP_SCHEMA)); + + test("drop view %s.%s", DFS_TMP_SCHEMA, temporaryTableName); } - private void checkPermission(String tmpTableName) throws IOException { - List<Path> matchingPath = findTemporaryTableLocation(tmpTableName); - assertEquals("Only one directory should match temporary table name " + tmpTableName, 1, matchingPath.size()); - Path tmpTablePath = matchingPath.get(0); - assertEquals("Directory permission should match", - expectedFolderPermission, fs.getFileStatus(tmpTablePath).getPermission()); - RemoteIterator<LocatedFileStatus> fileIterator = fs.listFiles(tmpTablePath, false); - while (fileIterator.hasNext()) { - assertEquals("File permission should match", expectedFilePermission, fileIterator.next().getPermission()); - } + private void expectUserRemoteExceptionWithMessage(String message) { + thrown.expect(UserRemoteException.class); + thrown.expectMessage(containsString(message)); } - private List<Path> findTemporaryTableLocation(String tableName) throws IOException { - Path sessionTempLocation = new Path(dirTestWatcher.getDfsTestTmpDir().getAbsolutePath(), session_id.toString()); - assertTrue("Session temporary location must exist", fs.exists(sessionTempLocation)); - assertEquals("Session temporary location permission should match", - expectedFolderPermission, fs.getFileStatus(sessionTempLocation).getPermission()); - String tableUUID = UUID.nameUUIDFromBytes(tableName.getBytes()).toString(); - - RemoteIterator<LocatedFileStatus> pathList = fs.listLocatedStatus(sessionTempLocation); - List<Path> matchingPath = Lists.newArrayList(); - while (pathList.hasNext()) { - LocatedFileStatus path = pathList.next(); - if (path.isDirectory() && path.getPath().getName().equals(tableUUID)) { - matchingPath.add(path.getPath()); - } - } - return matchingPath; + private void expectUserRemoteExceptionWithTableExistsMessage(String tableName, String schemaName) { + expectUserRemoteExceptionWithMessage(String.format( + "VALIDATION ERROR: A table or view with given name [%s]" + + " already exists in schema [%s]", tableName, schemaName)); } + } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/TestEmptyPopulation.java b/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/TestEmptyPopulation.java index c2add41..307faab 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/TestEmptyPopulation.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/TestEmptyPopulation.java @@ -28,10 +28,7 @@ import org.apache.drill.exec.vector.UInt4Vector; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; -@RunWith(MockitoJUnitRunner.class) public class TestEmptyPopulation extends BaseTestQuery { private UInt4Vector offsets; diff --git a/pom.xml b/pom.xml index 4272978..151f208 100644 --- a/pom.xml +++ b/pom.xml @@ -798,9 +798,9 @@ <!-- Test Dependencies --> <dependency> <!-- JMockit needs to be on class path before JUnit. --> - <groupId>com.googlecode.jmockit</groupId> + <groupId>org.jmockit</groupId> <artifactId>jmockit</artifactId> - <version>1.3</version> + <version>1.39</version> <scope>test</scope> </dependency> <dependency> @@ -814,7 +814,8 @@ long as Mockito _contains_ older Hamcrest classes. See DRILL-2130. --> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> - <version>1.9.5</version> + <version>2.18.3</version> + <scope>test</scope> </dependency> <dependency> <groupId>ch.qos.logback</groupId> -- To stop receiving notification emails like this one, please contact [email protected].
