Ejemplo n.º 1
0
        public void TestOnOfferedDeadlineMissed()
        {
            DataWriter writer             = null;
            int        totalCount         = 0;
            int        totalCountChange   = 0;
            var        lastInstanceHandle = InstanceHandle.HandleNil;

            // Attach to the event
            int count = 0;

            _listener.OfferedDeadlineMissed += (w, s) =>
            {
                writer             = w;
                totalCount         = s.TotalCount;
                totalCountChange   = s.TotalCountChange;
                lastInstanceHandle = s.LastInstanceHandle;
                count++;
            };

            // Prepare QoS for the test
            DataWriterQos dwQos = new DataWriterQos();

            dwQos.Deadline.Period = new Duration {
                Seconds = 1
            };
            ReturnCode result = _writer.SetQos(dwQos);

            Assert.AreEqual(ReturnCode.Ok, result);

            // Enable entities
            result = _writer.Enable();
            Assert.AreEqual(ReturnCode.Ok, result);

            result = _reader.Enable();
            Assert.AreEqual(ReturnCode.Ok, result);

            // Wait for discovery and write an instance
            bool found = _writer.WaitForSubscriptions(1, 1000);

            Assert.IsTrue(found);

            _dataWriter.Write(new TestStruct {
                Id = 1
            });

            // After half second deadline should not be lost yet
            System.Threading.Thread.Sleep(500);
            Assert.AreEqual(0, count);

            // After one second and a half one deadline should be lost
            System.Threading.Thread.Sleep(1000);
            Assert.AreEqual(1, count);
            Assert.AreEqual(_writer, writer);
            Assert.AreEqual(1, totalCount);
            Assert.AreEqual(1, totalCountChange);

            // Remove the listener to avoid extra messages
            result = _publisher.SetListener(null);
            Assert.AreEqual(ReturnCode.Ok, result);
        }
Ejemplo n.º 2
0
        public void TestOnRequestedIncompatibleQos()
        {
            int        count                      = 0;
            DataReader dr                         = null;
            int        totalCount                 = 0;
            int        totalCountChange           = 0;
            int        lastPolicyId               = 0;
            ICollection <QosPolicyCount> policies = new List <QosPolicyCount>();

            // Attach to the event
            _listener.RequestedIncompatibleQos += (r, s) =>
            {
                dr               = r;
                totalCount       = s.TotalCount;
                totalCountChange = s.TotalCountChange;
                lastPolicyId     = s.LastPolicyId;
                policies         = s.Policies;

                count++;
            };

            // Create a incompatible DataWriter
            DataWriterQos dwQos = new DataWriterQos();

            dwQos.Reliability.Kind = ReliabilityQosPolicyKind.BestEffortReliabilityQos;
            DataWriter otherDataWriter = _publisher.CreateDataWriter(_topic, dwQos);

            Assert.IsNotNull(otherDataWriter);

            // Enable entities
            ReturnCode result = _writer.Enable();

            Assert.AreEqual(ReturnCode.Ok, result);

            result = _reader.Enable();
            Assert.AreEqual(ReturnCode.Ok, result);

            result = otherDataWriter.Enable();
            Assert.AreEqual(ReturnCode.Ok, result);

            // Wait for discovery
            bool found = _writer.WaitForSubscriptions(1, 1000);

            Assert.IsTrue(found);

            // Check the number of incompatible DataWriter
            Thread.Sleep(100);
            Assert.AreEqual(1, count);
            Assert.AreEqual(_reader, dr);
            Assert.AreEqual(1, totalCount);
            Assert.AreEqual(1, totalCountChange);
            Assert.AreEqual(11, lastPolicyId);
            Assert.IsNotNull(policies);
            Assert.AreEqual(1, policies.Count);
            Assert.AreEqual(1, policies.First().Count);
            Assert.AreEqual(11, policies.First().PolicyId);
        }
