Пример #1
0
        public void QueueRegisterationTest()
        {
            // we need to make sure we are starting clean:
            while (RollbarQueueController.Instance.GetQueuesCount() > 0)
            {
                Thread.Sleep(TimeSpan.FromMilliseconds(250));
            }

            RollbarConfig loggerConfig1 =
                new RollbarConfig(RollbarUnitTestSettings.AccessToken)
            {
                Environment = RollbarUnitTestSettings.Environment,
            };
            RollbarConfig loggerConfig2 =
                new RollbarConfig(RollbarUnitTestSettings.AccessToken.Replace('0', '1'))
            {
                Environment = RollbarUnitTestSettings.Environment,
            };

            Assert.AreNotEqual(loggerConfig1.AccessToken, loggerConfig2.AccessToken);

            int initialCount  = RollbarQueueController.Instance.GetQueuesCount();
            int initialCount1 = RollbarQueueController.Instance.GetQueuesCount(loggerConfig1.AccessToken);
            int initialCount2 = RollbarQueueController.Instance.GetQueuesCount(loggerConfig2.AccessToken);

            Assert.AreEqual(initialCount + 0, RollbarQueueController.Instance.GetQueuesCount());
            Assert.AreEqual(initialCount1 + 0, RollbarQueueController.Instance.GetQueuesCount(loggerConfig1.AccessToken));
            Assert.AreEqual(initialCount2 + 0, RollbarQueueController.Instance.GetQueuesCount(loggerConfig2.AccessToken));

            using (var logger1 = RollbarFactory.CreateNew().Configure(loggerConfig1))
            {
                Assert.AreEqual(initialCount + 1, RollbarQueueController.Instance.GetQueuesCount());
                Assert.AreEqual(initialCount1 + 1, RollbarQueueController.Instance.GetQueuesCount(loggerConfig1.AccessToken));
                Assert.AreEqual(initialCount2 + 0, RollbarQueueController.Instance.GetQueuesCount(loggerConfig2.AccessToken));

                using (var logger2 = RollbarFactory.CreateNew().Configure(loggerConfig1))
                {
                    Assert.AreEqual(initialCount + 2, RollbarQueueController.Instance.GetQueuesCount());
                    Assert.AreEqual(initialCount1 + 2, RollbarQueueController.Instance.GetQueuesCount(loggerConfig1.AccessToken));
                    Assert.AreEqual(initialCount2 + 0, RollbarQueueController.Instance.GetQueuesCount(loggerConfig2.AccessToken));

                    using (var logger3 = RollbarFactory.CreateNew().Configure(loggerConfig2))
                    {
                        Assert.AreEqual(initialCount + 3, RollbarQueueController.Instance.GetQueuesCount());
                        Assert.AreEqual(initialCount1 + 2, RollbarQueueController.Instance.GetQueuesCount(loggerConfig1.AccessToken));
                        Assert.AreEqual(initialCount2 + 1, RollbarQueueController.Instance.GetQueuesCount(loggerConfig2.AccessToken));
                    }

                    // an unused queue does not get removed immediately (but eventually) - so let's wait for it for a few processing cycles:
                    while ((initialCount + 2) != RollbarQueueController.Instance.GetQueuesCount())
                    {
                        Thread.Sleep(TimeSpan.FromMilliseconds(250));
                    }

                    // if everything is good, we should get here way before this test method times out:
                    Assert.AreEqual(initialCount + 2, RollbarQueueController.Instance.GetQueuesCount());
                    Assert.AreEqual(initialCount1 + 2, RollbarQueueController.Instance.GetQueuesCount(loggerConfig1.AccessToken));
                    Assert.AreEqual(initialCount2 + 0, RollbarQueueController.Instance.GetQueuesCount(loggerConfig2.AccessToken));
                }

                // an unused queue does not get removed immediately (but eventually) - so let's wait for it for a few processing cycles:
                while ((initialCount + 1) != RollbarQueueController.Instance.GetQueuesCount())
                {
                    Thread.Sleep(TimeSpan.FromMilliseconds(250));
                }

                // if everything is good, we should get here way before this test method times out:
                Assert.AreEqual(initialCount + 1, RollbarQueueController.Instance.GetQueuesCount());
                Assert.AreEqual(initialCount1 + 1, RollbarQueueController.Instance.GetQueuesCount(loggerConfig1.AccessToken));
                Assert.AreEqual(initialCount2 + 0, RollbarQueueController.Instance.GetQueuesCount(loggerConfig2.AccessToken));
            }

            // an unused queue does not get removed immediately (but eventually) - so let's wait for it for a few processing cycles:
            while ((initialCount + 0) != RollbarQueueController.Instance.GetQueuesCount())
            {
                Thread.Sleep(TimeSpan.FromMilliseconds(250));
            }

            // if everything is good, we should get here way before this test method times out:
            Assert.AreEqual(initialCount + 0, RollbarQueueController.Instance.GetQueuesCount());
            Assert.AreEqual(initialCount1 + 0, RollbarQueueController.Instance.GetQueuesCount(loggerConfig1.AccessToken));
            Assert.AreEqual(initialCount2 + 0, RollbarQueueController.Instance.GetQueuesCount(loggerConfig2.AccessToken));
        }
