public void TestTakeNextInstance() { ReturnCode ret; DomainParticipant otherParticipant = null; Topic topic = null; try { List <TopicBuiltinTopicData> data = new List <TopicBuiltinTopicData>(); List <SampleInfo> infos = new List <SampleInfo>(); ret = _dr.TakeNextInstance(data, infos, InstanceHandle.HandleNil); Assert.AreEqual(ReturnCode.NoData, ret); Assert.AreEqual(0, data.Count); Assert.AreEqual(0, infos.Count); otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.INFOREPO_DOMAIN); Assert.IsNotNull(otherParticipant); otherParticipant.BindRtpsUdpTransportConfig(); TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(otherParticipant, typeName); Assert.AreEqual(ReturnCode.Ok, result); TopicQos qos = TestHelper.CreateNonDefaultTopicQos(); topic = otherParticipant.CreateTopic(TestContext.TestName, typeName, qos); Assert.IsNotNull(topic); int count = 200; ret = ReturnCode.NoData; while (ret != ReturnCode.Ok && count > 0) { Thread.Sleep(100); ret = _dr.TakeNextInstance(data, infos, InstanceHandle.HandleNil); count--; } Assert.AreEqual(ReturnCode.Ok, ret); Assert.AreEqual(1, data.Count); Assert.AreEqual(1, infos.Count); Assert.AreEqual(typeName, data.First().TypeName); Assert.IsNotNull(data.First().Key); TestHelper.TestNonDefaultTopicData(data.First()); } finally { ret = otherParticipant.DeleteTopic(topic); Assert.AreEqual(ReturnCode.Ok, ret); ret = otherParticipant.DeleteContainedEntities(); Assert.AreEqual(ReturnCode.Ok, ret); ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant); Assert.AreEqual(ReturnCode.Ok, ret); } }
public void TestLookupInstance() { ReturnCode ret; DomainParticipant otherParticipant = null; Topic topic = null; try { TopicBuiltinTopicData data = default; SampleInfo info = new SampleInfo(); otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.INFOREPO_DOMAIN); Assert.IsNotNull(otherParticipant); otherParticipant.BindRtpsUdpTransportConfig(); TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(otherParticipant, typeName); Assert.AreEqual(ReturnCode.Ok, result); TopicQos qos = TestHelper.CreateNonDefaultTopicQos(); topic = otherParticipant.CreateTopic(TestContext.TestName, typeName, qos); Assert.IsNotNull(topic); int count = 200; ret = ReturnCode.NoData; while (ret != ReturnCode.Ok && count > 0) { Thread.Sleep(100); ret = _dr.ReadNextSample(ref data, info); count--; } Assert.AreEqual(ReturnCode.Ok, ret); Assert.AreEqual(typeName, data.TypeName); Assert.IsNotNull(data.Key); TestHelper.TestNonDefaultTopicData(data); // Lookup for an existing instance var handle = _dr.LookupInstance(data); Assert.AreNotEqual(InstanceHandle.HandleNil, handle); } finally { ret = otherParticipant.DeleteTopic(topic); Assert.AreEqual(ReturnCode.Ok, ret); ret = otherParticipant.DeleteContainedEntities(); Assert.AreEqual(ReturnCode.Ok, ret); ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant); Assert.AreEqual(ReturnCode.Ok, ret); } }