コード例 #1
0
ファイル: PublisherTest.cs プロジェクト: hvuwbmi/openddsharp
        public void TestBeginEndCoherentChanges()
        {
            // 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(TestBeginEndCoherentChanges), typeName);

            Assert.IsNotNull(topic);
            Assert.IsNull(topic.GetListener());
            Assert.AreEqual(nameof(TestBeginEndCoherentChanges), topic.Name);
            Assert.AreEqual(typeName, topic.TypeName);

            PublisherQos pQos = new PublisherQos();

            pQos.Presentation.CoherentAccess = true;
            pQos.Presentation.OrderedAccess  = true;
            pQos.Presentation.AccessScope    = PresentationQosPolicyAccessScopeKind.TopicPresentationQos;
            Publisher publisher = _participant.CreatePublisher(pQos);

            Assert.IsNotNull(publisher);

            SubscriberQos sQos = new SubscriberQos();

            sQos.Presentation.CoherentAccess = true;
            sQos.Presentation.OrderedAccess  = true;
            sQos.Presentation.AccessScope    = PresentationQosPolicyAccessScopeKind.TopicPresentationQos;
            Subscriber subscriber = _participant.CreateSubscriber(sQos);

            Assert.IsNotNull(subscriber);

            DataWriter writer = publisher.CreateDataWriter(topic);

            Assert.IsNotNull(writer);
            TestStructDataWriter dataWriter = new TestStructDataWriter(writer);

            DataReaderQos drQos = new DataReaderQos();

            drQos.Reliability.Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos;
            drQos.History.Kind     = HistoryQosPolicyKind.KeepAllHistoryQos;
            DataReader reader = subscriber.CreateDataReader(topic, drQos);

            Assert.IsNotNull(reader);

            TestStructDataReader dataReader = new TestStructDataReader(reader);

            // Call EndCoherentChanges without calling first SuspendPublications
            result = publisher.EndCoherentChanges();
            Assert.AreEqual(ReturnCode.PreconditionNotMet, result);

            // Begin coherent access and write samples
            result = publisher.BeginCoherentChanges();
            Assert.AreEqual(ReturnCode.Ok, result);

            for (int i = 1; i <= 5; i++)
            {
                TestStruct sample = new TestStruct
                {
                    Id        = i,
                    ShortType = (short)i
                };

                InstanceHandle handle = dataWriter.RegisterInstance(sample);
                Assert.AreNotEqual(InstanceHandle.HandleNil, handle);

                result = dataWriter.Write(sample, handle);
                Assert.AreEqual(ReturnCode.Ok, result);
            }

            System.Threading.Thread.Sleep(500);

            // Check that not samples arrived
            List <TestStruct> data        = new List <TestStruct>();
            List <SampleInfo> sampleInfos = new List <SampleInfo>();

            #region OpenDDS Issue
            // Coherent sets for PRESENTATION QoS not Currently implemented on RTPS
            //result = dataReader.Read(data, sampleInfos);
            //Assert.AreEqual(ReturnCode.NoData, result);
            #endregion

            // End coherent access and check the samples
            result = publisher.EndCoherentChanges();
            Assert.AreEqual(ReturnCode.Ok, result);

            System.Threading.Thread.Sleep(500);

            data        = new List <TestStruct>();
            sampleInfos = new List <SampleInfo>();
            result      = dataReader.Read(data, sampleInfos);
            Assert.AreEqual(ReturnCode.Ok, result);

            for (int i = 0; i < data.Count; i++)
            {
                Assert.IsTrue(sampleInfos[i].ValidData);
                Assert.AreEqual(i + 1, data[i].Id);
                Assert.AreEqual(i + 1, data[i].ShortType);
            }
        }