Пример #2
0
        public void TestTruncation()
        {
            Payload[] testPayloads = new Payload[]
            {
                new Payload(this._config.RollbarLoggerConfig.RollbarDestinationOptions.AccessToken, new Data(
                                this._config.RollbarLoggerConfig,
                                new Body(new Message("A message I wish to send to the rollbar overlords", new Dictionary <string, object>()
                {
                    { "longMessageString", "very-long-string-very-long-string-very-long-" }, { "theMessageNumber", 11 },
                })),
                                new Dictionary <string, object>()
                {
                    { "longDataString", "long-string-very-long-string-very-long-" }, { "theDataNumber", 15 },
                })
                            ),
                new Payload(this._config.RollbarLoggerConfig.RollbarDestinationOptions.AccessToken, new Data(
                                this._config.RollbarLoggerConfig,
                                new Body("A terrible crash!"),
                                new Dictionary <string, object>()
                {
                    { "longDataString", "long-string-very-long-string-very-long-" }, { "theDataNumber", 15 },
                })
                            ),
                new Payload(this._config.RollbarLoggerConfig.RollbarDestinationOptions.AccessToken, new Data(
                                this._config.RollbarLoggerConfig,
                                new Body(GetException()),
                                new Dictionary <string, object>()
                {
                    { "longDataString", "long-string-very-long-string-very-long-" }, { "theDataNumber", 15 },
                })
                            ),
                new Payload(this._config.RollbarLoggerConfig.RollbarDestinationOptions.AccessToken, new Data(
                                this._config.RollbarLoggerConfig,
                                new Body(GetAggregateException()),
                                new Dictionary <string, object>()
                {
                    { "longDataString", "long-string-very-long-string-very-long-" }, { "theDataNumber", 15 },
                })
                            ),
            };

            TimeSpan blockingTimeout = TimeSpan.FromSeconds(10);

            using (var logger = RollbarFactory.CreateNew(this._config.RollbarLoggerConfig))
            {
                Assert.IsTrue(logger.Config.RollbarDeveloperOptions.Transmit);

                foreach (var payload in testPayloads)
                {
                    logger.AsBlockingLogger(blockingTimeout).Log(payload.Data);
                }
            }

            IterativeTruncationStrategy truncationStrategy = null;

            const int payloadByteSizeLimit = 10; //we are intentionally exaggerating here to force all the iterations to happen...
            List <IPayloadTruncationStrategy> iterations = new List <IPayloadTruncationStrategy>();

            iterations.Add(new RawTruncationStrategy());
            truncationStrategy = new IterativeTruncationStrategy(400, iterations);
            AssertPayloadSizeReduction(false, testPayloads, truncationStrategy);
            AssertPayloadSizeReduction(false, testPayloads, truncationStrategy);
            //using (var logger = RollbarFactory.CreateNew(this._config))
            //{
            //    foreach (var payload in testPayloads)
            //    {
            //        logger.AsBlockingLogger(blockingTimeout).Log(payload.Data);
            //    }
            //}

            iterations.Add(new FramesTruncationStrategy(totalHeadFramesToPreserve: 1, totalTailFramesToPreserve: 1));
            truncationStrategy = new IterativeTruncationStrategy(payloadByteSizeLimit, iterations);
            AssertPayloadSizeReduction(false, testPayloads.Take(2).ToArray(), truncationStrategy);
            AssertPayloadSizeReduction(false, testPayloads.Take(2).ToArray(), truncationStrategy);
            Payload[] payloadsWithFrames = testPayloads.Reverse().Take(2).ToArray();
            foreach (var payload in payloadsWithFrames)
            {
                bool hasFramesToTrim = false;
                hasFramesToTrim |= (payload?.Data?.Body?.Trace?.Frames?.Length > 1);
                hasFramesToTrim |= ((payload?.Data?.Body?.TraceChain != null) && payload.Data.Body.TraceChain.Any(trace => trace?.Frames?.Length > 1));
                AssertPayloadSizeReduction(hasFramesToTrim, payload, truncationStrategy);
                AssertPayloadSizeReduction(false, payload, truncationStrategy);
            }
            //using (var logger = RollbarFactory.CreateNew(this._config))
            //{
            //    foreach (var payload in testPayloads)
            //    {
            //        logger.AsBlockingLogger(blockingTimeout).Log(payload.Data);
            //    }
            //}

            iterations.Add(new StringsTruncationStrategy(stringBytesLimit: 10));
            truncationStrategy = new IterativeTruncationStrategy(payloadByteSizeLimit, iterations);
            AssertPayloadSizeReduction(true, testPayloads, truncationStrategy);
            AssertPayloadSizeReduction(false, testPayloads, truncationStrategy);
            //using (var logger = RollbarFactory.CreateNew(this._config))
            //{
            //    foreach (var payload in testPayloads)
            //    {
            //        logger.AsBlockingLogger(blockingTimeout).Log(payload.Data);
            //    }
            //}

            iterations.Add(new StringsTruncationStrategy(stringBytesLimit:  7));
            truncationStrategy = new IterativeTruncationStrategy(payloadByteSizeLimit, iterations);
            AssertPayloadSizeReduction(true, testPayloads, truncationStrategy);
            AssertPayloadSizeReduction(false, testPayloads, truncationStrategy);
            //using (var logger = RollbarFactory.CreateNew(this._config))
            //{
            //    foreach (var payload in testPayloads)
            //    {
            //        logger.AsBlockingLogger(blockingTimeout).Log(payload.Data);
            //    }
            //}

            iterations.Add(new StringsTruncationStrategy(stringBytesLimit:  3));
            truncationStrategy = new IterativeTruncationStrategy(payloadByteSizeLimit, iterations);
            AssertPayloadSizeReduction(true, testPayloads, truncationStrategy);
            AssertPayloadSizeReduction(false, testPayloads, truncationStrategy);
            //using (var logger = RollbarFactory.CreateNew(this._config))
            //{
            //    foreach (var payload in testPayloads)
            //    {
            //        logger.AsBlockingLogger(blockingTimeout).Log(payload.Data);
            //    }
            //}

            iterations.Add(new MinBodyTruncationStrategy());
            truncationStrategy = new IterativeTruncationStrategy(payloadByteSizeLimit, iterations);
            AssertPayloadSizeReduction(false, testPayloads.Take(2).ToArray(), truncationStrategy);
            AssertPayloadSizeReduction(false, testPayloads.Take(2).ToArray(), truncationStrategy);

            payloadsWithFrames = testPayloads.Reverse().Take(2).ToArray();
            foreach (var payload in payloadsWithFrames)
            {
                bool hasFramesToTrim = false;
                hasFramesToTrim |= (payload?.Data?.Body?.Trace?.Frames?.Length > 1);
                hasFramesToTrim |= ((payload?.Data?.Body?.TraceChain != null) && payload.Data.Body.TraceChain.Any(trace => trace?.Frames?.Length > 1));
                AssertPayloadSizeReduction(hasFramesToTrim, payload, truncationStrategy);
                AssertPayloadSizeReduction(false, payload, truncationStrategy);
            }

            //using (var logger = RollbarFactory.CreateNew(this._config))
            //{
            //    foreach (var payload in testPayloads)
            //    {
            //        logger.AsBlockingLogger(blockingTimeout).Log(payload.Data);
            //    }
            //}
        }
