Search in sources :

Example 1 with Revision

use of org.apache.zeppelin.notebook.repo.NotebookRepoWithVersionControl.Revision in project zeppelin by apache.

the class GitNotebookRepoTest method setRevisionTest.

@Test
public void setRevisionTest() throws IOException {
    // create repo and check that note doesn't contain revisions
    notebookRepo = new GitNotebookRepo(conf);
    assertFalse(notebookRepo.list(null).isEmpty());
    assertTrue(containsNote(notebookRepo.list(null), TEST_NOTE_ID));
    assertTrue(notebookRepo.revisionHistory(TEST_NOTE_ID, TEST_NOTE_PATH, null).isEmpty());
    // get current note
    Note note = notebookRepo.get(TEST_NOTE_ID, TEST_NOTE_PATH, null);
    note.setInterpreterFactory(mock(InterpreterFactory.class));
    int paragraphCount_1 = note.getParagraphs().size();
    LOG.info("initial paragraph count: {}", paragraphCount_1);
    // checkpoint revision1
    Revision revision1 = notebookRepo.checkpoint(TEST_NOTE_ID, TEST_NOTE_PATH, "set revision: first commit", null);
    // TODO(khalid): change to EMPTY after rebase
    assertNotNull(revision1);
    assertEquals(1, notebookRepo.revisionHistory(TEST_NOTE_ID, TEST_NOTE_PATH, null).size());
    // add one more paragraph and save
    Paragraph p1 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
    Map<String, Object> config = p1.getConfig();
    config.put("enabled", true);
    p1.setConfig(config);
    p1.setText("set revision sample text");
    notebookRepo.save(note, null);
    int paragraphCount_2 = note.getParagraphs().size();
    assertEquals(paragraphCount_1 + 1, paragraphCount_2);
    LOG.info("paragraph count after modification: {}", paragraphCount_2);
    // checkpoint revision2
    Revision revision2 = notebookRepo.checkpoint(TEST_NOTE_ID, TEST_NOTE_PATH, "set revision: second commit", null);
    // TODO(khalid): change to EMPTY after rebase
    assertNotNull(revision2);
    assertEquals(2, notebookRepo.revisionHistory(TEST_NOTE_ID, TEST_NOTE_PATH, null).size());
    // set note to revision1
    Note returnedNote = notebookRepo.setNoteRevision(note.getId(), note.getPath(), revision1.id, null);
    assertNotNull(returnedNote);
    assertEquals(paragraphCount_1, returnedNote.getParagraphs().size());
    // check note from repo
    Note updatedNote = notebookRepo.get(note.getId(), note.getPath(), null);
    assertNotNull(updatedNote);
    assertEquals(paragraphCount_1, updatedNote.getParagraphs().size());
    // set back to revision2
    returnedNote = notebookRepo.setNoteRevision(note.getId(), note.getPath(), revision2.id, null);
    assertNotNull(returnedNote);
    assertEquals(paragraphCount_2, returnedNote.getParagraphs().size());
    // check note from repo
    updatedNote = notebookRepo.get(note.getId(), note.getPath(), null);
    assertNotNull(updatedNote);
    assertEquals(paragraphCount_2, updatedNote.getParagraphs().size());
    // try failure case - set to invalid revision
    returnedNote = notebookRepo.setNoteRevision(note.getId(), note.getPath(), "nonexistent_id", null);
    assertNull(returnedNote);
}
Also used : Revision(org.apache.zeppelin.notebook.repo.NotebookRepoWithVersionControl.Revision) Note(org.apache.zeppelin.notebook.Note) InterpreterFactory(org.apache.zeppelin.interpreter.InterpreterFactory) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 2 with Revision

use of org.apache.zeppelin.notebook.repo.NotebookRepoWithVersionControl.Revision in project zeppelin by apache.

the class GitNotebookRepoTest method addCheckpointTest.

