Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 27FEF200BB1 for ; Thu, 20 Oct 2016 08:23:17 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 26B04160AFD; Thu, 20 Oct 2016 06:23:17 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7CDC3160AEA for ; Thu, 20 Oct 2016 08:23:15 +0200 (CEST) Received: (qmail 27765 invoked by uid 500); 20 Oct 2016 06:23:14 -0000 Mailing-List: contact commits-help@zeppelin.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zeppelin.apache.org Delivered-To: mailing list commits@zeppelin.apache.org Received: (qmail 27755 invoked by uid 99); 20 Oct 2016 06:23:14 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Oct 2016 06:23:14 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 32DFBDFCF2; Thu, 20 Oct 2016 06:23:14 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jongyoul@apache.org To: commits@zeppelin.apache.org Date: Thu, 20 Oct 2016 06:23:14 -0000 Message-Id: <637665404aea49a69de1d6a9bc026b72@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/3] zeppelin git commit: [ZEPPELIN-1210] Run interpreter per user archived-at: Thu, 20 Oct 2016 06:23:17 -0000 Repository: zeppelin Updated Branches: refs/heads/master a3a2e4d34 -> 908b2a74f http://git-wip-us.apache.org/repos/asf/zeppelin/blob/908b2a74/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 86d6c06..d0af2c9 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 @@ -65,6 +65,7 @@ public class NotebookTest implements JobListenerFactory{ private DependencyResolver depResolver; private NotebookAuthorization notebookAuthorization; private Credentials credentials; + private AuthenticationInfo anonymous = new AuthenticationInfo("anonymous"); @Before public void setUp() throws Exception { @@ -88,7 +89,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, null, depResolver); + factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, null, depResolver, false); SearchService search = mock(SearchService.class); notebookRepo = new VFSNotebookRepo(conf); @@ -106,8 +107,8 @@ public class NotebookTest implements JobListenerFactory{ @Test public void testSelectingReplImplementation() throws IOException { - Note note = notebook.createNote(null); - factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList()); + Note note = notebook.createNote(anonymous); + factory.setInterpreters(anonymous.getUser(), note.getId(), factory.getDefaultInterpreterSettingList()); // run with default repl Paragraph p1 = note.addParagraph(); @@ -115,6 +116,7 @@ public class NotebookTest implements JobListenerFactory{ config.put("enabled", true); p1.setConfig(config); p1.setText("hello world"); + p1.setAuthenticationInfo(anonymous); note.run(p1.getId()); while(p1.isTerminated()==false || p1.getResult()==null) Thread.yield(); assertEquals("repl1: hello world", p1.getResult().message()); @@ -123,10 +125,11 @@ public class NotebookTest implements JobListenerFactory{ Paragraph p2 = note.addParagraph(); p2.setConfig(config); p2.setText("%mock2 hello world"); + p2.setAuthenticationInfo(anonymous); note.run(p2.getId()); while(p2.isTerminated()==false || p2.getResult()==null) Thread.yield(); assertEquals("repl2: hello world", p2.getResult().message()); - notebook.removeNote(note.getId(), null); + notebook.removeNote(note.getId(), anonymous); } @Test @@ -137,7 +140,7 @@ public class NotebookTest implements JobListenerFactory{ FileUtils.copyDirectory(srcDir, destDir); // when load - notebook.reloadAllNotes(null); + notebook.reloadAllNotes(anonymous); assertEquals(1, notebook.getAllNotes().size()); // then interpreter factory should be injected into all the paragraphs @@ -169,8 +172,8 @@ public class NotebookTest implements JobListenerFactory{ assertEquals(notes.size(), 0); // load copied notebook on memory when reloadAllNotes() is called - Note copiedNote = notebookRepo.get("2A94M5J1Z", null); - notebook.reloadAllNotes(null); + Note copiedNote = notebookRepo.get("2A94M5J1Z", anonymous); + notebook.reloadAllNotes(anonymous); notes = notebook.getAllNotes(); assertEquals(notes.size(), 2); assertEquals(notes.get(1).getId(), copiedNote.getId()); @@ -188,14 +191,14 @@ public class NotebookTest implements JobListenerFactory{ assertEquals(notes.size(), 2); // delete notebook from notebook list when reloadAllNotes() is called - notebook.reloadAllNotes(null); + notebook.reloadAllNotes(anonymous); notes = notebook.getAllNotes(); assertEquals(notes.size(), 0); } @Test public void testPersist() throws IOException, SchedulerException, RepositoryException { - Note note = notebook.createNote(null); + Note note = notebook.createNote(anonymous); // run with default repl Paragraph p1 = note.addParagraph(); @@ -203,14 +206,14 @@ public class NotebookTest implements JobListenerFactory{ config.put("enabled", true); p1.setConfig(config); p1.setText("hello world"); - note.persist(null); + note.persist(anonymous); Notebook notebook2 = new Notebook( conf, notebookRepo, schedulerFactory, - new InterpreterFactory(conf, null, null, null, depResolver), this, null, null, null); + new InterpreterFactory(conf, null, null, null, depResolver, false), this, null, null, null); assertEquals(1, notebook2.getAllNotes().size()); - notebook.removeNote(note.getId(), null); + notebook.removeNote(note.getId(), anonymous); } @Test @@ -223,17 +226,18 @@ public class NotebookTest implements JobListenerFactory{ Set owners = new HashSet<>(); owners.add("user1"); assertEquals(owners, notebook.getNotebookAuthorization().getOwners(note.getId())); - notebook.removeNote(note.getId(), null); + notebook.removeNote(note.getId(), anonymous); } @Test public void testClearParagraphOutput() throws IOException, SchedulerException{ - Note note = notebook.createNote(null); + Note note = notebook.createNote(anonymous); Paragraph p1 = note.addParagraph(); Map config = p1.getConfig(); config.put("enabled", true); p1.setConfig(config); p1.setText("hello world"); + p1.setAuthenticationInfo(anonymous); note.run(p1.getId()); while(p1.isTerminated() == false || p1.getResult() == null) Thread.yield(); @@ -242,13 +246,13 @@ public class NotebookTest implements JobListenerFactory{ // clear paragraph output/result note.clearParagraphOutput(p1.getId()); assertNull(p1.getResult()); - notebook.removeNote(note.getId(), null); + notebook.removeNote(note.getId(), anonymous); } @Test public void testRunAll() throws IOException { - Note note = notebook.createNote(null); - factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList()); + Note note = notebook.createNote(anonymous); + factory.setInterpreters("user", note.getId(), factory.getDefaultInterpreterSettingList()); // p1 Paragraph p1 = note.addParagraph(); @@ -280,14 +284,14 @@ public class NotebookTest implements JobListenerFactory{ assertNull(p2.getResult()); assertEquals("repl1: p3", p3.getResult().message()); - notebook.removeNote(note.getId(), null); + notebook.removeNote(note.getId(), anonymous); } @Test public void testSchedule() throws InterruptedException, IOException { // create a note and a paragraph - Note note = notebook.createNote(null); - factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList()); + Note note = notebook.createNote(anonymous); + factory.setInterpreters("user", note.getId(), factory.getDefaultInterpreterSettingList()); Paragraph p = note.addParagraph(); Map config = new HashMap(); @@ -313,14 +317,14 @@ public class NotebookTest implements JobListenerFactory{ assertNotNull(dateFinished); Thread.sleep(1 * 1000); assertEquals(dateFinished, p.getDateFinished()); - notebook.removeNote(note.getId(), null); + notebook.removeNote(note.getId(), anonymous); } @Test public void testAutoRestartInterpreterAfterSchedule() throws InterruptedException, IOException{ // create a note and a paragraph - Note note = notebook.createNote(null); - factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList()); + Note note = notebook.createNote(anonymous); + factory.setInterpreters(anonymous.getUser(), note.getId(), factory.getDefaultInterpreterSettingList()); Paragraph p = note.addParagraph(); Map config = new HashMap(); @@ -341,11 +345,11 @@ public class NotebookTest implements JobListenerFactory{ MockInterpreter1 mock1 = ((MockInterpreter1) (((ClassloaderInterpreter) - ((LazyOpenInterpreter) factory.getInterpreter(note.getId(), "mock1")).getInnerInterpreter()) + ((LazyOpenInterpreter) factory.getInterpreter(anonymous.getUser(), note.getId(), "mock1")).getInnerInterpreter()) .getInnerInterpreter())); MockInterpreter2 mock2 = ((MockInterpreter2) (((ClassloaderInterpreter) - ((LazyOpenInterpreter) factory.getInterpreter(note.getId(), "mock2")).getInnerInterpreter()) + ((LazyOpenInterpreter) factory.getInterpreter(anonymous.getUser(), note.getId(), "mock2")).getInnerInterpreter()) .getInnerInterpreter())); // wait until interpreters are started @@ -366,14 +370,14 @@ public class NotebookTest implements JobListenerFactory{ // make sure all paragraph has been executed assertNotNull(p.getDateFinished()); assertNotNull(p2.getDateFinished()); - notebook.removeNote(note.getId(), null); + notebook.removeNote(note.getId(), anonymous); } @Test public void testExportAndImportNote() throws IOException, CloneNotSupportedException, InterruptedException, InterpreterException, SchedulerException, RepositoryException { - Note note = notebook.createNote(null); - factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList()); + Note note = notebook.createNote(anonymous); + factory.setInterpreters("user", note.getId(), factory.getDefaultInterpreterSettingList()); final Paragraph p = note.addParagraph(); String simpleText = "hello world"; @@ -386,7 +390,7 @@ public class NotebookTest implements JobListenerFactory{ String exportedNoteJson = notebook.exportNote(note.getId()); - Note importedNote = notebook.importNote(exportedNoteJson, "Title", null); + Note importedNote = notebook.importNote(exportedNoteJson, "Title", anonymous); Paragraph p2 = importedNote.getParagraphs().get(0); @@ -403,16 +407,16 @@ public class NotebookTest implements JobListenerFactory{ Set owners = new HashSet<>(); owners.add("user1"); assertEquals(owners, notebook.getNotebookAuthorization().getOwners(importedNote2.getId())); - notebook.removeNote(note.getId(), null); - notebook.removeNote(importedNote.getId(), null); - notebook.removeNote(importedNote2.getId(), null); + notebook.removeNote(note.getId(), anonymous); + notebook.removeNote(importedNote.getId(), anonymous); + notebook.removeNote(importedNote2.getId(), anonymous); } @Test public void testCloneNote() throws IOException, CloneNotSupportedException, InterruptedException, InterpreterException, SchedulerException, RepositoryException { - Note note = notebook.createNote(null); - factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList()); + Note note = notebook.createNote(anonymous); + factory.setInterpreters("user", note.getId(), factory.getDefaultInterpreterSettingList()); final Paragraph p = note.addParagraph(); p.setText("hello world"); @@ -420,7 +424,7 @@ public class NotebookTest implements JobListenerFactory{ while(p.isTerminated()==false || p.getResult()==null) Thread.yield(); p.setStatus(Status.RUNNING); - Note cloneNote = notebook.cloneNote(note.getId(), "clone note", null); + Note cloneNote = notebook.cloneNote(note.getId(), "clone note", anonymous); Paragraph cp = cloneNote.paragraphs.get(0); assertEquals(cp.getStatus(), Status.READY); @@ -437,28 +441,28 @@ public class NotebookTest implements JobListenerFactory{ Set owners = new HashSet<>(); owners.add("user1"); assertEquals(owners, notebook.getNotebookAuthorization().getOwners(cloneNote2.getId())); - notebook.removeNote(note.getId(), null); - notebook.removeNote(cloneNote.getId(), null); - notebook.removeNote(cloneNote2.getId(), null); + notebook.removeNote(note.getId(), anonymous); + notebook.removeNote(cloneNote.getId(), anonymous); + notebook.removeNote(cloneNote2.getId(), anonymous); } @Test public void testCloneNoteWithNoName() throws IOException, CloneNotSupportedException, InterruptedException { - Note note = notebook.createNote(null); - factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList()); + Note note = notebook.createNote(anonymous); + factory.setInterpreters(anonymous.getUser(), note.getId(), factory.getDefaultInterpreterSettingList()); - Note cloneNote = notebook.cloneNote(note.getId(), null, null); + Note cloneNote = notebook.cloneNote(note.getId(), null, anonymous); assertEquals(cloneNote.getName(), "Note " + cloneNote.getId()); - notebook.removeNote(note.getId(), null); - notebook.removeNote(cloneNote.getId(), null); + notebook.removeNote(note.getId(), anonymous); + notebook.removeNote(cloneNote.getId(), anonymous); } @Test public void testCloneNoteWithExceptionResult() throws IOException, CloneNotSupportedException, InterruptedException { - Note note = notebook.createNote(null); - factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList()); + Note note = notebook.createNote(anonymous); + factory.setInterpreters(anonymous.getUser(), note.getId(), factory.getDefaultInterpreterSettingList()); final Paragraph p = note.addParagraph(); p.setText("hello world"); @@ -469,21 +473,21 @@ public class NotebookTest implements JobListenerFactory{ // Force paragraph to have String type object p.setResult("Exception"); - Note cloneNote = notebook.cloneNote(note.getId(), "clone note with Exception result", null); + Note cloneNote = notebook.cloneNote(note.getId(), "clone note with Exception result", anonymous); Paragraph cp = cloneNote.paragraphs.get(0); // Keep same ParagraphID assertEquals(cp.getId(), p.getId()); assertEquals(cp.text, p.text); assertNull(cp.getResult()); - notebook.removeNote(note.getId(), null); - notebook.removeNote(cloneNote.getId(), null); + notebook.removeNote(note.getId(), anonymous); + notebook.removeNote(cloneNote.getId(), anonymous); } @Test public void testResourceRemovealOnParagraphNoteRemove() throws IOException { - Note note = notebook.createNote(null); - factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList()); + Note note = notebook.createNote(anonymous); + factory.setInterpreters(anonymous.getUser(), note.getId(), factory.getDefaultInterpreterSettingList()); for (InterpreterGroup intpGroup : InterpreterGroup.getAll()) { intpGroup.setResourcePool(new LocalResourcePool(intpGroup.getId())); } @@ -499,11 +503,11 @@ public class NotebookTest implements JobListenerFactory{ assertEquals(2, ResourcePoolUtils.getAllResources().size()); // remove a paragraph - note.removeParagraph(p1.getId()); + note.removeParagraph(anonymous.getUser(), p1.getId()); assertEquals(1, ResourcePoolUtils.getAllResources().size()); // remove note - notebook.removeNote(note.getId(), null); + notebook.removeNote(note.getId(), anonymous); assertEquals(0, ResourcePoolUtils.getAllResources().size()); } @@ -511,11 +515,11 @@ public class NotebookTest implements JobListenerFactory{ public void testAngularObjectRemovalOnNotebookRemove() throws InterruptedException, IOException { // create a note and a paragraph - Note note = notebook.createNote(null); - factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList()); + Note note = notebook.createNote(anonymous); + factory.setInterpreters(anonymous.getUser(), note.getId(), factory.getDefaultInterpreterSettingList()); AngularObjectRegistry registry = factory - .getInterpreterSettings(note.getId()).get(0).getInterpreterGroup("sharedProcess") + .getInterpreterSettings(note.getId()).get(0).getInterpreterGroup(anonymous.getUser(), "sharedProcess") .getAngularObjectRegistry(); Paragraph p1 = note.addParagraph(); @@ -530,7 +534,7 @@ public class NotebookTest implements JobListenerFactory{ registry.add("o3", "object3", null, null); // remove notebook - notebook.removeNote(note.getId(), null); + notebook.removeNote(note.getId(), anonymous); // notebook scope or paragraph scope object should be removed assertNull(registry.get("o1", note.getId(), null)); @@ -544,11 +548,11 @@ public class NotebookTest implements JobListenerFactory{ public void testAngularObjectRemovalOnParagraphRemove() throws InterruptedException, IOException { // create a note and a paragraph - Note note = notebook.createNote(null); - factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList()); + Note note = notebook.createNote(anonymous); + factory.setInterpreters(anonymous.getUser(), note.getId(), factory.getDefaultInterpreterSettingList()); AngularObjectRegistry registry = factory - .getInterpreterSettings(note.getId()).get(0).getInterpreterGroup("sharedProcess") + .getInterpreterSettings(note.getId()).get(0).getInterpreterGroup(anonymous.getUser(), "sharedProcess") .getAngularObjectRegistry(); Paragraph p1 = note.addParagraph(); @@ -563,7 +567,7 @@ public class NotebookTest implements JobListenerFactory{ registry.add("o3", "object3", null, null); // remove notebook - note.removeParagraph(p1.getId()); + note.removeParagraph(anonymous.getUser(), p1.getId()); // paragraph scope should be removed assertNull(registry.get("o1", note.getId(), null)); @@ -571,18 +575,18 @@ public class NotebookTest implements JobListenerFactory{ // notebook scope and global object sould be remained assertNotNull(registry.get("o2", note.getId(), null)); assertNotNull(registry.get("o3", null, null)); - notebook.removeNote(note.getId(), null); + notebook.removeNote(note.getId(), anonymous); } @Test public void testAngularObjectRemovalOnInterpreterRestart() throws InterruptedException, IOException { // create a note and a paragraph - Note note = notebook.createNote(null); - factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList()); + Note note = notebook.createNote(anonymous); + factory.setInterpreters(anonymous.getUser(), note.getId(), factory.getDefaultInterpreterSettingList()); AngularObjectRegistry registry = factory - .getInterpreterSettings(note.getId()).get(0).getInterpreterGroup("sharedProcess") + .getInterpreterSettings(note.getId()).get(0).getInterpreterGroup(anonymous.getUser(), "sharedProcess") .getAngularObjectRegistry(); // add local scope object @@ -592,19 +596,19 @@ public class NotebookTest implements JobListenerFactory{ // restart interpreter factory.restart(factory.getInterpreterSettings(note.getId()).get(0).getId()); - registry = factory.getInterpreterSettings(note.getId()).get(0).getInterpreterGroup("sharedProcess") + registry = factory.getInterpreterSettings(note.getId()).get(0).getInterpreterGroup(anonymous.getUser(), "sharedProcess") .getAngularObjectRegistry(); // local and global scope object should be removed assertNull(registry.get("o1", note.getId(), null)); assertNull(registry.get("o2", null, null)); - notebook.removeNote(note.getId(), null); + notebook.removeNote(note.getId(), anonymous); } @Test public void testPermissions() throws IOException { // create a note and a paragraph - Note note = notebook.createNote(null); + Note note = notebook.createNote(anonymous); NotebookAuthorization notebookAuthorization = notebook.getNotebookAuthorization(); // empty owners, readers or writers means note is public assertEquals(notebookAuthorization.isOwner(note.getId(), @@ -643,14 +647,14 @@ public class NotebookTest implements JobListenerFactory{ assertEquals(notebookAuthorization.isReader(note.getId(), new HashSet(Arrays.asList("user3"))), true); - notebook.removeNote(note.getId(), null); + notebook.removeNote(note.getId(), anonymous); } @Test public void testAbortParagraphStatusOnInterpreterRestart() throws InterruptedException, IOException { - Note note = notebook.createNote(null); - factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList()); + Note note = notebook.createNote(anonymous); + factory.setInterpreters(anonymous.getUser(), note.getId(), factory.getDefaultInterpreterSettingList()); ArrayList paragraphs = new ArrayList<>(); for (int i = 0; i < 100; i++) { @@ -681,19 +685,20 @@ public class NotebookTest implements JobListenerFactory{ } assertTrue(isAborted); - notebook.removeNote(note.getId(), null); + notebook.removeNote(note.getId(), anonymous); } @Test public void testPerSessionInterpreterCloseOnNoteRemoval() throws IOException { // create a notes - Note note1 = notebook.createNote(null); + Note note1 = notebook.createNote(anonymous); Paragraph p1 = note1.addParagraph(); p1.setText("getId"); + p1.setAuthenticationInfo(anonymous); - // restart interpreter with per note session enabled + // restart interpreter with per user session enabled for (InterpreterSetting setting : factory.getInterpreterSettings(note1.getId())) { - setting.getOption().setPerNoteSession(true); + setting.getOption().setPerNote(setting.getOption().SCOPED); notebook.getInterpreterFactory().restart(setting.getId()); } @@ -702,29 +707,32 @@ public class NotebookTest implements JobListenerFactory{ InterpreterResult result = p1.getResult(); // remove note and recreate - notebook.removeNote(note1.getId(), null); - note1 = notebook.createNote(null); + notebook.removeNote(note1.getId(), anonymous); + note1 = notebook.createNote(anonymous); p1 = note1.addParagraph(); p1.setText("getId"); + p1.setAuthenticationInfo(anonymous); note1.run(p1.getId()); while (p1.getStatus() != Status.FINISHED) Thread.yield(); assertNotEquals(p1.getResult().message(), result.message()); - notebook.removeNote(note1.getId(), null); + notebook.removeNote(note1.getId(), anonymous); } @Test public void testPerSessionInterpreter() throws IOException { // create two notes - Note note1 = notebook.createNote(null); + Note note1 = notebook.createNote(anonymous); Paragraph p1 = note1.addParagraph(); - Note note2 = notebook.createNote(null); + Note note2 = notebook.createNote(anonymous); Paragraph p2 = note2.addParagraph(); p1.setText("getId"); + p1.setAuthenticationInfo(anonymous); p2.setText("getId"); + p2.setAuthenticationInfo(anonymous); // run per note session disabled note1.run(p1.getId()); @@ -738,7 +746,7 @@ public class NotebookTest implements JobListenerFactory{ // restart interpreter with per note session enabled for (InterpreterSetting setting : notebook.getInterpreterFactory().getInterpreterSettings(note1.getId())) { - setting.getOption().setPerNoteSession(true); + setting.getOption().setPerNote(InterpreterOption.SCOPED); notebook.getInterpreterFactory().restart(setting.getId()); } @@ -751,20 +759,21 @@ public class NotebookTest implements JobListenerFactory{ assertNotEquals(p1.getResult().message(), p2.getResult().message()); - notebook.removeNote(note1.getId(), null); - notebook.removeNote(note2.getId(), null); + notebook.removeNote(note1.getId(), anonymous); + notebook.removeNote(note2.getId(), anonymous); } @Test public void testPerSessionInterpreterCloseOnUnbindInterpreterSetting() throws IOException { // create a notes - Note note1 = notebook.createNote(null); + Note note1 = notebook.createNote(anonymous); Paragraph p1 = note1.addParagraph(); + p1.setAuthenticationInfo(anonymous); p1.setText("getId"); // restart interpreter with per note session enabled for (InterpreterSetting setting : factory.getInterpreterSettings(note1.getId())) { - setting.getOption().setPerNoteSession(true); + setting.getOption().setPerNote(InterpreterOption.SCOPED); notebook.getInterpreterFactory().restart(setting.getId()); } @@ -775,15 +784,15 @@ public class NotebookTest implements JobListenerFactory{ // unbind, and rebind setting. that result interpreter instance close List bindedSettings = notebook.getBindedInterpreterSettingsIds(note1.getId()); - notebook.bindInterpretersToNote(note1.getId(), new LinkedList()); - notebook.bindInterpretersToNote(note1.getId(), bindedSettings); + notebook.bindInterpretersToNote(anonymous.getUser(), note1.getId(), new LinkedList()); + notebook.bindInterpretersToNote(anonymous.getUser(), note1.getId(), bindedSettings); note1.run(p1.getId()); while (p1.getStatus() != Status.FINISHED) Thread.yield(); assertNotEquals(result.message(), p1.getResult().message()); - notebook.removeNote(note1.getId(), null); + notebook.removeNote(note1.getId(), anonymous); } @Test @@ -825,7 +834,7 @@ public class NotebookTest implements JobListenerFactory{ } }); - Note note1 = notebook.createNote(null); + Note note1 = notebook.createNote(anonymous); assertEquals(1, onNoteCreate.get()); Paragraph p1 = note1.addParagraph(); @@ -834,14 +843,14 @@ public class NotebookTest implements JobListenerFactory{ note1.addCloneParagraph(p1); assertEquals(2, onParagraphCreate.get()); - note1.removeParagraph(p1.getId()); + note1.removeParagraph(anonymous.getUser(), p1.getId()); assertEquals(1, onParagraphRemove.get()); List settings = notebook.getBindedInterpreterSettingsIds(note1.getId()); - notebook.bindInterpretersToNote(note1.getId(), new LinkedList()); + notebook.bindInterpretersToNote(anonymous.getUser(), note1.getId(), new LinkedList()); assertEquals(settings.size(), unbindInterpreter.get()); - notebook.removeNote(note1.getId(), null); + notebook.removeNote(note1.getId(), anonymous); assertEquals(1, onNoteRemove.get()); assertEquals(1, onParagraphRemove.get()); } @@ -849,7 +858,7 @@ public class NotebookTest implements JobListenerFactory{ @Test public void testNormalizeNoteName() throws IOException { // create a notes - Note note1 = notebook.createNote(null); + Note note1 = notebook.createNote(anonymous); note1.setName("MyNote"); assertEquals(note1.getName(), "MyNote"); @@ -869,29 +878,29 @@ public class NotebookTest implements JobListenerFactory{ note1.setName("\\\\\\MyNote///sub"); assertEquals(note1.getName(), "/MyNote/sub"); - notebook.removeNote(note1.getId(), null); + notebook.removeNote(note1.getId(), anonymous); } @Test public void testGetAllNotes() throws Exception { - Note note1 = notebook.createNote(null); - Note note2 = notebook.createNote(null); - assertEquals(2, notebook.getAllNotes(new AuthenticationInfo("anonymous")).size()); + Note note1 = notebook.createNote(anonymous); + Note note2 = notebook.createNote(anonymous); + assertEquals(2, notebook.getAllNotes(anonymous).size()); notebook.getNotebookAuthorization().setOwners(note1.getId(), Sets.newHashSet("user1")); notebook.getNotebookAuthorization().setWriters(note1.getId(), Sets.newHashSet("user1")); notebook.getNotebookAuthorization().setReaders(note1.getId(), Sets.newHashSet("user1")); - assertEquals(1, notebook.getAllNotes(new AuthenticationInfo("anonymous")).size()); + assertEquals(1, notebook.getAllNotes(anonymous).size()); assertEquals(2, notebook.getAllNotes(new AuthenticationInfo("user1")).size()); notebook.getNotebookAuthorization().setOwners(note2.getId(), Sets.newHashSet("user2")); notebook.getNotebookAuthorization().setWriters(note2.getId(), Sets.newHashSet("user2")); notebook.getNotebookAuthorization().setReaders(note2.getId(), Sets.newHashSet("user2")); - assertEquals(0, notebook.getAllNotes(new AuthenticationInfo("anonymous")).size()); + assertEquals(0, notebook.getAllNotes(anonymous).size()); assertEquals(1, notebook.getAllNotes(new AuthenticationInfo("user1")).size()); assertEquals(1, notebook.getAllNotes(new AuthenticationInfo("user2")).size()); - notebook.removeNote(note1.getId(), null); - notebook.removeNote(note2.getId(), null); + notebook.removeNote(note1.getId(), anonymous); + notebook.removeNote(note2.getId(), anonymous); } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/908b2a74/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 5a3915c..43ed586 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 @@ -42,6 +42,7 @@ import org.apache.zeppelin.scheduler.JobListener; import org.apache.zeppelin.scheduler.SchedulerFactory; import org.apache.zeppelin.search.SearchService; import org.apache.zeppelin.search.LuceneSearch; +import org.apache.zeppelin.user.AuthenticationInfo; import org.apache.zeppelin.user.Credentials; import org.junit.After; import org.junit.Before; @@ -65,6 +66,7 @@ public class NotebookRepoSyncTest implements JobListenerFactory { private SearchService search; private NotebookAuthorization notebookAuthorization; private Credentials credentials; + private AuthenticationInfo anonymous; private static final Logger LOG = LoggerFactory.getLogger(NotebookRepoSyncTest.class); @Before @@ -95,7 +97,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, null, depResolver); + factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, null, depResolver, false); search = mock(SearchService.class); notebookRepoSync = new NotebookRepoSync(conf); @@ -103,6 +105,7 @@ public class NotebookRepoSyncTest implements JobListenerFactory { credentials = new Credentials(conf.credentialsPersist(), conf.getCredentialsPath()); notebookSync = new Notebook(conf, notebookRepoSync, schedulerFactory, factory, this, search, notebookAuthorization, credentials); + anonymous = new AuthenticationInfo("anonymous"); } @After @@ -119,40 +122,40 @@ public class NotebookRepoSyncTest implements JobListenerFactory { public void testSyncOnCreate() throws IOException { /* check that both storage systems are empty */ assertTrue(notebookRepoSync.getRepoCount() > 1); - assertEquals(0, notebookRepoSync.list(0, null).size()); - assertEquals(0, notebookRepoSync.list(1, null).size()); + assertEquals(0, notebookRepoSync.list(0, anonymous).size()); + assertEquals(0, notebookRepoSync.list(1, anonymous).size()); /* create note */ - Note note = notebookSync.createNote(null); + Note note = notebookSync.createNote(anonymous); // check that automatically saved on both storages - assertEquals(1, notebookRepoSync.list(0, null).size()); - assertEquals(1, notebookRepoSync.list(1, null).size()); - assertEquals(notebookRepoSync.list(0, null).get(0).getId(),notebookRepoSync.list(1, null).get(0).getId()); - - notebookSync.removeNote(notebookRepoSync.list(0, null).get(0).getId(), null); + 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, null).size()); - assertEquals(0, notebookRepoSync.list(1, null).size()); + assertEquals(0, notebookRepoSync.list(0, anonymous).size()); + assertEquals(0, notebookRepoSync.list(1, anonymous).size()); - Note note = notebookSync.createNote(null); + Note note = notebookSync.createNote(anonymous); /* check that created in both storage systems */ - assertEquals(1, notebookRepoSync.list(0, null).size()); - assertEquals(1, notebookRepoSync.list(1, null).size()); - assertEquals(notebookRepoSync.list(0, null).get(0).getId(),notebookRepoSync.list(1, null).get(0).getId()); + 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, null).get(0).getId(), null); + notebookSync.removeNote(notebookRepoSync.list(0, anonymous).get(0).getId(), anonymous); /* check that deleted in both storages */ - assertEquals(0, notebookRepoSync.list(0, null).size()); - assertEquals(0, notebookRepoSync.list(1, null).size()); + assertEquals(0, notebookRepoSync.list(0, anonymous).size()); + assertEquals(0, notebookRepoSync.list(1, anonymous).size()); } @@ -160,7 +163,7 @@ public class NotebookRepoSyncTest implements JobListenerFactory { public void testSyncUpdateMain() throws IOException { /* create note */ - Note note = notebookSync.createNote(null); + Note note = notebookSync.createNote(anonymous); Paragraph p1 = note.addParagraph(); Map config = p1.getConfig(); config.put("enabled", true); @@ -172,38 +175,38 @@ public class NotebookRepoSyncTest implements JobListenerFactory { /* new paragraph not yet saved into storages */ assertEquals(0, notebookRepoSync.get(0, - notebookRepoSync.list(0, null).get(0).getId(), null).getParagraphs().size()); + notebookRepoSync.list(0, anonymous).get(0).getId(), anonymous).getParagraphs().size()); assertEquals(0, notebookRepoSync.get(1, - notebookRepoSync.list(1, null).get(0).getId(), null).getParagraphs().size()); + notebookRepoSync.list(1, anonymous).get(0).getId(), anonymous).getParagraphs().size()); /* save to storage under index 0 (first storage) */ - notebookRepoSync.save(0, note, null); + notebookRepoSync.save(0, note, anonymous); /* check paragraph saved to first storage */ assertEquals(1, notebookRepoSync.get(0, - notebookRepoSync.list(0, null).get(0).getId(), null).getParagraphs().size()); + 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, null).get(0).getId(), null).getParagraphs().size()); + 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, null).get(0).getId(), null).getParagraphs().size()); + notebookRepoSync.list(1, anonymous).get(0).getId(), anonymous).getParagraphs().size()); /* check whether same paragraph id */ assertEquals(p1.getId(), notebookRepoSync.get(0, - notebookRepoSync.list(0, null).get(0).getId(), null).getLastParagraph().getId()); + notebookRepoSync.list(0, anonymous).get(0).getId(), anonymous).getLastParagraph().getId()); assertEquals(p1.getId(), notebookRepoSync.get(1, - notebookRepoSync.list(1, null).get(0).getId(), null).getLastParagraph().getId()); - notebookRepoSync.remove(note.getId(), null); + 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, null).size()); - assertEquals(0, notebookRepoSync.list(1, null).size()); + 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"); @@ -214,13 +217,13 @@ public class NotebookRepoSyncTest implements JobListenerFactory { } catch (IOException e) { LOG.error(e.toString(), e); } - assertEquals(0, notebookRepoSync.list(0, null).size()); - assertEquals(1, notebookRepoSync.list(1, null).size()); + assertEquals(0, notebookRepoSync.list(0, anonymous).size()); + assertEquals(1, notebookRepoSync.list(1, anonymous).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()); + notebookSync.reloadAllNotes(anonymous); + assertEquals(1, notebookRepoSync.list(0, anonymous).size()); + assertEquals(1, notebookRepoSync.list(1, anonymous).size()); } @Test @@ -287,15 +290,15 @@ public class NotebookRepoSyncTest implements JobListenerFactory { GitNotebookRepo gitRepo = (GitNotebookRepo) vRepoSync.getRepo(0); // no notes - assertThat(vRepoSync.list(null).size()).isEqualTo(0); + assertThat(vRepoSync.list(anonymous).size()).isEqualTo(0); // create note - Note note = vNotebookSync.createNote(null); - assertThat(vRepoSync.list(null).size()).isEqualTo(1); + Note note = vNotebookSync.createNote(anonymous); + assertThat(vRepoSync.list(anonymous).size()).isEqualTo(1); - String noteId = vRepoSync.list(null).get(0).getId(); + String noteId = vRepoSync.list(anonymous).get(0).getId(); // first checkpoint - vRepoSync.checkpoint(noteId, "checkpoint message", null); - int vCount = gitRepo.revisionHistory(noteId, null).size(); + vRepoSync.checkpoint(noteId, "checkpoint message", anonymous); + int vCount = gitRepo.revisionHistory(noteId, anonymous).size(); assertThat(vCount).isEqualTo(1); Paragraph p = note.addParagraph(); @@ -305,10 +308,10 @@ public class NotebookRepoSyncTest implements JobListenerFactory { p.setText("%md checkpoint test"); // save and checkpoint again - vRepoSync.save(note, null); - vRepoSync.checkpoint(noteId, "checkpoint message 2", null); - assertThat(gitRepo.revisionHistory(noteId, null).size()).isEqualTo(vCount + 1); - notebookRepoSync.remove(note.getId(), null); + 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); } static void delete(File file){ http://git-wip-us.apache.org/repos/asf/zeppelin/blob/908b2a74/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 9fc2d82..e6236c8 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 @@ -32,10 +32,12 @@ import org.apache.zeppelin.interpreter.InterpreterFactory; import org.apache.zeppelin.interpreter.InterpreterOption; import org.apache.zeppelin.interpreter.mock.MockInterpreter1; import org.apache.zeppelin.notebook.*; +import org.apache.zeppelin.notebook.repo.zeppelinhub.security.Authentication; import org.apache.zeppelin.scheduler.JobListener; import org.apache.zeppelin.scheduler.SchedulerFactory; import org.apache.zeppelin.search.SearchService; import org.apache.zeppelin.search.LuceneSearch; +import org.apache.zeppelin.user.AuthenticationInfo; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -76,7 +78,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, null, depResolver); + factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null, null, depResolver, false); SearchService search = mock(SearchService.class); notebookRepo = new VFSNotebookRepo(conf); @@ -106,14 +108,16 @@ public class VFSNotebookRepoTest implements JobListenerFactory { @Test public void testSaveNotebook() throws IOException, InterruptedException { - Note note = notebook.createNote(null); - factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList()); + AuthenticationInfo anonymous = new AuthenticationInfo("anonymous"); + Note note = notebook.createNote(anonymous); + factory.setInterpreters("user", note.getId(), factory.getDefaultInterpreterSettingList()); Paragraph p1 = note.addParagraph(); Map 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; http://git-wip-us.apache.org/repos/asf/zeppelin/blob/908b2a74/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 81c4b81..bf4d9aa 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 @@ -29,6 +29,7 @@ import org.apache.zeppelin.interpreter.InterpreterFactory; import org.apache.zeppelin.notebook.Note; import org.apache.zeppelin.notebook.Paragraph; import org.apache.zeppelin.notebook.repo.NotebookRepo; +import org.apache.zeppelin.user.AuthenticationInfo; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; @@ -41,6 +42,7 @@ public class LuceneSearchTest { private static NotebookRepo notebookRepoMock; private static InterpreterFactory interpreterFactory; private SearchService notebookIndex; + private AuthenticationInfo anonymous; @BeforeClass public static void beforeStartUp() { @@ -54,6 +56,7 @@ public class LuceneSearchTest { @Before public void startUp() { notebookIndex = new LuceneSearch(); + anonymous = new AuthenticationInfo("anonymous"); } @After @@ -202,7 +205,7 @@ public class LuceneSearchTest { //when Paragraph p1 = note1.getLastParagraph(); p1.setText("no no no"); - note1.persist(null); + note1.persist(anonymous); //then assertThat(resultForQuery("Notebook1").size()).isEqualTo(1); @@ -226,7 +229,7 @@ public class LuceneSearchTest { //when note1.setName("NotebookN"); - note1.persist(null); + note1.persist(anonymous); //then assertThat(resultForQuery("Notebook1")).isEmpty();