You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hawq.apache.org by nh...@apache.org on 2015/11/24 00:27:04 UTC
incubator-hawq git commit: HAWQ-120. Descriptive error message if the
PXF plugin used has the old package name
Repository: incubator-hawq
Updated Branches:
refs/heads/master 2058ea5b4 -> e2511afde
HAWQ-120. Descriptive error message if the PXF plugin used has the old package name
Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/e2511afd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/e2511afd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/e2511afd
Branch: refs/heads/master
Commit: e2511afde81e69d241f435d98011d42eb3e8321f
Parents: 2058ea5
Author: Noa Horn <nh...@pivotal.io>
Authored: Mon Nov 23 15:20:11 2015 -0800
Committer: Noa Horn <nh...@pivotal.io>
Committed: Mon Nov 23 15:20:11 2015 -0800
----------------------------------------------------------------------
.../hawq/pxf/service/utilities/Utilities.java | 21 ++++++++++-
.../pxf/service/utilities/UtilitiesTest.java | 37 ++++++++++++++++----
2 files changed, 51 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e2511afd/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/Utilities.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/Utilities.java b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/Utilities.java
index b29a863..139c309 100644
--- a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/Utilities.java
+++ b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/utilities/Utilities.java
@@ -30,8 +30,27 @@ public class Utilities {
public static Object createAnyInstance(Class<?> confClass,
String className, InputData metaData)
throws Exception {
- Class<?> cls = Class.forName(className);
+
+ Class<?> cls = null;
+ try {
+ cls = Class.forName(className);
+ } catch (ClassNotFoundException e) {
+ // in case the class name uses the old "com.pivotal.pxf" package
+ // name, recommend using the new package "org.apache.hawq.pxf".
+ if (className.startsWith("com.pivotal.pxf")) {
+ throw new Exception(
+ "Class "
+ + className
+ + " doesn't not appear in classpath. "
+ + "Plugins provided by PXF must start with \"org.apache.hawq.pxf\"",
+ e.getCause());
+ } else {
+ throw e;
+ }
+ }
+
Constructor<?> con = cls.getConstructor(confClass);
+
return instantiate(con, metaData);
}
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e2511afd/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/utilities/UtilitiesTest.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/utilities/UtilitiesTest.java b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/utilities/UtilitiesTest.java
index 8b1c9b6..a8a4a47 100644
--- a/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/utilities/UtilitiesTest.java
+++ b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/utilities/UtilitiesTest.java
@@ -1,17 +1,20 @@
package org.apache.hawq.pxf.service.utilities;
-import org.apache.hadoop.security.UserGroupInformation;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.hawq.pxf.api.utilities.InputData;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-
@RunWith(PowerMockRunner.class)
-@PrepareForTest({UserGroupInformation.class})
+@PrepareForTest({Class.class})
public class UtilitiesTest {
@Test
public void byteArrayToOctalStringNull() throws Exception {
@@ -45,4 +48,26 @@ public class UtilitiesTest {
assertEquals(orig.length() + (octal.length() * 5), sb.length());
assertEquals(expected, sb.toString());
}
+
+ @Test
+ public void createAnyInstanceOldPackageName() throws Exception {
+
+ InputData metaData = mock(InputData.class);
+ String className = "com.pivotal.pxf.Lucy";
+ ClassNotFoundException exception = new ClassNotFoundException(className);
+ PowerMockito.mockStatic(Class.class);
+ when(Class.forName(className)).thenThrow(exception);
+
+ try {
+ Utilities.createAnyInstance(InputData.class,
+ className, metaData);
+ fail("creating an instance should fail because the class doesn't exist in classpath");
+ } catch (Exception e) {
+ assertEquals(e.getClass(), Exception.class);
+ assertEquals(
+ e.getMessage(),
+ "Class " + className + " doesn't not appear in classpath. "
+ + "Plugins provided by PXF must start with \"org.apache.hawq.pxf\"");
+ }
+ }
}