sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject sqoop git commit: SQOOP-3218: Make sure the original ClassLoader is restored when running HCatalog tests
Date Fri, 11 Aug 2017 15:42:16 GMT
Repository: sqoop
Updated Branches:
  refs/heads/trunk ba058ac33 -> 92e2f9992


SQOOP-3218: Make sure the original ClassLoader is restored when running HCatalog tests

(Szabolcs Vasas via Boglarka Egyed)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/92e2f999
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/92e2f999
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/92e2f999

Branch: refs/heads/trunk
Commit: 92e2f999263c0c54b07ab1cde70a0606b277365c
Parents: ba058ac
Author: Boglarka Egyed <bogi@apache.org>
Authored: Fri Aug 11 17:39:38 2017 +0200
Committer: Boglarka Egyed <bogi@apache.org>
Committed: Fri Aug 11 17:39:38 2017 +0200

----------------------------------------------------------------------
 .../mapreduce/hcat/SqoopHCatUtilities.java      |  4 +-
 .../mapreduce/hcat/TestSqoopHCatUtilities.java  | 65 ++++++++++++++++++++
 2 files changed, 68 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/92e2f999/src/java/org/apache/sqoop/mapreduce/hcat/SqoopHCatUtilities.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/sqoop/mapreduce/hcat/SqoopHCatUtilities.java b/src/java/org/apache/sqoop/mapreduce/hcat/SqoopHCatUtilities.java
index 2101b06..2a1de7f 100644
--- a/src/java/org/apache/sqoop/mapreduce/hcat/SqoopHCatUtilities.java
+++ b/src/java/org/apache/sqoop/mapreduce/hcat/SqoopHCatUtilities.java
@@ -1197,8 +1197,9 @@ public final class SqoopHCatUtilities {
     }
   }
 
-  public void executeHCatProgramInProcess(String[] argv) throws IOException {
+  void executeHCatProgramInProcess(String[] argv) throws IOException {
     SubprocessSecurityManager subprocessSM = null;
+    final ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
 
     try {
       Class<?> cliDriverClass = Class.forName(HCAT_CLI_MAIN_CLASS);
@@ -1229,6 +1230,7 @@ public final class SqoopHCatUtilities {
       if (null != subprocessSM) {
         subprocessSM.uninstall();
       }
+      Thread.currentThread().setContextClassLoader(originalClassLoader);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/92e2f999/src/test/org/apache/sqoop/mapreduce/hcat/TestSqoopHCatUtilities.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/mapreduce/hcat/TestSqoopHCatUtilities.java b/src/test/org/apache/sqoop/mapreduce/hcat/TestSqoopHCatUtilities.java
new file mode 100644
index 0000000..dff11f1
--- /dev/null
+++ b/src/test/org/apache/sqoop/mapreduce/hcat/TestSqoopHCatUtilities.java
@@ -0,0 +1,65 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.sqoop.mapreduce.hcat;
+
+import static java.lang.Thread.currentThread;
+import static org.junit.Assert.assertSame;
+
+import java.io.IOException;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestSqoopHCatUtilities {
+
+  private static final String[] VALID_HCAT_ARGS = new String[] {"-h"};
+  private static final String[] INVALID_HCAT_ARGS = new String[] {};
+
+  private SqoopHCatUtilities sqoopHCatUtilities;
+  private ClassLoader originalClassLoader;
+
+  @Before
+  public void before() {
+    sqoopHCatUtilities = SqoopHCatUtilities.instance();
+    originalClassLoader = currentThread().getContextClassLoader();
+  }
+
+  @Test
+  public void testOriginalClassLoaderIsRestoredWhenHCatCliIsInvokedWithValidArguments() throws
IOException {
+    sqoopHCatUtilities.executeHCatProgramInProcess(VALID_HCAT_ARGS);
+
+    assertSame(originalClassLoader, currentThread().getContextClassLoader());
+  }
+
+  @Test
+  public void testOriginalClassLoaderIsRestoredWhenHCatCliIsInvokedWithInvalidArguments()
{
+    try {
+      sqoopHCatUtilities.executeHCatProgramInProcess(INVALID_HCAT_ARGS);
+    } catch (IOException e) {
+      // Exception is swallowed because we test the classloader value only.
+    }
+
+    assertSame(originalClassLoader, currentThread().getContextClassLoader());
+  }
+
+  @Test(expected = IOException.class)
+  public void testExecuteHCatProgramInProcessThrowsWithInvalidArguments() throws IOException
{
+    sqoopHCatUtilities.executeHCatProgramInProcess(INVALID_HCAT_ARGS);
+  }
+}
\ No newline at end of file


Mime
View raw message