You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by zj...@apache.org on 2020/04/21 06:57:28 UTC
[zeppelin] branch master updated: [ZEPPELIN-4743] fix
MongoNotebookRepo get unstable note path
This is an automated email from the ASF dual-hosted git repository.
zjffdu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push:
new 5de88ea [ZEPPELIN-4743] fix MongoNotebookRepo get unstable note path
5de88ea is described below
commit 5de88ea94cf73ec9d64b39c4136c5978ef6aad89
Author: archy.gu <ar...@maiscrm.com>
AuthorDate: Fri Apr 10 11:02:02 2020 +0800
[ZEPPELIN-4743] fix MongoNotebookRepo get unstable note path
### What is this PR for?
This PR sorts documents returned by aggregation $graphLookup which used by MongoNotebookRepo to get the path of note.
### What type of PR is it?
Bug Fix
### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-4743
### How should this be tested?
2 types of tests:
* Unit test added
* Create notes(more nested folders is better) in zeppelin web UI, then restart zeppelin or call /api/notebook-repositories/reload. After doing the above, check if the note path is correct.
### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No
Author: archy.gu <ar...@maiscrm.com>
Closes #3730 from zuiluoyin/ZEPPELIN-4743 and squashes the following commits:
abb4c0d57 [archy.gu] [ZEPPELIN-4743] fix MongoNotebookRepo get unstable note path
(cherry picked from commit 53fa69a524981d6065eabe7d141b200aad7987e2)
Signed-off-by: Jeff Zhang <zj...@apache.org>
---
.../zeppelin/notebook/repo/MongoNotebookRepo.java | 2 ++
.../notebook/repo/MongoNotebookRepoTest.java | 24 ++++++++++++++++++++--
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/zeppelin-plugins/notebookrepo/mongo/src/main/java/org/apache/zeppelin/notebook/repo/MongoNotebookRepo.java b/zeppelin-plugins/notebookrepo/mongo/src/main/java/org/apache/zeppelin/notebook/repo/MongoNotebookRepo.java
index 34ebec6..568de20 100644
--- a/zeppelin-plugins/notebookrepo/mongo/src/main/java/org/apache/zeppelin/notebook/repo/MongoNotebookRepo.java
+++ b/zeppelin-plugins/notebookrepo/mongo/src/main/java/org/apache/zeppelin/notebook/repo/MongoNotebookRepo.java
@@ -31,6 +31,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -127,6 +128,7 @@ public class MongoNotebookRepo implements NotebookRepo {
String id = document.getString(Fields.ID);
String name = document.getString(Fields.NAME);
List<Document> fullPath = document.get(Fields.FULL_PATH, List.class);
+ fullPath.sort(Comparator.comparing(pathNode -> pathNode.getString(Fields.ID)));
StringBuilder sb = new StringBuilder();
for (Document pathNode : fullPath) {
diff --git a/zeppelin-plugins/notebookrepo/mongo/src/test/java/org/apache/zeppelin/notebook/repo/MongoNotebookRepoTest.java b/zeppelin-plugins/notebookrepo/mongo/src/test/java/org/apache/zeppelin/notebook/repo/MongoNotebookRepoTest.java
index 9c103cb..042d34b 100644
--- a/zeppelin-plugins/notebookrepo/mongo/src/test/java/org/apache/zeppelin/notebook/repo/MongoNotebookRepoTest.java
+++ b/zeppelin-plugins/notebookrepo/mongo/src/test/java/org/apache/zeppelin/notebook/repo/MongoNotebookRepoTest.java
@@ -49,7 +49,9 @@ public class MongoNotebookRepoTest {
@Before
public void setUp() throws IOException {
String bindIp = "localhost";
- int port = new ServerSocket(0).getLocalPort();
+ ServerSocket socket = new ServerSocket(0);
+ int port = socket.getLocalPort();
+ socket.close();
IMongodConfig mongodConfig = new MongodConfigBuilder()
.version(Version.Main.PRODUCTION)
@@ -124,4 +126,22 @@ public class MongoNotebookRepoTest {
notebookRepo.remove("/my_project3", AuthenticationInfo.ANONYMOUS);
assertEquals(0, notebookRepo.list(AuthenticationInfo.ANONYMOUS).size());
}
-}
\ No newline at end of file
+
+ @Test
+ public void testGetNotePath() throws IOException {
+ assertEquals(0, notebookRepo.list(AuthenticationInfo.ANONYMOUS).size());
+
+ Note note = new Note();
+ String notePath = "/folder1/folder2/folder3/folder4/folder5/my_note";
+ note.setPath(notePath);
+ notebookRepo.save(note, AuthenticationInfo.ANONYMOUS);
+
+ notebookRepo.init(zConf);
+ Map<String, NoteInfo> noteInfos = notebookRepo.list(AuthenticationInfo.ANONYMOUS);
+ assertEquals(1, notebookRepo.list(AuthenticationInfo.ANONYMOUS).size());
+ assertEquals(notePath, noteInfos.get(note.getId()).getPath());
+
+ notebookRepo.remove(note.getId(), note.getPath(), AuthenticationInfo.ANONYMOUS);
+ assertEquals(0, notebookRepo.list(AuthenticationInfo.ANONYMOUS).size());
+ }
+}