public void LogCountMetricTotalSuccessTest() { using (mocks.Ordered) { // Expects for calls to Increment() Expect.Once.On(mockDateTime).GetProperty("UtcNow").Will(Return.Value(new System.DateTime(2014, 07, 12, 15, 20, 21))); Expect.Once.On(mockDateTime).GetProperty("UtcNow").Will(Return.Value(new System.DateTime(2014, 07, 12, 15, 20, 23))); Expect.Once.On(mockDateTime).GetProperty("UtcNow").Will(Return.Value(new System.DateTime(2014, 07, 12, 15, 20, 25))); // Expects for calls to Start() Expect.Once.On(mockDateTime).GetProperty("UtcNow").Will(Return.Value(new System.DateTime(2014, 07, 12, 15, 20, 27))); SetWriteTitleExpectations(); Expect.Once.On(mockConsole).Method("WriteLine").With(new TestMessageReceivedMetric().Name + separatorString + "2"); Expect.Once.On(mockConsole).Method("WriteLine").With(new TestDiskReadOperationMetric().Name + separatorString + "1").Will(Signal.EventWaitHandle(workerThreadLoopCompleteSignal)); } testConsoleMetricLogger.Increment(new TestMessageReceivedMetric()); testConsoleMetricLogger.Increment(new TestDiskReadOperationMetric()); testConsoleMetricLogger.Increment(new TestMessageReceivedMetric()); testConsoleMetricLogger.Start(); workerThreadLoopCompleteSignal.WaitOne(); mocks.VerifyAllExpectationsHaveBeenMet(); Assert.IsNull(exceptionStorer.StoredException); }
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(); } }