STORM-3873: Remove junit4 dependency (#3488)
* STORM-3873: Remove junit4 dependency
* STORM-3877: use unittest pkg for mock
Co-authored-by: snikhil5 <nik@nik.com>
diff --git a/DEPENDENCY-LICENSES b/DEPENDENCY-LICENSES
index f991a7f..54c6819 100644
--- a/DEPENDENCY-LICENSES
+++ b/DEPENDENCY-LICENSES
@@ -563,7 +563,6 @@
* ASM Core (asm:asm:3.1 - http://asm.objectweb.org/asm/)
* ASM Tree (asm:asm-tree:3.1 - http://asm.objectweb.org/asm-tree/)
* Commons Compiler (org.codehaus.janino:commons-compiler:2.7.6 - http://docs.codehaus.org/display/JANINO/Home/commons-compiler)
- * Hamcrest Core (org.hamcrest:hamcrest-core:1.3 - https://github.com/hamcrest/JavaHamcrest/hamcrest-core)
* Janino (org.codehaus.janino:janino:2.7.6 - http://docs.codehaus.org/display/JANINO/Home/janino)
* JPMML evaluator (org.jpmml:pmml-evaluator:1.0.22 - http://www.jpmml.org/pmml-evaluator)
* JPMML manager (org.jpmml:pmml-manager:1.0.22 - http://www.jpmml.org/pmml-manager)
@@ -602,10 +601,6 @@
* Stax2 API (org.codehaus.woodstox:stax2-api:3.1.4 - http://wiki.fasterxml.com/WoodstoxStax2)
* xmlenc Library (xmlenc:xmlenc:0.52 - http://xmlenc.sourceforge.net)
- BSD style
-
- * Hamcrest Core (org.hamcrest:hamcrest-core:1.1 - no url defined)
-
CC0 1.0 Universal
* JSR166e (com.twitter:jsr166e:1.1.0 - http://github.com/twitter/jsr166e)
@@ -660,7 +655,6 @@
* Aether Utilities (org.eclipse.aether:aether-util:0.9.0.M2 - http://www.eclipse.org/aether/aether-util/)
* clojure (org.clojure:clojure:1.10.0 - http://clojure.org/)
* core.specs.alpha (org.clojure:core.specs.alpha:0.2.44 - https://github.com/clojure/build.poms/core.specs.alpha)
- * JUnit (junit:junit:4.12 - http://junit.org)
* org.eclipse.sisu.inject (org.eclipse.sisu:org.eclipse.sisu.inject:0.3.3 - http://www.eclipse.org/sisu/org.eclipse.sisu.inject/)
* org.eclipse.sisu.plexus (org.eclipse.sisu:org.eclipse.sisu.plexus:0.3.3 - http://www.eclipse.org/sisu/org.eclipse.sisu.plexus/)
* spec.alpha (org.clojure:spec.alpha:0.2.176 - https://github.com/clojure/build.poms/spec.alpha)
diff --git a/external/storm-hdfs-blobstore/pom.xml b/external/storm-hdfs-blobstore/pom.xml
index f61257d..586d194 100644
--- a/external/storm-hdfs-blobstore/pom.xml
+++ b/external/storm-hdfs-blobstore/pom.xml
@@ -30,8 +30,6 @@
<properties>
<!-- Required downgrade by hadoop-hdfs 2.8.5 -->
<guava.version>16.0.1</guava.version>
- <!-- Required downgrade by hadoop-hdfs 2.8.5 (org.apache.hadoop.test.GenericTestUtils.getTestDir)-->
- <junit.version>4.12</junit.version>
</properties>
<developers>
@@ -215,11 +213,6 @@
<version>${guava.version}</version>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>${junit.version}</version>
- </dependency>
- <dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
diff --git a/external/storm-hdfs/pom.xml b/external/storm-hdfs/pom.xml
index 14f16d4..259ce07 100644
--- a/external/storm-hdfs/pom.xml
+++ b/external/storm-hdfs/pom.xml
@@ -30,8 +30,6 @@
<properties>
<!-- Required downgrade by hadoop-hdfs 2.8.5 -->
<guava.version>16.0.1</guava.version>
- <!-- Required downgrade by hadoop-hdfs 2.8.5 (org.apache.hadoop.test.GenericTestUtils.getTestDir)-->
- <junit.version>4.12</junit.version>
</properties>
<developers>
@@ -238,11 +236,6 @@
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>${junit.version}</version>
- </dependency>
- <dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
diff --git a/external/storm-hdfs/src/test/java/org/apache/storm/hdfs/testing/MiniDFSClusterExtension.java b/external/storm-hdfs/src/test/java/org/apache/storm/hdfs/testing/MiniDFSClusterExtension.java
index f88fef5..93a0eab 100644
--- a/external/storm-hdfs/src/test/java/org/apache/storm/hdfs/testing/MiniDFSClusterExtension.java
+++ b/external/storm-hdfs/src/test/java/org/apache/storm/hdfs/testing/MiniDFSClusterExtension.java
@@ -17,6 +17,7 @@
*/
package org.apache.storm.hdfs.testing;
+import java.io.File;
import java.util.function.Supplier;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.MiniDFSCluster;
@@ -24,6 +25,10 @@
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
+import static org.apache.hadoop.test.GenericTestUtils.DEFAULT_TEST_DATA_DIR;
+import static org.apache.hadoop.test.GenericTestUtils.SYSPROP_TEST_DATA_DIR;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
public class MiniDFSClusterExtension implements BeforeEachCallback, AfterEachCallback {
private static final String TEST_BUILD_DATA = "test.build.data";
@@ -52,6 +57,8 @@
public void beforeEach(ExtensionContext arg0) throws Exception {
System.setProperty(TEST_BUILD_DATA, "target/test/data");
hadoopConf = hadoopConfSupplier.get();
+ String tempDir = getTestDir("dfs").getAbsolutePath() + File.separator;
+ hadoopConf.set("hdfs.minidfs.basedir", tempDir);
dfscluster = new MiniDFSCluster.Builder(hadoopConf).numDataNodes(3).build();
dfscluster.waitActive();
}
@@ -61,4 +68,30 @@
dfscluster.shutdown();
System.clearProperty(TEST_BUILD_DATA);
}
+
+ /**
+ * Get an uncreated directory for tests.
+ * We use this method to get rid of getTestDir() in GenericTestUtils in Hadoop code
+ * which uses assert from junit4.
+ * @return the absolute directory for tests. Caller is expected to create it.
+ */
+ public static File getTestDir(String subdir) {
+ return new File(getTestDir(), subdir).getAbsoluteFile();
+ }
+
+ /**
+ * Get the (created) base directory for tests.
+ * @return the absolute directory
+ */
+ public static File getTestDir() {
+ String prop = System.getProperty(SYSPROP_TEST_DATA_DIR, DEFAULT_TEST_DATA_DIR);
+ if (prop.isEmpty()) {
+ // corner case: property is there but empty
+ prop = DEFAULT_TEST_DATA_DIR;
+ }
+ File dir = new File(prop).getAbsoluteFile();
+ dir.mkdirs();
+ assertTrue(dir.exists(), "File " + dir + " should exist");
+ return dir;
+ }
}
diff --git a/external/storm-hdfs/src/test/java/org/apache/storm/hdfs/testing/MiniDFSClusterExtensionClassLevel.java b/external/storm-hdfs/src/test/java/org/apache/storm/hdfs/testing/MiniDFSClusterExtensionClassLevel.java
index 820421d..d13208a 100644
--- a/external/storm-hdfs/src/test/java/org/apache/storm/hdfs/testing/MiniDFSClusterExtensionClassLevel.java
+++ b/external/storm-hdfs/src/test/java/org/apache/storm/hdfs/testing/MiniDFSClusterExtensionClassLevel.java
@@ -17,6 +17,7 @@
*/
package org.apache.storm.hdfs.testing;
+import java.io.File;
import java.util.function.Supplier;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.MiniDFSCluster;
@@ -24,6 +25,8 @@
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
+import static org.apache.storm.hdfs.testing.MiniDFSClusterExtension.getTestDir;
+
public class MiniDFSClusterExtensionClassLevel implements BeforeAllCallback, AfterAllCallback {
private static final String TEST_BUILD_DATA = "test.build.data";
@@ -52,6 +55,8 @@
public void beforeAll(ExtensionContext arg0) throws Exception {
System.setProperty(TEST_BUILD_DATA, "target/test/data");
hadoopConf = hadoopConfSupplier.get();
+ String tempDir = getTestDir("dfs").getAbsolutePath() + File.separator;
+ hadoopConf.set("hdfs.minidfs.basedir", tempDir);
dfscluster = new MiniDFSCluster.Builder(hadoopConf).numDataNodes(3).build();
dfscluster.waitActive();
}
diff --git a/storm-client/test/py/test_storm_cli.py b/storm-client/test/py/test_storm_cli.py
index 14b8bd7..104baa6 100644
--- a/storm-client/test/py/test_storm_cli.py
+++ b/storm-client/test/py/test_storm_cli.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -17,7 +17,7 @@
# limitations under the License.
from unittest import TestCase, main as test_main
-import mock
+from unittest import mock
import sys
import os