You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by ar...@apache.org on 2019/08/27 10:18:27 UTC
[drill] 06/06: DRILL-7353: Wrong driver class is written to the
java.sql.Driver
This is an automated email from the ASF dual-hosted git repository.
arina pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/drill.git
commit 31a41995c3f708894cc77bad3b27ce72203c423c
Author: Anton Gozhiy <an...@gmail.com>
AuthorDate: Mon Aug 19 20:33:14 2019 +0300
DRILL-7353: Wrong driver class is written to the java.sql.Driver
closes #1845
---
exec/jdbc-all/pom.xml | 16 +++++++++++++
.../org/apache/drill/jdbc/ITTestShadedJar.java | 28 ++++++++++++++++++----
2 files changed, 39 insertions(+), 5 deletions(-)
diff --git a/exec/jdbc-all/pom.xml b/exec/jdbc-all/pom.xml
index 2dab193..13234fd 100644
--- a/exec/jdbc-all/pom.xml
+++ b/exec/jdbc-all/pom.xml
@@ -496,6 +496,14 @@
<exclude>webapps/**</exclude>
</excludes>
</filter>
+ <!-- This file is used to automatically load given jdbc driver without calling Class.forName().
+ Excluding the Avatica service file which is conflicting with the Drill one. -->
+ <filter>
+ <artifact>org.apache.calcite.avatica:*</artifact>
+ <excludes>
+ <exclude>META-INF/services/java.sql.Driver</exclude>
+ </excludes>
+ </filter>
</filters>
</configuration>
</plugin>
@@ -799,6 +807,14 @@
<exclude>webapps/**</exclude>
</excludes>
</filter>
+ <!-- This file is used to automatically load given jdbc driver without calling Class.forName().
+ Excluding the Avatica service file which is conflicting with the Drill one. -->
+ <filter>
+ <artifact>org.apache.calcite.avatica:*</artifact>
+ <excludes>
+ <exclude>META-INF/services/java.sql.Driver</exclude>
+ </excludes>
+ </filter>
</filters>
</configuration>
</plugin>
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 4fed146..c343037 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
@@ -17,9 +17,16 @@
*/
package org.apache.drill.jdbc;
-import static org.junit.Assert.assertEquals;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
+import java.io.BufferedReader;
import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
@@ -32,11 +39,10 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import java.util.concurrent.Semaphore;
+import java.util.stream.Collectors;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.rules.TestWatcher;
-import org.junit.runner.Description;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
public class ITTestShadedJar {
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ITTestShadedJar.class);
@@ -166,6 +172,18 @@ public class ITTestShadedJar {
}
+ @Test
+ public void serviceFileContainsCorrectDriver() throws IOException {
+ URLClassLoader loader = URLClassLoader.newInstance(new URL[]{getJdbcUrl()});
+ try (InputStream resourceStream = loader.getResourceAsStream("META-INF/services/java.sql.Driver")) {
+ assertNotNull("java.sql.Driver is not present in the jdbc jar", resourceStream);
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(resourceStream))) {
+ String driverClass = reader.lines().collect(Collectors.joining(System.lineSeparator()));
+ assertEquals("org.apache.drill.jdbc.Driver", driverClass);
+ }
+ }
+ }
+
private static void printQuery(Connection c, String query) throws SQLException {
final StringBuilder sb = new StringBuilder();