From 2f5612594967c6fe0f6c533090c8f6448c32ce49 Mon Sep 17 00:00:00 2001 From: Paul Rogers Date: Fri, 2 Dec 2016 14:02:03 -0800 Subject: [PATCH] DRILL-5091: JDBC unit test fails to set up test storage plugin config on Java 8 Fixes the two issues described in DRILL-5091: * Missing test config parameter * Handle new Java 8 JDBC functions Cleans up compiler warnings seen in Eclipse. Added TODO's based on code reviews --- .../apache/drill/exec/server/Drillbit.java | 2 +- .../exec/store/StoragePluginRegistryImpl.java | 8 +++ .../exec/store/sys/PersistentStoreConfig.java | 2 +- .../store/sys/store/LocalPersistentStore.java | 17 ++--- .../CachingPersistentStoreProvider.java | 3 +- .../LocalPersistentStoreProvider.java | 8 +-- .../org/apache/drill/jdbc/JdbcTestBase.java | 7 +- ...489CallsAfterCloseThrowExceptionsTest.java | 71 ++++++++++++------- ...UnsupportedReportsUseSqlExceptionTest.java | 66 ++++++++++------- .../apache/drill/jdbc/test/JdbcAssert.java | 8 ++- 10 files changed, 119 insertions(+), 73 deletions(-) diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/Drillbit.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/Drillbit.java index 3f74268bc23..a28dc9146df 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/Drillbit.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/Drillbit.java @@ -101,7 +101,7 @@ public Drillbit( storeProvider = new CachingPersistentStoreProvider(new LocalPersistentStoreProvider(config)); } else { coord = new ZKClusterCoordinator(config); - storeProvider = new PersistentStoreRegistry(this.coord, config).newPStoreProvider(); + storeProvider = new PersistentStoreRegistry(this.coord, config).newPStoreProvider(); isDistributedMode = true; } diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistryImpl.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistryImpl.java index ad3858671d0..bf4affdb812 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistryImpl.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistryImpl.java @@ -115,10 +115,12 @@ public StoragePlugin load(StoragePluginConfig config) throws Exception { }); } + @Override public PersistentStore getStore() { return pluginSystemTable; } + @Override public void init() throws DrillbitStartupException { availablePlugins = findAvailablePlugins(classpathScan); @@ -188,6 +190,7 @@ public void addPlugin(String name, StoragePlugin plugin) { plugins.put(name, plugin); } + @Override public void deletePlugin(String name) { StoragePlugin plugin = plugins.remove(name); closePlugin(plugin); @@ -206,6 +209,7 @@ private void closePlugin(StoragePlugin plugin) { } } + @Override public StoragePlugin createOrUpdate(String name, StoragePluginConfig config, boolean persist) throws ExecutionSetupException { for (;;) { @@ -243,6 +247,7 @@ public StoragePlugin createOrUpdate(String name, StoragePluginConfig config, boo } } + @Override public StoragePlugin getPlugin(String name) throws ExecutionSetupException { StoragePlugin plugin = plugins.get(name); if (name.equals(SYS_PLUGIN) || name.equals(INFORMATION_SCHEMA_PLUGIN)) { @@ -267,6 +272,7 @@ public StoragePlugin getPlugin(String name) throws ExecutionSetupException { } + @Override public StoragePlugin getPlugin(StoragePluginConfig config) throws ExecutionSetupException { if (config instanceof NamedStoragePluginConfig) { return getPlugin(((NamedStoragePluginConfig) config).name); @@ -293,6 +299,7 @@ public StoragePlugin getPlugin(StoragePluginConfig config) throws ExecutionSetup } } + @Override public FormatPlugin getFormatPlugin(StoragePluginConfig storageConfig, FormatPluginConfig formatConfig) throws ExecutionSetupException { StoragePlugin p = getPlugin(storageConfig); @@ -332,6 +339,7 @@ public Iterator> iterator() { return plugins.iterator(); } + @Override public SchemaFactory getSchemaFactory() { return schemaFactory; } diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/PersistentStoreConfig.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/PersistentStoreConfig.java index ca319f202c3..00a75a2f98e 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/PersistentStoreConfig.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/PersistentStoreConfig.java @@ -65,7 +65,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { if (obj instanceof PersistentStoreConfig) { - final PersistentStoreConfig other = PersistentStoreConfig.class.cast(obj); + final PersistentStoreConfig other = PersistentStoreConfig.class.cast(obj); return Objects.equal(name, other.name) && Objects.equal(valueSerializer, other.valueSerializer) && Objects.equal(mode, other.mode); diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/store/LocalPersistentStore.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/store/LocalPersistentStore.java index 1ef8d126c0c..b9a4b59eaab 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/store/LocalPersistentStore.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/store/LocalPersistentStore.java @@ -31,27 +31,25 @@ import javax.annotation.Nullable; -import com.google.common.base.Function; -import com.google.common.base.Preconditions; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import org.apache.commons.io.IOUtils; import org.apache.drill.common.collections.ImmutableEntry; import org.apache.drill.common.config.DrillConfig; import org.apache.drill.exec.store.dfs.DrillFileSystem; import org.apache.drill.exec.store.sys.BasePersistentStore; -import org.apache.drill.exec.store.sys.PersistentStore; import org.apache.drill.exec.store.sys.PersistentStoreConfig; import org.apache.drill.exec.store.sys.PersistentStoreMode; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import com.google.common.base.Function; +import com.google.common.base.Preconditions; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; public class LocalPersistentStore extends BasePersistentStore { - private static final Logger logger = LoggerFactory.getLogger(LocalPersistentStore.class); +// private static final Logger logger = LoggerFactory.getLogger(LocalPersistentStore.class); private final Path basePath; private final PersistentStoreConfig config; @@ -140,6 +138,7 @@ private Path makePath(String name) { return path; } + @Override public V get(String key) { try{ Path path = makePath(key); @@ -158,6 +157,7 @@ public V get(String key) { } } + @Override public void put(String key, V value) { try (OutputStream os = fs.create(makePath(key))) { IOUtils.write(config.getSerializer().serialize(value), os); @@ -181,6 +181,7 @@ public boolean putIfAbsent(String key, V value) { } } + @Override public void delete(String key) { try { fs.delete(makePath(key), false); diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/store/provider/CachingPersistentStoreProvider.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/store/provider/CachingPersistentStoreProvider.java index 99ccc8eeea2..771005f48d1 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/store/provider/CachingPersistentStoreProvider.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/store/provider/CachingPersistentStoreProvider.java @@ -29,7 +29,7 @@ import org.apache.drill.exec.store.sys.PersistentStoreProvider; public class CachingPersistentStoreProvider extends BasePersistentStoreProvider { - private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(CachingPersistentStoreProvider.class); +// private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(CachingPersistentStoreProvider.class); private final ConcurrentMap, PersistentStore> storeCache = Maps.newConcurrentMap(); private final PersistentStoreProvider provider; @@ -38,6 +38,7 @@ public CachingPersistentStoreProvider(PersistentStoreProvider provider) { this.provider = provider; } + @Override @SuppressWarnings("unchecked") public PersistentStore getOrCreateStore(final PersistentStoreConfig config) throws StoreException { final PersistentStore store = storeCache.get(config); diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/store/provider/LocalPersistentStoreProvider.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/store/provider/LocalPersistentStoreProvider.java index 9bf18ab553b..0b4a20128f1 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/store/provider/LocalPersistentStoreProvider.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/store/provider/LocalPersistentStoreProvider.java @@ -23,20 +23,18 @@ import org.apache.drill.exec.ExecConstants; import org.apache.drill.exec.exception.StoreException; import org.apache.drill.exec.store.dfs.DrillFileSystem; -import org.apache.drill.exec.store.sys.PersistentStoreRegistry; import org.apache.drill.exec.store.sys.PersistentStore; import org.apache.drill.exec.store.sys.PersistentStoreConfig; +import org.apache.drill.exec.store.sys.PersistentStoreRegistry; import org.apache.drill.exec.store.sys.store.LocalPersistentStore; import org.apache.drill.exec.testing.store.NoWriteLocalStore; import org.apache.hadoop.fs.Path; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * A really simple provider that stores data in the local file system, one value per file. */ public class LocalPersistentStoreProvider extends BasePersistentStoreProvider { - private static final Logger logger = LoggerFactory.getLogger(LocalPersistentStoreProvider.class); +// private static final Logger logger = LoggerFactory.getLogger(LocalPersistentStoreProvider.class); private final Path path; private final DrillFileSystem fs; @@ -44,7 +42,7 @@ public class LocalPersistentStoreProvider extends BasePersistentStoreProvider { // how to handle this flag. private final boolean enableWrite; - public LocalPersistentStoreProvider(final PersistentStoreRegistry registry) throws StoreException { + public LocalPersistentStoreProvider(final PersistentStoreRegistry registry) throws StoreException { this(registry.getConfig()); } 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 7fb601d6972..b9e83927d3d 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 @@ -114,7 +114,8 @@ protected static void changeSchemaIfSupplied(Connection conn, Properties info) { protected static void changeSchema(Connection conn, String schema) { final String query = String.format("use %s", schema); - try ( Statement s = conn.createStatement() ) { + try (Statement s = conn.createStatement()) { + @SuppressWarnings("unused") ResultSet r = s.executeQuery(query); // TODO: Purge nextUntilEnd(...) and calls when remaining fragment // race conditions are fixed (not just DRILL-2245 fixes). @@ -147,10 +148,10 @@ public static void tearDownTestCase() throws Exception { * (Note: Not a guaranteed test--depends on order in which test methods are * run.) */ - @Ignore( "Usually disabled; enable temporarily to check tests" ) + @Ignore("Usually disabled; enable temporarily to check tests") @Test public void testJdbcTestConnectionResettingCompatibility() { - fail( "Intentional failure--did other test methods still run?" ); + fail("Intentional failure--did other test methods still run?"); } } 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 ee94fd2433c..b8a7895fdb8 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 @@ -38,6 +38,7 @@ import java.sql.ResultSetMetaData; import java.sql.SQLClientInfoException; import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; import java.sql.Statement; import java.sql.Struct; import java.util.ArrayList; @@ -81,7 +82,6 @@ public class Drill2489CallsAfterCloseThrowExceptionsTest extends JdbcTestBase { private static ResultSetMetaData resultSetMetaDataOfClosedStmt; private static DatabaseMetaData databaseMetaDataOfClosedConn; - @BeforeClass public static void setUpClosedObjects() throws Exception { // (Note: Can't use JdbcTest's connect(...) for this test class.) @@ -135,15 +135,14 @@ public static void setUpClosedObjects() throws Exception { resultSetMetaDataOfClosedStmt = rsmdForClosedStmt; databaseMetaDataOfClosedConn = dbmd; - // Self-check that member variables are set (and objects are in right open // or closed state): - assertTrue( "Test setup error", closedConn.isClosed()); + assertTrue("Test setup error", closedConn.isClosed()); assertFalse("Test setup error", openConn.isClosed()); - assertTrue( "Test setup error", closedPlainStmtOfOpenConn.isClosed()); - assertTrue( "Test setup error", closedPreparedStmtOfOpenConn.isClosed()); - assertTrue( "Test setup error", closedResultSetOfClosedStmt.isClosed()); - assertTrue( "Test setup error", closedResultSetOfOpenStmt.isClosed()); + assertTrue("Test setup error", closedPlainStmtOfOpenConn.isClosed()); + assertTrue("Test setup error", closedPreparedStmtOfOpenConn.isClosed()); + assertTrue("Test setup error", closedResultSetOfClosedStmt.isClosed()); + assertTrue("Test setup error", closedResultSetOfOpenStmt.isClosed()); // (No ResultSetMetaData.isClosed() or DatabaseMetaData.isClosed():) assertNotNull("Test setup error", resultSetMetaDataOfClosedResultSet); assertNotNull("Test setup error", resultSetMetaDataOfClosedStmt); @@ -155,7 +154,6 @@ public static void tearDownConnection() throws Exception { openConn.close(); } - /////////////////////////////////////////////////////////////// // 1. Check that isClosed() and close() do not throw, and isClosed() returns // true. @@ -200,12 +198,10 @@ public void testClosedResultSet_isClosed_returnsTrue() throws SQLException { assertThat(closedResultSetOfOpenStmt.isClosed(), equalTo(true)); } - /////////////////////////////////////////////////////////////// // 2. Check that all methods throw or not appropriately (either as specified // by JDBC or currently intended as partial Avatica workaround). - /** * Reflection-based checker of throwing of "already closed" exception by JDBC * interfaces' implementation methods. @@ -405,17 +401,14 @@ public String getReport() { + ")"; return report; } - } // class ThrowsClosedChecker - private static class ClosedConnectionChecker extends ThrowsClosedBulkChecker { private static final String STATEMENT_CLOSED_MESSAGE = "Connection is already closed."; - ClosedConnectionChecker(Class intf, Connection jdbcObject) { super(intf, jdbcObject, STATEMENT_CLOSED_MESSAGE); } @@ -449,7 +442,6 @@ else if (RuntimeException.class == cause.getClass() } return result; } - } // class ClosedConnectionChecker @Test @@ -465,7 +457,6 @@ public void testClosedConnectionMethodsThrowRight() { } } - private static class ClosedPlainStatementChecker extends ThrowsClosedBulkChecker { @@ -476,12 +467,25 @@ private static class ClosedPlainStatementChecker super(intf, jdbcObject, PLAIN_STATEMENT_CLOSED_MESSAGE); } + @Override + protected boolean isOkayNonthrowingMethod(Method method) { + // TODO: Java 8 method + if ("getLargeUpdateCount".equals(method.getName())) { + return true; } + return super.isOkayNonthrowingMethod(method); + } + @Override protected boolean isOkaySpecialCaseException(Method method, Throwable cause) { final boolean result; if (super.isOkaySpecialCaseException(method, cause)) { result = true; } + else if ( method.getName().equals("executeLargeBatch") + || method.getName().equals("executeLargeUpdate")) { + // TODO: New Java 8 methods not implemented in Avatica. + result = true; + } else if (RuntimeException.class == cause.getClass() && normalClosedExceptionText.equals(cause.getMessage()) && (false @@ -489,6 +493,7 @@ else if (RuntimeException.class == cause.getClass() || method.getName().equals("getFetchDirection") || method.getName().equals("getFetchSize") || method.getName().equals("getMaxRows") + || method.getName().equals("getLargeMaxRows") // TODO: Java 8 )) { // Special good-enough case--we had to use RuntimeException for now. result = true; @@ -498,7 +503,6 @@ else if (RuntimeException.class == cause.getClass() } return result; } - } // class ClosedPlainStatementChecker @Test @@ -513,7 +517,6 @@ public void testClosedPlainStatementMethodsThrowRight() { } } - private static class ClosedPreparedStatementChecker extends ThrowsClosedBulkChecker { @@ -525,6 +528,15 @@ private static class ClosedPreparedStatementChecker super(intf, jdbcObject, PREPAREDSTATEMENT_CLOSED_MESSAGE); } + @Override + protected boolean isOkayNonthrowingMethod(Method method) { + // TODO: Java 8 methods not yet supported by Avatica. + if (method.getName().equals("getLargeUpdateCount")) { + return true; + } + return super.isOkayNonthrowingMethod(method); + } + @Override protected boolean isOkaySpecialCaseException(Method method, Throwable cause) { final boolean result; @@ -543,12 +555,19 @@ else if (RuntimeException.class == cause.getClass() // Special good-enough case--we had to use RuntimeException for now. result = true; } + else if ( method.getName().equals("setObject") + || method.getName().equals("executeLargeUpdate") + || method.getName().equals("executeLargeBatch") + || method.getName().equals("getLargeMaxRows") + ) { + // TODO: Java 8 methods not yet supported by Avatica. + result = true; + } else { result = false; } return result; } - } // class closedPreparedStmtOfOpenConnChecker @Test @@ -564,7 +583,6 @@ public void testclosedPreparedStmtOfOpenConnMethodsThrowRight() { } } - private static class ClosedResultSetChecker extends ThrowsClosedBulkChecker { @@ -587,12 +605,16 @@ else if (RuntimeException.class == cause.getClass() // Special good-enough case--we had to use RuntimeException for now. result = true; } + else if (SQLFeatureNotSupportedException.class == cause.getClass() + && (method.getName().equals("updateObject"))) { + // TODO: Java 8 methods not yet supported by Avatica. + result = true; + } else { result = false; } return result; } - } // class ClosedResultSetChecker @Test @@ -630,7 +652,6 @@ private static class ClosedResultSetMetaDataChecker ResultSetMetaData jdbcObject) { super(intf, jdbcObject, RESULTSETMETADATA_CLOSED_MESSAGE); } - } // class ClosedResultSetMetaDataChecker @Test @@ -671,12 +692,16 @@ private static class ClosedDatabaseMetaDataChecker super(intf, jdbcObject, DATABASEMETADATA_CLOSED_MESSAGE); } + @Override protected boolean isOkayNonthrowingMethod(Method method) { return super.isOkayNonthrowingMethod(method) || method.getName().equals("getDriverMajorVersion") || method.getName().equals("getDriverMinorVersion") - || method.getName().equals("getConnection"); + || method.getName().equals("getConnection") + // TODO: New Java 8 methods not implemented in Avatica. + || method.getName().equals("getMaxLogicalLobSize") + || method.getName().equals("supportsRefCursors"); } @Override @@ -696,7 +721,6 @@ else if (RuntimeException.class == cause.getClass() } return result; } - } // class ClosedDatabaseMetaDataChecker @@ -712,5 +736,4 @@ public void testClosedDatabaseMetaDataMethodsThrowRight() { fail("Already-closed exception error(s): \n" + checker.getReport()); } } - } 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 8bc03aac872..1de737a2dd2 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 @@ -17,38 +17,33 @@ */ package org.apache.drill.jdbc.test; -import static org.junit.Assert.*; -import static org.hamcrest.CoreMatchers.*; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestRule; -import org.slf4j.Logger; - +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; import static org.slf4j.LoggerFactory.getLogger; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.sql.Array; -import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; -import java.sql.SQLClientInfoException; import java.sql.SQLException; import java.sql.Statement; -import java.sql.Struct; import java.util.ArrayList; import java.util.List; import org.apache.drill.common.util.TestTools; +import org.apache.drill.jdbc.AlreadyClosedSqlException; import org.apache.drill.jdbc.Driver; import org.apache.drill.jdbc.JdbcTestBase; -import org.apache.drill.jdbc.AlreadyClosedSqlException; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestRule; +import org.slf4j.Logger; /** @@ -84,7 +79,6 @@ public class Drill2769UnsupportedReportsUseSqlExceptionTest extends JdbcTestBase private static ResultSetMetaData resultSetMetaData; private static DatabaseMetaData databaseMetaData; - @BeforeClass public static void setUpObjects() throws Exception { // (Note: Can't use JdbcTest's connect(...) for this test class.) @@ -117,7 +111,6 @@ public static void setUpObjects() throws Exception { resultSetMetaData = resultSet.getMetaData(); databaseMetaData = connection.getMetaData(); - // Self-check that member variables are set: assertFalse("Test setup error", connection.isClosed()); assertFalse("Test setup error", plainStatement.isClosed()); @@ -133,7 +126,6 @@ public static void tearDownConnection() throws Exception { connection.close(); } - /** * Reflection-based checker that exceptions thrown by JDBC interfaces' * implementation methods for unsupported-operation cases are SQLExceptions @@ -148,7 +140,6 @@ private static class NoNonSqlExceptionsChecker { private final StringBuilder failureLinesBuf = new StringBuilder(); private final StringBuilder successLinesBuf = new StringBuilder(); - NoNonSqlExceptionsChecker(final Class jdbcIntf, final INTF jdbcObject) { this.jdbcIntf = jdbcIntf; @@ -280,6 +271,10 @@ else if (NullPointerException.class == cause.getClass() // code implements them. successLinesBuf.append(resultLine); } + else if (isOkaySpecialCaseException(method, cause)) { + successLinesBuf.append(resultLine); + } + else { final String badResultLine = "- " + methodLabel + " threw <" + cause + "> instead" @@ -319,6 +314,15 @@ else if (DatabaseMetaData.class == jdbcIntf } } + /** + * Reports whether it's okay if given method throw given exception (that is + * not preferred AlreadyClosedException with regular message). + */ + protected boolean isOkaySpecialCaseException(Method method, + Throwable cause) { + return false; + } + public boolean hadAnyFailures() { return 0 != failureLinesBuf.length(); } @@ -340,10 +344,8 @@ public String getReport() { + ")"; return report; } - } // class NoNonSqlExceptionsChecker - @Test public void testConnectionMethodsThrowRight() { NoNonSqlExceptionsChecker checker = @@ -357,7 +359,6 @@ public void testConnectionMethodsThrowRight() { } } - private static class PlainStatementChecker extends NoNonSqlExceptionsChecker { @@ -368,10 +369,18 @@ private static class PlainStatementChecker this.factoryConnection = factoryConnection; } + @Override protected Statement getJdbcObject() throws SQLException { return factoryConnection.createStatement(); } + @Override + protected boolean isOkaySpecialCaseException(Method method, + Throwable cause) { + // New Java 8 method not supported by Avatica + + return method.getName().equals( "executeLargeBatch" ); + } } // class PlainStatementChecker @Test @@ -386,7 +395,6 @@ public void testPlainStatementMethodsThrowRight() { } } - private static class PreparedStatementChecker extends NoNonSqlExceptionsChecker { @@ -397,10 +405,18 @@ private static class PreparedStatementChecker this.factoryConnection = factoryConnection; } + @Override protected PreparedStatement getJdbcObject() throws SQLException { return factoryConnection.prepareStatement("VALUES 1"); } + @Override + protected boolean isOkaySpecialCaseException(Method method, + Throwable cause) { + // New Java 8 method not supported by Avatica + + return method.getName().equals( "executeLargeBatch" ); + } } // class PlainStatementChecker @Test @@ -415,7 +431,6 @@ public void testPreparedStatementMethodsThrowRight() { } } - @Test public void testResultSetMethodsThrowRight() { NoNonSqlExceptionsChecker checker = @@ -428,7 +443,6 @@ public void testResultSetMethodsThrowRight() { } } - @Test public void testResultSetMetaDataMethodsThrowRight() { NoNonSqlExceptionsChecker checker = @@ -442,7 +456,6 @@ public void testResultSetMetaDataMethodsThrowRight() { } } - @Test public void testDatabaseMetaDataMethodsThrowRight() { NoNonSqlExceptionsChecker checker = @@ -455,5 +468,4 @@ public void testDatabaseMetaDataMethodsThrowRight() { fail("Non-SQLException exception error(s): \n" + checker.getReport()); } } - } 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 index 3f8514e45f3..caa09b81c20 100644 --- 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 @@ -66,6 +66,11 @@ public static void setFactory(ConnectionFactory factory) { 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; } @@ -246,7 +251,6 @@ public TestDataConnection returnsSet(Set expected) throws Exception { } } - /** * 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. @@ -291,7 +295,6 @@ public TestDataConnection displayResults(int recordCount) throws Exception { connection.close(); } } - } private SortedSet unsortedList(List strings) { @@ -353,7 +356,6 @@ public boolean apply(LogicalOperator input) { private static interface ConnectionFactoryAdapter { Connection createConnection() throws Exception; } - } // End JdbcAssert.java