def test_on_offered_incompatible_qos(manual_setup, hitpoint):
    class MyListener(Listener):
        def on_offered_incompatible_qos(self, writer, status):
            hitpoint.hit()

    wqos = Qos(Policy.Durability.Volatile)
    rqos = Qos(Policy.Durability.Transient)

    datawriter = manual_setup.dw(qos=wqos, listener=MyListener())
    manual_setup.dr(qos=rqos)

    datawriter.write(manual_setup.msg)

    assert hitpoint.was_hit()
def test_liveliness(manual_setup, hitpoint_factory):
    handler = hitpoint_factory()
    alive = hitpoint_factory()
    notalive = hitpoint_factory()

    class MyListenerWriter(Listener):
        def on_liveliness_lost(self, writer, status):
            handler.hit(data=timestamp.now())

    class MyListenerReader(Listener):
        def on_liveliness_changed(self, reader, status):
            if status.alive_count == 1:
                alive.hit(data=status.alive_count_change)
            else:
                notalive.hit(data=status.alive_count_change)

    qos = Qos(Policy.Liveliness.ManualByTopic(duration(seconds=0.2)),
              Policy.Ownership.Exclusive)

    manual_setup.tp(qos=qos)
    manual_setup.dr(listener=MyListenerReader())
    datawriter = manual_setup.dw(listener=MyListenerWriter())

    write_time = timestamp.now()
    datawriter.write(manual_setup.msg)

    assert handler.was_hit()
    assert handler.data - write_time >= duration(seconds=0.2)
    assert alive.was_hit() and alive.data == 1
    assert notalive.was_hit() and notalive.data == -1
Ejemplo n.º 3
0
    async def test_inner():
        qos = Qos(Policy.OwnershipStrength(10),
                  Policy.Userdata("Old".encode()))
        dp = DomainParticipant(0)
        tp = Topic(dp, "MessageTopic", Message)
        dw = DataWriter(dp, tp, qos=qos)
        await asyncio.sleep(0.5)

        old_qos = dw.get_qos()
        await asyncio.sleep(0.5)

        new_qos = Qos(Policy.OwnershipStrength(20),
                      Policy.Userdata("New".encode()))
        dw.set_qos(new_qos)

        await asyncio.sleep(0.5)

        return dp, tp, dw, old_qos, new_qos
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 6
0
    def check_entity_qos(self, entity, eqos_mapper, qos):
        eq = []
        for q in qos:
            policy_scope = f"Policy.{q.__scope__}"

            if policy_scope in eqos_mapper:
                eq.append(q)
            elif self.entity != "all" and self.entity is not None:
                warnings.warn(
                    f"The {q} is not applicable for {entity}, will be ignored.",
                    InapplicableQosWarning)
        return Qos(*eq)
def test_on_requested_deadline_missed(manual_setup, hitpoint):
    class MyListener(Listener):
        def on_requested_deadline_missed(self, reader, status):
            hitpoint.hit(data=timestamp.now())

    qos = Qos(Policy.Deadline(duration(seconds=0.2)))
    datawriter = manual_setup.dw(qos=qos)
    manual_setup.dr(qos=qos, listener=MyListener())

    write_time = timestamp.now()
    datawriter.write(manual_setup.msg)

    assert hitpoint.was_hit()
    assert hitpoint.data - write_time >= duration(seconds=0.2)
Ejemplo n.º 8
0
def test_on_sample_rejected(manual_setup, hitpoint):
    class MyListener(Listener):
        def on_sample_rejected(self, reader, status):
            hitpoint.hit()

    qos = Qos(Policy.ResourceLimits(max_samples=1))

    datawriter = manual_setup.dw()
    manual_setup.dr(qos=qos, listener=MyListener())

    datawriter.write(manual_setup.msg)
    assert hitpoint.was_not_hit()

    datawriter.write(manual_setup.msg2)
    assert hitpoint.was_hit()
def test_on_sample_lost(manual_setup, hitpoint):
    class MyListener(Listener):
        def on_sample_lost(self, reader, status):
            hitpoint.hit()

    qos = Qos(Policy.DestinationOrder.BySourceTimestamp)

    datawriter = manual_setup.dw(qos=qos)
    datareader = manual_setup.dr(qos=qos, listener=MyListener())

    t1 = timestamp.now()
    t2 = t1 + duration(seconds=1)

    datawriter.write(manual_setup.msg, timestamp=t2)
    datareader.take()
    datawriter.write(manual_setup.msg, timestamp=t1)

    assert hitpoint.was_hit()
def test_on_sample_rejected(manual_setup, hitpoint):
    class MyListener(Listener):
        def on_sample_rejected(self, reader, status):
            hitpoint.hit()

    qos = Qos(
        Policy.ResourceLimits(max_samples=1,
                              max_instances=1,
                              max_samples_per_instance=1),
        Policy.Durability.Transient, Policy.History.KeepAll)

    datawriter = manual_setup.dw(qos=qos, listener=MyListener())
    manual_setup.dr(qos=qos, listener=MyListener())

    datawriter.write(manual_setup.msg)
    assert hitpoint.was_not_hit()

    datawriter.write(manual_setup.msg2)
    assert hitpoint.was_hit()
import time
import random

from cyclonedds.core import Qos, Policy
from cyclonedds.domain import DomainParticipant
from cyclonedds.pub import Publisher, DataWriter
from cyclonedds.topic import Topic
from cyclonedds.util import duration

from vehicles import Vehicle

