Beispiel #1
0
    def test_default_protobuf_serialization(self):
        """Test that the default Protobuf serialization works."""
        message_bytes = ProtobufSerializer().encode(self.message)
        envelope = Envelope(
            to="receiver",
            sender="sender",
            protocol_id=UNKNOWN_PROTOCOL_PUBLIC_ID,
            message=message_bytes,
        )
        envelope_bytes = envelope.encode()

        expected_envelope = Envelope.decode(envelope_bytes)
        actual_envelope = envelope
        assert expected_envelope == actual_envelope

        expected_msg = ProtobufSerializer().decode(expected_envelope.message)
        actual_msg = self.message
        assert expected_msg == actual_msg
Beispiel #2
0
def test_inbox_nowait():
    """Tests the inbox without waiting."""
    msg = Message(content="hello")
    message_bytes = ProtobufSerializer().encode(msg)
    multiplexer = Multiplexer([DummyConnection()])
    envelope = Envelope(to="Agent1",
                        sender="Agent0",
                        protocol_id="my_own_protocol",
                        message=message_bytes)
    multiplexer.in_queue.put(envelope)
    inbox = InBox(multiplexer)
    assert inbox.get_nowait(
    ) == envelope, "Check for a message on the in queue and wait for no time."
Beispiel #3
0
def test_inbox_get():
    """Tests for a envelope on the in queue."""
    msg = Message(content="hello")
    message_bytes = ProtobufSerializer().encode(msg)
    multiplexer = Multiplexer([DummyConnection()])
    envelope = Envelope(to="Agent1",
                        sender="Agent0",
                        protocol_id="my_own_protocol",
                        message=message_bytes)
    multiplexer.in_queue.put(envelope)
    inbox = InBox(multiplexer)

    assert inbox.get(
    ) == envelope, "Checks if the returned envelope is the same with the queued envelope."
Beispiel #4
0
def test_outbox_put():
    """Tests that an envelope is putted into the queue."""
    msg = Message(content="hello")
    message_bytes = ProtobufSerializer().encode(msg)
    my_queue = Queue()
    envelope = Envelope(to="Agent1",
                        sender="Agent0",
                        protocol_id="my_own_protocol",
                        message=message_bytes)
    my_queue.put(envelope)
    _outbox = OutBox(my_queue)
    _outbox.put(envelope)
    assert _outbox.empty() is False,\
        "Oubox must not be empty after putting an envelope"
Beispiel #5
0
def test_inbox_get():
    """Tests for a envelope on the in queue."""
    msg = Message(content="hello")
    message_bytes = ProtobufSerializer().encode(msg)
    my_queue = Queue()
    envelope = Envelope(to="Agent1",
                        sender="Agent0",
                        protocol_id="my_own_protocol",
                        message=message_bytes)
    my_queue.put(envelope)
    _inbox = InBox(my_queue)

    assert _inbox.get() == envelope,\
        "Checks if the returned envelope is the same with the queued envelope."
Beispiel #6
0
def test_inbox_nowait():
    """Tests the inbox without waiting."""
    msg = Message(content="hello")
    message_bytes = ProtobufSerializer().encode(msg)
    multiplexer = Multiplexer([_make_dummy_connection()])
    envelope = Envelope(
        to="Agent1",
        sender="Agent0",
        protocol_id=UNKNOWN_PROTOCOL_PUBLIC_ID,
        message=message_bytes,
    )
    multiplexer.in_queue.put(envelope)
    inbox = InBox(multiplexer)
    assert (inbox.get_nowait() == envelope
            ), "Check for a message on the in queue and wait for no time."
Beispiel #7
0
def test_inbox_get():
    """Tests for a envelope on the in queue."""
    msg = Message(content="hello")
    message_bytes = ProtobufSerializer().encode(msg)
    multiplexer = Multiplexer([_make_dummy_connection()])
    envelope = Envelope(
        to="Agent1",
        sender="Agent0",
        protocol_id=UNKNOWN_PROTOCOL_PUBLIC_ID,
        message=message_bytes,
    )
    multiplexer.in_queue.put(envelope)
    inbox = InBox(multiplexer)

    assert (
        inbox.get() == envelope
    ), "Checks if the returned envelope is the same with the queued envelope."