Skip to content

Commit 47cc668

Browse files
committed
Fixed tests to use AuthenticationInfo
1 parent 012cf99 commit 47cc668

File tree

8 files changed

+112
-73
lines changed

8 files changed

+112
-73
lines changed

zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumApplicationFactoryTest.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import org.apache.zeppelin.scheduler.Job;
2828
import org.apache.zeppelin.scheduler.SchedulerFactory;
2929
import org.apache.zeppelin.search.SearchService;
30+
import org.apache.zeppelin.user.AuthenticationInfo;
31+
import org.apache.zeppelin.user.Credentials;
3032
import org.junit.After;
3133
import org.junit.Before;
3234
import org.junit.Test;
@@ -50,6 +52,7 @@ public class HeliumApplicationFactoryTest implements JobListenerFactory {
5052
private VFSNotebookRepo notebookRepo;
5153
private Notebook notebook;
5254
private HeliumApplicationFactory heliumAppFactory;
55+
private AuthenticationInfo anonymous;
5356

5457
@Before
5558
public void setUp() throws Exception {
@@ -98,11 +101,13 @@ public void setUp() throws Exception {
98101
this,
99102
search,
100103
notebookAuthorization,
101-
null);
104+
new Credentials(false, null));
102105

103106
heliumAppFactory.setNotebook(notebook);
104107

105108
notebook.addNotebookEventListener(heliumAppFactory);
109+
110+
anonymous = new AuthenticationInfo("anonymous");
106111
}
107112

108113
@After
@@ -131,13 +136,14 @@ public void testLoadRunUnloadApplication()
131136
HeliumTestApplication.class.getName(),
132137
new String[][]{});
133138

134-
Note note1 = notebook.createNote(null);
139+
Note note1 = notebook.createNote(anonymous);
135140
factory.setInterpreters("user", note1.getId(),factory.getDefaultInterpreterSettingList());
136141

137142
Paragraph p1 = note1.addParagraph();
138143

139144
// make sure interpreter process running
140145
p1.setText("%mock1 job");
146+
p1.setAuthenticationInfo(anonymous);
141147
note1.run(p1.getId());
142148
while(p1.isTerminated()==false || p1.getResult()==null) Thread.yield();
143149

@@ -162,7 +168,7 @@ public void testLoadRunUnloadApplication()
162168

163169
// clean
164170
heliumAppFactory.unload(p1, appId);
165-
notebook.removeNote(note1.getId(), null);
171+
notebook.removeNote(note1.getId(), anonymous);
166172
}
167173

168174
@Test
@@ -175,13 +181,14 @@ public void testUnloadOnParagraphRemove() throws IOException {
175181
HeliumTestApplication.class.getName(),
176182
new String[][]{});
177183

178-
Note note1 = notebook.createNote(null);
184+
Note note1 = notebook.createNote(anonymous);
179185
factory.setInterpreters("user", note1.getId(), factory.getDefaultInterpreterSettingList());
180186

181187
Paragraph p1 = note1.addParagraph();
182188

183189
// make sure interpreter process running
184190
p1.setText("%mock1 job");
191+
p1.setAuthenticationInfo(anonymous);
185192
note1.run(p1.getId());
186193
while(p1.isTerminated()==false || p1.getResult()==null) Thread.yield();
187194

@@ -199,7 +206,7 @@ public void testUnloadOnParagraphRemove() throws IOException {
199206
assertEquals(ApplicationState.Status.UNLOADED, app.getStatus());
200207

201208
// clean
202-
notebook.removeNote(note1.getId(), null);
209+
notebook.removeNote(note1.getId(), anonymous);
203210
}
204211

205212

@@ -213,13 +220,14 @@ public void testUnloadOnInterpreterUnbind() throws IOException {
213220
HeliumTestApplication.class.getName(),
214221
new String[][]{});
215222

216-
Note note1 = notebook.createNote(null);
223+
Note note1 = notebook.createNote(anonymous);
217224
notebook.bindInterpretersToNote("user", note1.getId(), factory.getDefaultInterpreterSettingList());
218225

219226
Paragraph p1 = note1.addParagraph();
220227

