Ejemplo n.º 1
0
        public void MonitorPublisherEventScope()
        {
            var c = new TestMonitorEventConsumer(MonitorEventLevel.Information, MonitorEventOpCode.All);

            List <MonitorEventEntry> items = new List <MonitorEventEntry>();

            c.OnEventAction = (e) =>
            {
                items.Add(e);
            };

            using (EventPublisher.AddConsumer(c))
            {
                using (EventPublisher.Default.RaiseScope(MonitorEventLevel.Information, name: "foo"))
                {
                    Thread.Sleep(2);
                }
            }

            Assert.AreEqual(2, items.Count);
            Assert.AreEqual(MonitorEventOpCode.Start, items[0].OpCode);
            Assert.AreEqual(0.0, items[0].RuntimeMilliseconds);
            Assert.AreEqual(MonitorEventOpCode.Stop, items[1].OpCode);
            Assert.AreNotEqual(0.0, items[1].RuntimeMilliseconds);
        }
        public void Monitor2Consumers()
        {
            var consumer = new TestMonitorEventConsumer(MonitorEventLevel.All, MonitorEventOpCode.All);

            int callCount = 0;

            consumer.OnEventAction = (e) =>
            {
                Assert.AreEqual(e.OpCode, MonitorEventOpCode.Stop);
                Assert.AreEqual(e.Level, MonitorEventLevel.Information);
                Assert.AreEqual("Test1", e.Name);
                callCount++;
            };

            var consumer2 = new TestMonitorEventConsumer(MonitorEventLevel.All, MonitorEventOpCode.All);

            consumer2.OnEventAction = (e) =>
            {
                Assert.AreEqual(e.OpCode, MonitorEventOpCode.Stop);
                Assert.AreEqual(e.Level, MonitorEventLevel.Information);
                Assert.AreEqual("Test1", e.Name);
                callCount++;
            };

            using (EventPublisher.AddConsumer(consumer))
            {
                using (EventPublisher.AddConsumer(consumer2))
                {
                    EventPublisher.Default.Raise(MonitorEventLevel.Information, MonitorEventOpCode.Stop, name: "Test1");
                }
            }

            Assert.AreEqual(2, callCount);
        }
Ejemplo n.º 3
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Arriba Local Server\r\n");

            Configuration c          = Configuration.GetConfigurationForArgs(args);
            int           portNumber = c.GetConfigurationInt("port", DefaultPort);

            // Write trace messages to console if /trace is specified
            if (c.GetConfigurationBool("trace", Debugger.IsAttached))
            {
                EventPublisher.AddConsumer(new ConsoleEventConsumer());
            }

            // Always log to CSV
            EventPublisher.AddConsumer(new CsvEventConsumer());

            using (var app = WebApp.Start <SelfHostArribaOwinStartup>(String.Format("http://*:{0}/", portNumber)))
            {
                Console.WriteLine("Running... Press any key to exit.");
                Console.ReadKey();
            }

            Console.WriteLine("Exiting.");
            Environment.Exit(0);
        }
Ejemplo n.º 4
0
        public void MonitorEventTimeStampSet()
        {
            DateTime start = DateTime.UtcNow;

            var consumer = new TestMonitorEventConsumer(MonitorEventLevel.All, MonitorEventOpCode.All);

            DateTime eventTime      = DateTime.MinValue;
            bool     callbackRaised = false;

            consumer.OnEventAction = (e) =>
            {
                eventTime      = e.TimeStamp;
                callbackRaised = true;
            };

            using (EventPublisher.AddConsumer(consumer))
            {
                EventPublisher.Default.Raise(name: "Foo");

                DateTime end = DateTime.UtcNow;

                Assert.IsTrue(callbackRaised, "Callback raised");
                Assert.IsTrue(eventTime >= start, "Timestamp after start of test (Start: {0}, TimeStamp: {1})", start, eventTime);
                Assert.IsTrue(eventTime <= end, "Timestamp before end of test (End: {0}, Timestamp: {1})", end, eventTime);
            }
        }
        public void MonitorMarkFiltering()
        {
            var consumer = new TestMonitorEventConsumer(MonitorEventLevel.All, MonitorEventOpCode.Start);

            bool eventCalled = false;

            consumer.OnEventAction = (e) => { eventCalled = true; };

            using (EventPublisher.AddConsumer(consumer))
            {
                EventPublisher.Default.Raise(MonitorEventLevel.Information, MonitorEventOpCode.Stop);
            }

            Assert.IsFalse(eventCalled);
        }
