|
@@ -17,10 +17,14 @@
|
|
|
*/
|
|
|
package org.apache.hadoop.util;
|
|
|
|
|
|
+import static org.apache.hadoop.util.RunJar.MATCH_ANY;
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
import static org.junit.Assert.assertFalse;
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
+import static org.mockito.Matchers.any;
|
|
|
import static org.mockito.Mockito.spy;
|
|
|
+import static org.mockito.Mockito.times;
|
|
|
+import static org.mockito.Mockito.verify;
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
|
import java.io.File;
|
|
@@ -99,7 +103,7 @@ public class TestRunJar {
|
|
|
|
|
|
// Unjar everything
|
|
|
RunJar.unJar(new File(TEST_ROOT_DIR, TEST_JAR_NAME),
|
|
|
- unjarDir);
|
|
|
+ unjarDir, MATCH_ANY);
|
|
|
assertTrue("foobar unpacked",
|
|
|
new File(unjarDir, TestRunJar.FOOBAR_TXT).exists());
|
|
|
assertTrue("foobaz unpacked",
|
|
@@ -177,7 +181,7 @@ public class TestRunJar {
|
|
|
|
|
|
// Unjar everything
|
|
|
RunJar.unJar(new File(TEST_ROOT_DIR, TEST_JAR_NAME),
|
|
|
- unjarDir);
|
|
|
+ unjarDir, MATCH_ANY);
|
|
|
|
|
|
String failureMessage = "Last modify time was lost during unJar";
|
|
|
assertEquals(failureMessage, MOCKED_NOW, new File(unjarDir, TestRunJar.FOOBAR_TXT).lastModified());
|
|
@@ -221,5 +225,34 @@ public class TestRunJar {
|
|
|
// run RunJar
|
|
|
runJar.run(args);
|
|
|
// it should not throw an exception
|
|
|
+ verify(runJar, times(1)).unJar(any(File.class), any(File.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testClientClassLoaderSkipUnjar() throws Throwable {
|
|
|
+ RunJar runJar = spy(new RunJar());
|
|
|
+ // enable the client classloader
|
|
|
+ when(runJar.useClientClassLoader()).thenReturn(true);
|
|
|
+ // set the system classes and blacklist the test main class and the test
|
|
|
+ // third class so they can be loaded by the application classloader
|
|
|
+ String mainCls = ClassLoaderCheckMain.class.getName();
|
|
|
+ String thirdCls = ClassLoaderCheckThird.class.getName();
|
|
|
+ String systemClasses = "-" + mainCls + "," +
|
|
|
+ "-" + thirdCls + "," +
|
|
|
+ ApplicationClassLoader.SYSTEM_CLASSES_DEFAULT;
|
|
|
+ when(runJar.getSystemClasses()).thenReturn(systemClasses);
|
|
|
+
|
|
|
+ // create the test jar
|
|
|
+ File testJar = JarFinder.makeClassLoaderTestJar(this.getClass(),
|
|
|
+ TEST_ROOT_DIR, TEST_JAR_2_NAME, BUFF_SIZE, mainCls, thirdCls);
|
|
|
+ // form the args
|
|
|
+ String[] args = new String[3];
|
|
|
+ args[0] = testJar.getAbsolutePath();
|
|
|
+ args[1] = mainCls;
|
|
|
+ when(runJar.skipUnjar()).thenReturn(true);
|
|
|
+ // run RunJar
|
|
|
+ runJar.run(args);
|
|
|
+ // it should not throw an exception
|
|
|
+ verify(runJar, times(0)).unJar(any(File.class), any(File.class));
|
|
|
}
|
|
|
}
|