Search in sources :

Example 1 with MessageHolder

use of com.twosigma.beakerx.kernel.msg.MessageHolder in project beakerx by twosigma.

the class MessageCreatorNoResultTest method noResult.

@Test
public void noResult() throws Exception {
    // given
    SimpleEvaluationObject seo = new SimpleEvaluationObject("code");
    seo.setJupyterMessage(new Message());
    seo.finished(OutputCell.HIDDEN);
    // when
    List<MessageHolder> messages = MessageCreator.createMessage(seo);
    // then
    messages.forEach(m -> assertThat(JupyterMessages.EXECUTE_RESULT).isNotEqualTo(m.getMessage().type()));
}
Also used : MessageHolder(com.twosigma.beakerx.kernel.msg.MessageHolder) Message(com.twosigma.beakerx.message.Message) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 2 with MessageHolder

use of com.twosigma.beakerx.kernel.msg.MessageHolder in project beakerx by twosigma.

the class MessageCreatorTest method createMessageWithNotNullResult_shouldReturnResult.

@Test
public void createMessageWithNotNullResult_shouldReturnResult() throws Exception {
    // given
    seo.finished("NotNullResult");
    // when
    List<MessageHolder> message = MessageCreator.createMessage(seo);
    // then
    Map data = TestWidgetUtils.getData(message.get(0).getMessage());
    assertThat(data.get(MessageCreator.TEXT_PLAIN)).isEqualTo("NotNullResult");
}
Also used : MessageHolder(com.twosigma.beakerx.kernel.msg.MessageHolder) Map(java.util.Map) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 3 with MessageHolder

use of com.twosigma.beakerx.kernel.msg.MessageHolder in project beakerx by twosigma.

the class MessageCreatorTest method createMessageForCollection.

// @Test
public void createMessageForCollection() throws Exception {
    // given
    seo.finished(asList("1", "2"));
    // when
    List<MessageHolder> message = MessageCreator.createMessage(seo);
    // then
    Map data = TestWidgetUtils.getData(message.get(0).getMessage());
    assertThat(data.get(MessageCreator.TEXT_PLAIN)).isEqualTo("[\"1\",\"2\"]");
}
Also used : MessageHolder(com.twosigma.beakerx.kernel.msg.MessageHolder) Map(java.util.Map)

Example 4 with MessageHolder

use of com.twosigma.beakerx.kernel.msg.MessageHolder in project beakerx by twosigma.

the class MessageCreatorTest method createMessageWithNullResult_shouldReturnNullStringForNull.

@Test
public void createMessageWithNullResult_shouldReturnNullStringForNull() throws Exception {
    // given
    seo.finished(null);
    // when
    List<MessageHolder> message = MessageCreator.createMessage(seo);
    // then
    Map data = TestWidgetUtils.getData(message.get(0).getMessage());
    assertThat(data.get(MessageCreator.TEXT_PLAIN)).isEqualTo(NULL_RESULT);
}
Also used : MessageHolder(com.twosigma.beakerx.kernel.msg.MessageHolder) Map(java.util.Map) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 5 with MessageHolder

use of com.twosigma.beakerx.kernel.msg.MessageHolder in project beakerx by twosigma.

the class ExecutionResultSender method update.

@Override
public synchronized void update(Observable o, Object arg) {
    SimpleEvaluationObject seo = (SimpleEvaluationObject) o;
    if (seo != null) {
        List<MessageHolder> message = MessageCreator.createMessage(seo);
        message.forEach(job -> {
            if (SocketEnum.IOPUB_SOCKET.equals(job.getSocketType())) {
                kernel.publish(singletonList(job.getMessage()));
            } else if (SocketEnum.SHELL_SOCKET.equals(job.getSocketType())) {
                kernel.send(job.getMessage());
            }
        });
    }
}
Also used : MessageHolder(com.twosigma.beakerx.kernel.msg.MessageHolder) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject)

Aggregations

MessageHolder (com.twosigma.beakerx.kernel.msg.MessageHolder)5 KernelTest (com.twosigma.beakerx.KernelTest)3 Map (java.util.Map)3 Test (org.junit.Test)3 SimpleEvaluationObject (com.twosigma.beakerx.jvm.object.SimpleEvaluationObject)2 Message (com.twosigma.beakerx.message.Message)1