Beispiel #1
0
def test_querycondition_read(common_setup):
    qc = QueryCondition(
        common_setup.dr,
        SampleState.Any | ViewState.Any | InstanceState.NotAliveDisposed,
        lambda msg: msg.message.startswith("Hi"))

    assert not qc.triggered

    messages = [Message(message=f"Hi {i}!")
                for i in range(5)] + [Message(message="Goodbye")]
    for m in messages:
        common_setup.dw.write(m)

    received = common_setup.dr.read(N=6)

    assert messages == received

    common_setup.dw.dispose(messages[5])
    assert not qc.triggered

    common_setup.dw.dispose(messages[1])
    assert qc.triggered

    received = common_setup.dr.read(condition=qc)

    assert len(received) == 1 and received[0] == messages[1]
Beispiel #2
0
def test_regression_write_read_take(common_setup):
    """
        This popped up in early testing, if the refcounting in the C backend is not done right
        the count can become zero between read and take and python frees it.
    """

    common_setup.dw.write(Message(message="Hi!"))
    assert common_setup.dr.read()[0] == Message(message="Hi!")
    assert common_setup.dr.take()[0] == Message(message="Hi!")
Beispiel #3
0
def test_communication_order(common_setup):
    msg1 = Message(message="Hi1!")
    msg2 = Message(message="Hi2!")
    common_setup.dw.write(msg1)
    common_setup.dw.write(msg2)
    result = common_setup.dr.read(N=2)

    assert len(result) == 2
    assert result[0] == msg1
    assert result[1] == msg2
Beispiel #4
0
    def __init__(self, domain_id=0):
        self.qos = Qos(Policy.Reliability.Reliable(duration(seconds=2)), Policy.History.KeepLast(10))

        self.dp = DomainParticipant(domain_id)
        self._tp = None
        self._pub = None
        self._sub = None
        self._dw = None
        self._dr = None
        self.msg = Message(message="hi")
        self.msg2 = Message(message="hi2")
Beispiel #5
0
    def __init__(self, domain_id=0):
        self.qos = Qos(Policy.Reliability.Reliable(duration(seconds=2)), Policy.History.KeepLast(10))

        self.dp = DomainParticipant(domain_id)
        self.tp = Topic(self.dp, 'Message', Message)
        self.pub = Publisher(self.dp)
        self.sub = Subscriber(self.dp)
        self.dw = DataWriter(self.pub, self.tp, qos=self.qos)
        self.dr = DataReader(self.sub, self.tp, qos=self.qos)
        self.msg = Message(message="hi")
        self.msg2 = Message(message="hi2")
def test_reader_keepalive_parents():
    dr = _make_reader_without_saving_deps()

    msg = Message("Hello")
    dw = DataWriter(dr.participant, dr.topic).write(msg)

    assert dr.read_next() == msg
Beispiel #7
0
def test_communication_basic_read(common_setup):
    msg = Message(message="Hi!")
    common_setup.dw.write(msg)
    result = common_setup.dr.read()

    assert len(result) == 1
    assert result[0] == msg
Beispiel #8
0
def test_writeto_writer():
    dp = DomainParticipant(0)
    tp = Topic(dp, "Message", Message)
    pub = Publisher(dp)
    dw = DataWriter(pub, tp)

    msg = Message(message="TestMessage")

    dw.write(msg)
    assert dw.wait_for_acks(duration(seconds=1))
Beispiel #9
0
def test_communication_take_destroys(common_setup):
    msg = Message(message="Hi!")
    common_setup.dw.write(msg)
    result1 = common_setup.dr.read()
    result2 = common_setup.dr.take()
    result3 = common_setup.dr.read()

    assert len(result1) == 1
    assert len(result2) == 1
    assert len(result3) == 0
    assert result1[0] == result2[0] == msg
Beispiel #10
0
def test_reader_readnext_takenext():
    dp = DomainParticipant(0)
    tp = Topic(dp, "Message__DONOTPUBLISH", Message)
    sub = Subscriber(dp)
    pub = Publisher(dp)
    dr = DataReader(sub, tp)
    dw = DataWriter(pub, tp)

    msg = Message("Hello")
    dw.write(msg)

    assert dr.read_next() == msg
    assert dr.read_next() is None
    dw.write(msg)
    assert dr.take_next() == msg
    assert dr.take_next() is None
Beispiel #11
0
def test_reader_readiter():
    dp = DomainParticipant(0)
    tp = Topic(dp, "Message", Message)
    sub = Subscriber(dp)
    pub = Publisher(dp)
    dr = DataReader(sub, tp)
    dw = DataWriter(pub, tp)

    msg = Message("Hello")
    dw.write(msg)

    read = False

    for msgr in dr.read_iter(timeout=duration(milliseconds=10)):
        assert not read
        assert msg == msgr
        read = True
def test_waitset_wait(common_setup):
    ws = WaitSet(common_setup.dp)

    rc1 = ReadCondition(common_setup.dr,
                        ViewState.Any | InstanceState.Any | SampleState.Any)
    ws.attach(rc1)

    assert ws.wait(duration(milliseconds=5)) == 0

    common_setup.dw.write(Message(message="Hi!"))

    assert ws.wait(duration(seconds=1)) == 1

    rc2 = ReadCondition(
        common_setup.dr,
        ViewState.Any | InstanceState.Any | SampleState.NotRead)
    ws.attach(rc2)

    assert ws.wait(duration(seconds=1)) == 2
Beispiel #13
0
def test_readcondition_read(common_setup):
    rc = ReadCondition(
        common_setup.dr,
        SampleState.Any | ViewState.Any | InstanceState.NotAliveDisposed)

    assert not rc.triggered

    messages = [Message(message=f"Hi {i}!") for i in range(5)]
    for m in messages:
        common_setup.dw.write(m)

    received = common_setup.dr.read(N=5)

    assert messages == received

    common_setup.dw.dispose(messages[1])
    assert rc.triggered

    received = common_setup.dr.read(condition=rc)

    assert len(received) == 1 and received[0] == messages[1]