This is an automated email from the ASF dual-hosted git repository. jongyoul 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 bcf3499fc8 [ZEPPELIN-6020] Remove TestUtils class in zeppelin-server (#4764) bcf3499fc8 is described below commit bcf3499fc82261a06e88a62b0e5182840d0598ba Author: Philipp Dallig <philipp.dal...@gmail.com> AuthorDate: Sun Aug 4 05:52:52 2024 +0200 [ZEPPELIN-6020] Remove TestUtils class in zeppelin-server (#4764) --- .../zeppelin/integration/FlinkIntegrationTest.java | 2 +- .../zeppelin/integration/JdbcIntegrationTest.java | 2 +- .../zeppelin/integration/ShellIntegrationTest.java | 7 +- .../zeppelin/integration/SparkIntegrationTest.java | 4 +- .../integration/SparkSubmitIntegrationTest.java | 4 +- .../YarnInterpreterLauncherIntegrationTest.java | 2 +- .../integration/ZSessionIntegrationTest.java | 2 +- .../integration/ZeppelinClientIntegrationTest.java | 2 +- .../integration/ZeppelinFlinkClusterTest.java | 13 +- .../integration/ZeppelinSparkClusterTest.java | 139 ++++++++------- .../org/apache/zeppelin/socket/NotebookServer.java | 5 - .../java/org/apache/zeppelin/utils/TestUtils.java | 50 ------ .../org/apache/zeppelin/MiniZeppelinServer.java | 6 + .../apache/zeppelin/cluster/ClusterEventTest.java | 27 ++- .../apache/zeppelin/integration/TestHelper.java | 6 +- .../org/apache/zeppelin/recovery/RecoveryTest.java | 50 +++--- .../apache/zeppelin/rest/HeliumRestApiTest.java | 2 +- .../zeppelin/rest/InterpreterRestApiTest.java | 37 ++-- .../apache/zeppelin/rest/NotebookRestApiTest.java | 154 ++++++++--------- .../zeppelin/rest/NotebookSecurityRestApiTest.java | 8 +- .../apache/zeppelin/rest/ZeppelinRestApiTest.java | 189 +++++++++++---------- .../zeppelin/service/ConfigurationServiceTest.java | 3 +- .../apache/zeppelin/socket/NotebookServerTest.java | 8 +- 23 files changed, 332 insertions(+), 390 deletions(-) diff --git a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/FlinkIntegrationTest.java b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/FlinkIntegrationTest.java index 6d6eae07af..c58b4ed34c 100644 --- a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/FlinkIntegrationTest.java +++ b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/FlinkIntegrationTest.java @@ -96,7 +96,7 @@ public abstract class FlinkIntegrationTest { @BeforeEach void setup() { - interpreterSettingManager = zepServer.getServiceLocator().getService(InterpreterSettingManager.class); + interpreterSettingManager = zepServer.getService(InterpreterSettingManager.class); interpreterFactory = new InterpreterFactory(interpreterSettingManager); } diff --git a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/JdbcIntegrationTest.java b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/JdbcIntegrationTest.java index 92178c2746..e201aac120 100644 --- a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/JdbcIntegrationTest.java +++ b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/JdbcIntegrationTest.java @@ -58,7 +58,7 @@ public class JdbcIntegrationTest { @BeforeEach void setup() { - interpreterSettingManager = zepServer.getServiceLocator().getService(InterpreterSettingManager.class); + interpreterSettingManager = zepServer.getService(InterpreterSettingManager.class); interpreterFactory = new InterpreterFactory(interpreterSettingManager); } diff --git a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ShellIntegrationTest.java b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ShellIntegrationTest.java index 6af3dbf573..1a5ed40eef 100644 --- a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ShellIntegrationTest.java +++ b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ShellIntegrationTest.java @@ -24,7 +24,6 @@ import org.apache.zeppelin.notebook.Paragraph; import org.apache.zeppelin.rest.AbstractTestRestApi; import org.apache.zeppelin.scheduler.Job; import org.apache.zeppelin.user.AuthenticationInfo; -import org.apache.zeppelin.utils.TestUtils; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -62,8 +61,8 @@ class ShellIntegrationTest extends AbstractTestRestApi { void testBasicShell() throws IOException { String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", AuthenticationInfo.ANONYMOUS); - TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = zepServer.getService(Notebook.class).createNote("note1", AuthenticationInfo.ANONYMOUS); + zepServer.getService(Notebook.class).processNote(noteId, note -> { Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); @@ -96,7 +95,7 @@ class ShellIntegrationTest extends AbstractTestRestApi { } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, AuthenticationInfo.ANONYMOUS); + zepServer.getService(Notebook.class).removeNote(noteId, AuthenticationInfo.ANONYMOUS); } } } diff --git a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/SparkIntegrationTest.java b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/SparkIntegrationTest.java index 4286f824f1..73f49b1cd6 100644 --- a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/SparkIntegrationTest.java +++ b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/SparkIntegrationTest.java @@ -93,8 +93,8 @@ public abstract class SparkIntegrationTest { zepServer.getZeppelinConfiguration().setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_HELIUM_REGISTRY.getVarName(), "helium"); zepServer.start(); - interpreterSettingManager = zepServer.getServiceLocator().getService(InterpreterSettingManager.class); - interpreterFactory = zepServer.getServiceLocator().getService(InterpreterFactory.class); + interpreterSettingManager = zepServer.getService(InterpreterSettingManager.class); + interpreterFactory = zepServer.getService(InterpreterFactory.class); } @AfterAll diff --git a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/SparkSubmitIntegrationTest.java b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/SparkSubmitIntegrationTest.java index 05e6af3778..405bf8309d 100644 --- a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/SparkSubmitIntegrationTest.java +++ b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/SparkSubmitIntegrationTest.java @@ -76,8 +76,8 @@ public class SparkSubmitIntegrationTest { zepServer.getZeppelinConfiguration().setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_HELIUM_REGISTRY.getVarName(), "helium"); zepServer.start(); - interpreterSettingManager = zepServer.getServiceLocator().getService(InterpreterSettingManager.class); - interpreterFactory = zepServer.getServiceLocator().getService(InterpreterFactory.class); + interpreterSettingManager = zepServer.getService(InterpreterSettingManager.class); + interpreterFactory = zepServer.getService(InterpreterFactory.class); InterpreterSetting sparkSubmitInterpreterSetting = interpreterSettingManager.getInterpreterSettingByName("spark-submit"); sparkSubmitInterpreterSetting.setProperty("SPARK_HOME", sparkHome); sparkSubmitInterpreterSetting.setProperty("HADOOP_CONF_DIR", hadoopCluster.getConfigPath()); diff --git a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/YarnInterpreterLauncherIntegrationTest.java b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/YarnInterpreterLauncherIntegrationTest.java index 2a39e04715..46f8bc1267 100644 --- a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/YarnInterpreterLauncherIntegrationTest.java +++ b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/YarnInterpreterLauncherIntegrationTest.java @@ -78,7 +78,7 @@ public class YarnInterpreterLauncherIntegrationTest { } @BeforeEach void setup() { - interpreterSettingManager = zepServer.getServiceLocator().getService(InterpreterSettingManager.class); + interpreterSettingManager = zepServer.getService(InterpreterSettingManager.class); interpreterFactory = new InterpreterFactory(interpreterSettingManager); } @AfterAll diff --git a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZSessionIntegrationTest.java b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZSessionIntegrationTest.java index 6c4029955d..d346779483 100644 --- a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZSessionIntegrationTest.java +++ b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZSessionIntegrationTest.java @@ -79,7 +79,7 @@ public class ZSessionIntegrationTest extends AbstractTestRestApi { sparkHome = DownloadUtils.downloadSpark(); flinkHome = DownloadUtils.downloadFlink("1.17.1", "2.12"); zepServer.start(); - notebook = zepServer.getServiceLocator().getService(Notebook.class); + notebook = zepServer.getService(Notebook.class); } diff --git a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinClientIntegrationTest.java b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinClientIntegrationTest.java index fb0fbdf5d2..f2486a58bb 100644 --- a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinClientIntegrationTest.java +++ b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinClientIntegrationTest.java @@ -70,7 +70,7 @@ class ZeppelinClientIntegrationTest extends AbstractTestRestApi { zepServer.start(); clientConfig = new ClientConfig("http://localhost:" + zepServer.getZeppelinConfiguration().getServerPort()); zeppelinClient = new ZeppelinClient(clientConfig); - notebook = zepServer.getServiceLocator().getService(Notebook.class); + notebook = zepServer.getService(Notebook.class); } @AfterAll diff --git a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinFlinkClusterTest.java b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinFlinkClusterTest.java index 65060ee49a..ef3e5a286a 100644 --- a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinFlinkClusterTest.java +++ b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinFlinkClusterTest.java @@ -26,7 +26,6 @@ import org.apache.zeppelin.notebook.Paragraph; import org.apache.zeppelin.rest.AbstractTestRestApi; import org.apache.zeppelin.scheduler.Job; import org.apache.zeppelin.user.AuthenticationInfo; -import org.apache.zeppelin.utils.TestUtils; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -87,11 +86,11 @@ public abstract class ZeppelinFlinkClusterTest extends AbstractTestRestApi { String noteId = null; try { // create new note - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", AuthenticationInfo.ANONYMOUS); + noteId = zepServer.getService(Notebook.class).createNote("note1", AuthenticationInfo.ANONYMOUS); // run p0 for %flink.conf String checkpointPath = Files.createTempDirectory("checkpoint").toAbsolutePath().toString(); - TestUtils.getInstance(Notebook.class).processNote(noteId, + zepServer.getService(Notebook.class).processNote(noteId, note -> { Paragraph p0 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); StringBuilder builder = new StringBuilder("%flink.conf\n"); @@ -142,7 +141,7 @@ public abstract class ZeppelinFlinkClusterTest extends AbstractTestRestApi { throw e; } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, AuthenticationInfo.ANONYMOUS); + zepServer.getService(Notebook.class).removeNote(noteId, AuthenticationInfo.ANONYMOUS); } } } @@ -154,11 +153,11 @@ public abstract class ZeppelinFlinkClusterTest extends AbstractTestRestApi { String noteId = null; try { // create new note - noteId = TestUtils.getInstance(Notebook.class).createNote("note2", AuthenticationInfo.ANONYMOUS); + noteId = zepServer.getService(Notebook.class).createNote("note2", AuthenticationInfo.ANONYMOUS); // run p0 for %flink.conf String checkpointPath = Files.createTempDirectory("checkpoint").toAbsolutePath().toString(); - TestUtils.getInstance(Notebook.class).processNote(noteId, + zepServer.getService(Notebook.class).processNote(noteId, note -> { Paragraph p0 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); StringBuilder builder = new StringBuilder("%flink.conf\n"); @@ -207,7 +206,7 @@ public abstract class ZeppelinFlinkClusterTest extends AbstractTestRestApi { throw e; } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, AuthenticationInfo.ANONYMOUS); + zepServer.getService(Notebook.class).removeNote(noteId, AuthenticationInfo.ANONYMOUS); } } } diff --git a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinSparkClusterTest.java b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinSparkClusterTest.java index 2fd93d331b..8a55fb2ede 100644 --- a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinSparkClusterTest.java +++ b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinSparkClusterTest.java @@ -37,7 +37,6 @@ import org.apache.zeppelin.notebook.Paragraph; import org.apache.zeppelin.rest.AbstractTestRestApi; import org.apache.zeppelin.scheduler.Job.Status; import org.apache.zeppelin.user.AuthenticationInfo; -import org.apache.zeppelin.utils.TestUtils; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -106,7 +105,7 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { } public void setupSparkInterpreter(String sparkHome) throws InterpreterException { - InterpreterSetting sparkIntpSetting = TestUtils.getInstance(Notebook.class).getInterpreterSettingManager() + InterpreterSetting sparkIntpSetting = zepServer.getService(Notebook.class).getInterpreterSettingManager() .getInterpreterSettingByName("spark"); Map<String, InterpreterProperty> sparkProperties = @@ -130,7 +129,7 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { new InterpreterProperty("zeppelin.spark.scala.color", "false")); sparkProperties.put("zeppelin.spark.deprecatedMsg.show", new InterpreterProperty("zeppelin.spark.deprecatedMsg.show", "false")); - zepServer.getServiceLocator().getService(Notebook.class).getInterpreterSettingManager().restart(sparkIntpSetting.getId()); + zepServer.getService(Notebook.class).getInterpreterSettingManager().restart(sparkIntpSetting.getId()); } @BeforeAll @@ -171,8 +170,8 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { String noteId = null; try { // create new note - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = zepServer.getService(Notebook.class).createNote("note1", anonymous); + zepServer.getService(Notebook.class).processNote(noteId, note -> { Paragraph p = note.addNewParagraph(anonymous); p.setText("%spark import java.util.Date\n" + @@ -187,7 +186,7 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { p.getReturn().message().get(0).getData()); // check spark weburl in zeppelin-server side - InterpreterSettingManager interpreterSettingManager = TestUtils.getInstance(InterpreterSettingManager.class); + InterpreterSettingManager interpreterSettingManager = zepServer.getService(InterpreterSettingManager.class); InterpreterSetting sparkInterpreterSetting = interpreterSettingManager.getByName("spark"); assertEquals(1, sparkInterpreterSetting.getAllInterpreterGroups().size()); assertNotNull(sparkInterpreterSetting.getAllInterpreterGroups().get(0).getWebUrl()); @@ -218,7 +217,7 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { }); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + zepServer.getService(Notebook.class).removeNote(noteId, anonymous); } } } @@ -230,8 +229,8 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = zepServer.getService(Notebook.class).createNote("note1", anonymous); + zepServer.getService(Notebook.class).processNote(noteId, note -> { Paragraph p = note.addNewParagraph(anonymous); p.setText("%spark print(sc.parallelize(1 to 10).reduce(_ + _))"); @@ -242,7 +241,7 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { }); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + zepServer.getService(Notebook.class).removeNote(noteId, anonymous); } } } @@ -253,8 +252,8 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = zepServer.getService(Notebook.class).createNote("note1", anonymous); + zepServer.getService(Notebook.class).processNote(noteId, note -> { Paragraph p = note.addNewParagraph(anonymous); File tmpJsonFile = File.createTempFile("test", ".json"); @@ -271,7 +270,7 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { }); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + zepServer.getService(Notebook.class).removeNote(noteId, anonymous); } } } @@ -282,8 +281,8 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = zepServer.getService(Notebook.class).createNote("note1", anonymous); + zepServer.getService(Notebook.class).processNote(noteId, note -> { Paragraph p = note.addNewParagraph(anonymous); File tmpCSVFile = File.createTempFile("test", ".csv"); @@ -299,7 +298,7 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { }); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + zepServer.getService(Notebook.class).removeNote(noteId, anonymous); } } } @@ -310,8 +309,8 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = zepServer.getService(Notebook.class).createNote("note1", anonymous); + zepServer.getService(Notebook.class).processNote(noteId, note -> { // test basic dataframe api Paragraph p = note.addNewParagraph(anonymous); @@ -387,7 +386,7 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { }); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + zepServer.getService(Notebook.class).removeNote(noteId, anonymous); } } } @@ -398,8 +397,8 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = zepServer.getService(Notebook.class).createNote("note1", anonymous); + zepServer.getService(Notebook.class).processNote(noteId, note -> { Paragraph p = note.addNewParagraph(anonymous); @@ -415,7 +414,7 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { }); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + zepServer.getService(Notebook.class).removeNote(noteId, anonymous); } } } @@ -427,8 +426,8 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { // create new note String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = zepServer.getService(Notebook.class).createNote("note1", anonymous); + zepServer.getService(Notebook.class).processNote(noteId, note -> { // run markdown paragraph, again @@ -473,7 +472,7 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { }); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + zepServer.getService(Notebook.class).removeNote(noteId, anonymous); } } } @@ -486,8 +485,8 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { String note2Id = null; try { // create new note - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - note2Id = TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = zepServer.getService(Notebook.class).createNote("note1", anonymous); + note2Id = zepServer.getService(Notebook.class).processNote(noteId, note -> { Paragraph p0 = note.addNewParagraph(anonymous); // z.run(paragraphIndex) @@ -532,8 +531,8 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { assertEquals("END\n", p3.getReturn().message().get(0).getData()); // run paragraph in note2 via paragraph in note1 - String noteId2 = TestUtils.getInstance(Notebook.class).createNote("note2", anonymous); - TestUtils.getInstance(Notebook.class).processNote(noteId2, + String noteId2 = zepServer.getService(Notebook.class).createNote("note2", anonymous); + zepServer.getService(Notebook.class).processNote(noteId2, note2 -> { Paragraph p20 = note2.addNewParagraph(anonymous); p20.setText("%spark val a = 1"); @@ -560,10 +559,10 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { }); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + zepServer.getService(Notebook.class).removeNote(noteId, anonymous); } if (null != note2Id) { - TestUtils.getInstance(Notebook.class).removeNote(note2Id, anonymous); + zepServer.getService(Notebook.class).removeNote(note2Id, anonymous); } } } @@ -574,8 +573,8 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = zepServer.getService(Notebook.class).createNote("note1", anonymous); + zepServer.getService(Notebook.class).processNote(noteId, note -> { Paragraph p1 = note.addNewParagraph(anonymous); p1.setText("%spark z.put(\"var_1\", \"hello world\")"); @@ -613,7 +612,7 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { }); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + zepServer.getService(Notebook.class).removeNote(noteId, anonymous); } } } @@ -625,8 +624,8 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { String noteId = null; String note2Id = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - note2Id = TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = zepServer.getService(Notebook.class).createNote("note1", anonymous); + note2Id = zepServer.getService(Notebook.class).processNote(noteId, note -> { // register global hook & note1 hook Paragraph p1 = note.addNewParagraph(anonymous); @@ -646,8 +645,8 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { assertEquals(Status.FINISHED, p2.getStatus()); assertEquals("1\n3\n5\n4\n2\n", p2.getReturn().message().get(0).getData()); - String note2Tmp = TestUtils.getInstance(Notebook.class).createNote("note2", anonymous); - TestUtils.getInstance(Notebook.class).processNote(note2Tmp, + String note2Tmp = zepServer.getService(Notebook.class).createNote("note2", anonymous); + zepServer.getService(Notebook.class).processNote(note2Tmp, note2 -> { Paragraph p3 = note2.addNewParagraph(anonymous); p3.setText("%python print(6)"); @@ -659,10 +658,10 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { }); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + zepServer.getService(Notebook.class).removeNote(noteId, anonymous); } if (null != note2Id) { - TestUtils.getInstance(Notebook.class).removeNote(note2Id, anonymous); + zepServer.getService(Notebook.class).removeNote(note2Id, anonymous); } } } @@ -670,8 +669,8 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { private void verifySparkVersionNumber() throws IOException { String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = zepServer.getService(Notebook.class).createNote("note1", anonymous); + zepServer.getService(Notebook.class).processNote(noteId, note -> { Paragraph p = note.addNewParagraph(anonymous); @@ -691,7 +690,7 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { }); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + zepServer.getService(Notebook.class).removeNote(noteId, anonymous); } } } @@ -702,8 +701,8 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = zepServer.getService(Notebook.class).createNote("note1", anonymous); + zepServer.getService(Notebook.class).processNote(noteId, note -> { Paragraph p = note.addNewParagraph(anonymous); String code = "%spark println(z.textbox(\"my_input\", \"default_name\"))\n" + @@ -736,7 +735,7 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { }); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + zepServer.getService(Notebook.class).removeNote(noteId, anonymous); } } } @@ -747,8 +746,8 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = zepServer.getService(Notebook.class).createNote("note1", anonymous); + zepServer.getService(Notebook.class).processNote(noteId, note -> { Paragraph p = note.addNewParagraph(anonymous); String code = "%spark.pyspark print(z.input('my_input', 'default_name'))\n" + @@ -779,7 +778,7 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { }); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + zepServer.getService(Notebook.class).removeNote(noteId, anonymous); } } } @@ -790,8 +789,8 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = zepServer.getService(Notebook.class).createNote("note1", anonymous); + zepServer.getService(Notebook.class).processNote(noteId, note -> { Paragraph p1 = note.addNewParagraph(anonymous); @@ -896,7 +895,7 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { }); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + zepServer.getService(Notebook.class).removeNote(noteId, anonymous); } } } @@ -907,8 +906,8 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = zepServer.getService(Notebook.class).createNote("note1", anonymous); + zepServer.getService(Notebook.class).processNote(noteId, note -> { Paragraph p1 = note.addNewParagraph(anonymous); @@ -966,7 +965,7 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { }); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + zepServer.getService(Notebook.class).removeNote(noteId, anonymous); } } } @@ -977,8 +976,8 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = zepServer.getService(Notebook.class).createNote("note1", anonymous); + zepServer.getService(Notebook.class).processNote(noteId, note -> { Paragraph p1 = note.addNewParagraph(anonymous); @@ -1036,7 +1035,7 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { }); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + zepServer.getService(Notebook.class).removeNote(noteId, anonymous); } } } @@ -1047,8 +1046,8 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = zepServer.getService(Notebook.class).createNote("note1", anonymous); + zepServer.getService(Notebook.class).processNote(noteId, note -> { Paragraph p1 = note.addNewParagraph(anonymous); @@ -1072,7 +1071,7 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { }); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + zepServer.getService(Notebook.class).removeNote(noteId, anonymous); } } } @@ -1083,9 +1082,9 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { String noteId = null; try { - TestUtils.getInstance(Notebook.class).getInterpreterSettingManager().close(); - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - TestUtils.getInstance(Notebook.class).processNote(noteId, + zepServer.getService(Notebook.class).getInterpreterSettingManager().close(); + noteId = zepServer.getService(Notebook.class).createNote("note1", anonymous); + zepServer.getService(Notebook.class).processNote(noteId, note -> { Paragraph p = note.addNewParagraph(anonymous); p.setText("%spark.conf spark.jars.packages\tcom.databricks:spark-csv_2.11:1.2.0"); @@ -1113,7 +1112,7 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { }); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + zepServer.getService(Notebook.class).removeNote(noteId, anonymous); } } } @@ -1124,9 +1123,9 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { String noteId = null; try { - TestUtils.getInstance(Notebook.class).getInterpreterSettingManager().close(); - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - TestUtils.getInstance(Notebook.class).processNote(noteId, + zepServer.getService(Notebook.class).getInterpreterSettingManager().close(); + noteId = zepServer.getService(Notebook.class).createNote("note1", anonymous); + zepServer.getService(Notebook.class).processNote(noteId, note -> { Paragraph p = note.addNewParagraph(anonymous); p.setText("%spark.conf SPARK_HOME invalid_spark_home"); @@ -1151,10 +1150,10 @@ public abstract class ZeppelinSparkClusterTest extends AbstractTestRestApi { }); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + zepServer.getService(Notebook.class).removeNote(noteId, anonymous); } // reset SPARK_HOME, otherwise it will cause the following test fail - InterpreterSetting sparkIntpSetting = TestUtils.getInstance(Notebook.class).getInterpreterSettingManager() + InterpreterSetting sparkIntpSetting = zepServer.getService(Notebook.class).getInterpreterSettingManager() .getInterpreterSettingByName("spark"); Map<String, InterpreterProperty> sparkProperties = (Map<String, InterpreterProperty>) sparkIntpSetting.getProperties(); diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java index 662206dc59..33122d45c1 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java @@ -102,7 +102,6 @@ import org.apache.zeppelin.user.AuthenticationInfo; import org.apache.zeppelin.util.IdHashes; import org.apache.zeppelin.utils.CorsUtils; import org.apache.zeppelin.utils.ServerUtils; -import org.apache.zeppelin.utils.TestUtils; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.annotation.ManagedOperation; @@ -226,10 +225,6 @@ public class NotebookServer implements AngularObjectRegistryListener, this.jobManagerServiceProvider = jobManagerServiceProvider; } - public static NotebookServer getInstance() { - return TestUtils.getInstance(NotebookServer.class); - } - public Notebook getNotebook() { return notebookProvider.get(); } diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/utils/TestUtils.java b/zeppelin-server/src/main/java/org/apache/zeppelin/utils/TestUtils.java deleted file mode 100644 index 470b3dce49..0000000000 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/utils/TestUtils.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.zeppelin.utils; - -import java.util.Arrays; -import org.apache.zeppelin.server.ZeppelinServer; -import org.glassfish.hk2.api.ServiceLocator; -import org.glassfish.hk2.api.ServiceLocatorFactory; - -//TODO(zjffdu) refactor this class, it should not be called by non-test code. Or rename it. -public class TestUtils { - public static <T> T getInstance(Class<T> clazz) { - checkCalledByTestMethod(); - return getInstance(ServiceLocatorFactory.getInstance().find(ZeppelinServer.DEFAULT_SERVICE_LOCATOR_NAME), clazz); - } - - public static void clearInstances() { - checkCalledByTestMethod(); - ServiceLocatorFactory.getInstance().destroy(ZeppelinServer.DEFAULT_SERVICE_LOCATOR_NAME); - } - - static <T> T getInstance(ServiceLocator serviceLocator, Class<T> clazz) { - return serviceLocator.getService(clazz); - } - - static void checkCalledByTestMethod() { - StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); - // The first element of [0] indicates 'java.lang.Thread.getStackTrace'. - // The second element of [1] indicates this method. - // The third element of [2] indicates a caller of this method. - if (Arrays.stream(stackTraceElements) - .noneMatch(stackTraceElement -> stackTraceElement.getClassName().contains("Test"))) { - throw new RuntimeException("This method shouldn't be used in production"); - } - } -} diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/MiniZeppelinServer.java b/zeppelin-server/src/test/java/org/apache/zeppelin/MiniZeppelinServer.java index 2ba059a871..17ae4a5634 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/MiniZeppelinServer.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/MiniZeppelinServer.java @@ -21,6 +21,8 @@ import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.zeppelin.conf.ZeppelinConfiguration; import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars; +import org.apache.zeppelin.interpreter.InterpreterSetting; +import org.apache.zeppelin.notebook.Notebook; import org.apache.zeppelin.rest.AbstractTestRestApi; import org.apache.zeppelin.server.ZeppelinServer; import org.glassfish.hk2.api.ServiceLocator; @@ -317,4 +319,8 @@ public class MiniZeppelinServer implements AutoCloseable { public void destroy() throws Exception { close(); } + + public <T> T getService(Class<T> clazz) { + return getServiceLocator().getService(clazz); + } } diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/cluster/ClusterEventTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/cluster/ClusterEventTest.java index 79a65c7615..7e2c06b293 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/cluster/ClusterEventTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/cluster/ClusterEventTest.java @@ -42,7 +42,6 @@ import org.apache.zeppelin.service.ConfigurationService; import org.apache.zeppelin.service.NotebookService; import org.apache.zeppelin.socket.NotebookServer; import org.apache.zeppelin.user.AuthenticationInfo; -import org.apache.zeppelin.utils.TestUtils; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -103,13 +102,13 @@ public class ClusterEventTest extends AbstractTestRestApi { zepServer.addInterpreter("sh"); genClusterAddressConf(zepServer.getZeppelinConfiguration()); zepServer.start(); - notebook = zepServer.getServiceLocator().getService(Notebook.class); - authorizationService = zepServer.getServiceLocator().getService(AuthorizationService.class); + notebook = zepServer.getService(Notebook.class); + authorizationService = zepServer.getService(AuthorizationService.class); ZeppelinConfiguration zconf = zepServer.getZeppelinConfiguration(); schedulerService = new QuartzSchedulerService(zconf, notebook); notebook.initNotebook(); notebook.waitForFinishInit(1, TimeUnit.MINUTES); - notebookServer = spy(NotebookServer.getInstance()); + notebookServer = spy(zepServer.getService(NotebookServer.class)); notebookService = new NotebookService(notebook, authorizationService, zconf, schedulerService); ConfigurationService configurationService = new ConfigurationService(notebook.getConf()); @@ -289,8 +288,8 @@ public class ClusterEventTest extends AbstractTestRestApi { String noteId = null; try { String oldName = "old_name"; - noteId = TestUtils.getInstance(Notebook.class).createNote(oldName, anonymous); - TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = notebook.createNote(oldName, anonymous); + notebook.processNote(noteId, note -> { assertEquals(note.getName(), oldName); return null; @@ -307,7 +306,7 @@ public class ClusterEventTest extends AbstractTestRestApi { Thread.sleep(1000); checkClusterNoteEventListener(); - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, note -> { assertEquals(note.getName(), newName); return null; @@ -319,7 +318,7 @@ public class ClusterEventTest extends AbstractTestRestApi { } finally { // cleanup if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } } } @@ -329,7 +328,7 @@ public class ClusterEventTest extends AbstractTestRestApi { String note1Id = null; String clonedNoteId = null; try { - note1Id = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); + note1Id = notebook.createNote("note1", anonymous); Thread.sleep(1000); CloseableHttpResponse post = httpPost("/notebook/" + note1Id, ""); @@ -358,10 +357,10 @@ public class ClusterEventTest extends AbstractTestRestApi { } finally { // cleanup if (null != note1Id) { - TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous); + notebook.removeNote(note1Id, anonymous); } if (null != clonedNoteId) { - TestUtils.getInstance(Notebook.class).removeNote(clonedNoteId, anonymous); + notebook.removeNote(clonedNoteId, anonymous); } } } @@ -371,8 +370,8 @@ public class ClusterEventTest extends AbstractTestRestApi { String noteId = null; try { // Create note and set result explicitly - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = notebook.createNote("note1", anonymous); + notebook.processNote(noteId, note -> { Paragraph p1 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); InterpreterResult result = new InterpreterResult(InterpreterResult.Code.SUCCESS, @@ -399,7 +398,7 @@ public class ClusterEventTest extends AbstractTestRestApi { } finally { // cleanup if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } } } diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/integration/TestHelper.java b/zeppelin-server/src/test/java/org/apache/zeppelin/integration/TestHelper.java index e4d270c948..f6ea68de4f 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/integration/TestHelper.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/integration/TestHelper.java @@ -32,8 +32,8 @@ public class TestHelper { public static void configureSparkInterpreter(MiniZeppelinServer zepServer, String sparkHome) { await().until(interpreterSettingManagerAvailable(zepServer)); - InterpreterSetting sparkInterpreterSetting = zepServer.getServiceLocator() - .getService(InterpreterSettingManager.class).getInterpreterSettingByName("spark"); + InterpreterSetting sparkInterpreterSetting = + zepServer.getService(InterpreterSettingManager.class).getInterpreterSettingByName("spark"); sparkInterpreterSetting.setProperty("spark.master", "local[*]"); sparkInterpreterSetting.setProperty("SPARK_HOME", sparkHome); sparkInterpreterSetting.close(); @@ -41,6 +41,6 @@ public class TestHelper { private static Callable<Boolean> interpreterSettingManagerAvailable( MiniZeppelinServer zepServer) { - return () -> zepServer.getServiceLocator().getService(InterpreterSettingManager.class) != null; + return () -> zepServer.getService(InterpreterSettingManager.class) != null; } } diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/recovery/RecoveryTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/recovery/RecoveryTest.java index f13a9d9e3e..3512e9376c 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/recovery/RecoveryTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/recovery/RecoveryTest.java @@ -34,7 +34,6 @@ import org.apache.zeppelin.notebook.Paragraph; import org.apache.zeppelin.rest.AbstractTestRestApi; import org.apache.zeppelin.scheduler.Job; import org.apache.zeppelin.user.AuthenticationInfo; -import org.apache.zeppelin.utils.TestUtils; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -90,7 +89,7 @@ class RecoveryTest extends AbstractTestRestApi { @BeforeEach void setUp() { conf = zepServer.getZeppelinConfiguration(); - notebook = zepServer.getServiceLocator().getService(Notebook.class); + notebook = zepServer.getService(Notebook.class); anonymous = new AuthenticationInfo("anonymous"); } @@ -119,7 +118,7 @@ class RecoveryTest extends AbstractTestRestApi { note1 -> { Paragraph p1 = note1.getParagraph(0); assertEquals(Job.Status.FINISHED, p1.getStatus()); - TestUtils.getInstance(Notebook.class).saveNote(note1, anonymous); + notebook.saveNote(note1, anonymous); return null; }); @@ -129,7 +128,7 @@ class RecoveryTest extends AbstractTestRestApi { // run the paragraph again, but change the text to print variable `user` Thread.sleep(10 * 1000); - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { Paragraph p1 = note1.getParagraph(0); p1 = note1.getParagraph(p1.getId()); @@ -139,7 +138,7 @@ class RecoveryTest extends AbstractTestRestApi { post = httpPost("/notebook/job/" + note1Id + "?blocking=true", ""); assertEquals("OK", resp.get("status")); post.close(); - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { Paragraph p1 = note1.getParagraph(0); assertEquals(Job.Status.FINISHED, p1.getStatus()); @@ -151,7 +150,7 @@ class RecoveryTest extends AbstractTestRestApi { throw e; } finally { if (null != note1Id) { - TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous); + notebook.removeNote(note1Id, anonymous); } } } @@ -180,10 +179,10 @@ class RecoveryTest extends AbstractTestRestApi { note1 -> { Paragraph p1 = note1.getParagraph(0); assertEquals(Job.Status.FINISHED, p1.getStatus()); - TestUtils.getInstance(Notebook.class).saveNote(note1, AuthenticationInfo.ANONYMOUS); + notebook.saveNote(note1, AuthenticationInfo.ANONYMOUS); // restart the python interpreter try { - TestUtils.getInstance(Notebook.class).getInterpreterSettingManager().restart( + notebook.getInterpreterSettingManager().restart( ((ManagedInterpreterGroup) p1.getBindedInterpreter().getInterpreterGroup()) .getInterpreterSetting().getId() ); @@ -200,7 +199,7 @@ class RecoveryTest extends AbstractTestRestApi { Thread.sleep(5 * 1000); // run the paragraph again, but change the text to print variable `user`. // can not recover the python interpreter, because it has been shutdown. - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { Paragraph p1 = note1.getParagraph(0); p1.setText("%python print(user)"); @@ -209,7 +208,7 @@ class RecoveryTest extends AbstractTestRestApi { post = httpPost("/notebook/job/" + note1Id + "?blocking=true", ""); assertEquals("OK", resp.get("status")); post.close(); - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { Paragraph p1 = note1.getParagraph(0); assertEquals(Job.Status.ERROR, p1.getStatus()); @@ -220,7 +219,7 @@ class RecoveryTest extends AbstractTestRestApi { throw e; } finally { if (null != note1Id) { - TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous); + notebook.removeNote(note1Id, anonymous); } } } @@ -230,8 +229,8 @@ class RecoveryTest extends AbstractTestRestApi { LOG.info("Test testRecovery_3"); String note1Id = null; try { - note1Id = TestUtils.getInstance(Notebook.class).createNote("note3", AuthenticationInfo.ANONYMOUS); - TestUtils.getInstance(Notebook.class).processNote(note1Id, + note1Id = notebook.createNote("note3", AuthenticationInfo.ANONYMOUS); + notebook.processNote(note1Id, note1 -> { // run python interpreter and create new variable `user` Paragraph p1 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); @@ -245,11 +244,11 @@ class RecoveryTest extends AbstractTestRestApi { new TypeToken<Map<String, Object>>() {}.getType()); assertEquals("OK", resp.get("status")); post.close(); - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { Paragraph p1 = note1.getParagraph(0); assertEquals(Job.Status.FINISHED, p1.getStatus()); - TestUtils.getInstance(Notebook.class).saveNote(note1, AuthenticationInfo.ANONYMOUS); + notebook.saveNote(note1, AuthenticationInfo.ANONYMOUS); return null; }); @@ -260,7 +259,7 @@ class RecoveryTest extends AbstractTestRestApi { Thread.sleep(5 * 1000); // run the paragraph again, but change the text to print variable `user`. // can not recover the python interpreter, because it has been shutdown. - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { Paragraph p1 = note1.getParagraph(0); p1.setText("%python print(user)"); @@ -270,7 +269,7 @@ class RecoveryTest extends AbstractTestRestApi { post = httpPost("/notebook/job/" + note1Id + "?blocking=true", ""); assertEquals("OK", resp.get("status")); post.close(); - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { Paragraph p1 = note1.getParagraph(0); assertEquals(Job.Status.ERROR, p1.getStatus()); @@ -281,7 +280,7 @@ class RecoveryTest extends AbstractTestRestApi { throw e; } finally { if (null != note1Id) { - TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous); + notebook.removeNote(note1Id, anonymous); } } } @@ -299,9 +298,9 @@ class RecoveryTest extends AbstractTestRestApi { LOG.info("Test testRecovery_Running_Paragraph_sh"); String note1Id = null; try { - note1Id = zepServer.getServiceLocator().getService(Notebook.class).createNote("note4", + note1Id = notebook.createNote("note4", AuthenticationInfo.ANONYMOUS); - Paragraph p1 = TestUtils.getInstance(Notebook.class).processNote(note1Id, + Paragraph p1 = notebook.processNote(note1Id, note1 -> { return note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); }); @@ -332,7 +331,7 @@ class RecoveryTest extends AbstractTestRestApi { throw e; } finally { if (null != note1Id) { - TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous); + notebook.removeNote(note1Id, anonymous); } } } @@ -342,15 +341,16 @@ class RecoveryTest extends AbstractTestRestApi { LOG.info("Test testRecovery_Finished_Paragraph_python"); String note1Id = null; try { - InterpreterSettingManager interpreterSettingManager = TestUtils.getInstance(InterpreterSettingManager.class); + InterpreterSettingManager interpreterSettingManager = + zepServer.getService(InterpreterSettingManager.class); InterpreterSetting interpreterSetting = interpreterSettingManager.getInterpreterSettingByName("python"); interpreterSetting.setProperty("zeppelin.python.useIPython", "false"); interpreterSetting.setProperty("zeppelin.interpreter.result.cache", "100"); - note1Id = TestUtils.getInstance(Notebook.class).createNote("note4", AuthenticationInfo.ANONYMOUS); + note1Id = notebook.createNote("note4", AuthenticationInfo.ANONYMOUS); // run paragraph async, print 'hello' after 10 seconds - Paragraph p1 = TestUtils.getInstance(Notebook.class).processNote(note1Id, + Paragraph p1 = notebook.processNote(note1Id, note1 -> { return note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); }); @@ -391,7 +391,7 @@ class RecoveryTest extends AbstractTestRestApi { throw e; } finally { if (null != note1Id) { - TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous); + notebook.removeNote(note1Id, anonymous); } } } diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/HeliumRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/HeliumRestApiTest.java index c28b8d5412..49d537f23d 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/HeliumRestApiTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/HeliumRestApiTest.java @@ -54,7 +54,7 @@ class HeliumRestApiTest extends AbstractTestRestApi { static void init() throws Exception { zepServer = new MiniZeppelinServer(HeliumRestApi.class.getSimpleName()); zepServer.start(); - helium = zepServer.getServiceLocator().getService(Helium.class); + helium = zepServer.getService(Helium.class); } @BeforeEach diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java index 127e88b5a6..4506b05811 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java @@ -31,7 +31,6 @@ import org.apache.zeppelin.notebook.Notebook; import org.apache.zeppelin.notebook.Paragraph; import org.apache.zeppelin.scheduler.Job.Status; import org.apache.zeppelin.user.AuthenticationInfo; -import org.apache.zeppelin.utils.TestUtils; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -60,6 +59,7 @@ class InterpreterRestApiTest extends AbstractTestRestApi { private Gson gson = new Gson(); private AuthenticationInfo anonymous; private static MiniZeppelinServer zepServer; + private Notebook notebook; @BeforeAll static void init() throws Exception { @@ -77,6 +77,7 @@ class InterpreterRestApiTest extends AbstractTestRestApi { @BeforeEach void setUp() { conf = zepServer.getZeppelinConfiguration(); + notebook = zepServer.getService(Notebook.class); anonymous = new AuthenticationInfo("anonymous"); } @@ -88,7 +89,7 @@ class InterpreterRestApiTest extends AbstractTestRestApi { // then assertThat(get, isAllowed()); - assertEquals(TestUtils.getInstance(Notebook.class).getInterpreterSettingManager() + assertEquals(notebook.getInterpreterSettingManager() .getInterpreterSettingTemplates().size(), body.entrySet().size()); get.close(); } @@ -304,9 +305,9 @@ class InterpreterRestApiTest extends AbstractTestRestApi { String noteId = null; try { // when: create new note - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); + noteId = notebook.createNote("note1", anonymous); - String pId = TestUtils.getInstance(Notebook.class).processNote(noteId, + String pId = notebook.processNote(noteId, note -> { Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); Map<String, Object> config = p.getConfig(); @@ -320,21 +321,21 @@ class InterpreterRestApiTest extends AbstractTestRestApi { return p.getId(); }); - Status status = TestUtils.getInstance(Notebook.class).processNote(noteId, + Status status = notebook.processNote(noteId, note -> { Paragraph p = note.getParagraph(pId); return p.getStatus(); }); while (status != Status.FINISHED) { Thread.sleep(100); - status = TestUtils.getInstance(Notebook.class).processNote(noteId, + status = notebook.processNote(noteId, note -> { Paragraph p = note.getParagraph(pId); return p.getStatus(); }); } - List<InterpreterSetting> settings = TestUtils.getInstance(Notebook.class).processNote(noteId, + List<InterpreterSetting> settings = notebook.processNote(noteId, note -> { Paragraph p = note.getParagraph(pId); assertEquals(p.getReturn().message().get(0).getData(), getSimulatedMarkdownResult("markdown")); @@ -353,7 +354,7 @@ class InterpreterRestApiTest extends AbstractTestRestApi { } // when: run markdown paragraph, again - String p2Id = TestUtils.getInstance(Notebook.class).processNote(noteId, + String p2Id = notebook.processNote(noteId, note -> { Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); Map<String, Object> config = p.getConfig(); @@ -367,14 +368,14 @@ class InterpreterRestApiTest extends AbstractTestRestApi { return p.getId(); }); - status = TestUtils.getInstance(Notebook.class).processNote(noteId, + status = notebook.processNote(noteId, note -> { Paragraph p = note.getParagraph(p2Id); return p.getStatus(); }); while (status != Status.FINISHED) { Thread.sleep(100); - status = TestUtils.getInstance(Notebook.class).processNote(noteId, + status = notebook.processNote(noteId, note -> { Paragraph p = note.getParagraph(p2Id); return p.getStatus(); @@ -382,7 +383,7 @@ class InterpreterRestApiTest extends AbstractTestRestApi { } // then - status = TestUtils.getInstance(Notebook.class).processNote(noteId, + status = notebook.processNote(noteId, note -> { Paragraph p = note.getParagraph(p2Id); assertEquals(p.getReturn().message().get(0).getData(), @@ -391,7 +392,7 @@ class InterpreterRestApiTest extends AbstractTestRestApi { }); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } } } @@ -401,8 +402,8 @@ class InterpreterRestApiTest extends AbstractTestRestApi { String noteId = null; try { // when: create new note - noteId = TestUtils.getInstance(Notebook.class).createNote("note2", anonymous); - String pId = TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = notebook.createNote("note2", anonymous); + String pId = notebook.processNote(noteId, note -> { Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); Map<String, Object> config = p.getConfig(); @@ -415,20 +416,20 @@ class InterpreterRestApiTest extends AbstractTestRestApi { return p.getId(); }); - Status status = TestUtils.getInstance(Notebook.class).processNote(noteId, + Status status = notebook.processNote(noteId, note -> { Paragraph p = note.getParagraph(pId); return p.getStatus(); }); while (status != Status.FINISHED) { Thread.sleep(100); - status = TestUtils.getInstance(Notebook.class).processNote(noteId, + status = notebook.processNote(noteId, note -> { Paragraph p = note.getParagraph(pId); return p.getStatus(); }); } - List<InterpreterSetting> settings = TestUtils.getInstance(Notebook.class).processNote(noteId, + List<InterpreterSetting> settings = notebook.processNote(noteId, note -> { Paragraph p = note.getParagraph(pId); assertEquals(p.getReturn().message().get(0).getData(), getSimulatedMarkdownResult("markdown")); @@ -466,7 +467,7 @@ class InterpreterRestApiTest extends AbstractTestRestApi { } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } } } diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java index 2f340070ad..227b8e2df5 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java @@ -24,7 +24,6 @@ import org.apache.zeppelin.interpreter.InterpreterSettingManager; import org.apache.zeppelin.notebook.Notebook; import org.apache.zeppelin.notebook.repo.NotebookRepoWithVersionControl; import org.apache.zeppelin.rest.message.ParametersRequest; -import org.apache.zeppelin.utils.TestUtils; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -63,7 +62,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { private static final Logger LOG = LoggerFactory.getLogger(NotebookRestApiTest.class); Gson gson = new Gson(); AuthenticationInfo anonymous; - + private Notebook notebook; private static MiniZeppelinServer zepServer; @BeforeAll @@ -85,6 +84,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { @BeforeEach void setUp() { conf = zepServer.getZeppelinConfiguration(); + notebook = zepServer.getService(Notebook.class); anonymous = new AuthenticationInfo("anonymous"); } @@ -93,11 +93,11 @@ class NotebookRestApiTest extends AbstractTestRestApi { LOG.info("Running testGetNote"); String note1Id = null; try { - note1Id = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - TestUtils.getInstance(Notebook.class).processNote(note1Id, + note1Id = notebook.createNote("note1", anonymous); + notebook.processNote(note1Id, note1 -> { note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); - TestUtils.getInstance(Notebook.class).saveNote(note1, anonymous); + notebook.saveNote(note1, anonymous); return null; }); @@ -109,7 +109,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { assertEquals(1, ((List)noteObject.get("paragraphs")).size()); // add one new paragraph, but don't save it and reload it again - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); return null; @@ -125,7 +125,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { } finally { // cleanup if (null != note1Id) { - TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous); + notebook.removeNote(note1Id, anonymous); } } } @@ -136,11 +136,11 @@ class NotebookRestApiTest extends AbstractTestRestApi { String note1Id = null; try { String notePath = "dir1/note1"; - note1Id = TestUtils.getInstance(Notebook.class).createNote(notePath, anonymous); - TestUtils.getInstance(Notebook.class).processNote(note1Id, + note1Id = notebook.createNote(notePath, anonymous); + notebook.processNote(note1Id, note1 -> { note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); - TestUtils.getInstance(Notebook.class).saveNote(note1, anonymous); + notebook.saveNote(note1, anonymous); return null; }); @@ -155,7 +155,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { } finally { // cleanup if (null != note1Id) { - TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous); + notebook.removeNote(note1Id, anonymous); } } } @@ -177,7 +177,6 @@ class NotebookRestApiTest extends AbstractTestRestApi { void testGetNoteRevisionHistory() throws IOException { LOG.info("Running testGetNoteRevisionHistory"); String note1Id = null; - Notebook notebook = TestUtils.getInstance(Notebook.class); try { String notePath = "note1"; note1Id = notebook.createNote(notePath, anonymous); @@ -238,7 +237,6 @@ class NotebookRestApiTest extends AbstractTestRestApi { void testGetNoteByRevision() throws IOException { LOG.info("Running testGetNoteByRevision"); String note1Id = null; - Notebook notebook = TestUtils.getInstance(Notebook.class); try { String notePath = "note1"; note1Id = notebook.createNote(notePath, anonymous); @@ -284,8 +282,8 @@ class NotebookRestApiTest extends AbstractTestRestApi { LOG.info("Running testGetNoteParagraphJobStatus"); String note1Id = null; try { - note1Id = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - String paragraphId = TestUtils.getInstance(Notebook.class).processNote(note1Id, + note1Id = notebook.createNote("note1", anonymous); + String paragraphId = notebook.processNote(note1Id, note1 -> { return note1.addNewParagraph(AuthenticationInfo.ANONYMOUS).getId(); }); @@ -303,7 +301,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { } finally { // cleanup if (null != note1Id) { - TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous); + notebook.removeNote(note1Id, anonymous); } } } @@ -312,7 +310,6 @@ class NotebookRestApiTest extends AbstractTestRestApi { void testCheckpointNote() throws IOException { LOG.info("Running testCheckpointNote"); String note1Id = null; - Notebook notebook = TestUtils.getInstance(Notebook.class); try { String notePath = "note1"; note1Id = notebook.createNote(notePath, anonymous); @@ -356,7 +353,6 @@ class NotebookRestApiTest extends AbstractTestRestApi { void testSetNoteRevision() throws IOException { LOG.info("Running testSetNoteRevision"); String note1Id = null; - Notebook notebook = TestUtils.getInstance(Notebook.class); try { String notePath = "note1"; note1Id = notebook.createNote(notePath, anonymous); @@ -406,8 +402,8 @@ class NotebookRestApiTest extends AbstractTestRestApi { LOG.info("Running testRunParagraphJob"); String note1Id = null; try { - note1Id = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - Paragraph p = TestUtils.getInstance(Notebook.class).processNote(note1Id, + note1Id = notebook.createNote("note1", anonymous); + Paragraph p = notebook.processNote(note1Id, note1 -> { return note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); }); @@ -436,7 +432,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { } finally { // cleanup if (null != note1Id) { - TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous); + notebook.removeNote(note1Id, anonymous); } } } @@ -445,7 +441,6 @@ class NotebookRestApiTest extends AbstractTestRestApi { void testCancelNoteJob() throws Exception { LOG.info("Running testCancelNoteJob"); String note1Id = null; - Notebook notebook = TestUtils.getInstance(Notebook.class); try { note1Id = notebook.createNote("note1", anonymous); // Add 3 paragraphs for the note. @@ -490,8 +485,8 @@ class NotebookRestApiTest extends AbstractTestRestApi { LOG.info("Running testRunParagraphSynchronously"); String note1Id = null; try { - note1Id = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - Paragraph p = TestUtils.getInstance(Notebook.class).processNote(note1Id, + note1Id = notebook.createNote("note1", anonymous); + Paragraph p = notebook.processNote(note1Id, note1 -> { return note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); }); @@ -538,7 +533,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { } finally { // cleanup if (null != note1Id) { - TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous); + notebook.removeNote(note1Id, anonymous); } } } @@ -555,7 +550,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { assertEquals("OK", resp1.get("status")); String note1Id = (String) resp1.get("body"); - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { assertEquals("test1", note1.getName()); assertEquals(1, note1.getParagraphCount()); @@ -574,7 +569,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { assertEquals("OK", resp2.get("status")); String noteId2 = (String) resp2.get("body"); - Note note2 = TestUtils.getInstance(Notebook.class).processNote(noteId2, + Note note2 = notebook.processNote(noteId2, note -> { return note; }); @@ -587,7 +582,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { LOG.info("Running testRunNoteBlocking"); String note1Id = null; try { - note1Id = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); + note1Id = notebook.createNote("note1", anonymous); // 2 paragraphs // P1: // %python @@ -599,7 +594,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { // %python // print(user) // - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { Paragraph p1 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); Paragraph p2 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); @@ -615,7 +610,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { assertEquals("OK", resp.get("status")); post.close(); - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { Paragraph p1 = note1.getParagraph(0); Paragraph p2 = note1.getParagraph(1); @@ -627,7 +622,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { } finally { // cleanup if (null != note1Id) { - TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous); + notebook.removeNote(note1Id, anonymous); } } } @@ -637,7 +632,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { LOG.info("Running testRunNoteNonBlocking"); String note1Id = null; try { - note1Id = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); + note1Id = notebook.createNote("note1", anonymous); // 2 paragraphs // P1: // %python @@ -649,7 +644,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { // %%sh(interpolate=true) // echo '{name}' // - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { Paragraph p1 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); Paragraph p2 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); @@ -665,7 +660,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { assertEquals("OK", resp.get("status")); post.close(); - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { Paragraph p1 = note1.getParagraph(0); Paragraph p2 = note1.getParagraph(1); @@ -683,7 +678,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { } finally { // cleanup if (null != note1Id) { - TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous); + notebook.removeNote(note1Id, anonymous); } } } @@ -693,12 +688,11 @@ class NotebookRestApiTest extends AbstractTestRestApi { LOG.info("Running testRunNoteBlocking_Isolated"); String note1Id = null; try { - InterpreterSettingManager interpreterSettingManager = - TestUtils.getInstance(InterpreterSettingManager.class); + InterpreterSettingManager interpreterSettingManager = notebook.getInterpreterSettingManager(); InterpreterSetting interpreterSetting = interpreterSettingManager.getInterpreterSettingByName("python"); int pythonProcessNum = interpreterSetting.getAllInterpreterGroups().size(); - note1Id = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); + note1Id = notebook.createNote("note1", anonymous); // 2 paragraphs // P1: // %python @@ -710,7 +704,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { // %python // print(user) // - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { Paragraph p1 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); Paragraph p2 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); @@ -726,7 +720,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { assertEquals("OK", resp.get("status")); post.close(); - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { Paragraph p1 = note1.getParagraph(0); Paragraph p2 = note1.getParagraph(1); @@ -740,7 +734,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { } finally { // cleanup if (null != note1Id) { - TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous); + notebook.removeNote(note1Id, anonymous); } } } @@ -750,12 +744,11 @@ class NotebookRestApiTest extends AbstractTestRestApi { LOG.info("Running testRunNoteNonBlocking_Isolated"); String note1Id = null; try { - InterpreterSettingManager interpreterSettingManager = - TestUtils.getInstance(InterpreterSettingManager.class); + InterpreterSettingManager interpreterSettingManager = notebook.getInterpreterSettingManager(); InterpreterSetting interpreterSetting = interpreterSettingManager.getInterpreterSettingByName("python"); int pythonProcessNum = interpreterSetting.getAllInterpreterGroups().size(); - note1Id = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); + note1Id = notebook.createNote("note1", anonymous); // 2 paragraphs // P1: // %python @@ -767,7 +760,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { // %python // print(user) // - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { Paragraph p1 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); Paragraph p2 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); @@ -785,12 +778,12 @@ class NotebookRestApiTest extends AbstractTestRestApi { post.close(); // wait for all the paragraphs are done - boolean isRunning = TestUtils.getInstance(Notebook.class).processNote(note1Id, Note::isRunning); + boolean isRunning = notebook.processNote(note1Id, Note::isRunning); while(isRunning) { Thread.sleep(1000); - isRunning = TestUtils.getInstance(Notebook.class).processNote(note1Id, Note::isRunning); + isRunning = notebook.processNote(note1Id, Note::isRunning); } - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { Paragraph p1 = note1.getParagraph(0); Paragraph p2 = note1.getParagraph(1); @@ -805,7 +798,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { } finally { // cleanup if (null != note1Id) { - TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous); + notebook.removeNote(note1Id, anonymous); } } } @@ -814,7 +807,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { void testRunNoteWithParams() throws IOException, InterruptedException { String note1Id = null; try { - note1Id = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); + note1Id = notebook.createNote("note1", anonymous); // 2 paragraphs // P1: // %python @@ -824,7 +817,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { // %sh // echo ${name|world} // - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { Paragraph p1 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); Paragraph p2 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); @@ -845,12 +838,12 @@ class NotebookRestApiTest extends AbstractTestRestApi { post.close(); // wait for all the paragraphs are done - boolean isRunning = TestUtils.getInstance(Notebook.class).processNote(note1Id, Note::isRunning); + boolean isRunning = notebook.processNote(note1Id, Note::isRunning); while(isRunning) { Thread.sleep(1000); - isRunning = TestUtils.getInstance(Notebook.class).processNote(note1Id, Note::isRunning); + isRunning = notebook.processNote(note1Id, Note::isRunning); } - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { Paragraph p1 = note1.getParagraph(0); Paragraph p2 = note1.getParagraph(1); @@ -870,12 +863,12 @@ class NotebookRestApiTest extends AbstractTestRestApi { post.close(); // wait for all the paragraphs are done - isRunning = TestUtils.getInstance(Notebook.class).processNote(note1Id, Note::isRunning); + isRunning = notebook.processNote(note1Id, Note::isRunning); while(isRunning) { Thread.sleep(1000); - isRunning = TestUtils.getInstance(Notebook.class).processNote(note1Id, Note::isRunning); + isRunning = notebook.processNote(note1Id, Note::isRunning); } - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { Paragraph p1 = note1.getParagraph(0); Paragraph p2 = note1.getParagraph(1); @@ -888,7 +881,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { } finally { // cleanup if (null != note1Id) { - TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous); + notebook.removeNote(note1Id, anonymous); } } } @@ -898,7 +891,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { LOG.info("Running testRunAllParagraph_FirstFailed"); String note1Id = null; try { - note1Id = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); + note1Id = notebook.createNote("note1", anonymous); // 2 paragraphs // P1: // %python @@ -912,7 +905,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { // user2='abc' // print(user2) // - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { Paragraph p1 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); Paragraph p2 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); @@ -926,7 +919,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { assertThat(post, isAllowed()); post.close(); - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { Paragraph p1 = note1.getParagraph(0); Paragraph p2 = note1.getParagraph(1); @@ -938,7 +931,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { } finally { // cleanup if (null != note1Id) { - TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous); + notebook.removeNote(note1Id, anonymous); } } } @@ -951,7 +944,6 @@ class NotebookRestApiTest extends AbstractTestRestApi { String text1 = "%text clone note"; String text2 = "%text clone revision of note"; try { - Notebook notebook = TestUtils.getInstance(Notebook.class); note1Id = notebook.createNote("note1", anonymous); // add text and commit note @@ -1004,11 +996,11 @@ class NotebookRestApiTest extends AbstractTestRestApi { } finally { // cleanup if (null != note1Id) { - TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous); + notebook.removeNote(note1Id, anonymous); } if (null != clonedNoteIds) { for (String clonedNoteId : clonedNoteIds) { - TestUtils.getInstance(Notebook.class).removeNote(clonedNoteId, anonymous); + notebook.removeNote(clonedNoteId, anonymous); } } } @@ -1020,8 +1012,8 @@ class NotebookRestApiTest extends AbstractTestRestApi { String noteId = null; try { String oldName = "old_name"; - noteId = TestUtils.getInstance(Notebook.class).createNote(oldName, anonymous); - assertEquals(oldName, TestUtils.getInstance(Notebook.class).processNote(noteId, Note::getName)); + noteId = notebook.createNote(oldName, anonymous); + assertEquals(oldName, notebook.processNote(noteId, Note::getName)); final String newName = "testName"; String jsonRequest = "{\"name\": " + newName + "}"; @@ -1030,11 +1022,11 @@ class NotebookRestApiTest extends AbstractTestRestApi { assertThat("test testRenameNote:", put, isAllowed()); put.close(); - assertEquals(newName, TestUtils.getInstance(Notebook.class).processNote(noteId, Note::getName)); + assertEquals(newName, notebook.processNote(noteId, Note::getName)); } finally { // cleanup if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } } } @@ -1044,8 +1036,8 @@ class NotebookRestApiTest extends AbstractTestRestApi { LOG.info("Running testUpdateParagraphConfig"); String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - String paragraphId = TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = notebook.createNote("note1", anonymous); + String paragraphId = notebook.processNote(noteId, note -> { Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); assertNull(p.getConfig().get("colWidth")); @@ -1065,7 +1057,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { put.close(); assertEquals(config.get("colWidth"), 6.0); - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, note -> { assertEquals(note.getParagraph(paragraphId).getConfig().get("colWidth"), 6.0); return null; @@ -1073,7 +1065,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { } finally { // cleanup if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } } } @@ -1084,8 +1076,8 @@ class NotebookRestApiTest extends AbstractTestRestApi { String noteId = null; try { // Create note and set result explicitly - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); - String p1Id = TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = notebook.createNote("note1", anonymous); + String p1Id = notebook.processNote(noteId, note -> { Paragraph p1 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); InterpreterResult result = new InterpreterResult(InterpreterResult.Code.SUCCESS, @@ -1094,7 +1086,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { return p1.getId(); }); - String p2Id = TestUtils.getInstance(Notebook.class).processNote(noteId, + String p2Id = notebook.processNote(noteId, note -> { Paragraph p2 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); InterpreterResult result = new InterpreterResult(InterpreterResult.Code.SUCCESS, @@ -1128,7 +1120,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { } finally { // cleanup if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } } } @@ -1138,7 +1130,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { LOG.info("Running testRunWithServerRestart"); String note1Id = null; try { - note1Id = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); + note1Id = notebook.createNote("note1", anonymous); // 2 paragraphs // P1: // %python @@ -1150,7 +1142,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { // %python // print(user) // - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { Paragraph p1 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); Paragraph p2 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); @@ -1178,7 +1170,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { new TypeToken<Map<String, Object>>() {}.getType()); assertEquals("OK", resp.get("status")); post2.close(); - TestUtils.getInstance(Notebook.class).processNote(note1Id, + notebook.processNote(note1Id, note1 -> { Paragraph p1 = note1.getParagraph(0); Paragraph p2 = note1.getParagraph(1); @@ -1191,7 +1183,7 @@ class NotebookRestApiTest extends AbstractTestRestApi { } finally { // cleanup if (null != note1Id) { - TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous); + notebook.removeNote(note1Id, anonymous); } } } diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookSecurityRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookSecurityRestApiTest.java index 564711b01a..14dec8210b 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookSecurityRestApiTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookSecurityRestApiTest.java @@ -28,7 +28,6 @@ import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.util.EntityUtils; import org.apache.zeppelin.MiniZeppelinServer; import org.apache.zeppelin.notebook.Notebook; -import org.apache.zeppelin.utils.TestUtils; import org.hamcrest.Matcher; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -44,6 +43,7 @@ public class NotebookSecurityRestApiTest extends AbstractTestRestApi { Gson gson = new Gson(); private static MiniZeppelinServer zepServer; + private Notebook notebook; @BeforeAll public static void init() throws Exception { @@ -58,6 +58,7 @@ public class NotebookSecurityRestApiTest extends AbstractTestRestApi { @BeforeEach void setup() { + notebook = zepServer.getService(Notebook.class); conf = zepServer.getZeppelinConfiguration(); } @@ -111,7 +112,7 @@ public class NotebookSecurityRestApiTest extends AbstractTestRestApi { userTryRemoveNote(noteId, "user2", "password3", isForbidden()); userTryRemoveNote(noteId, "user1", "password2", isAllowed()); - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, deletedNote -> { assertNull(deletedNote, "Deleted note should be null"); return null; @@ -150,7 +151,6 @@ public class NotebookSecurityRestApiTest extends AbstractTestRestApi { EntityUtils.toString(post.getEntity(), StandardCharsets.UTF_8), new TypeToken<Map<String, Object>>() {}.getType()); post.close(); String newNoteId = (String) resp.get("body"); - Notebook notebook = TestUtils.getInstance(Notebook.class); notebook.processNote(newNoteId, newNote -> { assertNotNull(newNote, "Can not find new note by id"); @@ -165,7 +165,7 @@ public class NotebookSecurityRestApiTest extends AbstractTestRestApi { delete.close(); // make sure note is deleted if (!noteId.isEmpty()) { - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, deletedNote -> { assertNull(deletedNote, "Deleted note should be null"); return null; diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java index 8abb03ce8f..cc61de492a 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java @@ -26,7 +26,6 @@ import org.apache.zeppelin.notebook.AuthorizationService; import org.apache.zeppelin.notebook.Notebook; import org.apache.zeppelin.rest.message.NoteJobStatus; import org.apache.zeppelin.test.DownloadUtils; -import org.apache.zeppelin.utils.TestUtils; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -69,6 +68,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { Gson gson = new Gson(); AuthenticationInfo anonymous; private static MiniZeppelinServer zepServer; + private Notebook notebook; @BeforeAll public static void init() throws Exception { @@ -90,6 +90,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { @BeforeEach void setUp() { conf = zepServer.getZeppelinConfiguration(); + notebook = zepServer.getService(Notebook.class); anonymous = new AuthenticationInfo("anonymous"); } @@ -111,10 +112,10 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { String noteId = null; try { // Create note to get info - noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); + noteId = notebook.createNote("note1", anonymous); assertNotNull("can't create new note", noteId); // use write lock because name is overwritten - String paragraphText = TestUtils.getInstance(Notebook.class).processNote(noteId, + String paragraphText = notebook.processNote(noteId, note -> { note.setName("note"); Paragraph paragraph = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); @@ -123,7 +124,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { paragraph.setConfig(config); String paragraphTextTmp = "%md This is my new paragraph in my new note"; paragraph.setText(paragraphTextTmp); - TestUtils.getInstance(Notebook.class).saveNote(note, anonymous); + notebook.saveNote(note, anonymous); return paragraphTextTmp; }); @@ -147,7 +148,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { get.close(); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } } } @@ -184,7 +185,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { String newNoteId = (String) resp.get("body"); LOG.info("newNoteId:=" + newNoteId); - TestUtils.getInstance(Notebook.class).processNote(newNoteId, + notebook.processNote(newNoteId, newNote -> { assertNotNull(newNote, "Can not find new note by id"); // This is partial test as newNote is in memory but is not persistent @@ -214,7 +215,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { }); // cleanup - TestUtils.getInstance(Notebook.class).removeNote(newNoteId, anonymous); + notebook.removeNote(newNoteId, anonymous); post.close(); } @@ -231,7 +232,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { String newNoteId = (String) resp.get("body"); LOG.info("newNoteId:=" + newNoteId); - TestUtils.getInstance(Notebook.class).processNote(newNoteId, + notebook.processNote(newNoteId, newNote -> { assertNotNull(newNote, "Can not find new note by id"); // This is partial test as newNote is in memory but is not persistent @@ -245,7 +246,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { return null; }); // cleanup - TestUtils.getInstance(Notebook.class).removeNote(newNoteId, anonymous); + notebook.removeNote(newNoteId, anonymous); post.close(); } @@ -255,11 +256,11 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { String noteId = null; try { //Create note and get ID - noteId = TestUtils.getInstance(Notebook.class).createNote("note1_testDeletedNote", anonymous); + noteId = notebook.createNote("note1_testDeletedNote", anonymous); testDeleteNote(noteId); } finally { if (noteId != null) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } } } @@ -276,9 +277,9 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1_testExportNote", anonymous); + noteId = notebook.createNote("note1_testExportNote", anonymous); // use write lock because name is overwritten - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, note -> { assertNotNull(note, "can't create new note"); note.setName("source note for export"); @@ -287,7 +288,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { config.put("enabled", true); paragraph.setConfig(config); paragraph.setText("%md This is my new paragraph in my new note"); - TestUtils.getInstance(Notebook.class).saveNote(note, anonymous); + notebook.saveNote(note, anonymous); return null; }); @@ -307,7 +308,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { get.close(); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } } } @@ -323,9 +324,9 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { noteName = "source note for import"; LOG.info("testImportNote"); // create test note - noteId = TestUtils.getInstance(Notebook.class).createNote("note1_testImportNotebook", anonymous); + noteId = notebook.createNote("note1_testImportNotebook", anonymous); // use write lock because name is overwritten - int paragraphSize = TestUtils.getInstance(Notebook.class).processNote(noteId, + int paragraphSize = notebook.processNote(noteId, note -> { assertNotNull(note, "can't create new note"); note.setName(noteName); @@ -334,14 +335,14 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { config.put("enabled", true); paragraph.setConfig(config); paragraph.setText("%md This is my new paragraph in my new note"); - TestUtils.getInstance(Notebook.class).saveNote(note, anonymous); + notebook.saveNote(note, anonymous); return note.getParagraphs().size(); }); // get note content as JSON oldJson = getNoteContent(noteId); // delete it first then import it - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); // call note post CloseableHttpResponse importPost = httpPost("/notebook/import/", oldJson); @@ -352,7 +353,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { importId = (String) resp.get("body"); assertNotNull("Did not get back a note id in body", importId); - TestUtils.getInstance(Notebook.class).processNote(importId, + notebook.processNote(importId, newNote -> { assertEquals(noteName, newNote.getName(), "Compare note names"); assertEquals(paragraphSize, newNote.getParagraphs().size(), "Compare paragraphs count"); @@ -361,9 +362,9 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { importPost.close(); } finally { if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } - TestUtils.getInstance(Notebook.class).removeNote(importId, anonymous); + notebook.removeNote(importId, anonymous); } } @@ -387,7 +388,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { delete.close(); // make sure note is deleted if (!noteId.isEmpty()) { - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, deletedNote -> { assertNull(deletedNote, "Deleted note should be null"); return null; @@ -409,8 +410,8 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { String newNoteId = null; try { // Create note to clone - noteId = TestUtils.getInstance(Notebook.class).createNote("note1_testCloneNote", anonymous); - int paragraphSize = TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = notebook.createNote("note1_testCloneNote", anonymous); + int paragraphSize = notebook.processNote(noteId, note -> { assertNotNull(note, "can't create new note"); note.setName("source note for clone"); @@ -419,7 +420,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { config.put("enabled", true); paragraph.setConfig(config); paragraph.setText("%md This is my new paragraph in my new note"); - TestUtils.getInstance(Notebook.class).saveNote(note, anonymous); + notebook.saveNote(note, anonymous); return note.getParagraphs().size(); }); @@ -436,7 +437,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { newNoteId = (String) resp.get("body"); LOG.info("newNoteId:=" + newNoteId); - TestUtils.getInstance(Notebook.class).processNote(newNoteId, + notebook.processNote(newNoteId, newNote -> { assertNotNull(newNote, "Can not find new note by id"); assertEquals(noteName, newNote.getName(), "Compare note names"); @@ -448,9 +449,9 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { } finally { //cleanup if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } - TestUtils.getInstance(Notebook.class).removeNote(newNoteId, anonymous); + notebook.removeNote(newNoteId, anonymous); } } @@ -464,8 +465,8 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { List<Map<String, String>> body = (List<Map<String, String>>) resp.get("body"); //TODO(khalid): anonymous or specific user notes? HashSet<String> anonymous = new HashSet<>(Arrays.asList("anonymous")); - AuthorizationService authorizationService = TestUtils.getInstance(AuthorizationService.class); - assertEquals(TestUtils.getInstance(Notebook.class) + AuthorizationService authorizationService = zepServer.getService(AuthorizationService.class); + assertEquals(notebook .getNotesInfo(noteId -> authorizationService.isReader(noteId, anonymous)) .size(), body.size(), "List notes are equal"); get.close(); @@ -478,9 +479,9 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { String noteId = null; try { // Create note to run test. - noteId = TestUtils.getInstance(Notebook.class).createNote("note1_testNoteJobs", anonymous); + noteId = notebook.createNote("note1_testNoteJobs", anonymous); // use write lock because name is overwritten - String paragraphId = TestUtils.getInstance(Notebook.class).processNote(noteId, + String paragraphId = notebook.processNote(noteId, note -> { assertNotNull(note, "can't create new note"); note.setName("note for run test"); @@ -491,11 +492,11 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { paragraph.setConfig(config); paragraph.setText("%md This is test paragraph."); - TestUtils.getInstance(Notebook.class).saveNote(note, anonymous); + notebook.saveNote(note, anonymous); return paragraph.getId(); }); - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, note -> { try { note.runAll(anonymous, true, false, new HashMap<>()); @@ -507,10 +508,11 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { // wait until job is finished or timeout. int timeout = 1; - boolean terminated = TestUtils.getInstance(Notebook.class).processNote(noteId, note -> note.getParagraph(0).isTerminated()); + boolean terminated = + notebook.processNote(noteId, note -> note.getParagraph(0).isTerminated()); while (!terminated) { Thread.sleep(1000); - terminated = TestUtils.getInstance(Notebook.class).processNote(noteId, note -> note.getParagraph(0).isTerminated()); + terminated = notebook.processNote(noteId, note -> note.getParagraph(0).isTerminated()); if (timeout++ > 10) { LOG.info("testNoteJobs timeout job."); break; @@ -542,7 +544,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { } finally { //cleanup if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } } } @@ -554,9 +556,9 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { String noteId = null; try { // Create note to run test. - noteId = TestUtils.getInstance(Notebook.class).createNote("note1_testGetNoteJob", anonymous); + noteId = notebook.createNote("note1_testGetNoteJob", anonymous); // use write lock because name is overwritten - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, note -> { assertNotNull(note, "can't create new note"); note.setName("note for run test"); @@ -568,11 +570,11 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { paragraph.setText("%sh sleep 1"); paragraph.setAuthenticationInfo(anonymous); - TestUtils.getInstance(Notebook.class).saveNote(note, anonymous); + notebook.saveNote(note, anonymous); return null; }); - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, note -> { try { note.runAll(anonymous, true, false, new HashMap<>()); @@ -598,10 +600,11 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { // wait until job is finished or timeout. int timeout = 1; - boolean terminated = TestUtils.getInstance(Notebook.class).processNote(noteId, note -> note.getParagraph(0).isTerminated()); + boolean terminated = + notebook.processNote(noteId, note -> note.getParagraph(0).isTerminated()); while (!terminated) { Thread.sleep(100); - terminated = TestUtils.getInstance(Notebook.class).processNote(noteId, note -> note.getParagraph(0).isTerminated()); + terminated = notebook.processNote(noteId, note -> note.getParagraph(0).isTerminated()); if (timeout++ > 10) { LOG.info("testGetNoteJob timeout job."); break; @@ -610,7 +613,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { } finally { //cleanup if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } } } @@ -622,9 +625,9 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { String noteId = null; try { // Create note to run test. - noteId = TestUtils.getInstance(Notebook.class).createNote("note1_testRunParagraphWithParams", anonymous); + noteId = notebook.createNote("note1_testRunParagraphWithParams", anonymous); // use write lock because name is overwritten - String paragraphId = TestUtils.getInstance(Notebook.class).processNote(noteId, + String paragraphId = notebook.processNote(noteId, note -> { assertNotNull(note, "can't create new note"); note.setName("note for run test"); @@ -635,12 +638,12 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { paragraph.setConfig(config); paragraph.setText("%spark\nval param = z.input(\"param\").toString\nprintln(param)"); - TestUtils.getInstance(Notebook.class).saveNote(note, anonymous); + notebook.saveNote(note, anonymous); return paragraph.getId(); }); - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, note -> { try { note.runAll(anonymous, true, false, new HashMap<>()); @@ -657,7 +660,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { postParagraph.close(); Thread.sleep(1000); - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, retrNote -> { Paragraph retrParagraph = retrNote.getParagraph(paragraphId); Map<String, Object> params = retrParagraph.settings.getParams(); @@ -668,7 +671,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { } finally { //cleanup if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } } } @@ -680,9 +683,9 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { String noteId = null; try { System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_CRON_ENABLE.getVarName(), "true"); - noteId = TestUtils.getInstance(Notebook.class).createNote("note1_testJobs", anonymous); + noteId = notebook.createNote("note1_testJobs", anonymous); // Use write lock, because name is overwritten - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, note -> { note.setName("note for run test"); Paragraph paragraph = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); @@ -694,7 +697,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { return null; }); - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, note -> { try { note.runAll(AuthenticationInfo.ANONYMOUS, false, false, new HashMap<>()); @@ -730,7 +733,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { } finally { //cleanup if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } System.clearProperty(ConfVars.ZEPPELIN_NOTEBOOK_CRON_ENABLE.getVarName()); } @@ -743,9 +746,9 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { try { // create a note and a paragraph System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_CRON_ENABLE.getVarName(), "false"); - noteId = TestUtils.getInstance(Notebook.class).createNote("note1_testCronDisable", anonymous); + noteId = notebook.createNote("note1_testCronDisable", anonymous); // use write lock because Name is overwritten - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, note -> { note.setName("note for run test"); Paragraph paragraph = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); @@ -757,7 +760,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { return null; }); - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, note -> { try { note.runAll(AuthenticationInfo.ANONYMOUS, true, true, new HashMap<>()); @@ -778,12 +781,12 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_CRON_FOLDERS.getVarName(), "/System"); // use write lock, because Name is overwritten - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, note -> { note.setName("System/test2"); return null; }); - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, note -> { try { note.runAll(AuthenticationInfo.ANONYMOUS, true, true, new HashMap<>()); @@ -807,7 +810,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { } finally { //cleanup if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } System.clearProperty(ConfVars.ZEPPELIN_NOTEBOOK_CRON_ENABLE.getVarName()); } @@ -817,9 +820,9 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { void testRegressionZEPPELIN_527() throws Exception { String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1_testRegressionZEPPELIN_527", anonymous); + noteId = notebook.createNote("note1_testRegressionZEPPELIN_527", anonymous); // use write lock because name is overwritten - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, note -> { note.setName("note for run test"); Paragraph paragraph = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); @@ -827,11 +830,11 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { return null; }); - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, note -> { try { note.runAll(AuthenticationInfo.ANONYMOUS, true, false, new HashMap<>()); - TestUtils.getInstance(Notebook.class).saveNote(note, anonymous); + notebook.saveNote(note, anonymous); } catch (Exception e) { fail(); } @@ -851,7 +854,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { } finally { //cleanup if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } } } @@ -860,7 +863,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { void testInsertParagraph() throws IOException { String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1_testInsertParagraph", anonymous); + noteId = notebook.createNote("note1_testInsertParagraph", anonymous); String jsonRequest = "{\"title\": \"title1\", \"text\": \"text1\"}"; CloseableHttpResponse post = httpPost("/notebook/" + noteId + "/paragraph", jsonRequest); @@ -875,8 +878,8 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { String newParagraphId = (String) resp.get("body"); LOG.info("newParagraphId:=" + newParagraphId); - Paragraph lastParagraph = TestUtils.getInstance(Notebook.class).processNote(noteId, Note::getLastParagraph); - TestUtils.getInstance(Notebook.class).processNote(noteId, + Paragraph lastParagraph = notebook.processNote(noteId, Note::getLastParagraph); + notebook.processNote(noteId, retrNote -> { Paragraph newParagraph = retrNote.getParagraph(newParagraphId); assertNotNull(newParagraph, "Can not find new paragraph by id"); @@ -893,7 +896,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { assertThat("Test insert method:", post2, isAllowed()); post2.close(); - Paragraph paragraphAtIdx0 =TestUtils.getInstance(Notebook.class).processNote(noteId, note -> note.getParagraphs().get(0)); + Paragraph paragraphAtIdx0 = notebook.processNote(noteId, note -> note.getParagraphs().get(0)); assertEquals("title2", paragraphAtIdx0.getTitle()); assertEquals("text2", paragraphAtIdx0.getText()); @@ -906,7 +909,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { assertThat("Test insert method:", post3, isAllowed()); post3.close(); - Paragraph p = TestUtils.getInstance(Notebook.class).processNote(noteId, Note::getLastParagraph); + Paragraph p = notebook.processNote(noteId, Note::getLastParagraph); assertEquals("title3", p.getTitle()); assertEquals("text3", p.getText()); Map result = ((List<Map>) p.getConfig().get("results")).get(0); @@ -917,7 +920,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { } finally { //cleanup if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } } } @@ -926,7 +929,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { void testUpdateParagraph() throws IOException { String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1_testUpdateParagraph", anonymous); + noteId = notebook.createNote("note1_testUpdateParagraph", anonymous); String jsonRequest = "{\"title\": \"title1\", \"text\": \"text1\"}"; CloseableHttpResponse post = httpPost("/notebook/" + noteId + "/paragraph", jsonRequest); @@ -935,7 +938,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { post.close(); String newParagraphId = (String) resp.get("body"); - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, noteP -> { Paragraph newParagraph = noteP.getParagraph(newParagraphId); assertEquals("title1", newParagraph.getTitle()); @@ -949,7 +952,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { assertThat("Test update method:", put, isAllowed()); put.close(); - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, noteP -> { Paragraph updatedParagraph = noteP.getParagraph(newParagraphId); assertEquals("title1", updatedParagraph.getTitle()); @@ -962,7 +965,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { updateBothRequest); updatePut.close(); - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, noteP -> { Paragraph updatedBothParagraph = noteP.getParagraph(newParagraphId); assertEquals("updated title", updatedBothParagraph.getTitle()); @@ -972,7 +975,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { } finally { //cleanup if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } } } @@ -981,13 +984,13 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { void testGetParagraph() throws IOException { String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1_testGetParagraph", anonymous); - String pId = TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = notebook.createNote("note1_testGetParagraph", anonymous); + String pId = notebook.processNote(noteId, note -> { Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); p.setTitle("hello"); p.setText("world"); - TestUtils.getInstance(Notebook.class).saveNote(note, anonymous); + notebook.saveNote(note, anonymous); return p.getId(); }); @@ -1011,7 +1014,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { } finally { //cleanup if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } } } @@ -1020,8 +1023,8 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { void testMoveParagraph() throws IOException { String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1_testMoveParagraph", anonymous); - Paragraph p2 = TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = notebook.createNote("note1_testMoveParagraph", anonymous); + Paragraph p2 = notebook.processNote(noteId, note -> { Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); p.setTitle("title1"); @@ -1029,7 +1032,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { Paragraph p2tmp = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); p2tmp.setTitle("title2"); p2tmp.setText("text2"); - TestUtils.getInstance(Notebook.class).saveNote(note, anonymous); + notebook.saveNote(note, anonymous); return p2tmp; }); @@ -1038,7 +1041,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { assertThat("Test post method: ", post, isAllowed()); post.close(); - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, retrNote -> { Paragraph paragraphAtIdx0 = retrNote.getParagraphs().get(0); @@ -1056,7 +1059,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { } finally { //cleanup if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } } } @@ -1065,14 +1068,14 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { void testDeleteParagraph() throws IOException { String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1_testDeleteParagraph", anonymous); - Paragraph p = TestUtils.getInstance(Notebook.class).processNote(noteId, + noteId = notebook.createNote("note1_testDeleteParagraph", anonymous); + Paragraph p = notebook.processNote(noteId, note -> { Paragraph ptmp = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); ptmp.setTitle("title1"); ptmp.setText("text1"); - TestUtils.getInstance(Notebook.class).saveNote(note, anonymous); + notebook.saveNote(note, anonymous); return ptmp; }); @@ -1081,7 +1084,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { assertThat("Test delete method: ", delete, isAllowed()); delete.close(); - TestUtils.getInstance(Notebook.class).processNote(noteId, + notebook.processNote(noteId, retrNote -> { Paragraph retrParagrah = retrNote.getParagraph(p.getId()); assertNull(retrParagrah, "paragraph should be deleted"); @@ -1090,7 +1093,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { } finally { //cleanup if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } } } @@ -1099,7 +1102,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { void testTitleSearch() throws IOException, InterruptedException { String noteId = null; try { - noteId = TestUtils.getInstance(Notebook.class).createNote("note1_testTitleSearch", anonymous); + noteId = notebook.createNote("note1_testTitleSearch", anonymous); String jsonRequest = "{\"title\": \"testTitleSearchOfParagraph\", " + "\"text\": \"ThisIsToTestSearchMethodWithTitle \"}"; CloseableHttpResponse postNoteText = httpPost("/notebook/" + noteId + "/paragraph", jsonRequest); @@ -1124,7 +1127,7 @@ class ZeppelinRestApiTest extends AbstractTestRestApi { } finally { //cleanup if (null != noteId) { - TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous); + notebook.removeNote(noteId, anonymous); } } } diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/service/ConfigurationServiceTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/service/ConfigurationServiceTest.java index a8443e605c..131238f8d1 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/service/ConfigurationServiceTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/service/ConfigurationServiceTest.java @@ -22,7 +22,6 @@ import org.apache.zeppelin.MiniZeppelinServer; import org.apache.zeppelin.conf.ZeppelinConfiguration; import org.apache.zeppelin.rest.AbstractTestRestApi; import org.apache.zeppelin.user.AuthenticationInfo; -import org.apache.zeppelin.utils.TestUtils; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -56,7 +55,7 @@ class ConfigurationServiceTest extends AbstractTestRestApi { ZeppelinConfiguration.ConfVars.ZEPPELIN_HELIUM_REGISTRY.getVarName(), "helium"); zepServer.start(); - configurationService = zepServer.getServiceLocator().getService(ConfigurationService.class); + configurationService = zepServer.getService(ConfigurationService.class); } @AfterAll diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java index 1a8a032e2a..4a05c1425b 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java @@ -100,10 +100,10 @@ class NotebookServerTest extends AbstractTestRestApi { zepServer.addInterpreter("spark"); zepServer.copyBinDir(); zepServer.start(); - notebook = zepServer.getServiceLocator().getService(Notebook.class); - authorizationService = zepServer.getServiceLocator().getService(AuthorizationService.class); - notebookServer = zepServer.getServiceLocator().getService(NotebookServer.class); - notebookService = zepServer.getServiceLocator().getService(NotebookService.class); + notebook = zepServer.getService(Notebook.class); + authorizationService = zepServer.getService(AuthorizationService.class); + notebookServer = zepServer.getService(NotebookServer.class); + notebookService = zepServer.getService(NotebookService.class); } @AfterAll