예제 #1
0
        public void BufferProcessedEventRaisedAfterEventsBufferred()
        {
            testSizeLimitedBufferProcessor.Start();
            testSizeLimitedBufferProcessor.NotifyCountMetricEventBuffered();
            testSizeLimitedBufferProcessor.NotifyAmountMetricEventBuffered();
            testSizeLimitedBufferProcessor.NotifyStatusMetricEventBuffered();
            testSizeLimitedBufferProcessor.NotifyIntervalMetricEventBuffered();
            testSizeLimitedBufferProcessor.NotifyCountMetricEventBuffered();
            // After 5 metric events are buffered the buffer size limit is reached, and the metric events should be processed and the buffers cleared
            testSizeLimitedBufferProcessor.NotifyCountMetricEventBufferCleared();
            testSizeLimitedBufferProcessor.NotifyAmountMetricEventBufferCleared();
            testSizeLimitedBufferProcessor.NotifyStatusMetricEventBufferCleared();
            testSizeLimitedBufferProcessor.NotifyIntervalMetricEventBufferCleared();
            testSizeLimitedBufferProcessor.Stop();

            Assert.AreEqual(1, bufferProcessedEventRaisedCount);
        }
예제 #2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Setup metric logger and MethodInvocationRemoting objects
            MetricLoggerDistributor distributor         = new MetricLoggerDistributor();
            ConsoleMetricLogger     consoleMetricLogger = new ConsoleMetricLogger(5000, true);

            using (FileApplicationLogger logger = new FileApplicationLogger(LogLevel.Information, '|', "  ", @"C:\Temp\C#Sender.log"))
                using (SizeLimitedBufferProcessor fileMetricLoggerBufferProcessor = new SizeLimitedBufferProcessor(50))
                    using (FileMetricLogger fileMetricLogger = new FileMetricLogger('|', @"C:\Temp\C#Metrics.log", fileMetricLoggerBufferProcessor, true))
                        using (SizeLimitedBufferProcessor accessMetricLoggerBufferProcessor = new SizeLimitedBufferProcessor(50))
                            using (MicrosoftAccessMetricLogger accessMetricLogger = new MicrosoftAccessMetricLogger(@"C:\Temp\MetricLogger.mdb", "SampleApplication5-C#", accessMetricLoggerBufferProcessor, true))
                                using (PerformanceCounterMetricLogger perfmonMetricLogger = new PerformanceCounterMetricLogger("SampleApplication5Metrics", "Metrics produced by MethodInvocationRemoting sample application 5", 1000, true))
                                    using (TcpRemoteSender tcpSender = new TcpRemoteSender(System.Net.IPAddress.Loopback, 55000, 10, 1000, 30000, 25, logger, distributor))
                                        using (TcpRemoteReceiver tcpReceiver = new TcpRemoteReceiver(55001, 10, 1000, 25, logger, distributor))
                                        {
                                            RemoteReceiverDecompressor   decompressorReceiver         = new RemoteReceiverDecompressor(tcpReceiver, logger, distributor);
                                            MethodInvocationSerializer   serializer                   = new MethodInvocationSerializer(new SerializerOperationMap(), logger, distributor);
                                            MethodInvocationRemoteSender methodInvocationRemoteSender = new MethodInvocationRemoteSender(serializer, tcpSender, decompressorReceiver, logger, distributor);

                                            // Define metric aggregates for the console logger
                                            DefineMetricAggregates(consoleMetricLogger);

                                            // Register base metrics and aggregates with the performance monitor logger
                                            perfmonMetricLogger.RegisterMetric(new RemoteMethodSendTime());
                                            perfmonMetricLogger.RegisterMetric(new RemoteMethodSent());
                                            perfmonMetricLogger.RegisterMetric(new MethodInvocationSerializeTime());
                                            perfmonMetricLogger.RegisterMetric(new MethodInvocationSerialized());
                                            perfmonMetricLogger.RegisterMetric(new SerializedMethodInvocationSize(0));
                                            perfmonMetricLogger.RegisterMetric(new ReturnValueDeserializeTime());
                                            perfmonMetricLogger.RegisterMetric(new ReturnValueDeserialized());
                                            perfmonMetricLogger.RegisterMetric(new StringDecompressTime());
                                            perfmonMetricLogger.RegisterMetric(new RemoteReceiverDecompressorReadBufferCreated());
                                            perfmonMetricLogger.RegisterMetric(new StringDecompressed());
                                            perfmonMetricLogger.RegisterMetric(new TcpRemoteReceiverReconnected());
                                            perfmonMetricLogger.RegisterMetric(new MessageReceiveTime());
                                            perfmonMetricLogger.RegisterMetric(new MessageReceived());
                                            perfmonMetricLogger.RegisterMetric(new ReceivedMessageSize(0));
                                            perfmonMetricLogger.RegisterMetric(new TcpRemoteReceiverDuplicateSequenceNumber());
                                            perfmonMetricLogger.RegisterMetric(new MessageSendTime());
                                            perfmonMetricLogger.RegisterMetric(new MessageSent());
                                            perfmonMetricLogger.RegisterMetric(new TcpRemoteSenderReconnected());
                                            DefineMetricAggregates(perfmonMetricLogger);

                                            // Create performance monitor counters in the operating system
                                            perfmonMetricLogger.CreatePerformanceCounters();

                                            distributor.AddLogger(consoleMetricLogger);
                                            distributor.AddLogger(fileMetricLogger);
                                            distributor.AddLogger(accessMetricLogger);
                                            distributor.AddLogger(perfmonMetricLogger);
                                            consoleMetricLogger.Start();
                                            fileMetricLoggerBufferProcessor.Start();
                                            accessMetricLoggerBufferProcessor.Start();
                                            accessMetricLogger.Connect();
                                            perfmonMetricLogger.Start();

                                            // Connect to the MethodInvocationRemoteReceiver
                                            tcpSender.Connect();
                                            tcpReceiver.Connect();

                                            // Setup the layers of the application MVP model
                                            MainView  mainView  = new MainView();
                                            Model     model     = new Model(methodInvocationRemoteSender);
                                            Presenter presenter = new Presenter(mainView, model);
                                            mainView.Presenter = presenter;

                                            // Start the application
                                            Application.Run(mainView);

                                            // Disconnect from the MethodInvocationRemoteReceiver
                                            tcpReceiver.Disconnect();
                                            tcpSender.Disconnect();

                                            // Stop the metric loggers
                                            consoleMetricLogger.Stop();
                                            fileMetricLoggerBufferProcessor.Stop();
                                            accessMetricLoggerBufferProcessor.Stop();
                                            accessMetricLogger.Disconnect();
                                            perfmonMetricLogger.Stop();
                                        }
        }