221228
// make sure interpreter process running
222229
p1.setText("%mock1 job");
230+
p1.setAuthenticationInfo(anonymous);
223231
note1.run(p1.getId());
224232
while(p1.isTerminated()==false || p1.getResult()==null) Thread.yield();
225233

@@ -237,13 +245,13 @@ public void testUnloadOnInterpreterUnbind() throws IOException {
237245
assertEquals(ApplicationState.Status.UNLOADED, app.getStatus());
238246

239247
// clean
240-
notebook.removeNote(note1.getId(), null);
248+
notebook.removeNote(note1.getId(), anonymous);
241249
}
242250

243251
@Test
244252
public void testInterpreterUnbindOfNullReplParagraph() throws IOException {
245253
// create note
246-
Note note1 = notebook.createNote(null);
254+
Note note1 = notebook.createNote(anonymous);
247255

248256
// add paragraph with invalid magic
249257
Paragraph p1 = note1.addParagraph();
@@ -258,7 +266,7 @@ public void testInterpreterUnbindOfNullReplParagraph() throws IOException {
258266
notebook.bindInterpretersToNote("user", note1.getId(), new LinkedList<String>());
259267

260268
// remove note
261-
notebook.removeNote(note1.getId(), null);
269+
notebook.removeNote(note1.getId(), anonymous);
262270
}
263271

264272

@@ -272,7 +280,7 @@ public void testUnloadOnInterpreterRestart() throws IOException {
272280
HeliumTestApplication.class.getName(),
273281
new String[][]{});
274282

275-
Note note1 = notebook.createNote(null);
283+
Note note1 = notebook.createNote(anonymous);
276284
notebook.bindInterpretersToNote("user", note1.getId(), factory.getDefaultInterpreterSettingList());
277285
String mock1IntpSettingId = null;
278286
for (InterpreterSetting setting : notebook.getBindedInterpreterSettings(note1.getId())) {
@@ -286,6 +294,7 @@ public void testUnloadOnInterpreterRestart() throws IOException {
286294

287295
// make sure interpreter process running
288296
p1.setText("%mock1 job");
297+
p1.setAuthenticationInfo(anonymous);
289298
note1.run(p1.getId());
290299
while(p1.isTerminated()==false || p1.getResult()==null) Thread.yield();
291300
assertEquals(0, p1.getAllApplicationStates().size());
@@ -307,7 +316,7 @@ public void testUnloadOnInterpreterRestart() throws IOException {
307316
assertEquals(ApplicationState.Status.UNLOADED, app.getStatus());
308317

309318
// clean
310-
notebook.removeNote(note1.getId(), null);
319+
notebook.removeNote(note1.getId(), anonymous);
311320
}
312321

313322
@Override

zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,10 @@ public void testMultiUser() throws IOException, RepositoryException {
224224
add(info1);
225225
}}, new ArrayList<Dependency>(), new InterpreterOption(true), new Properties(), "/path1");
226226

227-
final InterpreterSetting setting1 = factory.createNewSetting("test-group1", "group1", new ArrayList<Dependency>(), new InterpreterOption(true), new Properties());
227+
InterpreterOption perUserInterpreterOption = new InterpreterOption(true);
228+
perUserInterpreterOption.setSession(true);
229+
perUserInterpreterOption.setPerUser(true);
230+
final InterpreterSetting setting1 = factory.createNewSetting("test-group1", "group1", new ArrayList<Dependency>(), perUserInterpreterOption, new Properties());
228231

229232
factory.setInterpreters("user1", "note", new ArrayList<String>() {{
230233
add(setting1.getId());

zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteInterpreterLoaderTest.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,15 @@ public void testGetInterpreter() throws IOException {
9797
public void testNoteSession() throws IOException {
9898
factory.setInterpreters("user", "noteA", factory.getDefaultInterpreterSettingList());
9999
factory.getInterpreterSettings("noteA").get(0).getOption().setSession(true);
100+
factory.getInterpreterSettings("noteA").get(0).getOption().setPerNote(true);
100101

101102
factory.setInterpreters("user", "noteB", factory.getDefaultInterpreterSettingList());
102103
factory.getInterpreterSettings("noteB").get(0).getOption().setSession(true);
104+
factory.getInterpreterSettings("noteB").get(0).getOption().setPerNote(true);
103105

104106
// interpreters are not created before accessing it
105-
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "shared_process").get("noteA"));
106-
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "shared_process").get("noteB"));
107+
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "noteA").get(":noteA"));
108+
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "noteB").get(":noteB"));
107109

