public void TestSetListener() { // Create a new Subscriber without listener Subscriber subscriber = _participant.CreateSubscriber(); Assert.IsNotNull(subscriber); MySubscriberListener listener = (MySubscriberListener)subscriber.GetListener(); Assert.IsNull(listener); // Create a listener, set it and check that is correctly setted listener = new MySubscriberListener(); ReturnCode result = subscriber.SetListener(listener, StatusMask.AllStatusMask); Assert.AreEqual(ReturnCode.Ok, result); MySubscriberListener received = (MySubscriberListener)subscriber.GetListener(); Assert.IsNotNull(received); Assert.AreEqual(listener, received); // Remove the listener calling SetListener with null and check it result = subscriber.SetListener(null, StatusMask.NoStatusMask); Assert.AreEqual(ReturnCode.Ok, result); received = (MySubscriberListener)subscriber.GetListener(); Assert.IsNull(received); }
public void TestGetListener() { // Create a new Subscriber with a listener MySubscriberListener listener = new MySubscriberListener(); Subscriber subscriber = _participant.CreateSubscriber(listener); Assert.IsNotNull(subscriber); // Call to GetListener and check the listener received MySubscriberListener received = (MySubscriberListener)subscriber.GetListener(); Assert.IsNotNull(received); Assert.AreEqual(listener, received); }
public void TestGetListener() { // Create a new Subscriber with a listener MySubscriberListener listener = new MySubscriberListener(); Subscriber subscriber = _participant.CreateSubscriber(null, listener); Assert.IsNotNull(subscriber); // Call to GetListener and check the listener received #pragma warning disable CS0618 // Type or member is obsolete MySubscriberListener received = (MySubscriberListener)subscriber.GetListener(); #pragma warning restore CS0618 // Type or member is obsolete Assert.IsNotNull(received); Assert.AreEqual(listener, received); }
public void TestInitialize() { _participant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN); Assert.IsNotNull(_participant); _participant.BindRtpsUdpTransportConfig(); TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(_participant, typeName); Assert.AreEqual(ReturnCode.Ok, result); _topic = _participant.CreateTopic(TestContext.TestName, typeName); Assert.IsNotNull(_topic); Assert.IsNull(_topic.GetListener()); Assert.AreEqual(TestContext.TestName, _topic.Name); Assert.AreEqual(typeName, _topic.TypeName); _listener = new MySubscriberListener(); SubscriberQos sQos = new SubscriberQos(); sQos.EntityFactory.AutoenableCreatedEntities = false; sQos.Presentation.OrderedAccess = true; sQos.Presentation.CoherentAccess = true; sQos.Presentation.AccessScope = PresentationQosPolicyAccessScopeKind.InstancePresentationQos; _subscriber = _participant.CreateSubscriber(sQos, _listener); Assert.IsNotNull(_subscriber); PublisherQos pQos = new PublisherQos(); pQos.EntityFactory.AutoenableCreatedEntities = false; pQos.Presentation.OrderedAccess = true; pQos.Presentation.CoherentAccess = true; pQos.Presentation.AccessScope = PresentationQosPolicyAccessScopeKind.InstancePresentationQos; _publisher = _participant.CreatePublisher(pQos); Assert.IsNotNull(_publisher); _writer = _publisher.CreateDataWriter(_topic); Assert.IsNotNull(_writer); _dataWriter = new TestStructDataWriter(_writer); DataReaderQos qos = new DataReaderQos(); qos.Reliability.Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos; _reader = _subscriber.CreateDataReader(_topic, qos); Assert.IsNotNull(_reader); }
public void TestBeginEndAccess() { // OpenDDS Issue: Coherent sets for PRESENTATION QoS not Currently implemented on RTPS. // Just prepare the unit test for the moment. // Initialize entities TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(_participant, typeName); Assert.AreEqual(ReturnCode.Ok, result); Topic topic = _participant.CreateTopic(nameof(TestNotifyDataReaders), typeName); Assert.IsNotNull(topic); Assert.IsNull(topic.GetListener()); Assert.AreEqual(nameof(TestNotifyDataReaders), topic.Name); Assert.AreEqual(typeName, topic.TypeName); Topic otherTopic = _participant.CreateTopic("Other" + nameof(TestNotifyDataReaders), typeName); Assert.IsNotNull(otherTopic); Assert.IsNull(otherTopic.GetListener()); Assert.AreEqual("Other" + nameof(TestNotifyDataReaders), otherTopic.Name); Assert.AreEqual(typeName, otherTopic.TypeName); PublisherQos pubQos = new PublisherQos(); pubQos.Presentation.AccessScope = PresentationQosPolicyAccessScopeKind.GroupPresentationQos; pubQos.Presentation.CoherentAccess = true; pubQos.Presentation.OrderedAccess = true; Publisher publisher = _participant.CreatePublisher(pubQos); Assert.IsNotNull(publisher); DataWriter writer = publisher.CreateDataWriter(topic); Assert.IsNotNull(writer); TestStructDataWriter dataWriter = new TestStructDataWriter(writer); DataWriter otherWriter = publisher.CreateDataWriter(otherTopic); Assert.IsNotNull(otherWriter); TestStructDataWriter otherDataWriter = new TestStructDataWriter(otherWriter); SubscriberQos subQos = new SubscriberQos(); subQos.Presentation.AccessScope = PresentationQosPolicyAccessScopeKind.GroupPresentationQos; subQos.Presentation.CoherentAccess = true; subQos.Presentation.OrderedAccess = true; MySubscriberListener listener = new MySubscriberListener(); listener.DataOnReaders += (sub) => { result = sub.BeginAccess(); Assert.AreEqual(ReturnCode.Ok, result); List <DataReader> list = new List <DataReader>(); result = sub.GetDataReaders(list); // Here we should check that we received two DataReader // read the data of each one and confirm tha the group coherent access // is working as expected. result = sub.EndAccess(); Assert.AreEqual(ReturnCode.Ok, result); }; Subscriber subscriber = _participant.CreateSubscriber(subQos, listener); Assert.IsNotNull(subscriber); DataReader reader = subscriber.CreateDataReader(topic); Assert.IsNotNull(reader); TestStructDataReader dataReader = new TestStructDataReader(reader); DataReader otherReader = subscriber.CreateDataReader(otherTopic); Assert.IsNotNull(otherReader); TestStructDataReader otherDataReader = new TestStructDataReader(otherReader); // Call EndAccess without calling first BeginAccess result = subscriber.EndAccess(); Assert.AreEqual(ReturnCode.PreconditionNotMet, result); // Publish a samples in both topics result = publisher.BeginCoherentChanges(); Assert.AreEqual(ReturnCode.Ok, result); result = dataWriter.Write(new TestStruct { Id = 1 }); Assert.AreEqual(ReturnCode.Ok, result); result = otherDataWriter.Write(new TestStruct { Id = 1 }); Assert.AreEqual(ReturnCode.Ok, result); result = publisher.EndCoherentChanges(); Assert.AreEqual(ReturnCode.Ok, result); // Give some time to the subscriber to process the messages System.Threading.Thread.Sleep(500); }
public void TestNotifyDataReaders() { // Initialize entities TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(_participant, typeName); Assert.AreEqual(ReturnCode.Ok, result); Topic topic = _participant.CreateTopic(nameof(TestNotifyDataReaders), typeName); Assert.IsNotNull(topic); Assert.IsNull(topic.GetListener()); Assert.AreEqual(nameof(TestNotifyDataReaders), topic.Name); Assert.AreEqual(typeName, topic.TypeName); Publisher publisher = _participant.CreatePublisher(); Assert.IsNotNull(publisher); DataWriter writer = publisher.CreateDataWriter(topic); Assert.IsNotNull(writer); TestStructDataWriter dataWriter = new TestStructDataWriter(writer); int subscriberReceived = 0; int readerReceived = 0; // Create the Subscriber and the DataReader with the corresponding listeners MySubscriberListener subListener = new MySubscriberListener(); subListener.DataOnReaders += (sub) => { subscriberReceived++; if (subscriberReceived % 2 == 0) { sub.NotifyDataReaders(); } }; Subscriber subscriber = _participant.CreateSubscriber(subListener); Assert.IsNotNull(subscriber); MyDataReaderListener readListener = new MyDataReaderListener(); readListener.DataAvailable += (read) => { readerReceived++; }; DataReader reader = subscriber.CreateDataReader(topic, readListener); Assert.IsNotNull(reader); System.Threading.Thread.Sleep(100); // Publish instances for (int i = 0; i < 10; i++) { dataWriter.Write(new TestStruct { Id = i, ShortType = (short)i }); System.Threading.Thread.Sleep(100); } System.Threading.Thread.Sleep(100); // Check the received instances Assert.AreEqual(10, subscriberReceived); Assert.AreEqual(5, readerReceived); }