You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by jo...@apache.org on 2018/08/26 04:43:45 UTC
[02/49] zeppelin git commit: [ZEPPELIN-3740] Adopt
`google-java-format` and `fmt-maven-plugin`
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/FolderViewTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/FolderViewTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/FolderViewTest.java
index e127be8..5eecf80 100644
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/FolderViewTest.java
+++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/FolderViewTest.java
@@ -17,6 +17,11 @@
package org.apache.zeppelin.notebook;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.util.*;
import org.apache.zeppelin.interpreter.Interpreter;
import org.apache.zeppelin.interpreter.InterpreterFactory;
import org.apache.zeppelin.interpreter.InterpreterSettingManager;
@@ -30,40 +35,25 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
-import java.util.*;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
@RunWith(MockitoJUnitRunner.class)
public class FolderViewTest {
- @Mock
- NotebookRepo repo;
+ @Mock NotebookRepo repo;
- @Mock
- ParagraphJobListener paragraphJobListener;
+ @Mock ParagraphJobListener paragraphJobListener;
- @Mock
- SearchService index;
+ @Mock SearchService index;
- @Mock
- Credentials credentials;
+ @Mock Credentials credentials;
- @Mock
- Interpreter interpreter;
+ @Mock Interpreter interpreter;
- @Mock
- Scheduler scheduler;
+ @Mock Scheduler scheduler;
- @Mock
- NoteEventListener noteEventListener;
+ @Mock NoteEventListener noteEventListener;
- @Mock
- InterpreterFactory interpreterFactory;
+ @Mock InterpreterFactory interpreterFactory;
- @Mock
- InterpreterSettingManager interpreterSettingManager;
+ @Mock InterpreterSettingManager interpreterSettingManager;
FolderView folderView;
@@ -71,11 +61,11 @@ public class FolderViewTest {
Note note2;
Note note3;
- List<String> testNoteNames = Arrays.asList(
+ List<String> testNoteNames =
+ Arrays.asList(
"note1", "/note2",
"a/note1", "/a/note2",
- "a/b/note1", "/a/b/note2"
- );
+ "a/b/note1", "/a/b/note2");
Folder rootFolder;
Folder aFolder;
@@ -89,7 +79,17 @@ public class FolderViewTest {
Note abNote2;
private Note createNote() {
- Note note = new Note("test", "test", repo, interpreterFactory, interpreterSettingManager, paragraphJobListener, index, credentials, noteEventListener);
+ Note note =
+ new Note(
+ "test",
+ "test",
+ repo,
+ interpreterFactory,
+ interpreterSettingManager,
+ paragraphJobListener,
+ index,
+ credentials,
+ noteEventListener);
note.setNoteNameListener(folderView);
return note;
}
@@ -279,9 +279,7 @@ public class FolderViewTest {
assertEquals(sameName, aFolder.getId());
}
- /**
- * Should rename a empty folder
- */
+ /** Should rename a empty folder */
@Test
public void renameEmptyFolderTest() {
// Create a note of which name is "x/y/z" and rename "x" -> "u"
@@ -296,9 +294,7 @@ public class FolderViewTest {
assertNotNull(folderView.getFolder("u/y"));
}
- /**
- * Should also rename child folders of the target folder
- */
+ /** Should also rename child folders of the target folder */
@Test
public void renameFolderHasChildrenTest() {
// "a" -> "x"
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/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 d8e7f13..01e18e0 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
@@ -17,6 +17,9 @@
package org.apache.zeppelin.notebook;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
import com.google.common.collect.Lists;
import org.apache.zeppelin.display.AngularObject;
import org.apache.zeppelin.display.ui.TextBox;
@@ -36,47 +39,46 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
-
@RunWith(MockitoJUnitRunner.class)
public class NoteTest {
- @Mock
- NotebookRepo repo;
+ @Mock NotebookRepo repo;
- @Mock
- ParagraphJobListener paragraphJobListener;
+ @Mock ParagraphJobListener paragraphJobListener;
- @Mock
- SearchService index;
+ @Mock SearchService index;
- @Mock
- Credentials credentials;
+ @Mock Credentials credentials;
- @Mock
- Interpreter interpreter;
+ @Mock Interpreter interpreter;
- @Mock
- Scheduler scheduler;
+ @Mock Scheduler scheduler;
- @Mock
- NoteEventListener noteEventListener;
+ @Mock NoteEventListener noteEventListener;
- @Mock
- InterpreterFactory interpreterFactory;
+ @Mock InterpreterFactory interpreterFactory;
- @Mock
- InterpreterSettingManager interpreterSettingManager;
+ @Mock InterpreterSettingManager interpreterSettingManager;
private AuthenticationInfo anonymous = new AuthenticationInfo("anonymous");
@Test
public void runNormalTest() throws InterpreterNotFoundException {
- when(interpreterFactory.getInterpreter(anyString(), anyString(), eq("spark"), anyString())).thenReturn(interpreter);
+ when(interpreterFactory.getInterpreter(anyString(), anyString(), eq("spark"), anyString()))
+ .thenReturn(interpreter);
when(interpreter.getScheduler()).thenReturn(scheduler);
String pText = "%spark sc.version";
- Note note = new Note("test", "test", repo, interpreterFactory, interpreterSettingManager, paragraphJobListener, index, credentials, noteEventListener);
+ Note note =
+ new Note(
+ "test",
+ "test",
+ repo,
+ interpreterFactory,
+ interpreterSettingManager,
+ paragraphJobListener,
+ index,
+ credentials,
+ noteEventListener);
Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p.setText(pText);
@@ -85,14 +87,25 @@ public class NoteTest {
ArgumentCaptor<Paragraph> pCaptor = ArgumentCaptor.forClass(Paragraph.class);
verify(scheduler, only()).submit(pCaptor.capture());
- verify(interpreterFactory, times(1)).getInterpreter(anyString(), anyString(), eq("spark"), anyString());
+ verify(interpreterFactory, times(1))
+ .getInterpreter(anyString(), anyString(), eq("spark"), anyString());
assertEquals("Paragraph text", pText, pCaptor.getValue().getText());
}
@Test
public void addParagraphWithEmptyReplNameTest() {
- Note note = new Note("test", "", repo, interpreterFactory, interpreterSettingManager, paragraphJobListener, index, credentials, noteEventListener);
+ Note note =
+ new Note(
+ "test",
+ "",
+ repo,
+ interpreterFactory,
+ interpreterSettingManager,
+ paragraphJobListener,
+ index,
+ credentials,
+ noteEventListener);
Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
assertNull(p.getText());
@@ -100,9 +113,20 @@ public class NoteTest {
@Test
public void addParagraphWithLastReplNameTest() throws InterpreterNotFoundException {
- when(interpreterFactory.getInterpreter(anyString(), anyString(), eq("spark"), anyString())).thenReturn(interpreter);
-
- Note note = new Note("test", "", repo, interpreterFactory, interpreterSettingManager, paragraphJobListener, index, credentials, noteEventListener);
+ when(interpreterFactory.getInterpreter(anyString(), anyString(), eq("spark"), anyString()))
+ .thenReturn(interpreter);
+
+ Note note =
+ new Note(
+ "test",
+ "",
+ repo,
+ interpreterFactory,
+ interpreterSettingManager,
+ paragraphJobListener,
+ index,
+ credentials,
+ noteEventListener);
Paragraph p1 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p1.setText("%spark ");
Paragraph p2 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
@@ -112,43 +136,91 @@ public class NoteTest {
@Test
public void insertParagraphWithLastReplNameTest() throws InterpreterNotFoundException {
- when(interpreterFactory.getInterpreter(anyString(), anyString(), eq("spark"), anyString())).thenReturn(interpreter);
-
- Note note = new Note("test", "", repo, interpreterFactory, interpreterSettingManager, paragraphJobListener, index, credentials, noteEventListener);
+ when(interpreterFactory.getInterpreter(anyString(), anyString(), eq("spark"), anyString()))
+ .thenReturn(interpreter);
+
+ Note note =
+ new Note(
+ "test",
+ "",
+ repo,
+ interpreterFactory,
+ interpreterSettingManager,
+ paragraphJobListener,
+ index,
+ credentials,
+ noteEventListener);
Paragraph p1 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p1.setText("%spark ");
- Paragraph p2 = note.insertNewParagraph(note.getParagraphs().size(), AuthenticationInfo.ANONYMOUS);
+ Paragraph p2 =
+ note.insertNewParagraph(note.getParagraphs().size(), AuthenticationInfo.ANONYMOUS);
assertEquals("%spark\n", p2.getText());
}
@Test
public void insertParagraphWithInvalidReplNameTest() throws InterpreterNotFoundException {
- when(interpreterFactory.getInterpreter(anyString(), anyString(), eq("invalid"), anyString())).thenReturn(null);
-
- Note note = new Note("test", "", repo, interpreterFactory, interpreterSettingManager, paragraphJobListener, index, credentials, noteEventListener);
+ when(interpreterFactory.getInterpreter(anyString(), anyString(), eq("invalid"), anyString()))
+ .thenReturn(null);
+
+ Note note =
+ new Note(
+ "test",
+ "",
+ repo,
+ interpreterFactory,
+ interpreterSettingManager,
+ paragraphJobListener,
+ index,
+ credentials,
+ noteEventListener);
Paragraph p1 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p1.setText("%invalid ");
- Paragraph p2 = note.insertNewParagraph(note.getParagraphs().size(), AuthenticationInfo.ANONYMOUS);
+ Paragraph p2 =
+ note.insertNewParagraph(note.getParagraphs().size(), AuthenticationInfo.ANONYMOUS);
assertNull(p2.getText());
}
@Test
public void insertParagraphwithUser() {
- Note note = new Note("test", "", repo, interpreterFactory, interpreterSettingManager, paragraphJobListener, index, credentials, noteEventListener);
- Paragraph p = note.insertNewParagraph(note.getParagraphs().size(), AuthenticationInfo.ANONYMOUS);
+ Note note =
+ new Note(
+ "test",
+ "",
+ repo,
+ interpreterFactory,
+ interpreterSettingManager,
+ paragraphJobListener,
+ index,
+ credentials,
+ noteEventListener);
+ Paragraph p =
+ note.insertNewParagraph(note.getParagraphs().size(), AuthenticationInfo.ANONYMOUS);
assertEquals("anonymous", p.getUser());
}
@Test
public void clearAllParagraphOutputTest() throws InterpreterNotFoundException {
- when(interpreterFactory.getInterpreter(anyString(), anyString(), eq("md"), anyString())).thenReturn(interpreter);
+ when(interpreterFactory.getInterpreter(anyString(), anyString(), eq("md"), anyString()))
+ .thenReturn(interpreter);
when(interpreter.getScheduler()).thenReturn(scheduler);
- Note note = new Note("test", "", repo, interpreterFactory, interpreterSettingManager, paragraphJobListener, index, credentials, noteEventListener);
+ Note note =
+ new Note(
+ "test",
+ "",
+ repo,
+ interpreterFactory,
+ interpreterSettingManager,
+ paragraphJobListener,
+ index,
+ credentials,
+ noteEventListener);
Paragraph p1 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
- InterpreterResult result = new InterpreterResult(InterpreterResult.Code.SUCCESS, InterpreterResult.Type.TEXT, "result");
+ InterpreterResult result =
+ new InterpreterResult(
+ InterpreterResult.Code.SUCCESS, InterpreterResult.Type.TEXT, "result");
p1.setResult(result);
Paragraph p2 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
@@ -162,7 +234,17 @@ public class NoteTest {
@Test
public void getFolderIdTest() {
- Note note = new Note("test", "", repo, interpreterFactory, interpreterSettingManager, paragraphJobListener, index, credentials, noteEventListener);
+ Note note =
+ new Note(
+ "test",
+ "",
+ repo,
+ interpreterFactory,
+ interpreterSettingManager,
+ paragraphJobListener,
+ index,
+ credentials,
+ noteEventListener);
// Ordinary case test
note.setName("this/is/a/folder/noteName");
assertEquals("this/is/a/folder", note.getFolderId());
@@ -178,7 +260,17 @@ public class NoteTest {
@Test
public void getNameWithoutPathTest() {
- Note note = new Note("test", "", repo, interpreterFactory, interpreterSettingManager, paragraphJobListener, index, credentials, noteEventListener);
+ Note note =
+ new Note(
+ "test",
+ "",
+ repo,
+ interpreterFactory,
+ interpreterSettingManager,
+ paragraphJobListener,
+ index,
+ credentials,
+ noteEventListener);
// Notes in the root folder
note.setName("noteOnRootFolder");
assertEquals("noteOnRootFolder", note.getNameWithoutPath());
@@ -193,7 +285,17 @@ public class NoteTest {
@Test
public void isTrashTest() {
- Note note = new Note("test", "", repo, interpreterFactory, interpreterSettingManager, paragraphJobListener, index, credentials, noteEventListener);
+ Note note =
+ new Note(
+ "test",
+ "",
+ repo,
+ interpreterFactory,
+ interpreterSettingManager,
+ paragraphJobListener,
+ index,
+ credentials,
+ noteEventListener);
// Notes in the root folder
note.setName("noteOnRootFolder");
assertFalse(note.isTrash());
@@ -217,7 +319,17 @@ public class NoteTest {
@Test
public void personalizedModeReturnDifferentParagraphInstancePerUser() {
- Note note = new Note("test", "", repo, interpreterFactory, interpreterSettingManager, paragraphJobListener, index, credentials, noteEventListener);
+ Note note =
+ new Note(
+ "test",
+ "",
+ repo,
+ interpreterFactory,
+ interpreterSettingManager,
+ paragraphJobListener,
+ index,
+ credentials,
+ noteEventListener);
String user1 = "user1";
String user2 = "user2";
@@ -226,13 +338,26 @@ public class NoteTest {
Paragraph baseParagraph = note.getParagraphs().get(0);
Paragraph user1Paragraph = baseParagraph.getUserParagraph(user1);
Paragraph user2Paragraph = baseParagraph.getUserParagraph(user2);
- assertNotEquals(System.identityHashCode(baseParagraph), System.identityHashCode(user1Paragraph));
- assertNotEquals(System.identityHashCode(baseParagraph), System.identityHashCode(user2Paragraph));
- assertNotEquals(System.identityHashCode(user1Paragraph), System.identityHashCode(user2Paragraph));
+ assertNotEquals(
+ System.identityHashCode(baseParagraph), System.identityHashCode(user1Paragraph));
+ assertNotEquals(
+ System.identityHashCode(baseParagraph), System.identityHashCode(user2Paragraph));
+ assertNotEquals(
+ System.identityHashCode(user1Paragraph), System.identityHashCode(user2Paragraph));
}
public void testNoteJson() {
- Note note = new Note("test", "", repo, interpreterFactory, interpreterSettingManager, paragraphJobListener, index, credentials, noteEventListener);
+ Note note =
+ new Note(
+ "test",
+ "",
+ repo,
+ interpreterFactory,
+ interpreterSettingManager,
+ paragraphJobListener,
+ index,
+ credentials,
+ noteEventListener);
note.setName("/test_note");
note.getConfig().put("config_1", "value_1");
note.getInfo().put("info_1", "value_1");
@@ -242,7 +367,11 @@ public class NoteTest {
p.setResult(new InterpreterResult(InterpreterResult.Code.SUCCESS, "1.6.2"));
p.settings.getForms().put("textbox_1", new TextBox("name", "default_name"));
p.settings.getParams().put("textbox_1", "my_name");
- note.getAngularObjects().put("ao_1", Lists.newArrayList(new AngularObject("name_1", "value_1", note.getId(), p.getId(), null)));
+ note.getAngularObjects()
+ .put(
+ "ao_1",
+ Lists.newArrayList(
+ new AngularObject("name_1", "value_1", note.getId(), p.getId(), null)));
// test Paragraph Json
Paragraph p2 = Paragraph.fromJson(p.toJson());
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java
index ab39952..78c7b5d 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
@@ -17,7 +17,29 @@
package org.apache.zeppelin.notebook;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+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 static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+
import com.google.common.collect.Sets;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
import org.apache.zeppelin.conf.ZeppelinConfiguration;
import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars;
import org.apache.zeppelin.display.AngularObjectRegistry;
@@ -49,31 +71,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonatype.aether.RepositoryException;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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 static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-
-
public class NotebookTest extends AbstractInterpreterTest implements ParagraphJobListener {
private static final Logger logger = LoggerFactory.getLogger(NotebookTest.class);
@@ -98,8 +95,17 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
notebookAuthorization = NotebookAuthorization.init(conf);
credentials = new Credentials(conf.credentialsPersist(), conf.getCredentialsPath(), null);
- notebook = new Notebook(conf, notebookRepo, schedulerFactory, interpreterFactory, interpreterSettingManager, this, search,
- notebookAuthorization, credentials);
+ notebook =
+ new Notebook(
+ conf,
+ notebookRepo,
+ schedulerFactory,
+ interpreterFactory,
+ interpreterSettingManager,
+ this,
+ search,
+ notebookAuthorization,
+ credentials);
}
@After
@@ -113,25 +119,40 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
Notebook notebook;
notebookRepo = new DummyNotebookRepo();
- notebook = new Notebook(conf, notebookRepo, schedulerFactory, interpreterFactory,
- interpreterSettingManager, this, null,
- notebookAuthorization, credentials);
+ notebook =
+ new Notebook(
+ conf,
+ notebookRepo,
+ schedulerFactory,
+ interpreterFactory,
+ interpreterSettingManager,
+ this,
+ null,
+ notebookAuthorization,
+ credentials);
assertFalse("Revision is not supported in DummyNotebookRepo", notebook.isRevisionSupported());
notebookRepo = new DummyNotebookRepoWithVersionControl();
- notebook = new Notebook(conf, notebookRepo, schedulerFactory, interpreterFactory,
- interpreterSettingManager, this, null,
- notebookAuthorization, credentials);
- assertTrue("Revision is supported in DummyNotebookRepoWithVersionControl",
+ notebook =
+ new Notebook(
+ conf,
+ notebookRepo,
+ schedulerFactory,
+ interpreterFactory,
+ interpreterSettingManager,
+ this,
+ null,
+ notebookAuthorization,
+ credentials);
+ assertTrue(
+ "Revision is supported in DummyNotebookRepoWithVersionControl",
notebook.isRevisionSupported());
}
public static class DummyNotebookRepo implements NotebookRepo {
@Override
- public void init(ZeppelinConfiguration zConf) throws IOException {
-
- }
+ public void init(ZeppelinConfiguration zConf) throws IOException {}
@Override
public List<NoteInfo> list(AuthenticationInfo subject) throws IOException {
@@ -144,19 +165,13 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
}
@Override
- public void save(Note note, AuthenticationInfo subject) throws IOException {
-
- }
+ public void save(Note note, AuthenticationInfo subject) throws IOException {}
@Override
- public void remove(String noteId, AuthenticationInfo subject) throws IOException {
-
- }
+ public void remove(String noteId, AuthenticationInfo subject) throws IOException {}
@Override
- public void close() {
-
- }
+ public void close() {}
@Override
public List<NotebookRepoSettingsInfo> getSettings(AuthenticationInfo subject) {
@@ -164,13 +179,11 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
}
@Override
- public void updateSettings(Map<String, String> settings, AuthenticationInfo subject) {
-
- }
+ public void updateSettings(Map<String, String> settings, AuthenticationInfo subject) {}
}
- public static class DummyNotebookRepoWithVersionControl implements
- NotebookRepoWithVersionControl {
+ public static class DummyNotebookRepoWithVersionControl
+ implements NotebookRepoWithVersionControl {
@Override
public Revision checkpoint(String noteId, String checkpointMsg, AuthenticationInfo subject)
@@ -189,15 +202,13 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
}
@Override
- public Note setNoteRevision(String noteId, String revId, AuthenticationInfo subject) throws
- IOException {
+ public Note setNoteRevision(String noteId, String revId, AuthenticationInfo subject)
+ throws IOException {
return null;
}
@Override
- public void init(ZeppelinConfiguration zConf) throws IOException {
-
- }
+ public void init(ZeppelinConfiguration zConf) throws IOException {}
@Override
public List<NoteInfo> list(AuthenticationInfo subject) throws IOException {
@@ -210,19 +221,13 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
}
@Override
- public void save(Note note, AuthenticationInfo subject) throws IOException {
-
- }
+ public void save(Note note, AuthenticationInfo subject) throws IOException {}
@Override
- public void remove(String noteId, AuthenticationInfo subject) throws IOException {
-
- }
+ public void remove(String noteId, AuthenticationInfo subject) throws IOException {}
@Override
- public void close() {
-
- }
+ public void close() {}
@Override
public List<NotebookRepoSettingsInfo> getSettings(AuthenticationInfo subject) {
@@ -230,9 +235,7 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
}
@Override
- public void updateSettings(Map<String, String> settings, AuthenticationInfo subject) {
-
- }
+ public void updateSettings(Map<String, String> settings, AuthenticationInfo subject) {}
}
@Test
@@ -299,14 +302,14 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
// format has make some changes due to
// Notebook.convertFromSingleResultToMultipleResultsFormat
assertEquals(notes.get(1).getParagraphs().size(), copiedNote.getParagraphs().size());
- assertEquals(notes.get(1).getParagraphs().get(0).getText(),
- copiedNote.getParagraphs().get(0).getText());
- assertEquals(notes.get(1).getParagraphs().get(0).settings,
- copiedNote.getParagraphs().get(0).settings);
- assertEquals(notes.get(1).getParagraphs().get(0).getTitle(),
+ assertEquals(
+ notes.get(1).getParagraphs().get(0).getText(), copiedNote.getParagraphs().get(0).getText());
+ assertEquals(
+ notes.get(1).getParagraphs().get(0).settings, copiedNote.getParagraphs().get(0).settings);
+ assertEquals(
+ notes.get(1).getParagraphs().get(0).getTitle(),
copiedNote.getParagraphs().get(0).getTitle());
-
// delete notebook from notebook list when reloadAllNotes() is called
((InMemoryNotebookRepo) notebookRepo).reset();
notebook.reloadAllNotes(anonymous);
@@ -327,7 +330,9 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
p1.setText("hello world");
note.persist(anonymous);
} catch (IOException fe) {
- logger.warn("Failed to create note and paragraph. Possible problem with persisting note, safe to ignore", fe);
+ logger.warn(
+ "Failed to create note and paragraph. Possible problem with persisting note, safe to ignore",
+ fe);
}
try {
@@ -350,17 +355,25 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
p1.setText("hello world");
note.persist(anonymous);
- Notebook notebook2 = new Notebook(
- conf, notebookRepo, schedulerFactory,
- new InterpreterFactory(interpreterSettingManager),
- interpreterSettingManager, null, null, null, null);
+ Notebook notebook2 =
+ new Notebook(
+ conf,
+ notebookRepo,
+ schedulerFactory,
+ new InterpreterFactory(interpreterSettingManager),
+ interpreterSettingManager,
+ null,
+ null,
+ null,
+ null);
assertEquals(1, notebook2.getAllNotes().size());
notebook.removeNote(note.getId(), anonymous);
}
@Test
- public void testCreateNoteWithSubject() throws IOException, SchedulerException, RepositoryException {
+ public void testCreateNoteWithSubject()
+ throws IOException, SchedulerException, RepositoryException {
AuthenticationInfo subject = new AuthenticationInfo("user1");
Note note = notebook.createNote(subject);
@@ -471,12 +484,13 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
}
@Test
- public void testScheduleAgainstRunningAndPendingParagraph() throws InterruptedException, IOException {
+ public void testScheduleAgainstRunningAndPendingParagraph()
+ throws InterruptedException, IOException {
// create a note
Note note = notebook.createNote(anonymous);
// append running and pending paragraphs to the note
- for (Status status : new Status[]{Status.RUNNING, Status.PENDING}) {
+ for (Status status : new Status[] {Status.RUNNING, Status.PENDING}) {
Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
Map config = new HashMap<>();
p.setConfig(config);
@@ -516,14 +530,15 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
final Note note = notebook.createNote(anonymous);
executeNewParagraphByCron(note, everySecondCron);
- afterStatusChangedListener = new StatusChangedListener() {
- @Override
- public void onStatusChanged(Job job, Status before, Status after) {
- if (after == Status.FINISHED) {
- jobsToExecuteCount.countDown();
- }
- }
- };
+ afterStatusChangedListener =
+ new StatusChangedListener() {
+ @Override
+ public void onStatusChanged(Job job, Status before, Status after) {
+ if (after == Status.FINISHED) {
+ jobsToExecuteCount.countDown();
+ }
+ }
+ };
assertTrue(jobsToExecuteCount.await(timeout, TimeUnit.SECONDS));
@@ -552,16 +567,17 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
final Note note = notebook.createNote(anonymous);
executeNewParagraphByCron(note, everySecondCron);
- afterStatusChangedListener = new StatusChangedListener() {
- @Override
- public void onStatusChanged(Job job, Status before, Status after) {
- if (after == Status.FINISHED) {
- jobsToExecuteCount.countDown();
- }
- }
- };
-
- //This job should not run because "ZEPPELIN_NOTEBOOK_CRON_ENABLE" is set to false
+ afterStatusChangedListener =
+ new StatusChangedListener() {
+ @Override
+ public void onStatusChanged(Job job, Status before, Status after) {
+ if (after == Status.FINISHED) {
+ jobsToExecuteCount.countDown();
+ }
+ }
+ };
+
+ // This job should not run because "ZEPPELIN_NOTEBOOK_CRON_ENABLE" is set to false
assertFalse(jobsToExecuteCount.await(timeout, TimeUnit.SECONDS));
terminateScheduledNote(note);
@@ -582,16 +598,17 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
final Note note = notebook.createNote(anonymous);
executeNewParagraphByCron(note, everySecondCron);
- afterStatusChangedListener = new StatusChangedListener() {
- @Override
- public void onStatusChanged(Job job, Status before, Status after) {
- if (after == Status.FINISHED) {
- jobsToExecuteCount.countDown();
- }
- }
- };
-
- //This job should not run because it's name does not matches "ZEPPELIN_NOTEBOOK_CRON_FOLDERS"
+ afterStatusChangedListener =
+ new StatusChangedListener() {
+ @Override
+ public void onStatusChanged(Job job, Status before, Status after) {
+ if (after == Status.FINISHED) {
+ jobsToExecuteCount.countDown();
+ }
+ }
+ };
+
+ // This job should not run because it's name does not matches "ZEPPELIN_NOTEBOOK_CRON_FOLDERS"
assertFalse(jobsToExecuteCount.await(timeout, TimeUnit.SECONDS));
terminateScheduledNote(note);
@@ -602,16 +619,17 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
final CountDownLatch jobsToExecuteCountNameSystem = new CountDownLatch(5);
executeNewParagraphByCron(noteNameSystem, everySecondCron);
- afterStatusChangedListener = new StatusChangedListener() {
- @Override
- public void onStatusChanged(Job job, Status before, Status after) {
- if (after == Status.FINISHED) {
- jobsToExecuteCountNameSystem.countDown();
- }
- }
- };
-
- //This job should run because it's name contains "System/"
+ afterStatusChangedListener =
+ new StatusChangedListener() {
+ @Override
+ public void onStatusChanged(Job job, Status before, Status after) {
+ if (after == Status.FINISHED) {
+ jobsToExecuteCountNameSystem.countDown();
+ }
+ }
+ };
+
+ // This job should run because it's name contains "System/"
assertTrue(jobsToExecuteCountNameSystem.await(timeout, TimeUnit.SECONDS));
terminateScheduledNote(noteNameSystem);
@@ -627,9 +645,9 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
notebook.removeNote(note.getId(), anonymous);
}
-
// @Test
- public void testAutoRestartInterpreterAfterSchedule() throws InterruptedException, IOException, InterpreterNotFoundException {
+ public void testAutoRestartInterpreterAfterSchedule()
+ throws InterruptedException, IOException, InterpreterNotFoundException {
// create a note and a paragraph
Note note = notebook.createNote(anonymous);
@@ -650,10 +668,13 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
note.setConfig(config);
notebook.refreshCron(note.getId());
+ RemoteInterpreter mock1 =
+ (RemoteInterpreter)
+ interpreterFactory.getInterpreter(anonymous.getUser(), note.getId(), "mock1", "test");
- RemoteInterpreter mock1 = (RemoteInterpreter) interpreterFactory.getInterpreter(anonymous.getUser(), note.getId(), "mock1", "test");
-
- RemoteInterpreter mock2 = (RemoteInterpreter) interpreterFactory.getInterpreter(anonymous.getUser(), note.getId(), "mock2", "test");
+ RemoteInterpreter mock2 =
+ (RemoteInterpreter)
+ interpreterFactory.getInterpreter(anonymous.getUser(), note.getId(), "mock2", "test");
// wait until interpreters are started
while (!mock1.isOpened() || !mock2.isOpened()) {
@@ -681,40 +702,45 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
throws IOException, InterruptedException, InterpreterNotFoundException {
// create a cron scheduled note.
Note cronNote = notebook.createNote(anonymous);
- cronNote.setConfig(new HashMap() {
- {
- put("cron", "1/5 * * * * ?");
- put("cronExecutingUser", anonymous.getUser());
- put("releaseresource", true);
- }
- });
+ cronNote.setConfig(
+ new HashMap() {
+ {
+ put("cron", "1/5 * * * * ?");
+ put("cronExecutingUser", anonymous.getUser());
+ put("releaseresource", true);
+ }
+ });
RemoteInterpreter cronNoteInterpreter =
- (RemoteInterpreter) interpreterFactory.getInterpreter(anonymous.getUser(),
- cronNote.getId(), "mock1", "test");
+ (RemoteInterpreter)
+ interpreterFactory.getInterpreter(
+ anonymous.getUser(), cronNote.getId(), "mock1", "test");
// create a paragraph of the cron scheduled note.
Paragraph cronNoteParagraph = cronNote.addNewParagraph(AuthenticationInfo.ANONYMOUS);
- cronNoteParagraph.setConfig(new HashMap() {
- {
- put("enabled", true);
- }
- });
+ cronNoteParagraph.setConfig(
+ new HashMap() {
+ {
+ put("enabled", true);
+ }
+ });
cronNoteParagraph.setText("%mock1 sleep 1000");
// create another note
Note anotherNote = notebook.createNote(anonymous);
interpreterSettingManager.getByName("mock2").getOption().setPerNote("scoped");
RemoteInterpreter anotherNoteInterpreter =
- (RemoteInterpreter) interpreterFactory.getInterpreter(anonymous.getUser(),
- anotherNote.getId(), "mock2", "test");
+ (RemoteInterpreter)
+ interpreterFactory.getInterpreter(
+ anonymous.getUser(), anotherNote.getId(), "mock2", "test");
// create a paragraph of another note
Paragraph anotherNoteParagraph = anotherNote.addNewParagraph(AuthenticationInfo.ANONYMOUS);
- anotherNoteParagraph.setConfig(new HashMap() {
- {
- put("enabled", true);
- }
- });
+ anotherNoteParagraph.setConfig(
+ new HashMap() {
+ {
+ put("enabled", true);
+ }
+ });
anotherNoteParagraph.setText("%mock2 echo 1");
// run the paragraph of another note
@@ -744,13 +770,14 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
assertTrue(anotherNoteInterpreter.isOpened());
// remove cron scheduler
- cronNote.setConfig(new HashMap() {
- {
- put("cron", null);
- put("cronExecutingUser", null);
- put("releaseresource", null);
- }
- });
+ cronNote.setConfig(
+ new HashMap() {
+ {
+ put("cron", null);
+ put("cronExecutingUser", null);
+ put("releaseresource", null);
+ }
+ });
notebook.refreshCron(cronNote.getId());
// remove notebooks
@@ -759,8 +786,9 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
}
@Test
- public void testExportAndImportNote() throws IOException, CloneNotSupportedException,
- InterruptedException, InterpreterException, SchedulerException, RepositoryException {
+ public void testExportAndImportNote()
+ throws IOException, CloneNotSupportedException, InterruptedException, InterpreterException,
+ SchedulerException, RepositoryException {
Note note = notebook.createNote(anonymous);
final Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
@@ -778,7 +806,8 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
// Test
assertEquals(p.getId(), p2.getId());
assertEquals(p.getText(), p2.getText());
- assertEquals(p.getReturn().message().get(0).getData(), p2.getReturn().message().get(0).getData());
+ assertEquals(
+ p.getReturn().message().get(0).getData(), p2.getReturn().message().get(0).getData());
// Verify import note with subject
AuthenticationInfo subject = new AuthenticationInfo("user1");
@@ -794,8 +823,9 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
}
@Test
- public void testCloneNote() throws IOException, CloneNotSupportedException,
- InterruptedException, InterpreterException, SchedulerException, RepositoryException {
+ public void testCloneNote()
+ throws IOException, CloneNotSupportedException, InterruptedException, InterpreterException,
+ SchedulerException, RepositoryException {
Note note = notebook.createNote(anonymous);
final Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
@@ -810,7 +840,8 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
// Keep same ParagraphId
assertEquals(cp.getId(), p.getId());
assertEquals(cp.getText(), p.getText());
- assertEquals(cp.getReturn().message().get(0).getData(), p.getReturn().message().get(0).getData());
+ assertEquals(
+ cp.getReturn().message().get(0).getData(), p.getReturn().message().get(0).getData());
// Verify clone note with subject
AuthenticationInfo subject = new AuthenticationInfo("user1");
@@ -826,8 +857,8 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
}
@Test
- public void testCloneNoteWithNoName() throws IOException, CloneNotSupportedException,
- InterruptedException {
+ public void testCloneNoteWithNoName()
+ throws IOException, CloneNotSupportedException, InterruptedException {
Note note = notebook.createNote(anonymous);
Note cloneNote = notebook.cloneNote(note.getId(), null, anonymous);
@@ -835,7 +866,7 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
notebook.removeNote(note.getId(), anonymous);
notebook.removeNote(cloneNote.getId(), anonymous);
}
-
+
@Test
public void testResourceRemovealOnParagraphNoteRemove() throws IOException {
Note note = notebook.createNote(anonymous);
@@ -861,14 +892,16 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
}
@Test
- public void testAngularObjectRemovalOnNotebookRemove() throws InterruptedException,
- IOException {
+ public void testAngularObjectRemovalOnNotebookRemove() throws InterruptedException, IOException {
// create a note and a paragraph
Note note = notebook.createNote(anonymous);
- AngularObjectRegistry registry = interpreterSettingManager
- .getInterpreterSettings(note.getId()).get(0).getOrCreateInterpreterGroup(anonymous.getUser(), "sharedProcess")
- .getAngularObjectRegistry();
+ AngularObjectRegistry registry =
+ interpreterSettingManager
+ .getInterpreterSettings(note.getId())
+ .get(0)
+ .getOrCreateInterpreterGroup(anonymous.getUser(), "sharedProcess")
+ .getAngularObjectRegistry();
Paragraph p1 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
@@ -893,14 +926,16 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
}
@Test
- public void testAngularObjectRemovalOnParagraphRemove() throws InterruptedException,
- IOException {
+ public void testAngularObjectRemovalOnParagraphRemove() throws InterruptedException, IOException {
// create a note and a paragraph
Note note = notebook.createNote(anonymous);
- AngularObjectRegistry registry = interpreterSettingManager
- .getInterpreterSettings(note.getId()).get(0).getOrCreateInterpreterGroup(anonymous.getUser(), "sharedProcess")
- .getAngularObjectRegistry();
+ AngularObjectRegistry registry =
+ interpreterSettingManager
+ .getInterpreterSettings(note.getId())
+ .get(0)
+ .getOrCreateInterpreterGroup(anonymous.getUser(), "sharedProcess")
+ .getAngularObjectRegistry();
Paragraph p1 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
@@ -926,14 +961,17 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
}
@Test
- public void testAngularObjectRemovalOnInterpreterRestart() throws InterruptedException,
- IOException, InterpreterException {
+ public void testAngularObjectRemovalOnInterpreterRestart()
+ throws InterruptedException, IOException, InterpreterException {
// create a note and a paragraph
Note note = notebook.createNote(anonymous);
- AngularObjectRegistry registry = interpreterSettingManager
- .getInterpreterSettings(note.getId()).get(0).getOrCreateInterpreterGroup(anonymous.getUser(), "sharedProcess")
- .getAngularObjectRegistry();
+ AngularObjectRegistry registry =
+ interpreterSettingManager
+ .getInterpreterSettings(note.getId())
+ .get(0)
+ .getOrCreateInterpreterGroup(anonymous.getUser(), "sharedProcess")
+ .getAngularObjectRegistry();
// add local scope object
registry.add("o1", "object1", note.getId(), null);
@@ -941,10 +979,14 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
registry.add("o2", "object2", null, null);
// restart interpreter
- interpreterSettingManager.restart(interpreterSettingManager.getInterpreterSettings(note.getId()).get(0).getId());
- registry = interpreterSettingManager.getInterpreterSettings(note.getId()).get(0)
- .getOrCreateInterpreterGroup(anonymous.getUser(), "sharedProcess")
- .getAngularObjectRegistry();
+ interpreterSettingManager.restart(
+ interpreterSettingManager.getInterpreterSettings(note.getId()).get(0).getId());
+ registry =
+ interpreterSettingManager
+ .getInterpreterSettings(note.getId())
+ .get(0)
+ .getOrCreateInterpreterGroup(anonymous.getUser(), "sharedProcess")
+ .getAngularObjectRegistry();
// New InterpreterGroup will be created and its AngularObjectRegistry will be created
assertNull(registry.get("o1", note.getId(), null));
@@ -958,50 +1000,46 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
Note note = notebook.createNote(anonymous);
NotebookAuthorization notebookAuthorization = notebook.getNotebookAuthorization();
// empty owners, readers or writers means note is public
- assertEquals(notebookAuthorization.isOwner(note.getId(),
- new HashSet<>(Arrays.asList("user2"))), true);
- assertEquals(notebookAuthorization.isReader(note.getId(),
- new HashSet<>(Arrays.asList("user2"))), true);
- assertEquals(notebookAuthorization.isRunner(note.getId(),
- new HashSet<>(Arrays.asList("user2"))), true);
- assertEquals(notebookAuthorization.isWriter(note.getId(),
- new HashSet<>(Arrays.asList("user2"))), true);
-
- notebookAuthorization.setOwners(note.getId(),
- new HashSet<>(Arrays.asList("user1")));
- notebookAuthorization.setReaders(note.getId(),
- new HashSet<>(Arrays.asList("user1", "user2")));
- notebookAuthorization.setRunners(note.getId(),
- new HashSet<>(Arrays.asList("user3")));
- notebookAuthorization.setWriters(note.getId(),
- new HashSet<>(Arrays.asList("user1")));
-
- assertEquals(notebookAuthorization.isOwner(note.getId(),
- new HashSet<>(Arrays.asList("user2"))), false);
- assertEquals(notebookAuthorization.isOwner(note.getId(),
- new HashSet<>(Arrays.asList("user1"))), true);
-
- assertEquals(notebookAuthorization.isReader(note.getId(),
- new HashSet<>(Arrays.asList("user4"))), false);
- assertEquals(notebookAuthorization.isReader(note.getId(),
- new HashSet<>(Arrays.asList("user2"))), true);
-
- assertEquals(notebookAuthorization.isRunner(note.getId(),
- new HashSet<>(Arrays.asList("user3"))), true);
- assertEquals(notebookAuthorization.isRunner(note.getId(),
- new HashSet<>(Arrays.asList("user2"))), false);
-
- assertEquals(notebookAuthorization.isWriter(note.getId(),
- new HashSet<>(Arrays.asList("user2"))), false);
- assertEquals(notebookAuthorization.isWriter(note.getId(),
- new HashSet<>(Arrays.asList("user1"))), true);
+ assertEquals(
+ notebookAuthorization.isOwner(note.getId(), new HashSet<>(Arrays.asList("user2"))), true);
+ assertEquals(
+ notebookAuthorization.isReader(note.getId(), new HashSet<>(Arrays.asList("user2"))), true);
+ assertEquals(
+ notebookAuthorization.isRunner(note.getId(), new HashSet<>(Arrays.asList("user2"))), true);
+ assertEquals(
+ notebookAuthorization.isWriter(note.getId(), new HashSet<>(Arrays.asList("user2"))), true);
+
+ notebookAuthorization.setOwners(note.getId(), new HashSet<>(Arrays.asList("user1")));
+ notebookAuthorization.setReaders(note.getId(), new HashSet<>(Arrays.asList("user1", "user2")));
+ notebookAuthorization.setRunners(note.getId(), new HashSet<>(Arrays.asList("user3")));
+ notebookAuthorization.setWriters(note.getId(), new HashSet<>(Arrays.asList("user1")));
+
+ assertEquals(
+ notebookAuthorization.isOwner(note.getId(), new HashSet<>(Arrays.asList("user2"))), false);
+ assertEquals(
+ notebookAuthorization.isOwner(note.getId(), new HashSet<>(Arrays.asList("user1"))), true);
+
+ assertEquals(
+ notebookAuthorization.isReader(note.getId(), new HashSet<>(Arrays.asList("user4"))), false);
+ assertEquals(
+ notebookAuthorization.isReader(note.getId(), new HashSet<>(Arrays.asList("user2"))), true);
+
+ assertEquals(
+ notebookAuthorization.isRunner(note.getId(), new HashSet<>(Arrays.asList("user3"))), true);
+ assertEquals(
+ notebookAuthorization.isRunner(note.getId(), new HashSet<>(Arrays.asList("user2"))), false);
+
+ assertEquals(
+ notebookAuthorization.isWriter(note.getId(), new HashSet<>(Arrays.asList("user2"))), false);
+ assertEquals(
+ notebookAuthorization.isWriter(note.getId(), new HashSet<>(Arrays.asList("user1"))), true);
// Test clearing of permissions
notebookAuthorization.setReaders(note.getId(), Sets.<String>newHashSet());
- assertEquals(notebookAuthorization.isReader(note.getId(),
- new HashSet<>(Arrays.asList("user2"))), true);
- assertEquals(notebookAuthorization.isReader(note.getId(),
- new HashSet<>(Arrays.asList("user4"))), true);
+ assertEquals(
+ notebookAuthorization.isReader(note.getId(), new HashSet<>(Arrays.asList("user2"))), true);
+ assertEquals(
+ notebookAuthorization.isReader(note.getId(), new HashSet<>(Arrays.asList("user4"))), true);
notebook.removeNote(note.getId(), anonymous);
}
@@ -1018,24 +1056,16 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
Note note = notebook.createNote(new AuthenticationInfo(user1));
// check that user1 is owner, reader, runner and writer
- assertEquals(notebookAuthorization.isOwner(note.getId(),
- Sets.newHashSet(user1)), true);
- assertEquals(notebookAuthorization.isReader(note.getId(),
- Sets.newHashSet(user1)), true);
- assertEquals(notebookAuthorization.isRunner(note.getId(),
- Sets.newHashSet(user2)), true);
- assertEquals(notebookAuthorization.isWriter(note.getId(),
- Sets.newHashSet(user1)), true);
+ assertEquals(notebookAuthorization.isOwner(note.getId(), Sets.newHashSet(user1)), true);
+ assertEquals(notebookAuthorization.isReader(note.getId(), Sets.newHashSet(user1)), true);
+ assertEquals(notebookAuthorization.isRunner(note.getId(), Sets.newHashSet(user2)), true);
+ assertEquals(notebookAuthorization.isWriter(note.getId(), Sets.newHashSet(user1)), true);
// since user1 and user2 both have admin role, user2 will be reader and writer as well
- assertEquals(notebookAuthorization.isOwner(note.getId(),
- Sets.newHashSet(user2)), false);
- assertEquals(notebookAuthorization.isReader(note.getId(),
- Sets.newHashSet(user2)), true);
- assertEquals(notebookAuthorization.isRunner(note.getId(),
- Sets.newHashSet(user2)), true);
- assertEquals(notebookAuthorization.isWriter(note.getId(),
- Sets.newHashSet(user2)), true);
+ assertEquals(notebookAuthorization.isOwner(note.getId(), Sets.newHashSet(user2)), false);
+ assertEquals(notebookAuthorization.isReader(note.getId(), Sets.newHashSet(user2)), true);
+ assertEquals(notebookAuthorization.isRunner(note.getId(), Sets.newHashSet(user2)), true);
+ assertEquals(notebookAuthorization.isWriter(note.getId(), Sets.newHashSet(user2)), true);
// check that user1 has note listed in his workbench
Set<String> user1AndRoles = notebookAuthorization.getRoles(user1);
@@ -1053,8 +1083,8 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
}
@Test
- public void testAbortParagraphStatusOnInterpreterRestart() throws InterruptedException,
- IOException, InterpreterException {
+ public void testAbortParagraphStatusOnInterpreterRestart()
+ throws InterruptedException, IOException, InterpreterException {
Note note = notebook.createNote(anonymous);
// create three paragraphs
@@ -1065,7 +1095,6 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
Paragraph p3 = note.addNewParagraph(anonymous);
p3.setText("%mock1 sleep 1000");
-
note.runAll(AuthenticationInfo.ANONYMOUS, false);
// wait until first paragraph finishes and second paragraph starts
@@ -1076,7 +1105,8 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
assertEquals(Status.PENDING, p3.getStatus());
// restart interpreter
- interpreterSettingManager.restart(interpreterSettingManager.getInterpreterSettingByName("mock1").getId());
+ interpreterSettingManager.restart(
+ interpreterSettingManager.getInterpreterSettingByName("mock1").getId());
// make sure three different status aborted well.
assertEquals(Status.FINISHED, p1.getStatus());
@@ -1087,7 +1117,8 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
}
@Test
- public void testPerSessionInterpreterCloseOnNoteRemoval() throws IOException, InterpreterException {
+ public void testPerSessionInterpreterCloseOnNoteRemoval()
+ throws IOException, InterpreterException {
// create a notes
Note note1 = notebook.createNote(anonymous);
Paragraph p1 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);
@@ -1095,7 +1126,8 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
p1.setAuthenticationInfo(anonymous);
// restart interpreter with per user session enabled
- for (InterpreterSetting setting : interpreterSettingManager.getInterpreterSettings(note1.getId())) {
+ for (InterpreterSetting setting :
+ interpreterSettingManager.getInterpreterSettings(note1.getId())) {
setting.getOption().setPerNote(setting.getOption().SCOPED);
notebook.getInterpreterSettingManager().restart(setting.getId());
}
@@ -1139,11 +1171,12 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
while (p1.getStatus() != Status.FINISHED) Thread.yield();
while (p2.getStatus() != Status.FINISHED) Thread.yield();
- assertEquals(p1.getReturn().message().get(0).getData(), p2.getReturn().message().get(0).getData());
-
+ assertEquals(
+ p1.getReturn().message().get(0).getData(), p2.getReturn().message().get(0).getData());
// restart interpreter with per note session enabled
- for (InterpreterSetting setting : notebook.getInterpreterSettingManager().getInterpreterSettings(note1.getId())) {
+ for (InterpreterSetting setting :
+ notebook.getInterpreterSettingManager().getInterpreterSettings(note1.getId())) {
setting.getOption().setPerNote(InterpreterOption.SCOPED);
notebook.getInterpreterSettingManager().restart(setting.getId());
}
@@ -1161,7 +1194,6 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
notebook.removeNote(note2.getId(), anonymous);
}
-
@Test
public void testPerNoteSessionInterpreter() throws IOException, InterpreterException {
// create two notes
@@ -1183,10 +1215,12 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
while (p1.getStatus() != Status.FINISHED) Thread.yield();
while (p2.getStatus() != Status.FINISHED) Thread.yield();
- assertEquals(p1.getReturn().message().get(0).getData(), p2.getReturn().message().get(0).getData());
+ assertEquals(
+ p1.getReturn().message().get(0).getData(), p2.getReturn().message().get(0).getData());
// restart interpreter with scoped mode enabled
- for (InterpreterSetting setting : notebook.getInterpreterSettingManager().getInterpreterSettings(note1.getId())) {
+ for (InterpreterSetting setting :
+ notebook.getInterpreterSettingManager().getInterpreterSettings(note1.getId())) {
setting.getOption().setPerNote(InterpreterOption.SCOPED);
notebook.getInterpreterSettingManager().restart(setting.getId());
}
@@ -1198,10 +1232,12 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
while (p1.getStatus() != Status.FINISHED) Thread.yield();
while (p2.getStatus() != Status.FINISHED) Thread.yield();
- assertNotEquals(p1.getReturn().message().get(0).getData(), p2.getReturn().message().get(0).getData());
+ assertNotEquals(
+ p1.getReturn().message().get(0).getData(), p2.getReturn().message().get(0).getData());
// restart interpreter with isolated mode enabled
- for (InterpreterSetting setting : notebook.getInterpreterSettingManager().getInterpreterSettings(note1.getId())) {
+ for (InterpreterSetting setting :
+ notebook.getInterpreterSettingManager().getInterpreterSettings(note1.getId())) {
setting.getOption().setPerNote(InterpreterOption.ISOLATED);
setting.getInterpreterSettingManager().restart(setting.getId());
}
@@ -1213,7 +1249,8 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
while (p1.getStatus() != Status.FINISHED) Thread.yield();
while (p2.getStatus() != Status.FINISHED) Thread.yield();
- assertNotEquals(p1.getReturn().message().get(0).getData(), p2.getReturn().message().get(0).getData());
+ assertNotEquals(
+ p1.getReturn().message().get(0).getData(), p2.getReturn().message().get(0).getData());
notebook.removeNote(note1.getId(), anonymous);
notebook.removeNote(note2.getId(), anonymous);
@@ -1226,31 +1263,31 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
final AtomicInteger onParagraphRemove = new AtomicInteger(0);
final AtomicInteger onParagraphCreate = new AtomicInteger(0);
- notebook.addNotebookEventListener(new NotebookEventListener() {
- @Override
- public void onNoteRemove(Note note) {
- onNoteRemove.incrementAndGet();
- }
+ notebook.addNotebookEventListener(
+ new NotebookEventListener() {
+ @Override
+ public void onNoteRemove(Note note) {
+ onNoteRemove.incrementAndGet();
+ }
- @Override
- public void onNoteCreate(Note note) {
- onNoteCreate.incrementAndGet();
- }
+ @Override
+ public void onNoteCreate(Note note) {
+ onNoteCreate.incrementAndGet();
+ }
- @Override
- public void onParagraphRemove(Paragraph p) {
- onParagraphRemove.incrementAndGet();
- }
+ @Override
+ public void onParagraphRemove(Paragraph p) {
+ onParagraphRemove.incrementAndGet();
+ }
- @Override
- public void onParagraphCreate(Paragraph p) {
- onParagraphCreate.incrementAndGet();
- }
+ @Override
+ public void onParagraphCreate(Paragraph p) {
+ onParagraphCreate.incrementAndGet();
+ }
- @Override
- public void onParagraphStatusChange(Paragraph p, Status status) {
- }
- });
+ @Override
+ public void onParagraphStatusChange(Paragraph p, Status status) {}
+ });
Note note1 = notebook.createNote(anonymous);
assertEquals(1, onNoteCreate.get());
@@ -1319,7 +1356,6 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
notebook.removeNote(note2.getId(), anonymous);
}
-
@Test
public void testGetAllNotesWithDifferentPermissions() throws IOException {
HashSet<String> user1 = Sets.newHashSet("user1");
@@ -1329,7 +1365,7 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
assertEquals(notes1.size(), 0);
assertEquals(notes2.size(), 0);
- //creates note and sets user1 owner
+ // creates note and sets user1 owner
Note note = notebook.createNote(new AuthenticationInfo("user1"));
// note is public since readers and writers empty
@@ -1339,7 +1375,7 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
assertEquals(notes2.size(), 1);
notebook.getNotebookAuthorization().setReaders(note.getId(), Sets.newHashSet("user1"));
- //note is public since writers empty
+ // note is public since writers empty
notes1 = notebook.getAllNotes(user1);
notes2 = notebook.getAllNotes(user2);
assertEquals(notes1.size(), 1);
@@ -1418,28 +1454,28 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
assertEquals(notebookAuthorization.getRunners(notePrivate.getId()).size(), 1);
assertEquals(notebookAuthorization.getWriters(notePrivate.getId()).size(), 1);
- //set back public to true
+ // set back public to true
System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_PUBLIC.getVarName(), "true");
ZeppelinConfiguration.create();
}
-
+
@Test
public void testCloneImportCheck() throws IOException {
Note sourceNote = notebook.createNote(new AuthenticationInfo("user"));
sourceNote.setName("TestNote");
-
- assertEquals("TestNote",sourceNote.getName());
+
+ assertEquals("TestNote", sourceNote.getName());
Paragraph sourceParagraph = sourceNote.addNewParagraph(AuthenticationInfo.ANONYMOUS);
assertEquals("anonymous", sourceParagraph.getUser());
Note destNote = notebook.createNote(new AuthenticationInfo("user"));
destNote.setName("ClonedNote");
- assertEquals("ClonedNote",destNote.getName());
+ assertEquals("ClonedNote", destNote.getName());
List<Paragraph> paragraphs = sourceNote.getParagraphs();
for (Paragraph p : paragraphs) {
- destNote.addCloneParagraph(p, AuthenticationInfo.ANONYMOUS);
+ destNote.addCloneParagraph(p, AuthenticationInfo.ANONYMOUS);
assertEquals("anonymous", p.getUser());
}
}
@@ -1458,26 +1494,17 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
}
}
-
-
@Override
- public void onOutputAppend(Paragraph paragraph, int idx, String output) {
-
- }
+ public void onOutputAppend(Paragraph paragraph, int idx, String output) {}
@Override
- public void onOutputUpdate(Paragraph paragraph, int idx, InterpreterResultMessage msg) {
-
- }
+ public void onOutputUpdate(Paragraph paragraph, int idx, InterpreterResultMessage msg) {}
@Override
- public void onOutputUpdateAll(Paragraph paragraph, List<InterpreterResultMessage> msgs) {
-
- }
+ public void onOutputUpdateAll(Paragraph paragraph, List<InterpreterResultMessage> msgs) {}
@Override
- public void onProgressUpdate(Paragraph paragraph, int progress) {
- }
+ public void onProgressUpdate(Paragraph paragraph, int progress) {}
@Override
public void onStatusChange(Paragraph paragraph, Status before, Status after) {
@@ -1486,7 +1513,6 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
}
}
-
private interface StatusChangedListener {
void onStatusChanged(Job job, Status before, Status after);
}
@@ -1496,9 +1522,7 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
private Map<String, Note> notes = new HashMap<>();
@Override
- public void init(ZeppelinConfiguration zConf) throws IOException {
-
- }
+ public void init(ZeppelinConfiguration zConf) throws IOException {}
@Override
public List<NoteInfo> list(AuthenticationInfo subject) throws IOException {
@@ -1525,9 +1549,7 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
}
@Override
- public void close() {
-
- }
+ public void close() {}
@Override
public List<NotebookRepoSettingsInfo> getSettings(AuthenticationInfo subject) {
@@ -1535,9 +1557,7 @@ public class NotebookTest extends AbstractInterpreterTest implements ParagraphJo
}
@Override
- public void updateSettings(Map<String, String> settings, AuthenticationInfo subject) {
-
- }
+ public void updateSettings(Map<String, String> settings, AuthenticationInfo subject) {}
public void reset() {
this.notes.clear();
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java
index 609f16c..962c39c 100644
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java
+++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java
@@ -17,7 +17,6 @@
package org.apache.zeppelin.notebook;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
@@ -31,10 +30,10 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.google.common.collect.Lists;
-
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
-
+import java.util.Map;
import org.apache.commons.lang3.tuple.Triple;
import org.apache.zeppelin.display.AngularObject;
import org.apache.zeppelin.display.AngularObjectBuilder;
@@ -53,10 +52,6 @@ import org.apache.zeppelin.user.AuthenticationInfo;
import org.apache.zeppelin.user.Credentials;
import org.junit.Rule;
import org.junit.Test;
-
-import java.util.HashMap;
-import java.util.Map;
-
import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
@@ -128,8 +123,7 @@ public class ParagraphTest extends AbstractInterpreterTest {
assertEquals(0, paragraph.getLocalProperties().size());
}
- @Rule
- public ExpectedException expectedEx = ExpectedException.none();
+ @Rule public ExpectedException expectedEx = ExpectedException.none();
@Test
public void testInvalidProperties() {
@@ -201,7 +195,7 @@ public class ParagraphTest extends AbstractInterpreterTest {
@Test
public void should_extract_variable_from_angular_object_registry() throws Exception {
- //Given
+ // Given
final String noteId = "noteId";
final AngularObjectRegistry registry = mock(AngularObjectRegistry.class);
@@ -211,14 +205,15 @@ public class ParagraphTest extends AbstractInterpreterTest {
inputs.put("age", null);
inputs.put("job", null);
- final String scriptBody = "My name is ${name} and I am ${age=20} years old. " +
- "My occupation is ${ job = engineer | developer | artists}";
+ final String scriptBody =
+ "My name is ${name} and I am ${age=20} years old. "
+ + "My occupation is ${ job = engineer | developer | artists}";
final Paragraph paragraph = new Paragraph(note, null, null);
final String paragraphId = paragraph.getId();
- final AngularObject nameAO = AngularObjectBuilder.build("name", "DuyHai DOAN", noteId,
- paragraphId);
+ final AngularObject nameAO =
+ AngularObjectBuilder.build("name", "DuyHai DOAN", noteId, paragraphId);
final AngularObject ageAO = AngularObjectBuilder.build("age", 34, noteId, null);
@@ -226,13 +221,14 @@ public class ParagraphTest extends AbstractInterpreterTest {
when(registry.get("name", noteId, paragraphId)).thenReturn(nameAO);
when(registry.get("age", noteId, null)).thenReturn(ageAO);
- final String expected = "My name is DuyHai DOAN and I am 34 years old. " +
- "My occupation is ${ job = engineer | developer | artists}";
- //When
- final String actual = paragraph.extractVariablesFromAngularRegistry(scriptBody, inputs,
- registry);
+ final String expected =
+ "My name is DuyHai DOAN and I am 34 years old. "
+ + "My occupation is ${ job = engineer | developer | artists}";
+ // When
+ final String actual =
+ paragraph.extractVariablesFromAngularRegistry(scriptBody, inputs, registry);
- //Then
+ // Then
verify(registry).get("name", noteId, paragraphId);
verify(registry).get("age", noteId, null);
assertEquals(actual, expected);
@@ -252,7 +248,7 @@ public class ParagraphTest extends AbstractInterpreterTest {
public void returnUnchangedResultsWithDifferentUser() throws Throwable {
Note mockNote = mock(Note.class);
when(mockNote.getCredentials()).thenReturn(mock(Credentials.class));
- Paragraph spyParagraph = spy(new Paragraph("para_1", mockNote, null, null));
+ Paragraph spyParagraph = spy(new Paragraph("para_1", mockNote, null, null));
Interpreter mockInterpreter = mock(Interpreter.class);
spyParagraph.setInterpreter(mockInterpreter);
@@ -261,10 +257,12 @@ public class ParagraphTest extends AbstractInterpreterTest {
ManagedInterpreterGroup mockInterpreterGroup = mock(ManagedInterpreterGroup.class);
when(mockInterpreter.getInterpreterGroup()).thenReturn(mockInterpreterGroup);
when(mockInterpreterGroup.getId()).thenReturn("mock_id_1");
- when(mockInterpreterGroup.getAngularObjectRegistry()).thenReturn(mock(AngularObjectRegistry.class));
+ when(mockInterpreterGroup.getAngularObjectRegistry())
+ .thenReturn(mock(AngularObjectRegistry.class));
when(mockInterpreterGroup.getResourcePool()).thenReturn(mock(ResourcePool.class));
- List<InterpreterSetting> spyInterpreterSettingList = spy(Lists.<InterpreterSetting>newArrayList());
+ List<InterpreterSetting> spyInterpreterSettingList =
+ spy(Lists.<InterpreterSetting>newArrayList());
InterpreterSetting mockInterpreterSetting = mock(InterpreterSetting.class);
when(mockInterpreterGroup.getInterpreterSetting()).thenReturn(mockInterpreterSetting);
InterpreterOption mockInterpreterOption = mock(InterpreterOption.class);
@@ -272,7 +270,8 @@ public class ParagraphTest extends AbstractInterpreterTest {
when(mockInterpreterOption.permissionIsSet()).thenReturn(false);
when(mockInterpreterSetting.getStatus()).thenReturn(Status.READY);
when(mockInterpreterSetting.getId()).thenReturn("mock_id_1");
- when(mockInterpreterSetting.getOrCreateInterpreterGroup(anyString(), anyString())).thenReturn(mockInterpreterGroup);
+ when(mockInterpreterSetting.getOrCreateInterpreterGroup(anyString(), anyString()))
+ .thenReturn(mockInterpreterGroup);
when(mockInterpreterSetting.isUserAuthorized(any(List.class))).thenReturn(true);
spyInterpreterSettingList.add(mockInterpreterSetting);
when(mockNote.getId()).thenReturn("any_id");
@@ -281,10 +280,13 @@ public class ParagraphTest extends AbstractInterpreterTest {
ParagraphJobListener mockJobListener = mock(ParagraphJobListener.class);
doReturn(mockJobListener).when(spyParagraph).getListener();
- doNothing().when(mockJobListener).onOutputUpdateAll(Mockito.<Paragraph>any(), Mockito.anyList());
+ doNothing()
+ .when(mockJobListener)
+ .onOutputUpdateAll(Mockito.<Paragraph>any(), Mockito.anyList());
InterpreterResult mockInterpreterResult = mock(InterpreterResult.class);
- when(mockInterpreter.interpret(anyString(), Mockito.<InterpreterContext>any())).thenReturn(mockInterpreterResult);
+ when(mockInterpreter.interpret(anyString(), Mockito.<InterpreterContext>any()))
+ .thenReturn(mockInterpreterResult);
when(mockInterpreterResult.code()).thenReturn(Code.SUCCESS);
// Actual test
@@ -315,25 +317,25 @@ public class ParagraphTest extends AbstractInterpreterTest {
public void testCursorPosition() {
Paragraph paragraph = spy(new Paragraph());
// left = buffer, middle = cursor position into source code, right = cursor position after parse
- List<Triple<String, Integer, Integer>> dataSet = Arrays.asList(
- Triple.of("%jdbc schema.", 13, 7),
- Triple.of(" %jdbc schema.", 16, 7),
- Triple.of(" \n%jdbc schema.", 15, 7),
- Triple.of("%jdbc schema.table. ", 19, 13),
- Triple.of("%jdbc schema.\n\n", 13, 7),
- Triple.of(" %jdbc schema.tab\n\n", 18, 10),
- Triple.of(" \n%jdbc schema.\n \n", 16, 7),
- Triple.of(" \n%jdbc schema.\n \n", 16, 7),
- Triple.of(" \n%jdbc\n\n schema\n \n", 17, 6),
- Triple.of("%another\n\n schema.", 18, 7),
- Triple.of("\n\n schema.", 10, 7),
- Triple.of("schema.", 7, 7),
- Triple.of("schema. \n", 7, 7),
- Triple.of(" \n %jdbc", 11, 0),
- Triple.of("\n %jdbc", 9, 0),
- Triple.of("%jdbc \n schema", 16, 6),
- Triple.of("%jdbc \n \n schema", 20, 6)
- );
+ List<Triple<String, Integer, Integer>> dataSet =
+ Arrays.asList(
+ Triple.of("%jdbc schema.", 13, 7),
+ Triple.of(" %jdbc schema.", 16, 7),
+ Triple.of(" \n%jdbc schema.", 15, 7),
+ Triple.of("%jdbc schema.table. ", 19, 13),
+ Triple.of("%jdbc schema.\n\n", 13, 7),
+ Triple.of(" %jdbc schema.tab\n\n", 18, 10),
+ Triple.of(" \n%jdbc schema.\n \n", 16, 7),
+ Triple.of(" \n%jdbc schema.\n \n", 16, 7),
+ Triple.of(" \n%jdbc\n\n schema\n \n", 17, 6),
+ Triple.of("%another\n\n schema.", 18, 7),
+ Triple.of("\n\n schema.", 10, 7),
+ Triple.of("schema.", 7, 7),
+ Triple.of("schema. \n", 7, 7),
+ Triple.of(" \n %jdbc", 11, 0),
+ Triple.of("\n %jdbc", 9, 0),
+ Triple.of("%jdbc \n schema", 16, 6),
+ Triple.of("%jdbc \n \n schema", 20, 6));
for (Triple<String, Integer, Integer> data : dataSet) {
paragraph.setText(data.getLeft());
@@ -341,5 +343,4 @@ public class ParagraphTest extends AbstractInterpreterTest {
assertEquals(data.getRight(), actual);
}
}
-
}
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/zeppelin-zengine/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java
index 925515e..1b8c7a7 100644
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java
+++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java
@@ -16,6 +16,9 @@
*/
package org.apache.zeppelin.resource;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import com.google.gson.Gson;
import org.apache.zeppelin.interpreter.AbstractInterpreterTest;
import org.apache.zeppelin.interpreter.InterpreterContext;
@@ -27,30 +30,26 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Unittest for DistributedResourcePool
- */
+/** Unittest for DistributedResourcePool */
public class DistributedResourcePoolTest extends AbstractInterpreterTest {
private RemoteInterpreter intp1;
private RemoteInterpreter intp2;
private InterpreterContext context;
-
@Before
public void setUp() throws Exception {
super.setUp();
- InterpreterSetting interpreterSetting = interpreterSettingManager.getByName("mock_resource_pool");
- intp1 = (RemoteInterpreter) interpreterSetting.getInterpreter("user1", "note1", "mock_resource_pool");
- intp2 = (RemoteInterpreter) interpreterSetting.getInterpreter("user2", "note1", "mock_resource_pool");
+ InterpreterSetting interpreterSetting =
+ interpreterSettingManager.getByName("mock_resource_pool");
+ intp1 =
+ (RemoteInterpreter)
+ interpreterSetting.getInterpreter("user1", "note1", "mock_resource_pool");
+ intp2 =
+ (RemoteInterpreter)
+ interpreterSetting.getInterpreter("user2", "note1", "mock_resource_pool");
- context = InterpreterContext.builder()
- .setNoteId("note")
- .setParagraphId("id")
- .build();
+ context = InterpreterContext.builder().setNoteId("note").setParagraphId("id").build();
intp1.open();
intp2.open();
@@ -86,48 +85,55 @@ public class DistributedResourcePoolTest extends AbstractInterpreterTest {
final LocalResourcePool pool2 = new LocalResourcePool("pool2");
final LocalResourcePool pool3 = new LocalResourcePool("pool3");
- DistributedResourcePool pool1 = new DistributedResourcePool("pool1", new ResourcePoolConnector() {
- @Override
- public ResourceSet getAllResources() {
- ResourceSet set = pool2.getAll();
- set.addAll(pool3.getAll());
-
- ResourceSet remoteSet = new ResourceSet();
- Gson gson = new Gson();
- for (Resource s : set) {
- RemoteResource remoteResource = RemoteResource.fromJson(s.toJson());
- remoteResource.setResourcePoolConnector(this);
- remoteSet.add(remoteResource);
- }
- return remoteSet;
- }
-
- @Override
- public Object readResource(ResourceId id) {
- if (id.getResourcePoolId().equals(pool2.id())) {
- return pool2.get(id.getName()).get();
- }
- if (id.getResourcePoolId().equals(pool3.id())) {
- return pool3.get(id.getName()).get();
- }
- return null;
- }
-
- @Override
- public Object invokeMethod(ResourceId id, String methodName, Class[] paramTypes, Object[] params) {
- return null;
- }
-
- @Override
- public Resource invokeMethod(ResourceId id, String methodName, Class[] paramTypes, Object[]
- params, String returnResourceName) {
- return null;
- }
- });
+ DistributedResourcePool pool1 =
+ new DistributedResourcePool(
+ "pool1",
+ new ResourcePoolConnector() {
+ @Override
+ public ResourceSet getAllResources() {
+ ResourceSet set = pool2.getAll();
+ set.addAll(pool3.getAll());
+
+ ResourceSet remoteSet = new ResourceSet();
+ Gson gson = new Gson();
+ for (Resource s : set) {
+ RemoteResource remoteResource = RemoteResource.fromJson(s.toJson());
+ remoteResource.setResourcePoolConnector(this);
+ remoteSet.add(remoteResource);
+ }
+ return remoteSet;
+ }
+
+ @Override
+ public Object readResource(ResourceId id) {
+ if (id.getResourcePoolId().equals(pool2.id())) {
+ return pool2.get(id.getName()).get();
+ }
+ if (id.getResourcePoolId().equals(pool3.id())) {
+ return pool3.get(id.getName()).get();
+ }
+ return null;
+ }
+
+ @Override
+ public Object invokeMethod(
+ ResourceId id, String methodName, Class[] paramTypes, Object[] params) {
+ return null;
+ }
+
+ @Override
+ public Resource invokeMethod(
+ ResourceId id,
+ String methodName,
+ Class[] paramTypes,
+ Object[] params,
+ String returnResourceName) {
+ return null;
+ }
+ });
assertEquals(0, pool1.getAll().size());
-
// test get() can get from pool
pool2.put("object1", "value2");
assertEquals(1, pool1.getAll().size());
@@ -155,7 +161,6 @@ public class DistributedResourcePoolTest extends AbstractInterpreterTest {
intp2.interpret("put note2:paragraph1:key1 value1", context);
intp2.interpret("put note2:paragraph2:key2 value2", context);
-
// then get all resources.
assertEquals(4, interpreterSettingManager.getAllResources().size());
@@ -164,23 +169,27 @@ public class DistributedResourcePoolTest extends AbstractInterpreterTest {
// then resources should be removed.
assertEquals(2, interpreterSettingManager.getAllResources().size());
- assertEquals("", gson.fromJson(
- intp1.interpret("get note1:paragraph1:key1", context).message().get(0).getData(),
- String.class));
- assertEquals("", gson.fromJson(
- intp1.interpret("get note1:paragraph2:key1", context).message().get(0).getData(),
- String.class));
-
+ assertEquals(
+ "",
+ gson.fromJson(
+ intp1.interpret("get note1:paragraph1:key1", context).message().get(0).getData(),
+ String.class));
+ assertEquals(
+ "",
+ gson.fromJson(
+ intp1.interpret("get note1:paragraph2:key1", context).message().get(0).getData(),
+ String.class));
// when remove all resources from note2:paragraph1
interpreterSettingManager.removeResourcesBelongsToParagraph("note2", "paragraph1");
// then 1
assertEquals(1, interpreterSettingManager.getAllResources().size());
- assertEquals("value2", gson.fromJson(
- intp1.interpret("get note2:paragraph2:key2", context).message().get(0).getData(),
- String.class));
-
+ assertEquals(
+ "value2",
+ gson.fromJson(
+ intp1.interpret("get note2:paragraph2:key2", context).message().get(0).getData(),
+ String.class));
}
@Test