108110
factory.getInterpreter("user", "noteA", null).open();
109111
factory.getInterpreter("user", "noteB", null).open();
@@ -113,30 +115,32 @@ public void testNoteSession() throws IOException {
113115
factory.getInterpreter("user", "noteB", null).getInterpreterGroup().getId()));
114116

115117
// interpreters are created after accessing it
116-
assertNotNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "shared_process").get("noteA"));
117-
assertNotNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "shared_process").get("noteB"));
118+
assertNotNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "noteA").get(":noteA"));
119+
assertNotNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "noteB").get(":noteB"));
118120

119121
// when
120122
factory.closeNote("user", "noteA");
121123
factory.closeNote("user", "noteB");
122124

123125
// interpreters are destroyed after close
124-
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "shared_process").get("noteA"));
125-
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "shared_process").get("noteB"));
126+
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "shared_process").get(":noteA"));
127+
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "shared_process").get(":noteB"));
126128

127129
}
128130

129131
@Test
130132
public void testNotePerInterpreterProcess() throws IOException {
131133
factory.setInterpreters("user", "noteA", factory.getDefaultInterpreterSettingList());
132134
factory.getInterpreterSettings("noteA").get(0).getOption().setProcess(true);
135+
factory.getInterpreterSettings("noteA").get(0).getOption().setPerNote(true);
133136

134137
factory.setInterpreters("user", "noteB", factory.getDefaultInterpreterSettingList());
135138
factory.getInterpreterSettings("noteB").get(0).getOption().setProcess(true);
139+
factory.getInterpreterSettings("noteA").get(0).getOption().setPerNote(true);
136140

137141
// interpreters are not created before accessing it
138-
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "noteA").get("noteA"));
139-
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "noteB").get("noteB"));
142+
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "noteA").get(":noteA"));
143+
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "noteB").get(":noteB"));
140144

141145
factory.getInterpreter("user", "noteA", null).open();
142146
factory.getInterpreter("user", "noteB", null).open();
@@ -147,16 +151,16 @@ public void testNotePerInterpreterProcess() throws IOException {
147151
factory.getInterpreter("user", "noteB", null).getInterpreterGroup().getId()));
148152

149153
// interpreters are created after accessing it
150-
assertNotNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "noteA").get("noteA"));
151-
assertNotNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "noteB").get("noteB"));
154+
assertNotNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "noteA").get(":noteA"));
155+
assertNotNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "noteB").get(":noteB"));
152156

153157
// when
154158
factory.closeNote("user", "noteA");
155159
factory.closeNote("user", "noteB");
156160

157161
// interpreters are destroyed after close
158-
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "noteA").get("noteA"));
159-
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "noteB").get("noteB"));
162+
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "noteA").get(":noteA"));
163+
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "noteB").get(":noteB"));
160164
}
161165

162166

zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.zeppelin.notebook.repo.NotebookRepo;
2323
import org.apache.zeppelin.scheduler.Scheduler;
2424
import org.apache.zeppelin.search.SearchService;
25+
import org.apache.zeppelin.user.AuthenticationInfo;
2526
import org.apache.zeppelin.user.Credentials;
2627
import org.junit.Test;
2728
import org.junit.runner.RunWith;
@@ -58,6 +59,8 @@ public class NoteTest {
5859
@Mock
5960
InterpreterFactory interpreterFactory;
6061

62+
private AuthenticationInfo anonymous = new AuthenticationInfo("anonymous");
63+
6164
@Test
6265
public void runNormalTest() {
6366
when(interpreterFactory.getInterpreter(anyString(), anyString(), eq("spark"))).thenReturn(interpreter);
@@ -68,6 +71,7 @@ public void runNormalTest() {
6871

6972
Paragraph p = note.addParagraph();
7073
p.setText(pText);
74+
p.setAuthenticationInfo(anonymous);
7175
note.run(p.getId());
7276

7377
ArgumentCaptor<Paragraph> pCaptor = ArgumentCaptor.forClass(Paragraph.class);
@@ -87,7 +91,7 @@ public void addParagraphWithEmptyReplNameTest() {
8791

8892
@Test
8993
public void addParagraphWithLastReplNameTest() {
90-
when(interpreterFactory.getInterpreter(anyString(), eq("spark"))).thenReturn(interpreter);
94+
when(interpreterFactory.getInterpreter(anyString(), anyString(), eq("spark"))).thenReturn(interpreter);
9195

9296
Note note = new Note(repo, interpreterFactory, jobListenerFactory, index, credentials, noteEventListener);
9397
Paragraph p1 = note.addParagraph();

zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public void testSelectingReplImplementation() throws IOException {
116116
config.put("enabled", true);
117117
p1.setConfig(config);
118118
p1.setText("hello world");
119+
p1.setAuthenticationInfo(anonymous);
119120
note.run(p1.getId());
120121
while(p1.isTerminated()==false || p1.getResult()==null) Thread.yield();
121122
assertEquals("repl1: hello world", p1.getResult().message());
@@ -124,6 +125,7 @@ public void testSelectingReplImplementation() throws IOException {
124125
Paragraph p2 = note.addParagraph();
125126
p2.setConfig(config);
126127
p2.setText("%mock2 hello world");
128+
p2.setAuthenticationInfo(anonymous);
127129
note.run(p2.getId());
128130
while(p2.isTerminated()==false || p2.getResult()==null) Thread.yield();
129131
assertEquals("repl2: hello world", p2.getResult().message());
@@ -235,6 +237,7 @@ public void testClearParagraphOutput() throws IOException, SchedulerException{
235237
config.put("enabled", true);
236238
p1.setConfig(config);
237239
p1.setText("hello world");
240+
p1.setAuthenticationInfo(anonymous);
238241
note.run(p1.getId());
239242

240243
while(p1.isTerminated() == false || p1.getResult() == null) Thread.yield();
@@ -688,13 +691,15 @@ public void testAbortParagraphStatusOnInterpreterRestart() throws InterruptedExc
688691
@Test
689692
public void testPerSessionInterpreterCloseOnNoteRemoval() throws IOException {
690693
// create a notes
691-
Note note1 = notebook.createNote(new AuthenticationInfo());
694+
Note note1 = notebook.createNote(anonymous);
692695
Paragraph p1 = note1.addParagraph();
693696
p1.setText("getId");
697+
p1.setAuthenticationInfo(anonymous);
694698

695699
// restart interpreter with per note session enabled
696700
for (InterpreterSetting setting : factory.getInterpreterSettings(note1.getId())) {
697701
setting.getOption().setSession(true);
702+
setting.getOption().setPerUser(true);
698703
notebook.getInterpreterFactory().restart(setting.getId());
699704
}
700705

@@ -707,6 +712,7 @@ public void testPerSessionInterpreterCloseOnNoteRemoval() throws IOException {
707712
note1 = notebook.createNote(anonymous);
708713
p1 = note1.addParagraph();
709714
p1.setText("getId");
715+
p1.setAuthenticationInfo(anonymous);
710716

711717
note1.run(p1.getId());
712718
while (p1.getStatus() != Status.FINISHED) Thread.yield();
@@ -725,7 +731,9 @@ public void testPerSessionInterpreter() throws IOException {
725731
Paragraph p2 = note2.addParagraph();
726732

727733
p1.setText("getId");
734+
p1.setAuthenticationInfo(anonymous);
728735
p2.setText("getId");
736+
p2.setAuthenticationInfo(anonymous);
729737

730738
// run per note session disabled
731739
note1.run(p1.getId());
@@ -740,6 +748,7 @@ public void testPerSessionInterpreter() throws IOException {
740748
// restart interpreter with per note session enabled
741749
for (InterpreterSetting setting : notebook.getInterpreterFactory().getInterpreterSettings(note1.getId())) {
742750
setting.getOption().setSession(true);
751+
setting.getOption().setPerNote(true);
743752
notebook.getInterpreterFactory().restart(setting.getId());
744753
}
745754

0 commit comments

Comments
 (0)