Ejemplo n.º 6
0
        public override void Configuration(IAppBuilder app)
        {
            string csvLogsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\Logs");

            EventPublisher.AddConsumer(new CsvEventConsumer(csvLogsPath));

            // TODO: this should be configurable.
            BinarySerializable.CachePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\DiskCache");

            // App configuration
            base.Configuration(app);

            // Enable requests that are not handled to use the regular pipeline
            app.UseStageMarker(Owin.PipelineStage.MapHandler);
        }
        public void MonitorLevelFiltering()
        {
            var consumer = new TestMonitorEventConsumer(MonitorEventLevel.Error, MonitorEventOpCode.Start);

            bool eventCalled = false;

            consumer.OnEventAction = (e) => { eventCalled = true; };

            using (EventPublisher.AddConsumer(consumer))
            {
                EventPublisher.Default.Raise(MonitorEventLevel.Error, MonitorEventOpCode.Mark);
                EventPublisher.Default.Raise(MonitorEventLevel.Warning, MonitorEventOpCode.Start);
                Assert.IsFalse(eventCalled, "Event should not be raised to consumer");
                EventPublisher.Default.Raise(MonitorEventLevel.Error, MonitorEventOpCode.Start);
                Assert.IsTrue(eventCalled, "Event should be raised to consumer");
            }
        }
        public void MonitorLevelChange()
        {
            var consumer = new TestMonitorEventConsumer(MonitorEventLevel.Error, MonitorEventOpCode.All);

            bool eventCalled = false;

            consumer.OnEventAction = (e) => { eventCalled = true; };

            using (EventPublisher.AddConsumer(consumer))
            {
                EventPublisher.Default.Raise(MonitorEventLevel.Information, MonitorEventOpCode.Mark);
                Assert.IsFalse(eventCalled, "Event should not be raised to consumer");
                consumer.ChangeEventLevel(MonitorEventLevel.All, MonitorEventOpCode.All);

                EventPublisher.Default.Raise(MonitorEventLevel.Information, MonitorEventOpCode.Mark);
                Assert.IsTrue(eventCalled, "Event should be raised to consumer");
            }
        }
        public void MonitorSingleEvent()
        {
            var consumer = new TestMonitorEventConsumer(MonitorEventLevel.All, MonitorEventOpCode.All);

            bool wasCalled = false;

            consumer.OnEventAction = (e) =>
            {
                Assert.AreEqual(e.OpCode, MonitorEventOpCode.Stop);
                Assert.AreEqual(e.Level, MonitorEventLevel.Information);
                Assert.AreEqual("Test1", e.Name);
                wasCalled = true;
            };

            using (EventPublisher.AddConsumer(consumer))
            {
                EventPublisher.Default.Raise(MonitorEventLevel.Information, MonitorEventOpCode.Stop, name: "Test1");
            }

            Assert.IsTrue(wasCalled);
        }
Ejemplo n.º 10
0
        public void MonitorPublisherScopedEventSource()
        {
            var c = new TestMonitorEventConsumer(MonitorEventLevel.All, MonitorEventOpCode.All);

            List <MonitorEventEntry> items = new List <MonitorEventEntry>();
            bool eventRaised = false;

            c.OnEventAction = (e) =>
            {
                Assert.AreEqual("MySource", e.Source);
                Assert.AreEqual("test", e.Name);
                eventRaised = true;
            };

            using (EventPublisher.AddConsumer(c))
            {
                var source = EventPublisher.CreateEventSource("MySource");

                source.Raise(name: "test");
            }

            Assert.IsTrue(eventRaised);
        }
        public void MonitorDispose()
        {
            var consumer = new TestMonitorEventConsumer(MonitorEventLevel.All, MonitorEventOpCode.All);

            bool disposeCalled = false;
            bool eventCalled   = false;

            consumer.OnDisposeAction = () => { disposeCalled = true; };
            consumer.OnEventAction   = (e) => { eventCalled = true; };

            using (EventPublisher.AddConsumer(consumer))
            {
                EventPublisher.Default.Raise(MonitorEventLevel.Information);
                Assert.IsTrue(eventCalled);
                Assert.IsFalse(disposeCalled);

                eventCalled = false;
            }

            Assert.IsTrue(disposeCalled);

            EventPublisher.Default.Raise(MonitorEventLevel.Information);
            Assert.IsFalse(eventCalled);
        }