Example #1
0
        public void TestRedisHostCount()
        {
            string redisJson = @"{  
                ""TimberWinR"":
                {        
                    ""Outputs"":  
	                {  
		                ""Redis"":
                        [{  
                            ""host"": 
                            [
                                ""logaggregator.mycompany.svc""
                            ]                   
		                }]
	                }
                }
            }";


            Configuration         c     = Configuration.FromString(redisJson);
            RedisOutputParameters redis = c.RedisOutputs.First() as RedisOutputParameters;

            Assert.IsTrue(redis.Host.Length >= 1);
        }
        //     [Test]
        public void TestDynamicBatch()
        {
            var mgr = new Manager();

            mgr.LogfileDir = ".";

            mgr.Config = new Configuration();

            CancellationTokenSource cancelTokenSource = new CancellationTokenSource();

            var cancelToken = cancelTokenSource.Token;

            FakeRediServer fr = new FakeRediServer(cancelToken);

            var redisParams = new RedisOutputParameters();

            redisParams.BatchCount    = 10;
            redisParams.MaxBatchCount = 40;
            redisParams.Interval      = 100;

            var redisOutput = new Outputs.RedisOutput(mgr, redisParams, cancelToken);


            // Message is irrelavant
            JObject jsonMessage = new JObject
            {
                { "type", "Win32-FileLog" },
                { "ComputerName", "dev.vistaprint.net" },
                { "Text", "{\"Email\":\"[email protected]\",\"Active\":true,\"CreatedDate\":\"2013-01-20T00:00:00Z\",\"Roles\":[\"User\",\"Admin\"]}" }
            };


            // Send 1000 messages at max throttle
            for (int i = 0; i < 1000; i++)
            {
                Thread.Sleep(10);
                redisOutput.Startup(jsonMessage);
            }

            while (redisOutput.SentMessages < 1000)
            {
                System.Diagnostics.Debug.WriteLine(redisOutput.SentMessages);
                Thread.Sleep(1000);
            }

            fr.Shutdown();

            cancelTokenSource.Cancel();

            System.Diagnostics.Debug.WriteLine(redisOutput.ToJson());
            System.Diagnostics.Debug.WriteLine(redisOutput.QueueDepth);

            JObject json = redisOutput.ToJson();
            var     mbc  = json["redis"]["reachedMaxBatchCountTimes"].Value <int>();
            var     sm   = json["redis"]["sentMessageCount"].Value <int>();
            var     errs = json["redis"]["errors"].Value <int>();
            var     cbc  = json["redis"]["currentBatchCount"].Value <int>();

            // No errors
            Assert.AreEqual(0, errs);

            // Should have reached max at least 1 time
            Assert.GreaterOrEqual(mbc, 1);

            // Should have sent 1000 messages
            Assert.AreEqual(1000, sm);

            // Should reset back down to original
            Assert.AreEqual(cbc, 10);
        }