Search in sources :

Example 21 with AngularObjectRegistry

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));
}
Also used : AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) Test(org.junit.Test)

Example 22 with AngularObjectRegistry

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);
}
Also used : AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) Test(org.junit.Test)

Example 23 with AngularObjectRegistry

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'");
}
Also used : AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) ParamOption(org.apache.zeppelin.display.Input.ParamOption) Test(org.junit.Test)

Example 24 with AngularObjectRegistry

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();
}
Also used : AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) Test(org.junit.Test)

Example 25 with AngularObjectRegistry

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'");
}
Also used : AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) Test(org.junit.Test)

Aggregations

AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)48 Test (org.junit.Test)20 HashMap (java.util.HashMap)19 LinkedList (java.util.LinkedList)18 GUI (org.apache.zeppelin.display.GUI)18 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)18 Properties (java.util.Properties)16 AngularObject (org.apache.zeppelin.display.AngularObject)16 LocalResourcePool (org.apache.zeppelin.resource.LocalResourcePool)16 RemoteAngularObjectRegistry (org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry)11 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)8 File (java.io.File)5 Map (java.util.Map)5 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)5 Note (org.apache.zeppelin.notebook.Note)5 Before (org.junit.Before)5 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)4 MockInterpreterA (org.apache.zeppelin.interpreter.remote.mock.MockInterpreterA)4 Message (org.apache.zeppelin.notebook.socket.Message)4 Job (org.apache.zeppelin.scheduler.Job)4