def test_004_service_rpc(self):
        cb_called = [False
                     ]  # So that cb_called[0] is mutable in inner function
        p = {"test": "foo"}

        def cb(f, t, msg, arg):
            cb_called[0] = True
            self.assertEqual(msg.payload, p)
            f.reactor_stop()

        w2 = self.f.msg_watcher_create(cb, FLUX_MSGTYPE_RESPONSE, "foo.echo")
        w2.start()
        self.assertIsNotNone(w2, msg="msg_watcher_create response handler")

        m = Message()
        m.topic = "foo.echo"
        m.payload = p
        self.assertTrue(m is not None)
        ret = self.f.send(m)
        self.assertEqual(ret, 0)

        ret = self.f.reactor_run()
        self.assertTrue(ret >= 0)
        self.assertTrue(cb_called[0])
        w2.stop()
        w2.destroy()
    def test_004_service_rpc(self):
        cb_called = [False]  # So that cb_called[0] is mutable in inner function
        p = {"test": "foo"}

        def cb(f, t, msg, arg):
            cb_called[0] = True
            self.assertEqual(msg.payload, p)
            f.reactor_stop(f.get_reactor())

        w2 = self.f.msg_watcher_create(cb, FLUX_MSGTYPE_RESPONSE, "foo.echo")
        w2.start()
        self.assertIsNotNone(w2, msg="msg_watcher_create response handler")

        m = Message()
        m.topic = "foo.echo"
        m.payload = p
        self.assertTrue(m is not None)
        ret = self.f.send(m)
        self.assertEqual(ret, 0)

        ret = self.f.reactor_run(self.f.get_reactor(), 0)
        self.assertTrue(ret >= 0)
        self.assertTrue(cb_called[0])
        w2.stop()
        w2.destroy()
Exemplo n.º 3
0
    def event_create(self, topic, payload=None):
        """ Create a new event message.

        :param topic: A string, the event's topic
        :param payload: If a string, the payload is used unmodified, if it is another type json.dumps() is used to stringify it
        """
        return Message.from_event_encode(topic, payload)
Exemplo n.º 4
0
    def event_create(self, topic, payload=None):
        """ Create a new event message.

        :param topic: A string, the event's topic
        :param payload: If a string, the payload is used unmodified, if it is another type json.dumps() is used to stringify it
        """
        return Message.from_event_encode(topic, payload)
Exemplo n.º 5
0
 def recv(self,
          type_mask=raw.FLUX_MSGTYPE_ANY,
          match_tag=raw.FLUX_MATCHTAG_NONE,
          topic_glob=None,
          flags=0):
     """
     Receive a message, returns a flux.Message containing the result or None
     """
     match = ffi.new(
         'struct flux_match *', {
             'typemask': type_mask,
             'matchtag': match_tag,
             'topic_glob':
             topic_glob if topic_glob is not None else ffi.NULL,
         })
     handle = self.flux_recv(match[0], flags)
     if handle is not None:
         return Message(handle=handle)
     else:  # pragma: no cover
         return None
Exemplo n.º 6
0
 def recv(
     self,
     type_mask=raw.FLUX_MSGTYPE_ANY,
     match_tag=raw.FLUX_MATCHTAG_NONE,
     topic_glob=None,
     flags=0,
 ):
     """
     Receive a message, returns a flux.Message containing the result or None
     """
     match = ffi.new(
         "struct flux_match *",
         {
             "typemask": type_mask,
             "matchtag": match_tag,
             "topic_glob": topic_glob if topic_glob is not None else ffi.NULL,
         },
     )
     handle = self.flux_recv(match[0], flags)
     if handle is not None:
         return Message(handle=handle)
     return None