From 96d04005d253c36f45b72ccbc00c9d5a1b40883e Mon Sep 17 00:00:00 2001 From: jose_morato Date: Wed, 18 Dec 2024 10:35:31 +0100 Subject: [PATCH] Use private publisher --- .../OpenDDSharp.UnitTest/DataReaderCDRTest.cs | 167 +++++++++--------- 1 file changed, 84 insertions(+), 83 deletions(-) diff --git a/Tests/OpenDDSharp.UnitTest/DataReaderCDRTest.cs b/Tests/OpenDDSharp.UnitTest/DataReaderCDRTest.cs index 48dc75f2..27665b8e 100644 --- a/Tests/OpenDDSharp.UnitTest/DataReaderCDRTest.cs +++ b/Tests/OpenDDSharp.UnitTest/DataReaderCDRTest.cs @@ -1883,9 +1883,6 @@ public void TestReadNextInstance() var statusCondition = dataReader.StatusCondition; statusCondition.EnabledStatuses = StatusKind.DataAvailableStatus; - var publisher = _participant.CreatePublisher(); - Assert.IsNotNull(publisher); - var dwQos = new DataWriterQos { Reliability = @@ -1893,95 +1890,95 @@ public void TestReadNextInstance() Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos, }, }; - var writer = publisher.CreateDataWriter(_topic, dwQos); + var writer = _publisher.CreateDataWriter(_topic, dwQos); Assert.IsNotNull(writer); var dataWriter = new TestIncludeDataWriter(writer); // Wait for discovery - var found = reader.WaitForPublications(1, 5000); + var found = reader.WaitForPublications(1, 5_000); + Assert.IsTrue(found); + found = writer.WaitForSubscriptions(1, 5_000); Assert.IsTrue(found); - // // Write two samples of three different instances - // for (short i = 1; i <= 3; i++) - // { - // evt.Reset(); - // TestHelper.CreateWaitSetThread(evt, statusCondition); - // - // result = dataWriter.Write(new TestInclude { Id = i.ToString() }); - // Assert.AreEqual(ReturnCode.Ok, result); - // - // result = dataWriter.WaitForAcknowledgments(duration); - // Assert.AreEqual(ReturnCode.Ok, result); - // - // Assert.IsTrue(evt.Wait(1_500)); - // - // evt.Reset(); - // TestHelper.CreateWaitSetThread(evt, statusCondition); - // - // result = dataWriter.Write(new TestInclude { Id = i.ToString(), ShortField = i }); - // Assert.AreEqual(ReturnCode.Ok, result); - // - // result = dataWriter.WaitForAcknowledgments(duration); - // Assert.AreEqual(ReturnCode.Ok, result); - // - // Assert.IsTrue(evt.Wait(1_500)); - // } - - // // Read next instance with the simplest overload - // var data = new List(); - // var sampleInfos = new List(); - // result = dataReader.ReadNextInstance(data, sampleInfos, InstanceHandle.HandleNil); - // Assert.AreEqual(ReturnCode.Ok, result); - // Assert.IsNotNull(data); - // Assert.IsNotNull(sampleInfos); - // Assert.AreEqual(2, data.Count); - // Assert.AreEqual(2, sampleInfos.Count); - // Assert.AreEqual("1", data[0].Id); - // Assert.AreEqual(0, data[0].ShortField); - // Assert.AreEqual("1", data[1].Id); - // Assert.AreEqual(1, data[1].ShortField); - - // // Read next instance limiting the max samples - // result = dataReader.ReadNextInstance(data, sampleInfos, InstanceHandle.HandleNil, 1); - // Assert.AreEqual(ReturnCode.Ok, result); - // Assert.IsNotNull(data); - // Assert.IsNotNull(sampleInfos); - // Assert.AreEqual(1, data.Count); - // Assert.AreEqual(1, sampleInfos.Count); - // Assert.AreEqual("1", data[0].Id); - // Assert.AreEqual(0, data[0].ShortField); - - // // Read next instance with QueryCondition - // var condition = reader.CreateQueryCondition("ShortField = 3"); - // Assert.IsNotNull(condition); - // - // result = dataReader.ReadNextInstance(data, sampleInfos, InstanceHandle.HandleNil, ResourceLimitsQosPolicy.LengthUnlimited, condition); - // Assert.AreEqual(ReturnCode.Ok, result); - // Assert.IsNotNull(data); - // Assert.IsNotNull(sampleInfos); - // Assert.AreEqual(1, data.Count); - // Assert.AreEqual(1, sampleInfos.Count); - // Assert.AreEqual("3", data[0].Id); - // Assert.AreEqual(3, data[0].ShortField); - // - // // Read next instance with mask parameters - // var handle = dataReader.LookupInstance(new TestInclude { Id = "2" }); - // Assert.AreNotEqual(InstanceHandle.HandleNil, handle); - // - // result = dataReader.ReadNextInstance(data, sampleInfos, handle, ResourceLimitsQosPolicy.LengthUnlimited, SampleStateKind.NotReadSampleState, ViewStateMask.AnyViewState, InstanceStateKind.AliveInstanceState); - // Assert.AreEqual(ReturnCode.Ok, result); - // Assert.IsNotNull(data); - // Assert.IsNotNull(sampleInfos); - // Assert.AreEqual(1, data.Count); - // Assert.AreEqual(1, sampleInfos.Count); - // Assert.AreEqual("3", data[0].Id); - // Assert.AreEqual(0, data[0].ShortField); + // Write two samples of three different instances + for (short i = 1; i <= 3; i++) + { + evt.Reset(); + TestHelper.CreateWaitSetThread(evt, statusCondition); + + result = dataWriter.Write(new TestInclude { Id = i.ToString() }); + Assert.AreEqual(ReturnCode.Ok, result); + + result = dataWriter.WaitForAcknowledgments(duration); + Assert.AreEqual(ReturnCode.Ok, result); + + Assert.IsTrue(evt.Wait(1_500)); + + evt.Reset(); + TestHelper.CreateWaitSetThread(evt, statusCondition); + + result = dataWriter.Write(new TestInclude { Id = i.ToString(), ShortField = i }); + Assert.AreEqual(ReturnCode.Ok, result); + + result = dataWriter.WaitForAcknowledgments(duration); + Assert.AreEqual(ReturnCode.Ok, result); + + Assert.IsTrue(evt.Wait(1_500)); + } + + // Read next instance with the simplest overload + var data = new List(); + var sampleInfos = new List(); + result = dataReader.ReadNextInstance(data, sampleInfos, InstanceHandle.HandleNil); + Assert.AreEqual(ReturnCode.Ok, result); + Assert.IsNotNull(data); + Assert.IsNotNull(sampleInfos); + Assert.AreEqual(2, data.Count); + Assert.AreEqual(2, sampleInfos.Count); + Assert.AreEqual("1", data[0].Id); + Assert.AreEqual(0, data[0].ShortField); + Assert.AreEqual("1", data[1].Id); + Assert.AreEqual(1, data[1].ShortField); + + // Read next instance limiting the max samples + result = dataReader.ReadNextInstance(data, sampleInfos, InstanceHandle.HandleNil, 1); + Assert.AreEqual(ReturnCode.Ok, result); + Assert.IsNotNull(data); + Assert.IsNotNull(sampleInfos); + Assert.AreEqual(1, data.Count); + Assert.AreEqual(1, sampleInfos.Count); + Assert.AreEqual("1", data[0].Id); + Assert.AreEqual(0, data[0].ShortField); + + // Read next instance with QueryCondition + var condition = reader.CreateQueryCondition("ShortField = 3"); + Assert.IsNotNull(condition); + + result = dataReader.ReadNextInstance(data, sampleInfos, InstanceHandle.HandleNil, ResourceLimitsQosPolicy.LengthUnlimited, condition); + Assert.AreEqual(ReturnCode.Ok, result); + Assert.IsNotNull(data); + Assert.IsNotNull(sampleInfos); + Assert.AreEqual(1, data.Count); + Assert.AreEqual(1, sampleInfos.Count); + Assert.AreEqual("3", data[0].Id); + Assert.AreEqual(3, data[0].ShortField); + + // Read next instance with mask parameters + var handle = dataReader.LookupInstance(new TestInclude { Id = "2" }); + Assert.AreNotEqual(InstanceHandle.HandleNil, handle); + + result = dataReader.ReadNextInstance(data, sampleInfos, handle, ResourceLimitsQosPolicy.LengthUnlimited, SampleStateKind.NotReadSampleState, ViewStateMask.AnyViewState, InstanceStateKind.AliveInstanceState); + Assert.AreEqual(ReturnCode.Ok, result); + Assert.IsNotNull(data); + Assert.IsNotNull(sampleInfos); + Assert.AreEqual(1, data.Count); + Assert.AreEqual(1, sampleInfos.Count); + Assert.AreEqual("3", data[0].Id); + Assert.AreEqual(0, data[0].ShortField); reader.DeleteContainedEntities(); _subscriber.DeleteDataReader(reader); - publisher.DeleteDataWriter(writer); - publisher.DeleteContainedEntities(); - _participant.DeletePublisher(publisher); + _publisher.DeleteDataWriter(writer); } /// @@ -2031,6 +2028,8 @@ public void TestTakeNextInstance() // Wait for discovery var found = reader.WaitForPublications(1, 5000); Assert.IsTrue(found); + found = writer.WaitForSubscriptions(1, 5000); + Assert.IsTrue(found); // Write two samples of three different instances for (short i = 1; i <= 3; i++) @@ -2162,6 +2161,8 @@ public void TestReadNextSample() // Wait for discovery var found = reader.WaitForPublications(1, 5000); Assert.IsTrue(found); + found = writer.WaitForSubscriptions(1, 5000); + Assert.IsTrue(found); // Write two samples of two different instances for (short i = 1; i <= 2; i++)