Пример #3
0
 protected override void InitializeTarget()
 {
     RollbarFactory.CreateProper(RollbarConfig, BlockingLoggingTimeout, out _rollbarAsyncLogger, out _rollbarLogger);
     base.InitializeTarget();
 }
Пример #4
0
        private void EvaluateLogMethod(ClassificationDeclaration classificationDeclaration)
        {
            RollbarConfig loggerConfig = ProvideRollbarConfig();

            object payload = null;

            switch (classificationDeclaration.PayloadType)
            {
            case PayloadType.Message:
            {
                payload = ProvideObjectToLog(classificationDeclaration);
            }
            break;

            case PayloadType.Exception:
            {
                payload = ProvideObjectToLog(classificationDeclaration);
            }
            break;

            default:
                break;
            }
            Assert.IsNotNull(payload);

            // Let's give things change to stabilize:
            //Thread.Sleep(TimeSpan.FromSeconds(2));

            using (var rollbar = RollbarFactory.CreateNew().Configure(loggerConfig))
            {
                for (int i = 0; i < Constants.TotalMeasurementSamples; i++)
                {
                    switch (classificationDeclaration.MethodVariant)
                    {
                    case MethodVariant.Async:
                    {
                        ILogger logger = rollbar;
                        using (PerformanceUtil.GetPerformanceTimer(classificationDeclaration))
                        {
                            logger.Log(ErrorLevel.Warning, payload);
                        }
                        break;
                    }

                    case MethodVariant.AsyncWaited:
                    {
                        ILogger logger = rollbar;
                        using (PerformanceUtil.GetPerformanceTimer(classificationDeclaration))
                        {
                            //TODO: implement and add SynchronousPackage around the payload object!!!
                            logger.Log(ErrorLevel.Warning, new ObjectPackage(payload, true));
                            //logger.Log(ErrorLevel.Warning, payload);
                        }
                        break;
                    }

                    case MethodVariant.Blocking:
                    {
                        // NOTE: for blocking call we want to eliminate effect of
                        // the max reporting rate restriction, so that the wait time
                        // that is a result of the rate limit is not counted against
                        // the blocking call:
                        BlockUntilRollbarQueuesAreEmpty();
                        Thread.Sleep(TimeSpan.FromSeconds(60 / rollbar.Config.MaxReportsPerMinute));

                        ILogger logger = rollbar.AsBlockingLogger(Constants.RollbarBlockingTimeout);
                        using (PerformanceUtil.GetPerformanceTimer(classificationDeclaration))
                        {
                            logger.Log(ErrorLevel.Critical, payload);
                        }
                        break;
                    }

                    default:
                        // nothing to do...
                        break;
                    }
                }

                //BlockUntilRollbarQueuesAreEmpty();
                //Thread.Sleep(TimeSpan.FromMilliseconds(250));
                //if (classificationDeclaration.MethodVariant == MethodVariant.Async)
                //{
                //    // NOTE: for async call we want to make sure the logger's instance is not
                //    // disposed until all the buffered payloads delivered to the Rollbar API.
                //    // This delay ios needed until issue #197 is resolved...
                //    BlockUntilRollbarQueuesAreEmpty();
                //}
            }
        }
        public void TestTruncation()
        {
            Payload[] testPayloads = new Payload[]
            {
                new Payload(this._config.AccessToken, new Data(
                                this._config,
                                new Body(new Message("A message I wish to send to the rollbar overlords", new Dictionary <string, object>()
                {
                    { "longMessageString", "very-long-string-very-long-string-very-long-" }, { "theMessageNumber", 11 },
                })),
                                new Dictionary <string, object>()
                {
                    { "longDataString", "long-string-very-long-string-very-long-" }, { "theDataNumber", 15 },
                })
                            ),
                new Payload(this._config.AccessToken, new Data(
                                this._config,
                                new Body("A terrible crash!"),
                                new Dictionary <string, object>()
                {
                    { "longDataString", "long-string-very-long-string-very-long-" }, { "theDataNumber", 15 },
                })
                            ),
                new Payload(this._config.AccessToken, new Data(
                                this._config,
                                new Body(GetException()),
                                new Dictionary <string, object>()
                {
                    { "longDataString", "long-string-very-long-string-very-long-" }, { "theDataNumber", 15 },
                })
                            ),
                new Payload(this._config.AccessToken, new Data(
                                this._config,
                                new Body(GetAggregateException()),
                                new Dictionary <string, object>()
                {
                    { "longDataString", "long-string-very-long-string-very-long-" }, { "theDataNumber", 15 },
                })
                            ),
            };

            TimeSpan blockingTimeout = TimeSpan.FromSeconds(5);

            using (var logger = RollbarFactory.CreateNew().Configure(this._config))
            {
                foreach (var payload in testPayloads)
                {
                    logger.AsBlockingLogger(blockingTimeout).Log(payload.Data);
                }
            }

            IterativeTruncationStrategy trancationStrategy = null;

            const int payloadByteSizeLimit = 10; //we are intentionally exaggerating here to force all the iterations to happen...
            List <IPayloadTruncationStrategy> iterations = new List <IPayloadTruncationStrategy>();

            iterations.Add(new RawTruncationStrategy());
            trancationStrategy = new IterativeTruncationStrategy(400, iterations);
            AssertPayloadSizeReduction(false, testPayloads, trancationStrategy);
            AssertPayloadSizeReduction(false, testPayloads, trancationStrategy);
            using (var logger = RollbarFactory.CreateNew().Configure(this._config))
            {
                foreach (var payload in testPayloads)
                {
                    logger.AsBlockingLogger(blockingTimeout).Log(payload.Data);
                }
            }

            iterations.Add(new FramesTruncationStrategy(totalHeadFramesToPreserve: 1, totalTailFramesToPreserve: 1));
            trancationStrategy = new IterativeTruncationStrategy(payloadByteSizeLimit, iterations);
            AssertPayloadSizeReduction(false, testPayloads.Take(3).ToArray(), trancationStrategy);
            AssertPayloadSizeReduction(false, testPayloads.Take(3).ToArray(), trancationStrategy);
            AssertPayloadSizeReduction(true, testPayloads.Reverse().Take(1).ToArray(), trancationStrategy);
            AssertPayloadSizeReduction(false, testPayloads.Reverse().Take(1).ToArray(), trancationStrategy);
            using (var logger = RollbarFactory.CreateNew().Configure(this._config))
            {
                foreach (var payload in testPayloads)
                {
                    logger.AsBlockingLogger(blockingTimeout).Log(payload.Data);
                }
            }

            iterations.Add(new StringsTruncationStrategy(stringBytesLimit: 10));
            trancationStrategy = new IterativeTruncationStrategy(payloadByteSizeLimit, iterations);
            AssertPayloadSizeReduction(true, testPayloads, trancationStrategy);
            AssertPayloadSizeReduction(false, testPayloads, trancationStrategy);
            using (var logger = RollbarFactory.CreateNew().Configure(this._config))
            {
                foreach (var payload in testPayloads)
                {
                    logger.AsBlockingLogger(blockingTimeout).Log(payload.Data);
                }
            }

            iterations.Add(new StringsTruncationStrategy(stringBytesLimit:  7));
            trancationStrategy = new IterativeTruncationStrategy(payloadByteSizeLimit, iterations);
            AssertPayloadSizeReduction(true, testPayloads, trancationStrategy);
            AssertPayloadSizeReduction(false, testPayloads, trancationStrategy);
            using (var logger = RollbarFactory.CreateNew().Configure(this._config))
            {
                foreach (var payload in testPayloads)
                {
                    logger.AsBlockingLogger(blockingTimeout).Log(payload.Data);
                }
            }

            iterations.Add(new StringsTruncationStrategy(stringBytesLimit:  3));
            trancationStrategy = new IterativeTruncationStrategy(payloadByteSizeLimit, iterations);
            AssertPayloadSizeReduction(true, testPayloads, trancationStrategy);
            AssertPayloadSizeReduction(false, testPayloads, trancationStrategy);
            using (var logger = RollbarFactory.CreateNew().Configure(this._config))
            {
                foreach (var payload in testPayloads)
                {
                    logger.AsBlockingLogger(blockingTimeout).Log(payload.Data);
                }
            }

            iterations.Add(new MinBodyTruncationStrategy());
            trancationStrategy = new IterativeTruncationStrategy(payloadByteSizeLimit, iterations);
            AssertPayloadSizeReduction(false, testPayloads.Take(2).ToArray(), trancationStrategy);
            AssertPayloadSizeReduction(false, testPayloads.Take(2).ToArray(), trancationStrategy);
            AssertPayloadSizeReduction(true, testPayloads.Reverse().Take(2).ToArray(), trancationStrategy);
            AssertPayloadSizeReduction(false, testPayloads.Reverse().Take(2).ToArray(), trancationStrategy);
            using (var logger = RollbarFactory.CreateNew().Configure(this._config))
            {
                foreach (var payload in testPayloads)
                {
                    logger.AsBlockingLogger(blockingTimeout).Log(payload.Data);
                }
            }
        }
        public void ConvenienceMethodsUseAppropriateErrorLevels(ErrorLevel expectedLogLevel)
        {
            var awaitAsyncSend  = new ManualResetEventSlim(false);
            var acctualLogLevel = ErrorLevel.Info;

            void Transform(Payload payload)
            {
                acctualLogLevel = payload.Data.Level.Value;
                awaitAsyncSend.Set();
            }

            RollbarDestinationOptions destinationOptions =
                new RollbarDestinationOptions(
                    RollbarUnitTestSettings.AccessToken,
                    RollbarUnitTestSettings.Environment
                    );
            RollbarLoggerConfig loggerConfig = new RollbarLoggerConfig();

            loggerConfig.RollbarDestinationOptions.Reconfigure(destinationOptions);

            RollbarPayloadManipulationOptions payloadManipulationOptions = new RollbarPayloadManipulationOptions();

            payloadManipulationOptions.Transform = Transform;
            loggerConfig.RollbarPayloadManipulationOptions.Reconfigure(payloadManipulationOptions);

            this.IncrementCount <CommunicationEventArgs>();
            using (var logger = RollbarFactory.CreateNew().Configure(loggerConfig))
            {
                try
                {
                    //TODO: implement and add SynchronousPackage around the payload object!!!
                    var ex = new Exception();
                    switch (expectedLogLevel)
                    {
                    case ErrorLevel.Critical:
                        logger.Critical(ex);
                        break;

                    case ErrorLevel.Error:
                        logger.Error(ex);
                        break;

                    case ErrorLevel.Warning:
                        logger.Warning(ex);
                        break;

                    case ErrorLevel.Info:
                        logger.Info(ex);
                        break;

                    case ErrorLevel.Debug:
                        logger.Debug(ex);
                        break;
                    }
                }
                catch
                {
                    Assert.Fail("should never reach here!");
                }
            }

            awaitAsyncSend.Wait();
            Assert.AreEqual(expectedLogLevel, acctualLogLevel);
        }
        public void ScopedInstanceTest()
        {
            // we need to make sure we are starting clean:
            RollbarQueueController.Instance.FlushQueues();
            RollbarQueueController.Instance.Start();
            var accessTokenQueues =
                RollbarQueueController.Instance.GetQueues(RollbarUnitTestSettings.AccessToken);

            while (accessTokenQueues.Any())
            {
                string msg = "Initial queues count: " + accessTokenQueues.Count();
                System.Diagnostics.Trace.WriteLine(msg);
                Console.WriteLine(msg);
                foreach (var queue in accessTokenQueues)
                {
                    msg = "---Payloads in a queue: " + queue.GetPayloadCount();
                    System.Diagnostics.Trace.WriteLine(msg);
                    Console.WriteLine(msg);

                    if (!queue.IsReleased)
                    {
                        queue.Release();
                    }
                    else
                    {
                        queue.Flush();
                    }
                }
                Thread.Sleep(TimeSpan.FromMilliseconds(250));
                accessTokenQueues =
                    RollbarQueueController.Instance.GetQueues(RollbarUnitTestSettings.AccessToken);
            }

            RollbarDestinationOptions destinationOptions =
                new RollbarDestinationOptions(
                    RollbarUnitTestSettings.AccessToken,
                    RollbarUnitTestSettings.Environment
                    );
            RollbarLoggerConfig loggerConfig = new RollbarLoggerConfig();

            loggerConfig.RollbarDestinationOptions.Reconfigure(destinationOptions);

            int totalInitialQueues = RollbarQueueController.Instance.GetQueuesCount(RollbarUnitTestSettings.AccessToken);

            using (var logger = RollbarFactory.CreateNew().Configure(loggerConfig))
            {
                Assert.AreEqual(totalInitialQueues + 1, RollbarQueueController.Instance.GetQueuesCount(RollbarUnitTestSettings.AccessToken));
                this.IncrementCount <CommunicationEventArgs>();
                logger.Log(ErrorLevel.Error, "test message");
            }
            // an unused queue does not get removed immediately (but eventually) - so let's wait for it for a few processing cycles:
            int currentQueuesCount =
                RollbarQueueController.Instance.GetQueuesCount(RollbarUnitTestSettings.AccessToken);

            while (totalInitialQueues != currentQueuesCount)
            {
                string msg = "Current queues count: " + currentQueuesCount + " while initial count was: " + totalInitialQueues;
                System.Diagnostics.Trace.WriteLine(msg);
                Console.WriteLine(msg);
                Thread.Sleep(TimeSpan.FromMilliseconds(250));
                currentQueuesCount =
                    RollbarQueueController.Instance.GetQueuesCount(RollbarUnitTestSettings.AccessToken);
            }

            // if everything is good, we should get here way before this test method times out:
            Assert.AreEqual(totalInitialQueues, RollbarQueueController.Instance.GetQueuesCount(RollbarUnitTestSettings.AccessToken));
        }
        public void QueueRegisterationTest()
        {
            Console.WriteLine($"Unrealeased queues count: {RollbarQueueController.Instance.GetUnReleasedQueuesCount()}");

            // we need to make sure we are starting clean:
            RollbarQueueController.Instance.FlushQueues();
            RollbarQueueController.Instance.Stop(true);
            RollbarQueueController.Instance.Start();
            //while (RollbarQueueController.Instance.GetQueuesCount() > 0)
            //{
            //    Thread.Sleep(TimeSpan.FromMilliseconds(250));
            //}
            Console.WriteLine($"Unreleased queues count: {RollbarQueueController.Instance.GetUnReleasedQueuesCount()}");

            RollbarDestinationOptions destinationOptions =
                new RollbarDestinationOptions(
                    RollbarUnitTestSettings.AccessToken,
                    RollbarUnitTestSettings.Environment
                    );
            RollbarLoggerConfig loggerConfig1 =
                new RollbarLoggerConfig();

            loggerConfig1.RollbarDestinationOptions.Reconfigure(destinationOptions);

            destinationOptions.AccessToken =
                RollbarUnitTestSettings.AccessToken.Replace('0', '1');
            RollbarLoggerConfig loggerConfig2 =
                new RollbarLoggerConfig();

            loggerConfig2.RollbarDestinationOptions.Reconfigure(destinationOptions);

            Console.WriteLine($"Unreleased queues count: {RollbarQueueController.Instance.GetUnReleasedQueuesCount()}");

            Assert.AreNotEqual(loggerConfig1.RollbarDestinationOptions.AccessToken, loggerConfig2.RollbarDestinationOptions.AccessToken);

            int initialCount  = RollbarQueueController.Instance.GetQueuesCount();
            int initialCount1 = RollbarQueueController.Instance.GetQueuesCount(loggerConfig1.RollbarDestinationOptions.AccessToken);
            int initialCount2 = RollbarQueueController.Instance.GetQueuesCount(loggerConfig2.RollbarDestinationOptions.AccessToken);

            Assert.AreEqual(initialCount + 0, RollbarQueueController.Instance.GetQueuesCount());
            Assert.AreEqual(initialCount1 + 0,
                            RollbarQueueController.Instance.GetQueuesCount(loggerConfig1.RollbarDestinationOptions.AccessToken));
            Assert.AreEqual(initialCount2 + 0,
                            RollbarQueueController.Instance.GetQueuesCount(loggerConfig2.RollbarDestinationOptions.AccessToken));

            using (var logger1 = RollbarFactory.CreateNew().Configure(loggerConfig1))
            {
                Assert.AreEqual(initialCount + 1, RollbarQueueController.Instance.GetQueuesCount());
                Assert.AreEqual(initialCount1 + 1,
                                RollbarQueueController.Instance.GetQueuesCount(loggerConfig1.RollbarDestinationOptions.AccessToken));
                Assert.AreEqual(initialCount2 + 0,
                                RollbarQueueController.Instance.GetQueuesCount(loggerConfig2.RollbarDestinationOptions.AccessToken));

                using (var logger2 = RollbarFactory.CreateNew().Configure(loggerConfig1))
                {
                    Assert.AreEqual(initialCount + 2, RollbarQueueController.Instance.GetQueuesCount());
                    Assert.AreEqual(initialCount1 + 2,
                                    RollbarQueueController.Instance.GetQueuesCount(loggerConfig1.RollbarDestinationOptions.AccessToken));
                    Assert.AreEqual(initialCount2 + 0,
                                    RollbarQueueController.Instance.GetQueuesCount(loggerConfig2.RollbarDestinationOptions.AccessToken));

                    using (var logger3 = RollbarFactory.CreateNew().Configure(loggerConfig2))
                    {
                        Assert.AreEqual(initialCount + 3, RollbarQueueController.Instance.GetQueuesCount());
                        Assert.AreEqual(initialCount1 + 2,
                                        RollbarQueueController.Instance.GetQueuesCount(loggerConfig1.RollbarDestinationOptions.AccessToken));
                        Assert.AreEqual(initialCount2 + 1,
                                        RollbarQueueController.Instance.GetQueuesCount(loggerConfig2.RollbarDestinationOptions.AccessToken));
                    }

                    // an unused queue does not get removed immediately (but eventually) - so let's wait for it for a few processing cycles:
                    while ((initialCount + 2) != RollbarQueueController.Instance.GetQueuesCount())
                    {
                        Thread.Sleep(TimeSpan.FromMilliseconds(250));
                    }

                    // if everything is good, we should get here way before this test method times out:
                    Assert.AreEqual(initialCount + 2, RollbarQueueController.Instance.GetQueuesCount());
                    Assert.AreEqual(initialCount1 + 2,
                                    RollbarQueueController.Instance.GetQueuesCount(loggerConfig1.RollbarDestinationOptions.AccessToken));
                    Assert.AreEqual(initialCount2 + 0,
                                    RollbarQueueController.Instance.GetQueuesCount(loggerConfig2.RollbarDestinationOptions.AccessToken));
                }

                // an unused queue does not get removed immediately (but eventually) - so let's wait for it for a few processing cycles:
                while ((initialCount + 1) != RollbarQueueController.Instance.GetQueuesCount())
                {
                    Thread.Sleep(TimeSpan.FromMilliseconds(250));
                }

                // if everything is good, we should get here way before this test method times out:
                Assert.AreEqual(initialCount + 1, RollbarQueueController.Instance.GetQueuesCount());
                Assert.AreEqual(initialCount1 + 1,
                                RollbarQueueController.Instance.GetQueuesCount(loggerConfig1.RollbarDestinationOptions.AccessToken));
                Assert.AreEqual(initialCount2 + 0,
                                RollbarQueueController.Instance.GetQueuesCount(loggerConfig2.RollbarDestinationOptions.AccessToken));
            }

            // an unused queue does not get removed immediately (but eventually) - so let's wait for it for a few processing cycles:
            while ((initialCount + 0) != RollbarQueueController.Instance.GetQueuesCount())
            {
                Console.WriteLine($"Unreleased queues count: {RollbarQueueController.Instance.GetUnReleasedQueuesCount()}");
                Thread.Sleep(TimeSpan.FromMilliseconds(250));
            }


            // if everything is good, we should get here way before this test method times out:
            Assert.AreEqual(initialCount + 0, RollbarQueueController.Instance.GetQueuesCount());
            Assert.AreEqual(initialCount1 + 0,
                            RollbarQueueController.Instance.GetQueuesCount(loggerConfig1.RollbarDestinationOptions.AccessToken));
            Assert.AreEqual(initialCount2 + 0,
                            RollbarQueueController.Instance.GetQueuesCount(loggerConfig2.RollbarDestinationOptions.AccessToken));
        }
Пример #9
0
 private static IRollbar FakeLogger()
 {
     return(RollbarFactory.CreateNew());
 }