qos = Qos(Policy.Reliability.BestEffort,
          Policy.Deadline(duration(microseconds=10)),
          Policy.Durability.Transient, Policy.History.KeepLast(10))

domain_participant = DomainParticipant(0)
topic = Topic(domain_participant, 'Vehicle', Vehicle, qos=qos)
publisher = Publisher(domain_participant)
writer = DataWriter(publisher, topic)

cart = Vehicle(name="Dallara IL-15", x=200, y=200)

while True:
    cart.x += random.choice([-1, 0, 1])
    cart.y += random.choice([-1, 0, 1])
    writer.write(cart)
    print(">> Wrote vehicle")
    time.sleep(random.random() * 0.9 + 0.1)
Ejemplo n.º 12
0
import time


@cdr
class hello:
    x: int


def change_qos(qos):
    writer.set_qos(qos)
    print(qos.asdict())


sample = "hi"
qos = Qos(Policy.Userdata(data=sample.encode()), Policy.OwnershipStrength(10))

domain_participant = DomainParticipant(0)
topic = Topic(domain_participant, "hello", hello)
publisher = Publisher(domain_participant)
writer = DataWriter(publisher, topic, qos=qos)
print(qos.asdict())
time.sleep(3)

qos = Qos(Policy.OwnershipStrength(20))
change_qos(qos)

sample = input("input new user data: ")
qos = Qos(Policy.Userdata(data=sample.encode()))
change_qos(qos)
time.sleep(5)
Ejemplo n.º 13
0
def test_parse_qos():
    tests = \
    [
        (
            [
                "Reliability.Reliable 10000000",
                "Durability.TransientLocal",
                "History.KeepLast 10",
                "ResourceLimits 100 -1 100",
                "PresentationAccessScope.Topic True False",
                "Lifespan 1000000",
                "Deadline seconds=1",
                "LatencyBudget 10000000",
                "Ownership.Exclusive",
                "OwnershipStrength 20",
                "Liveliness.ManualByParticipant 100000",
                "TimeBasedFilter 100000",
                "Partition Hello, world",
                "TransportPriority 1",
                "DestinationOrder.BySourceTimestamp",
                "WriterDataLifecycle False",
                "ReaderDataLifecycle 10000000 10000000",
                "DurabilityService 100000 History.KeepLast 100, 2000, 1000, 1000",
                "Userdata HiUser",
                "Groupdata HiGroup",
                "Topicdata HiTopic"
            ],
            Qos(
                Policy.Reliability.Reliable(max_blocking_time=10000000),
                Policy.Durability.TransientLocal,
                Policy.History.KeepLast(depth=10),
                Policy.ResourceLimits(max_samples=100, max_instances=-1, max_samples_per_instance=100),
                Policy.PresentationAccessScope.Topic(coherent_access=True, ordered_access=False),
                Policy.Lifespan(lifespan=1000000),
                Policy.Deadline(deadline=1000000000),
                Policy.LatencyBudget(budget=10000000),
                Policy.Ownership.Exclusive,
                Policy.OwnershipStrength(strength=20),
                Policy.Liveliness.ManualByParticipant(lease_duration=100000),
                Policy.TimeBasedFilter(filter_time=100000),
                Policy.Partition(partitions=('Hello', 'world')),
                Policy.TransportPriority(priority=1),
                Policy.DestinationOrder.BySourceTimestamp,
                Policy.WriterDataLifecycle(autodispose=False),
                Policy.ReaderDataLifecycle(autopurge_nowriter_samples_delay=10000000, autopurge_disposed_samples_delay=10000000),
                Policy.DurabilityService(cleanup_delay=100000, history=Policy.History.KeepLast(depth=100),
                                            max_samples=2000, max_instances=1000, max_samples_per_instance=1000),
                Policy.Userdata(data=b'HiUser'),
                Policy.Groupdata(data=b'HiGroup'),
                Policy.Topicdata(data=b'HiTopic'),
            )
        )
    ]

    for (input, result) in tests:
        pubsub, ddsls = run_pubsub_ddsls(["-T", "test", "-q", ' '.join(input)],
                                         ["-a"],
                                         runtime=2)
        for policy in result:
            assert str(policy) in ddsls["stdout"]

        assert pubsub["status"] == 0
Ejemplo n.º 14
0
def test_scoped_qos(common_setup):
    with pytest.raises(TypeError):
        DomainParticipant(qos=Qos().topic())
    DomainParticipant(qos=Qos().domain_participant())

    with pytest.raises(TypeError):
        Topic(common_setup.dp,
              'Message',
              Message,
              qos=Qos().domain_participant())
    Topic(common_setup.dp, 'Message', Message, qos=Qos().topic())

    with pytest.raises(TypeError):
        Publisher(common_setup.dp, qos=Qos().subscriber())
    Publisher(common_setup.dp, qos=Qos().publisher())

    with pytest.raises(TypeError):
        Subscriber(common_setup.dp, qos=Qos().publisher())
    Subscriber(common_setup.dp, qos=Qos().subscriber())

    with pytest.raises(TypeError):
        DataWriter(common_setup.pub, common_setup.tp, qos=Qos().datareader())
    DataWriter(common_setup.pub, common_setup.tp, qos=Qos().datawriter())

    with pytest.raises(TypeError):
        DataReader(common_setup.sub, common_setup.tp, qos=Qos().datawriter())
    DataReader(common_setup.sub, common_setup.tp, qos=Qos().datareader())