Ejemplo n.º 3
0
        public void TestOnDataOnReaders()
        {
            Subscriber subscriber = null;

            // Attach to the event
            int count = 0;

            _listener.DataOnReaders += (s) =>
            {
                subscriber = s;
                count++;
            };

            // Enable entities
            ReturnCode result = _writer.Enable();

            Assert.AreEqual(ReturnCode.Ok, result);

            result = _reader.Enable();
            Assert.AreEqual(ReturnCode.Ok, result);

            // Wait for discovery
            bool found = _writer.WaitForSubscriptions(1, 1000);

            Assert.IsTrue(found);

            // Write some instances
            int total = 5;

            for (int i = 1; i <= total; i++)
            {
                result = _dataWriter.Write(new TestStruct
                {
                    Id = i,
                });
                Assert.AreEqual(ReturnCode.Ok, result);

                result = _dataWriter.WaitForAcknowledgments(new Duration {
                    Seconds = 5
                });
                Assert.AreEqual(ReturnCode.Ok, result);
            }

            System.Threading.Thread.Sleep(100);

            Assert.AreEqual(total, count);
            Assert.IsNotNull(subscriber);
            Assert.AreEqual(_subscriber, subscriber);
        }
        public void TestOnRequestedIncompatibleQos()
        {
            // Attach to the event
            int count = 0;

            _listener.RequestedIncompatibleQos += (r, s) =>
            {
                Assert.AreEqual(_reader, r);
                Assert.AreEqual(1, s.TotalCount);
                Assert.AreEqual(1, s.TotalCountChange);
                Assert.AreEqual(11, s.LastPolicyId);
                Assert.IsNotNull(s.Policies);
                Assert.AreEqual(1, s.Policies.Count());
                Assert.AreEqual(1, s.Policies.First().Count);
                Assert.AreEqual(11, s.Policies.First().PolicyId);
                count++;
            };

            // Create a incompatible DataWriter
            DataWriterQos dwQos = new DataWriterQos();

            dwQos.Reliability.Kind = ReliabilityQosPolicyKind.BestEffortReliabilityQos;
            DataWriter otherDataWriter = _publisher.CreateDataWriter(_topic, dwQos);

            Assert.IsNotNull(otherDataWriter);

            // Enable entities
            ReturnCode result = _writer.Enable();

            Assert.AreEqual(ReturnCode.Ok, result);

            result = _reader.Enable();
            Assert.AreEqual(ReturnCode.Ok, result);

            result = otherDataWriter.Enable();
            Assert.AreEqual(ReturnCode.Ok, result);

            // Wait for discovery
            bool found = _writer.WaitForSubscriptions(1, 1000);

            Assert.IsTrue(found);

            // Check the number of incompatible DataWriter
            System.Threading.Thread.Sleep(100);
            Assert.AreEqual(1, count);
        }
Ejemplo n.º 5
0
        public void TestOnDataAvailable()
        {
            // Attach to the event
            int count = 0;

            _listener.DataAvailable += (r) =>
            {
                Assert.AreEqual(_reader, r);
                count++;
            };

            // Enable entities
            ReturnCode result = _writer.Enable();

            Assert.AreEqual(ReturnCode.Ok, result);

            result = _reader.Enable();
            Assert.AreEqual(ReturnCode.Ok, result);

            // Wait for discovery
            bool found = _writer.WaitForSubscriptions(1, 1000);

            Assert.IsTrue(found);

            // Write some instances
            for (int i = 1; i <= 5; i++)
            {
                result = _dataWriter.Write(new TestStruct
                {
                    Id = i
                });
                Assert.AreEqual(ReturnCode.Ok, result);

                result = _dataWriter.WaitForAcknowledgments(new Duration {
                    Seconds = 5
                });
                Assert.AreEqual(ReturnCode.Ok, result);
            }

            Thread.Sleep(100);

            Assert.AreEqual(5, count);
        }
