This is an automated email from the ASF dual-hosted git repository. pdallig pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push: new e8aff2468a [ZEPPELIN-5960] migrate submarine to JUnit5 (#4655) e8aff2468a is described below commit e8aff2468a82cc65559a206d5eda4b42b4830760 Author: Philipp Dallig <philipp.dal...@gmail.com> AuthorDate: Wed Sep 13 14:53:21 2023 +0200 [ZEPPELIN-5960] migrate submarine to JUnit5 (#4655) --- submarine/pom.xml | 5 ++ .../zeppelin/submarine/BaseInterpreterTest.java | 8 +-- .../apache/zeppelin/submarine/HdfsClientTest.java | 62 ++++++---------------- .../zeppelin/submarine/JinjaTemplatesTest.java | 34 ++++++------ .../submarine/PySubmarineInterpreterTest.java | 20 +++---- .../submarine/SubmarineInterpreterTest.java | 24 +++++---- .../zeppelin/submarine/SubmarineJobTest.java | 4 +- .../apache/zeppelin/submarine/YarnClientTest.java | 30 +++++------ 8 files changed, 82 insertions(+), 105 deletions(-) diff --git a/submarine/pom.xml b/submarine/pom.xml index 0a48aa5dc9..55e6638af3 100644 --- a/submarine/pom.xml +++ b/submarine/pom.xml @@ -141,6 +141,11 @@ <artifactId>mockito-core</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-params</artifactId> + <scope>test</scope> + </dependency> </dependencies> <build> diff --git a/submarine/src/test/java/org/apache/zeppelin/submarine/BaseInterpreterTest.java b/submarine/src/test/java/org/apache/zeppelin/submarine/BaseInterpreterTest.java index 3cb1b2f24e..25061fd144 100644 --- a/submarine/src/test/java/org/apache/zeppelin/submarine/BaseInterpreterTest.java +++ b/submarine/src/test/java/org/apache/zeppelin/submarine/BaseInterpreterTest.java @@ -25,8 +25,8 @@ import org.apache.zeppelin.interpreter.InterpreterException; import org.apache.zeppelin.interpreter.InterpreterOutput; import org.apache.zeppelin.interpreter.remote.RemoteInterpreterEventClient; import org.apache.zeppelin.user.AuthenticationInfo; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import java.util.concurrent.atomic.AtomicInteger; @@ -34,10 +34,10 @@ import static org.mockito.Mockito.mock; public abstract class BaseInterpreterTest { - @Before + @BeforeEach public abstract void setUp() throws InterpreterException; - @After + @AfterEach public abstract void tearDown() throws InterpreterException; protected InterpreterContext getIntpContext() { diff --git a/submarine/src/test/java/org/apache/zeppelin/submarine/HdfsClientTest.java b/submarine/src/test/java/org/apache/zeppelin/submarine/HdfsClientTest.java index fd39ef7059..25378510e0 100644 --- a/submarine/src/test/java/org/apache/zeppelin/submarine/HdfsClientTest.java +++ b/submarine/src/test/java/org/apache/zeppelin/submarine/HdfsClientTest.java @@ -14,75 +14,47 @@ package org.apache.zeppelin.submarine; -import org.apache.zeppelin.conf.ZeppelinConfiguration; import org.apache.zeppelin.submarine.hadoop.HdfsClient; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.io.IOException; import java.util.Properties; -import static org.junit.Assert.assertEquals; - public class HdfsClientTest { private static Logger LOGGER = LoggerFactory.getLogger(HdfsClientTest.class); private static HdfsClient hdfsClient = null; - @BeforeClass + @BeforeAll public static void initEnv() { - ZeppelinConfiguration zconf = ZeppelinConfiguration.create(); Properties properties = new Properties(); hdfsClient = new HdfsClient(properties); } - @Test - public void testParseText0() throws IOException { - String text = "abc"; - String script = hdfsClient.parseText(text); - LOGGER.info(script); - assertEquals(script, "abc"); - } - - @Test - public void testParseText1() throws IOException { - String text = "%submarine abc"; - String script = hdfsClient.parseText(text); - LOGGER.info(script); - assertEquals(script, "abc"); - } - - @Test - public void testParseText2() throws IOException { - String text = "%submarine.sh abc"; - String script = hdfsClient.parseText(text); - LOGGER.info(script); - assertEquals(script, "abc"); - } - - @Test - public void testParseText3() throws IOException { - String text = "%submarine.sh(k1=v1,k2=v2) abc"; - String script = hdfsClient.parseText(text); - LOGGER.info(script); - assertEquals(script, "abc"); - } - - @Test - public void testParseText4() throws IOException { - String text = "%submarine.sh(k1=v1,k2=v2) abc"; + @ParameterizedTest + @ValueSource(strings = { + "abc", + "%submarine abc", + "%submarine.sh abc", + "%submarine.sh(k1=v1,k2=v2) abc" }) + void testParseText0(String text) throws IOException { String script = hdfsClient.parseText(text); LOGGER.info(script); - assertEquals(script, "abc"); + assertEquals("abc", script); } @Test - public void testParseText5() throws IOException { + void testParseText5() throws IOException { String text = ""; String script = hdfsClient.parseText(text); LOGGER.info(script); - assertEquals(script, ""); + assertEquals("", script); } } diff --git a/submarine/src/test/java/org/apache/zeppelin/submarine/JinjaTemplatesTest.java b/submarine/src/test/java/org/apache/zeppelin/submarine/JinjaTemplatesTest.java index 984190223e..0d89bd4851 100644 --- a/submarine/src/test/java/org/apache/zeppelin/submarine/JinjaTemplatesTest.java +++ b/submarine/src/test/java/org/apache/zeppelin/submarine/JinjaTemplatesTest.java @@ -16,27 +16,27 @@ package org.apache.zeppelin.submarine; import com.google.common.io.Resources; import com.hubspot.jinjava.Jinjava; -import org.apache.commons.io.Charsets; import org.apache.zeppelin.submarine.commons.SubmarineConstants; import org.apache.zeppelin.submarine.job.SubmarineJob; +import org.junit.jupiter.api.Test; import org.apache.zeppelin.submarine.commons.SubmarineUtils; -import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.io.IOException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import static org.junit.Assert.assertEquals; - -public class JinjaTemplatesTest { +class JinjaTemplatesTest { private static Logger LOGGER = LoggerFactory.getLogger(JinjaTemplatesTest.class); @Test - public void jobRunJinjaTemplateTest1() throws IOException { + void jobRunJinjaTemplateTest1() throws IOException { String str = jobRunJinjaTemplateTest(Boolean.TRUE, Boolean.TRUE); StringBuffer sbCheck = new StringBuffer(); @@ -79,7 +79,7 @@ public class JinjaTemplatesTest { } @Test - public void jobRunJinjaTemplateTest2() throws IOException { + void jobRunJinjaTemplateTest2() throws IOException { String str = jobRunJinjaTemplateTest(Boolean.TRUE, Boolean.FALSE); StringBuffer sbCheck = new StringBuffer(); sbCheck.append("SUBMARINE_HADOOP_HOME_VALUE/bin/yarn jar HADOOP_YARN_SUBMARINE_JAR_VALUE \\\n" + @@ -119,7 +119,7 @@ public class JinjaTemplatesTest { } @Test - public void jobRunJinjaTemplateTest3() throws IOException { + void jobRunJinjaTemplateTest3() throws IOException { String str = jobRunJinjaTemplateTest(Boolean.TRUE, null); StringBuffer sbCheck = new StringBuffer(); sbCheck.append("SUBMARINE_HADOOP_HOME_VALUE/bin/yarn jar HADOOP_YARN_SUBMARINE_JAR_VALUE \\\n" + @@ -159,7 +159,7 @@ public class JinjaTemplatesTest { } @Test - public void jobRunJinjaTemplateTest4() throws IOException { + void jobRunJinjaTemplateTest4() throws IOException { String str = jobRunJinjaTemplateTest(Boolean.FALSE, Boolean.TRUE); StringBuffer sbCheck = new StringBuffer(); sbCheck.append("DOCKER_HADOOP_HDFS_HOME_VALUE/bin/yarn jar " + @@ -195,7 +195,7 @@ public class JinjaTemplatesTest { } @Test - public void jobRunJinjaTemplateTest5() throws IOException { + void jobRunJinjaTemplateTest5() throws IOException { String str = jobRunJinjaTemplateTest(Boolean.FALSE, Boolean.FALSE); StringBuffer sbCheck = new StringBuffer(); sbCheck.append("SUBMARINE_HADOOP_HOME_VALUE/bin/yarn jar " + @@ -231,7 +231,7 @@ public class JinjaTemplatesTest { } @Test - public void jobRunJinjaTemplateTest6() throws IOException { + void jobRunJinjaTemplateTest6() throws IOException { String str = jobRunJinjaTemplateTest(null, Boolean.FALSE); StringBuffer sbCheck = new StringBuffer(); sbCheck.append("SUBMARINE_HADOOP_HOME_VALUE/bin/yarn jar HADOOP_YARN_SUBMARINE_JAR_VALUE \\\n" + @@ -266,7 +266,7 @@ public class JinjaTemplatesTest { } @Test - public void jobRunJinjaTemplateTest7() throws IOException { + void jobRunJinjaTemplateTest7() throws IOException { String str = jobRunJinjaTemplateTest(null, null); StringBuffer sbCheck = new StringBuffer(); sbCheck.append("SUBMARINE_HADOOP_HOME_VALUE/bin/yarn jar HADOOP_YARN_SUBMARINE_JAR_VALUE \\\n" + @@ -301,7 +301,7 @@ public class JinjaTemplatesTest { } @Test - public void jobRunJinjaTemplateTest8() throws IOException { + void jobRunJinjaTemplateTest8() throws IOException { String str = tensorboardJinjaTemplateTest(Boolean.TRUE, Boolean.TRUE); StringBuffer sbCheck = new StringBuffer(); sbCheck.append("DOCKER_HADOOP_HDFS_HOME_VALUE/bin/yarn jar \\\n" + @@ -324,7 +324,7 @@ public class JinjaTemplatesTest { } @Test - public void jobRunJinjaTemplateTest9() throws IOException { + void jobRunJinjaTemplateTest9() throws IOException { String str = tensorboardJinjaTemplateTest(Boolean.TRUE, Boolean.FALSE); StringBuffer sbCheck = new StringBuffer(); sbCheck.append("SUBMARINE_HADOOP_HOME_VALUE/bin/yarn jar \\\n" + @@ -348,7 +348,7 @@ public class JinjaTemplatesTest { public String jobRunJinjaTemplateTest(Boolean dist, Boolean launchMode) throws IOException { URL urlTemplate = Resources.getResource(SubmarineJob.SUBMARINE_JOBRUN_TF_JINJA); - String template = Resources.toString(urlTemplate, Charsets.UTF_8); + String template = Resources.toString(urlTemplate, StandardCharsets.UTF_8); Jinjava jinjava = new Jinjava(); HashMap<String, Object> jinjaParams = initJinjaParams(dist, launchMode); @@ -367,7 +367,7 @@ public class JinjaTemplatesTest { public String tensorboardJinjaTemplateTest(Boolean dist, Boolean launchMode) throws IOException { URL urlTemplate = Resources.getResource(SubmarineJob.SUBMARINE_TENSORBOARD_JINJA); - String template = Resources.toString(urlTemplate, Charsets.UTF_8); + String template = Resources.toString(urlTemplate, StandardCharsets.UTF_8); Jinjava jinjava = new Jinjava(); HashMap<String, Object> jinjaParams = initJinjaParams(dist, launchMode); @@ -384,7 +384,7 @@ public class JinjaTemplatesTest { } private HashMap<String, Object> initJinjaParams(Boolean dist, Boolean launchMode) { - HashMap<String, Object> jinjaParams = new HashMap(); + HashMap<String, Object> jinjaParams = new HashMap<>(); if (launchMode == Boolean.TRUE) { jinjaParams.put(SubmarineUtils.unifyKey(SubmarineConstants.INTERPRETER_LAUNCH_MODE), "yarn"); diff --git a/submarine/src/test/java/org/apache/zeppelin/submarine/PySubmarineInterpreterTest.java b/submarine/src/test/java/org/apache/zeppelin/submarine/PySubmarineInterpreterTest.java index 5d18ae308f..ebe5ab197d 100644 --- a/submarine/src/test/java/org/apache/zeppelin/submarine/PySubmarineInterpreterTest.java +++ b/submarine/src/test/java/org/apache/zeppelin/submarine/PySubmarineInterpreterTest.java @@ -23,24 +23,24 @@ import org.apache.zeppelin.interpreter.InterpreterException; import org.apache.zeppelin.interpreter.InterpreterGroup; import org.apache.zeppelin.interpreter.InterpreterResult; import org.apache.zeppelin.submarine.commons.SubmarineConstants; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.LinkedList; import java.util.Properties; import static org.apache.zeppelin.submarine.commons.SubmarineConstants.ZEPPELIN_SUBMARINE_AUTH_TYPE; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class PySubmarineInterpreterTest extends BaseInterpreterTest { - private static Logger LOGGER = LoggerFactory.getLogger(PySubmarineInterpreterTest.class); +class PySubmarineInterpreterTest extends BaseInterpreterTest { PySubmarineInterpreter pySubmarineIntp; protected InterpreterGroup intpGroup; @Override + @BeforeEach public void setUp() throws InterpreterException { intpGroup = new InterpreterGroup(); Properties properties = new Properties(); @@ -60,7 +60,7 @@ public class PySubmarineInterpreterTest extends BaseInterpreterTest { } @Test - public void testTensorflow() throws InterpreterException { + void testTensorflow() throws InterpreterException { String callTensorflowFunc = "import tensorflow as tf\n" + "print('Installed TensorFlow version:' + tf.__version__)"; @@ -73,12 +73,12 @@ public class PySubmarineInterpreterTest extends BaseInterpreterTest { // Successfully execute tensorflow to get the version function, // otherwise it will trigger an exception. String tfVersionInfo = intpContext.out().getCurrentOutput().toString(); - LOGGER.info(tfVersionInfo); boolean getVersion = tfVersionInfo.contains("Installed TensorFlow version:"); - assertTrue(tfVersionInfo, getVersion); + assertTrue(getVersion, tfVersionInfo); } @Override + @AfterEach public void tearDown() throws InterpreterException { pySubmarineIntp.close(); intpGroup.close(); diff --git a/submarine/src/test/java/org/apache/zeppelin/submarine/SubmarineInterpreterTest.java b/submarine/src/test/java/org/apache/zeppelin/submarine/SubmarineInterpreterTest.java index 4e3271016b..2021ac44ac 100644 --- a/submarine/src/test/java/org/apache/zeppelin/submarine/SubmarineInterpreterTest.java +++ b/submarine/src/test/java/org/apache/zeppelin/submarine/SubmarineInterpreterTest.java @@ -22,7 +22,9 @@ import org.apache.zeppelin.interpreter.InterpreterException; import org.apache.zeppelin.interpreter.InterpreterResult; import org.apache.zeppelin.submarine.commons.SubmarineConstants; import org.apache.zeppelin.submarine.job.SubmarineJob; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,15 +32,16 @@ import java.util.Properties; import static org.apache.zeppelin.submarine.commons.SubmarineConstants.OPERATION_TYPE; import static org.apache.zeppelin.submarine.commons.SubmarineConstants.ZEPPELIN_SUBMARINE_AUTH_TYPE; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class SubmarineInterpreterTest extends BaseInterpreterTest { +class SubmarineInterpreterTest extends BaseInterpreterTest { private static Logger LOGGER = LoggerFactory.getLogger(SubmarineInterpreterTest.class); private SubmarineInterpreter submarineIntp; @Override + @BeforeEach public void setUp() throws InterpreterException { Properties properties = new Properties(); properties.setProperty(ZEPPELIN_SUBMARINE_AUTH_TYPE, "simple"); @@ -54,7 +57,7 @@ public class SubmarineInterpreterTest extends BaseInterpreterTest { } @Test - public void testDashboard() throws InterpreterException { + void testDashboard() throws InterpreterException { String script = "dashboard"; InterpreterContext intpContext = getIntpContext(); @@ -62,16 +65,16 @@ public class SubmarineInterpreterTest extends BaseInterpreterTest { String message = interpreterResult.toJson(); LOGGER.info(message); - assertEquals(interpreterResult.code(), InterpreterResult.Code.SUCCESS); + assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code()); assertTrue(intpContext.out().size() >= 2); String dashboardTemplate = intpContext.out().getOutputAt(0).toString(); LOGGER.info(dashboardTemplate); - assertTrue("Did not generate template!", (dashboardTemplate.length() > 500)); + assertTrue(dashboardTemplate.length() > 500, "Did not generate template!"); } @Test - public void testJobRun() throws InterpreterException { + void testJobRun() throws InterpreterException { String script = "JOB_RUN"; InterpreterContext intpContext = getIntpContext(); @@ -81,10 +84,10 @@ public class SubmarineInterpreterTest extends BaseInterpreterTest { String message = interpreterResult.toJson(); LOGGER.info(message); - assertEquals(interpreterResult.code(), InterpreterResult.Code.SUCCESS); + assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code()); assertTrue(intpContext.out().size() >= 2); String template = intpContext.out().getOutputAt(0).toString(); - assertTrue("Did not generate template!", (template.length() > 500)); + assertTrue(template.length() > 500, "Did not generate template!"); SubmarineJob job = submarineIntp.getSubmarineContext().getSubmarineJob("noteId"); int loop = 10; @@ -99,6 +102,7 @@ public class SubmarineInterpreterTest extends BaseInterpreterTest { } @Override + @AfterEach public void tearDown() throws InterpreterException { submarineIntp.close(); } diff --git a/submarine/src/test/java/org/apache/zeppelin/submarine/SubmarineJobTest.java b/submarine/src/test/java/org/apache/zeppelin/submarine/SubmarineJobTest.java index 1922a29fc5..d14f957213 100644 --- a/submarine/src/test/java/org/apache/zeppelin/submarine/SubmarineJobTest.java +++ b/submarine/src/test/java/org/apache/zeppelin/submarine/SubmarineJobTest.java @@ -21,7 +21,7 @@ import org.apache.commons.exec.DefaultExecutor; import org.apache.commons.exec.ExecuteException; import org.apache.commons.exec.LogOutputStream; import org.apache.commons.exec.PumpStreamHandler; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,7 +40,7 @@ public class SubmarineJobTest { private static final String DEFAULT_EXECUTOR_TEST = "DefaultExecutorTest.sh"; @Test - public void defaultExecutorTest() throws IOException { + void defaultExecutorTest() throws IOException { DefaultExecutor executor = new DefaultExecutor(); CommandLine cmdLine = CommandLine.parse(shell); diff --git a/submarine/src/test/java/org/apache/zeppelin/submarine/YarnClientTest.java b/submarine/src/test/java/org/apache/zeppelin/submarine/YarnClientTest.java index c267fded9b..bcfd0c36c8 100644 --- a/submarine/src/test/java/org/apache/zeppelin/submarine/YarnClientTest.java +++ b/submarine/src/test/java/org/apache/zeppelin/submarine/YarnClientTest.java @@ -16,13 +16,10 @@ package org.apache.zeppelin.submarine; import com.google.common.base.Charsets; import com.google.common.io.Resources; -import org.apache.zeppelin.conf.ZeppelinConfiguration; import org.apache.zeppelin.submarine.commons.SubmarineConstants; import org.apache.zeppelin.submarine.hadoop.YarnClient; -import org.junit.BeforeClass; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.net.URL; @@ -31,15 +28,14 @@ import java.util.Map; import java.util.Properties; import static org.apache.zeppelin.submarine.commons.SubmarineConstants.ZEPPELIN_SUBMARINE_AUTH_TYPE; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class YarnClientTest { - private static Logger LOGGER = LoggerFactory.getLogger(YarnClientTest.class); private static YarnClient yarnClient = null; - @BeforeClass + @BeforeAll public static void initEnv() { - ZeppelinConfiguration zconf = ZeppelinConfiguration.create(); Properties properties = new Properties(); properties.setProperty(ZEPPELIN_SUBMARINE_AUTH_TYPE, "simple"); properties.setProperty("zeppelin.python.useIPython", "false"); @@ -50,39 +46,39 @@ public class YarnClientTest { } @Test - public void testParseAppAttempts() throws IOException { + void testParseAppAttempts() throws IOException { String jsonFile = "ws-v1-cluster-apps-application_id-appattempts.json"; URL urlJson = Resources.getResource(jsonFile); String jsonContent = Resources.toString(urlJson, Charsets.UTF_8); List<Map<String, Object>> list = yarnClient.parseAppAttempts(jsonContent); - LOGGER.info(""); + assertNotNull(list); } @Test - public void testParseAppAttemptsContainers() throws IOException { + void testParseAppAttemptsContainers() throws IOException { String jsonFile = "ws-v1-cluster-apps-application_id-appattempts-appattempt_id-containers.json"; URL urlJson = Resources.getResource(jsonFile); String jsonContent = Resources.toString(urlJson, Charsets.UTF_8); List<Map<String, Object>> list = yarnClient.parseAppAttemptsContainers(jsonContent); - list.get(0).get(YarnClient.HOST_IP); - list.get(0).get(YarnClient.HOST_PORT); - list.get(0).get(YarnClient.CONTAINER_PORT); + assertNotNull(list.get(0).get(YarnClient.HOST_IP)); + assertNotNull(list.get(0).get(YarnClient.HOST_PORT)); + assertNotNull(list.get(0).get(YarnClient.CONTAINER_PORT)); - LOGGER.info(""); + assertNotNull(list); } @Test - public void testParseClusterApps() throws IOException { + void testParseClusterApps() throws IOException { String jsonFile = "ws-v1-cluster-apps-application_id-finished.json"; URL urlJson = Resources.getResource(jsonFile); String jsonContent = Resources.toString(urlJson, Charsets.UTF_8); Map<String, Object> list = yarnClient.parseClusterApps(jsonContent); - LOGGER.info(""); + assertNotNull(list); } }