Search in sources :

Example 21 with Message

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

the class KernelSocketsZMQ method readMessage.

private Message readMessage(ZMQ.Socket socket) {
    ZMsg zmsg = null;
    Message message = new Message();
    try {
        zmsg = ZMsg.recvMsg(socket);
        ZFrame[] parts = new ZFrame[zmsg.size()];
        zmsg.toArray(parts);
        byte[] uuid = parts[MessageParts.UUID].getData();
        byte[] header = parts[MessageParts.HEADER].getData();
        byte[] parent = parts[MessageParts.PARENT].getData();
        byte[] metadata = parts[MessageParts.METADATA].getData();
        byte[] content = parts[MessageParts.CONTENT].getData();
        byte[] expectedSig = parts[MessageParts.HMAC].getData();
        verifyDelim(parts[MessageParts.DELIM]);
        verifySignatures(expectedSig, header, parent, metadata, content);
        if (uuid != null) {
            message.getIdentities().add(uuid);
        }
        message.setHeader(parse(header, Header.class));
        message.setParentHeader(parse(parent, Header.class));
        message.setMetadata(parse(metadata, LinkedHashMap.class));
        message.setContent(parse(content, LinkedHashMap.class));
    } finally {
        if (zmsg != null) {
            zmsg.destroy();
        }
    }
    return message;
}
Also used : ZFrame(org.zeromq.ZFrame) Message(com.twosigma.beakerx.message.Message) Header(com.twosigma.beakerx.message.Header) ZMsg(org.zeromq.ZMsg) LinkedHashMap(java.util.LinkedHashMap)

Example 22 with Message

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

the class PasswordTest method verifyPasswordField.

public static void verifyPasswordField(List<Message> messages, String modelNameValue, String modelModuleValue, String viewNameValue, String viewModuleValue) {
    Message widget = SearchMessages.getListWidgetsByViewName(messages, viewNameValue).get(0);
    Message layout = SearchMessages.getLayoutForWidget(messages, widget);
    verifyTypeMsg(widget, COMM_OPEN);
    Map data = getState(widget);
    assertThat(data.get(LAYOUT)).isEqualTo(IPY_MODEL + layout.getContent().get(Comm.COMM_ID));
    assertThat(data.get(MODEL_NAME)).isEqualTo(modelNameValue);
    assertThat(data.get(MODEL_MODULE)).isEqualTo(modelModuleValue);
    assertThat(data.get(VIEW_NAME)).isEqualTo(viewNameValue);
    assertThat(data.get(VIEW_MODULE)).isEqualTo(viewModuleValue);
}
Also used : Message(com.twosigma.beakerx.message.Message) Map(java.util.Map)

Example 23 with Message

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

the class BeakerxWidgetTest method verifyOpenCommMsgBeakerxWidget.

private void verifyOpenCommMsgBeakerxWidget(List<Message> messages, String modelNameValue, String viewNameValue) {
    assertThat(messages.size()).isEqualTo(1);
    Message widget = messages.get(0);
    assertThat(widget.getHeader().getType()).isEqualTo(COMM_OPEN.getName());
    Map data = TestWidgetUtils.getData(widget);
    assertThat(data.get(Widget.MODEL_MODULE)).isEqualTo(BeakerxWidget.MODEL_MODULE_VALUE);
    assertThat(data.get(Widget.VIEW_MODULE)).isEqualTo(BeakerxWidget.VIEW_MODULE_VALUE);
    assertThat(data.get(Widget.MODEL_NAME)).isEqualTo(modelNameValue);
    assertThat(data.get(Widget.VIEW_NAME)).isEqualTo(viewNameValue);
}
Also used : Message(com.twosigma.beakerx.message.Message) Map(java.util.Map)

Example 24 with Message

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

the class ImageTest method shouldSendCommMsgWhenValueChange.

@Test
public void shouldSendCommMsgWhenValueChange() throws Exception {
    // given
    Image widget = image();
    // when
    widget.setValue("picture".getBytes());
    // then
    Message message = groovyKernel.getPublishedMessages().get(0);
    Map data = getData(message);
    List<List<String>> o = (List) data.get(Comm.BUFFER_PATHS);
    Assertions.assertThat(o.get(0).get(0)).isEqualTo("value");
}
Also used : Message(com.twosigma.beakerx.message.Message) List(java.util.List) Map(java.util.Map) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 25 with Message

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

the class OutputWidgetTest method submitCodeToExecution.

private Message submitCodeToExecution() {
    SimpleEvaluationObject value = new SimpleEvaluationObject("output");
    Message jupyterMessage = new Message();
    value.setJupyterMessage(jupyterMessage);
    InternalVariable.setValue(value);
    return jupyterMessage;
}
Also used : Message(com.twosigma.beakerx.message.Message) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject)

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