Exemple #1
0
        public void FlightRecorder_Persist_Multiple()
        {
            // Verify that a second flight recorder trying to use the same
            // backing file will fail-over to using a memory stream.

            string path = Path.GetTempFileName();

            try
            {
                using (var recorder1 = new FlightRecorder(path))
                {
                    Assert.IsTrue(recorder1.IsPersistMode);
                    Assert.IsFalse(recorder1.IsPassThruMode);

                    using (var recorder2 = new FlightRecorder(path))
                    {
                        // Perform some operations to the second recorder.  These
                        // operations will be NOPs since the recorder is blocked,
                        // but should not fail or impact the first recorder's
                        // backing file.

                        recorder2.Log("Test");
                        recorder2.Dequeue();
                        recorder2.Dequeue(2);
                        recorder2.GetEvents();

                        // Record some events to the first recorder.

                        recorder1.Log("event #1");
                        recorder1.Log("event #2");
                    }
                }

                // Verify that the first instance did record properly.

                using (var recorder = new FlightRecorder(path))
                {
                    Assert.AreEqual(2, recorder.Count);
                    Assert.AreEqual("event #1", recorder.Dequeue().Operation);
                    Assert.AreEqual(1, recorder.Count);
                    Assert.AreEqual("event #2", recorder.Dequeue().Operation);
                    Assert.AreEqual(0, recorder.Count);

                    Assert.IsNull(recorder.Dequeue());
                }
            }
            finally
            {
                Helper.DeleteFile(path);
            }
        }
Exemple #2
0
        public void FlightRecorder_PassThru_GetEvents()
        {
            // Verify that GetEvents() always returns an empty list.

            Queue <FlightEvent> queue = new Queue <FlightEvent>();

            using (var recorder = new FlightRecorder(evt => queue.Enqueue(evt)))
            {
                for (int i = 0; i < 20; i++)
                {
                    recorder.Log(i.ToString());
                }

                Assert.AreEqual(0, recorder.GetEvents().Count);
            }
        }
Exemple #3
0
        public void FlightRecorder_Persist_GetEvents()
        {
            // Verify that GetEvents() works

            MemoryStream       stream = new MemoryStream();
            List <FlightEvent> events;

            using (var recorder = new FlightRecorder(stream))
            {
                for (int i = 0; i < 20; i++)
                {
                    recorder.Log(i.ToString());
                }

                events = new List <FlightEvent>();
                recorder.GetEvents().CopyTo(events);
            }

            for (int i = 0; i < 20; i++)
            {
                Assert.AreEqual(i.ToString(), events[i].Operation);
            }
        }