mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
Fixed some tests
This commit is contained in:
parent
47cc668ff9
commit
7b7eb7864c
5 changed files with 117 additions and 70 deletions
|
|
@ -30,7 +30,9 @@ import org.apache.zeppelin.notebook.Note;
|
|||
import org.apache.zeppelin.notebook.Paragraph;
|
||||
import org.apache.zeppelin.scheduler.Job.Status;
|
||||
import org.apache.zeppelin.server.ZeppelinServer;
|
||||
import org.apache.zeppelin.user.AuthenticationInfo;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
|
|
@ -47,6 +49,7 @@ import static org.junit.Assert.*;
|
|||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class InterpreterRestApiTest extends AbstractTestRestApi {
|
||||
Gson gson = new Gson();
|
||||
AuthenticationInfo anonymous;
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws Exception {
|
||||
|
|
@ -58,6 +61,11 @@ public class InterpreterRestApiTest extends AbstractTestRestApi {
|
|||
AbstractTestRestApi.shutDown();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
anonymous = new AuthenticationInfo("anonymous");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailableInterpreters() throws IOException {
|
||||
// when
|
||||
|
|
@ -131,7 +139,7 @@ public class InterpreterRestApiTest extends AbstractTestRestApi {
|
|||
@Test
|
||||
public void testInterpreterAutoBinding() throws IOException {
|
||||
// create note
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
|
||||
// check interpreter is binded
|
||||
GetMethod get = httpGet("/notebook/interpreter/bind/" + note.getId());
|
||||
|
|
@ -144,13 +152,13 @@ public class InterpreterRestApiTest extends AbstractTestRestApi {
|
|||
|
||||
get.releaseConnection();
|
||||
//cleanup
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInterpreterRestart() throws IOException, InterruptedException {
|
||||
// create new note
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
note.addParagraph();
|
||||
Paragraph p = note.getLastParagraph();
|
||||
Map config = p.getConfig();
|
||||
|
|
@ -159,6 +167,7 @@ public class InterpreterRestApiTest extends AbstractTestRestApi {
|
|||
// run markdown paragraph
|
||||
p.setConfig(config);
|
||||
p.setText("%md markdown");
|
||||
p.setAuthenticationInfo(anonymous);
|
||||
note.run(p.getId());
|
||||
while (p.getStatus() != Status.FINISHED) {
|
||||
Thread.sleep(100);
|
||||
|
|
@ -181,13 +190,14 @@ public class InterpreterRestApiTest extends AbstractTestRestApi {
|
|||
p = note.addParagraph();
|
||||
p.setConfig(config);
|
||||
p.setText("%md markdown restarted");
|
||||
p.setAuthenticationInfo(anonymous);
|
||||
note.run(p.getId());
|
||||
while (p.getStatus() != Status.FINISHED) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
assertEquals("<p>markdown restarted</p>\n", p.getResult().message());
|
||||
//cleanup
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -28,7 +28,9 @@ import org.apache.zeppelin.notebook.Note;
|
|||
import org.apache.zeppelin.notebook.NotebookAuthorization;
|
||||
import org.apache.zeppelin.notebook.NotebookAuthorizationInfoSaving;
|
||||
import org.apache.zeppelin.server.ZeppelinServer;
|
||||
import org.apache.zeppelin.user.AuthenticationInfo;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
|
|
@ -49,6 +51,7 @@ import static org.junit.Assert.assertThat;
|
|||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class NotebookRestApiTest extends AbstractTestRestApi {
|
||||
Gson gson = new Gson();
|
||||
AuthenticationInfo anonymous;
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws Exception {
|
||||
|
|
@ -60,9 +63,14 @@ public class NotebookRestApiTest extends AbstractTestRestApi {
|
|||
AbstractTestRestApi.shutDown();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
anonymous = new AuthenticationInfo("anonymous");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPermissions() throws IOException {
|
||||
Note note1 = ZeppelinServer.notebook.createNote(null);
|
||||
Note note1 = ZeppelinServer.notebook.createNote(anonymous);
|
||||
// Set only readers
|
||||
String jsonRequest = "{\"readers\":[\"admin-team\"],\"owners\":[]," +
|
||||
"\"writers\":[]}";
|
||||
|
|
@ -85,7 +93,7 @@ public class NotebookRestApiTest extends AbstractTestRestApi {
|
|||
get.releaseConnection();
|
||||
|
||||
|
||||
Note note2 = ZeppelinServer.notebook.createNote(null);
|
||||
Note note2 = ZeppelinServer.notebook.createNote(anonymous);
|
||||
// Set only writers
|
||||
jsonRequest = "{\"readers\":[],\"owners\":[]," +
|
||||
"\"writers\":[\"admin-team\"]}";
|
||||
|
|
@ -119,8 +127,8 @@ public class NotebookRestApiTest extends AbstractTestRestApi {
|
|||
assertEquals(authInfo.get("owners"), Lists.newArrayList());
|
||||
get.releaseConnection();
|
||||
//cleanup
|
||||
ZeppelinServer.notebook.removeNote(note1.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note2.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note1.getId(), anonymous);
|
||||
ZeppelinServer.notebook.removeNote(note2.getId(), anonymous);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import org.apache.zeppelin.scheduler.Job.Status;
|
|||
import org.apache.zeppelin.server.ZeppelinServer;
|
||||
import org.apache.zeppelin.user.AuthenticationInfo;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
|
|
@ -51,6 +52,7 @@ import static org.junit.Assert.*;
|
|||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
||||
Gson gson = new Gson();
|
||||
AuthenticationInfo anonymous;
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws Exception {
|
||||
|
|
@ -62,6 +64,11 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
AbstractTestRestApi.shutDown();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
anonymous = new AuthenticationInfo("anonymous");
|
||||
}
|
||||
|
||||
/***
|
||||
* ROOT API TEST
|
||||
***/
|
||||
|
|
@ -78,7 +85,7 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
public void testGetNotebookInfo() throws IOException {
|
||||
LOG.info("testGetNotebookInfo");
|
||||
// Create note to get info
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
assertNotNull("can't create new note", note);
|
||||
note.setName("note");
|
||||
Paragraph paragraph = note.addParagraph();
|
||||
|
|
@ -87,7 +94,7 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
paragraph.setConfig(config);
|
||||
String paragraphText = "%md This is my new paragraph in my new note";
|
||||
paragraph.setText(paragraphText);
|
||||
note.persist(null);
|
||||
note.persist(anonymous);
|
||||
|
||||
String sourceNoteID = note.getId();
|
||||
GetMethod get = httpGet("/notebook/" + sourceNoteID);
|
||||
|
|
@ -156,7 +163,7 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
assertTrue("paragraph text check failed", p.getText().startsWith("text"));
|
||||
}
|
||||
// cleanup
|
||||
ZeppelinServer.notebook.removeNote(newNotebookId, null);
|
||||
ZeppelinServer.notebook.removeNote(newNotebookId, anonymous);
|
||||
post.releaseConnection();
|
||||
}
|
||||
|
||||
|
|
@ -183,7 +190,7 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
}
|
||||
assertEquals("compare note name", expectedNoteName, newNoteName);
|
||||
// cleanup
|
||||
ZeppelinServer.notebook.removeNote(newNotebookId, null);
|
||||
ZeppelinServer.notebook.removeNote(newNotebookId, anonymous);
|
||||
post.releaseConnection();
|
||||
|
||||
}
|
||||
|
|
@ -192,7 +199,7 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
public void testDeleteNote() throws IOException {
|
||||
LOG.info("testDeleteNote");
|
||||
//Create note and get ID
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
String noteId = note.getId();
|
||||
testDeleteNotebook(noteId);
|
||||
}
|
||||
|
|
@ -208,7 +215,7 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
@Test
|
||||
public void testExportNotebook() throws IOException {
|
||||
LOG.info("testExportNotebook");
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
assertNotNull("can't create new note", note);
|
||||
note.setName("source note for export");
|
||||
Paragraph paragraph = note.addParagraph();
|
||||
|
|
@ -216,7 +223,7 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
config.put("enabled", true);
|
||||
paragraph.setConfig(config);
|
||||
paragraph.setText("%md This is my new paragraph in my new note");
|
||||
note.persist(null);
|
||||
note.persist(anonymous);
|
||||
String sourceNoteID = note.getId();
|
||||
// Call export Notebook REST API
|
||||
GetMethod get = httpGet("/notebook/export/" + sourceNoteID);
|
||||
|
|
@ -230,7 +237,7 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
String exportJSON = (String) resp.get("body");
|
||||
assertNotNull("Can not find new notejson", exportJSON);
|
||||
LOG.info("export JSON:=" + exportJSON);
|
||||
ZeppelinServer.notebook.removeNote(sourceNoteID, null);
|
||||
ZeppelinServer.notebook.removeNote(sourceNoteID, anonymous);
|
||||
get.releaseConnection();
|
||||
|
||||
}
|
||||
|
|
@ -241,7 +248,7 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
String noteName = "source note for import";
|
||||
LOG.info("testImortNotebook");
|
||||
// create test notebook
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
assertNotNull("can't create new note", note);
|
||||
note.setName(noteName);
|
||||
Paragraph paragraph = note.addParagraph();
|
||||
|
|
@ -249,7 +256,7 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
config.put("enabled", true);
|
||||
paragraph.setConfig(config);
|
||||
paragraph.setText("%md This is my new paragraph in my new note");
|
||||
note.persist(null);
|
||||
note.persist(anonymous);
|
||||
String sourceNoteID = note.getId();
|
||||
// get note content as JSON
|
||||
String oldJson = getNoteContent(sourceNoteID);
|
||||
|
|
@ -267,8 +274,8 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
assertEquals("Compare paragraphs count", note.getParagraphs().size(), newNote.getParagraphs()
|
||||
.size());
|
||||
// cleanup
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(newNote.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
|
||||
ZeppelinServer.notebook.removeNote(newNote.getId(), anonymous);
|
||||
importPost.releaseConnection();
|
||||
}
|
||||
|
||||
|
|
@ -303,7 +310,7 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
public void testCloneNotebook() throws IOException, CloneNotSupportedException, IllegalArgumentException {
|
||||
LOG.info("testCloneNotebook");
|
||||
// Create note to clone
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
assertNotNull("can't create new note", note);
|
||||
note.setName("source note for clone");
|
||||
Paragraph paragraph = note.addParagraph();
|
||||
|
|
@ -311,7 +318,7 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
config.put("enabled", true);
|
||||
paragraph.setConfig(config);
|
||||
paragraph.setText("%md This is my new paragraph in my new note");
|
||||
note.persist(null);
|
||||
note.persist(anonymous);
|
||||
String sourceNoteID = note.getId();
|
||||
|
||||
String noteName = "clone Note Name";
|
||||
|
|
@ -331,8 +338,8 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
assertEquals("Compare note names", noteName, newNote.getName());
|
||||
assertEquals("Compare paragraphs count", note.getParagraphs().size(), newNote.getParagraphs().size());
|
||||
//cleanup
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(newNote.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
|
||||
ZeppelinServer.notebook.removeNote(newNote.getId(), anonymous);
|
||||
post.releaseConnection();
|
||||
}
|
||||
|
||||
|
|
@ -354,7 +361,7 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
public void testNoteJobs() throws IOException, InterruptedException {
|
||||
LOG.info("testNoteJobs");
|
||||
// Create note to run test.
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
assertNotNull("can't create new note", note);
|
||||
note.setName("note for run test");
|
||||
Paragraph paragraph = note.addParagraph();
|
||||
|
|
@ -364,7 +371,7 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
paragraph.setConfig(config);
|
||||
|
||||
paragraph.setText("%md This is test paragraph.");
|
||||
note.persist(null);
|
||||
note.persist(anonymous);
|
||||
String noteID = note.getId();
|
||||
|
||||
note.runAll();
|
||||
|
|
@ -402,14 +409,14 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
Thread.sleep(1000);
|
||||
|
||||
//cleanup
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNotebookJob() throws IOException, InterruptedException {
|
||||
LOG.info("testGetNotebookJob");
|
||||
// Create note to run test.
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
assertNotNull("can't create new note", note);
|
||||
note.setName("note for run test");
|
||||
Paragraph paragraph = note.addParagraph();
|
||||
|
|
@ -419,7 +426,7 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
paragraph.setConfig(config);
|
||||
|
||||
paragraph.setText("%sh sleep 1");
|
||||
note.persist(null);
|
||||
note.persist(anonymous);
|
||||
String noteID = note.getId();
|
||||
|
||||
note.runAll();
|
||||
|
|
@ -455,14 +462,14 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
}
|
||||
}
|
||||
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRunParagraphWithParams() throws IOException, InterruptedException {
|
||||
LOG.info("testRunParagraphWithParams");
|
||||
// Create note to run test.
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
assertNotNull("can't create new note", note);
|
||||
note.setName("note for run test");
|
||||
Paragraph paragraph = note.addParagraph();
|
||||
|
|
@ -472,7 +479,7 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
paragraph.setConfig(config);
|
||||
|
||||
paragraph.setText("%spark\nval param = z.input(\"param\").toString\nprintln(param)");
|
||||
note.persist(null);
|
||||
note.persist(anonymous);
|
||||
String noteID = note.getId();
|
||||
|
||||
note.runAll();
|
||||
|
|
@ -500,13 +507,13 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
assertEquals("world", params.get("param2"));
|
||||
|
||||
//cleanup
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCronJobs() throws InterruptedException, IOException{
|
||||
// create a note and a paragraph
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
|
||||
note.setName("note for run test");
|
||||
Paragraph paragraph = note.addParagraph();
|
||||
|
|
@ -550,18 +557,18 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
DeleteMethod deleteCron = httpDelete("/notebook/cron/" + note.getId());
|
||||
assertThat("", deleteCron, isAllowed());
|
||||
deleteCron.releaseConnection();
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegressionZEPPELIN_527() throws IOException {
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
|
||||
note.setName("note for run test");
|
||||
Paragraph paragraph = note.addParagraph();
|
||||
paragraph.setText("%spark\nval param = z.input(\"param\").toString\nprintln(param)");
|
||||
|
||||
note.persist(null);
|
||||
note.persist(anonymous);
|
||||
|
||||
GetMethod getNoteJobs = httpGet("/notebook/job/" + note.getId());
|
||||
assertThat("test notebook jobs run:", getNoteJobs, isAllowed());
|
||||
|
|
@ -572,12 +579,12 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
assertFalse(body.get(0).containsKey("finished"));
|
||||
getNoteJobs.releaseConnection();
|
||||
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertParagraph() throws IOException {
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
|
||||
String jsonRequest = "{\"title\": \"title1\", \"text\": \"text1\"}";
|
||||
PostMethod post = httpPost("/notebook/" + note.getId() + "/paragraph", jsonRequest);
|
||||
|
|
@ -612,17 +619,17 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
assertEquals("title2", paragraphAtIdx0.getTitle());
|
||||
assertEquals("text2", paragraphAtIdx0.getText());
|
||||
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetParagraph() throws IOException {
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
|
||||
Paragraph p = note.addParagraph();
|
||||
p.setTitle("hello");
|
||||
p.setText("world");
|
||||
note.persist(null);
|
||||
note.persist(anonymous);
|
||||
|
||||
GetMethod get = httpGet("/notebook/" + note.getId() + "/paragraph/" + p.getId());
|
||||
LOG.info("testGetParagraph response\n" + get.getResponseBodyAsString());
|
||||
|
|
@ -641,12 +648,12 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
assertEquals("hello", body.get("title"));
|
||||
assertEquals("world", body.get("text"));
|
||||
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMoveParagraph() throws IOException {
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
|
||||
Paragraph p = note.addParagraph();
|
||||
p.setTitle("title1");
|
||||
|
|
@ -656,7 +663,7 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
p2.setTitle("title2");
|
||||
p2.setText("text2");
|
||||
|
||||
note.persist(null);
|
||||
note.persist(anonymous);
|
||||
|
||||
PostMethod post = httpPost("/notebook/" + note.getId() + "/paragraph/" + p2.getId() + "/move/" + 0, "");
|
||||
assertThat("Test post method: ", post, isAllowed());
|
||||
|
|
@ -673,18 +680,18 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
assertThat("Test post method: ", post2, isBadRequest());
|
||||
post.releaseConnection();
|
||||
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteParagraph() throws IOException {
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
|
||||
Paragraph p = note.addParagraph();
|
||||
p.setTitle("title1");
|
||||
p.setText("text1");
|
||||
|
||||
note.persist(null);
|
||||
note.persist(anonymous);
|
||||
|
||||
DeleteMethod delete = httpDelete("/notebook/" + note.getId() + "/paragraph/" + p.getId());
|
||||
assertThat("Test delete method: ", delete, isAllowed());
|
||||
|
|
@ -694,7 +701,7 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
Paragraph retrParagrah = retrNote.getParagraph(p.getId());
|
||||
assertNull("paragraph should be deleted", retrParagrah);
|
||||
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -710,12 +717,12 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
String username = body.get("principal");
|
||||
getSecurityTicket.releaseConnection();
|
||||
|
||||
Note note1 = ZeppelinServer.notebook.createNote(null);
|
||||
Note note1 = ZeppelinServer.notebook.createNote(anonymous);
|
||||
String jsonRequest = "{\"title\": \"title1\", \"text\": \"ThisIsToTestSearchMethodWithPermissions 1\"}";
|
||||
PostMethod postNotebookText = httpPost("/notebook/" + note1.getId() + "/paragraph", jsonRequest);
|
||||
postNotebookText.releaseConnection();
|
||||
|
||||
Note note2 = ZeppelinServer.notebook.createNote(null);
|
||||
Note note2 = ZeppelinServer.notebook.createNote(anonymous);
|
||||
jsonRequest = "{\"title\": \"title1\", \"text\": \"ThisIsToTestSearchMethodWithPermissions 2\"}";
|
||||
postNotebookText = httpPost("/notebook/" + note2.getId() + "/paragraph", jsonRequest);
|
||||
postNotebookText.releaseConnection();
|
||||
|
|
@ -757,13 +764,13 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
getPermission.releaseConnection();
|
||||
}
|
||||
searchNotebook.releaseConnection();
|
||||
ZeppelinServer.notebook.removeNote(note1.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note2.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note1.getId(), anonymous);
|
||||
ZeppelinServer.notebook.removeNote(note2.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTitleSearch() throws IOException {
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
String jsonRequest = "{\"title\": \"testTitleSearchOfParagraph\", \"text\": \"ThisIsToTestSearchMethodWithTitle \"}";
|
||||
PostMethod postNotebookText = httpPost("/notebook/" + note.getId() + "/paragraph", jsonRequest);
|
||||
postNotebookText.releaseConnection();
|
||||
|
|
@ -784,7 +791,7 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
|
|||
}
|
||||
assertEquals("Paragraph title hits must be at-least one", true, numberOfTitleHits >= 1);
|
||||
searchNotebook.releaseConnection();
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,9 @@ import org.apache.zeppelin.notebook.Note;
|
|||
import org.apache.zeppelin.notebook.Paragraph;
|
||||
import org.apache.zeppelin.scheduler.Job.Status;
|
||||
import org.apache.zeppelin.server.ZeppelinServer;
|
||||
import org.apache.zeppelin.user.AuthenticationInfo;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -43,6 +45,7 @@ import com.google.gson.Gson;
|
|||
*/
|
||||
public class ZeppelinSparkClusterTest extends AbstractTestRestApi {
|
||||
Gson gson = new Gson();
|
||||
AuthenticationInfo anonymous;
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws Exception {
|
||||
|
|
@ -54,6 +57,11 @@ public class ZeppelinSparkClusterTest extends AbstractTestRestApi {
|
|||
AbstractTestRestApi.shutDown();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
anonymous = new AuthenticationInfo("anonymous");
|
||||
}
|
||||
|
||||
private void waitForFinish(Paragraph p) {
|
||||
while (p.getStatus() != Status.FINISHED
|
||||
&& p.getStatus() != Status.ERROR
|
||||
|
|
@ -69,7 +77,7 @@ public class ZeppelinSparkClusterTest extends AbstractTestRestApi {
|
|||
@Test
|
||||
public void basicRDDTransformationAndActionTest() throws IOException {
|
||||
// create new note
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
|
||||
// run markdown paragraph, again
|
||||
Paragraph p = note.addParagraph();
|
||||
|
|
@ -77,11 +85,12 @@ public class ZeppelinSparkClusterTest extends AbstractTestRestApi {
|
|||
config.put("enabled", true);
|
||||
p.setConfig(config);
|
||||
p.setText("%spark print(sc.parallelize(1 to 10).reduce(_ + _))");
|
||||
p.setAuthenticationInfo(anonymous);
|
||||
note.run(p.getId());
|
||||
waitForFinish(p);
|
||||
assertEquals(Status.FINISHED, p.getStatus());
|
||||
assertEquals("55", p.getResult().message());
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -138,7 +147,7 @@ public class ZeppelinSparkClusterTest extends AbstractTestRestApi {
|
|||
@Test
|
||||
public void sparkRTest() throws IOException {
|
||||
// create new note
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
int sparkVersion = getSparkVersionNumber(note);
|
||||
|
||||
if (isSparkR() && sparkVersion >= 14) { // sparkr supported from 1.4.0
|
||||
|
|
@ -165,19 +174,20 @@ public class ZeppelinSparkClusterTest extends AbstractTestRestApi {
|
|||
"df <- createDataFrame(" + sqlContextName + ", localDF)\n" +
|
||||
"count(df)"
|
||||
);
|
||||
p.setAuthenticationInfo(anonymous);
|
||||
note.run(p.getId());
|
||||
waitForFinish(p);
|
||||
System.err.println("sparkRTest=" + p.getResult().message());
|
||||
assertEquals(Status.FINISHED, p.getStatus());
|
||||
assertEquals("[1] 3", p.getResult().message());
|
||||
}
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pySparkTest() throws IOException {
|
||||
// create new note
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
note.setName("note");
|
||||
int sparkVersion = getSparkVersionNumber(note);
|
||||
|
||||
|
|
@ -188,6 +198,7 @@ public class ZeppelinSparkClusterTest extends AbstractTestRestApi {
|
|||
config.put("enabled", true);
|
||||
p.setConfig(config);
|
||||
p.setText("%pyspark print(sc.parallelize(range(1, 11)).reduce(lambda a, b: a + b))");
|
||||
p.setAuthenticationInfo(anonymous);
|
||||
note.run(p.getId());
|
||||
waitForFinish(p);
|
||||
assertEquals(Status.FINISHED, p.getStatus());
|
||||
|
|
@ -261,13 +272,13 @@ public class ZeppelinSparkClusterTest extends AbstractTestRestApi {
|
|||
assertEquals("[Row(len=u'3')]\n", p.getResult().message());
|
||||
}
|
||||
}
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pySparkAutoConvertOptionTest() throws IOException {
|
||||
// create new note
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
note.setName("note");
|
||||
|
||||
int sparkVersionNumber = getSparkVersionNumber(note);
|
||||
|
|
@ -286,33 +297,37 @@ public class ZeppelinSparkClusterTest extends AbstractTestRestApi {
|
|||
|
||||
p.setText("%pyspark\nfrom pyspark.sql.functions import *\n"
|
||||
+ "print(" + sqlContextName + ".range(0, 10).withColumn('uniform', rand(seed=10) * 3.14).count())");
|
||||
p.setAuthenticationInfo(anonymous);
|
||||
note.run(p.getId());
|
||||
waitForFinish(p);
|
||||
assertEquals(Status.FINISHED, p.getStatus());
|
||||
assertEquals("10\n", p.getResult().message());
|
||||
}
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void zRunTest() throws IOException {
|
||||
// create new note
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
Paragraph p0 = note.addParagraph();
|
||||
Map config0 = p0.getConfig();
|
||||
config0.put("enabled", true);
|
||||
p0.setConfig(config0);
|
||||
p0.setText("%spark z.run(1)");
|
||||
p0.setAuthenticationInfo(anonymous);
|
||||
Paragraph p1 = note.addParagraph();
|
||||
Map config1 = p1.getConfig();
|
||||
config1.put("enabled", true);
|
||||
p1.setConfig(config1);
|
||||
p1.setText("%spark val a=10");
|
||||
p1.setAuthenticationInfo(anonymous);
|
||||
Paragraph p2 = note.addParagraph();
|
||||
Map config2 = p2.getConfig();
|
||||
config2.put("enabled", true);
|
||||
p2.setConfig(config2);
|
||||
p2.setText("%spark print(a)");
|
||||
p2.setAuthenticationInfo(anonymous);
|
||||
|
||||
note.run(p0.getId());
|
||||
waitForFinish(p0);
|
||||
|
|
@ -323,13 +338,13 @@ public class ZeppelinSparkClusterTest extends AbstractTestRestApi {
|
|||
assertEquals(Status.FINISHED, p2.getStatus());
|
||||
assertEquals("10", p2.getResult().message());
|
||||
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pySparkDepLoaderTest() throws IOException {
|
||||
// create new note
|
||||
Note note = ZeppelinServer.notebook.createNote(null);
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
int sparkVersionNumber = getSparkVersionNumber(note);
|
||||
|
||||
if (isPyspark() && sparkVersionNumber >= 14) {
|
||||
|
|
@ -350,6 +365,7 @@ public class ZeppelinSparkClusterTest extends AbstractTestRestApi {
|
|||
config.put("enabled", true);
|
||||
p0.setConfig(config);
|
||||
p0.setText("%dep z.load(\"com.databricks:spark-csv_2.11:1.2.0\")");
|
||||
p0.setAuthenticationInfo(anonymous);
|
||||
note.run(p0.getId());
|
||||
waitForFinish(p0);
|
||||
assertEquals(Status.FINISHED, p0.getStatus());
|
||||
|
|
@ -370,13 +386,14 @@ public class ZeppelinSparkClusterTest extends AbstractTestRestApi {
|
|||
"from pyspark.sql import SQLContext\n" +
|
||||
"print(" + sqlContextName + ".read.format('com.databricks.spark.csv')" +
|
||||
".load('"+ tmpFile.getAbsolutePath() +"').count())");
|
||||
p0.setAuthenticationInfo(anonymous);
|
||||
note.run(p1.getId());
|
||||
|
||||
waitForFinish(p1);
|
||||
assertEquals(Status.FINISHED, p1.getStatus());
|
||||
assertEquals("2\n", p1.getResult().message());
|
||||
}
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), null);
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -390,6 +407,7 @@ public class ZeppelinSparkClusterTest extends AbstractTestRestApi {
|
|||
config.put("enabled", true);
|
||||
p.setConfig(config);
|
||||
p.setText("%spark print(sc.version)");
|
||||
p.setAuthenticationInfo(anonymous);
|
||||
note.run(p.getId());
|
||||
waitForFinish(p);
|
||||
assertEquals(Status.FINISHED, p.getStatus());
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import org.apache.zeppelin.notebook.socket.Message;
|
|||
import org.apache.zeppelin.notebook.socket.Message.OP;
|
||||
import org.apache.zeppelin.rest.AbstractTestRestApi;
|
||||
import org.apache.zeppelin.server.ZeppelinServer;
|
||||
import org.apache.zeppelin.user.AuthenticationInfo;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
|
|
@ -57,6 +58,7 @@ public class NotebookServerTest extends AbstractTestRestApi {
|
|||
private static NotebookServer notebookServer;
|
||||
private static Gson gson;
|
||||
private HttpServletRequest mockRequest;
|
||||
private AuthenticationInfo anonymous;
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws Exception {
|
||||
|
|
@ -74,6 +76,7 @@ public class NotebookServerTest extends AbstractTestRestApi {
|
|||
@Before
|
||||
public void setUp() {
|
||||
mockRequest = mock(HttpServletRequest.class);
|
||||
anonymous = new AuthenticationInfo("anonymous");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -94,7 +97,7 @@ public class NotebookServerTest extends AbstractTestRestApi {
|
|||
@Test
|
||||
public void testMakeSureNoAngularObjectBroadcastToWebsocketWhoFireTheEvent() throws IOException {
|
||||
// create a notebook
|
||||
Note note1 = notebook.createNote(null);
|
||||
Note note1 = notebook.createNote(anonymous);
|
||||
|
||||
// get reference to interpreterGroup
|
||||
InterpreterGroup interpreterGroup = null;
|
||||
|
|
@ -109,6 +112,7 @@ public class NotebookServerTest extends AbstractTestRestApi {
|
|||
// start interpreter process
|
||||
Paragraph p1 = note1.addParagraph();
|
||||
p1.setText("%md start remote interpreter process");
|
||||
p1.setAuthenticationInfo(anonymous);
|
||||
note1.run(p1.getId());
|
||||
|
||||
// add angularObject
|
||||
|
|
@ -144,7 +148,7 @@ public class NotebookServerTest extends AbstractTestRestApi {
|
|||
verify(sock1, times(0)).send(anyString());
|
||||
verify(sock2, times(1)).send(anyString());
|
||||
|
||||
notebook.removeNote(note1.getId(), null);
|
||||
notebook.removeNote(note1.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -167,7 +171,7 @@ public class NotebookServerTest extends AbstractTestRestApi {
|
|||
assertNotEquals(null, notebook.getNote(note.getId()));
|
||||
assertEquals("Test Zeppelin notebook import", notebook.getNote(note.getId()).getName());
|
||||
assertEquals("Test paragraphs import", notebook.getNote(note.getId()).getParagraphs().get(0).getText());
|
||||
notebook.removeNote(note.getId(), null);
|
||||
notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in a new issue