Ejemplo n.º 6
0
        public void TestOnInconsistentTopic()
        {
            using (ManualResetEventSlim evt = new ManualResetEventSlim(false))
            {
                Topic topic            = null;
                int   totalCount       = 0;
                int   totalCountChange = 0;

                // Attach to the event
                int count = 0;
                _listener.InconsistentTopic += (t, s) =>
                {
                    topic            = t;
                    totalCount       = s.TotalCount;
                    totalCountChange = s.TotalCountChange;

                    count++;
                    evt.Set();
                };

                // Enable entities
                ReturnCode result = _writer.Enable();
                Assert.AreEqual(ReturnCode.Ok, result);

                SupportProcessHelper supportProcess = new SupportProcessHelper(TestContext);
                Process process = supportProcess.SpawnSupportProcess(SupportTestKind.InconsistentTopicTest);

                // Wait the signal
                bool wait = evt.Wait(20000);
                Assert.IsTrue(wait);
                Assert.AreSame(_topic, topic);
                Assert.AreEqual(1, totalCount);
                Assert.AreEqual(1, totalCountChange);

                // Kill the process
                supportProcess.KillProcess(process);

                Assert.AreEqual(1, count);

                // Remove listener to avoid extra messages
                result = _topic.SetListener(null);
                Assert.AreEqual(ReturnCode.Ok, result);
            }
        }
Ejemplo n.º 7
0
        public void TestSetQos()
        {
            // Create a new DataWriter using the default QoS
            DataWriter dataWriter = _publisher.CreateDataWriter(_topic);

            Assert.IsNotNull(dataWriter);

            // Get the qos to ensure that is using the default properties
            DataWriterQos qos    = new DataWriterQos();
            ReturnCode    result = dataWriter.GetQos(qos);

            Assert.AreEqual(ReturnCode.Ok, result);
            TestHelper.TestDefaultDataWriterQos(qos);

            // Try to change an immutable property
            qos.Ownership.Kind = OwnershipQosPolicyKind.ExclusiveOwnershipQos;
            result             = dataWriter.SetQos(qos);
            Assert.AreEqual(ReturnCode.ImmutablePolicy, result);

            // Change some mutable properties and check them
            qos = new DataWriterQos();
            qos.OwnershipStrength.Value = 100;

            result = dataWriter.SetQos(qos);
            Assert.AreEqual(ReturnCode.Ok, result);

            qos    = new DataWriterQos();
            result = dataWriter.GetQos(qos);
            Assert.AreEqual(ReturnCode.Ok, result);
            Assert.AreEqual(100, qos.OwnershipStrength.Value);

            // Try to set immutable QoS properties before enable the datawriter
            PublisherQos pubQos = new PublisherQos();

            pubQos.EntityFactory.AutoenableCreatedEntities = false;
            result = _publisher.SetQos(pubQos);
            Assert.AreEqual(ReturnCode.Ok, result);

            DataWriter otherDataWriter = _publisher.CreateDataWriter(_topic);

            Assert.IsNotNull(otherDataWriter);

            qos = new DataWriterQos();
            qos.Ownership.Kind = OwnershipQosPolicyKind.ExclusiveOwnershipQos;
            result             = otherDataWriter.SetQos(qos);
            Assert.AreEqual(ReturnCode.Ok, result);

            qos    = new DataWriterQos();
            result = otherDataWriter.GetQos(qos);
            Assert.AreEqual(ReturnCode.Ok, result);
            Assert.AreEqual(OwnershipQosPolicyKind.ExclusiveOwnershipQos, qos.Ownership.Kind);

            result = otherDataWriter.Enable();
            Assert.AreEqual(ReturnCode.Ok, result);

            // Set back the default publisher QoS
            pubQos = new PublisherQos();
            _publisher.SetQos(pubQos);
            Assert.AreEqual(ReturnCode.Ok, result);

            // Test SetQos with null parameter
            result = dataWriter.SetQos(null);
            Assert.AreEqual(ReturnCode.BadParameter, result);
        }