http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTest.java index 3357151..bdd639e 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTest.java @@ -16,28 +16,27 @@ */ package org.apache.zeppelin.helium; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException; -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; import org.apache.commons.io.FileUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + public class HeliumTest { private File tmpDir; private File localRegistryPath; @Before public void setUp() throws Exception { - tmpDir = - new File( - System.getProperty("java.io.tmpdir") + "/ZeppelinLTest_" + System.currentTimeMillis()); + tmpDir = new File(System.getProperty("java.io.tmpdir") + "/ZeppelinLTest_" + System.currentTimeMillis()); tmpDir.mkdirs(); localRegistryPath = new File(tmpDir, "helium"); localRegistryPath.mkdirs(); @@ -52,14 +51,8 @@ public class HeliumTest { public void testSaveLoadConf() throws IOException, URISyntaxException, TaskRunnerException { // given File heliumConf = new File(tmpDir, "helium.conf"); - Helium helium = - new Helium( - heliumConf.getAbsolutePath(), - localRegistryPath.getAbsolutePath(), - null, - null, - null, - null); + Helium helium = new Helium(heliumConf.getAbsolutePath(), localRegistryPath.getAbsolutePath(), + null, null, null, null); assertFalse(heliumConf.exists()); // when @@ -69,55 +62,40 @@ public class HeliumTest { assertTrue(heliumConf.exists()); // then load without exception - Helium heliumRestored = - new Helium( - heliumConf.getAbsolutePath(), - localRegistryPath.getAbsolutePath(), - null, - null, - null, - null); + Helium heliumRestored = new Helium( + heliumConf.getAbsolutePath(), localRegistryPath.getAbsolutePath(), null, null, null, null); } @Test - public void testRestoreRegistryInstances() - throws IOException, URISyntaxException, TaskRunnerException { + public void testRestoreRegistryInstances() throws IOException, URISyntaxException, TaskRunnerException { File heliumConf = new File(tmpDir, "helium.conf"); - Helium helium = - new Helium( - heliumConf.getAbsolutePath(), - localRegistryPath.getAbsolutePath(), - null, - null, - null, - null); + Helium helium = new Helium( + heliumConf.getAbsolutePath(), localRegistryPath.getAbsolutePath(), null, null, null, null); HeliumTestRegistry registry1 = new HeliumTestRegistry("r1", "r1"); HeliumTestRegistry registry2 = new HeliumTestRegistry("r2", "r2"); helium.addRegistry(registry1); helium.addRegistry(registry2); // when - registry1.add( - new HeliumPackage( - HeliumType.APPLICATION, - "name1", - "desc1", - "artifact1", - "className1", - new String[][] {}, - "", - "")); - - registry2.add( - new HeliumPackage( - HeliumType.APPLICATION, - "name2", - "desc2", - "artifact2", - "className2", - new String[][] {}, - "", - "")); + registry1.add(new HeliumPackage( + HeliumType.APPLICATION, + "name1", + "desc1", + "artifact1", + "className1", + new String[][]{}, + "", + "")); + + registry2.add(new HeliumPackage( + HeliumType.APPLICATION, + "name2", + "desc2", + "artifact2", + "className2", + new String[][]{}, + "", + "")); // then assertEquals(2, helium.getAllPackageInfo().size()); @@ -126,43 +104,35 @@ public class HeliumTest { @Test public void testRefresh() throws IOException, URISyntaxException, TaskRunnerException { File heliumConf = new File(tmpDir, "helium.conf"); - Helium helium = - new Helium( - heliumConf.getAbsolutePath(), - localRegistryPath.getAbsolutePath(), - null, - null, - null, - null); + Helium helium = new Helium( + heliumConf.getAbsolutePath(), localRegistryPath.getAbsolutePath(), null, null, null, null); HeliumTestRegistry registry1 = new HeliumTestRegistry("r1", "r1"); helium.addRegistry(registry1); // when - registry1.add( - new HeliumPackage( - HeliumType.APPLICATION, - "name1", - "desc1", - "artifact1", - "className1", - new String[][] {}, - "", - "")); + registry1.add(new HeliumPackage( + HeliumType.APPLICATION, + "name1", + "desc1", + "artifact1", + "className1", + new String[][]{}, + "", + "")); // then assertEquals(1, helium.getAllPackageInfo().size()); // when - registry1.add( - new HeliumPackage( - HeliumType.APPLICATION, - "name2", - "desc2", - "artifact2", - "className2", - new String[][] {}, - "", - "")); + registry1.add(new HeliumPackage( + HeliumType.APPLICATION, + "name2", + "desc2", + "artifact2", + "className2", + new String[][]{}, + "", + "")); // then assertEquals(2, helium.getAllPackageInfo(true, null).size());
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTestApplication.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTestApplication.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTestApplication.java index f13eec3..2e66a3f 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTestApplication.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTestApplication.java @@ -16,13 +16,13 @@ */ package org.apache.zeppelin.helium; +import org.apache.zeppelin.resource.ResourceSet; + import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; -import org.apache.zeppelin.resource.ResourceSet; public class HeliumTestApplication extends Application { private AtomicInteger numRun = new AtomicInteger(0); - public HeliumTestApplication(ApplicationContext context) { super(context); } @@ -39,5 +39,7 @@ public class HeliumTestApplication extends Application { } @Override - public void unload() throws ApplicationException {} + public void unload() throws ApplicationException { + + } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTestRegistry.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTestRegistry.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTestRegistry.java index e8ab9c1..a7b1538 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTestRegistry.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTestRegistry.java @@ -17,6 +17,7 @@ package org.apache.zeppelin.helium; import java.io.IOException; +import java.net.URI; import java.util.LinkedList; import java.util.List; http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/AbstractInterpreterTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/AbstractInterpreterTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/AbstractInterpreterTest.java index 3476d74..cd556a6 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/AbstractInterpreterTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/AbstractInterpreterTest.java @@ -1,8 +1,5 @@ package org.apache.zeppelin.interpreter; -import static org.mockito.Mockito.mock; - -import java.io.File; import org.apache.commons.io.FileUtils; import org.apache.zeppelin.conf.ZeppelinConfiguration; import org.apache.zeppelin.display.AngularObjectRegistryListener; @@ -14,11 +11,17 @@ import org.junit.Before; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; + +import static org.mockito.Mockito.mock; + /** - * This class will load configuration files under src/test/resources/interpreter - * src/test/resources/conf + * This class will load configuration files under + * src/test/resources/interpreter + * src/test/resources/conf + * + * to construct InterpreterSettingManager and InterpreterFactory properly * - * <p>to construct InterpreterSettingManager and InterpreterFactory properly */ public abstract class AbstractInterpreterTest { protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractInterpreterTest.class); @@ -47,26 +50,15 @@ public abstract class AbstractInterpreterTest { FileUtils.copyDirectory(new File("src/test/resources/interpreter"), interpreterDir); FileUtils.copyDirectory(new File("src/test/resources/conf"), confDir); - System.setProperty( - ZeppelinConfiguration.ConfVars.ZEPPELIN_HOME.getVarName(), zeppelinHome.getAbsolutePath()); - System.setProperty( - ZeppelinConfiguration.ConfVars.ZEPPELIN_CONF_DIR.getVarName(), confDir.getAbsolutePath()); - System.setProperty( - ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_DIR.getVarName(), - interpreterDir.getAbsolutePath()); - System.setProperty( - ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), - notebookDir.getAbsolutePath()); - System.setProperty( - ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_GROUP_DEFAULT.getVarName(), "test"); + System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_HOME.getVarName(), zeppelinHome.getAbsolutePath()); + System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_CONF_DIR.getVarName(), confDir.getAbsolutePath()); + System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_DIR.getVarName(), interpreterDir.getAbsolutePath()); + System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), notebookDir.getAbsolutePath()); + System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_GROUP_DEFAULT.getVarName(), "test"); conf = new ZeppelinConfiguration(); - interpreterSettingManager = - new InterpreterSettingManager( - conf, - mock(AngularObjectRegistryListener.class), - mock(RemoteInterpreterProcessListener.class), - mock(ApplicationEventListener.class)); + interpreterSettingManager = new InterpreterSettingManager(conf, + mock(AngularObjectRegistryListener.class), mock(RemoteInterpreterProcessListener.class), mock(ApplicationEventListener.class)); interpreterFactory = new InterpreterFactory(interpreterSettingManager); } @@ -79,19 +71,13 @@ public abstract class AbstractInterpreterTest { } protected Note createNote() { - return new Note( - "test", - "test", - null, - interpreterFactory, - interpreterSettingManager, - null, - null, - null, - null); + return new Note("test", "test", null, interpreterFactory, interpreterSettingManager, null, null, null, null); } protected InterpreterContext createDummyInterpreterContext() { - return InterpreterContext.builder().setNoteId("noteId").setParagraphId("paragraphId").build(); + return InterpreterContext.builder() + .setNoteId("noteId") + .setParagraphId("paragraphId") + .build(); } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/ConfInterpreterTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/ConfInterpreterTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/ConfInterpreterTest.java index 9e73590..d39b0ec 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/ConfInterpreterTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/ConfInterpreterTest.java @@ -17,35 +17,31 @@ package org.apache.zeppelin.interpreter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; import org.apache.zeppelin.interpreter.remote.RemoteInterpreter; import org.junit.Test; +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + public class ConfInterpreterTest extends AbstractInterpreterTest { @Test public void testCorrectConf() throws IOException, InterpreterException { - assertTrue( - interpreterFactory.getInterpreter("user1", "note1", "test.conf", "test") - instanceof ConfInterpreter); - ConfInterpreter confInterpreter = - (ConfInterpreter) interpreterFactory.getInterpreter("user1", "note1", "test.conf", "test"); + assertTrue(interpreterFactory.getInterpreter("user1", "note1", "test.conf", "test") instanceof ConfInterpreter); + ConfInterpreter confInterpreter = (ConfInterpreter) interpreterFactory.getInterpreter("user1", "note1", "test.conf", "test"); - InterpreterContext context = - InterpreterContext.builder().setNoteId("noteId").setParagraphId("paragraphId").build(); + InterpreterContext context = InterpreterContext.builder() + .setNoteId("noteId") + .setParagraphId("paragraphId") + .build(); - InterpreterResult result = - confInterpreter.interpret("property_1\tnew_value\nnew_property\tdummy_value", context); + InterpreterResult result = confInterpreter.interpret("property_1\tnew_value\nnew_property\tdummy_value", context); assertEquals(InterpreterResult.Code.SUCCESS, result.code); - assertTrue( - interpreterFactory.getInterpreter("user1", "note1", "test", "test") - instanceof RemoteInterpreter); - RemoteInterpreter remoteInterpreter = - (RemoteInterpreter) interpreterFactory.getInterpreter("user1", "note1", "test", "test"); + assertTrue(interpreterFactory.getInterpreter("user1", "note1", "test", "test") instanceof RemoteInterpreter); + RemoteInterpreter remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("user1", "note1", "test", "test"); remoteInterpreter.interpret("hello world", context); assertEquals(7, remoteInterpreter.getProperties().size()); assertEquals("new_value", remoteInterpreter.getProperty("property_1")); @@ -57,51 +53,46 @@ public class ConfInterpreterTest extends AbstractInterpreterTest { assertEquals(InterpreterResult.Code.SUCCESS, result.code); // run the paragraph with the same properties would result in ERROR - result = - confInterpreter.interpret("property_1\tnew_value_2\nnew_property\tdummy_value", context); + result = confInterpreter.interpret("property_1\tnew_value_2\nnew_property\tdummy_value", context); assertEquals(InterpreterResult.Code.ERROR, result.code); } @Test public void testEmptyConf() throws IOException, InterpreterException { - assertTrue( - interpreterFactory.getInterpreter("user1", "note1", "test.conf", "test") - instanceof ConfInterpreter); - ConfInterpreter confInterpreter = - (ConfInterpreter) interpreterFactory.getInterpreter("user1", "note1", "test.conf", "test"); - - InterpreterContext context = - InterpreterContext.builder().setNoteId("noteId").setParagraphId("paragraphId").build(); + assertTrue(interpreterFactory.getInterpreter("user1", "note1", "test.conf", "test") instanceof ConfInterpreter); + ConfInterpreter confInterpreter = (ConfInterpreter) interpreterFactory.getInterpreter("user1", "note1", "test.conf", "test"); + + InterpreterContext context = InterpreterContext.builder() + .setNoteId("noteId") + .setParagraphId("paragraphId") + .build(); InterpreterResult result = confInterpreter.interpret("", context); assertEquals(InterpreterResult.Code.SUCCESS, result.code); - assertTrue( - interpreterFactory.getInterpreter("user1", "note1", "test", "test") - instanceof RemoteInterpreter); - RemoteInterpreter remoteInterpreter = - (RemoteInterpreter) interpreterFactory.getInterpreter("user1", "note1", "test", "test"); + assertTrue(interpreterFactory.getInterpreter("user1", "note1", "test", "test") instanceof RemoteInterpreter); + RemoteInterpreter remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("user1", "note1", "test", "test"); assertEquals(6, remoteInterpreter.getProperties().size()); assertEquals("value_1", remoteInterpreter.getProperty("property_1")); assertEquals("value_3", remoteInterpreter.getProperty("property_3")); } + @Test public void testRunningAfterOtherInterpreter() throws IOException, InterpreterException { - assertTrue( - interpreterFactory.getInterpreter("user1", "note1", "test.conf", "test") - instanceof ConfInterpreter); - ConfInterpreter confInterpreter = - (ConfInterpreter) interpreterFactory.getInterpreter("user1", "note1", "test.conf", "test"); + assertTrue(interpreterFactory.getInterpreter("user1", "note1", "test.conf", "test") instanceof ConfInterpreter); + ConfInterpreter confInterpreter = (ConfInterpreter) interpreterFactory.getInterpreter("user1", "note1", "test.conf", "test"); - InterpreterContext context = - InterpreterContext.builder().setNoteId("noteId").setParagraphId("paragraphId").build(); + InterpreterContext context = InterpreterContext.builder() + .setNoteId("noteId") + .setParagraphId("paragraphId") + .build(); - RemoteInterpreter remoteInterpreter = - (RemoteInterpreter) interpreterFactory.getInterpreter("user1", "note1", "test", "test"); + RemoteInterpreter remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("user1", "note1", "test", "test"); InterpreterResult result = remoteInterpreter.interpret("hello world", context); assertEquals(InterpreterResult.Code.SUCCESS, result.code); result = confInterpreter.interpret("property_1\tnew_value\nnew_property\tdummy_value", context); assertEquals(InterpreterResult.Code.ERROR, result.code); } + } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/DoubleEchoInterpreter.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/DoubleEchoInterpreter.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/DoubleEchoInterpreter.java index 13d72c2..be3d5be 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/DoubleEchoInterpreter.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/DoubleEchoInterpreter.java @@ -15,10 +15,12 @@ * limitations under the License. */ + package org.apache.zeppelin.interpreter; import java.util.Properties; + public class DoubleEchoInterpreter extends Interpreter { public DoubleEchoInterpreter(Properties property) { @@ -26,10 +28,14 @@ public class DoubleEchoInterpreter extends Interpreter { } @Override - public void open() {} + public void open() { + + } @Override - public void close() {} + public void close() { + + } @Override public InterpreterResult interpret(String st, InterpreterContext context) { @@ -37,7 +43,9 @@ public class DoubleEchoInterpreter extends Interpreter { } @Override - public void cancel(InterpreterContext context) {} + public void cancel(InterpreterContext context) { + + } @Override public FormType getFormType() { http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/EchoInterpreter.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/EchoInterpreter.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/EchoInterpreter.java index e7ac62d..cf1713f 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/EchoInterpreter.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/EchoInterpreter.java @@ -15,11 +15,14 @@ * limitations under the License. */ + package org.apache.zeppelin.interpreter; import java.util.Properties; -/** Just return the received statement back */ +/** + * Just return the received statement back + */ public class EchoInterpreter extends Interpreter { public EchoInterpreter(Properties property) { @@ -27,10 +30,14 @@ public class EchoInterpreter extends Interpreter { } @Override - public void open() {} + public void open() { + + } @Override - public void close() {} + public void close() { + + } @Override public InterpreterResult interpret(String st, InterpreterContext context) { @@ -42,7 +49,9 @@ public class EchoInterpreter extends Interpreter { } @Override - public void cancel(InterpreterContext context) {} + public void cancel(InterpreterContext context) { + + } @Override public FormType getFormType() { http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/FlinkIntegrationTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/FlinkIntegrationTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/FlinkIntegrationTest.java index 0148c4d..57aacdb 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/FlinkIntegrationTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/FlinkIntegrationTest.java @@ -1,12 +1,5 @@ package org.apache.zeppelin.interpreter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.util.Arrays; -import java.util.EnumSet; -import java.util.List; import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest; import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse; import org.apache.hadoop.yarn.api.records.YarnApplicationState; @@ -19,6 +12,14 @@ import org.junit.runners.Parameterized; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; +import java.util.Arrays; +import java.util.EnumSet; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + @RunWith(value = Parameterized.class) public class FlinkIntegrationTest { private static Logger LOGGER = LoggerFactory.getLogger(SparkIntegrationTest.class); @@ -39,7 +40,11 @@ public class FlinkIntegrationTest { @Parameterized.Parameters public static List<Object[]> data() { - return Arrays.asList(new Object[][] {{"1.5.1"}, {"1.5.2"}}); + return Arrays.asList(new Object[][]{ + {"1.5.1"}, + {"1.5.2"} + }); + } @BeforeClass @@ -65,35 +70,26 @@ public class FlinkIntegrationTest { private void testInterpreterBasics() throws IOException, InterpreterException { // test FlinkInterpreter - Interpreter flinkInterpreter = - interpreterFactory.getInterpreter("user1", "note1", "flink", "flink"); + Interpreter flinkInterpreter = interpreterFactory.getInterpreter("user1", "note1", "flink", "flink"); - InterpreterContext context = - new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").build(); + InterpreterContext context = new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").build(); InterpreterResult interpreterResult = flinkInterpreter.interpret("1+1", context); assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code); assertTrue(interpreterResult.msg.get(0).getData().contains("2")); + } @Test public void testLocalMode() throws IOException, YarnException, InterpreterException { - InterpreterSetting flinkInterpreterSetting = - interpreterSettingManager.getInterpreterSettingByName("flink"); + InterpreterSetting flinkInterpreterSetting = interpreterSettingManager.getInterpreterSettingByName("flink"); flinkInterpreterSetting.setProperty("FLINK_HOME", flinkHome); - flinkInterpreterSetting.setProperty( - "ZEPPELIN_CONF_DIR", zeppelin.getZeppelinConfDir().getAbsolutePath()); + flinkInterpreterSetting.setProperty("ZEPPELIN_CONF_DIR", zeppelin.getZeppelinConfDir().getAbsolutePath()); testInterpreterBasics(); // no yarn application launched - GetApplicationsRequest request = - GetApplicationsRequest.newInstance(EnumSet.of(YarnApplicationState.RUNNING)); - GetApplicationsResponse response = - hadoopCluster - .getYarnCluster() - .getResourceManager() - .getClientRMService() - .getApplications(request); + GetApplicationsRequest request = GetApplicationsRequest.newInstance(EnumSet.of(YarnApplicationState.RUNNING)); + GetApplicationsResponse response = hadoopCluster.getYarnCluster().getResourceManager().getClientRMService().getApplications(request); assertEquals(0, response.getApplicationList().size()); interpreterSettingManager.close(); @@ -102,24 +98,16 @@ public class FlinkIntegrationTest { // TODO(zjffdu) enable it when make yarn integration test work // @Test public void testYarnMode() throws IOException, InterpreterException, YarnException { - InterpreterSetting flinkInterpreterSetting = - interpreterSettingManager.getInterpreterSettingByName("flink"); + InterpreterSetting flinkInterpreterSetting = interpreterSettingManager.getInterpreterSettingByName("flink"); flinkInterpreterSetting.setProperty("HADOOP_CONF_DIR", hadoopCluster.getConfigPath()); flinkInterpreterSetting.setProperty("FLINK_HOME", flinkHome); - flinkInterpreterSetting.setProperty( - "ZEPPELIN_CONF_DIR", zeppelin.getZeppelinConfDir().getAbsolutePath()); + flinkInterpreterSetting.setProperty("ZEPPELIN_CONF_DIR", zeppelin.getZeppelinConfDir().getAbsolutePath()); flinkInterpreterSetting.setProperty("flink.execution.mode", "YARN"); testInterpreterBasics(); // 1 yarn application launched - GetApplicationsRequest request = - GetApplicationsRequest.newInstance(EnumSet.of(YarnApplicationState.RUNNING)); - GetApplicationsResponse response = - hadoopCluster - .getYarnCluster() - .getResourceManager() - .getClientRMService() - .getApplications(request); + GetApplicationsRequest request = GetApplicationsRequest.newInstance(EnumSet.of(YarnApplicationState.RUNNING)); + GetApplicationsResponse response = hadoopCluster.getYarnCluster().getResourceManager().getClientRMService().getApplications(request); assertEquals(1, response.getApplicationList().size()); interpreterSettingManager.close(); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java index 3be77e7..6d4666a 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java @@ -17,54 +17,37 @@ package org.apache.zeppelin.interpreter; +import org.apache.zeppelin.interpreter.remote.RemoteInterpreter; +import org.junit.Test; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import org.apache.zeppelin.interpreter.remote.RemoteInterpreter; -import org.junit.Test; - public class InterpreterFactoryTest extends AbstractInterpreterTest { @Test public void testGetFactory() throws InterpreterException { - assertTrue( - interpreterFactory.getInterpreter("user1", "note1", "", "test") - instanceof RemoteInterpreter); - RemoteInterpreter remoteInterpreter = - (RemoteInterpreter) interpreterFactory.getInterpreter("user1", "note1", "", "test"); + assertTrue(interpreterFactory.getInterpreter("user1", "note1", "", "test") instanceof RemoteInterpreter); + RemoteInterpreter remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("user1", "note1", "", "test"); // EchoInterpreter is the default interpreter because test is the default interpreter group assertEquals(EchoInterpreter.class.getName(), remoteInterpreter.getClassName()); - assertTrue( - interpreterFactory.getInterpreter("user1", "note1", "double_echo", "test") - instanceof RemoteInterpreter); - remoteInterpreter = - (RemoteInterpreter) - interpreterFactory.getInterpreter("user1", "note1", "double_echo", "test"); + assertTrue(interpreterFactory.getInterpreter("user1", "note1", "double_echo", "test") instanceof RemoteInterpreter); + remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("user1", "note1", "double_echo", "test"); assertEquals(DoubleEchoInterpreter.class.getName(), remoteInterpreter.getClassName()); - assertTrue( - interpreterFactory.getInterpreter("user1", "note1", "test", "test") - instanceof RemoteInterpreter); - remoteInterpreter = - (RemoteInterpreter) interpreterFactory.getInterpreter("user1", "note1", "test", "test"); + assertTrue(interpreterFactory.getInterpreter("user1", "note1", "test", "test") instanceof RemoteInterpreter); + remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("user1", "note1", "test", "test"); assertEquals(EchoInterpreter.class.getName(), remoteInterpreter.getClassName()); - assertTrue( - interpreterFactory.getInterpreter("user1", "note1", "test2", "test") - instanceof RemoteInterpreter); - remoteInterpreter = - (RemoteInterpreter) interpreterFactory.getInterpreter("user1", "note1", "test2", "test"); + assertTrue(interpreterFactory.getInterpreter("user1", "note1", "test2", "test") instanceof RemoteInterpreter); + remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("user1", "note1", "test2", "test"); assertEquals(EchoInterpreter.class.getName(), remoteInterpreter.getClassName()); - assertTrue( - interpreterFactory.getInterpreter("user1", "note1", "test2.double_echo", "test") - instanceof RemoteInterpreter); - remoteInterpreter = - (RemoteInterpreter) - interpreterFactory.getInterpreter("user1", "note1", "test2.double_echo", "test"); + assertTrue(interpreterFactory.getInterpreter("user1", "note1", "test2.double_echo", "test") instanceof RemoteInterpreter); + remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("user1", "note1", "test2.double_echo", "test"); assertEquals(DoubleEchoInterpreter.class.getName(), remoteInterpreter.getClassName()); } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterSettingManagerTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterSettingManagerTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterSettingManagerTest.java index 6418fac..1780960 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterSettingManagerTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterSettingManagerTest.java @@ -15,19 +15,9 @@ * limitations under the License. */ -package org.apache.zeppelin.interpreter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; +package org.apache.zeppelin.interpreter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import org.apache.zeppelin.conf.ZeppelinConfiguration; import org.apache.zeppelin.dep.Dependency; import org.apache.zeppelin.display.AngularObjectRegistryListener; @@ -38,6 +28,20 @@ import org.junit.Test; import org.sonatype.aether.RepositoryException; import org.sonatype.aether.repository.RemoteRepository; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; + + public class InterpreterSettingManagerTest extends AbstractInterpreterTest { @Test @@ -70,12 +74,8 @@ public class InterpreterSettingManagerTest extends AbstractInterpreterTest { assertEquals("central", repositories.get(0).getId()); // Load it again - InterpreterSettingManager interpreterSettingManager2 = - new InterpreterSettingManager( - conf, - mock(AngularObjectRegistryListener.class), - mock(RemoteInterpreterProcessListener.class), - mock(ApplicationEventListener.class)); + InterpreterSettingManager interpreterSettingManager2 = new InterpreterSettingManager(conf, + mock(AngularObjectRegistryListener.class), mock(RemoteInterpreterProcessListener.class), mock(ApplicationEventListener.class)); assertEquals(5, interpreterSettingManager2.get().size()); interpreterSetting = interpreterSettingManager2.getByName("test"); assertEquals("test", interpreterSetting.getName()); @@ -92,6 +92,7 @@ public class InterpreterSettingManagerTest extends AbstractInterpreterTest { repositories = interpreterSettingManager2.getRepositories(); assertEquals(2, repositories.size()); assertEquals("central", repositories.get(0).getId()); + } @Test @@ -101,18 +102,16 @@ public class InterpreterSettingManagerTest extends AbstractInterpreterTest { option.setPerNote("scoped"); option.setPerUser("scoped"); Map<String, InterpreterProperty> properties = new HashMap<>(); - properties.put("property_4", new InterpreterProperty("property_4", "value_4")); + properties.put("property_4", new InterpreterProperty("property_4","value_4")); try { - interpreterSettingManager.createNewSetting( - "test2", "test", new ArrayList<Dependency>(), option, properties); + interpreterSettingManager.createNewSetting("test2", "test", new ArrayList<Dependency>(), option, properties); fail("Should fail due to interpreter already existed"); } catch (IOException e) { assertTrue(e.getMessage().contains("already existed")); } - interpreterSettingManager.createNewSetting( - "test3", "test", new ArrayList<Dependency>(), option, properties); + interpreterSettingManager.createNewSetting("test3", "test", new ArrayList<Dependency>(), option, properties); assertEquals(6, interpreterSettingManager.get().size()); InterpreterSetting interpreterSetting = interpreterSettingManager.getByName("test3"); assertEquals("test3", interpreterSetting.getName()); @@ -133,12 +132,8 @@ public class InterpreterSettingManagerTest extends AbstractInterpreterTest { assertNotNull(interpreterSetting.getInterpreterSettingManager()); // load it again, it should be saved in interpreter-setting.json. So we can restore it properly - InterpreterSettingManager interpreterSettingManager2 = - new InterpreterSettingManager( - conf, - mock(AngularObjectRegistryListener.class), - mock(RemoteInterpreterProcessListener.class), - mock(ApplicationEventListener.class)); + InterpreterSettingManager interpreterSettingManager2 = new InterpreterSettingManager(conf, + mock(AngularObjectRegistryListener.class), mock(RemoteInterpreterProcessListener.class), mock(ApplicationEventListener.class)); assertEquals(6, interpreterSettingManager2.get().size()); interpreterSetting = interpreterSettingManager2.getByName("test3"); assertEquals("test3", interpreterSetting.getName()); @@ -157,8 +152,7 @@ public class InterpreterSettingManagerTest extends AbstractInterpreterTest { newProperties.put("property_4", new InterpreterProperty("property_4", "new_value_4")); List<Dependency> newDependencies = new ArrayList<>(); newDependencies.add(new Dependency("com.databricks:spark-avro_2.11:3.1.0")); - interpreterSettingManager.setPropertyAndRestart( - interpreterSetting.getId(), newOption, newProperties, newDependencies); + interpreterSettingManager.setPropertyAndRestart(interpreterSetting.getId(), newOption, newProperties, newDependencies); interpreterSetting = interpreterSettingManager.get(interpreterSetting.getId()); assertEquals("test3", interpreterSetting.getName()); assertEquals("test", interpreterSetting.getGroup()); @@ -190,29 +184,22 @@ public class InterpreterSettingManagerTest extends AbstractInterpreterTest { assertEquals(5, interpreterSettingManager.get().size()); // load it again - InterpreterSettingManager interpreterSettingManager3 = - new InterpreterSettingManager( - new ZeppelinConfiguration(), - mock(AngularObjectRegistryListener.class), - mock(RemoteInterpreterProcessListener.class), - mock(ApplicationEventListener.class)); + InterpreterSettingManager interpreterSettingManager3 = new InterpreterSettingManager(new ZeppelinConfiguration(), + mock(AngularObjectRegistryListener.class), mock(RemoteInterpreterProcessListener.class), mock(ApplicationEventListener.class)); assertEquals(5, interpreterSettingManager3.get().size()); + } @Test public void testGetEditor() throws IOException, InterpreterNotFoundException { - Interpreter echoInterpreter = - interpreterFactory.getInterpreter("user1", "note1", "test.echo", "test"); + Interpreter echoInterpreter = interpreterFactory.getInterpreter("user1", "note1", "test.echo", "test"); // get editor setting from interpreter-setting.json - Map<String, Object> editor = - interpreterSettingManager.getEditorSetting(echoInterpreter, "user1", "note1", "test.echo"); + Map<String, Object> editor = interpreterSettingManager.getEditorSetting(echoInterpreter, "user1", "note1", "test.echo"); assertEquals("java", editor.get("language")); // when editor setting doesn't exit, return the default editor - Interpreter mock1Interpreter = - interpreterFactory.getInterpreter("user1", "note1", "mock1", "test"); - editor = - interpreterSettingManager.getEditorSetting(mock1Interpreter, "user1", "note1", "mock1"); + Interpreter mock1Interpreter = interpreterFactory.getInterpreter("user1", "note1", "mock1", "test"); + editor = interpreterSettingManager.getEditorSetting(mock1Interpreter,"user1", "note1", "mock1"); assertEquals("text", editor.get("language")); } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterSettingTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterSettingTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterSettingTest.java index 974c155..e3e47d3 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterSettingTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterSettingTest.java @@ -17,13 +17,14 @@ package org.apache.zeppelin.interpreter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import org.junit.Test; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; public class InterpreterSettingTest { @@ -31,44 +32,28 @@ public class InterpreterSettingTest { public void testCreateInterpreters() { InterpreterOption interpreterOption = new InterpreterOption(); interpreterOption.setPerUser(InterpreterOption.SHARED); - InterpreterInfo interpreterInfo1 = - new InterpreterInfo( - EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>()); - InterpreterInfo interpreterInfo2 = - new InterpreterInfo( - DoubleEchoInterpreter.class.getName(), - "double_echo", - false, - new HashMap<String, Object>()); + InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>()); + InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(), "double_echo", false, new HashMap<String, Object>()); List<InterpreterInfo> interpreterInfos = new ArrayList<>(); interpreterInfos.add(interpreterInfo1); interpreterInfos.add(interpreterInfo2); - InterpreterSetting interpreterSetting = - new InterpreterSetting.Builder() - .setId("id") - .setName("test") - .setGroup("test") - .setInterpreterInfos(interpreterInfos) - .setOption(interpreterOption) - .create(); + InterpreterSetting interpreterSetting = new InterpreterSetting.Builder() + .setId("id") + .setName("test") + .setGroup("test") + .setInterpreterInfos(interpreterInfos) + .setOption(interpreterOption) + .create(); // create default interpreter for user1 and note1 - assertEquals( - EchoInterpreter.class.getName(), - interpreterSetting.getDefaultInterpreter("user1", "note1").getClassName()); + assertEquals(EchoInterpreter.class.getName(), interpreterSetting.getDefaultInterpreter("user1", "note1").getClassName()); // create interpreter echo for user1 and note1 - assertEquals( - EchoInterpreter.class.getName(), - interpreterSetting.getInterpreter("user1", "note1", "echo").getClassName()); - assertEquals( - interpreterSetting.getDefaultInterpreter("user1", "note1"), - interpreterSetting.getInterpreter("user1", "note1", "echo")); + assertEquals(EchoInterpreter.class.getName(), interpreterSetting.getInterpreter("user1", "note1", "echo").getClassName()); + assertEquals(interpreterSetting.getDefaultInterpreter("user1", "note1"), interpreterSetting.getInterpreter("user1", "note1", "echo")); // create interpreter double_echo for user1 and note1 - assertEquals( - DoubleEchoInterpreter.class.getName(), - interpreterSetting.getInterpreter("user1", "note1", "double_echo").getClassName()); + assertEquals(DoubleEchoInterpreter.class.getName(), interpreterSetting.getInterpreter("user1", "note1", "double_echo").getClassName()); // create non-existed interpreter assertNull(interpreterSetting.getInterpreter("user1", "note1", "invalid_echo")); @@ -78,26 +63,18 @@ public class InterpreterSettingTest { public void testSharedMode() { InterpreterOption interpreterOption = new InterpreterOption(); interpreterOption.setPerUser(InterpreterOption.SHARED); - InterpreterInfo interpreterInfo1 = - new InterpreterInfo( - EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>()); - InterpreterInfo interpreterInfo2 = - new InterpreterInfo( - DoubleEchoInterpreter.class.getName(), - "double_echo", - false, - new HashMap<String, Object>()); + InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>()); + InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(), "double_echo", false, new HashMap<String, Object>()); List<InterpreterInfo> interpreterInfos = new ArrayList<>(); interpreterInfos.add(interpreterInfo1); interpreterInfos.add(interpreterInfo2); - InterpreterSetting interpreterSetting = - new InterpreterSetting.Builder() - .setId("id") - .setName("test") - .setGroup("test") - .setInterpreterInfos(interpreterInfos) - .setOption(interpreterOption) - .create(); + InterpreterSetting interpreterSetting = new InterpreterSetting.Builder() + .setId("id") + .setName("test") + .setGroup("test") + .setInterpreterInfos(interpreterInfos) + .setOption(interpreterOption) + .create(); // create default interpreter for user1 and note1 interpreterSetting.getDefaultInterpreter("user1", "note1"); @@ -122,26 +99,18 @@ public class InterpreterSettingTest { public void testPerUserScopedMode() { InterpreterOption interpreterOption = new InterpreterOption(); interpreterOption.setPerUser(InterpreterOption.SCOPED); - InterpreterInfo interpreterInfo1 = - new InterpreterInfo( - EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>()); - InterpreterInfo interpreterInfo2 = - new InterpreterInfo( - DoubleEchoInterpreter.class.getName(), - "double_echo", - false, - new HashMap<String, Object>()); + InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>()); + InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(), "double_echo", false, new HashMap<String, Object>()); List<InterpreterInfo> interpreterInfos = new ArrayList<>(); interpreterInfos.add(interpreterInfo1); interpreterInfos.add(interpreterInfo2); - InterpreterSetting interpreterSetting = - new InterpreterSetting.Builder() - .setId("id") - .setName("test") - .setGroup("test") - .setInterpreterInfos(interpreterInfos) - .setOption(interpreterOption) - .create(); + InterpreterSetting interpreterSetting = new InterpreterSetting.Builder() + .setId("id") + .setName("test") + .setGroup("test") + .setInterpreterInfos(interpreterInfos) + .setOption(interpreterOption) + .create(); // create interpreter for user1 and note1 interpreterSetting.getDefaultInterpreter("user1", "note1"); @@ -166,26 +135,18 @@ public class InterpreterSettingTest { public void testPerNoteScopedMode() { InterpreterOption interpreterOption = new InterpreterOption(); interpreterOption.setPerNote(InterpreterOption.SCOPED); - InterpreterInfo interpreterInfo1 = - new InterpreterInfo( - EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>()); - InterpreterInfo interpreterInfo2 = - new InterpreterInfo( - DoubleEchoInterpreter.class.getName(), - "double_echo", - false, - new HashMap<String, Object>()); + InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>()); + InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(), "double_echo", false, new HashMap<String, Object>()); List<InterpreterInfo> interpreterInfos = new ArrayList<>(); interpreterInfos.add(interpreterInfo1); interpreterInfos.add(interpreterInfo2); - InterpreterSetting interpreterSetting = - new InterpreterSetting.Builder() - .setId("id") - .setName("test") - .setGroup("test") - .setInterpreterInfos(interpreterInfos) - .setOption(interpreterOption) - .create(); + InterpreterSetting interpreterSetting = new InterpreterSetting.Builder() + .setId("id") + .setName("test") + .setGroup("test") + .setInterpreterInfos(interpreterInfos) + .setOption(interpreterOption) + .create(); // create interpreter for user1 and note1 interpreterSetting.getDefaultInterpreter("user1", "note1"); @@ -210,26 +171,18 @@ public class InterpreterSettingTest { public void testPerUserIsolatedMode() { InterpreterOption interpreterOption = new InterpreterOption(); interpreterOption.setPerUser(InterpreterOption.ISOLATED); - InterpreterInfo interpreterInfo1 = - new InterpreterInfo( - EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>()); - InterpreterInfo interpreterInfo2 = - new InterpreterInfo( - DoubleEchoInterpreter.class.getName(), - "double_echo", - false, - new HashMap<String, Object>()); + InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>()); + InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(), "double_echo", false, new HashMap<String, Object>()); List<InterpreterInfo> interpreterInfos = new ArrayList<>(); interpreterInfos.add(interpreterInfo1); interpreterInfos.add(interpreterInfo2); - InterpreterSetting interpreterSetting = - new InterpreterSetting.Builder() - .setId("id") - .setName("test") - .setGroup("test") - .setInterpreterInfos(interpreterInfos) - .setOption(interpreterOption) - .create(); + InterpreterSetting interpreterSetting = new InterpreterSetting.Builder() + .setId("id") + .setName("test") + .setGroup("test") + .setInterpreterInfos(interpreterInfos) + .setOption(interpreterOption) + .create(); // create interpreter for user1 and note1 interpreterSetting.getDefaultInterpreter("user1", "note1"); @@ -254,26 +207,18 @@ public class InterpreterSettingTest { public void testPerNoteIsolatedMode() { InterpreterOption interpreterOption = new InterpreterOption(); interpreterOption.setPerNote(InterpreterOption.ISOLATED); - InterpreterInfo interpreterInfo1 = - new InterpreterInfo( - EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>()); - InterpreterInfo interpreterInfo2 = - new InterpreterInfo( - DoubleEchoInterpreter.class.getName(), - "double_echo", - false, - new HashMap<String, Object>()); + InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>()); + InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(), "double_echo", false, new HashMap<String, Object>()); List<InterpreterInfo> interpreterInfos = new ArrayList<>(); interpreterInfos.add(interpreterInfo1); interpreterInfos.add(interpreterInfo2); - InterpreterSetting interpreterSetting = - new InterpreterSetting.Builder() - .setId("id") - .setName("test") - .setGroup("test") - .setInterpreterInfos(interpreterInfos) - .setOption(interpreterOption) - .create(); + InterpreterSetting interpreterSetting = new InterpreterSetting.Builder() + .setId("id") + .setName("test") + .setGroup("test") + .setInterpreterInfos(interpreterInfos) + .setOption(interpreterOption) + .create(); // create interpreter for user1 and note1 interpreterSetting.getDefaultInterpreter("user1", "note1"); @@ -298,26 +243,18 @@ public class InterpreterSettingTest { InterpreterOption interpreterOption = new InterpreterOption(); interpreterOption.setPerUser(InterpreterOption.ISOLATED); interpreterOption.setPerNote(InterpreterOption.SCOPED); - InterpreterInfo interpreterInfo1 = - new InterpreterInfo( - EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>()); - InterpreterInfo interpreterInfo2 = - new InterpreterInfo( - DoubleEchoInterpreter.class.getName(), - "double_echo", - false, - new HashMap<String, Object>()); + InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>()); + InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(), "double_echo", false, new HashMap<String, Object>()); List<InterpreterInfo> interpreterInfos = new ArrayList<>(); interpreterInfos.add(interpreterInfo1); interpreterInfos.add(interpreterInfo2); - InterpreterSetting interpreterSetting = - new InterpreterSetting.Builder() - .setId("id") - .setName("test") - .setGroup("test") - .setInterpreterInfos(interpreterInfos) - .setOption(interpreterOption) - .create(); + InterpreterSetting interpreterSetting = new InterpreterSetting.Builder() + .setId("id") + .setName("test") + .setGroup("test") + .setInterpreterInfos(interpreterInfos) + .setOption(interpreterOption) + .create(); // create interpreter for user1 and note1 interpreterSetting.getDefaultInterpreter("user1", "note1"); @@ -333,9 +270,7 @@ public class InterpreterSettingTest { assertEquals(2, interpreterSetting.getAllInterpreterGroups().size()); // group1 for user1 has 2 sessions, and group2 for user2 has 1 session - assertEquals( - interpreterSetting.getInterpreterGroup("user1", "note1"), - interpreterSetting.getInterpreterGroup("user1", "note2")); + assertEquals(interpreterSetting.getInterpreterGroup("user1", "note1"), interpreterSetting.getInterpreterGroup("user1", "note2")); assertEquals(2, interpreterSetting.getInterpreterGroup("user1", "note1").getSessionNum()); assertEquals(2, interpreterSetting.getInterpreterGroup("user1", "note2").getSessionNum()); assertEquals(1, interpreterSetting.getInterpreterGroup("user2", "note1").getSessionNum()); @@ -359,26 +294,18 @@ public class InterpreterSettingTest { InterpreterOption interpreterOption = new InterpreterOption(); interpreterOption.setPerUser(InterpreterOption.ISOLATED); interpreterOption.setPerNote(InterpreterOption.ISOLATED); - InterpreterInfo interpreterInfo1 = - new InterpreterInfo( - EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>()); - InterpreterInfo interpreterInfo2 = - new InterpreterInfo( - DoubleEchoInterpreter.class.getName(), - "double_echo", - false, - new HashMap<String, Object>()); + InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>()); + InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(), "double_echo", false, new HashMap<String, Object>()); List<InterpreterInfo> interpreterInfos = new ArrayList<>(); interpreterInfos.add(interpreterInfo1); interpreterInfos.add(interpreterInfo2); - InterpreterSetting interpreterSetting = - new InterpreterSetting.Builder() - .setId("id") - .setName("test") - .setGroup("test") - .setInterpreterInfos(interpreterInfos) - .setOption(interpreterOption) - .create(); + InterpreterSetting interpreterSetting = new InterpreterSetting.Builder() + .setId("id") + .setName("test") + .setGroup("test") + .setInterpreterInfos(interpreterInfos) + .setOption(interpreterOption) + .create(); // create interpreter for user1 and note1 interpreterSetting.getDefaultInterpreter("user1", "note1"); @@ -423,26 +350,18 @@ public class InterpreterSettingTest { InterpreterOption interpreterOption = new InterpreterOption(); interpreterOption.setPerUser(InterpreterOption.SCOPED); interpreterOption.setPerNote(InterpreterOption.SCOPED); - InterpreterInfo interpreterInfo1 = - new InterpreterInfo( - EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>()); - InterpreterInfo interpreterInfo2 = - new InterpreterInfo( - DoubleEchoInterpreter.class.getName(), - "double_echo", - false, - new HashMap<String, Object>()); + InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>()); + InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(), "double_echo", false, new HashMap<String, Object>()); List<InterpreterInfo> interpreterInfos = new ArrayList<>(); interpreterInfos.add(interpreterInfo1); interpreterInfos.add(interpreterInfo2); - InterpreterSetting interpreterSetting = - new InterpreterSetting.Builder() - .setId("id") - .setName("test") - .setGroup("test") - .setInterpreterInfos(interpreterInfos) - .setOption(interpreterOption) - .create(); + InterpreterSetting interpreterSetting = new InterpreterSetting.Builder() + .setId("id") + .setName("test") + .setGroup("test") + .setInterpreterInfos(interpreterInfos) + .setOption(interpreterOption) + .create(); // create interpreter for user1 and note1 interpreterSetting.getDefaultInterpreter("user1", "note1"); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/ManagedInterpreterGroupTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/ManagedInterpreterGroupTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/ManagedInterpreterGroupTest.java index 010a2f8..aa73749 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/ManagedInterpreterGroupTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/ManagedInterpreterGroupTest.java @@ -17,18 +17,20 @@ package org.apache.zeppelin.interpreter; -import static org.junit.Assert.assertEquals; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonatype.aether.RepositoryException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import static org.junit.Assert.assertEquals; + + public class ManagedInterpreterGroupTest { private static final Logger LOGGER = LoggerFactory.getLogger(ManagedInterpreterGroupTest.class); @@ -39,32 +41,23 @@ public class ManagedInterpreterGroupTest { public void setUp() throws IOException, RepositoryException { InterpreterOption interpreterOption = new InterpreterOption(); interpreterOption.setPerUser(InterpreterOption.SCOPED); - InterpreterInfo interpreterInfo1 = - new InterpreterInfo( - EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>()); - InterpreterInfo interpreterInfo2 = - new InterpreterInfo( - DoubleEchoInterpreter.class.getName(), - "double_echo", - false, - new HashMap<String, Object>()); + InterpreterInfo interpreterInfo1 = new InterpreterInfo(EchoInterpreter.class.getName(), "echo", true, new HashMap<String, Object>()); + InterpreterInfo interpreterInfo2 = new InterpreterInfo(DoubleEchoInterpreter.class.getName(), "double_echo", false, new HashMap<String, Object>()); List<InterpreterInfo> interpreterInfos = new ArrayList<>(); interpreterInfos.add(interpreterInfo1); interpreterInfos.add(interpreterInfo2); - interpreterSetting = - new InterpreterSetting.Builder() - .setId("id") - .setName("test") - .setGroup("test") - .setInterpreterInfos(interpreterInfos) - .setOption(interpreterOption) - .create(); + interpreterSetting = new InterpreterSetting.Builder() + .setId("id") + .setName("test") + .setGroup("test") + .setInterpreterInfos(interpreterInfos) + .setOption(interpreterOption) + .create(); } @Test public void testInterpreterGroup() { - ManagedInterpreterGroup interpreterGroup = - new ManagedInterpreterGroup("group_1", interpreterSetting); + ManagedInterpreterGroup interpreterGroup = new ManagedInterpreterGroup("group_1", interpreterSetting); assertEquals(0, interpreterGroup.getSessionNum()); // create session_1 http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/MiniHadoopCluster.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/MiniHadoopCluster.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/MiniHadoopCluster.java index 4f29feb..b0799ae 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/MiniHadoopCluster.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/MiniHadoopCluster.java @@ -1,8 +1,5 @@ package org.apache.zeppelin.interpreter; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.yarn.conf.YarnConfiguration; @@ -12,7 +9,13 @@ import org.junit.BeforeClass; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; + + /** + * * Util class for creating a Mini Hadoop cluster in local machine to test scenarios that needs * hadoop cluster. */ @@ -31,31 +34,28 @@ public class MiniHadoopCluster { this.hadoopConf = new Configuration(); new File(configPath).mkdirs(); // start MiniDFSCluster - this.dfsCluster = - new MiniDFSCluster.Builder(hadoopConf) - .numDataNodes(2) - .format(true) - .waitSafeMode(true) - .build(); + this.dfsCluster = new MiniDFSCluster.Builder(hadoopConf) + .numDataNodes(2) + .format(true) + .waitSafeMode(true) + .build(); this.dfsCluster.waitActive(); saveConfig(hadoopConf, configPath + "/core-site.xml"); // start MiniYarnCluster YarnConfiguration baseConfig = new YarnConfiguration(hadoopConf); - baseConfig.set( - "yarn.nodemanager.disk-health-checker.max-disk-utilization-per-disk-percentage", "95"); - this.yarnCluster = new MiniYARNCluster(getClass().getName(), 2, 1, 1); + baseConfig.set("yarn.nodemanager.disk-health-checker.max-disk-utilization-per-disk-percentage", "95"); + this.yarnCluster = new MiniYARNCluster(getClass().getName(), 2, + 1, 1); yarnCluster.init(baseConfig); // Install a shutdown hook for stop the service and kill all running applications. - Runtime.getRuntime() - .addShutdownHook( - new Thread() { - @Override - public void run() { - yarnCluster.stop(); - } - }); + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + yarnCluster.stop(); + } + }); yarnCluster.start(); @@ -77,7 +77,7 @@ public class MiniHadoopCluster { } LOGGER.info("RM address in configuration is " + yarnConfig.get(YarnConfiguration.RM_ADDRESS)); - saveConfig(yarnConfig, configPath + "/yarn-site.xml"); + saveConfig(yarnConfig,configPath + "/yarn-site.xml"); } protected void saveConfig(Configuration conf, String dest) throws IOException { http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/MiniZeppelin.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/MiniZeppelin.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/MiniZeppelin.java index 9bb2976..1a1a2f3 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/MiniZeppelin.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/MiniZeppelin.java @@ -1,10 +1,7 @@ package org.apache.zeppelin.interpreter; -import static org.mockito.Mockito.mock; - -import java.io.File; -import java.io.IOException; import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; import org.apache.zeppelin.conf.ZeppelinConfiguration; import org.apache.zeppelin.display.AngularObjectRegistryListener; import org.apache.zeppelin.helium.ApplicationEventListener; @@ -12,6 +9,11 @@ import org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcessListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; +import java.io.IOException; + +import static org.mockito.Mockito.mock; + public class MiniZeppelin { protected static final Logger LOGGER = LoggerFactory.getLogger(MiniZeppelin.class); @@ -25,32 +27,21 @@ public class MiniZeppelin { public void start() throws IOException { zeppelinHome = new File(".."); - System.setProperty( - ZeppelinConfiguration.ConfVars.ZEPPELIN_HOME.getVarName(), zeppelinHome.getAbsolutePath()); + System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_HOME.getVarName(), + zeppelinHome.getAbsolutePath()); confDir = new File(zeppelinHome, "conf_" + getClass().getSimpleName()); notebookDir = new File(zeppelinHome, "notebook_" + getClass().getSimpleName()); confDir.mkdirs(); notebookDir.mkdirs(); LOGGER.info("ZEPPELIN_HOME: " + zeppelinHome.getAbsolutePath()); - FileUtils.copyFile( - new File(zeppelinHome, "conf/log4j.properties"), new File(confDir, "log4j.properties")); - FileUtils.copyFile( - new File(zeppelinHome, "conf/log4j_yarn_cluster.properties"), - new File(confDir, "log4j_yarn_cluster.properties")); - System.setProperty( - ZeppelinConfiguration.ConfVars.ZEPPELIN_CONF_DIR.getVarName(), confDir.getAbsolutePath()); - System.setProperty( - ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), - notebookDir.getAbsolutePath()); - System.setProperty( - ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_CONNECT_TIMEOUT.getVarName(), "120000"); + FileUtils.copyFile(new File(zeppelinHome, "conf/log4j.properties"), new File(confDir, "log4j.properties")); + FileUtils.copyFile(new File(zeppelinHome, "conf/log4j_yarn_cluster.properties"), new File(confDir, "log4j_yarn_cluster.properties")); + System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_CONF_DIR.getVarName(), confDir.getAbsolutePath()); + System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), notebookDir.getAbsolutePath()); + System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_CONNECT_TIMEOUT.getVarName(), "120000"); conf = new ZeppelinConfiguration(); - interpreterSettingManager = - new InterpreterSettingManager( - conf, - mock(AngularObjectRegistryListener.class), - mock(RemoteInterpreterProcessListener.class), - mock(ApplicationEventListener.class)); + interpreterSettingManager = new InterpreterSettingManager(conf, + mock(AngularObjectRegistryListener.class), mock(RemoteInterpreterProcessListener.class), mock(ApplicationEventListener.class)); interpreterFactory = new InterpreterFactory(interpreterSettingManager); } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/SessionConfInterpreterTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/SessionConfInterpreterTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/SessionConfInterpreterTest.java index f28d1ce..7baa2e2 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/SessionConfInterpreterTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/SessionConfInterpreterTest.java @@ -15,17 +15,19 @@ * limitations under the License. */ + package org.apache.zeppelin.interpreter; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import org.apache.zeppelin.interpreter.remote.RemoteInterpreter; +import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Properties; -import org.apache.zeppelin.interpreter.remote.RemoteInterpreter; -import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class SessionConfInterpreterTest { @@ -39,8 +41,8 @@ public class SessionConfInterpreterTest { Properties properties = new Properties(); properties.setProperty("property_1", "value_1"); properties.setProperty("property_2", "value_2"); - SessionConfInterpreter confInterpreter = - new SessionConfInterpreter(properties, "session_1", "group_1", mockInterpreterSetting); + SessionConfInterpreter confInterpreter = new SessionConfInterpreter( + properties, "session_1", "group_1", mockInterpreterSetting); RemoteInterpreter remoteInterpreter = new RemoteInterpreter(properties, "session_1", "clasName", "user1", null); @@ -50,8 +52,8 @@ public class SessionConfInterpreterTest { when(mockInterpreterGroup.get("session_1")).thenReturn(interpreters); InterpreterResult result = - confInterpreter.interpret( - "property_1\tupdated_value_1\nproperty_3\tvalue_3", mock(InterpreterContext.class)); + confInterpreter.interpret("property_1\tupdated_value_1\nproperty_3\tvalue_3", + mock(InterpreterContext.class)); assertEquals(InterpreterResult.Code.SUCCESS, result.code); assertEquals(3, remoteInterpreter.getProperties().size()); assertEquals("updated_value_1", remoteInterpreter.getProperty("property_1")); @@ -60,8 +62,8 @@ public class SessionConfInterpreterTest { remoteInterpreter.setOpened(true); result = - confInterpreter.interpret( - "property_1\tupdated_value_1\nproperty_3\tvalue_3", mock(InterpreterContext.class)); + confInterpreter.interpret("property_1\tupdated_value_1\nproperty_3\tvalue_3", + mock(InterpreterContext.class)); assertEquals(InterpreterResult.Code.ERROR, result.code); } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/SleepInterpreter.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/SleepInterpreter.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/SleepInterpreter.java index eb2437f..7a904c6 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/SleepInterpreter.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/SleepInterpreter.java @@ -1,10 +1,13 @@ package org.apache.zeppelin.interpreter; -import java.util.Properties; import org.apache.zeppelin.scheduler.Scheduler; import org.apache.zeppelin.scheduler.SchedulerFactory; -/** Interpreter that only accept long value and sleep for such period */ +import java.util.Properties; + +/** + * Interpreter that only accept long value and sleep for such period + */ public class SleepInterpreter extends Interpreter { public SleepInterpreter(Properties property) { @@ -12,10 +15,14 @@ public class SleepInterpreter extends Interpreter { } @Override - public void open() {} + public void open() { + + } @Override - public void close() {} + public void close() { + + } @Override public InterpreterResult interpret(String st, InterpreterContext context) { @@ -28,7 +35,9 @@ public class SleepInterpreter extends Interpreter { } @Override - public void cancel(InterpreterContext context) {} + public void cancel(InterpreterContext context) { + + } @Override public FormType getFormType() { @@ -38,8 +47,8 @@ public class SleepInterpreter extends Interpreter { @Override public Scheduler getScheduler() { if (Boolean.parseBoolean(getProperty("zeppelin.SleepInterpreter.parallel", "false"))) { - return SchedulerFactory.singleton() - .createOrGetParallelScheduler("Parallel-" + SleepInterpreter.class.getName(), 10); + return SchedulerFactory.singleton().createOrGetParallelScheduler( + "Parallel-" + SleepInterpreter.class.getName(), 10); } return super.getScheduler(); } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/SparkIntegrationTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/SparkIntegrationTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/SparkIntegrationTest.java index a97751e..fed9ad2 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/SparkIntegrationTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/SparkIntegrationTest.java @@ -1,12 +1,5 @@ package org.apache.zeppelin.interpreter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.util.Arrays; -import java.util.EnumSet; -import java.util.List; import org.apache.commons.io.IOUtils; import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest; import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse; @@ -20,6 +13,14 @@ import org.junit.runners.Parameterized; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; +import java.util.Arrays; +import java.util.EnumSet; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + @RunWith(value = Parameterized.class) public class SparkIntegrationTest { private static Logger LOGGER = LoggerFactory.getLogger(SparkIntegrationTest.class); @@ -40,7 +41,12 @@ public class SparkIntegrationTest { @Parameterized.Parameters public static List<Object[]> data() { - return Arrays.asList(new Object[][] {{"2.2.1"}, {"2.1.2"}, {"2.0.2"}, {"1.6.3"}}); + return Arrays.asList(new Object[][]{ + {"2.2.1"}, + {"2.1.2"}, + {"2.0.2"}, + {"1.6.3"} + }); } @BeforeClass @@ -66,54 +72,40 @@ public class SparkIntegrationTest { private void testInterpreterBasics() throws IOException, InterpreterException { // test SparkInterpreter - Interpreter sparkInterpreter = - interpreterFactory.getInterpreter("user1", "note1", "spark.spark", "test"); + Interpreter sparkInterpreter = interpreterFactory.getInterpreter("user1", "note1", "spark.spark", "test"); - InterpreterContext context = - new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").build(); + InterpreterContext context = new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").build(); InterpreterResult interpreterResult = sparkInterpreter.interpret("sc.version", context); assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code); String detectedSparkVersion = interpreterResult.message().get(0).getData(); - assertTrue( - detectedSparkVersion + " doesn't contain " + this.sparkVersion, - detectedSparkVersion.contains(this.sparkVersion)); + assertTrue(detectedSparkVersion +" doesn't contain " + this.sparkVersion, detectedSparkVersion.contains(this.sparkVersion)); interpreterResult = sparkInterpreter.interpret("sc.range(1,10).sum()", context); assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code); assertTrue(interpreterResult.msg.get(0).getData().contains("45")); // test PySparkInterpreter - Interpreter pySparkInterpreter = - interpreterFactory.getInterpreter("user1", "note1", "spark.pyspark", "test"); - interpreterResult = - pySparkInterpreter.interpret( - "sqlContext.createDataFrame([(1,'a'),(2,'b')], ['id','name']).registerTempTable('test')", - context); + Interpreter pySparkInterpreter = interpreterFactory.getInterpreter("user1", "note1", "spark.pyspark", "test"); + interpreterResult = pySparkInterpreter.interpret("sqlContext.createDataFrame([(1,'a'),(2,'b')], ['id','name']).registerTempTable('test')", context); assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code); // test IPySparkInterpreter - Interpreter ipySparkInterpreter = - interpreterFactory.getInterpreter("user1", "note1", "spark.ipyspark", "test"); + Interpreter ipySparkInterpreter = interpreterFactory.getInterpreter("user1", "note1", "spark.ipyspark", "test"); interpreterResult = ipySparkInterpreter.interpret("sqlContext.table('test').show()", context); assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code); // test SparkSQLInterpreter - Interpreter sqlInterpreter = - interpreterFactory.getInterpreter("user1", "note1", "spark.sql", "test"); + Interpreter sqlInterpreter = interpreterFactory.getInterpreter("user1", "note1", "spark.sql", "test"); interpreterResult = sqlInterpreter.interpret("select count(1) as c from test", context); assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code); assertEquals(InterpreterResult.Type.TABLE, interpreterResult.message().get(0).getType()); assertEquals("c\n2\n", interpreterResult.message().get(0).getData()); // test SparkRInterpreter - Interpreter sparkrInterpreter = - interpreterFactory.getInterpreter("user1", "note1", "spark.r", "test"); + Interpreter sparkrInterpreter = interpreterFactory.getInterpreter("user1", "note1", "spark.r", "test"); if (isSpark2()) { - interpreterResult = - sparkrInterpreter.interpret("df <- as.DataFrame(faithful)\nhead(df)", context); + interpreterResult = sparkrInterpreter.interpret("df <- as.DataFrame(faithful)\nhead(df)", context); } else { - interpreterResult = - sparkrInterpreter.interpret( - "df <- createDataFrame(sqlContext, faithful)\nhead(df)", context); + interpreterResult = sparkrInterpreter.interpret("df <- createDataFrame(sqlContext, faithful)\nhead(df)", context); } assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code); assertEquals(InterpreterResult.Type.TEXT, interpreterResult.message().get(0).getType()); @@ -122,41 +114,30 @@ public class SparkIntegrationTest { @Test public void testLocalMode() throws IOException, YarnException, InterpreterException { - InterpreterSetting sparkInterpreterSetting = - interpreterSettingManager.getInterpreterSettingByName("spark"); + InterpreterSetting sparkInterpreterSetting = interpreterSettingManager.getInterpreterSettingByName("spark"); sparkInterpreterSetting.setProperty("master", "local[*]"); sparkInterpreterSetting.setProperty("SPARK_HOME", sparkHome); - sparkInterpreterSetting.setProperty( - "ZEPPELIN_CONF_DIR", zeppelin.getZeppelinConfDir().getAbsolutePath()); + sparkInterpreterSetting.setProperty("ZEPPELIN_CONF_DIR", zeppelin.getZeppelinConfDir().getAbsolutePath()); sparkInterpreterSetting.setProperty("zeppelin.spark.useHiveContext", "false"); sparkInterpreterSetting.setProperty("zeppelin.pyspark.useIPython", "false"); testInterpreterBasics(); // no yarn application launched - GetApplicationsRequest request = - GetApplicationsRequest.newInstance(EnumSet.of(YarnApplicationState.RUNNING)); - GetApplicationsResponse response = - hadoopCluster - .getYarnCluster() - .getResourceManager() - .getClientRMService() - .getApplications(request); + GetApplicationsRequest request = GetApplicationsRequest.newInstance(EnumSet.of(YarnApplicationState.RUNNING)); + GetApplicationsResponse response = hadoopCluster.getYarnCluster().getResourceManager().getClientRMService().getApplications(request); assertEquals(0, response.getApplicationList().size()); interpreterSettingManager.close(); } @Test - public void testYarnClientMode() - throws IOException, YarnException, InterruptedException, InterpreterException { - InterpreterSetting sparkInterpreterSetting = - interpreterSettingManager.getInterpreterSettingByName("spark"); + public void testYarnClientMode() throws IOException, YarnException, InterruptedException, InterpreterException { + InterpreterSetting sparkInterpreterSetting = interpreterSettingManager.getInterpreterSettingByName("spark"); sparkInterpreterSetting.setProperty("master", "yarn-client"); sparkInterpreterSetting.setProperty("HADOOP_CONF_DIR", hadoopCluster.getConfigPath()); sparkInterpreterSetting.setProperty("SPARK_HOME", sparkHome); - sparkInterpreterSetting.setProperty( - "ZEPPELIN_CONF_DIR", zeppelin.getZeppelinConfDir().getAbsolutePath()); + sparkInterpreterSetting.setProperty("ZEPPELIN_CONF_DIR", zeppelin.getZeppelinConfDir().getAbsolutePath()); sparkInterpreterSetting.setProperty("zeppelin.spark.useHiveContext", "false"); sparkInterpreterSetting.setProperty("zeppelin.pyspark.useIPython", "false"); sparkInterpreterSetting.setProperty("PYSPARK_PYTHON", getPythonExec()); @@ -165,29 +146,20 @@ public class SparkIntegrationTest { testInterpreterBasics(); // 1 yarn application launched - GetApplicationsRequest request = - GetApplicationsRequest.newInstance(EnumSet.of(YarnApplicationState.RUNNING)); - GetApplicationsResponse response = - hadoopCluster - .getYarnCluster() - .getResourceManager() - .getClientRMService() - .getApplications(request); + GetApplicationsRequest request = GetApplicationsRequest.newInstance(EnumSet.of(YarnApplicationState.RUNNING)); + GetApplicationsResponse response = hadoopCluster.getYarnCluster().getResourceManager().getClientRMService().getApplications(request); assertEquals(1, response.getApplicationList().size()); interpreterSettingManager.close(); } @Test - public void testYarnClusterMode() - throws IOException, YarnException, InterruptedException, InterpreterException { - InterpreterSetting sparkInterpreterSetting = - interpreterSettingManager.getInterpreterSettingByName("spark"); + public void testYarnClusterMode() throws IOException, YarnException, InterruptedException, InterpreterException { + InterpreterSetting sparkInterpreterSetting = interpreterSettingManager.getInterpreterSettingByName("spark"); sparkInterpreterSetting.setProperty("master", "yarn-cluster"); sparkInterpreterSetting.setProperty("HADOOP_CONF_DIR", hadoopCluster.getConfigPath()); sparkInterpreterSetting.setProperty("SPARK_HOME", sparkHome); - sparkInterpreterSetting.setProperty( - "ZEPPELIN_CONF_DIR", zeppelin.getZeppelinConfDir().getAbsolutePath()); + sparkInterpreterSetting.setProperty("ZEPPELIN_CONF_DIR", zeppelin.getZeppelinConfDir().getAbsolutePath()); sparkInterpreterSetting.setProperty("zeppelin.spark.useHiveContext", "false"); sparkInterpreterSetting.setProperty("zeppelin.pyspark.useIPython", "false"); sparkInterpreterSetting.setProperty("PYSPARK_PYTHON", getPythonExec()); @@ -196,14 +168,8 @@ public class SparkIntegrationTest { testInterpreterBasics(); // 1 yarn application launched - GetApplicationsRequest request = - GetApplicationsRequest.newInstance(EnumSet.of(YarnApplicationState.RUNNING)); - GetApplicationsResponse response = - hadoopCluster - .getYarnCluster() - .getResourceManager() - .getClientRMService() - .getApplications(request); + GetApplicationsRequest request = GetApplicationsRequest.newInstance(EnumSet.of(YarnApplicationState.RUNNING)); + GetApplicationsResponse response = hadoopCluster.getYarnCluster().getResourceManager().getClientRMService().getApplications(request); assertEquals(1, response.getApplicationList().size()); interpreterSettingManager.close(); @@ -214,7 +180,7 @@ public class SparkIntegrationTest { } private String getPythonExec() throws IOException, InterruptedException { - Process process = Runtime.getRuntime().exec(new String[] {"which", "python"}); + Process process = Runtime.getRuntime().exec(new String[]{"which", "python"}); if (process.waitFor() != 0) { throw new RuntimeException("Fail to run command: which python."); }
