Search in sources :

Example 91 with Message

use of com.twosigma.beakerx.message.Message in project beakerx by twosigma.

the class InteractiveTest method getCommWidgetByViewName.

private Comm getCommWidgetByViewName(String viewName) {
    Message widget = SearchMessages.getListWidgetsByViewName(groovyKernel.getPublishedMessages(), viewName).get(0);
    String id = (String) widget.getContent().get(Comm.COMM_ID);
    return groovyKernel.getComm(id);
}
Also used : Message(com.twosigma.beakerx.message.Message)

Example 92 with Message

use of com.twosigma.beakerx.message.Message in project beakerx by twosigma.

the class Interactive method interact.

@SuppressWarnings("unchecked")
public static synchronized void interact(MethodClosure function, Object... parameters) {
    final List<ValueWidget<?>> widgets = widgetsFromAbbreviations(parameters);
    for (ValueWidget<?> widget : widgets) {
        widget.getComm().addMsgCallbackList(widget.new ValueChangeMsgCallbackHandler() {

            private void processCode(Object... params) throws Exception {
                Object call = function.call(getWidgetValues());
                if (call instanceof String || call instanceof Number) {
                    label.setValue(call);
                }
            }

            @Override
            public void updateValue(Object value, Message message) {
                try {
                    processCode();
                } catch (Exception e) {
                    throw new IllegalStateException("Error occurred during updating interactive widget.", e);
                }
            }

            private Object[] getWidgetValues() {
                List<Object> ret = new ArrayList<>(widgets.size());
                for (ValueWidget<?> wid : widgets) {
                    ret.add(wid.getValue());
                }
                return ret.toArray(new Object[ret.size()]);
            }
        });
        logger.info("interact Widget: " + widget.getClass().getName());
    }
    widgets.forEach(Widget::display);
    Object response = function.call(widgets.stream().map(ValueWidget::getValue).toArray());
    if (response instanceof Widget) {
        ((Widget) response).display();
    } else {
        label = new Label();
        label.setValue(response);
        label.display();
    }
}
Also used : ValueWidget(com.twosigma.beakerx.widget.ValueWidget) Message(com.twosigma.beakerx.message.Message) Widget(com.twosigma.beakerx.widget.Widget) ValueWidget(com.twosigma.beakerx.widget.ValueWidget) Label(com.twosigma.beakerx.widget.Label) List(java.util.List) ArrayList(java.util.ArrayList)

Example 93 with Message

use of com.twosigma.beakerx.message.Message in project beakerx by twosigma.

the class GroovyCompleteHandlerTest method shouldSendCompleteReplyMsgForPrintln.

@Test
public void shouldSendCompleteReplyMsgForPrintln() throws Exception {
    // given
    Message message = autocompleteMsgFor("//parentheses are optional\n" + "System.out.printl \"hey!\"\n" + "println \"no System.out either!\"", 44);
    // when
    completeHandler.handle(message);
    // then
    assertThat(groovyKernel.getSentMessages().size()).isEqualTo(1);
    verifyAutocompleteMsg(groovyKernel.getSentMessages().get(0), 38, 44);
}
Also used : Message(com.twosigma.beakerx.message.Message) Test(org.junit.Test) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest)

Example 94 with Message

use of com.twosigma.beakerx.message.Message in project beakerx by twosigma.

the class GroovyCompleteHandlerTest method autocompleteMsgFor.

private Message autocompleteMsgFor(String code, int curPos) {
    Message message = new Message();
    Map<String, Serializable> content = new HashMap();
    content.put(CompleteHandler.CODE, code);
    content.put(CompleteHandler.CURSOR_POS, curPos);
    message.setContent(content);
    return message;
}
Also used : Serializable(java.io.Serializable) Message(com.twosigma.beakerx.message.Message) HashMap(java.util.HashMap)

Example 95 with Message

use of com.twosigma.beakerx.message.Message in project beakerx by twosigma.

the class JavaKernelInfoHandlerTest method handle_sentMessageHasContent.

@Test
public void handle_sentMessageHasContent() throws Exception {
    // when
    handler.handle(message);
    // then
    Message sentMessage = kernel.getSentMessages().get(0);
    Assertions.assertThat(sentMessage.getContent()).isNotEmpty();
}
Also used : Message(com.twosigma.beakerx.message.Message) MessageTest(com.twosigma.beakerx.message.MessageTest) Test(org.junit.Test)

Aggregations

Message (com.twosigma.beakerx.message.Message)270 Test (org.junit.Test)170 KernelTest (com.twosigma.beakerx.KernelTest)121 EvaluatorResultTestWatcher.waitForIdleMessage (com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForIdleMessage)64 EvaluatorTest (com.twosigma.beakerx.evaluator.EvaluatorTest)57 Code (com.twosigma.beakerx.kernel.Code)55 Serializable (java.io.Serializable)36 MessageFactoryTest.getExecuteRequestMessage (com.twosigma.beakerx.MessageFactoryTest.getExecuteRequestMessage)35 EvaluatorResultTestWatcher.waitForErrorMessage (com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForErrorMessage)28 MessageTest (com.twosigma.beakerx.message.MessageTest)27 Map (java.util.Map)26 HashMap (java.util.HashMap)24 Header (com.twosigma.beakerx.message.Header)23 MessageAssertions.verifyExecuteReplyMessage (com.twosigma.MessageAssertions.verifyExecuteReplyMessage)19 EvaluatorResultTestWatcher.waitForSentMessage (com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForSentMessage)19 PlainCode (com.twosigma.beakerx.kernel.PlainCode)14 KernelExecutionTest (com.twosigma.beakerx.KernelExecutionTest)13 EvaluatorResultTestWatcher.waitForUpdateMessage (com.twosigma.beakerx.evaluator.EvaluatorResultTestWatcher.waitForUpdateMessage)13 LinkedHashMap (java.util.LinkedHashMap)12 SimpleEvaluationObject (com.twosigma.beakerx.jvm.object.SimpleEvaluationObject)11