http://git-wip-us.apache.org/repos/asf/drill/blob/acc5ed92/exec/jdbc-all/src/test/java/org/apache/drill/jdbc/ITTestShadedJar.java ---------------------------------------------------------------------- diff --git a/exec/jdbc-all/src/test/java/org/apache/drill/jdbc/ITTestShadedJar.java b/exec/jdbc-all/src/test/java/org/apache/drill/jdbc/ITTestShadedJar.java index d11af95..f652a91 100644 --- a/exec/jdbc-all/src/test/java/org/apache/drill/jdbc/ITTestShadedJar.java +++ b/exec/jdbc-all/src/test/java/org/apache/drill/jdbc/ITTestShadedJar.java @@ -31,21 +31,97 @@ import java.sql.DatabaseMetaData; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.UUID; import java.util.Vector; import java.util.concurrent.Semaphore; -import org.apache.commons.io.FileUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.ClassRule; import org.junit.Test; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; public class ITTestShadedJar { - private static DrillbitClassLoader drillbitLoader; private static URLClassLoader rootClassLoader; private static int userPort; + @ClassRule + public static final TestWatcher testWatcher = new TestWatcher() { + + @Override + protected void starting(Description description) { + super.starting(description); + + try { + drillbitLoader = new DrillbitClassLoader(); + drillbitLoader.loadClass("org.apache.commons.io.FileUtils"); + rootClassLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader(); + + Class<?> clazz = drillbitLoader.loadClass("org.apache.drill.test.BaseTestQuery"); + Class<?> watcherClazz = drillbitLoader.loadClass("org.apache.drill.test.BaseDirTestWatcher"); + + // Setup tmp dirs + runMethod("starting", description); + + // Configure tmp dir + Object watcher = clazz.getField("dirTestWatcher").get(null); + Method method = watcherClazz.getDeclaredMethod("getTmpDir"); + File tmpDir = (File) method.invoke(watcher); + System.setProperty("DRILL_CONF_DIR", tmpDir.getAbsolutePath()); + + // Start the drill cluster + try { + runWithLoader("DrillbitStartThread", drillbitLoader); + } catch (Exception e) { + printClassesLoaded("root", rootClassLoader); + throw e; + } + + DrillbitStartThread.SEM.acquire(); + + // After starting the drill cluster get the client port + userPort = (Integer) clazz.getMethod("getUserPort").invoke(null); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + protected void finished(Description description) { + super.finished(description); + done(); + runMethod("finished", description); + } + + @Override + protected void failed(Throwable e, Description description) { + super.failed(e, description); + done(); + runMethod("failed", description); + } + + private void done() { + try { + runWithLoader("DrillbitStopThread", drillbitLoader); + DrillbitStopThread.SEM.acquire(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private void runMethod(String name, Description description) { + try { + Class<?> clazz = drillbitLoader.loadClass("org.apache.drill.test.BaseTestQuery"); + Class<?> watcherClazz = drillbitLoader.loadClass("org.junit.rules.TestWatcher"); + Object watcher = clazz.getField("dirTestWatcher").get(null); + Method method = watcherClazz.getDeclaredMethod(name, Description.class); + method.setAccessible(true); + method.invoke(watcher, description); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }; + private static URL getJdbcUrl() throws MalformedURLException { return new URL( String.format("%s../../target/drill-jdbc-all-%s.jar", @@ -55,22 +131,6 @@ public class ITTestShadedJar { } - static { - String dirConfDir = "DRILL_CONF_DIR"; - if (System.getProperty(dirConfDir) == null) { - final File condDir = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); - condDir.mkdirs(); - condDir.deleteOnExit(); - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - FileUtils.deleteQuietly(condDir); - } - }); - System.setProperty(dirConfDir, condDir.getAbsolutePath()); - } - } - @Test public void testDatabaseVersion() throws Exception { @@ -90,7 +150,6 @@ public class ITTestShadedJar { DatabaseMetaData metadata = c.getMetaData(); assertEquals("Apache Drill JDBC Driver", metadata.getDriverName()); assertEquals("Apache Drill Server", metadata.getDatabaseProductName()); - //assertEquals() } } catch (Exception ex) { throw ex; @@ -114,8 +173,7 @@ public class ITTestShadedJar { try { Driver driver = (Driver) clazz.newInstance(); try (Connection c = driver.connect("jdbc:drill:drillbit=localhost:" + userPort, null)) { - String path = Paths.get("").toAbsolutePath().toString() + "/src/test/resources/types.json"; - printQuery(c, "select * from dfs.`" + path + "`"); + printQuery(c, "select * from cp.`types.json`"); } } catch (Exception ex) { throw ex; @@ -136,30 +194,6 @@ public class ITTestShadedJar { } } - @BeforeClass - public static void setupDefaultTestCluster() throws Exception { - drillbitLoader = new DrillbitClassLoader(); - rootClassLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader(); - try { - runWithLoader("DrillbitStartThread", drillbitLoader); - } catch (Exception e) { - printClassesLoaded("root", rootClassLoader); - throw e; - } - - Class<?> clazz = drillbitLoader.loadClass("org.apache.drill.BaseTestQuery"); - userPort = (Integer) clazz.getMethod("getUserPort").invoke(null); - - DrillbitStartThread.SEM.acquire(); - } - - @AfterClass - public static void closeClient() throws Exception { - runWithLoader("DrillbitStopThread", drillbitLoader); - - DrillbitStopThread.SEM.acquire(); - } - private static int getClassesLoadedCount(ClassLoader classLoader) { try { Field f = ClassLoader.class.getDeclaredField("classes"); @@ -229,7 +263,7 @@ public class ITTestShadedJar { @Override protected void internalRun() throws Exception { - Class<?> clazz = loader.loadClass("org.apache.drill.BaseTestQuery"); + Class<?> clazz = loader.loadClass("org.apache.drill.test.BaseTestQuery"); clazz.getMethod("setupDefaultTestCluster").invoke(null); // loader.loadClass("org.apache.drill.exec.exception.SchemaChangeException"); @@ -252,7 +286,7 @@ public class ITTestShadedJar { @Override protected void internalRun() throws Exception { - Class<?> clazz = loader.loadClass("org.apache.drill.BaseTestQuery"); + Class<?> clazz = loader.loadClass("org.apache.drill.test.BaseTestQuery"); clazz.getMethod("closeClient").invoke(null); SEM.release(); }
http://git-wip-us.apache.org/repos/asf/drill/blob/acc5ed92/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillConnectionImpl.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillConnectionImpl.java b/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillConnectionImpl.java index c0804c5..a2b9211 100644 --- a/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillConnectionImpl.java +++ b/exec/jdbc/src/main/java/org/apache/drill/jdbc/impl/DrillConnectionImpl.java @@ -17,6 +17,7 @@ */ package org.apache.drill.jdbc.impl; +import java.io.File; import java.sql.Array; import java.sql.Blob; import java.sql.CallableStatement; @@ -58,7 +59,6 @@ import org.apache.drill.exec.rpc.RpcException; import org.apache.drill.exec.server.Drillbit; import org.apache.drill.exec.server.RemoteServiceSet; import org.apache.drill.exec.store.StoragePluginRegistry; -import org.apache.drill.exec.util.TestUtilities; import org.apache.drill.jdbc.AlreadyClosedSqlException; import org.apache.drill.jdbc.DrillConnection; import org.apache.drill.jdbc.DrillConnectionConfig; @@ -68,6 +68,16 @@ import org.slf4j.Logger; import com.google.common.base.Throwables; +import static org.apache.drill.exec.util.StoragePluginTestUtils.DEFAULT_SCHEMA; +import static org.apache.drill.exec.util.StoragePluginTestUtils.DFS_PLUGIN_NAME; +import static org.apache.drill.exec.util.StoragePluginTestUtils.ROOT_SCHEMA; +import static org.apache.drill.exec.util.StoragePluginTestUtils.TMP_SCHEMA; +import static org.apache.drill.exec.util.StoragePluginTestUtils.UNIT_TEST_DFS_DEFAULT_PROP; +import static org.apache.drill.exec.util.StoragePluginTestUtils.UNIT_TEST_DFS_ROOT_PROP; +import static org.apache.drill.exec.util.StoragePluginTestUtils.UNIT_TEST_DFS_TMP_PROP; +import static org.apache.drill.exec.util.StoragePluginTestUtils.UNIT_TEST_PROP_PREFIX; +import static org.apache.drill.exec.util.StoragePluginTestUtils.updateSchemaLocation; + /** * Drill's implementation of {@link Connection}. */ @@ -817,16 +827,36 @@ class DrillConnectionImpl extends AvaticaConnection /** * Test only code to make JDBC tests run concurrently. If the property <i>drillJDBCUnitTests</i> is set to * <i>true</i> in connection properties: - * - Update dfs_test.tmp workspace location with a temp directory. This temp is for exclusive use for test jvm. + * - Update dfs.tmp workspace location with a temp directory. This temp is for exclusive use for test jvm. * - Update dfs.tmp workspace to immutable, so that test writer don't try to create views in dfs.tmp * @param pluginRegistry */ private static void makeTmpSchemaLocationsUnique(StoragePluginRegistry pluginRegistry, Properties props) { try { - if (props != null && "true".equalsIgnoreCase(props.getProperty("drillJDBCUnitTests"))) { - final String tmpDirPath = TestUtilities.createTempDir(); - TestUtilities.updateDfsTestTmpSchemaLocation(pluginRegistry, tmpDirPath); - TestUtilities.makeDfsTmpSchemaImmutable(pluginRegistry); + if (props != null && "true".equalsIgnoreCase(props.getProperty(UNIT_TEST_PROP_PREFIX))) { + final String logMessage = "The {} property was not configured"; + + final String dfsTmpPath = props.getProperty(UNIT_TEST_DFS_TMP_PROP); + final String dfsRootPath = props.getProperty(UNIT_TEST_DFS_ROOT_PROP); + final String dfsDefaultPath = props.getProperty(UNIT_TEST_DFS_DEFAULT_PROP); + + if (dfsTmpPath == null) { + logger.warn(logMessage, UNIT_TEST_DFS_TMP_PROP); + } else { + updateSchemaLocation(DFS_PLUGIN_NAME, pluginRegistry, new File(dfsTmpPath), TMP_SCHEMA); + } + + if (dfsRootPath == null) { + logger.warn(logMessage, UNIT_TEST_DFS_ROOT_PROP); + } else { + updateSchemaLocation(DFS_PLUGIN_NAME, pluginRegistry, new File(dfsRootPath), ROOT_SCHEMA); + } + + if (dfsDefaultPath == null) { + logger.warn(logMessage, UNIT_TEST_DFS_DEFAULT_PROP); + } else { + updateSchemaLocation(DFS_PLUGIN_NAME, pluginRegistry, new File(dfsDefaultPath), DEFAULT_SCHEMA); + } } } catch(Throwable e) { // Reason for catching Throwable is to capture NoSuchMethodError etc which depend on certain classed to be http://git-wip-us.apache.org/repos/asf/drill/blob/acc5ed92/exec/jdbc/src/test/java/org/apache/drill/jdbc/DatabaseMetaDataGetColumnsTest.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/DatabaseMetaDataGetColumnsTest.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/DatabaseMetaDataGetColumnsTest.java index 894abd9..ed95162 100644 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/DatabaseMetaDataGetColumnsTest.java +++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/DatabaseMetaDataGetColumnsTest.java @@ -20,6 +20,7 @@ package org.apache.drill.jdbc; import static java.sql.ResultSetMetaData.columnNoNulls; import static java.sql.ResultSetMetaData.columnNullable; import static java.sql.ResultSetMetaData.columnNullableUnknown; +import static org.apache.drill.exec.util.StoragePluginTestUtils.DFS_TMP_SCHEMA; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.nullValue; import static org.junit.Assert.assertNotNull; @@ -35,7 +36,6 @@ import java.sql.SQLException; import java.sql.Statement; import java.sql.Types; -import org.apache.drill.jdbc.test.JdbcAssert; import org.apache.drill.categories.JdbcTest; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -85,8 +85,6 @@ import org.junit.experimental.categories.Category; */ @Category(JdbcTest.class) public class DatabaseMetaDataGetColumnsTest extends JdbcTestBase { - - private static final String VIEW_SCHEMA = "dfs_test.tmp"; private static final String VIEW_NAME = DatabaseMetaDataGetColumnsTest.class.getSimpleName() + "_View"; @@ -189,8 +187,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTestBase { // (Note: Can't use JdbcTest's connect(...) because JdbcTest closes // Connection--and other JDBC objects--on test method failure, but this test // class uses some objects across methods.) - connection = new Driver().connect( "jdbc:drill:zk=local", - JdbcAssert.getDefaultProperties() ); + connection = connect(); dbMetadata = connection.getMetaData(); setUpMetadataToCheck(); @@ -229,7 +226,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTestBase { TODO(DRILL-3253)(end) */ // Create temporary test-columns view: - util = stmt.executeQuery( "USE dfs_test.tmp" ); + util = stmt.executeQuery( "USE dfs.tmp" ); assertTrue( util.next() ); assertTrue( "Error setting schema for test: " + util.getString( 2 ), util.getBoolean( 1 ) ); @@ -290,48 +287,48 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTestBase { // Set up result rows for temporary test view and Hivetest columns: - mdrOptBOOLEAN = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrOptBOOLEAN" ); + mdrOptBOOLEAN = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrOptBOOLEAN" ); // TODO(DRILL-2470): Uncomment when TINYINT is implemented: //mdrReqTINYINT = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqTINYINT" ); // TODO(DRILL-2470): Uncomment when SMALLINT is implemented: //mdrOptSMALLINT = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrOptSMALLINT" ); - mdrReqINTEGER = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqINTEGER" ); - mdrOptBIGINT = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrOptBIGINT" ); + mdrReqINTEGER = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrReqINTEGER" ); + mdrOptBIGINT = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrOptBIGINT" ); // TODO(DRILL-2683): Uncomment when REAL is implemented: //mdrOptREAL = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrOptREAL" ); - mdrOptFLOAT = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrOptFLOAT" ); - mdrReqDOUBLE = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqDOUBLE" ); - - mdrReqDECIMAL_5_3 = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqDECIMAL_5_3" ); - - mdrReqVARCHAR_10 = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqVARCHAR_10" ); - mdrOptVARCHAR = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrOptVARCHAR" ); - mdrReqCHAR_5 = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqCHAR_5" ); - mdrOptVARBINARY_16 = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrOptVARBINARY_16" ); - mdrOptBINARY_1048576 = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrOptBINARY_1048576" ); - - mdrReqDATE = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqDATE" ); - mdrReqTIME = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqTIME" ); - mdrOptTIME_7 = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrOptTIME_7" ); - mdrOptTIMESTAMP = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrOptTIMESTAMP" ); - - mdrReqINTERVAL_Y = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_Y" ); - mdrReqINTERVAL_3Y_Mo = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_3Y_Mo" ); - mdrReqINTERVAL_Mo = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_Mo" ); - mdrReqINTERVAL_D = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_D" ); - mdrReqINTERVAL_4D_H = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_4D_H" ); - mdrReqINTERVAL_3D_Mi = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_3D_Mi" ); - mdrReqINTERVAL_2D_S5 = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_2D_S5" ); - mdrReqINTERVAL_H = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_H" ); - mdrReqINTERVAL_1H_Mi = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_1H_Mi" ); - mdrReqINTERVAL_3H_S1 = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_3H_S1" ); - mdrReqINTERVAL_Mi = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_Mi" ); - mdrReqINTERVAL_5Mi_S = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_5Mi_S" ); - mdrReqINTERVAL_S = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_S" ); - mdrReqINTERVAL_3S = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_3S" ); - mdrReqINTERVAL_3S1 = setUpRow( VIEW_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_3S1" ); + mdrOptFLOAT = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrOptFLOAT" ); + mdrReqDOUBLE = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrReqDOUBLE" ); + + mdrReqDECIMAL_5_3 = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrReqDECIMAL_5_3" ); + + mdrReqVARCHAR_10 = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrReqVARCHAR_10" ); + mdrOptVARCHAR = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrOptVARCHAR" ); + mdrReqCHAR_5 = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrReqCHAR_5" ); + mdrOptVARBINARY_16 = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrOptVARBINARY_16" ); + mdrOptBINARY_1048576 = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrOptBINARY_1048576" ); + + mdrReqDATE = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrReqDATE" ); + mdrReqTIME = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrReqTIME" ); + mdrOptTIME_7 = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrOptTIME_7" ); + mdrOptTIMESTAMP = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrOptTIMESTAMP" ); + + mdrReqINTERVAL_Y = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_Y" ); + mdrReqINTERVAL_3Y_Mo = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_3Y_Mo" ); + mdrReqINTERVAL_Mo = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_Mo" ); + mdrReqINTERVAL_D = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_D" ); + mdrReqINTERVAL_4D_H = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_4D_H" ); + mdrReqINTERVAL_3D_Mi = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_3D_Mi" ); + mdrReqINTERVAL_2D_S5 = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_2D_S5" ); + mdrReqINTERVAL_H = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_H" ); + mdrReqINTERVAL_1H_Mi = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_1H_Mi" ); + mdrReqINTERVAL_3H_S1 = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_3H_S1" ); + mdrReqINTERVAL_Mi = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_Mi" ); + mdrReqINTERVAL_5Mi_S = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_5Mi_S" ); + mdrReqINTERVAL_S = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_S" ); + mdrReqINTERVAL_3S = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_3S" ); + mdrReqINTERVAL_3S1 = setUpRow( DFS_TMP_SCHEMA, VIEW_NAME, "mdrReqINTERVAL_3S1" ); /* TODO(DRILL-3253)(start): Update this once we have test plugin supporting all needed types. mdrReqARRAY = setUpRow( "hive_test.default", "infoschematest", "listtype" ); @@ -442,7 +439,7 @@ public class DatabaseMetaDataGetColumnsTest extends JdbcTestBase { @Test public void test_TABLE_SCHEM_hasRightValue_mdrOptBOOLEAN() throws SQLException { - assertThat( mdrOptBOOLEAN.getString( "TABLE_SCHEM" ), equalTo( VIEW_SCHEMA ) ); + assertThat( mdrOptBOOLEAN.getString( "TABLE_SCHEM" ), equalTo( DFS_TMP_SCHEMA ) ); } // Not bothering with other _local_view_ test columns for TABLE_SCHEM. http://git-wip-us.apache.org/repos/asf/drill/blob/acc5ed92/exec/jdbc/src/test/java/org/apache/drill/jdbc/DrillResultSetTest.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/DrillResultSetTest.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/DrillResultSetTest.java index a522954..e75d19c 100644 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/DrillResultSetTest.java +++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/DrillResultSetTest.java @@ -31,8 +31,6 @@ import java.sql.Statement; import org.apache.drill.categories.SlowTest; import org.apache.drill.exec.ExecConstants; -import org.apache.drill.jdbc.test.JdbcAssert; -import org.apache.drill.test.DrillTest; import org.apache.drill.categories.JdbcTest; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -40,7 +38,7 @@ import org.junit.Test; import org.junit.experimental.categories.Category; @Category({SlowTest.class, JdbcTest.class}) -public class DrillResultSetTest extends DrillTest { +public class DrillResultSetTest extends JdbcTestBase { // TODO: Move Jetty status server disabling to DrillTest. private static final String STATUS_SERVER_PROPERTY_NAME = @@ -66,8 +64,7 @@ public class DrillResultSetTest extends DrillTest { public void test_next_blocksFurtherAccessAfterEnd() throws SQLException { - Connection connection = - new Driver().connect( "jdbc:drill:zk=local", JdbcAssert.getDefaultProperties() ); + Connection connection = connect(); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery( "SELECT 1 AS x \n" + @@ -107,8 +104,7 @@ public class DrillResultSetTest extends DrillTest { public void test_next_blocksFurtherAccessWhenNoRows() throws Exception { - Connection connection = - new Driver().connect( "jdbc:drill:zk=local", JdbcAssert.getDefaultProperties() ); + Connection connection = connect(); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery( "SELECT 'Hi' AS x \n" + @@ -142,8 +138,7 @@ public class DrillResultSetTest extends DrillTest { public void test_getRow_isOneBased() throws Exception { - Connection connection = - new Driver().connect( "jdbc:drill:zk=local", JdbcAssert.getDefaultProperties() ); + Connection connection = connect(); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery( "VALUES (1), (2)" ); http://git-wip-us.apache.org/repos/asf/drill/blob/acc5ed92/exec/jdbc/src/test/java/org/apache/drill/jdbc/JdbcTestBase.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/JdbcTestBase.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/JdbcTestBase.java index 8763161..c275d00 100644 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/JdbcTestBase.java +++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/JdbcTestBase.java @@ -22,17 +22,38 @@ import static org.junit.Assert.fail; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; +import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.Properties; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; +import com.google.common.base.Function; +import com.google.common.base.Predicate; import com.google.common.base.Strings; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import org.apache.calcite.linq4j.Ord; +import org.apache.drill.common.config.DrillConfig; +import org.apache.drill.common.logical.LogicalPlan; +import org.apache.drill.common.logical.data.LogicalOperator; +import org.apache.drill.exec.ExecConstants; import org.apache.drill.exec.ExecTest; -import org.apache.drill.jdbc.test.JdbcAssert; +import org.apache.drill.exec.planner.PhysicalPlanReaderTestFactory; +import org.apache.drill.exec.util.StoragePluginTestUtils; +import org.apache.drill.jdbc.test.Hook; import org.apache.drill.categories.JdbcTest; +import org.apache.drill.test.BaseDirTestWatcher; import org.junit.AfterClass; +import org.junit.Assert; import org.junit.BeforeClass; +import org.junit.ClassRule; import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; @@ -49,6 +70,9 @@ public class JdbcTestBase extends ExecTest { @SuppressWarnings("unused") private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(JdbcTestBase.class); + @ClassRule + public static final BaseDirTestWatcher dirTestWatcher = new BaseDirTestWatcher(); + @Rule public final TestRule watcher = new TestWatcher() { @Override @@ -67,7 +91,6 @@ public class JdbcTestBase extends ExecTest { return DriverManager.getConnection(info.getUrl(), info.getParamsAsProperties()); } }); - JdbcAssert.setFactory(factory); } /** @@ -76,9 +99,12 @@ public class JdbcTestBase extends ExecTest { * @throws Exception if connection fails */ protected static Connection connect(String url) throws SQLException { - return connect(url, JdbcAssert.getDefaultProperties()); + return connect(url, getDefaultProperties()); } + protected static Connection connect() throws SQLException { + return connect("jdbc:drill:zk=local", getDefaultProperties()); + } /** * Creates a {@link java.sql.Connection connection} using the given parameters. @@ -144,6 +170,307 @@ public class JdbcTestBase extends ExecTest { } /** + * Returns default bag of properties that is passed to JDBC connection. + * By default, includes options to: + * - turn off the web server + * - indicate DrillConnectionImpl to set up dfs.tmp schema location to an exclusive dir just for this test jvm + */ + public static Properties getDefaultProperties() { + final Properties properties = new Properties(); + properties.setProperty(StoragePluginTestUtils.UNIT_TEST_PROP_PREFIX, "true"); + + properties.setProperty(StoragePluginTestUtils.UNIT_TEST_DFS_TMP_PROP, dirTestWatcher.getDfsTestTmpDir().getAbsolutePath()); + properties.setProperty(StoragePluginTestUtils.UNIT_TEST_DFS_ROOT_PROP, dirTestWatcher.getRootDir().getAbsolutePath()); + properties.setProperty(StoragePluginTestUtils.UNIT_TEST_DFS_DEFAULT_PROP, dirTestWatcher.getRootDir().getAbsolutePath()); + properties.setProperty(ExecConstants.DRILL_TMP_DIR, dirTestWatcher.getTmpDir().getAbsolutePath()); + properties.setProperty(ExecConstants.SYS_STORE_PROVIDER_LOCAL_ENABLE_WRITE, "false"); + properties.setProperty(ExecConstants.HTTP_ENABLE, "false"); + return properties; + } + + public static ModelAndSchema withModel(final String model, final String schema) { + final Properties info = getDefaultProperties(); + info.setProperty("schema", schema); + info.setProperty("model", "inline:" + model); + return new ModelAndSchema(info, factory); + } + + public static ModelAndSchema withFull(final String schema) { + final Properties info = getDefaultProperties(); + info.setProperty("schema", schema); + return new ModelAndSchema(info, factory); + } + + public static ModelAndSchema withNoDefaultSchema() { + return new ModelAndSchema(getDefaultProperties(), factory); + } + + public static String toString(ResultSet resultSet, int expectedRecordCount) throws SQLException { + final StringBuilder buf = new StringBuilder(); + while (resultSet.next()) { + final ResultSetMetaData metaData = resultSet.getMetaData(); + final int n = metaData.getColumnCount(); + String sep = ""; + for (int i = 1; i <= n; i++) { + buf.append(sep) + .append(metaData.getColumnLabel(i)) + .append("=") + .append(resultSet.getObject(i)); + sep = "; "; + } + buf.append("\n"); + } + return buf.toString(); + } + + public static String toString(ResultSet resultSet) throws SQLException { + StringBuilder buf = new StringBuilder(); + final List<Ord<String>> columns = columnLabels(resultSet); + while (resultSet.next()) { + for (Ord<String> column : columns) { + buf.append(column.i == 1 ? "" : "; ").append(column.e).append("=").append(resultSet.getObject(column.i)); + } + buf.append("\n"); + } + return buf.toString(); + } + + static Set<String> toStringSet(ResultSet resultSet) throws SQLException { + ImmutableSet.Builder<String> builder = ImmutableSet.builder(); + final List<Ord<String>> columns = columnLabels(resultSet); + while (resultSet.next()) { + StringBuilder buf = new StringBuilder(); + for (Ord<String> column : columns) { + buf.append(column.i == 1 ? "" : "; ").append(column.e).append("=").append(resultSet.getObject(column.i)); + } + builder.add(buf.toString()); + buf.setLength(0); + } + return builder.build(); + } + + static List<String> toStrings(ResultSet resultSet) throws SQLException { + final List<String> list = new ArrayList<>(); + StringBuilder buf = new StringBuilder(); + final List<Ord<String>> columns = columnLabels(resultSet); + while (resultSet.next()) { + buf.setLength(0); + for (Ord<String> column : columns) { + buf.append(column.i == 1 ? "" : "; ").append(column.e).append("=").append(resultSet.getObject(column.i)); + } + list.add(buf.toString()); + } + return list; + } + + private static List<Ord<String>> columnLabels(ResultSet resultSet) throws SQLException { + int n = resultSet.getMetaData().getColumnCount(); + List<Ord<String>> columns = new ArrayList<>(); + for (int i = 1; i <= n; i++) { + columns.add(Ord.of(i, resultSet.getMetaData().getColumnLabel(i))); + } + return columns; + } + + public static class ModelAndSchema { + private final Properties info; + private final ConnectionFactoryAdapter adapter; + + public ModelAndSchema(final Properties info, final ConnectionFactory factory) { + this.info = info; + this.adapter = new ConnectionFactoryAdapter() { + @Override + public Connection createConnection() throws SQLException { + return factory.getConnection(new ConnectionInfo("jdbc:drill:zk=local", ModelAndSchema.this.info)); + } + }; + } + + public TestDataConnection sql(String sql) { + return new TestDataConnection(adapter, sql); + } + + public <T> T withConnection(Function<Connection, T> function) throws Exception { + Connection connection = null; + try { + connection = adapter.createConnection(); + return function.apply(connection); + } finally { + if (connection != null) { + connection.close(); + } + } + } + } + + public static class TestDataConnection { + private final ConnectionFactoryAdapter adapter; + private final String sql; + + TestDataConnection(ConnectionFactoryAdapter adapter, String sql) { + this.adapter = adapter; + this.sql = sql; + } + + /** + * Checks that the current SQL statement returns the expected result. + */ + public TestDataConnection returns(String expected) throws Exception { + Connection connection = null; + Statement statement = null; + try { + connection = adapter.createConnection(); + statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery(sql); + expected = expected.trim(); + String result = JdbcTestBase.toString(resultSet).trim(); + resultSet.close(); + + if (!expected.equals(result)) { + Assert.fail(String.format("Generated string:\n%s\ndoes not match:\n%s", result, expected)); + } + return this; + } finally { + if (statement != null) { + statement.close(); + } + if (connection != null) { + connection.close(); + } + } + } + + public TestDataConnection returnsSet(Set<String> expected) throws Exception { + Connection connection = null; + Statement statement = null; + try { + connection = adapter.createConnection(); + statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery(sql); + Set<String> result = JdbcTestBase.toStringSet(resultSet); + resultSet.close(); + + if (!expected.equals(result)) { + Assert.fail(String.format("Generated set:\n%s\ndoes not match:\n%s", result, expected)); + } + return this; + } finally { + if (statement != null) { + statement.close(); + } + if (connection != null) { + connection.close(); + } + } + } + + /** + * Checks that the current SQL statement returns the expected result lines. Lines are compared unordered; the test + * succeeds if the query returns these lines in any order. + */ + public TestDataConnection returnsUnordered(String... expecteds) throws Exception { + Connection connection = null; + Statement statement = null; + try { + connection = adapter.createConnection(); + statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery(sql); + Assert.assertEquals(unsortedList(Arrays.asList(expecteds)), unsortedList(JdbcTestBase.toStrings(resultSet))); + resultSet.close(); + return this; + } finally { + if (statement != null) { + statement.close(); + } + if (connection != null) { + connection.close(); + } + } + } + + public TestDataConnection displayResults(int recordCount) throws Exception { + // record count check is done in toString method + + Connection connection = null; + Statement statement = null; + try { + connection = adapter.createConnection(); + statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery(sql); + System.out.println(JdbcTestBase.toString(resultSet, recordCount)); + resultSet.close(); + return this; + } finally { + if (statement != null) { + statement.close(); + } + if (connection != null) { + connection.close(); + } + } + } + + private SortedSet<String> unsortedList(List<String> strings) { + final SortedSet<String> set = new TreeSet<>(); + for (String string : strings) { + set.add(string + "\n"); + } + return set; + } + + public LogicalPlan logicalPlan() { + final String[] plan0 = {null}; + Connection connection = null; + Statement statement = null; + final Hook.Closeable x = Hook.LOGICAL_PLAN.add(new Function<String, Void>() { + @Override + public Void apply(String o) { + plan0[0] = o; + return null; + } + }); + try { + connection = adapter.createConnection(); + statement = connection.prepareStatement(sql); + statement.close(); + final String plan = plan0[0].trim(); + return LogicalPlan.parse(PhysicalPlanReaderTestFactory.defaultLogicalPlanPersistence(DrillConfig.create()), plan); + } catch (Exception e) { + throw new RuntimeException(e); + } finally { + if (statement != null) { + try { + statement.close(); + } catch (SQLException e) { + // ignore + } + } + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + // ignore + } + } + x.close(); + } + } + + public <T extends LogicalOperator> T planContains(final Class<T> operatorClazz) { + return (T) Iterables.find(logicalPlan().getSortedOperators(), new Predicate<LogicalOperator>() { + @Override + public boolean apply(LogicalOperator input) { + return input.getClass().equals(operatorClazz); + } + }); + } + } + + private interface ConnectionFactoryAdapter { + Connection createConnection() throws Exception; + } + + /** * Test of whether tests that get connection from JdbcTest.connect(...) * work with resetting of connections. If enabling this (failing) test method * causes other test methods to fail, something needs to be fixed. @@ -155,5 +482,4 @@ public class JdbcTestBase extends ExecTest { public void testJdbcTestConnectionResettingCompatibility() { fail("Intentional failure--did other test methods still run?"); } - } http://git-wip-us.apache.org/repos/asf/drill/blob/acc5ed92/exec/jdbc/src/test/java/org/apache/drill/jdbc/LegacyDatabaseMetaDataGetColumnsTest.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/LegacyDatabaseMetaDataGetColumnsTest.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/LegacyDatabaseMetaDataGetColumnsTest.java index 993c3e3..068fd6b 100644 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/LegacyDatabaseMetaDataGetColumnsTest.java +++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/LegacyDatabaseMetaDataGetColumnsTest.java @@ -24,7 +24,6 @@ import java.sql.SQLException; import java.sql.Types; import java.util.Properties; -import org.apache.drill.jdbc.test.JdbcAssert; import org.apache.drill.categories.JdbcTest; import org.junit.BeforeClass; import org.junit.Test; @@ -42,11 +41,10 @@ public class LegacyDatabaseMetaDataGetColumnsTest extends DatabaseMetaDataGetCol // (Note: Can't use JdbcTest's connect(...) because JdbcTest closes // Connection--and other JDBC objects--on test method failure, but this test // class uses some objects across methods.) - Properties defaultProperties = JdbcAssert.getDefaultProperties(); + Properties defaultProperties = getDefaultProperties(); defaultProperties.setProperty("server.metadata.disabled", "true"); - connection = new Driver().connect( "jdbc:drill:zk=local", - defaultProperties ); + connection = connect("jdbc:drill:zk=local", defaultProperties); dbMetadata = connection.getMetaData(); DatabaseMetaDataGetColumnsTest.setUpMetadataToCheck(); http://git-wip-us.apache.org/repos/asf/drill/blob/acc5ed92/exec/jdbc/src/test/java/org/apache/drill/jdbc/ResultSetMetaDataTest.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/ResultSetMetaDataTest.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/ResultSetMetaDataTest.java index b316b95..1ecfba6 100644 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/ResultSetMetaDataTest.java +++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/ResultSetMetaDataTest.java @@ -17,6 +17,7 @@ */ package org.apache.drill.jdbc; +import static org.apache.drill.exec.util.StoragePluginTestUtils.DFS_TMP_SCHEMA; import static org.hamcrest.CoreMatchers.anyOf; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; @@ -33,7 +34,6 @@ import java.sql.Time; import java.sql.Timestamp; import java.sql.Types; -import org.apache.drill.jdbc.test.JdbcAssert; import org.apache.drill.categories.JdbcTest; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -49,8 +49,6 @@ import org.junit.experimental.categories.Category; */ @Category(JdbcTest.class) public class ResultSetMetaDataTest extends JdbcTestBase { - - private static final String VIEW_SCHEMA = "dfs_test.tmp"; private static final String VIEW_NAME = ResultSetMetaDataTest.class.getSimpleName() + "_View"; @@ -122,14 +120,13 @@ public class ResultSetMetaDataTest extends JdbcTestBase { // (Note: Can't use JdbcTest's connect(...) because JdbcTest closes // Connection--and other JDBC objects--on test method failure, but this test // class uses some objects across methods.) - connection = new Driver().connect( "jdbc:drill:zk=local", - JdbcAssert.getDefaultProperties() ); + connection = connect("jdbc:drill:zk=local"); final Statement stmt = connection.createStatement(); ResultSet util; // Create temporary test-columns view: - util = stmt.executeQuery( "USE `" + VIEW_SCHEMA + "`" ); + util = stmt.executeQuery( "USE `" + DFS_TMP_SCHEMA + "`" ); assertTrue( util.next() ); assertTrue( "Error setting schema for test: " + util.getString( 2 ), util.getBoolean( 1 ) ); @@ -433,7 +430,7 @@ public class ResultSetMetaDataTest extends JdbcTestBase { @Test public void test_getSchemaName_forViewGetsName() throws SQLException { assertThat( rowMetadata.getSchemaName( ordOptBOOLEAN ), - anyOf( equalTo( VIEW_SCHEMA ), + anyOf( equalTo( DFS_TMP_SCHEMA ), equalTo( "" ) ) ); } http://git-wip-us.apache.org/repos/asf/drill/blob/acc5ed92/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Bug1735ConnectionCloseTest.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Bug1735ConnectionCloseTest.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Bug1735ConnectionCloseTest.java index 4ecddfc..397d2a4 100644 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Bug1735ConnectionCloseTest.java +++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Bug1735ConnectionCloseTest.java @@ -19,7 +19,7 @@ package org.apache.drill.jdbc.test; import java.sql.Connection; -import org.apache.drill.common.util.TestTools; +import org.apache.drill.test.TestTools; import org.apache.drill.exec.ExecConstants; import org.apache.drill.jdbc.Driver; import org.apache.drill.categories.JdbcTest; @@ -79,8 +79,7 @@ public class Bug1735ConnectionCloseTest extends JdbcTestQueryBase { for ( int i = 1; i <= SMALL_ITERATION_COUNT; i++ ) { logger.info( "iteration " + i + ":" ); System.out.println( "iteration " + i + ":" ); - Connection connection = new Driver().connect( "jdbc:drill:zk=local", - JdbcAssert.getDefaultProperties() ); + Connection connection = new Driver().connect("jdbc:drill:zk=local", getDefaultProperties()); connection.close(); } } @@ -100,8 +99,7 @@ public class Bug1735ConnectionCloseTest extends JdbcTestQueryBase { // (Note: Can't use JdbcTest's connect(...) because it returns connection // that doesn't really close. - Connection connection = new Driver().connect( "jdbc:drill:zk=local", - JdbcAssert.getDefaultProperties() ); + Connection connection = new Driver().connect("jdbc:drill:zk=local", getDefaultProperties()); connection.close(); } } http://git-wip-us.apache.org/repos/asf/drill/blob/acc5ed92/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Bug1735ResultSetCloseReleasesBuffersTest.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Bug1735ResultSetCloseReleasesBuffersTest.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Bug1735ResultSetCloseReleasesBuffersTest.java index 72b8dad..9449724 100644 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Bug1735ResultSetCloseReleasesBuffersTest.java +++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Bug1735ResultSetCloseReleasesBuffersTest.java @@ -67,14 +67,13 @@ public class Bug1735ResultSetCloseReleasesBuffersTest extends JdbcTestQueryBase @Test public void test() throws Exception { - JdbcAssert - .withNoDefaultSchema() + withNoDefaultSchema() .withConnection( new Function<Connection, Void>() { public Void apply( Connection connection ) { try { Statement statement = connection.createStatement(); - ResultSet resultSet = statement.executeQuery( "USE dfs_test.tmp" ); + ResultSet resultSet = statement.executeQuery( "USE dfs.tmp" ); // TODO: Purge nextUntilEnd(...) and calls when remaining fragment // race conditions are fixed (not just DRILL-2245 fixes). // resultSet.close( resultSet ); http://git-wip-us.apache.org/repos/asf/drill/blob/acc5ed92/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2128GetColumnsDataTypeNotTypeCodeIntBugsTest.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2128GetColumnsDataTypeNotTypeCodeIntBugsTest.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2128GetColumnsDataTypeNotTypeCodeIntBugsTest.java index 6d3b257..e167e4b 100644 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2128GetColumnsDataTypeNotTypeCodeIntBugsTest.java +++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2128GetColumnsDataTypeNotTypeCodeIntBugsTest.java @@ -37,7 +37,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; -import org.apache.drill.common.util.TestTools; +import org.apache.drill.test.TestTools; import org.apache.drill.jdbc.Driver; import org.apache.drill.jdbc.JdbcTestBase; http://git-wip-us.apache.org/repos/asf/drill/blob/acc5ed92/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2288GetColumnsMetadataWhenNoRowsTest.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2288GetColumnsMetadataWhenNoRowsTest.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2288GetColumnsMetadataWhenNoRowsTest.java index 83ddac8..c920c41 100644 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2288GetColumnsMetadataWhenNoRowsTest.java +++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2288GetColumnsMetadataWhenNoRowsTest.java @@ -26,9 +26,11 @@ import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; +import java.util.Properties; import org.apache.drill.jdbc.Driver; import org.apache.drill.categories.JdbcTest; +import org.apache.drill.jdbc.JdbcTestBase; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -40,16 +42,14 @@ import org.junit.experimental.categories.Category; */ @Category(JdbcTest.class) public class Drill2288GetColumnsMetadataWhenNoRowsTest { - private static Connection connection; - @BeforeClass public static void setUpConnection() throws SQLException { // (Note: Can't use JdbcTest's connect(...) because JdbcTest closes // Connection--and other JDBC objects--on test method failure, but this test // class uses some objects across methods.) - connection = new Driver().connect( "jdbc:drill:zk=local", null ); + connection = new Driver().connect( "jdbc:drill:zk=local", JdbcTestBase.getDefaultProperties()); } @AfterClass @@ -197,6 +197,4 @@ public class Drill2288GetColumnsMetadataWhenNoRowsTest { assertThat( "Unexpected non-empty results. Test rot?", false, equalTo( results.next() ) ); } - - } http://git-wip-us.apache.org/repos/asf/drill/blob/acc5ed92/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2439GetBooleanFailsSayingWrongTypeBugTest.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2439GetBooleanFailsSayingWrongTypeBugTest.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2439GetBooleanFailsSayingWrongTypeBugTest.java index e5d88d8..3fab8ce 100644 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2439GetBooleanFailsSayingWrongTypeBugTest.java +++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2439GetBooleanFailsSayingWrongTypeBugTest.java @@ -41,7 +41,7 @@ public class Drill2439GetBooleanFailsSayingWrongTypeBugTest extends JdbcTestBase @BeforeClass public static void setUpConnection() throws SQLException { - connection = new Driver().connect( "jdbc:drill:zk=local", JdbcAssert.getDefaultProperties() ); + connection = connect(); statement = connection.createStatement(); } http://git-wip-us.apache.org/repos/asf/drill/blob/acc5ed92/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2461IntervalsBreakInfoSchemaBugTest.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2461IntervalsBreakInfoSchemaBugTest.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2461IntervalsBreakInfoSchemaBugTest.java index dcf5bda..7e981f4 100644 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2461IntervalsBreakInfoSchemaBugTest.java +++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2461IntervalsBreakInfoSchemaBugTest.java @@ -56,9 +56,9 @@ public class Drill2461IntervalsBreakInfoSchemaBugTest extends JdbcTestBase { ResultSet util; // Create a view using an INTERVAL type: - util = stmt.executeQuery( "USE dfs_test.tmp" ); + util = stmt.executeQuery( "USE dfs.tmp" ); assertTrue( util.next() ); - assertTrue( "Error setting schema to dfs_test.tmp: " + util.getString( 2 ), util.getBoolean( 1 ) ); + assertTrue( "Error setting schema to dfs.tmp: " + util.getString( 2 ), util.getBoolean( 1 ) ); util = stmt.executeQuery( "CREATE OR REPLACE VIEW " + VIEW_NAME + " AS " + "\n SELECT CAST( NULL AS INTERVAL HOUR(4) TO MINUTE ) AS optINTERVAL_HM " http://git-wip-us.apache.org/repos/asf/drill/blob/acc5ed92/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2463GetNullsFailedWithAssertionsBugTest.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2463GetNullsFailedWithAssertionsBugTest.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2463GetNullsFailedWithAssertionsBugTest.java index a4b1065..66f0446 100644 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2463GetNullsFailedWithAssertionsBugTest.java +++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2463GetNullsFailedWithAssertionsBugTest.java @@ -45,7 +45,7 @@ public class Drill2463GetNullsFailedWithAssertionsBugTest extends JdbcTestBase { // (Note: Can't use JdbcTest's connect(...) because JdbcTest closes // Connection--and other JDBC objects--on test method failure, but this test // class uses some objects across methods.) - connection = new Driver().connect( "jdbc:drill:zk=local", JdbcAssert.getDefaultProperties() ); + connection = connect(); statement = connection.createStatement(); } http://git-wip-us.apache.org/repos/asf/drill/blob/acc5ed92/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2489CallsAfterCloseThrowExceptionsTest.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2489CallsAfterCloseThrowExceptionsTest.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2489CallsAfterCloseThrowExceptionsTest.java index f26b4c6..26ab7bd 100644 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2489CallsAfterCloseThrowExceptionsTest.java +++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2489CallsAfterCloseThrowExceptionsTest.java @@ -60,7 +60,7 @@ import org.apache.drill.jdbc.AlreadyClosedSqlException; * {@link Statement}, * {@link PreparedStatement}, * {@link ResultSet}, - * {@link ResultSetMetadata}, and + * {@link java.sql.ResultSetMetaData}, and * {@link DatabaseMetaData}. * </p> * <p> @@ -89,11 +89,9 @@ public class Drill2489CallsAfterCloseThrowExceptionsTest extends JdbcTestBase { // (Note: Can't use JdbcTest's connect(...) for this test class.) final Connection connToClose = - new Driver().connect("jdbc:drill:zk=local", - JdbcAssert.getDefaultProperties()); + new Driver().connect("jdbc:drill:zk=local", getDefaultProperties()); final Connection connToKeep = - new Driver().connect("jdbc:drill:zk=local", - JdbcAssert.getDefaultProperties()); + new Driver().connect("jdbc:drill:zk=local", getDefaultProperties()); final Statement plainStmtToClose = connToKeep.createStatement(); final Statement plainStmtToKeep = connToKeep.createStatement(); http://git-wip-us.apache.org/repos/asf/drill/blob/acc5ed92/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2769UnsupportedReportsUseSqlExceptionTest.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2769UnsupportedReportsUseSqlExceptionTest.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2769UnsupportedReportsUseSqlExceptionTest.java index 042c178..1a6ac40 100644 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2769UnsupportedReportsUseSqlExceptionTest.java +++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/Drill2769UnsupportedReportsUseSqlExceptionTest.java @@ -34,9 +34,8 @@ import java.sql.Statement; import java.util.ArrayList; import java.util.List; -import org.apache.drill.common.util.TestTools; +import org.apache.drill.test.TestTools; import org.apache.drill.jdbc.AlreadyClosedSqlException; -import org.apache.drill.jdbc.Driver; import org.apache.drill.jdbc.JdbcTestBase; import org.apache.drill.categories.JdbcTest; import org.junit.AfterClass; @@ -84,9 +83,7 @@ public class Drill2769UnsupportedReportsUseSqlExceptionTest extends JdbcTestBase @BeforeClass public static void setUpObjects() throws Exception { // (Note: Can't use JdbcTest's connect(...) for this test class.) - - connection = new Driver().connect("jdbc:drill:zk=local", - JdbcAssert.getDefaultProperties()); + connection = connect(); plainStatement = connection.createStatement(); preparedStatement = http://git-wip-us.apache.org/repos/asf/drill/blob/acc5ed92/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcAssert.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcAssert.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcAssert.java deleted file mode 100644 index da66ac1..0000000 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcAssert.java +++ /dev/null @@ -1,361 +0,0 @@ -/* - * 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.drill.jdbc.test; - -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Properties; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.apache.calcite.linq4j.Ord; -import org.apache.drill.common.config.DrillConfig; -import org.apache.drill.common.logical.LogicalPlan; -import org.apache.drill.common.logical.data.LogicalOperator; -import org.apache.drill.exec.ExecConstants; -import org.apache.drill.exec.planner.PhysicalPlanReaderTestFactory; -import org.apache.drill.jdbc.ConnectionFactory; -import org.apache.drill.jdbc.ConnectionInfo; -import org.junit.Assert; - -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSet.Builder; -import com.google.common.collect.Iterables; - -/** - * Fluent interface for writing JDBC and query-planning tests. - */ -public class JdbcAssert { - - private static ConnectionFactory factory = null; - - public static void setFactory(ConnectionFactory factory) { - JdbcAssert.factory = factory; - } - - /** - * Returns default bag of properties that is passed to JDBC connection. - * By default, includes options to: - * - turn off the web server - * - indicate DrillConnectionImpl to set up dfs_test.tmp schema location to an exclusive dir just for this test jvm - */ - public static Properties getDefaultProperties() { - final Properties properties = new Properties(); - properties.setProperty("drillJDBCUnitTests", "true"); - - // Must set this to false to ensure that the tests ignore any existing - // plugin configurations stored in /tmp/drill. - - properties.setProperty(ExecConstants.SYS_STORE_PROVIDER_LOCAL_ENABLE_WRITE, "false"); - properties.setProperty(ExecConstants.HTTP_ENABLE, "false"); - return properties; - } - - public static ModelAndSchema withModel(final String model, final String schema) { - final Properties info = getDefaultProperties(); - info.setProperty("schema", schema); - info.setProperty("model", "inline:" + model); - return new ModelAndSchema(info, factory); - } - - public static ModelAndSchema withFull(final String schema) { - final Properties info = getDefaultProperties(); - info.setProperty("schema", schema); - return new ModelAndSchema(info, factory); - } - - public static ModelAndSchema withNoDefaultSchema() { - return new ModelAndSchema(getDefaultProperties(), factory); - } - - static String toString(ResultSet resultSet, int expectedRecordCount) throws SQLException { - final StringBuilder buf = new StringBuilder(); - while (resultSet.next()) { - final ResultSetMetaData metaData = resultSet.getMetaData(); - final int n = metaData.getColumnCount(); - String sep = ""; - for (int i = 1; i <= n; i++) { - buf.append(sep) - .append(metaData.getColumnLabel(i)) - .append("=") - .append(resultSet.getObject(i)); - sep = "; "; - } - buf.append("\n"); - } - return buf.toString(); - } - - static String toString(ResultSet resultSet) throws SQLException { - StringBuilder buf = new StringBuilder(); - final List<Ord<String>> columns = columnLabels(resultSet); - while (resultSet.next()) { - for (Ord<String> column : columns) { - buf.append(column.i == 1 ? "" : "; ").append(column.e).append("=").append(resultSet.getObject(column.i)); - } - buf.append("\n"); - } - return buf.toString(); - } - - static Set<String> toStringSet(ResultSet resultSet) throws SQLException { - Builder<String> builder = ImmutableSet.builder(); - final List<Ord<String>> columns = columnLabels(resultSet); - while (resultSet.next()) { - StringBuilder buf = new StringBuilder(); - for (Ord<String> column : columns) { - buf.append(column.i == 1 ? "" : "; ").append(column.e).append("=").append(resultSet.getObject(column.i)); - } - builder.add(buf.toString()); - buf.setLength(0); - } - return builder.build(); - } - - static List<String> toStrings(ResultSet resultSet) throws SQLException { - final List<String> list = new ArrayList<>(); - StringBuilder buf = new StringBuilder(); - final List<Ord<String>> columns = columnLabels(resultSet); - while (resultSet.next()) { - buf.setLength(0); - for (Ord<String> column : columns) { - buf.append(column.i == 1 ? "" : "; ").append(column.e).append("=").append(resultSet.getObject(column.i)); - } - list.add(buf.toString()); - } - return list; - } - - private static List<Ord<String>> columnLabels(ResultSet resultSet) throws SQLException { - int n = resultSet.getMetaData().getColumnCount(); - List<Ord<String>> columns = new ArrayList<>(); - for (int i = 1; i <= n; i++) { - columns.add(Ord.of(i, resultSet.getMetaData().getColumnLabel(i))); - } - return columns; - } - - public static class ModelAndSchema { - private final Properties info; - private final ConnectionFactoryAdapter adapter; - - public ModelAndSchema(final Properties info, final ConnectionFactory factory) { - this.info = info; - this.adapter = new ConnectionFactoryAdapter() { - @Override - public Connection createConnection() throws SQLException { - return factory.getConnection(new ConnectionInfo("jdbc:drill:zk=local", ModelAndSchema.this.info)); - } - }; - } - - public TestDataConnection sql(String sql) { - return new TestDataConnection(adapter, sql); - } - - public <T> T withConnection(Function<Connection, T> function) throws Exception { - Connection connection = null; - try { - connection = adapter.createConnection(); - return function.apply(connection); - } finally { - if (connection != null) { - connection.close(); - } - } - } - } - - public static class TestDataConnection { - private final ConnectionFactoryAdapter adapter; - private final String sql; - - TestDataConnection(ConnectionFactoryAdapter adapter, String sql) { - this.adapter = adapter; - this.sql = sql; - } - - /** - * Checks that the current SQL statement returns the expected result. - */ - public TestDataConnection returns(String expected) throws Exception { - Connection connection = null; - Statement statement = null; - try { - connection = adapter.createConnection(); - statement = connection.createStatement(); - ResultSet resultSet = statement.executeQuery(sql); - expected = expected.trim(); - String result = JdbcAssert.toString(resultSet).trim(); - resultSet.close(); - - if (!expected.equals(result)) { - Assert.fail(String.format("Generated string:\n%s\ndoes not match:\n%s", result, expected)); - } - return this; - } finally { - if (statement != null) { - statement.close(); - } - if (connection != null) { - connection.close(); - } - } - } - - public TestDataConnection returnsSet(Set<String> expected) throws Exception { - Connection connection = null; - Statement statement = null; - try { - connection = adapter.createConnection(); - statement = connection.createStatement(); - ResultSet resultSet = statement.executeQuery(sql); - Set<String> result = JdbcAssert.toStringSet(resultSet); - resultSet.close(); - - if (!expected.equals(result)) { - Assert.fail(String.format("Generated set:\n%s\ndoes not match:\n%s", result, expected)); - } - return this; - } finally { - if (statement != null) { - statement.close(); - } - if (connection != null) { - connection.close(); - } - } - } - - /** - * Checks that the current SQL statement returns the expected result lines. Lines are compared unordered; the test - * succeeds if the query returns these lines in any order. - */ - public TestDataConnection returnsUnordered(String... expecteds) throws Exception { - Connection connection = null; - Statement statement = null; - try { - connection = adapter.createConnection(); - statement = connection.createStatement(); - ResultSet resultSet = statement.executeQuery(sql); - Assert.assertEquals(unsortedList(Arrays.asList(expecteds)), unsortedList(JdbcAssert.toStrings(resultSet))); - resultSet.close(); - return this; - } finally { - if (statement != null) { - statement.close(); - } - if (connection != null) { - connection.close(); - } - } - } - - public TestDataConnection displayResults(int recordCount) throws Exception { - // record count check is done in toString method - - Connection connection = null; - Statement statement = null; - try { - connection = adapter.createConnection(); - statement = connection.createStatement(); - ResultSet resultSet = statement.executeQuery(sql); - System.out.println(JdbcAssert.toString(resultSet, recordCount)); - resultSet.close(); - return this; - } finally { - if (statement != null) { - statement.close(); - } - if (connection != null) { - connection.close(); - } - } - } - - private SortedSet<String> unsortedList(List<String> strings) { - final SortedSet<String> set = new TreeSet<>(); - for (String string : strings) { - set.add(string + "\n"); - } - return set; - } - - public LogicalPlan logicalPlan() { - final String[] plan0 = {null}; - Connection connection = null; - Statement statement = null; - final Hook.Closeable x = Hook.LOGICAL_PLAN.add(new Function<String, Void>() { - @Override - public Void apply(String o) { - plan0[0] = o; - return null; - } - }); - try { - connection = adapter.createConnection(); - statement = connection.prepareStatement(sql); - statement.close(); - final String plan = plan0[0].trim(); - return LogicalPlan.parse(PhysicalPlanReaderTestFactory.defaultLogicalPlanPersistence(DrillConfig.create()), plan); - } catch (Exception e) { - throw new RuntimeException(e); - } finally { - if (statement != null) { - try { - statement.close(); - } catch (SQLException e) { - // ignore - } - } - if (connection != null) { - try { - connection.close(); - } catch (SQLException e) { - // ignore - } - } - x.close(); - } - } - - public <T extends LogicalOperator> T planContains(final Class<T> operatorClazz) { - return (T) Iterables.find(logicalPlan().getSortedOperators(), new Predicate<LogicalOperator>() { - @Override - public boolean apply(LogicalOperator input) { - return input.getClass().equals(operatorClazz); - } - }); - } - } - - private static interface ConnectionFactoryAdapter { - Connection createConnection() throws Exception; - } -} - -// End JdbcAssert.java http://git-wip-us.apache.org/repos/asf/drill/blob/acc5ed92/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcConnectTriesTestEmbeddedBits.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcConnectTriesTestEmbeddedBits.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcConnectTriesTestEmbeddedBits.java index 44b2e22..d7edd1e 100644 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcConnectTriesTestEmbeddedBits.java +++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcConnectTriesTestEmbeddedBits.java @@ -53,7 +53,7 @@ public class JdbcConnectTriesTestEmbeddedBits extends JdbcTestBase { Connection connection = null; try { connection = testDrillDriver.connect("jdbc:drill:drillbit=127.0.0.1:5000,127.0.0.1:5001;" + "tries=2", - JdbcAssert.getDefaultProperties()); + getDefaultProperties()); fail(); } catch (SQLException ex) { assertNull(connection); @@ -67,7 +67,7 @@ public class JdbcConnectTriesTestEmbeddedBits extends JdbcTestBase { Connection connection = null; try { connection = testDrillDriver.connect("jdbc:drill:drillbit=127.0.0.1:5000,127.0.0.1:5001;tries=5", - JdbcAssert.getDefaultProperties()); + getDefaultProperties()); fail(); } catch (SQLException ex) { assertNull(connection); @@ -81,7 +81,7 @@ public class JdbcConnectTriesTestEmbeddedBits extends JdbcTestBase { Connection connection = null; try { connection = testDrillDriver.connect("jdbc:drill:drillbit=127.0.0.1:5000,127.0.0.1:5001;tries=1", - JdbcAssert.getDefaultProperties()); + getDefaultProperties()); fail(); } catch (SQLException ex) { assertNull(connection); @@ -95,7 +95,7 @@ public class JdbcConnectTriesTestEmbeddedBits extends JdbcTestBase { Connection connection = null; try { connection = testDrillDriver.connect("jdbc:drill:drillbit=127.0.0.1:5000,127.0.0.1:5001;tries=abc", - JdbcAssert.getDefaultProperties()); + getDefaultProperties()); fail(); } catch (SQLException ex) { assertNull(connection); @@ -108,7 +108,7 @@ public class JdbcConnectTriesTestEmbeddedBits extends JdbcTestBase { Connection connection = null; try { connection = testDrillDriver.connect("jdbc:drill:drillbit=127.0.0.1:5000,127.0.0.1:5001;tries=0", - JdbcAssert.getDefaultProperties()); + getDefaultProperties()); fail(); } catch (SQLException ex) { assertNull(connection); @@ -122,7 +122,7 @@ public class JdbcConnectTriesTestEmbeddedBits extends JdbcTestBase { Connection connection = null; try { connection = testDrillDriver.connect("jdbc:drill:drillbit=127.0.0.1:5000,127.0.0.1:5001;tries=-5", - JdbcAssert.getDefaultProperties()); + getDefaultProperties()); fail(); } catch (SQLException ex) { assertNull(connection); @@ -133,21 +133,21 @@ public class JdbcConnectTriesTestEmbeddedBits extends JdbcTestBase { @Test public void testZKSuccessfulConnectionZeroConnectTries() throws SQLException { - Connection connection = testDrillDriver.connect("jdbc:drill:zk=local;tries=0", JdbcAssert.getDefaultProperties()); + Connection connection = testDrillDriver.connect("jdbc:drill:zk=local;tries=0", getDefaultProperties()); assertNotNull(connection); connection.close(); } @Test public void testZKSuccessfulConnectionNegativeConnectTries() throws SQLException { - Connection connection = testDrillDriver.connect("jdbc:drill:zk=local;tries=-1", JdbcAssert.getDefaultProperties()); + Connection connection = testDrillDriver.connect("jdbc:drill:zk=local;tries=-1", getDefaultProperties()); assertNotNull(connection); connection.close(); } @Test public void testZKSuccessfulConnectionGreaterThanConnectTries() throws SQLException { - Connection connection = testDrillDriver.connect("jdbc:drill:zk=local;tries=7", JdbcAssert.getDefaultProperties()); + Connection connection = testDrillDriver.connect("jdbc:drill:zk=local;tries=7", getDefaultProperties()); assertNotNull(connection); connection.close(); } @@ -156,7 +156,7 @@ public class JdbcConnectTriesTestEmbeddedBits extends JdbcTestBase { public void testZKConnectionInvalidConnectTries() throws SQLException { Connection connection = null; try { - connection = testDrillDriver.connect("jdbc:drill:zk=local;tries=abc", JdbcAssert.getDefaultProperties()); + connection = testDrillDriver.connect("jdbc:drill:zk=local;tries=abc", getDefaultProperties()); fail(); } catch (SQLException ex) { assertNull(connection); http://git-wip-us.apache.org/repos/asf/drill/blob/acc5ed92/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcDataTest.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcDataTest.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcDataTest.java index ad532cf..e4d97af 100644 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcDataTest.java +++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/JdbcDataTest.java @@ -40,7 +40,6 @@ import org.apache.drill.common.logical.data.Scan; import org.apache.drill.common.logical.data.Store; import org.apache.drill.common.logical.data.Union; import org.apache.drill.jdbc.JdbcTestBase; -import org.apache.drill.jdbc.test.JdbcAssert.TestDataConnection; import org.apache.drill.categories.JdbcTest; import org.junit.Assert; import org.junit.BeforeClass; @@ -112,7 +111,7 @@ public class JdbcDataTest extends JdbcTestBase { /** Load driver, make a connection, prepare a statement. */ @Test public void testPrepare() throws Exception { - JdbcAssert.withModel(MODEL, "DONUTS").withConnection(new Function<Connection, Void>() { + withModel(MODEL, "DONUTS").withConnection(new Function<Connection, Void>() { @Override public Void apply(Connection connection) { try { @@ -129,14 +128,13 @@ public class JdbcDataTest extends JdbcTestBase { /** Simple query against JSON. */ @Test public void testSelectJson() throws Exception { - JdbcAssert.withModel(MODEL, "DONUTS").sql("select * from donuts").returns(EXPECTED); + withModel(MODEL, "DONUTS").sql("select * from donuts").returns(EXPECTED); } /** Simple query against EMP table in HR database. */ @Test public void testSelectEmployees() throws Exception { - JdbcAssert - .withModel(MODEL, "HR") + withModel(MODEL, "HR") .sql("select * from employees") .returns( "_MAP={deptId=31, lastName=Rafferty}\n" + "_MAP={deptId=33, lastName=Jones}\n" @@ -147,8 +145,7 @@ public class JdbcDataTest extends JdbcTestBase { /** Simple query against EMP table in HR database. */ @Test public void testSelectEmpView() throws Exception { - JdbcAssert - .withModel(MODEL, "HR") + withModel(MODEL, "HR") .sql("select * from emp") .returns( "DEPTID=31; LASTNAME=Rafferty\n" + "DEPTID=33; LASTNAME=Jones\n" + "DEPTID=33; LASTNAME=Steinberg\n" @@ -158,8 +155,7 @@ public class JdbcDataTest extends JdbcTestBase { /** Simple query against EMP table in HR database. */ @Test public void testSelectDept() throws Exception { - JdbcAssert - .withModel(MODEL, "HR") + withModel(MODEL, "HR") .sql("select * from departments") .returns( "_MAP={deptId=31, name=Sales}\n" + "_MAP={deptId=33, name=Engineering}\n" @@ -169,29 +165,28 @@ public class JdbcDataTest extends JdbcTestBase { /** Query with project list. No field references yet. */ @Test public void testProjectConstant() throws Exception { - JdbcAssert.withModel(MODEL, "DONUTS").sql("select 1 + 3 as c from donuts") + withModel(MODEL, "DONUTS").sql("select 1 + 3 as c from donuts") .returns("C=4\n" + "C=4\n" + "C=4\n" + "C=4\n" + "C=4\n"); } /** Query that projects an element from the map. */ @Test public void testProject() throws Exception { - JdbcAssert.withModel(MODEL, "DONUTS").sql("select _MAP['ppu'] as ppu from donuts") + withModel(MODEL, "DONUTS").sql("select _MAP['ppu'] as ppu from donuts") .returns("PPU=0.55\n" + "PPU=0.69\n" + "PPU=0.55\n" + "PPU=0.69\n" + "PPU=1.0\n"); } /** Same logic as {@link #testProject()}, but using a subquery. */ @Test public void testProjectOnSubquery() throws Exception { - JdbcAssert.withModel(MODEL, "DONUTS").sql("select d['ppu'] as ppu from (\n" + " select _MAP as d from donuts)") + withModel(MODEL, "DONUTS").sql("select d['ppu'] as ppu from (\n" + " select _MAP as d from donuts)") .returns("PPU=0.55\n" + "PPU=0.69\n" + "PPU=0.55\n" + "PPU=0.69\n" + "PPU=1.0\n"); } /** Checks the logical plan. */ @Test public void testProjectPlan() throws Exception { - LogicalPlan plan = JdbcAssert - .withModel(MODEL, "DONUTS") + LogicalPlan plan = withModel(MODEL, "DONUTS") .sql("select _MAP['ppu'] as ppu from donuts") .logicalPlan(); @@ -221,8 +216,7 @@ public class JdbcDataTest extends JdbcTestBase { */ @Test public void testProjectFilterSubquery() throws Exception { - JdbcAssert - .withModel(MODEL, "DONUTS") + withModel(MODEL, "DONUTS") .sql( "select d['name'] as name, d['xx'] as xx from (\n" + " select _MAP as d from donuts)\n" + "where cast(d['ppu'] as double) > 0.6") @@ -244,8 +238,7 @@ public class JdbcDataTest extends JdbcTestBase { @Test public void testProjectFilterSubqueryPlan() throws Exception { - LogicalPlan plan = JdbcAssert - .withModel(MODEL, "DONUTS") + LogicalPlan plan = withModel(MODEL, "DONUTS") .sql( "select d['name'] as name, d['xx'] as xx from (\n" + " select _MAP['donuts'] as d from donuts)\n" + "where cast(d['ppu'] as double) > 0.6") @@ -279,74 +272,34 @@ public class JdbcDataTest extends JdbcTestBase { /** Query that projects one field. (Disabled; uses sugared syntax.) */ @Test @Ignore public void testProjectNestedFieldSugared() throws Exception { - JdbcAssert.withModel(MODEL, "DONUTS").sql("select donuts.ppu from donuts") + withModel(MODEL, "DONUTS").sql("select donuts.ppu from donuts") .returns("C=4\n" + "C=4\n" + "C=4\n" + "C=4\n" + "C=4\n"); } /** Query with filter. No field references yet. */ @Test public void testFilterConstantFalse() throws Exception { - JdbcAssert.withModel(MODEL, "DONUTS").sql("select * from donuts where 3 > 4").returns(""); + withModel(MODEL, "DONUTS").sql("select * from donuts where 3 > 4").returns(""); } @Test public void testFilterConstant() throws Exception { - JdbcAssert.withModel(MODEL, "DONUTS").sql("select * from donuts where 3 < 4").returns(EXPECTED); + withModel(MODEL, "DONUTS").sql("select * from donuts where 3 < 4").returns(EXPECTED); } @Ignore @Test public void testValues() throws Exception { - JdbcAssert.withModel(MODEL, "DONUTS").sql("values (1)").returns("EXPR$0=1\n"); + withModel(MODEL, "DONUTS").sql("values (1)").returns("EXPR$0=1\n"); // Enable when https://issues.apache.org/jira/browse/DRILL-57 fixed // .planContains("store"); } -// @Test -// public void testDistinct() throws Exception { -// JdbcAssert.withModel(MODEL, "HR").sql("select distinct deptId from emp") -// .returnsUnordered("DEPTID=null", "DEPTID=31", "DEPTID=34", "DEPTID=33") -// .planContains(CollapsingAggregate.class); -// } -// -// @Test -// public void testCountNoGroupBy() throws Exception { -// // 5 out of 6 employees have a not-null deptId -// JdbcAssert.withModel(MODEL, "HR").sql("select count(deptId) as cd, count(*) as c from emp").returns("CD=5; C=6\n") -// .planContains(CollapsingAggregate.class); -// } -// -// @Test -// public void testDistinctCountNoGroupBy() throws Exception { -// JdbcAssert.withModel(MODEL, "HR").sql("select count(distinct deptId) as c from emp").returns("C=3\n") -// .planContains(CollapsingAggregate.class); -// } -// -// @Test -// public void testDistinctCountGroupByEmpty() throws Exception { -// JdbcAssert.withModel(MODEL, "HR").sql("select count(distinct deptId) as c from emp group by ()").returns("C=3\n") -// .planContains(CollapsingAggregate.class); -// } -// -// @Test -// public void testCountNull() throws Exception { -// JdbcAssert.withModel(MODEL, "HR").sql("select count(distinct deptId) as c from emp group by ()").returns("C=3\n") -// .planContains(CollapsingAggregate.class); -// } -// -// @Test -// public void testCount() throws Exception { -// JdbcAssert.withModel(MODEL, "HR").sql("select deptId, count(*) as c from emp group by deptId") -// .returnsUnordered("DEPTID=31; C=1", "DEPTID=33; C=2", "DEPTID=34; C=2", "DEPTID=null; C=1") -// .planContains(CollapsingAggregate.class); // make sure using drill -// } - @Test public void testJoin() throws Exception { - Join join = JdbcAssert - .withModel(MODEL, "HR") + Join join = withModel(MODEL, "HR") .sql("select * from emp join dept on emp.deptId = dept.deptId") .returnsUnordered("DEPTID=31; LASTNAME=Rafferty; DEPTID0=31; NAME=Sales", "DEPTID=33; LASTNAME=Jones; DEPTID0=33; NAME=Engineering", @@ -358,8 +311,7 @@ public class JdbcDataTest extends JdbcTestBase { @Test public void testLeftJoin() throws Exception { - Join join = JdbcAssert - .withModel(MODEL, "HR") + Join join = withModel(MODEL, "HR") .sql("select * from emp left join dept on emp.deptId = dept.deptId") .returnsUnordered("DEPTID=31; LASTNAME=Rafferty; DEPTID0=31; NAME=Sales", "DEPTID=33; LASTNAME=Jones; DEPTID0=33; NAME=Engineering", @@ -375,15 +327,14 @@ public class JdbcDataTest extends JdbcTestBase { */ @Test @Ignore public void testRightJoin() throws Exception { - Join join = JdbcAssert.withModel(MODEL, "HR").sql("select * from emp right join dept on emp.deptId = dept.deptId") + Join join = withModel(MODEL, "HR").sql("select * from emp right join dept on emp.deptId = dept.deptId") .returnsUnordered("xx").planContains(Join.class); Assert.assertEquals(JoinRelType.LEFT, join.getJoinType()); } @Test public void testFullJoin() throws Exception { - Join join = JdbcAssert - .withModel(MODEL, "HR") + Join join = withModel(MODEL, "HR") .sql("select * from emp full join dept on emp.deptId = dept.deptId") .returnsUnordered("DEPTID=31; LASTNAME=Rafferty; DEPTID0=31; NAME=Sales", "DEPTID=33; LASTNAME=Jones; DEPTID0=33; NAME=Engineering", @@ -401,8 +352,7 @@ public class JdbcDataTest extends JdbcTestBase { */ @Test public void testJoinOnSubquery() throws Exception { - Join join = JdbcAssert - .withModel(MODEL, "HR") + Join join = withModel(MODEL, "HR") .sql( "select * from (\n" + "select deptId, lastname, 'x' as name from emp) as e\n" + " join dept on e.deptId = dept.deptId") @@ -417,8 +367,7 @@ public class JdbcDataTest extends JdbcTestBase { /** Tests that one of the FoodMart tables is present. */ @Test @Ignore public void testFoodMart() throws Exception { - JdbcAssert - .withModel(MODEL, "FOODMART") + withModel(MODEL, "FOODMART") .sql("select * from product_class where cast(_map['product_class_id'] as integer) < 3") .returnsUnordered( "_MAP={product_category=Seafood, product_class_id=2, product_department=Seafood, product_family=Food, product_subcategory=Shellfish}", @@ -427,25 +376,26 @@ public class JdbcDataTest extends JdbcTestBase { @Test public void testUnionAll() throws Exception { - Union union = JdbcAssert.withModel(MODEL, "HR").sql("select deptId from dept\n" + "union all\n" + "select deptId from emp") - .returnsUnordered("DEPTID=31", "DEPTID=33", "DEPTID=34", "DEPTID=35", "DEPTID=null") - .planContains(Union.class); + Union union = withModel(MODEL, "HR") + .sql("select deptId from dept\n" + "union all\n" + "select deptId from emp") + .returnsUnordered("DEPTID=31", "DEPTID=33", "DEPTID=34", "DEPTID=35", "DEPTID=null") + .planContains(Union.class); Assert.assertFalse(union.isDistinct()); } @Test public void testUnion() throws Exception { - Union union = JdbcAssert.withModel(MODEL, "HR").sql("select deptId from dept\n" + "union\n" + "select deptId from emp") - .returnsUnordered("DEPTID=31", "DEPTID=33", "DEPTID=34", "DEPTID=35", "DEPTID=null") - .planContains(Union.class); + Union union = withModel(MODEL, "HR") + .sql("select deptId from dept\n" + "union\n" + "select deptId from emp") + .returnsUnordered("DEPTID=31", "DEPTID=33", "DEPTID=34", "DEPTID=35", "DEPTID=null") + .planContains(Union.class); Assert.assertTrue(union.isDistinct()); } @Test public void testOrderByDescNullsFirst() throws Exception { // desc nulls last - JdbcAssert - .withModel(MODEL, "HR") + withModel(MODEL, "HR") .sql("select * from emp order by deptId desc nulls first") .returns( "DEPTID=null; LASTNAME=John\n" + "DEPTID=34; LASTNAME=Robinson\n" + "DEPTID=34; LASTNAME=Smith\n" @@ -456,8 +406,7 @@ public class JdbcDataTest extends JdbcTestBase { @Test public void testOrderByDescNullsLast() throws Exception { // desc nulls first - JdbcAssert - .withModel(MODEL, "HR") + withModel(MODEL, "HR") .sql("select * from emp order by deptId desc nulls last") .returns( "DEPTID=34; LASTNAME=Robinson\n" + "DEPTID=34; LASTNAME=Smith\n" + "DEPTID=33; LASTNAME=Jones\n" @@ -469,8 +418,7 @@ public class JdbcDataTest extends JdbcTestBase { public void testOrderByDesc() throws Exception { // desc is implicitly "nulls first" (i.e. null sorted as +inf) // Current behavior is to sort nulls last. This is wrong. - JdbcAssert - .withModel(MODEL, "HR") + withModel(MODEL, "HR") .sql("select * from emp order by deptId desc") .returns( "DEPTID=null; LASTNAME=John\n" + "DEPTID=34; LASTNAME=Robinson\n" + "DEPTID=34; LASTNAME=Smith\n" @@ -481,8 +429,7 @@ public class JdbcDataTest extends JdbcTestBase { @Test public void testOrderBy() throws Exception { // no sort order specified is implicitly "asc", and asc is "nulls last" - JdbcAssert - .withModel(MODEL, "HR") + withModel(MODEL, "HR") .sql("select * from emp order by deptId") .returns( "DEPTID=31; LASTNAME=Rafferty\n" @@ -496,8 +443,7 @@ public class JdbcDataTest extends JdbcTestBase { @Test public void testLimit() throws Exception { - JdbcAssert - .withModel(MODEL, "HR") + withModel(MODEL, "HR") .sql("select LASTNAME from emp limit 2") .returns("LASTNAME=Rafferty\n" + "LASTNAME=Jones") @@ -507,8 +453,7 @@ public class JdbcDataTest extends JdbcTestBase { @Test public void testLimitOrderBy() throws Exception { - TestDataConnection tdc = JdbcAssert - .withModel(MODEL, "HR") + TestDataConnection tdc = withModel(MODEL, "HR") .sql("select LASTNAME from emp order by LASTNAME limit 2") .returns("LASTNAME=John\n" + "LASTNAME=Jones"); @@ -519,8 +464,7 @@ public class JdbcDataTest extends JdbcTestBase { @Test public void testOrderByWithOffset() throws Exception { - JdbcAssert - .withModel(MODEL, "HR") + withModel(MODEL, "HR") .sql("select LASTNAME from emp order by LASTNAME asc offset 3") .returns("LASTNAME=Robinson\n" + "LASTNAME=Smith\n" + @@ -531,13 +475,10 @@ public class JdbcDataTest extends JdbcTestBase { @Test public void testOrderByWithOffsetAndFetch() throws Exception { - JdbcAssert - .withModel(MODEL, "HR") + withModel(MODEL, "HR") .sql("select LASTNAME from emp order by LASTNAME asc offset 3 fetch next 2 rows only") .returns("LASTNAME=Robinson\n" + "LASTNAME=Smith") .planContains(Limit.class); } } - -// End JdbcTest.java