You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by jo...@apache.org on 2018/09/14 02:20:40 UTC

zeppelin git commit: [ZEPPELIN-3733] Refactor `Notebook*` classes to remove circular dependencies and several listeners

Repository: zeppelin
Updated Branches:
  refs/heads/master a4ff3ab50 -> d37cc1b61


[ZEPPELIN-3733] Refactor `Notebook*` classes to remove circular dependencies and several listeners

### What is this PR for?
Decoupling `Notebook*` classes as they depend each others. it makes circular dependencies, and it bothers that contributors understand code.

### What type of PR is it?
[Refactoring]

### Todos
* [ ] - Task

### What is the Jira issue?
* https://issues.apache.org/jira/browse/ZEPPELIN-3733

### How should this be tested?
CI passes

### Screenshots (if appropriate)

### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No

Author: Jongyoul Lee <jo...@gmail.com>

Closes #3159 from jongyoul/ZEPPELIN-3733 and squashes the following commits:

69c72e548 [Jongyoul Lee] Fix a flaky test
4a846ae51 [Jongyoul Lee] Refactor NotebookServiceTest
8501fe881 [Jongyoul Lee] Fix tests
64f453421 [Jongyoul Lee] Revert "Disable flaky tests which should be enabled again"
3e2360d51 [Jongyoul Lee] Revert "Disable flaky tests which should be enabled again"
e778828e2 [Jongyoul Lee] Disable flaky tests which should be enabled again
48bff85c5 [Jongyoul Lee] Disable flaky tests which should be enabled again
4c2f715cb [Jongyoul Lee] Fix style
56c0c40a1 [Jongyoul Lee] Fix `NotebookServerTest` not to use `AbstractTestRestApi`
4271d9841 [Jongyoul Lee] Add trick to fix tests (+9 squashed commits) Squashed commits: [807e286] Fix tests [3b6ad26] Fix style Remove unused code [2dc0946] Fix style [7e96118] Remove unused code [472696d] Remove unused code [0ff6bdb] Change `ParagraphJobListener` from a parameter of constructor to setter Add code to enable `NotebookService` to set `ParagraphJobListener` into `Notebook` Add code to inject `NotebookServer` to `NotebookService` Add conservative logic to prepare the case where `ParagraphJobListener` is null [e97e165] Fix `NotebookServerTest` [1eccc3c] Change scopes for some bound classes [4c662c9] Add more injection code in NotebookRestApi Bind `NotebookAuthorization` and `NotebookService` Provide `getInstance()` of `ConfigurationService` and `NotebookService` to let `NotebookServer` call them


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/d37cc1b6
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/d37cc1b6
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/d37cc1b6

Branch: refs/heads/master
Commit: d37cc1b611dc761b1ec69c29d6b8ceaa84f301f4
Parents: a4ff3ab
Author: Jongyoul Lee <jo...@gmail.com>
Authored: Thu Sep 13 01:06:28 2018 +0900
Committer: Jongyoul Lee <jo...@apache.org>
Committed: Fri Sep 14 11:20:32 2018 +0900

----------------------------------------------------------------------
 .../notebook/repo/NotebookRepoSyncTest.java     |  96 ++++++-------
 .../apache/zeppelin/rest/NotebookRestApi.java   |  14 +-
 .../apache/zeppelin/server/ZeppelinServer.java  |  30 +++--
 .../zeppelin/service/ConfigurationService.java  |  17 +++
 .../zeppelin/service/NotebookService.java       |  70 ++++++++--
 .../apache/zeppelin/socket/NotebookServer.java  |  26 +++-
 .../apache/zeppelin/recovery/RecoveryTest.java  |   3 +
 .../zeppelin/rest/NotebookRestApiTest.java      |   1 +
 .../zeppelin/security/SecurityUtilsTest.java    |   3 +-
 .../zeppelin/service/NotebookServiceTest.java   | 133 +++++++++++++++----
 .../zeppelin/socket/NotebookServerTest.java     |  56 ++++----
 .../org/apache/zeppelin/notebook/Notebook.java  |  30 +++--
 .../org/apache/zeppelin/notebook/Paragraph.java |  63 +++++----
 .../helium/HeliumApplicationFactoryTest.java    |  67 +++-------
 .../apache/zeppelin/notebook/NotebookTest.java  |  62 ++++++---
 15 files changed, 420 insertions(+), 251 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d37cc1b6/zeppelin-plugins/notebookrepo/git/src/test/java/org/apache/zeppelin/notebook/repo/NotebookRepoSyncTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-plugins/notebookrepo/git/src/test/java/org/apache/zeppelin/notebook/repo/NotebookRepoSyncTest.java b/zeppelin-plugins/notebookrepo/git/src/test/java/org/apache/zeppelin/notebook/repo/NotebookRepoSyncTest.java
index 68e2615..ec1a2d4 100644
--- a/zeppelin-plugins/notebookrepo/git/src/test/java/org/apache/zeppelin/notebook/repo/NotebookRepoSyncTest.java
+++ b/zeppelin-plugins/notebookrepo/git/src/test/java/org/apache/zeppelin/notebook/repo/NotebookRepoSyncTest.java
@@ -17,6 +17,16 @@
 
 package org.apache.zeppelin.notebook.repo;
 
+import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
 import org.apache.commons.io.FileUtils;
 import org.apache.zeppelin.conf.ZeppelinConfiguration;
 import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars;
@@ -24,17 +34,12 @@ import org.apache.zeppelin.dep.DependencyResolver;
 import org.apache.zeppelin.display.AngularObjectRegistryListener;
 import org.apache.zeppelin.helium.ApplicationEventListener;
 import org.apache.zeppelin.interpreter.InterpreterFactory;
-import org.apache.zeppelin.interpreter.InterpreterResultMessage;
 import org.apache.zeppelin.interpreter.InterpreterSettingManager;
 import org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcessListener;
 import org.apache.zeppelin.notebook.Note;
 import org.apache.zeppelin.notebook.Notebook;
 import org.apache.zeppelin.notebook.NotebookAuthorization;
 import org.apache.zeppelin.notebook.Paragraph;
-import org.apache.zeppelin.notebook.ParagraphJobListener;
-import org.apache.zeppelin.scheduler.Job;
-import org.apache.zeppelin.scheduler.Job.Status;
-import org.apache.zeppelin.scheduler.SchedulerFactory;
 import org.apache.zeppelin.search.SearchService;
 import org.apache.zeppelin.storage.ConfigStorage;
 import org.apache.zeppelin.user.AuthenticationInfo;
