use of org.apache.zeppelin.display.AngularObjectRegistry in project zeppelin by apache.
the class NotebookTest method testAngularObjectRemovalOnNotebookRemove.
@Test
public void testAngularObjectRemovalOnNotebookRemove() throws InterruptedException, IOException {
// create a note and a paragraph
Note note = notebook.createNote(anonymous);
interpreterSettingManager.setInterpreters(anonymous.getUser(), note.getId(), interpreterSettingManager.getDefaultInterpreterSettingList());
AngularObjectRegistry registry = interpreterSettingManager.getInterpreterSettings(note.getId()).get(0).getInterpreterGroup(anonymous.getUser(), "sharedProcess").getAngularObjectRegistry();
Paragraph p1 = note.addParagraph(AuthenticationInfo.ANONYMOUS);
// add paragraph scope object
registry.add("o1", "object1", note.getId(), p1.getId());
// add notebook scope object
registry.add("o2", "object2", note.getId(), null);
// add global scope object
registry.add("o3", "object3", null, null);
// remove notebook
notebook.removeNote(note.getId(), anonymous);
// notebook scope or paragraph scope object should be removed
assertNull(registry.get("o1", note.getId(), null));
assertNull(registry.get("o2", note.getId(), p1.getId()));
// global object sould be remained
assertNotNull(registry.get("o3", null, null));
}
use of org.apache.zeppelin.display.AngularObjectRegistry in project zeppelin by apache.
the class NotebookTest method testAngularObjectRemovalOnInterpreterRestart.
@Test
public void testAngularObjectRemovalOnInterpreterRestart() throws InterruptedException, IOException {
// create a note and a paragraph
Note note = notebook.createNote(anonymous);
interpreterSettingManager.setInterpreters(anonymous.getUser(), note.getId(), interpreterSettingManager.getDefaultInterpreterSettingList());
AngularObjectRegistry registry = interpreterSettingManager.getInterpreterSettings(note.getId()).get(0).getInterpreterGroup(anonymous.getUser(), "sharedProcess").getAngularObjectRegistry();
// add local scope object
registry.add("o1", "object1", note.getId(), null);
// add global scope object
registry.add("o2", "object2", null, null);
// restart interpreter
interpreterSettingManager.restart(interpreterSettingManager.getInterpreterSettings(note.getId()).get(0).getId());
registry = interpreterSettingManager.getInterpreterSettings(note.getId()).get(0).getInterpreterGroup(anonymous.getUser(), "sharedProcess").getAngularObjectRegistry();
// local and global scope object should be removed
// But InterpreterGroup does not implement angularObjectRegistry per session (scoped, isolated)
// So for now, does not have good way to remove all objects in particular session on restart.
assertNotNull(registry.get("o1", note.getId(), null));
assertNotNull(registry.get("o2", null, null));
notebook.removeNote(note.getId(), anonymous);
}
use of org.apache.zeppelin.display.AngularObjectRegistry in project zeppelin by apache.
the class InterpreterLogicTest method should_extract_variable_and_choices.
@Test
public void should_extract_variable_and_choices() throws Exception {
//Given
AngularObjectRegistry angularObjectRegistry = new AngularObjectRegistry("cassandra", null);
when(intrContext.getAngularObjectRegistry()).thenReturn(angularObjectRegistry);
when(intrContext.getGui().select(eq("name"), eq("'Paul'"), optionsCaptor.capture())).thenReturn("'Jack'");
//When
final String actual = helper.maybeExtractVariables("SELECT * FROM zeppelin.artists WHERE name={{name='Paul'|'Jack'|'Smith'}}", intrContext);
//Then
assertThat(actual).isEqualTo("SELECT * FROM zeppelin.artists WHERE name='Jack'");
final List<ParamOption> paramOptions = asList(optionsCaptor.getValue());
assertThat(paramOptions.get(0).getValue()).isEqualTo("'Paul'");
assertThat(paramOptions.get(1).getValue()).isEqualTo("'Jack'");
assertThat(paramOptions.get(2).getValue()).isEqualTo("'Smith'");
}
use of org.apache.zeppelin.display.AngularObjectRegistry in project zeppelin by apache.
the class InterpreterLogicTest method should_extract_variable_from_angular_object_registry.
@Test
public void should_extract_variable_from_angular_object_registry() throws Exception {
//Given
AngularObjectRegistry angularObjectRegistry = new AngularObjectRegistry("cassandra", null);
angularObjectRegistry.add("id", "from_angular_registry", "noteId", "paragraphId");
when(intrContext.getAngularObjectRegistry()).thenReturn(angularObjectRegistry);
when(intrContext.getNoteId()).thenReturn("noteId");
when(intrContext.getParagraphId()).thenReturn("paragraphId");
//When
final String actual = helper.maybeExtractVariables("SELECT * FROM zeppelin.demo WHERE id='{{id=John}}'", intrContext);
//Then
assertThat(actual).isEqualTo("SELECT * FROM zeppelin.demo WHERE id='from_angular_registry'");
verify(intrContext, never()).getGui();
}
use of org.apache.zeppelin.display.AngularObjectRegistry in project zeppelin by apache.
the class InterpreterLogicTest method should_extract_variable_and_default_value.
@Test
public void should_extract_variable_and_default_value() throws Exception {
//Given
AngularObjectRegistry angularObjectRegistry = new AngularObjectRegistry("cassandra", null);
when(intrContext.getAngularObjectRegistry()).thenReturn(angularObjectRegistry);
when(intrContext.getGui().input("table", "zeppelin.demo")).thenReturn("zeppelin.demo");
when(intrContext.getGui().input("id", "'John'")).thenReturn("'John'");
//When
final String actual = helper.maybeExtractVariables("SELECT * FROM {{table=zeppelin.demo}} WHERE id={{id='John'}}", intrContext);
//Then
assertThat(actual).isEqualTo("SELECT * FROM zeppelin.demo WHERE id='John'");
}
Aggregations