Repository: zeppelin Updated Branches: refs/heads/master ebe885572 -> 9463fb854
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9463fb85/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTestApplication.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTestApplication.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTestApplication.java new file mode 100644 index 0000000..8b1d14f --- /dev/null +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTestApplication.java @@ -0,0 +1,45 @@ +/* + * 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.helium; + +import org.apache.zeppelin.resource.ResourceSet; + +import java.io.IOException; +import java.util.concurrent.atomic.AtomicInteger; + +public class HeliumTestApplication extends Application { + AtomicInteger numRun = new AtomicInteger(0); + public HeliumTestApplication(ApplicationContext context) { + super(context); + } + + @Override + public void run(ResourceSet args) throws ApplicationException { + try { + context().out.clear(); + context().out.write("Hello world " + numRun.incrementAndGet()); + context().out.flush(); + } catch (IOException e) { + throw new ApplicationException(e); + } + } + + @Override + public void unload() throws ApplicationException { + + } +} http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9463fb85/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTestRegistry.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTestRegistry.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTestRegistry.java new file mode 100644 index 0000000..d99f73f --- /dev/null +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumTestRegistry.java @@ -0,0 +1,39 @@ +/* + * 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.helium; + +import java.io.IOException; +import java.net.URI; +import java.util.LinkedList; +import java.util.List; + +public class HeliumTestRegistry extends HeliumRegistry { + List<HeliumPackage> infos = new LinkedList<HeliumPackage>(); + + public HeliumTestRegistry(String name, String uri) { + super(name, uri); + } + + @Override + public List<HeliumPackage> getAll() throws IOException { + return infos; + } + + public void add(HeliumPackage info) { + infos.add(info); + } +} http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9463fb85/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java index 3d9ee6f..9df494f 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java @@ -22,6 +22,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Properties; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang.NullArgumentException; import org.apache.zeppelin.conf.ZeppelinConfiguration; import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars; @@ -57,35 +58,28 @@ public class InterpreterFactoryTest { System.setProperty(ConfVars.ZEPPELIN_INTERPRETERS.getVarName(), "org.apache.zeppelin.interpreter.mock.MockInterpreter1,org.apache.zeppelin.interpreter.mock.MockInterpreter2"); conf = new ZeppelinConfiguration(); depResolver = new DependencyResolver(tmpDir.getAbsolutePath() + "/local-repo"); - factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, depResolver); + factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, null, depResolver); context = new InterpreterContext("note", "id", "title", "text", null, null, null, null, null, null, null); - } @After public void tearDown() throws Exception { - delete(tmpDir); + FileUtils.deleteDirectory(tmpDir); } - private 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); - } + @Test + public void testBasic() { + List<InterpreterSetting> all = factory.get(); + InterpreterSetting mock1Setting = null; + for (InterpreterSetting setting : all) { + if (setting.getName().equals("mock1")) { + mock1Setting = setting; + break; } - file.delete(); } - } - @Test - public void testBasic() { - List<String> all = factory.getDefaultInterpreterSettingList(); - InterpreterSetting setting = factory.get(all.get(0)); - InterpreterGroup interpreterGroup = setting.getInterpreterGroup("sharedProcess"); - factory.createInterpretersForNote(setting, "sharedProcess", "session"); + InterpreterGroup interpreterGroup = mock1Setting.getInterpreterGroup("sharedProcess"); + factory.createInterpretersForNote(mock1Setting, "sharedProcess", "session"); // get interpreter assertNotNull("get Interpreter", interpreterGroup.get("session").get(0)); @@ -94,15 +88,15 @@ public class InterpreterFactoryTest { assertNull(factory.get("unknown")); // restart interpreter - factory.restart(all.get(0)); - assertNull(setting.getInterpreterGroup("sharedProcess").get("session")); + factory.restart(mock1Setting.id()); + assertNull(mock1Setting.getInterpreterGroup("sharedProcess").get("session")); } @Test public void testFactoryDefaultList() throws IOException, RepositoryException { // get default settings List<String> all = factory.getDefaultInterpreterSettingList(); - assertEquals(2, all.size()); + assertTrue(factory.getRegisteredInterpreterList().size() >= all.size()); } @Test @@ -125,15 +119,15 @@ public class InterpreterFactoryTest { @Test public void testSaveLoad() throws IOException, RepositoryException { // interpreter settings - assertEquals(2, factory.get().size()); + int numInterpreters = factory.get().size(); // check if file saved assertTrue(new File(conf.getInterpreterSettingPath()).exists()); factory.add("newsetting", "mock1", new LinkedList<Dependency>(), new InterpreterOption(false), new Properties()); - assertEquals(3, factory.get().size()); + assertEquals(numInterpreters + 1, factory.get().size()); InterpreterFactory factory2 = new InterpreterFactory(conf, null, null, null, depResolver); - assertEquals(3, factory2.get().size()); + assertEquals(numInterpreters + 1, factory2.get().size()); } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9463fb85/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/mock/MockInterpreter1.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/mock/MockInterpreter1.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/mock/MockInterpreter1.java index 794ab6c..d690b67 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/mock/MockInterpreter1.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/mock/MockInterpreter1.java @@ -1,19 +1,19 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You under the Apache License, Version 2.0 +* (the "License"); you may not use this file except in compliance with +* the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ package org.apache.zeppelin.interpreter.mock; @@ -30,7 +30,7 @@ import org.apache.zeppelin.scheduler.Scheduler; import org.apache.zeppelin.scheduler.SchedulerFactory; public class MockInterpreter1 extends Interpreter{ - Map<String, Object> vars = new HashMap<String, Object>(); +Map<String, Object> vars = new HashMap<String, Object>(); public MockInterpreter1(Properties property) { super(property); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9463fb85/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteInterpreterLoaderTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteInterpreterLoaderTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteInterpreterLoaderTest.java index 7d9071c..2450899 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteInterpreterLoaderTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteInterpreterLoaderTest.java @@ -60,7 +60,7 @@ public class NoteInterpreterLoaderTest { MockInterpreter2.register("mock2", "group2", "org.apache.zeppelin.interpreter.mock.MockInterpreter2"); depResolver = new DependencyResolver(tmpDir.getAbsolutePath() + "/local-repo"); - factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, depResolver); + factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, null, depResolver); } @After http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9463fb85/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteTest.java index 2ca817f..9a737e6 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteTest.java @@ -58,6 +58,9 @@ public class NoteTest { Scheduler scheduler; @Mock + NoteEventListener noteEventListener; + + @Mock InterpreterFactory interpreterFactory; @Test @@ -66,7 +69,8 @@ public class NoteTest { when(interpreter.getScheduler()).thenReturn(scheduler); String pText = "%spark sc.version"; - Note note = new Note(repo, interpreterFactory, jobListenerFactory, index, credentials); + Note note = new Note(repo, interpreterFactory, jobListenerFactory, index, credentials, noteEventListener); + Paragraph p = note.addParagraph(); p.setText(pText); note.run(p.getId()); @@ -85,7 +89,8 @@ public class NoteTest { when(interpreter.getScheduler()).thenReturn(scheduler); String pText = "%mysql show databases"; - Note note = new Note(repo, interpreterFactory, jobListenerFactory, index, credentials); + + Note note = new Note(repo, interpreterFactory, jobListenerFactory, index, credentials, noteEventListener); Paragraph p = note.addParagraph(); p.setText(pText); note.run(p.getId()); @@ -103,7 +108,7 @@ public class NoteTest { when(interpreterFactory.getDefaultInterpreterSetting(anyString())) .thenReturn(null); - Note note = new Note(repo, interpreterFactory, jobListenerFactory, index, credentials); + Note note = new Note(repo, interpreterFactory, jobListenerFactory, index, credentials, noteEventListener); note.putDefaultReplName(); assertEquals(StringUtils.EMPTY, note.getLastReplName()); @@ -117,7 +122,7 @@ public class NoteTest { when(interpreterFactory.getDefaultInterpreterSetting(anyString())) .thenReturn(interpreterSetting); - Note note = new Note(repo, interpreterFactory, jobListenerFactory, index, credentials); + Note note = new Note(repo, interpreterFactory, jobListenerFactory, index, credentials, noteEventListener); note.putDefaultReplName(); assertEquals("spark", note.getLastReplName()); @@ -131,7 +136,7 @@ public class NoteTest { when(interpreterFactory.getDefaultInterpreterSetting(anyString())) .thenReturn(interpreterSetting); - Note note = new Note(repo, interpreterFactory, jobListenerFactory, index, credentials); + Note note = new Note(repo, interpreterFactory, jobListenerFactory, index, credentials, noteEventListener); note.putDefaultReplName(); //set lastReplName Paragraph p = note.addParagraph(); @@ -146,7 +151,7 @@ public class NoteTest { when(interpreterFactory.getDefaultInterpreterSetting(anyString())) .thenReturn(interpreterSetting); - Note note = new Note(repo, interpreterFactory, jobListenerFactory, index, credentials); + Note note = new Note(repo, interpreterFactory, jobListenerFactory, index, credentials, noteEventListener); note.putDefaultReplName(); //set lastReplName Paragraph p = note.insertParagraph(note.getParagraphs().size()); @@ -157,7 +162,7 @@ public class NoteTest { @Test public void setLastReplName() { String paragraphId = "HelloWorld"; - Note note = Mockito.spy(new Note(repo, interpreterFactory, jobListenerFactory, index, credentials)); + Note note = Mockito.spy(new Note(repo, interpreterFactory, jobListenerFactory, index, credentials, noteEventListener)); Paragraph mockParagraph = Mockito.mock(Paragraph.class); when(note.getParagraph(paragraphId)).thenReturn(mockParagraph); when(mockParagraph.getRequiredReplName()).thenReturn("spark"); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9463fb85/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 13771b7..479f567 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 @@ -23,6 +23,7 @@ import static org.mockito.Mockito.mock; import java.io.File; import java.io.IOException; import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; import com.google.common.collect.Sets; import org.apache.commons.io.FileUtils; @@ -85,7 +86,7 @@ public class NotebookTest implements JobListenerFactory{ MockInterpreter2.register("mock2", "org.apache.zeppelin.interpreter.mock.MockInterpreter2"); depResolver = new DependencyResolver(tmpDir.getAbsolutePath() + "/local-repo"); - factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, depResolver); + factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, null, depResolver); SearchService search = mock(SearchService.class); notebookRepo = new VFSNotebookRepo(conf); @@ -700,6 +701,66 @@ public class NotebookTest implements JobListenerFactory{ } @Test + public void testNotebookEventListener() throws IOException { + final AtomicInteger onNoteRemove = new AtomicInteger(0); + final AtomicInteger onNoteCreate = new AtomicInteger(0); + final AtomicInteger onParagraphRemove = new AtomicInteger(0); + final AtomicInteger onParagraphCreate = new AtomicInteger(0); + final AtomicInteger unbindInterpreter = new AtomicInteger(0); + + notebook.addNotebookEventListener(new NotebookEventListener() { + @Override + public void onNoteRemove(Note note) { + onNoteRemove.incrementAndGet(); + } + + @Override + public void onNoteCreate(Note note) { + onNoteCreate.incrementAndGet(); + } + + @Override + public void onUnbindInterpreter(Note note, InterpreterSetting setting) { + unbindInterpreter.incrementAndGet(); + } + + @Override + public void onParagraphRemove(Paragraph p) { + onParagraphRemove.incrementAndGet(); + } + + @Override + public void onParagraphCreate(Paragraph p) { + onParagraphCreate.incrementAndGet(); + } + + @Override + public void onParagraphStatusChange(Paragraph p, Status status) { + } + }); + + Note note1 = notebook.createNote(null); + assertEquals(1, onNoteCreate.get()); + + Paragraph p1 = note1.addParagraph(); + assertEquals(1, onParagraphCreate.get()); + + note1.addCloneParagraph(p1); + assertEquals(2, onParagraphCreate.get()); + + note1.removeParagraph(p1.getId()); + assertEquals(1, onParagraphRemove.get()); + + List<String> settings = notebook.getBindedInterpreterSettingsIds(note1.id()); + notebook.bindInterpretersToNote(note1.id(), new LinkedList<String>()); + assertEquals(settings.size(), unbindInterpreter.get()); + + notebook.removeNote(note1.getId(), null); + assertEquals(1, onNoteRemove.get()); + assertEquals(1, onParagraphRemove.get()); + } + + @Test public void testNormalizeNoteName() throws IOException { // create a notes Note note1 = notebook.createNote(null); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9463fb85/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 index fe7e3fc..0c67d79 100644 --- 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 @@ -94,7 +94,7 @@ public class NotebookRepoSyncTest implements JobListenerFactory { MockInterpreter2.register("mock2", "org.apache.zeppelin.interpreter.mock.MockInterpreter2"); depResolver = new DependencyResolver(mainZepDir.getAbsolutePath() + "/local-repo"); - factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, depResolver); + factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, null, depResolver); search = mock(SearchService.class); notebookRepoSync = new NotebookRepoSync(conf); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9463fb85/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 index 9fb0360..7eaca8c 100644 --- 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 @@ -76,7 +76,7 @@ public class VFSNotebookRepoTest implements JobListenerFactory { this.schedulerFactory = new SchedulerFactory(); depResolver = new DependencyResolver(mainZepDir.getAbsolutePath() + "/local-repo"); - factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, depResolver); + factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, null, depResolver); SearchService search = mock(SearchService.class); notebookRepo = new VFSNotebookRepo(conf); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9463fb85/zeppelin-zengine/src/test/java/org/apache/zeppelin/search/LuceneSearchTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/search/LuceneSearchTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/search/LuceneSearchTest.java index b7fa2df..81c4b81 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/search/LuceneSearchTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/search/LuceneSearchTest.java @@ -284,7 +284,7 @@ public class LuceneSearchTest { } private Note newNote(String name) { - Note note = new Note(notebookRepoMock, interpreterFactory, null, notebookIndex, null); + Note note = new Note(notebookRepoMock, interpreterFactory, null, notebookIndex, null, null); note.setName(name); return note; }
