Skip to content

Commit

Permalink
Use private publisher
Browse files Browse the repository at this point in the history
  • Loading branch information
jmmorato committed Dec 18, 2024
1 parent f44c8ca commit 96d0400
Showing 1 changed file with 84 additions and 83 deletions.
167 changes: 84 additions & 83 deletions Tests/OpenDDSharp.UnitTest/DataReaderCDRTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1883,105 +1883,102 @@ public void TestReadNextInstance()
var statusCondition = dataReader.StatusCondition;
statusCondition.EnabledStatuses = StatusKind.DataAvailableStatus;

var publisher = _participant.CreatePublisher();
Assert.IsNotNull(publisher);

var dwQos = new DataWriterQos
{
Reliability =
{
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<TestInclude>();
// var sampleInfos = new List<SampleInfo>();
// 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<TestInclude>();
var sampleInfos = new List<SampleInfo>();
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);
}

/// <summary>
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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++)
Expand Down

0 comments on commit 96d0400

Please sign in to comment.