Exemplo 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 = _dataWriter.SetListener(null);
            Assert.AreEqual(ReturnCode.Ok, result);
        }