コード例 #2
0
        public static void DataAvailable(DataReader reader)
        {
            try
            {
                TestStructDataReader dr = new TestStructDataReader(reader);

                List <TestStruct> samples = new List <TestStruct>();
                List <SampleInfo> infos   = new List <SampleInfo>();
                ReturnCode        error   = dr.Read(samples, infos);
                if ((error == ReturnCode.Ok))
                {
                    for (int i = 0; i < samples.Count; i++)
                    {
                        SampleInfo info   = infos[i];
                        TestStruct sample = samples[i];
                        if (info.ValidData)
                        {
                            Console.WriteLine();

                            Console.WriteLine("RawData:");
                            Console.WriteLine(sample.RawData);
                            Console.WriteLine();

                            Console.WriteLine("LongDoubleType:");
                            Console.WriteLine(sample.LongDoubleType);
                            Console.WriteLine();

                            Console.WriteLine("LongSequence:");
                            foreach (int l in sample.LongSequence)
                            {
                                Console.WriteLine(l);
                            }
                            Console.WriteLine();

                            Console.WriteLine("StringSequence:");
                            foreach (string s in sample.StringSequence)
                            {
                                Console.WriteLine(s);
                            }
                            Console.WriteLine();

                            Console.WriteLine("StructSequence:");
                            foreach (BasicTestStruct s in sample.StructSequence)
                            {
                                Console.WriteLine(s.Id);
                            }
                            Console.WriteLine();

                            Console.WriteLine("LongDoubleSequence:");
                            foreach (double ld in sample.LongDoubleSequence)
                            {
                                Console.WriteLine(ld);
                            }
                            Console.WriteLine();

                            Console.WriteLine("LongArray:");
                            foreach (int l in sample.LongArray)
                            {
                                Console.WriteLine(l);
                            }
                            Console.WriteLine();

                            Console.WriteLine("StringArray:");
                            foreach (string s in sample.StringArray)
                            {
                                Console.WriteLine(s);
                            }
                            Console.WriteLine();

                            Console.WriteLine("StructArray:");
                            foreach (BasicTestStruct s in sample.StructArray)
                            {
                                Console.WriteLine(s.Id);
                            }
                            Console.WriteLine();

                            Console.WriteLine("LongDoubleArray:");
                            foreach (double d in sample.LongDoubleArray)
                            {
                                Console.WriteLine(d);
                            }
                            Console.WriteLine();
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                System.Console.Write(ex);
            }
        }
コード例 #3
0
ファイル: PublisherTest.cs プロジェクト: hvuwbmi/openddsharp
        public void TestSuspendResumePublications()
        {
            // 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(TestSuspendResumePublications), typeName);

            Assert.IsNotNull(topic);
            Assert.IsNull(topic.GetListener());
            Assert.AreEqual(nameof(TestSuspendResumePublications), topic.Name);
            Assert.AreEqual(typeName, topic.TypeName);

            Publisher publisher = _participant.CreatePublisher();

            Assert.IsNotNull(publisher);

            Subscriber subscriber = _participant.CreateSubscriber();

            Assert.IsNotNull(subscriber);

            DataWriter writer = publisher.CreateDataWriter(topic);

            Assert.IsNotNull(writer);
            TestStructDataWriter dataWriter = new TestStructDataWriter(writer);

            DataReaderQos drQos = new DataReaderQos();

            drQos.Reliability.Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos;
            drQos.History.Kind     = HistoryQosPolicyKind.KeepAllHistoryQos;
            DataReader reader = subscriber.CreateDataReader(topic, drQos);

            Assert.IsNotNull(reader);

            TestStructDataReader dataReader = new TestStructDataReader(reader);

            // Call ResumePublications without calling first SuspendPublications
            result = publisher.ResumePublications();
            Assert.AreEqual(ReturnCode.PreconditionNotMet, result);

            // Suspend publications and write samples
            result = publisher.SuspendPublications();
            Assert.AreEqual(ReturnCode.Ok, result);

            for (int i = 1; i <= 5; i++)
            {
                // OpenDDS issue: cannot register more than one instance during SuspendPublications.
                // Looks like that the control messages are never delivered and the controlTracker never get free during delete_datawriter
                TestStruct sample = new TestStruct
                {
                    Id        = 1,
                    ShortType = (short)i
                };

                InstanceHandle handle = dataWriter.RegisterInstance(sample);
                Assert.AreNotEqual(InstanceHandle.HandleNil, handle);

                result = dataWriter.Write(sample, handle);
                Assert.AreEqual(ReturnCode.Ok, result);
            }

            System.Threading.Thread.Sleep(500);

            // Check that not samples arrived
            List <TestStruct> data        = new List <TestStruct>();
            List <SampleInfo> sampleInfos = new List <SampleInfo>();

            result = dataReader.Read(data, sampleInfos);
            Assert.AreEqual(ReturnCode.NoData, result);

            // Resume publication and check the samples
            result = publisher.ResumePublications();
            Assert.AreEqual(ReturnCode.Ok, result);

            System.Threading.Thread.Sleep(500);

            data        = new List <TestStruct>();
            sampleInfos = new List <SampleInfo>();
            result      = dataReader.Read(data, sampleInfos);
            Assert.AreEqual(ReturnCode.Ok, result);

            for (int i = 0; i < data.Count; i++)
            {
                Assert.IsTrue(sampleInfos[i].ValidData);
                Assert.AreEqual(i + 1, data[i].ShortType);
            }
        }