Repository: zeppelin Updated Branches: refs/heads/master db716c8b1 -> 3eea57ab2
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3eea57ab/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/NotebookRepoSyncTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/NotebookRepoSyncTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/NotebookRepoSyncTest.java deleted file mode 100644 index 5571230..0000000 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/NotebookRepoSyncTest.java +++ /dev/null @@ -1,437 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zeppelin.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.List; -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; -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.*; -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; -import org.apache.zeppelin.user.Credentials; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.quartz.SchedulerException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -public class NotebookRepoSyncTest implements JobListenerFactory { - - private File mainZepDir; - private ZeppelinConfiguration conf; - private SchedulerFactory schedulerFactory; - private File mainNotebookDir; - private File secNotebookDir; - private Notebook notebookSync; - private NotebookRepoSync notebookRepoSync; - private InterpreterFactory factory; - private InterpreterSettingManager interpreterSettingManager; - private DependencyResolver depResolver; - private SearchService search; - private NotebookAuthorization notebookAuthorization; - private Credentials credentials; - private AuthenticationInfo anonymous; - private static final Logger LOG = LoggerFactory.getLogger(NotebookRepoSyncTest.class); - - @Before - public void setUp() throws Exception { - String zpath = System.getProperty("java.io.tmpdir")+"/ZeppelinLTest_"+System.currentTimeMillis(); - mainZepDir = new File(zpath); - mainZepDir.mkdirs(); - new File(mainZepDir, "conf").mkdirs(); - String mainNotePath = zpath+"/notebook"; - String secNotePath = mainNotePath + "_secondary"; - mainNotebookDir = new File(mainNotePath); - secNotebookDir = new File(secNotePath); - mainNotebookDir.mkdirs(); - secNotebookDir.mkdirs(); - - System.setProperty(ConfVars.ZEPPELIN_HOME.getVarName(), mainZepDir.getAbsolutePath()); - System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), mainNotebookDir.getAbsolutePath()); - System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_STORAGE.getVarName(), "org.apache.zeppelin.notebook.repo.VFSNotebookRepo,org.apache.zeppelin.notebook.repo.mock.VFSNotebookRepoMock"); - System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_ONE_WAY_SYNC.getVarName(), "false"); - System.setProperty(ConfVars.ZEPPELIN_CONFIG_FS_DIR.getVarName(), mainZepDir.getAbsolutePath() + "/conf"); - - LOG.info("main Note dir : " + mainNotePath); - LOG.info("secondary note dir : " + secNotePath); - conf = ZeppelinConfiguration.create(); - - 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)); - factory = new InterpreterFactory(interpreterSettingManager); - - search = mock(SearchService.class); - 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); - anonymous = new AuthenticationInfo("anonymous"); - } - - @After - public void tearDown() throws Exception { - delete(mainZepDir); - } - - @Test - public void testRepoCount() throws IOException { - assertTrue(notebookRepoSync.getMaxRepoNum() >= notebookRepoSync.getRepoCount()); - } - - @Test - public void testSyncOnCreate() throws IOException { - /* check that both storage systems are empty */ - assertTrue(notebookRepoSync.getRepoCount() > 1); - assertEquals(0, notebookRepoSync.list(0, anonymous).size()); - assertEquals(0, notebookRepoSync.list(1, anonymous).size()); - - /* create note */ - Note note = notebookSync.createNote(anonymous); - - // check that automatically saved on both storages - assertEquals(1, notebookRepoSync.list(0, anonymous).size()); - assertEquals(1, notebookRepoSync.list(1, anonymous).size()); - assertEquals(notebookRepoSync.list(0, anonymous).get(0).getId(),notebookRepoSync.list(1, anonymous).get(0).getId()); - - notebookSync.removeNote(notebookRepoSync.list(0, null).get(0).getId(), anonymous); - } - - @Test - public void testSyncOnDelete() throws IOException { - /* create note */ - assertTrue(notebookRepoSync.getRepoCount() > 1); - assertEquals(0, notebookRepoSync.list(0, anonymous).size()); - assertEquals(0, notebookRepoSync.list(1, anonymous).size()); - - Note note = notebookSync.createNote(anonymous); - - /* check that created in both storage systems */ - assertEquals(1, notebookRepoSync.list(0, anonymous).size()); - assertEquals(1, notebookRepoSync.list(1, anonymous).size()); - assertEquals(notebookRepoSync.list(0, anonymous).get(0).getId(),notebookRepoSync.list(1, anonymous).get(0).getId()); - - /* remove Note */ - notebookSync.removeNote(notebookRepoSync.list(0, anonymous).get(0).getId(), anonymous); - - /* check that deleted in both storages */ - assertEquals(0, notebookRepoSync.list(0, anonymous).size()); - assertEquals(0, notebookRepoSync.list(1, anonymous).size()); - - } - - @Test - public void testSyncUpdateMain() throws IOException { - - /* create note */ - Note note = notebookSync.createNote(anonymous); - Paragraph p1 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); - Map config = p1.getConfig(); - config.put("enabled", true); - p1.setConfig(config); - p1.setText("hello world"); - - /* new paragraph exists in note instance */ - assertEquals(1, note.getParagraphs().size()); - - /* new paragraph not yet saved into storages */ - assertEquals(0, notebookRepoSync.get(0, - notebookRepoSync.list(0, anonymous).get(0).getId(), anonymous).getParagraphs().size()); - assertEquals(0, notebookRepoSync.get(1, - notebookRepoSync.list(1, anonymous).get(0).getId(), anonymous).getParagraphs().size()); - - /* save to storage under index 0 (first storage) */ - notebookRepoSync.save(0, note, anonymous); - - /* check paragraph saved to first storage */ - assertEquals(1, notebookRepoSync.get(0, - notebookRepoSync.list(0, anonymous).get(0).getId(), anonymous).getParagraphs().size()); - /* check paragraph isn't saved to second storage */ - assertEquals(0, notebookRepoSync.get(1, - notebookRepoSync.list(1, anonymous).get(0).getId(), anonymous).getParagraphs().size()); - /* apply sync */ - notebookRepoSync.sync(null); - /* check whether added to second storage */ - assertEquals(1, notebookRepoSync.get(1, - notebookRepoSync.list(1, anonymous).get(0).getId(), anonymous).getParagraphs().size()); - /* check whether same paragraph id */ - assertEquals(p1.getId(), notebookRepoSync.get(0, - notebookRepoSync.list(0, anonymous).get(0).getId(), anonymous).getLastParagraph().getId()); - assertEquals(p1.getId(), notebookRepoSync.get(1, - notebookRepoSync.list(1, anonymous).get(0).getId(), anonymous).getLastParagraph().getId()); - notebookRepoSync.remove(note.getId(), anonymous); - } - - @Test - public void testSyncOnReloadedList() throws IOException { - /* check that both storage repos are empty */ - assertTrue(notebookRepoSync.getRepoCount() > 1); - assertEquals(0, notebookRepoSync.list(0, anonymous).size()); - assertEquals(0, notebookRepoSync.list(1, anonymous).size()); - - File srcDir = new File("src/test/resources/2A94M5J1Z"); - File destDir = new File(secNotebookDir + "/2A94M5J1Z"); - - /* copy manually new notebook into secondary storage repo and check repos */ - try { - FileUtils.copyDirectory(srcDir, destDir); - } catch (IOException e) { - LOG.error(e.toString(), e); - } - assertEquals(0, notebookRepoSync.list(0, anonymous).size()); - assertEquals(1, notebookRepoSync.list(1, anonymous).size()); - - // After reloading notebooks repos should be synchronized - notebookSync.reloadAllNotes(anonymous); - assertEquals(1, notebookRepoSync.list(0, anonymous).size()); - assertEquals(1, notebookRepoSync.list(1, anonymous).size()); - } - - @Test - public void testOneWaySyncOnReloadedList() throws IOException, SchedulerException { - System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), mainNotebookDir.getAbsolutePath()); - 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); - - // check that both storage repos are empty - assertTrue(notebookRepoSync.getRepoCount() > 1); - assertEquals(0, notebookRepoSync.list(0, null).size()); - assertEquals(0, notebookRepoSync.list(1, null).size()); - - File srcDir = new File("src/test/resources/2A94M5J1Z"); - File destDir = new File(secNotebookDir + "/2A94M5J1Z"); - - // copy manually new notebook into secondary storage repo and check repos - try { - FileUtils.copyDirectory(srcDir, destDir); - } catch (IOException e) { - LOG.error(e.toString(), e); - } - assertEquals(0, notebookRepoSync.list(0, null).size()); - assertEquals(1, notebookRepoSync.list(1, null).size()); - - // after reloading the notebook should be wiped from secondary storage - notebookSync.reloadAllNotes(null); - assertEquals(0, notebookRepoSync.list(0, null).size()); - assertEquals(0, notebookRepoSync.list(1, null).size()); - - destDir = new File(mainNotebookDir + "/2A94M5J1Z"); - - // copy manually new notebook into primary storage repo and check repos - try { - FileUtils.copyDirectory(srcDir, destDir); - } catch (IOException e) { - LOG.error(e.toString(), e); - } - assertEquals(1, notebookRepoSync.list(0, null).size()); - assertEquals(0, notebookRepoSync.list(1, null).size()); - - // after reloading notebooks repos should be synchronized - notebookSync.reloadAllNotes(null); - assertEquals(1, notebookRepoSync.list(0, null).size()); - assertEquals(1, notebookRepoSync.list(1, null).size()); - } - - @Test - public void testCheckpointOneStorage() throws IOException, SchedulerException { - System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_STORAGE.getVarName(), "org.apache.zeppelin.notebook.repo.GitNotebookRepo"); - ZeppelinConfiguration vConf = ZeppelinConfiguration.create(); - - NotebookRepoSync vRepoSync = new NotebookRepoSync(vConf); - Notebook vNotebookSync = new Notebook(vConf, vRepoSync, schedulerFactory, factory, interpreterSettingManager, this, search, - notebookAuthorization, credentials); - - // one git versioned storage initialized - assertThat(vRepoSync.getRepoCount()).isEqualTo(1); - assertThat(vRepoSync.getRepo(0)).isInstanceOf(GitNotebookRepo.class); - - GitNotebookRepo gitRepo = (GitNotebookRepo) vRepoSync.getRepo(0); - - // no notes - assertThat(vRepoSync.list(anonymous).size()).isEqualTo(0); - // create note - Note note = vNotebookSync.createNote(anonymous); - assertThat(vRepoSync.list(anonymous).size()).isEqualTo(1); - - String noteId = vRepoSync.list(anonymous).get(0).getId(); - // first checkpoint - vRepoSync.checkpoint(noteId, "checkpoint message", anonymous); - int vCount = gitRepo.revisionHistory(noteId, anonymous).size(); - assertThat(vCount).isEqualTo(1); - - Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); - Map<String, Object> config = p.getConfig(); - config.put("enabled", true); - p.setConfig(config); - p.setText("%md checkpoint test"); - - // save and checkpoint again - vRepoSync.save(note, anonymous); - vRepoSync.checkpoint(noteId, "checkpoint message 2", anonymous); - assertThat(gitRepo.revisionHistory(noteId, anonymous).size()).isEqualTo(vCount + 1); - notebookRepoSync.remove(note.getId(), anonymous); - } - - @Test - public void testSyncWithAcl() throws IOException { - /* scenario 1 - note exists with acl on main storage */ - AuthenticationInfo user1 = new AuthenticationInfo("user1"); - Note note = notebookSync.createNote(user1); - assertEquals(0, note.getParagraphs().size()); - - // saved on both storages - assertEquals(1, notebookRepoSync.list(0, null).size()); - assertEquals(1, notebookRepoSync.list(1, null).size()); - - /* check that user1 is the only owner */ - NotebookAuthorization authInfo = NotebookAuthorization.getInstance(); - Set<String> entity = new HashSet<String>(); - entity.add(user1.getUser()); - assertEquals(true, authInfo.isOwner(note.getId(), entity)); - assertEquals(1, authInfo.getOwners(note.getId()).size()); - assertEquals(0, authInfo.getReaders(note.getId()).size()); - assertEquals(0, authInfo.getRunners(note.getId()).size()); - assertEquals(0, authInfo.getWriters(note.getId()).size()); - - /* update note and save on secondary storage */ - Paragraph p1 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); - p1.setText("hello world"); - assertEquals(1, note.getParagraphs().size()); - notebookRepoSync.save(1, note, null); - - /* check paragraph isn't saved into first storage */ - assertEquals(0, notebookRepoSync.get(0, - notebookRepoSync.list(0, null).get(0).getId(), null).getParagraphs().size()); - /* check paragraph is saved into second storage */ - assertEquals(1, notebookRepoSync.get(1, - notebookRepoSync.list(1, null).get(0).getId(), null).getParagraphs().size()); - - /* now sync by user1 */ - notebookRepoSync.sync(user1); - - /* check that note updated and acl are same on main storage*/ - assertEquals(1, notebookRepoSync.get(0, - notebookRepoSync.list(0, null).get(0).getId(), null).getParagraphs().size()); - assertEquals(true, authInfo.isOwner(note.getId(), entity)); - assertEquals(1, authInfo.getOwners(note.getId()).size()); - assertEquals(0, authInfo.getReaders(note.getId()).size()); - assertEquals(0, authInfo.getRunners(note.getId()).size()); - assertEquals(0, authInfo.getWriters(note.getId()).size()); - - /* scenario 2 - note doesn't exist on main storage */ - /* remove from main storage */ - notebookRepoSync.remove(0, note.getId(), user1); - assertEquals(0, notebookRepoSync.list(0, null).size()); - assertEquals(1, notebookRepoSync.list(1, null).size()); - authInfo.removeNote(note.getId()); - assertEquals(0, authInfo.getOwners(note.getId()).size()); - assertEquals(0, authInfo.getReaders(note.getId()).size()); - assertEquals(0, authInfo.getRunners(note.getId()).size()); - assertEquals(0, authInfo.getWriters(note.getId()).size()); - - /* now sync - should bring note from secondary storage with added acl */ - notebookRepoSync.sync(user1); - assertEquals(1, notebookRepoSync.list(0, null).size()); - assertEquals(1, notebookRepoSync.list(1, null).size()); - assertEquals(1, authInfo.getOwners(note.getId()).size()); - assertEquals(1, authInfo.getReaders(note.getId()).size()); - assertEquals(1, authInfo.getRunners(note.getId()).size()); - assertEquals(1, authInfo.getWriters(note.getId()).size()); - assertEquals(true, authInfo.isOwner(note.getId(), entity)); - assertEquals(true, authInfo.isReader(note.getId(), entity)); - assertEquals(true, authInfo.isRunner(note.getId(), entity)); - assertEquals(true, authInfo.isWriter(note.getId(), entity)); - } - - static void delete(File file){ - if(file.isFile()) file.delete(); - else if(file.isDirectory()){ - File [] files = file.listFiles(); - if(files!=null && files.length>0){ - for(File f : files){ - delete(f); - } - } - file.delete(); - } - } - - @Override - public ParagraphJobListener getParagraphJobListener(Note note) { - return new ParagraphJobListener(){ - - @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(Job job, int progress) { - } - - @Override - public void onStatusChange(Job job, Status before, Status after) { - - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3eea57ab/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/VFSNotebookRepoTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/VFSNotebookRepoTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/VFSNotebookRepoTest.java deleted file mode 100644 index d62c308..0000000 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/VFSNotebookRepoTest.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zeppelin.notebook.repo; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; - -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.Map; - -import org.apache.commons.io.FileUtils; -import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars; - -import org.apache.zeppelin.interpreter.AbstractInterpreterTest; - -import org.apache.zeppelin.notebook.JobListenerFactory; -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.SchedulerFactory; -import org.apache.zeppelin.search.SearchService; -import org.apache.zeppelin.user.AuthenticationInfo; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.collect.ImmutableMap; - -public class VFSNotebookRepoTest extends AbstractInterpreterTest implements JobListenerFactory { - - private static final Logger LOG = LoggerFactory.getLogger(VFSNotebookRepoTest.class); - - private SchedulerFactory schedulerFactory; - private Notebook notebook; - private NotebookRepo notebookRepo; - private NotebookAuthorization notebookAuthorization; - - @Before - public void setUp() throws Exception { - System.setProperty(ConfVars.ZEPPELIN_INTERPRETER_GROUP_ORDER.getVarName(), "mock1,mock2"); - System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_STORAGE.getVarName(), "org.apache.zeppelin.notebook.repo.VFSNotebookRepo"); - - super.setUp(); - - this.schedulerFactory = SchedulerFactory.singleton(); - SearchService search = mock(SearchService.class); - notebookRepo = new VFSNotebookRepo(conf); - notebookAuthorization = NotebookAuthorization.init(conf); - notebook = new Notebook(conf, notebookRepo, schedulerFactory, interpreterFactory, interpreterSettingManager, this, search, - notebookAuthorization, null); - } - - @After - public void tearDown() throws Exception { - super.tearDown(); - } - - @Test - public void testInvalidJsonFile() throws IOException { - // given - int numNotes = notebookRepo.list(null).size(); - - // when create invalid json file - File testNoteDir = new File(notebookDir, "interpreter/test"); - testNoteDir.mkdir(); - FileUtils.writeStringToFile(new File(testNoteDir, "note.json"), ""); - - // then - assertEquals(numNotes, notebookRepo.list(null).size()); - } - - @Test - public void testSaveNotebook() throws IOException, InterruptedException { - AuthenticationInfo anonymous = new AuthenticationInfo("anonymous"); - Note note = notebook.createNote(anonymous); - interpreterSettingManager.setInterpreterBinding("user", note.getId(), interpreterSettingManager.getInterpreterSettingIds()); - - Paragraph p1 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS); - Map<String, Object> config = p1.getConfig(); - config.put("enabled", true); - p1.setConfig(config); - p1.setText("%mock1 hello world"); - p1.setAuthenticationInfo(anonymous); - - note.run(p1.getId()); - int timeout = 1; - while (!p1.isTerminated()) { - Thread.sleep(1000); - if (timeout++ > 10) { - break; - } - } - int i = 0; - int TEST_COUNT = 10; - while (i++ < TEST_COUNT) { - p1.setText("%mock1 hello zeppelin"); - new Thread(new NotebookWriter(note)).start(); - p1.setText("%mock1 hello world"); - new Thread(new NotebookWriter(note)).start(); - } - - note.setName("SaveTest"); - notebookRepo.save(note, null); - assertEquals(note.getName(), "SaveTest"); - notebookRepo.remove(note.getId(), null); - } - - @Test - public void testUpdateSettings() throws IOException { - AuthenticationInfo subject = new AuthenticationInfo("anonymous"); - File tmpDir = File.createTempFile("temp", Long.toString(System.nanoTime())); - Map<String, String> settings = ImmutableMap.of("Notebook Path", tmpDir.getAbsolutePath()); - - List<NotebookRepoSettingsInfo> repoSettings = notebookRepo.getSettings(subject); - String originalDir = repoSettings.get(0).selected; - - notebookRepo.updateSettings(settings, subject); - repoSettings = notebookRepo.getSettings(subject); - assertEquals(repoSettings.get(0).selected, tmpDir.getAbsolutePath()); - - // restaure - notebookRepo.updateSettings(ImmutableMap.of("Notebook Path", originalDir), subject); - FileUtils.deleteQuietly(tmpDir); - } - - class NotebookWriter implements Runnable { - Note note; - public NotebookWriter(Note note) { - this.note = note; - } - - @Override - public void run() { - try { - notebookRepo.save(note, null); - } catch (IOException e) { - LOG.error(e.toString(), e); - } - } - } - - @Override - public ParagraphJobListener getParagraphJobListener(Note note) { - return null; - } -} http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3eea57ab/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/mock/VFSNotebookRepoMock.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/mock/VFSNotebookRepoMock.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/mock/VFSNotebookRepoMock.java deleted file mode 100644 index 2674cce..0000000 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/mock/VFSNotebookRepoMock.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.zeppelin.notebook.repo.mock; - -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; - -import org.apache.commons.vfs2.VFS; -import org.apache.zeppelin.conf.ZeppelinConfiguration; -import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars; -import org.apache.zeppelin.notebook.repo.VFSNotebookRepo; - -public class VFSNotebookRepoMock extends VFSNotebookRepo { - - private static ZeppelinConfiguration modifyNotebookDir(ZeppelinConfiguration conf) { - String secNotebookDir = conf.getNotebookDir() + "_secondary"; - System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), secNotebookDir); - ZeppelinConfiguration secConf = ZeppelinConfiguration.create(); - return secConf; - } - - public VFSNotebookRepoMock(ZeppelinConfiguration conf) throws IOException { - super(modifyNotebookDir(conf)); - } - -} http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3eea57ab/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/ZeppelinHubRepoTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/ZeppelinHubRepoTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/ZeppelinHubRepoTest.java deleted file mode 100644 index 251795a..0000000 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/ZeppelinHubRepoTest.java +++ /dev/null @@ -1,154 +0,0 @@ -package org.apache.zeppelin.notebook.repo.zeppelinhub; - -import static com.google.common.truth.Truth.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.File; -import java.io.IOException; -import java.util.List; - -import org.apache.commons.httpclient.HttpException; -import org.apache.zeppelin.conf.ZeppelinConfiguration; -import org.apache.zeppelin.notebook.Note; -import org.apache.zeppelin.notebook.NoteInfo; -import org.apache.zeppelin.notebook.repo.zeppelinhub.rest.ZeppelinhubRestApiHandler; -import org.apache.zeppelin.user.AuthenticationInfo; -import org.junit.Before; -import org.junit.Test; - -import com.google.common.io.Files; - - -public class ZeppelinHubRepoTest { - final String token = "AAA-BBB-CCC-00"; - final String testAddr = "http://zeppelinhub.ltd"; - final AuthenticationInfo auth = new AuthenticationInfo("anthony"); - - private ZeppelinHubRepo repo; - private File pathOfNotebooks = new File(System.getProperty("user.dir") + "/src/test/resources/list_of_notes"); - private File pathOfNotebook = new File(System.getProperty("user.dir") + "/src/test/resources/note"); - - @Before - public void setUp() throws Exception { - System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, testAddr); - System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_TOKEN, token); - - ZeppelinConfiguration conf = new ZeppelinConfiguration(); - repo = new ZeppelinHubRepo(conf); - repo.setZeppelinhubRestApiHandler(getMockedZeppelinHandler()); - } - - private ZeppelinhubRestApiHandler getMockedZeppelinHandler() throws HttpException, IOException { - ZeppelinhubRestApiHandler mockedZeppelinhubHandler = mock(ZeppelinhubRestApiHandler.class); - - byte[] listOfNotesResponse = Files.toByteArray(pathOfNotebooks); - when(mockedZeppelinhubHandler.get("AAA-BBB-CCC-00", "")) - .thenReturn(new String(listOfNotesResponse)); - - byte[] noteResponse = Files.toByteArray(pathOfNotebook); - when(mockedZeppelinhubHandler.get("AAA-BBB-CCC-00", "AAAAA")) - .thenReturn(new String(noteResponse)); - - return mockedZeppelinhubHandler; - } - - @Test - public void testGetZeppelinhubUrl() { - System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, testAddr); - - ZeppelinConfiguration config = new ZeppelinConfiguration(); - ZeppelinHubRepo repository = new ZeppelinHubRepo(config); - assertThat(repository.getZeppelinHubUrl(config)).isEqualTo("http://zeppelinhub.ltd"); - - System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, "yolow"); - - config = new ZeppelinConfiguration(); - repository = new ZeppelinHubRepo(config); - assertThat(repository.getZeppelinHubUrl(config)).isEqualTo("https://www.zeppelinhub.com"); - - System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, "http://zeppelinhub.ltd:4242"); - - config = new ZeppelinConfiguration(); - repository = new ZeppelinHubRepo(config); - assertThat(repository.getZeppelinHubUrl(config)).isEqualTo("http://zeppelinhub.ltd:4242"); - - System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, "http://zeppelinhub.ltd:0"); - - config = new ZeppelinConfiguration(); - repository = new ZeppelinHubRepo(config); - assertThat(repository.getZeppelinHubUrl(config)).isEqualTo("http://zeppelinhub.ltd"); - } - - @Test - public void testGetZeppelinHubWsEndpoint() { - System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, testAddr); - - ZeppelinConfiguration config = new ZeppelinConfiguration(); - ZeppelinHubRepo repository = new ZeppelinHubRepo(config); - assertThat(repository.getZeppelinhubWebsocketUri(config)).isEqualTo("ws://zeppelinhub.ltd:80/async"); - - System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, "https://zeppelinhub.ltd"); - - config = new ZeppelinConfiguration(); - repository = new ZeppelinHubRepo(config); - assertThat(repository.getZeppelinhubWebsocketUri(config)).isEqualTo("wss://zeppelinhub.ltd:443/async"); - - System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, "yolow"); - - config = new ZeppelinConfiguration(); - repository = new ZeppelinHubRepo(config); - assertThat(repository.getZeppelinhubWebsocketUri(config)).isEqualTo("wss://www.zeppelinhub.com:443/async"); - - System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, "http://zeppelinhub.ltd:4242"); - - config = new ZeppelinConfiguration(); - repository = new ZeppelinHubRepo(config); - assertThat(repository.getZeppelinhubWebsocketUri(config)).isEqualTo("ws://zeppelinhub.ltd:4242/async"); - - System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, "https://www.zeppelinhub.com"); - - config = new ZeppelinConfiguration(); - repository = new ZeppelinHubRepo(config); - assertThat(repository.getZeppelinhubWebsocketUri(config)).isEqualTo("wss://www.zeppelinhub.com:443/async"); - - System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, "http://www.zeppelinhub.com"); - - config = new ZeppelinConfiguration(); - repository = new ZeppelinHubRepo(config); - assertThat(repository.getZeppelinhubWebsocketUri(config)).isEqualTo("ws://www.zeppelinhub.com:80/async"); - - System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, "https://www.zeppelinhub.com:4242"); - - config = new ZeppelinConfiguration(); - repository = new ZeppelinHubRepo(config); - assertThat(repository.getZeppelinhubWebsocketUri(config)).isEqualTo("wss://www.zeppelinhub.com:4242/async"); - } - - @Test - public void testGetAllNotes() throws IOException { - List<NoteInfo> notebooks = repo.list(auth); - assertThat(notebooks).isNotEmpty(); - assertThat(notebooks.size()).isEqualTo(3); - } - - @Test - public void testGetNote() throws IOException { - Note notebook = repo.get("AAAAA", auth); - assertThat(notebook).isNotNull(); - assertThat(notebook.getId()).isEqualTo("2A94M5J1Z"); - } - - @Test - public void testRemoveNote() throws IOException { - // not suppose to throw - repo.remove("AAAAA", auth); - } - - @Test - public void testRemoveNoteError() throws IOException { - // not suppose to throw - repo.remove("BBBBB", auth); - } - -} http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3eea57ab/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/ZeppelinClientTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/ZeppelinClientTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/ZeppelinClientTest.java deleted file mode 100644 index b8e52e4..0000000 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/ZeppelinClientTest.java +++ /dev/null @@ -1,127 +0,0 @@ -package org.apache.zeppelin.notebook.repo.zeppelinhub.websocket; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.mock.MockEchoWebsocketServer; -import org.apache.zeppelin.notebook.socket.Message; -import org.apache.zeppelin.notebook.socket.Message.OP; -import org.eclipse.jetty.websocket.api.Session; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.collect.Maps; - -public class ZeppelinClientTest { - private Logger LOG = LoggerFactory.getLogger(ZeppelinClientTest.class); - private final int zeppelinPort = 8080; - private final String validWebsocketUrl = "ws://localhost:" + zeppelinPort + "/ws"; - private ExecutorService executor; - private MockEchoWebsocketServer echoServer; - - @Before - public void setUp() throws Exception { - startWebsocketServer(); - } - - @After - public void tearDown() throws Exception { - //tear down routine - echoServer.stop(); - executor.shutdown(); - } - - private void startWebsocketServer() throws InterruptedException { - // mock zeppelin websocket server setup - executor = Executors.newFixedThreadPool(1); - echoServer = new MockEchoWebsocketServer(zeppelinPort); - executor.submit(echoServer); - } - - @Test - public void zeppelinConnectionTest() { - try { - // Wait for websocket server to start - Thread.sleep(2000); - } catch (InterruptedException e) { - LOG.warn("Cannot wait for websocket server to start, returning"); - return; - } - // Initialize and start Zeppelin client - ZeppelinClient client = ZeppelinClient.initialize(validWebsocketUrl, "dummy token", null); - client.start(); - LOG.info("Zeppelin websocket client started"); - - // Connection to note AAAA - Session connectionA = client.getZeppelinConnection("AAAA", "anonymous", "anonymous"); - assertNotNull(connectionA); - assertTrue(connectionA.isOpen()); - - assertEquals(client.countConnectedNotes(), 1); - assertEquals(connectionA, client.getZeppelinConnection("AAAA", "anonymous", "anonymous")); - - // Connection to note BBBB - Session connectionB = client.getZeppelinConnection("BBBB", "anonymous", "anonymous"); - assertNotNull(connectionB); - assertTrue(connectionB.isOpen()); - - assertEquals(client.countConnectedNotes(), 2); - assertEquals(connectionB, client.getZeppelinConnection("BBBB", "anonymous", "anonymous")); - - // Remove connection to note AAAA - client.removeNoteConnection("AAAA"); - assertEquals(client.countConnectedNotes(), 1); - assertNotEquals(connectionA, client.getZeppelinConnection("AAAA", "anonymous", "anonymous")); - assertEquals(client.countConnectedNotes(), 2); - client.stop(); - } - - @Test - public void zeppelinClientSingletonTest() { - ZeppelinClient client1 = ZeppelinClient.getInstance(); - if (client1 == null) { - client1 = ZeppelinClient.initialize(validWebsocketUrl, "TOKEN", null); - } - assertNotNull(client1); - ZeppelinClient client2 = ZeppelinClient.getInstance(); - assertNotNull(client2); - assertEquals(client1, client2); - } - - @Test - public void zeppelinMessageSerializationTest() { - Message msg = new Message(OP.LIST_NOTES); - msg.data = Maps.newHashMap(); - msg.data.put("key", "value"); - ZeppelinClient client = ZeppelinClient.initialize(validWebsocketUrl, "TOKEN", null); - String serializedMsg = client.serialize(msg); - Message deserializedMsg = client.deserialize(serializedMsg); - assertEquals(msg.op, deserializedMsg.op); - assertEquals(msg.data.get("key"), deserializedMsg.data.get("key")); - - String invalidMsg = "random text"; - deserializedMsg =client.deserialize(invalidMsg); - assertNull(deserializedMsg); - } - - @Test - public void sendToZeppelinTest() { - ZeppelinClient client = ZeppelinClient.initialize(validWebsocketUrl, "TOKEN", null); - client.start(); - Message msg = new Message(OP.LIST_NOTES); - msg.data = Maps.newHashMap(); - msg.data.put("key", "value"); - client.send(msg, "DDDD"); - client.removeNoteConnection("DDDD"); - client.stop(); - } -} http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3eea57ab/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/ZeppelinhubClientTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/ZeppelinhubClientTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/ZeppelinhubClientTest.java deleted file mode 100644 index 384cfe4..0000000 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/ZeppelinhubClientTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.apache.zeppelin.notebook.repo.zeppelinhub.websocket; - -import static org.junit.Assert.*; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.ZeppelinhubClient; -import org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.mock.MockEchoWebsocketServer; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ZeppelinhubClientTest { - private Logger LOG = LoggerFactory.getLogger(ZeppelinClientTest.class); - private final int zeppelinPort = 8090; - private final String validWebsocketUrl = "ws://localhost:" + zeppelinPort + "/ws"; - private ExecutorService executor; - private MockEchoWebsocketServer echoServer; - private final String runNotebookMsg = - "{\"op\":\"RUN_NOTEBOOK\"," + - "\"data\":[{\"id\":\"20150112-172845_1301897143\",\"title\":null,\"config\":{},\"params\":{},\"data\":null}," + - "{\"id\":\"20150112-172845_1301897143\",\"title\":null,\"config\":{},\"params\":{},\"data\":null}]," + - "\"meta\":{\"owner\":\"author\",\"instance\":\"my-zepp\",\"noteId\":\"2AB7SY361\"}}"; - private final String invalidRunNotebookMsg = "some random string"; - - @Before - public void setUp() throws Exception { - startWebsocketServer(); - } - - @After - public void tearDown() throws Exception { - //tear down routine - echoServer.stop(); - executor.shutdown(); - } - - private void startWebsocketServer() throws InterruptedException { - // mock zeppelin websocket server setup - executor = Executors.newFixedThreadPool(1); - echoServer = new MockEchoWebsocketServer(zeppelinPort); - executor.submit(echoServer); - } - - @Test - public void zeppelinhubClientSingletonTest() { - ZeppelinhubClient client1 = ZeppelinhubClient.getInstance(); - if (client1 == null) { - client1 = ZeppelinhubClient.initialize(validWebsocketUrl, "TOKEN"); - } - assertNotNull(client1); - ZeppelinhubClient client2 = ZeppelinhubClient.getInstance(); - assertNotNull(client2); - assertEquals(client1, client2); - } - - @Test - public void runAllParagraphTest() throws Exception { - Client.initialize(validWebsocketUrl, validWebsocketUrl, "TOKEN", null); - Client.getInstance().start(); - ZeppelinhubClient zeppelinhubClient = ZeppelinhubClient.getInstance(); - boolean runStatus = zeppelinhubClient.runAllParagraph("2AB7SY361", runNotebookMsg); - assertTrue(runStatus); - runStatus = zeppelinhubClient.runAllParagraph("2AB7SY361", invalidRunNotebookMsg); - assertFalse(runStatus); - Client.getInstance().stop(); - } - -} http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3eea57ab/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/mock/MockEchoWebsocketServer.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/mock/MockEchoWebsocketServer.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/mock/MockEchoWebsocketServer.java deleted file mode 100644 index e9959e9..0000000 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/mock/MockEchoWebsocketServer.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.mock; - -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.ServerConnector; -import org.eclipse.jetty.servlet.ServletContextHandler; -import org.slf4j.LoggerFactory; - -public class MockEchoWebsocketServer implements Runnable { - private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(MockEchoWebsocketServer.class); - private Server server; - - public MockEchoWebsocketServer(int port) { - server = new Server(); - ServerConnector connector = new ServerConnector(server); - connector.setPort(port); - server.addConnector(connector); - - ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); - context.setContextPath("/"); - server.setHandler(context); - - //ServletHolder holderEvents = new ServletHolder("ws-events", MockEventServlet.class); - context.addServlet(MockEventServlet.class, "/ws/*"); - } - - public void start() throws Exception { - LOG.info("Starting mock echo websocket server"); - server.start(); - server.join(); - } - - public void stop() throws Exception { - LOG.info("Stopping mock echo websocket server"); - server.stop(); - } - - @Override - public void run() { - try { - this.start(); - } catch (Exception e) { - LOG.error("Couldn't start mock echo websocket server", e); - } - } - -} http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3eea57ab/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/mock/MockEventServlet.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/mock/MockEventServlet.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/mock/MockEventServlet.java deleted file mode 100644 index c84f2c3..0000000 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/mock/MockEventServlet.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.mock; - -import org.eclipse.jetty.websocket.servlet.WebSocketServlet; -import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; - -@SuppressWarnings("serial") -public class MockEventServlet extends WebSocketServlet -{ - @Override - public void configure(WebSocketServletFactory factory) - { - factory.register(MockEventSocket.class); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3eea57ab/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/mock/MockEventSocket.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/mock/MockEventSocket.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/mock/MockEventSocket.java deleted file mode 100644 index 0f39b01..0000000 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/mock/MockEventSocket.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.mock; - -import org.eclipse.jetty.websocket.api.Session; -import org.eclipse.jetty.websocket.api.WebSocketAdapter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class MockEventSocket extends WebSocketAdapter { - private static final Logger LOG = LoggerFactory.getLogger(MockEventServlet.class); - private Session session; - - @Override - public void onWebSocketConnect(Session session) { - super.onWebSocketConnect(session); - this.session = session; - LOG.info("Socket Connected: " + session); - } - - @Override - public void onWebSocketText(String message) { - super.onWebSocketText(message); - session.getRemote().sendStringByFuture(message); - LOG.info("Received TEXT message: {}", message); - - } - - @Override - public void onWebSocketClose(int statusCode, String reason) { - super.onWebSocketClose(statusCode, reason); - LOG.info("Socket Closed: [{}] {}", statusCode, reason); - } - - @Override - public void onWebSocketError(Throwable cause) { - super.onWebSocketError(cause); - LOG.error("Websocket error: {}", cause); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3eea57ab/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/protocol/ZeppelinhubMessageTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/protocol/ZeppelinhubMessageTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/protocol/ZeppelinhubMessageTest.java deleted file mode 100644 index 1f07f4f..0000000 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/websocket/protocol/ZeppelinhubMessageTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.protocol; - -import static org.junit.Assert.assertEquals; - -import java.util.Map; - -import org.apache.zeppelin.notebook.socket.Message.OP; -import org.junit.Test; - -import com.google.common.collect.Maps; - -public class ZeppelinhubMessageTest { - - private String msg = "{\"op\":\"LIST_NOTES\",\"data\":\"my data\",\"meta\":{\"key1\":\"val1\"}}"; - - @Test - public void testThatCanSerializeZeppelinHubMessage() { - Map<String,String> meta = Maps.newHashMap(); - meta.put("key1", "val1"); - String zeppelinHubMsg = ZeppelinhubMessage.newMessage(OP.LIST_NOTES, "my data", meta).toJson(); - - assertEquals(msg, zeppelinHubMsg); - } - - @Test - public void testThastCanDeserialiseZeppelinhubMessage() { - Map<String,String> meta = Maps.newHashMap(); - meta.put("key1", "val1"); - ZeppelinhubMessage expected = ZeppelinhubMessage.newMessage(OP.LIST_NOTES.toString(), "my data", meta); - ZeppelinhubMessage zeppelinHubMsg = ZeppelinhubMessage.fromJson(msg); - - assertEquals(expected.op, zeppelinHubMsg.op); - assertEquals(expected.data, zeppelinHubMsg.data); - assertEquals(expected.meta, zeppelinHubMsg.meta); - } - - @Test - public void testThatInvalidStringReturnEmptyZeppelinhubMessage() { - assertEquals(ZeppelinhubMessage.EMPTY, ZeppelinhubMessage.fromJson("")); - assertEquals(ZeppelinhubMessage.EMPTY, ZeppelinhubMessage.fromJson("dwfewewrewr")); - } - -} http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3eea57ab/zeppelin-zengine/src/test/resources/2A94M5J1Z/note.json ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/resources/2A94M5J1Z/note.json b/zeppelin-zengine/src/test/resources/2A94M5J1Z/note.json deleted file mode 100644 index 785ccea..0000000 --- a/zeppelin-zengine/src/test/resources/2A94M5J1Z/note.json +++ /dev/null @@ -1,341 +0,0 @@ -{ - "paragraphs": [ - { - "text": "%md\n## Welcome to Zeppelin.\n##### This is a live tutorial, you can run the code yourself. (Shift-Enter to Run)", - "config": { - "colWidth": 12.0, - "graph": { - "mode": "table", - "height": 300.0, - "optionOpen": false, - "keys": [], - "values": [], - "groups": [], - "scatter": {} - }, - "editorHide": true - }, - "settings": { - "params": {}, - "forms": {} - }, - "jobName": "paragraph_1423836981412_-1007008116", - "id": "20150213-231621_168813393", - "result": { - "code": "SUCCESS", - "type": "HTML", - "msg": "\u003ch2\u003eWelcome to Zeppelin.\u003c/h2\u003e\n\u003ch5\u003eThis is a live tutorial, you can run the code yourself. (Shift-Enter to Run)\u003c/h5\u003e\n" - }, - "dateCreated": "Feb 13, 2015 11:16:21 PM", - "dateStarted": "Apr 1, 2015 9:11:09 PM", - "dateFinished": "Apr 1, 2015 9:11:10 PM", - "status": "FINISHED", - "progressUpdateIntervalMs": 500 - }, - { - "title": "Load data into table", - "text": "import org.apache.commons.io.IOUtils\nimport java.net.URL\nimport java.nio.charset.Charset\n\n// Zeppelin creates and injects sc (SparkContext) and sqlContext (HiveContext or SqlContext)\n// So you don\u0027t need create them manually\n\n// load bank data\nval bankText \u003d sc.parallelize(\n IOUtils.toString(\n new URL(\"https://s3.amazonaws.com/apache-zeppelin/tutorial/bank/bank.csv\"),\n Charset.forName(\"utf8\")).split(\"\\n\"))\n\ncase class Bank(age: Integer, job: String, marital: String, education: String, balance: Integer)\n\nval bank \u003d bankText.map(s \u003d\u003e s.split(\";\")).filter(s \u003d\u003e s(0) !\u003d \"\\\"age\\\"\").map(\n s \u003d\u003e Bank(s(0).toInt, \n s(1).replaceAll(\"\\\"\", \"\"),\n s(2).replaceAll(\"\\\"\", \"\"),\n s(3).replaceAll(\"\\\"\", \"\"),\n s(5).replaceAll(\"\\\"\", \"\").toInt\n )\n).toDF()\nbank.registerTempTable(\"bank\")", - "config": { - "colWidth": 12.0, - "graph": { - "mode": "table", - "height": 300.0, - "optionOpen": false, - "keys": [], - "values": [], - "groups": [], - "scatter": {} - }, - "title": true - }, - "settings": { - "params": {}, - "forms": {} - }, - "jobName": "paragraph_1423500779206_-1502780787", - "id": "20150210-015259_1403135953", - "result": { - "code": "SUCCESS", - "type": "TEXT", - "msg": "import org.apache.commons.io.IOUtils\nimport java.net.URL\nimport java.nio.charset.Charset\nbankText: org.apache.spark.rdd.RDD[String] \u003d ParallelCollectionRDD[32] at parallelize at \u003cconsole\u003e:65\ndefined class Bank\nbank: org.apache.spark.sql.DataFrame \u003d [age: int, job: string, marital: string, education: string, balance: int]\n" - }, - "dateCreated": "Feb 10, 2015 1:52:59 AM", - "dateStarted": "Jul 3, 2015 1:43:40 PM", - "dateFinished": "Jul 3, 2015 1:43:45 PM", - "status": "FINISHED", - "progressUpdateIntervalMs": 500 - }, - { - "text": "%sql \nselect age, count(1) value\nfrom bank \nwhere age \u003c 30 \ngroup by age \norder by age", - "config": { - "colWidth": 4.0, - "graph": { - "mode": "multiBarChart", - "height": 300.0, - "optionOpen": false, - "keys": [ - { - "name": "age", - "index": 0.0, - "aggr": "sum" - } - ], - "values": [ - { - "name": "value", - "index": 1.0, - "aggr": "sum" - } - ], - "groups": [], - "scatter": { - "xAxis": { - "name": "age", - "index": 0.0, - "aggr": "sum" - }, - "yAxis": { - "name": "value", - "index": 1.0, - "aggr": "sum" - } - } - } - }, - "settings": { - "params": {}, - "forms": {} - }, - "jobName": "paragraph_1423500782552_-1439281894", - "id": "20150210-015302_1492795503", - "result": { - "code": "SUCCESS", - "type": "TABLE", - "msg": "age\tvalue\n19\t4\n20\t3\n21\t7\n22\t9\n23\t20\n24\t24\n25\t44\n26\t77\n27\t94\n28\t103\n29\t97\n" - }, - "dateCreated": "Feb 10, 2015 1:53:02 AM", - "dateStarted": "Jul 3, 2015 1:43:17 PM", - "dateFinished": "Jul 3, 2015 1:43:23 PM", - "status": "FINISHED", - "progressUpdateIntervalMs": 500 - }, - { - "text": "%sql \nselect age, count(1) value \nfrom bank \nwhere age \u003c ${maxAge\u003d30} \ngroup by age \norder by age", - "config": { - "colWidth": 4.0, - "graph": { - "mode": "multiBarChart", - "height": 300.0, - "optionOpen": false, - "keys": [ - { - "name": "age", - "index": 0.0, - "aggr": "sum" - } - ], - "values": [ - { - "name": "value", - "index": 1.0, - "aggr": "sum" - } - ], - "groups": [], - "scatter": { - "xAxis": { - "name": "age", - "index": 0.0, - "aggr": "sum" - }, - "yAxis": { - "name": "value", - "index": 1.0, - "aggr": "sum" - } - } - } - }, - "settings": { - "params": { - "maxAge": "35" - }, - "forms": { - "maxAge": { - "name": "maxAge", - "defaultValue": "30", - "hidden": false - } - } - }, - "jobName": "paragraph_1423720444030_-1424110477", - "id": "20150212-145404_867439529", - "result": { - "code": "SUCCESS", - "type": "TABLE", - "msg": "age\tvalue\n19\t4\n20\t3\n21\t7\n22\t9\n23\t20\n24\t24\n25\t44\n26\t77\n27\t94\n28\t103\n29\t97\n30\t150\n31\t199\n32\t224\n33\t186\n34\t231\n" - }, - "dateCreated": "Feb 12, 2015 2:54:04 PM", - "dateStarted": "Jul 3, 2015 1:43:28 PM", - "dateFinished": "Jul 3, 2015 1:43:29 PM", - "status": "FINISHED", - "progressUpdateIntervalMs": 500 - }, - { - "text": "%sql \nselect age, count(1) value \nfrom bank \nwhere marital\u003d\"${marital\u003dsingle,single|divorced|married}\" \ngroup by age \norder by age", - "config": { - "colWidth": 4.0, - "graph": { - "mode": "multiBarChart", - "height": 300.0, - "optionOpen": false, - "keys": [ - { - "name": "age", - "index": 0.0, - "aggr": "sum" - } - ], - "values": [ - { - "name": "value", - "index": 1.0, - "aggr": "sum" - } - ], - "groups": [], - "scatter": { - "xAxis": { - "name": "age", - "index": 0.0, - "aggr": "sum" - }, - "yAxis": { - "name": "value", - "index": 1.0, - "aggr": "sum" - } - } - } - }, - "settings": { - "params": { - "marital": "single" - }, - "forms": { - "marital": { - "name": "marital", - "defaultValue": "single", - "options": [ - { - "value": "single" - }, - { - "value": "divorced" - }, - { - "value": "married" - } - ], - "hidden": false - } - } - }, - "jobName": "paragraph_1423836262027_-210588283", - "id": "20150213-230422_1600658137", - "result": { - "code": "SUCCESS", - "type": "TABLE", - "msg": "age\tvalue\n19\t4\n20\t3\n21\t7\n22\t9\n23\t17\n24\t13\n25\t33\n26\t56\n27\t64\n28\t78\n29\t56\n30\t92\n31\t86\n32\t105\n33\t61\n34\t75\n35\t46\n36\t50\n37\t43\n38\t44\n39\t30\n40\t25\n41\t19\n42\t23\n43\t21\n44\t20\n45\t15\n46\t14\n47\t12\n48\t12\n49\t11\n50\t8\n51\t6\n52\t9\n53\t4\n55\t3\n56\t3\n57\t2\n58\t7\n59\t2\n60\t5\n66\t2\n69\t1\n" - }, - "dateCreated": "Feb 13, 2015 11:04:22 PM", - "dateStarted": "Jul 3, 2015 1:43:33 PM", - "dateFinished": "Jul 3, 2015 1:43:34 PM", - "status": "FINISHED", - "progressUpdateIntervalMs": 500 - }, - { - "text": "%md\n## Congratulations, it\u0027s done.\n##### You can create your own notebook in \u0027Notebook\u0027 menu. Good luck!", - "config": { - "colWidth": 12.0, - "graph": { - "mode": "table", - "height": 300.0, - "optionOpen": false, - "keys": [], - "values": [], - "groups": [], - "scatter": {} - }, - "editorHide": true - }, - "settings": { - "params": {}, - "forms": {} - }, - "jobName": "paragraph_1423836268492_216498320", - "id": "20150213-230428_1231780373", - "result": { - "code": "SUCCESS", - "type": "HTML", - "msg": "\u003ch2\u003eCongratulations, it\u0027s done.\u003c/h2\u003e\n\u003ch5\u003eYou can create your own notebook in \u0027Notebook\u0027 menu. Good luck!\u003c/h5\u003e\n" - }, - "dateCreated": "Feb 13, 2015 11:04:28 PM", - "dateStarted": "Apr 1, 2015 9:12:18 PM", - "dateFinished": "Apr 1, 2015 9:12:18 PM", - "status": "FINISHED", - "progressUpdateIntervalMs": 500 - }, - { - "text": "%md\n\nAbout bank data\n\n```\nCitation Request:\n This dataset is public available for research. The details are described in [Moro et al., 2011]. \n Please include this citation if you plan to use this database:\n\n [Moro et al., 2011] S. Moro, R. Laureano and P. Cortez. Using Data Mining for Bank Direct Marketing: An Application of the CRISP-DM Methodology. \n In P. Novais et al. (Eds.), Proceedings of the European Simulation and Modelling Conference - ESM\u00272011, pp. 117-121, Guimarães, Portugal, October, 2011. EUROSIS.\n\n Available at: [pdf] http://hdl.handle.net/1822/14838\n [bib] http://www3.dsi.uminho.pt/pcortez/bib/2011-esm-1.txt\n```", - "config": { - "colWidth": 12.0, - "graph": { - "mode": "table", - "height": 300.0, - "optionOpen": false, - "keys": [], - "values": [], - "groups": [], - "scatter": {} - }, - "editorHide": true - }, - "settings": { - "params": {}, - "forms": {} - }, - "jobName": "paragraph_1427420818407_872443482", - "id": "20150326-214658_12335843", - "result": { - "code": "SUCCESS", - "type": "HTML", - "msg": "\u003cp\u003eAbout bank data\u003c/p\u003e\n\u003cpre\u003e\u003ccode\u003eCitation Request:\n This dataset is public available for research. The details are described in [Moro et al., 2011]. \n Please include this citation if you plan to use this database:\n\n [Moro et al., 2011] S. Moro, R. Laureano and P. Cortez. Using Data Mining for Bank Direct Marketing: An Application of the CRISP-DM Methodology. \n In P. Novais et al. (Eds.), Proceedings of the European Simulation and Modelling Conference - ESM\u00272011, pp. 117-121, Guimarães, Portugal, October, 2011. EUROSIS.\n\n Available at: [pdf] http://hdl.handle.net/1822/14838\n [bib] http://www3.dsi.uminho.pt/pcortez/bib/2011-esm-1.txt\n\u003c/code\u003e\u003c/pre\u003e\n" - }, - "dateCreated": "Mar 26, 2015 9:46:58 PM", - "dateStarted": "Jul 3, 2015 1:44:56 PM", - "dateFinished": "Jul 3, 2015 1:44:56 PM", - "status": "FINISHED", - "progressUpdateIntervalMs": 500 - }, - { - "config": {}, - "settings": { - "params": {}, - "forms": {} - }, - "jobName": "paragraph_1435955447812_-158639899", - "id": "20150703-133047_853701097", - "dateCreated": "Jul 3, 2015 1:30:47 PM", - "status": "READY", - "progressUpdateIntervalMs": 500 - } - ], - "name": "Zeppelin Tutorial", - "id": "2A94M5J1Z", - "angularObjects": {}, - "config": { - "looknfeel": "default" - }, - "info": {} -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3eea57ab/zeppelin-zengine/src/test/resources/2A94M5J2Z/note.json ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/resources/2A94M5J2Z/note.json b/zeppelin-zengine/src/test/resources/2A94M5J2Z/note.json deleted file mode 100644 index 79fe35c..0000000 --- a/zeppelin-zengine/src/test/resources/2A94M5J2Z/note.json +++ /dev/null @@ -1,87 +0,0 @@ -{ - "paragraphs": [ - { - "text": "%md\n## Congratulations, it\u0027s done.\n##### You can create your own notebook in \u0027Notebook\u0027 menu. Good luck!", - "config": { - "colWidth": 12.0, - "graph": { - "mode": "table", - "height": 300.0, - "optionOpen": false, - "keys": [], - "values": [], - "groups": [], - "scatter": {} - }, - "editorHide": true - }, - "settings": { - "params": {}, - "forms": {} - }, - "jobName": "paragraph_1423836268492_216498320", - "id": "20150213-230428_1231780373", - "result": { - "code": "SUCCESS", - "type": "HTML", - "msg": "\u003ch2\u003eCongratulations, it\u0027s done.\u003c/h2\u003e\n\u003ch5\u003eYou can create your own notebook in \u0027Notebook\u0027 menu. Good luck!\u003c/h5\u003e\n" - }, - "dateCreated": "Feb 13, 2015 11:04:28 PM", - "dateStarted": "Apr 1, 2015 9:12:18 PM", - "dateFinished": "Apr 1, 2015 9:12:18 PM", - "status": "FINISHED", - "progressUpdateIntervalMs": 500 - }, - { - "text": "%md\n\nAbout bank data\n\n```\nCitation Request:\n This dataset is public available for research. The details are described in [Moro et al., 2011]. \n Please include this citation if you plan to use this database:\n\n [Moro et al., 2011] S. Moro, R. Laureano and P. Cortez. Using Data Mining for Bank Direct Marketing: An Application of the CRISP-DM Methodology. \n In P. Novais et al. (Eds.), Proceedings of the European Simulation and Modelling Conference - ESM\u00272011, pp. 117-121, Guimarães, Portugal, October, 2011. EUROSIS.\n\n Available at: [pdf] http://hdl.handle.net/1822/14838\n [bib] http://www3.dsi.uminho.pt/pcortez/bib/2011-esm-1.txt\n```", - "config": { - "colWidth": 12.0, - "graph": { - "mode": "table", - "height": 300.0, - "optionOpen": false, - "keys": [], - "values": [], - "groups": [], - "scatter": {} - }, - "editorHide": true - }, - "settings": { - "params": {}, - "forms": {} - }, - "jobName": "paragraph_1427420818407_872443482", - "id": "20150326-214658_12335843", - "result": { - "code": "SUCCESS", - "type": "HTML", - "msg": "\u003cp\u003eAbout bank data\u003c/p\u003e\n\u003cpre\u003e\u003ccode\u003eCitation Request:\n This dataset is public available for research. The details are described in [Moro et al., 2011]. \n Please include this citation if you plan to use this database:\n\n [Moro et al., 2011] S. Moro, R. Laureano and P. Cortez. Using Data Mining for Bank Direct Marketing: An Application of the CRISP-DM Methodology. \n In P. Novais et al. (Eds.), Proceedings of the European Simulation and Modelling Conference - ESM\u00272011, pp. 117-121, Guimarães, Portugal, October, 2011. EUROSIS.\n\n Available at: [pdf] http://hdl.handle.net/1822/14838\n [bib] http://www3.dsi.uminho.pt/pcortez/bib/2011-esm-1.txt\n\u003c/code\u003e\u003c/pre\u003e\n" - }, - "dateCreated": "Mar 26, 2015 9:46:58 PM", - "dateStarted": "Jul 3, 2015 1:44:56 PM", - "dateFinished": "Jul 3, 2015 1:44:56 PM", - "status": "FINISHED", - "progressUpdateIntervalMs": 500 - }, - { - "config": {}, - "settings": { - "params": {}, - "forms": {} - }, - "jobName": "paragraph_1435955447812_-158639899", - "id": "20150703-133047_853701097", - "dateCreated": "Jul 3, 2015 1:30:47 PM", - "status": "READY", - "progressUpdateIntervalMs": 500 - } - ], - "name": "Sample note - excerpt from Zeppelin Tutorial", - "id": "2A94M5J2Z", - "angularObjects": {}, - "config": { - "looknfeel": "default" - }, - "info": {} -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3eea57ab/zeppelin-zengine/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/resources/log4j.properties b/zeppelin-zengine/src/test/resources/log4j.properties index ecfd05e..e45936e 100644 --- a/zeppelin-zengine/src/test/resources/log4j.properties +++ b/zeppelin-zengine/src/test/resources/log4j.properties @@ -43,5 +43,4 @@ log4j.logger.DataNucleus.Datastore=ERROR log4j.logger.org.hibernate.type=ALL log4j.logger.org.apache.hadoop=WARN - -log4j.logger.org.apache.zeppelin.interpreter=DEBUG +log4j.logger.org.apache.zeppelin.plugin=DEBUG