@Test
public void addCheckpointTest() throws IOException, GitAPIException {
    // initial checks
    notebookRepo = new GitNotebookRepo(conf);
    assertFalse(notebookRepo.list(null).isEmpty());
    assertTrue(containsNote(notebookRepo.list(null), TEST_NOTE_ID));
    assertTrue(notebookRepo.revisionHistory(TEST_NOTE_ID, TEST_NOTE_PATH, null).isEmpty());
    notebookRepo.checkpoint(TEST_NOTE_ID, TEST_NOTE_PATH, "first commit", null);
    List<Revision> notebookHistoryBefore = notebookRepo.revisionHistory(TEST_NOTE_ID, TEST_NOTE_PATH, null);
    assertFalse(notebookRepo.revisionHistory(TEST_NOTE_ID, TEST_NOTE_PATH, null).isEmpty());
    int initialCount = notebookHistoryBefore.size();
    // add changes to note
    Note note = notebookRepo.get(TEST_NOTE_ID, TEST_NOTE_PATH, null);
    note.setInterpreterFactory(mock(InterpreterFactory.class));
    Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
    Map<String, Object> config = p.getConfig();
    config.put("enabled", true);
    p.setConfig(config);
    p.setText("%md checkpoint test text");
    // save and checkpoint note
    notebookRepo.save(note, null);
    notebookRepo.checkpoint(TEST_NOTE_ID, TEST_NOTE_PATH, "second commit", null);
    // see if commit is added
    List<Revision> notebookHistoryAfter = notebookRepo.revisionHistory(TEST_NOTE_ID, TEST_NOTE_PATH, null);
    assertEquals(initialCount + 1, notebookHistoryAfter.size());
    int revCountBefore = 0;
    Iterable<RevCommit> revCommits = notebookRepo.getGit().log().call();
    for (RevCommit revCommit : revCommits) {
        revCountBefore++;
    }
    // add changes to note2
    Note note2 = notebookRepo.get(TEST_NOTE_ID2, TEST_NOTE_PATH2, null);
    note2.setInterpreterFactory(mock(InterpreterFactory.class));
    Paragraph p2 = note2.addNewParagraph(AuthenticationInfo.ANONYMOUS);
    Map<String, Object> config2 = p2.getConfig();
    config2.put("enabled", true);
    p2.setConfig(config);
    p2.setText("%md checkpoint test text");
    // save note2 and checkpoint this note without changes
    notebookRepo.save(note2, null);
    notebookRepo.checkpoint(TEST_NOTE_ID, TEST_NOTE_PATH, "third commit", null);
    // should not add more commit
    int revCountAfter = 0;
    revCommits = notebookRepo.getGit().log().call();
    for (RevCommit revCommit : revCommits) {
        revCountAfter++;
    }
    assertEquals(revCountBefore, revCountAfter);
}
Also used : Revision(org.apache.zeppelin.notebook.repo.NotebookRepoWithVersionControl.Revision) Note(org.apache.zeppelin.notebook.Note) InterpreterFactory(org.apache.zeppelin.interpreter.InterpreterFactory) Paragraph(org.apache.zeppelin.notebook.Paragraph) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 3 with Revision

use of org.apache.zeppelin.notebook.repo.NotebookRepoWithVersionControl.Revision in project zeppelin by apache.

the class GitNotebookRepoTest method getRevisionFailTest.

@Test
public void getRevisionFailTest() throws IOException {
    // initial checks
    notebookRepo = new GitNotebookRepo(conf);
    assertFalse(notebookRepo.list(null).isEmpty());
    assertTrue(containsNote(notebookRepo.list(null), TEST_NOTE_ID));
    assertTrue(notebookRepo.revisionHistory(TEST_NOTE_ID, TEST_NOTE_PATH, null).isEmpty());
    // add first checkpoint
    Revision revision_1 = notebookRepo.checkpoint(TEST_NOTE_ID, TEST_NOTE_PATH, "first commit", null);
    assertEquals(1, notebookRepo.revisionHistory(TEST_NOTE_ID, TEST_NOTE_PATH, null).size());
    int paragraphCount_1 = notebookRepo.get(TEST_NOTE_ID, TEST_NOTE_PATH, null).getParagraphs().size();
    // get current note
    Note note = notebookRepo.get(TEST_NOTE_ID, TEST_NOTE_PATH, null);
    note.setInterpreterFactory(mock(InterpreterFactory.class));
    assertEquals(paragraphCount_1, note.getParagraphs().size());
    // add one more paragraph and save
    Paragraph p1 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
    Map<String, Object> config = p1.getConfig();
    config.put("enabled", true);
    p1.setConfig(config);
    p1.setText("get revision when modified note test text");
    notebookRepo.save(note, null);
    int paragraphCount_2 = note.getParagraphs().size();
    // get note from revision 1
    Note noteRevision_1 = notebookRepo.get(TEST_NOTE_ID, TEST_NOTE_PATH, revision_1.id, null);
    assertEquals(paragraphCount_1, noteRevision_1.getParagraphs().size());
    // get current note
    note = notebookRepo.get(TEST_NOTE_ID, TEST_NOTE_PATH, null);
    note.setInterpreterFactory(mock(InterpreterFactory.class));
    assertEquals(paragraphCount_2, note.getParagraphs().size());
    // test for absent revision
    Revision absentRevision = new Revision("absentId", StringUtils.EMPTY, 0);
    note = notebookRepo.get(TEST_NOTE_ID, TEST_NOTE_PATH, absentRevision.id, null);
    assertNull(note);
}
Also used : Revision(org.apache.zeppelin.notebook.repo.NotebookRepoWithVersionControl.Revision) Note(org.apache.zeppelin.notebook.Note) InterpreterFactory(org.apache.zeppelin.interpreter.InterpreterFactory) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 4 with Revision

