http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/install/InstallInterpreterTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/install/InstallInterpreterTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/install/InstallInterpreterTest.java index e934f1a..a03cee9 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/install/InstallInterpreterTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/install/InstallInterpreterTest.java @@ -1,17 +1,16 @@ package org.apache.zeppelin.interpreter.install; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; import org.apache.commons.io.FileUtils; import org.apache.zeppelin.conf.ZeppelinConfiguration; import org.junit.After; import org.junit.Before; import org.junit.Test; -import java.io.File; -import java.io.IOException; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -35,7 +34,9 @@ public class InstallInterpreterTest { @Before public void setUp() throws IOException { - tmpDir = new File(System.getProperty("java.io.tmpdir")+"/ZeppelinLTest_"+System.currentTimeMillis()); + tmpDir = + new File( + System.getProperty("java.io.tmpdir") + "/ZeppelinLTest_" + System.currentTimeMillis()); new File(tmpDir, "conf").mkdirs(); interpreterBaseDir = new File(tmpDir, "interpreter"); File localRepoDir = new File(tmpDir, "local-repo"); @@ -44,9 +45,9 @@ public class InstallInterpreterTest { File interpreterListFile = new File(tmpDir, "conf/interpreter-list"); - // create interpreter list file - System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_HOME.getVarName(), tmpDir.getAbsolutePath()); + System.setProperty( + ZeppelinConfiguration.ConfVars.ZEPPELIN_HOME.getVarName(), tmpDir.getAbsolutePath()); String interpreterList = ""; interpreterList += "intp1 org.apache.commons:commons-csv:1.1 test interpreter 1\n"; @@ -54,8 +55,9 @@ public class InstallInterpreterTest { FileUtils.writeStringToFile(new File(tmpDir, "conf/interpreter-list"), interpreterList); - installer = new InstallInterpreter(interpreterListFile, interpreterBaseDir, localRepoDir - .getAbsolutePath()); + installer = + new InstallInterpreter( + interpreterListFile, interpreterBaseDir, localRepoDir.getAbsolutePath()); } @After @@ -63,7 +65,6 @@ public class InstallInterpreterTest { FileUtils.deleteDirectory(tmpDir); } - @Test public void testList() { assertEquals(2, installer.list().size());
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/lifecycle/TimeoutLifecycleManagerTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/lifecycle/TimeoutLifecycleManagerTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/lifecycle/TimeoutLifecycleManagerTest.java index db08016..0576e9b 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/lifecycle/TimeoutLifecycleManagerTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/lifecycle/TimeoutLifecycleManagerTest.java @@ -17,6 +17,12 @@ package org.apache.zeppelin.interpreter.lifecycle; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.util.Map; import org.apache.zeppelin.conf.ZeppelinConfiguration; import org.apache.zeppelin.interpreter.AbstractInterpreterTest; import org.apache.zeppelin.interpreter.InterpreterContext; @@ -26,39 +32,43 @@ import org.apache.zeppelin.interpreter.remote.RemoteInterpreter; import org.apache.zeppelin.scheduler.Job; import org.junit.Test; -import java.io.IOException; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - public class TimeoutLifecycleManagerTest extends AbstractInterpreterTest { @Override public void setUp() throws Exception { - System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_LIFECYCLE_MANAGER_CLASS.getVarName(), + System.setProperty( + ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_LIFECYCLE_MANAGER_CLASS.getVarName(), TimeoutLifecycleManager.class.getName()); - System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_LIFECYCLE_MANAGER_TIMEOUT_CHECK_INTERVAL.getVarName(), "1000"); - System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_LIFECYCLE_MANAGER_TIMEOUT_THRESHOLD.getVarName(), "10000"); + System.setProperty( + ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_LIFECYCLE_MANAGER_TIMEOUT_CHECK_INTERVAL + .getVarName(), + "1000"); + System.setProperty( + ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_LIFECYCLE_MANAGER_TIMEOUT_THRESHOLD + .getVarName(), + "10000"); super.setUp(); } @Test public void testTimeout_1() throws InterpreterException, InterruptedException, IOException { - assertTrue(interpreterFactory.getInterpreter("user1", "note1", "test.echo", "test") instanceof RemoteInterpreter); - RemoteInterpreter remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("user1", "note1", "test.echo", "test"); + assertTrue( + interpreterFactory.getInterpreter("user1", "note1", "test.echo", "test") + instanceof RemoteInterpreter); + RemoteInterpreter remoteInterpreter = + (RemoteInterpreter) + interpreterFactory.getInterpreter("user1", "note1", "test.echo", "test"); assertFalse(remoteInterpreter.isOpened()); - InterpreterSetting interpreterSetting = interpreterSettingManager.getInterpreterSettingByName("test"); + InterpreterSetting interpreterSetting = + interpreterSettingManager.getInterpreterSettingByName("test"); assertEquals(1, interpreterSetting.getAllInterpreterGroups().size()); - Thread.sleep(15*1000); - // InterpreterGroup is not removed after 15 seconds, as TimeoutLifecycleManager only manage it after it is started + Thread.sleep(15 * 1000); + // InterpreterGroup is not removed after 15 seconds, as TimeoutLifecycleManager only manage it + // after it is started assertEquals(1, interpreterSetting.getAllInterpreterGroups().size()); - InterpreterContext context = InterpreterContext.builder() - .setNoteId("noteId") - .setParagraphId("paragraphId") - .build(); + InterpreterContext context = + InterpreterContext.builder().setNoteId("noteId").setParagraphId("paragraphId").build(); remoteInterpreter.interpret("hello world", context); assertTrue(remoteInterpreter.isOpened()); @@ -70,52 +80,59 @@ public class TimeoutLifecycleManagerTest extends AbstractInterpreterTest { @Test public void testTimeout_2() throws InterpreterException, InterruptedException, IOException { - assertTrue(interpreterFactory.getInterpreter("user1", "note1", "test.sleep", "test") instanceof RemoteInterpreter); - final RemoteInterpreter remoteInterpreter = (RemoteInterpreter) interpreterFactory.getInterpreter("user1", "note1", "test.sleep", "test"); + assertTrue( + interpreterFactory.getInterpreter("user1", "note1", "test.sleep", "test") + instanceof RemoteInterpreter); + final RemoteInterpreter remoteInterpreter = + (RemoteInterpreter) + interpreterFactory.getInterpreter("user1", "note1", "test.sleep", "test"); // simulate how zeppelin submit paragraph - remoteInterpreter.getScheduler().submit(new Job("test-job", null) { - @Override - public Object getReturn() { - return null; - } - - @Override - public int progress() { - return 0; - } - - @Override - public Map<String, Object> info() { - return null; - } - - @Override - protected Object jobRun() throws Throwable { - InterpreterContext context = InterpreterContext.builder() - .setNoteId("noteId") - .setParagraphId("paragraphId") - .build(); - return remoteInterpreter.interpret("100000", context); - } - - @Override - protected boolean jobAbort() { - return false; - } - - @Override - public void setResult(Object results) { - - } - }); - - while(!remoteInterpreter.isOpened()) { + remoteInterpreter + .getScheduler() + .submit( + new Job("test-job", null) { + @Override + public Object getReturn() { + return null; + } + + @Override + public int progress() { + return 0; + } + + @Override + public Map<String, Object> info() { + return null; + } + + @Override + protected Object jobRun() throws Throwable { + InterpreterContext context = + InterpreterContext.builder() + .setNoteId("noteId") + .setParagraphId("paragraphId") + .build(); + return remoteInterpreter.interpret("100000", context); + } + + @Override + protected boolean jobAbort() { + return false; + } + + @Override + public void setResult(Object results) {} + }); + + while (!remoteInterpreter.isOpened()) { Thread.sleep(1000); LOGGER.info("Wait for interpreter to be started"); } - InterpreterSetting interpreterSetting = interpreterSettingManager.getInterpreterSettingByName("test"); + InterpreterSetting interpreterSetting = + interpreterSettingManager.getInterpreterSettingByName("test"); assertEquals(1, interpreterSetting.getAllInterpreterGroups().size()); Thread.sleep(15 * 1000); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/mock/MockInterpreter1.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/mock/MockInterpreter1.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/mock/MockInterpreter1.java index 500c4f7..c466641 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/mock/MockInterpreter1.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/mock/MockInterpreter1.java @@ -1,115 +1,115 @@ /* -* 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. -*/ + * 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.interpreter.mock; -import org.apache.zeppelin.interpreter.Interpreter; -import org.apache.zeppelin.interpreter.InterpreterContext; -import org.apache.zeppelin.interpreter.InterpreterResult; -import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; -import org.apache.zeppelin.scheduler.Scheduler; -import org.apache.zeppelin.scheduler.SchedulerFactory; - import java.lang.management.ManagementFactory; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.concurrent.atomic.AtomicInteger; +import org.apache.zeppelin.interpreter.Interpreter; +import org.apache.zeppelin.interpreter.InterpreterContext; +import org.apache.zeppelin.interpreter.InterpreterResult; +import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; +import org.apache.zeppelin.scheduler.Scheduler; +import org.apache.zeppelin.scheduler.SchedulerFactory; public class MockInterpreter1 extends Interpreter { - private static AtomicInteger IdGenerator = new AtomicInteger(); - - private int object_id; - private String pid; - Map<String, Object> vars = new HashMap<>(); - - public MockInterpreter1(Properties property) { - super(property); - this.object_id = IdGenerator.getAndIncrement(); - this.pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0]; - } - - boolean open; - - - @Override - public void open() { - open = true; - } - - @Override - public void close() { - open = false; - } - - - public boolean isOpen() { - return open; - } - - @Override - public InterpreterResult interpret(String st, InterpreterContext context) { - InterpreterResult result; - - if ("getId".equals(st)) { - // get unique id of this interpreter instance - result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "" + this.object_id + "-" + this.pid); - } else if (st.startsWith("sleep")) { - try { - Thread.sleep(Integer.parseInt(st.split(" ")[1])); - } catch (InterruptedException e) { - // nothing to do - } - result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "repl1: " + st); - } else { - result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "repl1: " + st); - } - - if (context.getResourcePool() != null) { - context.getResourcePool().put(context.getNoteId(), context.getParagraphId(), "result", result); - } - - return result; - } - - @Override - public void cancel(InterpreterContext context) { - } - - @Override - public FormType getFormType() { - return FormType.SIMPLE; - } - - @Override - public int getProgress(InterpreterContext context) { - return 0; - } - - @Override - public Scheduler getScheduler() { - return SchedulerFactory.singleton().createOrGetFIFOScheduler("test_"+this.hashCode()); - } - - @Override - public List<InterpreterCompletion> completion(String buf, int cursor, - InterpreterContext interpreterContext) { - return null; - } + private static AtomicInteger IdGenerator = new AtomicInteger(); + + private int object_id; + private String pid; + Map<String, Object> vars = new HashMap<>(); + + public MockInterpreter1(Properties property) { + super(property); + this.object_id = IdGenerator.getAndIncrement(); + this.pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0]; + } + + boolean open; + + @Override + public void open() { + open = true; + } + + @Override + public void close() { + open = false; + } + + public boolean isOpen() { + return open; + } + + @Override + public InterpreterResult interpret(String st, InterpreterContext context) { + InterpreterResult result; + + if ("getId".equals(st)) { + // get unique id of this interpreter instance + result = + new InterpreterResult( + InterpreterResult.Code.SUCCESS, "" + this.object_id + "-" + this.pid); + } else if (st.startsWith("sleep")) { + try { + Thread.sleep(Integer.parseInt(st.split(" ")[1])); + } catch (InterruptedException e) { + // nothing to do + } + result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "repl1: " + st); + } else { + result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "repl1: " + st); + } + + if (context.getResourcePool() != null) { + context + .getResourcePool() + .put(context.getNoteId(), context.getParagraphId(), "result", result); + } + + return result; + } + + @Override + public void cancel(InterpreterContext context) {} + + @Override + public FormType getFormType() { + return FormType.SIMPLE; + } + + @Override + public int getProgress(InterpreterContext context) { + return 0; + } + + @Override + public Scheduler getScheduler() { + return SchedulerFactory.singleton().createOrGetFIFOScheduler("test_" + this.hashCode()); + } + + @Override + public List<InterpreterCompletion> completion( + String buf, int cursor, InterpreterContext interpreterContext) { + return null; + } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/mock/MockInterpreter2.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/mock/MockInterpreter2.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/mock/MockInterpreter2.java index f36df56..0d70635 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/mock/MockInterpreter2.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/mock/MockInterpreter2.java @@ -17,6 +17,10 @@ package org.apache.zeppelin.interpreter.mock; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; import org.apache.zeppelin.interpreter.Interpreter; import org.apache.zeppelin.interpreter.InterpreterContext; import org.apache.zeppelin.interpreter.InterpreterResult; @@ -24,81 +28,76 @@ import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; import org.apache.zeppelin.scheduler.Scheduler; import org.apache.zeppelin.scheduler.SchedulerFactory; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -public class MockInterpreter2 extends Interpreter{ +public class MockInterpreter2 extends Interpreter { Map<String, Object> vars = new HashMap<>(); - public MockInterpreter2(Properties property) { - super(property); - } - - boolean open; - - @Override - public void open() { - open = true; - } - - @Override - public void close() { - open = false; - } - - public boolean isOpen() { - return open; - } - - - @Override - public InterpreterResult interpret(String st, InterpreterContext context) { - InterpreterResult result; - - if ("getId".equals(st)) { - // get unique id of this interpreter instance - result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "" + this.hashCode()); - } else if (st.startsWith("sleep")) { - try { - Thread.sleep(Integer.parseInt(st.split(" ")[1])); - } catch (InterruptedException e) { - // nothing to do - } - result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "repl2: " + st); - } else { - result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "repl2: " + st); - } - - if (context.getResourcePool() != null) { - context.getResourcePool().put(context.getNoteId(), context.getParagraphId(), "result", result); - } - return result; - } - - @Override - public void cancel(InterpreterContext context) { - } - - @Override - public FormType getFormType() { - return FormType.SIMPLE; - } - - @Override - public int getProgress(InterpreterContext context) { - return 0; - } - - @Override - public Scheduler getScheduler() { - return SchedulerFactory.singleton().createOrGetFIFOScheduler("test_"+this.hashCode()); - } - - @Override - public List<InterpreterCompletion> completion(String buf, int cursor, - InterpreterContext interpreterContext) { - return null; - } + public MockInterpreter2(Properties property) { + super(property); + } + + boolean open; + + @Override + public void open() { + open = true; + } + + @Override + public void close() { + open = false; + } + + public boolean isOpen() { + return open; + } + + @Override + public InterpreterResult interpret(String st, InterpreterContext context) { + InterpreterResult result; + + if ("getId".equals(st)) { + // get unique id of this interpreter instance + result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "" + this.hashCode()); + } else if (st.startsWith("sleep")) { + try { + Thread.sleep(Integer.parseInt(st.split(" ")[1])); + } catch (InterruptedException e) { + // nothing to do + } + result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "repl2: " + st); + } else { + result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "repl2: " + st); + } + + if (context.getResourcePool() != null) { + context + .getResourcePool() + .put(context.getNoteId(), context.getParagraphId(), "result", result); + } + return result; + } + + @Override + public void cancel(InterpreterContext context) {} + + @Override + public FormType getFormType() { + return FormType.SIMPLE; + } + + @Override + public int getProgress(InterpreterContext context) { + return 0; + } + + @Override + public Scheduler getScheduler() { + return SchedulerFactory.singleton().createOrGetFIFOScheduler("test_" + this.hashCode()); + } + + @Override + public List<InterpreterCompletion> completion( + String buf, int cursor, InterpreterContext interpreterContext) { + return null; + } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/recovery/FileSystemRecoveryStorageTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/recovery/FileSystemRecoveryStorageTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/recovery/FileSystemRecoveryStorageTest.java index 2eaed74..c0b4f3a 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/recovery/FileSystemRecoveryStorageTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/recovery/FileSystemRecoveryStorageTest.java @@ -1,6 +1,10 @@ package org.apache.zeppelin.interpreter.recovery; +import static org.junit.Assert.assertEquals; + import com.google.common.io.Files; +import java.io.File; +import java.io.IOException; import org.apache.commons.io.FileUtils; import org.apache.zeppelin.conf.ZeppelinConfiguration; import org.apache.zeppelin.interpreter.AbstractInterpreterTest; @@ -13,21 +17,19 @@ import org.apache.zeppelin.interpreter.remote.RemoteInterpreter; import org.junit.Before; import org.junit.Test; -import java.io.File; -import java.io.IOException; - -import static org.junit.Assert.assertEquals; - public class FileSystemRecoveryStorageTest extends AbstractInterpreterTest { private File recoveryDir = null; @Before public void setUp() throws Exception { - System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_RECOVERY_STORAGE_CLASS.getVarName(), + System.setProperty( + ZeppelinConfiguration.ConfVars.ZEPPELIN_RECOVERY_STORAGE_CLASS.getVarName(), FileSystemRecoveryStorage.class.getName()); recoveryDir = Files.createTempDir(); - System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_RECOVERY_DIR.getVarName(), recoveryDir.getAbsolutePath()); + System.setProperty( + ZeppelinConfiguration.ConfVars.ZEPPELIN_RECOVERY_DIR.getVarName(), + recoveryDir.getAbsolutePath()); super.setUp(); } @@ -44,10 +46,8 @@ public class FileSystemRecoveryStorageTest extends AbstractInterpreterTest { Interpreter interpreter1 = interpreterSetting.getDefaultInterpreter("user1", "note1"); RemoteInterpreter remoteInterpreter1 = (RemoteInterpreter) interpreter1; - InterpreterContext context1 = InterpreterContext.builder() - .setNoteId("noteId") - .setParagraphId("paragraphId") - .build(); + InterpreterContext context1 = + InterpreterContext.builder().setNoteId("noteId").setParagraphId("paragraphId").build(); remoteInterpreter1.interpret("hello", context1); assertEquals(1, interpreterSettingManager.getRecoveryStorage().restore().size()); @@ -63,19 +63,15 @@ public class FileSystemRecoveryStorageTest extends AbstractInterpreterTest { Interpreter interpreter1 = interpreterSetting.getDefaultInterpreter("user1", "note1"); RemoteInterpreter remoteInterpreter1 = (RemoteInterpreter) interpreter1; - InterpreterContext context1 = InterpreterContext.builder() - .setNoteId("noteId") - .setParagraphId("paragraphId") - .build(); + InterpreterContext context1 = + InterpreterContext.builder().setNoteId("noteId").setParagraphId("paragraphId").build(); remoteInterpreter1.interpret("hello", context1); assertEquals(1, interpreterSettingManager.getRecoveryStorage().restore().size()); Interpreter interpreter2 = interpreterSetting.getDefaultInterpreter("user2", "note2"); RemoteInterpreter remoteInterpreter2 = (RemoteInterpreter) interpreter2; - InterpreterContext context2 = InterpreterContext.builder() - .setNoteId("noteId") - .setParagraphId("paragraphId") - .build(); + InterpreterContext context2 = + InterpreterContext.builder().setNoteId("noteId").setParagraphId("paragraphId").build(); remoteInterpreter2.interpret("hello", context2); assertEquals(2, interpreterSettingManager.getRecoveryStorage().restore().size()); @@ -86,5 +82,4 @@ public class FileSystemRecoveryStorageTest extends AbstractInterpreterTest { interpreterSetting.close(); assertEquals(0, interpreterSettingManager.getRecoveryStorage().restore().size()); } - } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/AppendOutputRunnerTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/AppendOutputRunnerTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/AppendOutputRunnerTest.java index 7bbd2b8..decc19d 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/AppendOutputRunnerTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/AppendOutputRunnerTest.java @@ -17,6 +17,18 @@ package org.apache.zeppelin.interpreter.remote; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Mockito.*; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; import org.apache.log4j.AppenderSkeleton; import org.apache.log4j.Level; import org.apache.log4j.Logger; @@ -26,30 +38,18 @@ import org.junit.Test; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Mockito.*; - public class AppendOutputRunnerTest { private static final int NUM_EVENTS = 10000; private static final int NUM_CLUBBED_EVENTS = 100; - private static final ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(); + private static final ScheduledExecutorService service = + Executors.newSingleThreadScheduledExecutor(); private static ScheduledFuture<?> future = null; /* It is being accessed by multiple threads. * While loop for 'loopForBufferCompletion' could * run for-ever. */ - private volatile static int numInvocations = 0; + private static volatile int numInvocations = 0; @After public void afterEach() { @@ -64,7 +64,8 @@ public class AppendOutputRunnerTest { String[][] buffer = {{"note", "para", "data\n"}}; loopForCompletingEvents(listener, 1, buffer); - verify(listener, times(1)).onOutputAppend(any(String.class), any(String.class), anyInt(), any(String.class)); + verify(listener, times(1)) + .onOutputAppend(any(String.class), any(String.class), anyInt(), any(String.class)); verify(listener, times(1)).onOutputAppend("note", "para", 0, "data\n"); } @@ -74,13 +75,14 @@ public class AppendOutputRunnerTest { String note1 = "note1"; String para1 = "para1"; String[][] buffer = { - {note1, para1, "data1\n"}, - {note1, para1, "data2\n"}, - {note1, para1, "data3\n"} + {note1, para1, "data1\n"}, + {note1, para1, "data2\n"}, + {note1, para1, "data3\n"} }; loopForCompletingEvents(listener, 1, buffer); - verify(listener, times(1)).onOutputAppend(any(String.class), any(String.class), anyInt(), any(String.class)); + verify(listener, times(1)) + .onOutputAppend(any(String.class), any(String.class), anyInt(), any(String.class)); verify(listener, times(1)).onOutputAppend(note1, para1, 0, "data1\ndata2\ndata3\n"); } @@ -92,14 +94,15 @@ public class AppendOutputRunnerTest { String para1 = "para1"; String para2 = "para2"; String[][] buffer = { - {note1, para1, "data1\n"}, - {note1, para2, "data2\n"}, - {note2, para1, "data3\n"}, - {note2, para2, "data4\n"} + {note1, para1, "data1\n"}, + {note1, para2, "data2\n"}, + {note2, para1, "data3\n"}, + {note2, para2, "data4\n"} }; loopForCompletingEvents(listener, 4, buffer); - verify(listener, times(4)).onOutputAppend(any(String.class), any(String.class), anyInt(), any(String.class)); + verify(listener, times(4)) + .onOutputAppend(any(String.class), any(String.class), anyInt(), any(String.class)); verify(listener, times(1)).onOutputAppend(note1, para1, 0, "data1\n"); verify(listener, times(1)).onOutputAppend(note1, para2, 0, "data2\n"); verify(listener, times(1)).onOutputAppend(note2, para1, 0, "data3\n"); @@ -110,8 +113,9 @@ public class AppendOutputRunnerTest { public void testClubbedData() throws InterruptedException { RemoteInterpreterProcessListener listener = mock(RemoteInterpreterProcessListener.class); AppendOutputRunner runner = new AppendOutputRunner(listener); - future = service.scheduleWithFixedDelay(runner, 0, - AppendOutputRunner.BUFFER_TIME_MS, TimeUnit.MILLISECONDS); + future = + service.scheduleWithFixedDelay( + runner, 0, AppendOutputRunner.BUFFER_TIME_MS, TimeUnit.MILLISECONDS); Thread thread = new Thread(new BombardEvents(runner)); thread.start(); thread.join(); @@ -122,7 +126,8 @@ public class AppendOutputRunnerTest { * calls, 30-40 Web-socket calls are made. Keeping * the unit-test to a pessimistic 100 web-socket calls. */ - verify(listener, atMost(NUM_CLUBBED_EVENTS)).onOutputAppend(any(String.class), any(String.class), anyInt(), any(String.class)); + verify(listener, atMost(NUM_CLUBBED_EVENTS)) + .onOutputAppend(any(String.class), any(String.class), anyInt(), any(String.class)); } @Test @@ -132,7 +137,7 @@ public class AppendOutputRunnerTest { String data = "data\n"; int numEvents = 100000; - for (int i=0; i<numEvents; i++) { + for (int i = 0; i < numEvents; i++) { runner.appendBuffer("noteId", "paraId", 0, data); } @@ -148,16 +153,18 @@ public class AppendOutputRunnerTest { do { warnLogCounter = 0; log = appender.getLog(); - for (LoggingEvent logEntry: log) { + for (LoggingEvent logEntry : log) { if (Level.WARN.equals(logEntry.getLevel())) { sizeWarnLogEntry = logEntry; warnLogCounter += 1; } } - } while(warnLogCounter != 2); + } while (warnLogCounter != 2); - String loggerString = "Processing size for buffered append-output is high: " + - (data.length() * numEvents) + " characters."; + String loggerString = + "Processing size for buffered append-output is high: " + + (data.length() * numEvents) + + " characters."; assertTrue(loggerString.equals(sizeWarnLogEntry.getMessage())); } @@ -173,7 +180,7 @@ public class AppendOutputRunnerTest { public void run() { String noteId = "noteId"; String paraId = "paraId"; - for (int i=0; i<NUM_EVENTS; i++) { + for (int i = 0; i < NUM_EVENTS; i++) { runner.appendBuffer(noteId, paraId, 0, "data\n"); } } @@ -184,48 +191,51 @@ public class AppendOutputRunnerTest { @Override public boolean requiresLayout() { - return false; + return false; } @Override protected void append(final LoggingEvent loggingEvent) { - log.add(loggingEvent); + log.add(loggingEvent); } @Override - public void close() { - } + public void close() {} public List<LoggingEvent> getLog() { - return new ArrayList<>(log); + return new ArrayList<>(log); } } private void prepareInvocationCounts(RemoteInterpreterProcessListener listener) { - doAnswer(new Answer<Void>() { - @Override - public Void answer(InvocationOnMock invocation) throws Throwable { - numInvocations += 1; - return null; - } - }).when(listener).onOutputAppend(any(String.class), any(String.class), anyInt(), any(String.class)); + doAnswer( + new Answer<Void>() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + numInvocations += 1; + return null; + } + }) + .when(listener) + .onOutputAppend(any(String.class), any(String.class), anyInt(), any(String.class)); } - private void loopForCompletingEvents(RemoteInterpreterProcessListener listener, - int numTimes, String[][] buffer) { + private void loopForCompletingEvents( + RemoteInterpreterProcessListener listener, int numTimes, String[][] buffer) { numInvocations = 0; prepareInvocationCounts(listener); AppendOutputRunner runner = new AppendOutputRunner(listener); - for (String[] bufferElement: buffer) { + for (String[] bufferElement : buffer) { runner.appendBuffer(bufferElement[0], bufferElement[1], 0, bufferElement[2]); } - future = service.scheduleWithFixedDelay(runner, 0, - AppendOutputRunner.BUFFER_TIME_MS, TimeUnit.MILLISECONDS); + future = + service.scheduleWithFixedDelay( + runner, 0, AppendOutputRunner.BUFFER_TIME_MS, TimeUnit.MILLISECONDS); long startTimeMs = System.currentTimeMillis(); - while(numInvocations != numTimes) { + while (numInvocations != numTimes) { if (System.currentTimeMillis() - startTimeMs > 2000) { fail("Buffered events were not sent for 2 seconds"); } } } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObjectTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObjectTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObjectTest.java index 1029696..757e402 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObjectTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObjectTest.java @@ -17,6 +17,9 @@ package org.apache.zeppelin.interpreter.remote; +import static org.junit.Assert.assertEquals; + +import java.util.concurrent.atomic.AtomicInteger; import org.apache.zeppelin.display.AngularObject; import org.apache.zeppelin.display.AngularObjectRegistry; import org.apache.zeppelin.display.AngularObjectRegistryListener; @@ -29,10 +32,6 @@ import org.apache.zeppelin.resource.LocalResourcePool; import org.junit.Before; import org.junit.Test; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.junit.Assert.assertEquals; - public class RemoteAngularObjectTest extends AbstractInterpreterTest implements AngularObjectRegistryListener { @@ -55,21 +54,24 @@ public class RemoteAngularObjectTest extends AbstractInterpreterTest interpreterSetting = interpreterSettingManager.getInterpreterSettingByName("test"); intp = (RemoteInterpreter) interpreterSetting.getInterpreter("user1", "note1", "mock_ao"); - localRegistry = (RemoteAngularObjectRegistry) intp.getInterpreterGroup().getAngularObjectRegistry(); - - context = InterpreterContext.builder() - .setNoteId("note") - .setParagraphId("id") - .setAngularObjectRegistry(new AngularObjectRegistry(intp.getInterpreterGroup().getId(), null)) - .setResourcePool(new LocalResourcePool("pool1")) - .build(); + localRegistry = + (RemoteAngularObjectRegistry) intp.getInterpreterGroup().getAngularObjectRegistry(); + + context = + InterpreterContext.builder() + .setNoteId("note") + .setParagraphId("id") + .setAngularObjectRegistry( + new AngularObjectRegistry(intp.getInterpreterGroup().getId(), null)) + .setResourcePool(new LocalResourcePool("pool1")) + .build(); intp.open(); - } @Test - public void testAngularObjectInterpreterSideCRUD() throws InterruptedException, InterpreterException { + public void testAngularObjectInterpreterSideCRUD() + throws InterruptedException, InterpreterException { InterpreterResult ret = intp.interpret("get", context); Thread.sleep(500); // waitFor eventpoller pool event String[] result = ret.message().get(0).getData().split(" "); @@ -102,7 +104,8 @@ public class RemoteAngularObjectTest extends AbstractInterpreterTest } @Test - public void testAngularObjectRemovalOnZeppelinServerSide() throws InterruptedException, InterpreterException { + public void testAngularObjectRemovalOnZeppelinServerSide() + throws InterruptedException, InterpreterException { // test if angularobject removal from server side propagate to interpreter process's registry. // will happen when notebook is removed. @@ -127,7 +130,8 @@ public class RemoteAngularObjectTest extends AbstractInterpreterTest } @Test - public void testAngularObjectAddOnZeppelinServerSide() throws InterruptedException, InterpreterException { + public void testAngularObjectAddOnZeppelinServerSide() + throws InterruptedException, InterpreterException { // test if angularobject add from server side propagate to interpreter process's registry. // will happen when zeppelin server loads notebook and restore the object into registry @@ -160,5 +164,4 @@ public class RemoteAngularObjectTest extends AbstractInterpreterTest public void onRemove(String interpreterGroupId, String name, String noteId, String paragraphId) { onRemove.incrementAndGet(); } - } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterOutputTestStream.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterOutputTestStream.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterOutputTestStream.java index 5e1cb7d..25e6f72 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterOutputTestStream.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterOutputTestStream.java @@ -17,6 +17,11 @@ package org.apache.zeppelin.interpreter.remote; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.List; +import java.util.Map; import org.apache.zeppelin.interpreter.AbstractInterpreterTest; import org.apache.zeppelin.interpreter.InterpreterContext; import org.apache.zeppelin.interpreter.InterpreterException; @@ -26,20 +31,10 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import java.io.IOException; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertEquals; - - -/** - * Test for remote interpreter output stream - */ +/** Test for remote interpreter output stream */ public class RemoteInterpreterOutputTestStream extends AbstractInterpreterTest implements RemoteInterpreterProcessListener { - private InterpreterSetting interpreterSetting; @Before @@ -54,15 +49,13 @@ public class RemoteInterpreterOutputTestStream extends AbstractInterpreterTest } private InterpreterContext createInterpreterContext() { - return InterpreterContext.builder() - .setNoteId("noteId") - .setParagraphId("id") - .build(); + return InterpreterContext.builder().setNoteId("noteId").setParagraphId("id").build(); } @Test public void testInterpreterResultOnly() throws InterpreterException { - RemoteInterpreter intp = (RemoteInterpreter) interpreterSetting.getInterpreter("user1", "note1", "mock_stream"); + RemoteInterpreter intp = + (RemoteInterpreter) interpreterSetting.getInterpreter("user1", "note1", "mock_stream"); InterpreterResult ret = intp.interpret("SUCCESS::staticresult", createInterpreterContext()); assertEquals(InterpreterResult.Code.SUCCESS, ret.code()); assertEquals("staticresult", ret.message().get(0).getData()); @@ -78,7 +71,8 @@ public class RemoteInterpreterOutputTestStream extends AbstractInterpreterTest @Test public void testInterpreterOutputStreamOnly() throws InterpreterException { - RemoteInterpreter intp = (RemoteInterpreter) interpreterSetting.getInterpreter("user1", "note1", "mock_stream"); + RemoteInterpreter intp = + (RemoteInterpreter) interpreterSetting.getInterpreter("user1", "note1", "mock_stream"); InterpreterResult ret = intp.interpret("SUCCESS:streamresult:", createInterpreterContext()); assertEquals(InterpreterResult.Code.SUCCESS, ret.code()); assertEquals("streamresult", ret.message().get(0).getData()); @@ -90,7 +84,8 @@ public class RemoteInterpreterOutputTestStream extends AbstractInterpreterTest @Test public void testInterpreterResultOutputStreamMixed() throws InterpreterException { - RemoteInterpreter intp = (RemoteInterpreter) interpreterSetting.getInterpreter("user1", "note1", "mock_stream"); + RemoteInterpreter intp = + (RemoteInterpreter) interpreterSetting.getInterpreter("user1", "note1", "mock_stream"); InterpreterResult ret = intp.interpret("SUCCESS:stream:static", createInterpreterContext()); assertEquals(InterpreterResult.Code.SUCCESS, ret.code()); assertEquals("stream", ret.message().get(0).getData()); @@ -99,7 +94,8 @@ public class RemoteInterpreterOutputTestStream extends AbstractInterpreterTest @Test public void testOutputType() throws InterpreterException { - RemoteInterpreter intp = (RemoteInterpreter) interpreterSetting.getInterpreter("user1", "note1", "mock_stream"); + RemoteInterpreter intp = + (RemoteInterpreter) interpreterSetting.getInterpreter("user1", "note1", "mock_stream"); InterpreterResult ret = intp.interpret("SUCCESS:%html hello:", createInterpreterContext()); assertEquals(InterpreterResult.Type.HTML, ret.message().get(0).getType()); @@ -117,28 +113,27 @@ public class RemoteInterpreterOutputTestStream extends AbstractInterpreterTest } @Override - public void onOutputAppend(String noteId, String paragraphId, int index, String output) { - - } + public void onOutputAppend(String noteId, String paragraphId, int index, String output) {} @Override - public void onOutputUpdated(String noteId, String paragraphId, int index, InterpreterResult.Type type, String output) { - - } + public void onOutputUpdated( + String noteId, String paragraphId, int index, InterpreterResult.Type type, String output) {} @Override - public void onOutputClear(String noteId, String paragraphId) { - - } + public void onOutputClear(String noteId, String paragraphId) {} @Override - public void runParagraphs(String noteId, List<Integer> paragraphIndices, List<String> paragraphIds, String curParagraphId) throws IOException { - - } + public void runParagraphs( + String noteId, + List<Integer> paragraphIndices, + List<String> paragraphIds, + String curParagraphId) + throws IOException {} @Override - public void onParaInfosReceived(String noteId, String paragraphId, - String interpreterSettingId, Map<String, String> metaInfos) { - } - + public void onParaInfosReceived( + String noteId, + String paragraphId, + String interpreterSettingId, + Map<String, String> metaInfos) {} } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java index 5b059ef..3086550 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java @@ -17,6 +17,13 @@ package org.apache.zeppelin.interpreter.remote; +import static org.junit.Assert.*; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import org.apache.thrift.transport.TTransportException; import org.apache.zeppelin.display.AngularObjectRegistry; import org.apache.zeppelin.display.GUI; @@ -24,22 +31,9 @@ import org.apache.zeppelin.display.Input; import org.apache.zeppelin.display.ui.OptionInput; import org.apache.zeppelin.interpreter.*; import org.apache.zeppelin.interpreter.InterpreterResult.Code; -import org.apache.zeppelin.interpreter.remote.mock.GetAngularObjectSizeInterpreter; -import org.apache.zeppelin.interpreter.remote.mock.GetEnvPropertyInterpreter; -import org.apache.zeppelin.user.AuthenticationInfo; -import org.junit.After; import org.junit.Before; import org.junit.Test; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.*; - public class RemoteInterpreterTest extends AbstractInterpreterTest { private InterpreterSetting interpreterSetting; @@ -64,14 +58,17 @@ public class RemoteInterpreterTest extends AbstractInterpreterTest { assertEquals(remoteInterpreter1.getScheduler(), remoteInterpreter2.getScheduler()); InterpreterContext context1 = createDummyInterpreterContext(); - assertEquals("hello", remoteInterpreter1.interpret("hello", context1).message().get(0).getData()); + assertEquals( + "hello", remoteInterpreter1.interpret("hello", context1).message().get(0).getData()); assertEquals(Interpreter.FormType.NATIVE, interpreter1.getFormType()); assertEquals(0, remoteInterpreter1.getProgress(context1)); assertNotNull(remoteInterpreter1.getOrCreateInterpreterProcess()); assertTrue(remoteInterpreter1.getInterpreterGroup().getRemoteInterpreterProcess().isRunning()); - assertEquals("hello", remoteInterpreter2.interpret("hello", context1).message().get(0).getData()); - assertEquals(remoteInterpreter1.getInterpreterGroup().getRemoteInterpreterProcess(), + assertEquals( + "hello", remoteInterpreter2.interpret("hello", context1).message().get(0).getData()); + assertEquals( + remoteInterpreter1.getInterpreterGroup().getRemoteInterpreterProcess(), remoteInterpreter2.getInterpreterGroup().getRemoteInterpreterProcess()); // Call InterpreterGroup.close instead of Interpreter.close, otherwise we will have the @@ -79,14 +76,16 @@ public class RemoteInterpreterTest extends AbstractInterpreterTest { remoteInterpreter1.getInterpreterGroup().close(remoteInterpreter1.getSessionId()); assertNull(remoteInterpreter1.getInterpreterGroup().getRemoteInterpreterProcess()); try { - assertEquals("hello", remoteInterpreter1.interpret("hello", context1).message().get(0).getData()); + assertEquals( + "hello", remoteInterpreter1.interpret("hello", context1).message().get(0).getData()); fail("Should not be able to call interpret after interpreter is closed"); } catch (Exception e) { e.printStackTrace(); } try { - assertEquals("hello", remoteInterpreter2.interpret("hello", context1).message().get(0).getData()); + assertEquals( + "hello", remoteInterpreter2.interpret("hello", context1).message().get(0).getData()); fail("Should not be able to call getProgress after RemoterInterpreterProcess is stoped"); } catch (Exception e) { e.printStackTrace(); @@ -107,28 +106,33 @@ public class RemoteInterpreterTest extends AbstractInterpreterTest { assertNotEquals(interpreter1.getScheduler(), interpreter2.getScheduler()); InterpreterContext context1 = createDummyInterpreterContext(); - assertEquals("hello", remoteInterpreter1.interpret("hello", context1).message().get(0).getData()); - assertEquals("hello", remoteInterpreter2.interpret("hello", context1).message().get(0).getData()); + assertEquals( + "hello", remoteInterpreter1.interpret("hello", context1).message().get(0).getData()); + assertEquals( + "hello", remoteInterpreter2.interpret("hello", context1).message().get(0).getData()); assertEquals(Interpreter.FormType.NATIVE, interpreter1.getFormType()); assertEquals(0, remoteInterpreter1.getProgress(context1)); assertNotNull(remoteInterpreter1.getOrCreateInterpreterProcess()); assertTrue(remoteInterpreter1.getInterpreterGroup().getRemoteInterpreterProcess().isRunning()); - assertEquals(remoteInterpreter1.getInterpreterGroup().getRemoteInterpreterProcess(), + assertEquals( + remoteInterpreter1.getInterpreterGroup().getRemoteInterpreterProcess(), remoteInterpreter2.getInterpreterGroup().getRemoteInterpreterProcess()); // Call InterpreterGroup.close instead of Interpreter.close, otherwise we will have the // RemoteInterpreterProcess leakage. remoteInterpreter1.getInterpreterGroup().close(remoteInterpreter1.getSessionId()); try { - assertEquals("hello", remoteInterpreter1.interpret("hello", context1).message().get(0).getData()); + assertEquals( + "hello", remoteInterpreter1.interpret("hello", context1).message().get(0).getData()); fail("Should not be able to call interpret after interpreter is closed"); } catch (Exception e) { e.printStackTrace(); } assertTrue(remoteInterpreter2.getInterpreterGroup().getRemoteInterpreterProcess().isRunning()); - assertEquals("hello", remoteInterpreter2.interpret("hello", context1).message().get(0).getData()); + assertEquals( + "hello", remoteInterpreter2.interpret("hello", context1).message().get(0).getData()); remoteInterpreter2.getInterpreterGroup().close(remoteInterpreter2.getSessionId()); try { assertEquals("hello", remoteInterpreter2.interpret("hello", context1)); @@ -153,14 +157,17 @@ public class RemoteInterpreterTest extends AbstractInterpreterTest { assertNotEquals(interpreter1.getScheduler(), interpreter2.getScheduler()); InterpreterContext context1 = createDummyInterpreterContext(); - assertEquals("hello", remoteInterpreter1.interpret("hello", context1).message().get(0).getData()); - assertEquals("hello", remoteInterpreter2.interpret("hello", context1).message().get(0).getData()); + assertEquals( + "hello", remoteInterpreter1.interpret("hello", context1).message().get(0).getData()); + assertEquals( + "hello", remoteInterpreter2.interpret("hello", context1).message().get(0).getData()); assertEquals(Interpreter.FormType.NATIVE, interpreter1.getFormType()); assertEquals(0, remoteInterpreter1.getProgress(context1)); assertNotNull(remoteInterpreter1.getOrCreateInterpreterProcess()); assertTrue(remoteInterpreter1.getInterpreterGroup().getRemoteInterpreterProcess().isRunning()); - assertNotEquals(remoteInterpreter1.getInterpreterGroup().getRemoteInterpreterProcess(), + assertNotEquals( + remoteInterpreter1.getInterpreterGroup().getRemoteInterpreterProcess(), remoteInterpreter2.getInterpreterGroup().getRemoteInterpreterProcess()); // Call InterpreterGroup.close instead of Interpreter.close, otherwise we will have the // RemoteInterpreterProcess leakage. @@ -174,29 +181,33 @@ public class RemoteInterpreterTest extends AbstractInterpreterTest { e.printStackTrace(); } - assertEquals("hello", remoteInterpreter2.interpret("hello", context1).message().get(0).getData()); + assertEquals( + "hello", remoteInterpreter2.interpret("hello", context1).message().get(0).getData()); remoteInterpreter2.getInterpreterGroup().close(remoteInterpreter2.getSessionId()); try { - assertEquals("hello", remoteInterpreter2.interpret("hello", context1).message().get(0).getData()); + assertEquals( + "hello", remoteInterpreter2.interpret("hello", context1).message().get(0).getData()); fail("Should not be able to call interpret after interpreter is closed"); } catch (Exception e) { e.printStackTrace(); } assertNull(remoteInterpreter2.getInterpreterGroup().getRemoteInterpreterProcess()); - } @Test - public void testExecuteIncorrectPrecode() throws TTransportException, IOException, InterpreterException { + public void testExecuteIncorrectPrecode() + throws TTransportException, IOException, InterpreterException { interpreterSetting.getOption().setPerUser(InterpreterOption.SHARED); interpreterSetting.setProperty("zeppelin.SleepInterpreter.precode", "fail test"); Interpreter interpreter1 = interpreterSetting.getInterpreter("user1", "note1", "sleep"); - InterpreterContext context1 = createDummyInterpreterContext();; + InterpreterContext context1 = createDummyInterpreterContext(); + ; assertEquals(Code.ERROR, interpreter1.interpret("10", context1).code()); } @Test - public void testExecuteCorrectPrecode() throws TTransportException, IOException, InterpreterException { + public void testExecuteCorrectPrecode() + throws TTransportException, IOException, InterpreterException { interpreterSetting.getOption().setPerUser(InterpreterOption.SHARED); interpreterSetting.setProperty("zeppelin.SleepInterpreter.precode", "1"); Interpreter interpreter1 = interpreterSetting.getInterpreter("user1", "note1", "sleep"); @@ -205,7 +216,8 @@ public class RemoteInterpreterTest extends AbstractInterpreterTest { } @Test - public void testRemoteInterperterErrorStatus() throws TTransportException, IOException, InterpreterException { + public void testRemoteInterperterErrorStatus() + throws TTransportException, IOException, InterpreterException { interpreterSetting.setProperty("zeppelin.interpreter.echo.fail", "true"); interpreterSetting.getOption().setPerUser(InterpreterOption.SHARED); @@ -213,7 +225,8 @@ public class RemoteInterpreterTest extends AbstractInterpreterTest { assertTrue(interpreter1 instanceof RemoteInterpreter); RemoteInterpreter remoteInterpreter1 = (RemoteInterpreter) interpreter1; - InterpreterContext context1 = createDummyInterpreterContext();; + InterpreterContext context1 = createDummyInterpreterContext(); + ; assertEquals(Code.ERROR, remoteInterpreter1.interpret("hello", context1).code()); } @@ -227,28 +240,30 @@ public class RemoteInterpreterTest extends AbstractInterpreterTest { // run this dummy interpret method first to launch the RemoteInterpreterProcess to avoid the // time overhead of launching the process. interpreter1.interpret("1", context1); - Thread thread1 = new Thread() { - @Override - public void run() { - try { - assertEquals(Code.SUCCESS, interpreter1.interpret("100", context1).code()); - } catch (InterpreterException e) { - e.printStackTrace(); - fail(); - } - } - }; - Thread thread2 = new Thread() { - @Override - public void run() { - try { - assertEquals(Code.SUCCESS, interpreter1.interpret("100", context1).code()); - } catch (InterpreterException e) { - e.printStackTrace(); - fail(); - } - } - }; + Thread thread1 = + new Thread() { + @Override + public void run() { + try { + assertEquals(Code.SUCCESS, interpreter1.interpret("100", context1).code()); + } catch (InterpreterException e) { + e.printStackTrace(); + fail(); + } + } + }; + Thread thread2 = + new Thread() { + @Override + public void run() { + try { + assertEquals(Code.SUCCESS, interpreter1.interpret("100", context1).code()); + } catch (InterpreterException e) { + e.printStackTrace(); + fail(); + } + } + }; long start = System.currentTimeMillis(); thread1.start(); thread2.start(); @@ -269,28 +284,30 @@ public class RemoteInterpreterTest extends AbstractInterpreterTest { // run this dummy interpret method first to launch the RemoteInterpreterProcess to avoid the // time overhead of launching the process. interpreter1.interpret("1", context1); - Thread thread1 = new Thread() { - @Override - public void run() { - try { - assertEquals(Code.SUCCESS, interpreter1.interpret("100", context1).code()); - } catch (InterpreterException e) { - e.printStackTrace(); - fail(); - } - } - }; - Thread thread2 = new Thread() { - @Override - public void run() { - try { - assertEquals(Code.SUCCESS, interpreter1.interpret("100", context1).code()); - } catch (InterpreterException e) { - e.printStackTrace(); - fail(); - } - } - }; + Thread thread1 = + new Thread() { + @Override + public void run() { + try { + assertEquals(Code.SUCCESS, interpreter1.interpret("100", context1).code()); + } catch (InterpreterException e) { + e.printStackTrace(); + fail(); + } + } + }; + Thread thread2 = + new Thread() { + @Override + public void run() { + try { + assertEquals(Code.SUCCESS, interpreter1.interpret("100", context1).code()); + } catch (InterpreterException e) { + e.printStackTrace(); + fail(); + } + } + }; long start = System.currentTimeMillis(); thread1.start(); thread2.start(); @@ -314,12 +331,14 @@ public class RemoteInterpreterTest extends AbstractInterpreterTest { interpreterSetting.getOption().setPerUser(InterpreterOption.SCOPED); Interpreter interpreter1_user1 = interpreterSetting.getInterpreter("user1", "note1", "sleep"); Interpreter interpreter2_user1 = interpreterSetting.getInterpreter("user1", "note1", "echo"); - assertEquals(interpreter1_user1.getInterpreterGroup(), interpreter2_user1.getInterpreterGroup()); + assertEquals( + interpreter1_user1.getInterpreterGroup(), interpreter2_user1.getInterpreterGroup()); assertEquals(interpreter1_user1.getScheduler(), interpreter2_user1.getScheduler()); Interpreter interpreter1_user2 = interpreterSetting.getInterpreter("user2", "note1", "sleep"); Interpreter interpreter2_user2 = interpreterSetting.getInterpreter("user2", "note1", "echo"); - assertEquals(interpreter1_user2.getInterpreterGroup(), interpreter2_user2.getInterpreterGroup()); + assertEquals( + interpreter1_user2.getInterpreterGroup(), interpreter2_user2.getInterpreterGroup()); assertEquals(interpreter1_user2.getScheduler(), interpreter2_user2.getScheduler()); // scheduler is shared in session but not across session @@ -361,19 +380,29 @@ public class RemoteInterpreterTest extends AbstractInterpreterTest { final Interpreter interpreter1 = interpreterSetting.getInterpreter("user1", "note1", "get"); final InterpreterContext context1 = createDummyInterpreterContext(); - assertEquals("VALUE_1", interpreter1.interpret("getEnv ENV_1", context1).message().get(0).getData()); - assertEquals("null", interpreter1.interpret("getEnv ENV_2", context1).message().get(0).getData()); - - assertEquals("value_1", interpreter1.interpret("getProperty property_1", context1).message().get(0).getData()); - assertEquals("null", interpreter1.interpret("getProperty not_existed_property", context1).message().get(0).getData()); + assertEquals( + "VALUE_1", interpreter1.interpret("getEnv ENV_1", context1).message().get(0).getData()); + assertEquals( + "null", interpreter1.interpret("getEnv ENV_2", context1).message().get(0).getData()); + + assertEquals( + "value_1", + interpreter1.interpret("getProperty property_1", context1).message().get(0).getData()); + assertEquals( + "null", + interpreter1 + .interpret("getProperty not_existed_property", context1) + .message() + .get(0) + .getData()); } @Test public void testConvertDynamicForms() throws InterpreterException { GUI gui = new GUI(); OptionInput.ParamOption[] paramOptions = { - new OptionInput.ParamOption("value1", "param1"), - new OptionInput.ParamOption("value2", "param2") + new OptionInput.ParamOption("value1", "param1"), + new OptionInput.ParamOption("value2", "param2") }; List<Object> defaultValues = new ArrayList(); defaultValues.add("default1"); @@ -388,5 +417,4 @@ public class RemoteInterpreterTest extends AbstractInterpreterTest { interpreter.interpret("text", context); assertArrayEquals(expected.values().toArray(), gui.getForms().values().toArray()); } - } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/GetAngularObjectSizeInterpreter.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/GetAngularObjectSizeInterpreter.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/GetAngularObjectSizeInterpreter.java index 6d6495f..551e10e 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/GetAngularObjectSizeInterpreter.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/GetAngularObjectSizeInterpreter.java @@ -17,13 +17,11 @@ package org.apache.zeppelin.interpreter.remote.mock; - +import java.util.Properties; import org.apache.zeppelin.interpreter.Interpreter; import org.apache.zeppelin.interpreter.InterpreterContext; import org.apache.zeppelin.interpreter.InterpreterResult; -import java.util.Properties; - public class GetAngularObjectSizeInterpreter extends Interpreter { public GetAngularObjectSizeInterpreter(Properties property) { @@ -31,25 +29,20 @@ public class GetAngularObjectSizeInterpreter extends Interpreter { } @Override - public void open() { - - } + public void open() {} @Override - public void close() { - - } + public void close() {} @Override public InterpreterResult interpret(String st, InterpreterContext context) { - return new InterpreterResult(InterpreterResult.Code.SUCCESS, + return new InterpreterResult( + InterpreterResult.Code.SUCCESS, "" + context.getAngularObjectRegistry().getRegistry().size()); } @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/55f6c91c/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/GetEnvPropertyInterpreter.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/GetEnvPropertyInterpreter.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/GetEnvPropertyInterpreter.java index a039a59..9d1b381 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/GetEnvPropertyInterpreter.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/GetEnvPropertyInterpreter.java @@ -16,6 +16,8 @@ */ package org.apache.zeppelin.interpreter.remote.mock; +import java.util.List; +import java.util.Properties; import org.apache.zeppelin.interpreter.Interpreter; import org.apache.zeppelin.interpreter.InterpreterContext; import org.apache.zeppelin.interpreter.InterpreterResult; @@ -23,10 +25,6 @@ import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; import org.apache.zeppelin.scheduler.Scheduler; import org.apache.zeppelin.scheduler.SchedulerFactory; -import java.util.List; -import java.util.Properties; - - public class GetEnvPropertyInterpreter extends Interpreter { public GetEnvPropertyInterpreter(Properties property) { @@ -34,29 +32,29 @@ public class GetEnvPropertyInterpreter extends Interpreter { } @Override - public void open() { - } + public void open() {} @Override - public void close() { - } + public void close() {} @Override public InterpreterResult interpret(String st, InterpreterContext context) { String[] cmd = st.split(" "); if (cmd[0].equals("getEnv")) { - return new InterpreterResult(InterpreterResult.Code.SUCCESS, System.getenv(cmd[1]) == null ? "null" : System.getenv(cmd[1])); - } else if (cmd[0].equals("getProperty")){ - return new InterpreterResult(InterpreterResult.Code.SUCCESS, System.getProperty(cmd[1]) == null ? "null" : System.getProperty(cmd[1])); + return new InterpreterResult( + InterpreterResult.Code.SUCCESS, + System.getenv(cmd[1]) == null ? "null" : System.getenv(cmd[1])); + } else if (cmd[0].equals("getProperty")) { + return new InterpreterResult( + InterpreterResult.Code.SUCCESS, + System.getProperty(cmd[1]) == null ? "null" : System.getProperty(cmd[1])); } else { return new InterpreterResult(InterpreterResult.Code.ERROR, cmd[0]); } } @Override - public void cancel(InterpreterContext context) { - - } + public void cancel(InterpreterContext context) {} @Override public FormType getFormType() { @@ -69,8 +67,8 @@ public class GetEnvPropertyInterpreter extends Interpreter { } @Override - public List<InterpreterCompletion> completion(String buf, int cursor, - InterpreterContext interpreterContext) { + public List<InterpreterCompletion> completion( + String buf, int cursor, InterpreterContext interpreterContext) { return null; } @@ -79,4 +77,3 @@ public class GetEnvPropertyInterpreter extends Interpreter { return SchedulerFactory.singleton().createOrGetFIFOScheduler("interpreter_" + this.hashCode()); } } - http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterA.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterA.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterA.java index dbd2df7..a4ba9e6 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterA.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterA.java @@ -17,6 +17,8 @@ package org.apache.zeppelin.interpreter.remote.mock; +import java.util.List; +import java.util.Properties; import org.apache.zeppelin.interpreter.Interpreter; import org.apache.zeppelin.interpreter.InterpreterContext; import org.apache.zeppelin.interpreter.InterpreterException; @@ -26,9 +28,6 @@ import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; import org.apache.zeppelin.scheduler.Scheduler; import org.apache.zeppelin.scheduler.SchedulerFactory; -import java.util.List; -import java.util.Properties; - public class MockInterpreterA extends Interpreter { private String lastSt; @@ -39,12 +38,11 @@ public class MockInterpreterA extends Interpreter { @Override public void open() { - //new RuntimeException().printStackTrace(); + // new RuntimeException().printStackTrace(); } @Override - public void close() { - } + public void close() {} public String getLastStatement() { return lastSt; @@ -66,9 +64,7 @@ public class MockInterpreterA extends Interpreter { } @Override - public void cancel(InterpreterContext context) { - - } + public void cancel(InterpreterContext context) {} @Override public FormType getFormType() { @@ -81,17 +77,19 @@ public class MockInterpreterA extends Interpreter { } @Override - public List<InterpreterCompletion> completion(String buf, int cursor, - InterpreterContext interpreterContext) { + public List<InterpreterCompletion> completion( + String buf, int cursor, InterpreterContext interpreterContext) { return null; } @Override public Scheduler getScheduler() { if (getProperty("parallel") != null && getProperty("parallel").equals("true")) { - return SchedulerFactory.singleton().createOrGetParallelScheduler("interpreter_" + this.hashCode(), 10); + return SchedulerFactory.singleton() + .createOrGetParallelScheduler("interpreter_" + this.hashCode(), 10); } else { - return SchedulerFactory.singleton().createOrGetFIFOScheduler("interpreter_" + this.hashCode()); + return SchedulerFactory.singleton() + .createOrGetFIFOScheduler("interpreter_" + this.hashCode()); } } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterAngular.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterAngular.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterAngular.java index ec89241..2e253bd 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterAngular.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterAngular.java @@ -17,6 +17,9 @@ package org.apache.zeppelin.interpreter.remote.mock; +import java.util.List; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicInteger; import org.apache.zeppelin.display.AngularObjectRegistry; import org.apache.zeppelin.display.AngularObjectWatcher; import org.apache.zeppelin.interpreter.Interpreter; @@ -25,10 +28,6 @@ import org.apache.zeppelin.interpreter.InterpreterResult; import org.apache.zeppelin.interpreter.InterpreterResult.Code; import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; -import java.util.List; -import java.util.Properties; -import java.util.concurrent.atomic.AtomicInteger; - public class MockInterpreterAngular extends Interpreter { AtomicInteger numWatch = new AtomicInteger(0); @@ -38,13 +37,10 @@ public class MockInterpreterAngular extends Interpreter { } @Override - public void open() { - } + public void open() {} @Override - public void close() { - - } + public void close() {} @Override public InterpreterResult interpret(String st, InterpreterContext context) { @@ -63,16 +59,16 @@ public class MockInterpreterAngular extends Interpreter { if (cmd.equals("add")) { registry.add(name, value, context.getNoteId(), null); - registry.get(name, context.getNoteId(), null).addWatcher(new AngularObjectWatcher - (null) { - - @Override - public void watch(Object oldObject, Object newObject, - InterpreterContext context) { - numWatch.incrementAndGet(); - } - - }); + registry + .get(name, context.getNoteId(), null) + .addWatcher( + new AngularObjectWatcher(null) { + + @Override + public void watch(Object oldObject, Object newObject, InterpreterContext context) { + numWatch.incrementAndGet(); + } + }); } else if (cmd.equalsIgnoreCase("update")) { registry.get(name, context.getNoteId(), null).set(value); } else if (cmd.equals("remove")) { @@ -85,14 +81,13 @@ public class MockInterpreterAngular extends Interpreter { logger.error("Exception in MockInterpreterAngular while interpret Thread.sleep", e); } - String msg = registry.getAll(context.getNoteId(), null).size() + " " + Integer.toString(numWatch - .get()); + String msg = + registry.getAll(context.getNoteId(), null).size() + " " + Integer.toString(numWatch.get()); return new InterpreterResult(Code.SUCCESS, msg); } @Override - public void cancel(InterpreterContext context) { - } + public void cancel(InterpreterContext context) {} @Override public FormType getFormType() { @@ -105,8 +100,8 @@ public class MockInterpreterAngular extends Interpreter { } @Override - public List<InterpreterCompletion> completion(String buf, int cursor, - InterpreterContext interpreterContext) { + public List<InterpreterCompletion> completion( + String buf, int cursor, InterpreterContext interpreterContext) { return null; } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterOutputStream.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterOutputStream.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterOutputStream.java index 7a5321a..aefd9c5 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterOutputStream.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterOutputStream.java @@ -16,6 +16,9 @@ */ package org.apache.zeppelin.interpreter.remote.mock; +import java.io.IOException; +import java.util.List; +import java.util.Properties; import org.apache.zeppelin.interpreter.Interpreter; import org.apache.zeppelin.interpreter.InterpreterContext; import org.apache.zeppelin.interpreter.InterpreterException; @@ -24,13 +27,7 @@ import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; import org.apache.zeppelin.scheduler.Scheduler; import org.apache.zeppelin.scheduler.SchedulerFactory; -import java.io.IOException; -import java.util.List; -import java.util.Properties; - -/** - * MockInterpreter to test outputstream - */ +/** MockInterpreter to test outputstream */ public class MockInterpreterOutputStream extends Interpreter { private String lastSt; @@ -40,12 +37,11 @@ public class MockInterpreterOutputStream extends Interpreter { @Override public void open() { - //new RuntimeException().printStackTrace(); + // new RuntimeException().printStackTrace(); } @Override - public void close() { - } + public void close() {} public String getLastStatement() { return lastSt; @@ -62,14 +58,12 @@ public class MockInterpreterOutputStream extends Interpreter { } catch (IOException e) { throw new InterpreterException(e); } - return new InterpreterResult(InterpreterResult.Code.valueOf(ret[0]), (ret.length > 2) ? - ret[2] : ""); + return new InterpreterResult( + InterpreterResult.Code.valueOf(ret[0]), (ret.length > 2) ? ret[2] : ""); } @Override - public void cancel(InterpreterContext context) { - - } + public void cancel(InterpreterContext context) {} @Override public FormType getFormType() { @@ -82,8 +76,8 @@ public class MockInterpreterOutputStream extends Interpreter { } @Override - public List<InterpreterCompletion> completion(String buf, int cursor, - InterpreterContext interpreterContext) { + public List<InterpreterCompletion> completion( + String buf, int cursor, InterpreterContext interpreterContext) { return null; } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterResourcePool.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterResourcePool.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterResourcePool.java index ee9f15c..b5604eb 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterResourcePool.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterResourcePool.java @@ -18,6 +18,9 @@ package org.apache.zeppelin.interpreter.remote.mock; import com.google.gson.Gson; +import java.util.List; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicInteger; import org.apache.zeppelin.interpreter.Interpreter; import org.apache.zeppelin.interpreter.InterpreterContext; import org.apache.zeppelin.interpreter.InterpreterResult; @@ -26,10 +29,6 @@ import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; import org.apache.zeppelin.resource.Resource; import org.apache.zeppelin.resource.ResourcePool; -import java.util.List; -import java.util.Properties; -import java.util.concurrent.atomic.AtomicInteger; - public class MockInterpreterResourcePool extends Interpreter { AtomicInteger numWatch = new AtomicInteger(0); @@ -39,13 +38,10 @@ public class MockInterpreterResourcePool extends Interpreter { } @Override - public void open() { - } + public void open() {} @Override - public void close() { - - } + public void close() {} @Override public InterpreterResult interpret(String st, InterpreterContext context) { @@ -86,7 +82,7 @@ public class MockInterpreterResourcePool extends Interpreter { ret = resourcePool.getAll(); } else if (cmd.equals("invoke")) { Resource resource = resourcePool.get(noteId, paragraphId, name); - if (stmt.length >=4) { + if (stmt.length >= 4) { Resource res = resource.invokeMethod(value, null, null, stmt[3]); ret = res.get(); } else { @@ -104,8 +100,7 @@ public class MockInterpreterResourcePool extends Interpreter { } @Override - public void cancel(InterpreterContext context) { - } + public void cancel(InterpreterContext context) {} @Override public FormType getFormType() { @@ -118,8 +113,8 @@ public class MockInterpreterResourcePool extends Interpreter { } @Override - public List<InterpreterCompletion> completion(String buf, int cursor, - InterpreterContext interpreterContext) { + public List<InterpreterCompletion> completion( + String buf, int cursor, InterpreterContext interpreterContext) { return null; } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/FolderTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/FolderTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/FolderTest.java index d756e14..29b46eb 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/FolderTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/FolderTest.java @@ -17,6 +17,10 @@ package org.apache.zeppelin.notebook; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import org.apache.zeppelin.interpreter.Interpreter; import org.apache.zeppelin.interpreter.InterpreterFactory; import org.apache.zeppelin.interpreter.InterpreterSettingManager; @@ -30,38 +34,25 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - @RunWith(MockitoJUnitRunner.class) public class FolderTest { - @Mock - NotebookRepo repo; + @Mock NotebookRepo repo; - @Mock - ParagraphJobListener paragraphJobListener; + @Mock ParagraphJobListener paragraphJobListener; - @Mock - SearchService index; + @Mock SearchService index; - @Mock - Credentials credentials; + @Mock Credentials credentials; - @Mock - Interpreter interpreter; + @Mock Interpreter interpreter; - @Mock - Scheduler scheduler; + @Mock Scheduler scheduler; - @Mock - NoteEventListener noteEventListener; + @Mock NoteEventListener noteEventListener; - @Mock - InterpreterFactory interpreterFactory; + @Mock InterpreterFactory interpreterFactory; - @Mock - InterpreterSettingManager interpreterSettingManager; + @Mock InterpreterSettingManager interpreterSettingManager; Folder folder; @@ -71,13 +62,43 @@ public class FolderTest { @Before public void createFolderAndNotes() { - note1 = new Note("test", "", repo, interpreterFactory, interpreterSettingManager, paragraphJobListener, index, credentials, noteEventListener); + note1 = + new Note( + "test", + "", + repo, + interpreterFactory, + interpreterSettingManager, + paragraphJobListener, + index, + credentials, + noteEventListener); note1.setName("this/is/a/folder/note1"); - note2 = new Note("test", "", repo, interpreterFactory, interpreterSettingManager, paragraphJobListener, index, credentials, noteEventListener); + note2 = + new Note( + "test", + "", + repo, + interpreterFactory, + interpreterSettingManager, + paragraphJobListener, + index, + credentials, + noteEventListener); note2.setName("this/is/a/folder/note2"); - note3 = new Note("test", "", repo, interpreterFactory, interpreterSettingManager, paragraphJobListener, index, credentials, noteEventListener); + note3 = + new Note( + "test", + "", + repo, + interpreterFactory, + interpreterSettingManager, + paragraphJobListener, + index, + credentials, + noteEventListener); note3.setName("this/is/a/folder/note3"); folder = new Folder("this/is/a/folder"); @@ -118,7 +139,17 @@ public class FolderTest { @Test public void addNoteTest() { - Note note4 = new Note("test", "", repo, interpreterFactory, interpreterSettingManager, paragraphJobListener, index, credentials, noteEventListener); + Note note4 = + new Note( + "test", + "", + repo, + interpreterFactory, + interpreterSettingManager, + paragraphJobListener, + index, + credentials, + noteEventListener); note4.setName("this/is/a/folder/note4"); folder.addNote(note4);