@@ -46,25 +51,11 @@ import org.quartz.SchedulerException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.File;
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-
-//TODO(zjffdu) move it to zeppelin-zengine
-public class NotebookRepoSyncTest implements ParagraphJobListener {
+// TODO(zjffdu) move it to zeppelin-zengine
+public class NotebookRepoSyncTest {
 
   private File mainZepDir;
   private ZeppelinConfiguration conf;
-  private SchedulerFactory schedulerFactory;
   private File mainNotebookDir;
   private File secNotebookDir;
   private Notebook notebookSync;
@@ -104,8 +95,6 @@ public class NotebookRepoSyncTest implements ParagraphJobListener {
 
     ConfigStorage.reset();
 
-    this.schedulerFactory = SchedulerFactory.singleton();
-
     depResolver = new DependencyResolver(mainZepDir.getAbsolutePath() + "/local-repo");
     interpreterSettingManager = new InterpreterSettingManager(conf,
         mock(AngularObjectRegistryListener.class), mock(RemoteInterpreterProcessListener.class), mock(ApplicationEventListener.class));
@@ -115,8 +104,15 @@ public class NotebookRepoSyncTest implements ParagraphJobListener {
     notebookRepoSync = new NotebookRepoSync(conf);
     notebookAuthorization = NotebookAuthorization.init(conf);
     credentials = new Credentials(conf.credentialsPersist(), conf.getCredentialsPath(), null);
-    notebookSync = new Notebook(conf, notebookRepoSync, schedulerFactory, factory, interpreterSettingManager, this, search,
-            notebookAuthorization, credentials);
+    notebookSync =
+        new Notebook(
+            conf,
+            notebookRepoSync,
+            factory,
+            interpreterSettingManager,
+            search,
+            notebookAuthorization,
+            credentials);
     anonymous = new AuthenticationInfo("anonymous");
   }
 
@@ -244,8 +240,15 @@ public class NotebookRepoSyncTest implements ParagraphJobListener {
     System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_ONE_WAY_SYNC.getVarName(), "true");
     conf = ZeppelinConfiguration.create();
     notebookRepoSync = new NotebookRepoSync(conf);
-    notebookSync = new Notebook(conf, notebookRepoSync, schedulerFactory, factory, interpreterSettingManager, this, search,
-            notebookAuthorization, credentials);
+    notebookSync =
+        new Notebook(
+            conf,
+            notebookRepoSync,
+            factory,
+            interpreterSettingManager,
+            search,
+            notebookAuthorization,
+            credentials);
 
     // check that both storage repos are empty
     assertTrue(notebookRepoSync.getRepoCount() > 1);
@@ -292,8 +295,15 @@ public class NotebookRepoSyncTest implements ParagraphJobListener {
     ZeppelinConfiguration vConf = ZeppelinConfiguration.create();
 
     NotebookRepoSync vRepoSync = new NotebookRepoSync(vConf);
-    Notebook vNotebookSync = new Notebook(vConf, vRepoSync, schedulerFactory, factory, interpreterSettingManager, this, search,
-            notebookAuthorization, credentials);
+    Notebook vNotebookSync =
+        new Notebook(
+            vConf,
+            vRepoSync,
+            factory,
+            interpreterSettingManager,
+            search,
+            notebookAuthorization,
+            credentials);
 
     // one git versioned storage initialized
     assertThat(vRepoSync.getRepoCount()).isEqualTo(1);
@@ -409,32 +419,4 @@ public class NotebookRepoSyncTest implements ParagraphJobListener {
         file.delete();
       }
   }
-
-
-
-  @Override
-  public void onOutputAppend(Paragraph paragraph, int idx, String output) {
-
-  }
-
-  @Override
-  public void onOutputUpdate(Paragraph paragraph, int idx, InterpreterResultMessage msg) {
-
-  }
-
-  @Override
-  public void onOutputUpdateAll(Paragraph paragraph, List<InterpreterResultMessage> msgs) {
-
-  }
-
-  @Override
-  public void onProgressUpdate(Paragraph paragraph, int progress) {
-  }
-
-  @Override
-  public void onStatusChange(Paragraph paragraph, Status before, Status after) {
-
-  }
-
-
 }

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d37cc1b6/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java
index 3258ec0..cc35293 100644
--- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java
+++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java
@@ -87,14 +87,20 @@ public class NotebookRestApi extends AbstractRestApi {
   private JobManagerService jobManagerService;
 
   @Inject
-  public NotebookRestApi(Notebook notebook, NotebookServer notebookServer, SearchService search) {
+  public NotebookRestApi(
+      Notebook notebook,
+      NotebookServer notebookServer,
+      NotebookService notebookService,
+      SearchService search,
+      NotebookAuthorization notebookAuthorization,
+      ZeppelinConfiguration zConf) {
     this.notebook = notebook;
     this.notebookServer = notebookServer;
-    this.notebookService = new NotebookService(notebook);
+    this.notebookService = notebookService;
     this.jobManagerService = new JobManagerService(notebook);
     this.noteSearchService = search;
-    this.notebookAuthorization = notebook.getNotebookAuthorization();
-    this.zConf = notebook.getConf();
+    this.notebookAuthorization = notebookAuthorization;
+    this.zConf = zConf;
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d37cc1b6/zeppelin-server/src/main/java/org/apache/zeppelin/server/ZeppelinServer.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/server/ZeppelinServer.java b/zeppelin-server/src/main/java/org/apache/zeppelin/server/ZeppelinServer.java
index 67629e1..b0ece52 100644
--- a/zeppelin-server/src/main/java/org/apache/zeppelin/server/ZeppelinServer.java
+++ b/zeppelin-server/src/main/java/org/apache/zeppelin/server/ZeppelinServer.java
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.lang.management.ManagementFactory;
 import java.util.Collection;
 import java.util.EnumSet;
+import javax.inject.Inject;
 import javax.inject.Singleton;
 import javax.management.InstanceAlreadyExistsException;
 import javax.management.MBeanRegistrationException;
@@ -29,6 +30,7 @@ import javax.management.MalformedObjectNameException;
 import javax.management.NotCompliantMBeanException;
 import javax.management.ObjectName;
 import javax.servlet.DispatcherType;
+import javax.ws.rs.ApplicationPath;
 import org.apache.commons.lang.StringUtils;
 import org.apache.shiro.UnavailableSecurityManagerException;
 import org.apache.shiro.realm.Realm;
@@ -48,14 +50,13 @@ import org.apache.zeppelin.notebook.Notebook;
 import org.apache.zeppelin.notebook.NotebookAuthorization;
 import org.apache.zeppelin.notebook.repo.NotebookRepoSync;
 import org.apache.zeppelin.rest.exception.WebApplicationExceptionMapper;
-import org.apache.zeppelin.scheduler.SchedulerFactory;
 import org.apache.zeppelin.search.LuceneSearch;
 import org.apache.zeppelin.search.SearchService;
 import org.apache.zeppelin.service.AdminService;
 import org.apache.zeppelin.service.ConfigurationService;
 import org.apache.zeppelin.service.InterpreterService;
+import org.apache.zeppelin.service.NotebookService;
 import org.apache.zeppelin.socket.NotebookServer;
-import org.apache.zeppelin.storage.ConfigStorage;
 import org.apache.zeppelin.user.Credentials;
 import org.apache.zeppelin.utils.SecurityUtils;
 import org.eclipse.jetty.http.HttpVersion;
@@ -73,12 +74,16 @@ import org.eclipse.jetty.servlet.ServletContextHandler;
 import org.eclipse.jetty.servlet.ServletHolder;
 import org.eclipse.jetty.util.ssl.SslContextFactory;
 import org.eclipse.jetty.webapp.WebAppContext;
+import org.glassfish.hk2.api.Immediate;
+import org.glassfish.hk2.api.ServiceLocator;
+import org.glassfish.hk2.utilities.ServiceLocatorUtilities;
 import org.glassfish.jersey.internal.inject.AbstractBinder;
 import org.glassfish.jersey.server.ResourceConfig;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /** Main class of Zeppelin. */
+@ApplicationPath("/api")
 public class ZeppelinServer extends ResourceConfig {
   private static final Logger LOG = LoggerFactory.getLogger(ZeppelinServer.class);
 
@@ -88,16 +93,14 @@ public class ZeppelinServer extends ResourceConfig {
   public static Helium helium;
 
   private final InterpreterSettingManager interpreterSettingManager;
-  private SchedulerFactory schedulerFactory;
   private InterpreterFactory replFactory;
-  private ConfigStorage configStorage;
   private SearchService noteSearchService;
   private NotebookRepoSync notebookRepo;
   private NotebookAuthorization notebookAuthorization;
   private Credentials credentials;
-  private InterpreterService interpreterService;
 
-  public ZeppelinServer() throws Exception {
+  @Inject
+  public ZeppelinServer(ServiceLocator serviceLocator) throws Exception {
     ZeppelinConfiguration conf = ZeppelinConfiguration.create();
     if (conf.getShiroPath().length() > 0) {
       try {
@@ -153,7 +156,6 @@ public class ZeppelinServer extends ResourceConfig {
               new File(conf.getRelativeDir("zeppelin-web/src/app/spell")));
     }
 
-    this.schedulerFactory = SchedulerFactory.singleton();
     this.interpreterSettingManager =
         new InterpreterSettingManager(conf, notebookWsServer, notebookWsServer, notebookWsServer);
     this.replFactory = new InterpreterFactory(interpreterSettingManager);
@@ -167,14 +169,11 @@ public class ZeppelinServer extends ResourceConfig {
         new Notebook(
             conf,
             notebookRepo,
-            schedulerFactory,
             replFactory,
             interpreterSettingManager,
-            notebookWsServer,
             noteSearchService,
             notebookAuthorization,
             credentials);
-    this.configStorage = ConfigStorage.getInstance(conf);
 
     ZeppelinServer.helium =
         new Helium(
@@ -199,7 +198,6 @@ public class ZeppelinServer extends ResourceConfig {
 
     notebook.addNotebookEventListener(heliumApplicationFactory);
     notebook.addNotebookEventListener(notebookWsServer.getNotebookInformationListener());
-    this.interpreterService = new InterpreterService(conf, interpreterSettingManager);
 
     // Register MBean
     if ("true".equals(System.getenv("ZEPPELIN_JMX_ENABLE"))) {
@@ -220,6 +218,8 @@ public class ZeppelinServer extends ResourceConfig {
       }
     }
 
+    ServiceLocatorUtilities.enableImmediateScope(serviceLocator);
+
     register(
         new AbstractBinder() {
           @Override
@@ -231,14 +231,16 @@ public class ZeppelinServer extends ResourceConfig {
             bind(helium).to(Helium.class).in(Singleton.class);
             bind(conf).to(ZeppelinConfiguration.class).in(Singleton.class);
             bind(interpreterSettingManager).to(InterpreterSettingManager.class).in(Singleton.class);
-            bind(InterpreterService.class).to(InterpreterService.class).in(Singleton.class);
+            bind(InterpreterService.class).to(InterpreterService.class).in(Immediate.class);
             bind(credentials).to(Credentials.class).in(Singleton.class);
             bind(GsonProvider.class).to(GsonProvider.class).in(Singleton.class);
             bind(WebApplicationExceptionMapper.class)
                 .to(WebApplicationExceptionMapper.class)
                 .in(Singleton.class);
-            bind(AdminService.class).to(AdminService.class).in(Singleton.class);
-            bind(ConfigurationService.class).to(ConfigurationService.class).in(Singleton.class);
+            bind(AdminService.class).to(AdminService.class).in(Immediate.class);
+            bind(notebookAuthorization).to(NotebookAuthorization.class).in(Singleton.class);
+            bind(ConfigurationService.class).to(ConfigurationService.class).in(Immediate.class);
+            bind(NotebookService.class).to(NotebookService.class).in(Immediate.class);
           }
         });
     packages("org.apache.zeppelin.rest");

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d37cc1b6/zeppelin-server/src/main/java/org/apache/zeppelin/service/ConfigurationService.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/service/ConfigurationService.java b/zeppelin-server/src/main/java/org/apache/zeppelin/service/ConfigurationService.java
index 280449b..593c17a 100644
--- a/zeppelin-server/src/main/java/org/apache/zeppelin/service/ConfigurationService.java
+++ b/zeppelin-server/src/main/java/org/apache/zeppelin/service/ConfigurationService.java
@@ -29,12 +29,29 @@ import java.util.Map;
 public class ConfigurationService {
 
   private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationService.class);
+  private static ConfigurationService self;
 
   private ZeppelinConfiguration zConf;
 
   @Inject
   public ConfigurationService(ZeppelinConfiguration zConf) {
     this.zConf = zConf;
+    ConfigurationService.self = this;
+  }
+
+  /**
+   * This is a temporal trick to connect injected class to non-injected class like {@link
+   * org.apache.zeppelin.socket.NotebookServer}. This will be removed after refactoring of Notebook*
+   * classes.
+   *
+   * @return ConfigurationService
+   */
+  public static ConfigurationService getInstance() {
+    if (null == ConfigurationService.self) {
+      throw new IllegalStateException("ConfigurationService should be called after injection");
+    } else {
+      return ConfigurationService.self;
+    }
   }
 
   public Map<String, String> getAllProperties(ServiceContext context,

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d37cc1b6/zeppelin-server/src/main/java/org/apache/zeppelin/service/NotebookService.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/service/NotebookService.java b/zeppelin-server/src/main/java/org/apache/zeppelin/service/NotebookService.java
index dfdcc4d..d050ab6 100644
--- a/zeppelin-server/src/main/java/org/apache/zeppelin/service/NotebookService.java
+++ b/zeppelin-server/src/main/java/org/apache/zeppelin/service/NotebookService.java
@@ -17,6 +17,16 @@
 
 package org.apache.zeppelin.service;
 
+import static org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_HOMESCREEN;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+import javax.inject.Inject;
 import org.apache.commons.lang.StringUtils;
 import org.apache.zeppelin.conf.ZeppelinConfiguration;
 import org.apache.zeppelin.interpreter.Interpreter;
@@ -35,18 +45,10 @@ import org.apache.zeppelin.rest.exception.ForbiddenException;
 import org.apache.zeppelin.rest.exception.NoteNotFoundException;
 import org.apache.zeppelin.rest.exception.ParagraphNotFoundException;
 import org.apache.zeppelin.scheduler.Job;
+import org.apache.zeppelin.socket.NotebookServer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import static org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_HOMESCREEN;
-
 /**
  * Service class for Notebook related operations.
  */
@@ -54,14 +56,64 @@ public class NotebookService {
 
   private static final Logger LOGGER = LoggerFactory.getLogger(NotebookService.class);
 
+  private static NotebookService self;
+
   private ZeppelinConfiguration zConf;
   private Notebook notebook;
   private NotebookAuthorization notebookAuthorization;
+  private NotebookServer notebookServer;
+  private CountDownLatch notebookServerInjected;
 
+  @Inject
   public NotebookService(Notebook notebook) {
     this.notebook = notebook;
     this.notebookAuthorization = notebook.getNotebookAuthorization();
     this.zConf = notebook.getConf();
+    NotebookService.self = this;
+    notebookServerInjected = new CountDownLatch(1);
+  }
+
+  /**
+   * This is a temporal trick to connect injected class to non-injected class like {@link
+   * org.apache.zeppelin.socket.NotebookServer}. This will be removed after refactoring of
+   * Notebook\* classes.
+   *
+   * @return NotebookService
+   */
+  public static NotebookService getInstance() {
+    if (null == NotebookService.self) {
+      throw new IllegalStateException("NotebookService should be called after injection");
+    } else {
+      return NotebookService.self;
+    }
+  }
+
+  /**
+   * Only NotebookServer will call this method to register itself. This will be
+   * changed @PostConstruct. Please see {@link NotebookServer#NotebookServer()}
+   *
+   * @param notebookServer NotebookServer instance to be injected
+   */
+  public void injectNotebookServer(NotebookServer notebookServer) {
+    this.notebookServer = notebookServer;
+    // Notebook was initialized by injection, thus it should be not null
+    notebook.setParagraphJobListener(notebookServer);
+    notebookServerInjected.countDown();
+  }
+
+  /**
+   * This is a conservative to avoid timing issue between registering it and using it.
+   *
+   * @return NotebookServer instance
+   */
+  public NotebookServer getNotebookServer() {
+    try {
+      notebookServerInjected.await();
+      return notebookServer;
+    } catch (InterruptedException e) {
+      LOGGER.info("Interrupted. getNotebookServer will return null");
+      return null;
+    }
   }
 
   public Note getHomeNote(ServiceContext context,

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d37cc1b6/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java
index 6f59dd5..64e70e9 100644
--- a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java
+++ b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java
@@ -143,6 +143,28 @@ public class NotebookServer extends WebSocketServlet
 
   public NotebookServer() {
     this.connectionManager = new ConnectionManager();
+    // TODO(jl): Replace this code with @PostConstruct after finishing injection
+    new Thread(
+        () -> {
+          Logger innerLogger = LoggerFactory.getLogger("NotebookServerRegister");
+          innerLogger.info("Started registration thread");
+          try {
+            NotebookService notebookService = null;
+            while (null == notebookService) {
+              try {
+                notebookService = getNotebookService();
+              } catch (IllegalStateException ignored) {
+                // ignored
+              }
+              Thread.sleep(100);
+            }
+            getNotebookService().injectNotebookServer(this);
+            innerLogger.info("Completed registration thread");
+          } catch (InterruptedException e) {
+            innerLogger.info("Interrupted. will stop registration process");
+          }
+        }, "NotebookServerRegister")
+      .start();
   }
 
   private Notebook notebook() {
@@ -151,14 +173,14 @@ public class NotebookServer extends WebSocketServlet
 
   public synchronized NotebookService getNotebookService() {
     if (this.notebookService == null) {
-      this.notebookService = new NotebookService(notebook());
+      this.notebookService = NotebookService.getInstance();
     }
     return this.notebookService;
   }
 
   public synchronized ConfigurationService getConfigurationService() {
     if (this.configurationService == null) {
-      this.configurationService = new ConfigurationService(notebook().getConf());
+      this.configurationService = ConfigurationService.getInstance();
     }
     return this.configurationService;
   }

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d37cc1b6/zeppelin-server/src/test/java/org/apache/zeppelin/recovery/RecoveryTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/recovery/RecoveryTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/recovery/RecoveryTest.java
index 7a58a41..fcf678a 100644
--- a/zeppelin-server/src/test/java/org/apache/zeppelin/recovery/RecoveryTest.java
+++ b/zeppelin-server/src/test/java/org/apache/zeppelin/recovery/RecoveryTest.java
@@ -55,6 +55,7 @@ public class RecoveryTest extends AbstractTestRestApi {
     System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_RECOVERY_DIR.getVarName(),
             recoveryDir.getAbsolutePath());
     startUp(RecoveryTest.class.getSimpleName());
+    ZeppelinServer.notebook.setParagraphJobListener(ZeppelinServer.notebookWsServer);
   }
 
   @AfterClass
@@ -107,6 +108,7 @@ public class RecoveryTest extends AbstractTestRestApi {
     assertEquals(resp.get("status"), "OK");
     post.releaseConnection();
     assertEquals(Job.Status.FINISHED, p1.getStatus());
+    note1.persist(AuthenticationInfo.ANONYMOUS);
 
     // restart the python interpreter
     ZeppelinServer.notebook.getInterpreterSettingManager().restart(
@@ -143,6 +145,7 @@ public class RecoveryTest extends AbstractTestRestApi {
     assertEquals(resp.get("status"), "OK");
     post.releaseConnection();
     assertEquals(Job.Status.FINISHED, p1.getStatus());
+    note1.persist(AuthenticationInfo.ANONYMOUS);
 
     // shutdown zeppelin and restart it
     shutDown();

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d37cc1b6/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java
index 9d96ee5..b8eccfe 100644
--- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java
+++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java
@@ -57,6 +57,7 @@ public class NotebookRestApiTest extends AbstractTestRestApi {
   @BeforeClass
   public static void init() throws Exception {
     startUp(NotebookRestApiTest.class.getSimpleName());
+    ZeppelinServer.notebook.setParagraphJobListener(ZeppelinServer.notebookWsServer);
   }
 
   @AfterClass

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d37cc1b6/zeppelin-server/src/test/java/org/apache/zeppelin/security/SecurityUtilsTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/security/SecurityUtilsTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/security/SecurityUtilsTest.java
index 0c535b9..b66792d 100644
--- a/zeppelin-server/src/test/java/org/apache/zeppelin/security/SecurityUtilsTest.java
+++ b/zeppelin-server/src/test/java/org/apache/zeppelin/security/SecurityUtilsTest.java
@@ -127,7 +127,8 @@ public class SecurityUtilsTest {
         .getVarName(), String.valueOf(true));
     setupPrincipalName(expectedName);
     assertEquals(expectedName.toLowerCase(), SecurityUtils.getPrincipal());
-
+    System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_USERNAME_FORCE_LOWERCASE
+        .getVarName(), String.valueOf(false));
   }
 
   private void setupPrincipalName(String expectedName) {

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d37cc1b6/zeppelin-server/src/test/java/org/apache/zeppelin/service/NotebookServiceTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/service/NotebookServiceTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/service/NotebookServiceTest.java
index ad13dae..2ded397 100644
--- a/zeppelin-server/src/test/java/org/apache/zeppelin/service/NotebookServiceTest.java
+++ b/zeppelin-server/src/test/java/org/apache/zeppelin/service/NotebookServiceTest.java
@@ -17,32 +17,50 @@
 
 package org.apache.zeppelin.service;
 
-import org.apache.zeppelin.conf.ZeppelinConfiguration;
-import org.apache.zeppelin.notebook.Note;
-import org.apache.zeppelin.notebook.Paragraph;
-import org.apache.zeppelin.rest.AbstractTestRestApi;
-import org.apache.zeppelin.server.ZeppelinServer;
-import org.apache.zeppelin.user.AuthenticationInfo;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doCallRealMethod;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.reset;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.collect.Maps;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.zeppelin.conf.ZeppelinConfiguration;
+import org.apache.zeppelin.interpreter.Interpreter;
+import org.apache.zeppelin.interpreter.Interpreter.FormType;
+import org.apache.zeppelin.interpreter.InterpreterFactory;
+import org.apache.zeppelin.interpreter.InterpreterResult;
+import org.apache.zeppelin.interpreter.InterpreterResult.Code;
+import org.apache.zeppelin.interpreter.InterpreterSetting;
+import org.apache.zeppelin.interpreter.InterpreterSettingManager;
+import org.apache.zeppelin.interpreter.ManagedInterpreterGroup;
+import org.apache.zeppelin.notebook.Note;
+import org.apache.zeppelin.notebook.NoteInfo;
+import org.apache.zeppelin.notebook.Notebook;
+import org.apache.zeppelin.notebook.NotebookAuthorization;
+import org.apache.zeppelin.notebook.Paragraph;
+import org.apache.zeppelin.notebook.repo.NotebookRepo;
+import org.apache.zeppelin.notebook.repo.NotebookRepoSettingsInfo;
+import org.apache.zeppelin.search.LuceneSearch;
+import org.apache.zeppelin.search.SearchService;
+import org.apache.zeppelin.user.AuthenticationInfo;
+import org.apache.zeppelin.user.Credentials;
+import org.junit.Before;
+import org.junit.Test;
 
-public class NotebookServiceTest extends AbstractTestRestApi {
+public class NotebookServiceTest {
 
   private static NotebookService notebookService;
 
@@ -51,17 +69,78 @@ public class NotebookServiceTest extends AbstractTestRestApi {
 
   private ServiceCallback callback = mock(ServiceCallback.class);
 
-  @BeforeClass
-  public static void setUp() throws Exception {
-    System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_HELIUM_REGISTRY.getVarName(),
-        "helium");
-    AbstractTestRestApi.startUp(NotebookServiceTest.class.getSimpleName());
-    notebookService = ZeppelinServer.notebookWsServer.getNotebookService();
-  }
+  @Before
+  public void setUp() throws Exception {
+    ZeppelinConfiguration zeppelinConfiguration = ZeppelinConfiguration.create();
+    NotebookRepo notebookRepo =
+        new NotebookRepo() {
+          Map<String, Note> notes = Maps.newHashMap();
+
+          @Override
+          public void init(ZeppelinConfiguration zConf) throws IOException {}
+
+          @Override
+          public List<NoteInfo> list(AuthenticationInfo subject) throws IOException {
+            return notes.values().stream().map(NoteInfo::new).collect(Collectors.toList());
+          }
+
+          @Override
+          public Note get(String noteId, AuthenticationInfo subject) throws IOException {
+            return notes.get(noteId);
+          }
+
+          @Override
+          public void save(Note note, AuthenticationInfo subject) throws IOException {
+            notes.put(note.getId(), note);
+          }
+
+          @Override
+          public void remove(String noteId, AuthenticationInfo subject) throws IOException {
+            notes.remove(notes.get(noteId));
+          }
+
+          @Override
+          public void close() {}
+
+          @Override
+          public List<NotebookRepoSettingsInfo> getSettings(AuthenticationInfo subject) {
+            return null;
+          }
+
+          @Override
+          public void updateSettings(Map<String, String> settings, AuthenticationInfo subject) {}
+        };
+    InterpreterSettingManager mockInterpreterSettingManager = mock(InterpreterSettingManager.class);
+    InterpreterFactory mockInterpreterFactory = mock(InterpreterFactory.class);
+    Interpreter mockInterpreter = mock(Interpreter.class);
+    when(mockInterpreterFactory.getInterpreter(any(), any(), any(), any())).thenReturn(mockInterpreter);
+    when(mockInterpreter.interpret(eq("invalid_code"), any())).thenReturn(new InterpreterResult(Code.ERROR, "failed"));
+    when(mockInterpreter.interpret(eq("1+1"), any())).thenReturn(new InterpreterResult(Code.SUCCESS, "succeed"));
+    doCallRealMethod().when(mockInterpreter).getScheduler();
+    when(mockInterpreter.getFormType()).thenReturn(FormType.NATIVE);
+    ManagedInterpreterGroup mockInterpreterGroup = mock(ManagedInterpreterGroup.class);
+    when(mockInterpreter.getInterpreterGroup()).thenReturn(mockInterpreterGroup);
+    InterpreterSetting mockInterpreterSetting = mock(InterpreterSetting.class);
+    when(mockInterpreterSetting.isUserAuthorized(any())).thenReturn(true);
+    when(mockInterpreterGroup.getInterpreterSetting()).thenReturn(mockInterpreterSetting);
+    SearchService searchService = new LuceneSearch(zeppelinConfiguration);
+    NotebookAuthorization notebookAuthorization = NotebookAuthorization.getInstance();
+    Credentials credentials = new Credentials(false, null, null);
+    Notebook notebook =
+        new Notebook(
+            zeppelinConfiguration,
+            notebookRepo,
+            mockInterpreterFactory,
+            mockInterpreterSettingManager,
+            searchService,
+            notebookAuthorization,
+            credentials);
+    notebookService = new NotebookService(notebook);
 
-  @AfterClass
-  public static void destroy() throws Exception {
-    AbstractTestRestApi.shutDown();
+    String interpreterName = "test";
+    when(mockInterpreterSetting.getName()).thenReturn(interpreterName);
+    when(mockInterpreterSettingManager.getDefaultInterpreterSetting())
+        .thenReturn(mockInterpreterSetting);
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d37cc1b6/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java
index 03e7ee6..c929e84 100644
--- a/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java
+++ b/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java
@@ -16,6 +16,27 @@
  */
 package org.apache.zeppelin.socket;
 
+import static java.util.Arrays.asList;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashSet;
+import java.util.List;
+import javax.servlet.http.HttpServletRequest;
 import org.apache.zeppelin.conf.ZeppelinConfiguration;
 import org.apache.zeppelin.display.AngularObject;
 import org.apache.zeppelin.display.AngularObjectBuilder;
@@ -31,36 +52,15 @@ import org.apache.zeppelin.notebook.socket.Message.OP;
 import org.apache.zeppelin.rest.AbstractTestRestApi;
 import org.apache.zeppelin.scheduler.Job;
 import org.apache.zeppelin.server.ZeppelinServer;
+import org.apache.zeppelin.service.ConfigurationService;
+import org.apache.zeppelin.service.NotebookService;
 import org.apache.zeppelin.user.AuthenticationInfo;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import javax.servlet.http.HttpServletRequest;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.HashSet;
-import java.util.List;
-
-import static java.util.Arrays.asList;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-/**
- * Basic REST API tests for notebookServer.
- */
+/** Basic REST API tests for notebookServer. */
 public class NotebookServerTest extends AbstractTestRestApi {
   private static Notebook notebook;
   private static NotebookServer notebookServer;
@@ -71,7 +71,11 @@ public class NotebookServerTest extends AbstractTestRestApi {
   public static void init() throws Exception {
     AbstractTestRestApi.startUp(NotebookServerTest.class.getSimpleName());
     notebook = ZeppelinServer.notebook;
-    notebookServer = ZeppelinServer.notebookWsServer;
+    notebookServer = spy(ZeppelinServer.notebookWsServer);
+    NotebookService notebookService = new NotebookService(notebook);
+    ConfigurationService configurationService = new ConfigurationService(notebook.getConf());
+    when(notebookServer.getNotebookService()).thenReturn(notebookService);
+    when(notebookServer.getConfigurationService()).thenReturn(configurationService);
   }
 
   @AfterClass
@@ -443,7 +447,7 @@ public class NotebookServerTest extends AbstractTestRestApi {
     server.getConnectionManager().noteSocketMap.put("noteId", asList(conn, otherConn));
 
     // When
-    server.angularObjectClientUnbind(conn, new HashSet<String>(), notebook, messageReceived);
+    server.angularObjectClientUnbind(conn, new HashSet<>(), notebook, messageReceived);
 
     // Then
     verify(otherConn).send(mdMsg1);

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d37cc1b6/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java
----------------------------------------------------------------------
diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java
index b7dcdc3..bb7ad1f 100644
--- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java
+++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java
@@ -52,7 +52,6 @@ import org.apache.zeppelin.notebook.repo.NotebookRepoSync;
 import org.apache.zeppelin.notebook.repo.NotebookRepoWithVersionControl;
 import org.apache.zeppelin.notebook.repo.NotebookRepoWithVersionControl.Revision;
 import org.apache.zeppelin.scheduler.Job;
-import org.apache.zeppelin.scheduler.SchedulerFactory;
 import org.apache.zeppelin.search.SearchService;
 import org.apache.zeppelin.user.AuthenticationInfo;
 import org.apache.zeppelin.user.Credentials;
@@ -75,9 +74,6 @@ import org.slf4j.LoggerFactory;
 public class Notebook implements NoteEventListener {
   private static final Logger logger = LoggerFactory.getLogger(Notebook.class);
 
-  @SuppressWarnings("unused") @Deprecated //TODO(bzz): remove unused
-  private SchedulerFactory schedulerFactory;
-
   private InterpreterFactory replFactory;
   private InterpreterSettingManager interpreterSettingManager;
   /**
@@ -93,7 +89,7 @@ public class Notebook implements NoteEventListener {
   private SearchService noteSearchService;
   private NotebookAuthorization notebookAuthorization;
   private final List<NotebookEventListener> notebookEventListeners =
-      Collections.synchronizedList(new LinkedList<NotebookEventListener>());
+      Collections.synchronizedList(new LinkedList<>());
   private Credentials credentials;
 
   /**
@@ -103,17 +99,19 @@ public class Notebook implements NoteEventListener {
    * @throws IOException
    * @throws SchedulerException
    */
-  public Notebook(ZeppelinConfiguration conf, NotebookRepo notebookRepo,
-      SchedulerFactory schedulerFactory, InterpreterFactory replFactory,
-      InterpreterSettingManager interpreterSettingManager, ParagraphJobListener paragraphJobListener,
-      SearchService noteSearchService, NotebookAuthorization notebookAuthorization,
-      Credentials credentials) throws IOException, SchedulerException {
+  public Notebook(
+      ZeppelinConfiguration conf,
+      NotebookRepo notebookRepo,
+      InterpreterFactory replFactory,
+      InterpreterSettingManager interpreterSettingManager,
+      SearchService noteSearchService,
+      NotebookAuthorization notebookAuthorization,
+      Credentials credentials)
+      throws IOException, SchedulerException {
     this.conf = conf;
     this.notebookRepo = notebookRepo;
-    this.schedulerFactory = schedulerFactory;
     this.replFactory = replFactory;
     this.interpreterSettingManager = interpreterSettingManager;
-    this.paragraphJobListener = paragraphJobListener;
     this.noteSearchService = noteSearchService;
     this.notebookAuthorization = notebookAuthorization;
     this.credentials = credentials;
@@ -134,6 +132,14 @@ public class Notebook implements NoteEventListener {
   }
 
   /**
+   * This method will be called only NotebookService to register {@link *
+   * org.apache.zeppelin.notebook.ParagraphJobListener}.
+   */
+  public void setParagraphJobListener(ParagraphJobListener paragraphJobListener) {
+    this.paragraphJobListener = paragraphJobListener;
+  }
+
+  /**
    * Create new note.
    *
    * @throws IOException

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d37cc1b6/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java
----------------------------------------------------------------------
diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java
index a88e0b9..0397075 100644
--- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java
+++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java
@@ -491,33 +491,42 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen
   private InterpreterContext getInterpreterContext() {
     final Paragraph self = this;
 
-    return getInterpreterContext(new InterpreterOutput(new InterpreterOutputListener() {
-      @Override
-      public void onAppend(int index, InterpreterResultMessageOutput out, byte[] line) {
-        ((ParagraphJobListener) getListener()).onOutputAppend(self, index, new String(line));
-      }
-
-      @Override
-      public void onUpdate(int index, InterpreterResultMessageOutput out) {
-        try {
-          ((ParagraphJobListener) getListener())
-              .onOutputUpdate(self, index, out.toInterpreterResultMessage());
-        } catch (IOException e) {
-          LOGGER.error(e.getMessage(), e);
-        }
-      }
-
-      @Override
-      public void onUpdateAll(InterpreterOutput out) {
-        try {
-          List<InterpreterResultMessage> messages = out.toInterpreterResultMessage();
-          ((ParagraphJobListener) getListener()).onOutputUpdateAll(self, messages);
-          updateParagraphResult(messages);
-        } catch (IOException e) {
-          LOGGER.error(e.getMessage(), e);
-        }
-
-      }
+    return getInterpreterContext(
+        new InterpreterOutput(
+            new InterpreterOutputListener() {
+              ParagraphJobListener paragraphJobListener = (ParagraphJobListener) getListener();
+
+              @Override
+              public void onAppend(int index, InterpreterResultMessageOutput out, byte[] line) {
+                if (null != paragraphJobListener) {
+                  paragraphJobListener.onOutputAppend(self, index, new String(line));
+                }
+              }
+
+              @Override
+              public void onUpdate(int index, InterpreterResultMessageOutput out) {
+                try {
+                  if (null != paragraphJobListener) {
+                    paragraphJobListener.onOutputUpdate(
+                        self, index, out.toInterpreterResultMessage());
+                  }
+                } catch (IOException e) {
+                  LOGGER.error(e.getMessage(), e);
+                }
+              }
+
+              @Override
+              public void onUpdateAll(InterpreterOutput out) {
+                try {
+                  List<InterpreterResultMessage> messages = out.toInterpreterResultMessage();
+                  if (null != paragraphJobListener) {
+                    paragraphJobListener.onOutputUpdateAll(self, messages);
+                  }
+                  updateParagraphResult(messages);
+                } catch (IOException e) {
+                  LOGGER.error(e.getMessage(), e);
+                }
+              }
 
       private void updateParagraphResult(List<InterpreterResultMessage> msgs) {
         // update paragraph results

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d37cc1b6/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumApplicationFactoryTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumApplicationFactoryTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumApplicationFactoryTest.java
index bc6f0ec..1d44dd5 100644
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumApplicationFactoryTest.java
+++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumApplicationFactoryTest.java
@@ -16,21 +16,22 @@
  */
 package org.apache.zeppelin.helium;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+
+import java.io.IOException;
 import org.apache.zeppelin.interpreter.AbstractInterpreterTest;
 import org.apache.zeppelin.interpreter.Interpreter;
 import org.apache.zeppelin.interpreter.InterpreterException;
 import org.apache.zeppelin.interpreter.InterpreterNotFoundException;
-import org.apache.zeppelin.interpreter.InterpreterResultMessage;
 import org.apache.zeppelin.interpreter.InterpreterSetting;
 import org.apache.zeppelin.notebook.ApplicationState;
 import org.apache.zeppelin.notebook.Note;
 import org.apache.zeppelin.notebook.Notebook;
 import org.apache.zeppelin.notebook.NotebookAuthorization;
 import org.apache.zeppelin.notebook.Paragraph;
-import org.apache.zeppelin.notebook.ParagraphJobListener;
 import org.apache.zeppelin.notebook.repo.NotebookRepo;
-import org.apache.zeppelin.scheduler.Job;
-import org.apache.zeppelin.scheduler.SchedulerFactory;
 import org.apache.zeppelin.search.SearchService;
 import org.apache.zeppelin.user.AuthenticationInfo;
 import org.apache.zeppelin.user.Credentials;
@@ -38,18 +39,8 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.io.IOException;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-
+public class HeliumApplicationFactoryTest extends AbstractInterpreterTest {
 
-public class HeliumApplicationFactoryTest extends AbstractInterpreterTest
-    implements ParagraphJobListener {
-
-  private SchedulerFactory schedulerFactory;
   private NotebookRepo notebookRepo;
   private Notebook notebook;
   private HeliumApplicationFactory heliumAppFactory;
@@ -59,7 +50,6 @@ public class HeliumApplicationFactoryTest extends AbstractInterpreterTest
   public void setUp() throws Exception {
     super.setUp();
 
-    this.schedulerFactory = SchedulerFactory.singleton();
     heliumAppFactory = new HeliumApplicationFactory();
     // set AppEventListener properly
     for (InterpreterSetting interpreterSetting : interpreterSettingManager.get()) {
@@ -69,16 +59,15 @@ public class HeliumApplicationFactoryTest extends AbstractInterpreterTest
     SearchService search = mock(SearchService.class);
     notebookRepo = mock(NotebookRepo.class);
     NotebookAuthorization notebookAuthorization = NotebookAuthorization.init(conf);
-    notebook = new Notebook(
-        conf,
-        notebookRepo,
-        schedulerFactory,
-        interpreterFactory,
-        interpreterSettingManager,
-        this,
-        search,
-        notebookAuthorization,
-        new Credentials(false, null, null));
+    notebook =
+        new Notebook(
+            conf,
+            notebookRepo,
+            interpreterFactory,
+            interpreterSettingManager,
+            search,
+            notebookAuthorization,
+            new Credentials(false, null, null));
 
     heliumAppFactory.setNotebook(notebook);
 
@@ -284,30 +273,4 @@ public class HeliumApplicationFactoryTest extends AbstractInterpreterTest
     // clean
     notebook.removeNote(note1.getId(), anonymous);
   }
-
-
-    @Override
-    public void onOutputAppend(Paragraph paragraph, int idx, String output) {
-
-    }
-
-    @Override
-    public void onOutputUpdate(Paragraph paragraph, int idx, InterpreterResultMessage msg) {
-
-    }
-
-    @Override
-    public void onOutputUpdateAll(Paragraph paragraph, List<InterpreterResultMessage> msgs) {
-
-    }
-
-    @Override
-    public void onProgressUpdate(Paragraph paragraph, int progress) {
-
-    }
-
-    @Override
-    public void onStatusChange(Paragraph paragraph, Job.Status before, Job.Status after) {
-
-    }
 }

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d37cc1b6/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java
index ab39952..6de2822 100644
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java
+++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java
@@ -37,7 +37,6 @@ import org.apache.zeppelin.notebook.repo.NotebookRepoWithVersionControl;
 import org.apache.zeppelin.resource.LocalResourcePool;
 import org.apache.zeppelin.scheduler.Job;
 import org.apache.zeppelin.scheduler.Job.Status;
-import org.apache.zeppelin.scheduler.SchedulerFactory;
 import org.apache.zeppelin.search.SearchService;
 import org.apache.zeppelin.user.AuthenticationInfo;
 import org.apache.zeppelin.user.Credentials;
@@ -77,7 +76,6 @@ import static org.mockito.Mockito.mock;
 public class NotebookTest extends AbstractInterpreterTest implements ParagraphJobListener {
   private static final Logger logger = LoggerFactory.getLogger(NotebookTest.class);
 
-  private SchedulerFactory schedulerFactory;
   private Notebook notebook;
   private NotebookRepo notebookRepo;
   private NotebookAuthorization notebookAuthorization;
@@ -91,15 +89,21 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
     System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_CRON_ENABLE.getVarName(), "true");
     super.setUp();
 
-    schedulerFactory = SchedulerFactory.singleton();
-
     SearchService search = mock(SearchService.class);
     notebookRepo = new InMemoryNotebookRepo();
     notebookAuthorization = NotebookAuthorization.init(conf);
     credentials = new Credentials(conf.credentialsPersist(), conf.getCredentialsPath(), null);
 
-    notebook = new Notebook(conf, notebookRepo, schedulerFactory, interpreterFactory, interpreterSettingManager, this, search,
-        notebookAuthorization, credentials);
+    notebook =
+        new Notebook(
+            conf,
+            notebookRepo,
+            interpreterFactory,
+            interpreterSettingManager,
+            search,
+            notebookAuthorization,
+            credentials);
+    notebook.setParagraphJobListener(this);
   }
 
   @After
@@ -113,16 +117,29 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
     Notebook notebook;
 
     notebookRepo = new DummyNotebookRepo();
-    notebook = new Notebook(conf, notebookRepo, schedulerFactory, interpreterFactory,
-        interpreterSettingManager, this, null,
-        notebookAuthorization, credentials);
+    notebook =
+        new Notebook(
+            conf,
+            notebookRepo,
+            interpreterFactory,
+            interpreterSettingManager,
+            null,
+            notebookAuthorization,
+            credentials);
     assertFalse("Revision is not supported in DummyNotebookRepo", notebook.isRevisionSupported());
 
     notebookRepo = new DummyNotebookRepoWithVersionControl();
-    notebook = new Notebook(conf, notebookRepo, schedulerFactory, interpreterFactory,
-        interpreterSettingManager, this, null,
-        notebookAuthorization, credentials);
-    assertTrue("Revision is supported in DummyNotebookRepoWithVersionControl",
+    notebook =
+        new Notebook(
+            conf,
+            notebookRepo,
+            interpreterFactory,
+            interpreterSettingManager,
+            null,
+            notebookAuthorization,
+            credentials);
+    assertTrue(
+        "Revision is supported in DummyNotebookRepoWithVersionControl",
         notebook.isRevisionSupported());
   }
 
@@ -350,10 +367,15 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
     p1.setText("hello world");
     note.persist(anonymous);
 
-    Notebook notebook2 = new Notebook(
-        conf, notebookRepo, schedulerFactory,
-        new InterpreterFactory(interpreterSettingManager),
-        interpreterSettingManager, null, null, null, null);
+    Notebook notebook2 =
+        new Notebook(
+            conf,
+            notebookRepo,
+            new InterpreterFactory(interpreterSettingManager),
+            interpreterSettingManager,
+            null,
+            null,
+            null);
 
     assertEquals(1, notebook2.getAllNotes().size());
     notebook.removeNote(note.getId(), anonymous);
@@ -835,7 +857,7 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
     notebook.removeNote(note.getId(), anonymous);
     notebook.removeNote(cloneNote.getId(), anonymous);
   }
-  
+
   @Test
   public void testResourceRemovealOnParagraphNoteRemove() throws IOException {
     Note note = notebook.createNote(anonymous);
@@ -1422,12 +1444,12 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
     System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_PUBLIC.getVarName(), "true");
     ZeppelinConfiguration.create();
   }
-  
+
   @Test
   public void testCloneImportCheck() throws IOException {
     Note sourceNote = notebook.createNote(new AuthenticationInfo("user"));
     sourceNote.setName("TestNote");
-    
+
     assertEquals("TestNote",sourceNote.getName());
 
     Paragraph sourceParagraph = sourceNote.addNewParagraph(AuthenticationInfo.ANONYMOUS);