use of org.apache.zeppelin.notebook.repo.NotebookRepoWithVersionControl.Revision in project zeppelin by apache.

the class GitNotebookRepoTest method getRevisionTest.

@Test
public void getRevisionTest() throws IOException {
    // initial checks
    notebookRepo = new GitNotebookRepo(conf);
    assertFalse(notebookRepo.list(null).isEmpty());
    assertTrue(containsNote(notebookRepo.list(null), TEST_NOTE_ID));
    assertTrue(notebookRepo.revisionHistory(TEST_NOTE_ID, TEST_NOTE_PATH, null).isEmpty());
    // add first checkpoint
    Revision revision_1 = notebookRepo.checkpoint(TEST_NOTE_ID, TEST_NOTE_PATH, "first commit", null);
    assertEquals(1, notebookRepo.revisionHistory(TEST_NOTE_ID, TEST_NOTE_PATH, null).size());
    int paragraphCount_1 = notebookRepo.get(TEST_NOTE_ID, TEST_NOTE_PATH, null).getParagraphs().size();
    // add paragraph and save
    Note note = notebookRepo.get(TEST_NOTE_ID, TEST_NOTE_PATH, null);
    note.setInterpreterFactory(mock(InterpreterFactory.class));
    Paragraph p1 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
    Map<String, Object> config = p1.getConfig();
    config.put("enabled", true);
    p1.setConfig(config);
    p1.setText("checkpoint test text");
    notebookRepo.save(note, null);
    // second checkpoint
    notebookRepo.checkpoint(TEST_NOTE_ID, TEST_NOTE_PATH, "second commit", null);
    assertEquals(2, notebookRepo.revisionHistory(TEST_NOTE_ID, TEST_NOTE_PATH, null).size());
    int paragraphCount_2 = notebookRepo.get(TEST_NOTE_ID, TEST_NOTE_PATH, null).getParagraphs().size();
    assertEquals(paragraphCount_1 + 1, paragraphCount_2);
    // get note from revision 1
    Note noteRevision_1 = notebookRepo.get(TEST_NOTE_ID, TEST_NOTE_PATH, revision_1.id, null);
    assertEquals(paragraphCount_1, noteRevision_1.getParagraphs().size());
    // get current note
    note = notebookRepo.get(TEST_NOTE_ID, TEST_NOTE_PATH, null);
    note.setInterpreterFactory(mock(InterpreterFactory.class));
    assertEquals(paragraphCount_2, note.getParagraphs().size());
    // add one more paragraph and save
    Paragraph p2 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
    config.put("enabled", false);
    p2.setConfig(config);
    p2.setText("get revision when modified note test text");
    notebookRepo.save(note, null);
    note = notebookRepo.get(TEST_NOTE_ID, TEST_NOTE_PATH, null);
    note.setInterpreterFactory(mock(InterpreterFactory.class));
    int paragraphCount_3 = note.getParagraphs().size();
    assertEquals(paragraphCount_2 + 1, paragraphCount_3);
    // get revision 1 again
    noteRevision_1 = notebookRepo.get(TEST_NOTE_ID, TEST_NOTE_PATH, revision_1.id, null);
    assertEquals(paragraphCount_1, noteRevision_1.getParagraphs().size());
    // check that note is unchanged
    note = notebookRepo.get(TEST_NOTE_ID, TEST_NOTE_PATH, null);
    assertEquals(paragraphCount_3, note.getParagraphs().size());
}
Also used : Revision(org.apache.zeppelin.notebook.repo.NotebookRepoWithVersionControl.Revision) Note(org.apache.zeppelin.notebook.Note) InterpreterFactory(org.apache.zeppelin.interpreter.InterpreterFactory) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Aggregations

InterpreterFactory (org.apache.zeppelin.interpreter.InterpreterFactory)4 Note (org.apache.zeppelin.notebook.Note)4 Paragraph (org.apache.zeppelin.notebook.Paragraph)4 Revision (org.apache.zeppelin.notebook.repo.NotebookRepoWithVersionControl.Revision)4 Test (org.junit.Test)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1