Example #1
0
        public void TestInitialize()
        {
            _participant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN);
            Assert.IsNotNull(_participant);
            _participant.BindRtpsUdpTransportConfig();

            AthleteTypeSupport athleteSupport  = new AthleteTypeSupport();
            string             athleteTypeName = athleteSupport.GetTypeName();
            ReturnCode         result          = athleteSupport.RegisterType(_participant, athleteTypeName);

            Assert.AreEqual(ReturnCode.Ok, result);

            _athleteTopic = _participant.CreateTopic("AthleteTopic", athleteTypeName);
            Assert.IsNotNull(_athleteTopic);
            Assert.IsNull(_athleteTopic.Listener);
            Assert.AreEqual("AthleteTopic", _athleteTopic.Name);
            Assert.AreEqual(athleteTypeName, _athleteTopic.TypeName);

            ResultTypeSupport resultSupport  = new ResultTypeSupport();
            string            resultTypeName = resultSupport.GetTypeName();

            result = resultSupport.RegisterType(_participant, resultTypeName);
            Assert.AreEqual(ReturnCode.Ok, result);

            _resultTopic = _participant.CreateTopic("ResultTopic", resultTypeName);
            Assert.IsNotNull(_resultTopic);
            Assert.IsNull(_resultTopic.Listener);
            Assert.AreEqual("ResultTopic", _resultTopic.Name);
            Assert.AreEqual(resultTypeName, _resultTopic.TypeName);

            _subscriber = _participant.CreateSubscriber();
            Assert.IsNotNull(_subscriber);

            _publisher = _participant.CreatePublisher();
            Assert.IsNotNull(_publisher);

            _athleteWriter = _publisher.CreateDataWriter(_athleteTopic);
            Assert.IsNotNull(_athleteWriter);
            _athleteDataWriter = new AthleteDataWriter(_athleteWriter);
            Assert.IsNotNull(_athleteDataWriter);

            _resultWriter = _publisher.CreateDataWriter(_resultTopic);
            Assert.IsNotNull(_resultWriter);
            _resultDataWriter = new ResultDataWriter(_resultWriter);
            Assert.IsNotNull(_resultDataWriter);

            DataReaderQos qos = new DataReaderQos();

            qos.Reliability.Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos;
            _reader = _subscriber.CreateDataReader(_athleteTopic, qos);
            Assert.IsNotNull(_reader);
        }
Example #2
0
        private static void TestOnInconsistentTopic()
        {
            DomainParticipantFactory dpf         = ParticipantService.Instance.GetDomainParticipantFactory();
            DomainParticipant        participant = dpf.CreateParticipant(RTPS_DOMAIN);

            if (participant == null)
            {
                throw new ApplicationException("Failed to create the participant.");
            }

            BindRtpsUdpTransportConfig(participant);

            Subscriber subscriber = participant.CreateSubscriber();

            if (subscriber == null)
            {
                throw new ApplicationException("Failed to create the subscriber.");
            }

            AthleteTypeSupport support  = new AthleteTypeSupport();
            string             typeName = support.GetTypeName();
            ReturnCode         result   = support.RegisterType(participant, typeName);

            if (result != ReturnCode.Ok)
            {
                throw new ApplicationException("Failed to register the type." + result.ToString());
            }

            Topic topic = participant.CreateTopic(nameof(TestOnInconsistentTopic), typeName);

            if (topic == null)
            {
                throw new ApplicationException("Failed to create the topic.");
            }

            DataReader reader = subscriber.CreateDataReader(topic);

            if (reader == null)
            {
                throw new ApplicationException("Failed to create the reader.");
            }

            while (true)
            {
                System.Threading.Thread.Sleep(100);
            }
        }