예제 #1
0
        public void Start_WithNoHeartbeat_ThrowsArgumentNullException()
        {
            var client = new MockSensuClient();

            _sut = new Pacemaker(client);
            Assert.Throws <ArgumentNullException>(() => _sut.Start(null));
        }
예제 #2
0
        public void Stop_WhenNotStarted_DoesNothing()
        {
            var client = new MockSensuClient();

            _sut = new Pacemaker(client);
            _sut.Stop();
        }
예제 #3
0
        public void Start_WithValidHeartbeat_Sends1stMessageWithin5ms()
        {
            var client = new MockSensuClient();

            _sut = new Pacemaker(client);
            _sut.Start(new Heartbeat("testApp"));
            Thread.Sleep(5);
            Assert.NotEmpty(client.Messages);
        }
예제 #4
0
        public void Send_OnIHaveMeta_DoesCallEnrichMessage()
        {
            ISensuEnricher enricher = new HostInfoEnricher();
            var            sut      = new MockSensuClient();

            sut.EnrichWith(enricher);
            sut.Send(new Ok("app_name", "some_metric"));
            Assert.True(sut.Enriched);
        }
예제 #5
0
        public void Send_OnNotIHaveMeta_DoesNotCallEnrichMessage()
        {
            ISensuEnricher enricher = new HostInfoEnricher();
            var            sut      = new MockSensuClient();

            sut.EnrichWith(enricher);
            sut.Send(new {});
            Assert.False(sut.Enriched);
        }
예제 #6
0
        public void Start_WithPeriodOf1sec_Sends2MessagesIn2sec()
        {
            var client = new MockSensuClient();

            _sut = new Pacemaker(client);
            _sut.Start(new Heartbeat("testApp", 1));
            Thread.Sleep(1900);
            _sut.Stop();
            Assert.Equal(2, client.Messages.Count);
        }
예제 #7
0
        public void Heartbeat_WithNoParameters_SendsHeartbeat()
        {
            var client = new MockSensuClient();
            var sut    = new SensuMonitor(client, "testApp");

            sut.Heartbeat();
            var message = client.Messages.First();

            Assert.IsType <Heartbeat>(message);
        }
예제 #8
0
        public void Error_WithNoParameters_SendsAppError()
        {
            var client = new MockSensuClient();
            var sut    = new SensuMonitor(client, "testApp");

            sut.Error("some_dependency");
            var message = client.Messages.First();

            Assert.IsType <Error>(message);
        }
예제 #9
0
        public void Heartbeat_WithPeriod5_SetsTtlTo5()
        {
            var client = new MockSensuClient();
            var sut    = new SensuMonitor(client, "testApp");

            sut.Heartbeat(period: 5);
            var message = client.Messages.First() as Heartbeat;

            Assert.Equal(5, message.Ttl);
        }
예제 #10
0
        public void Heartbeat_WithNoParameters_SetsTtlTo60()
        {
            var client = new MockSensuClient();
            var sut    = new SensuMonitor(client, "testApp");

            sut.Heartbeat();
            var message = client.Messages.First() as Heartbeat;

            Assert.Equal(60, message.Ttl);
        }
예제 #11
0
        public void EnrichWith_WithAnEnricher_AddsEnricherToClient()
        {
            ISensuEnricher enricher = new HostInfoEnricher();
            var            sut      = new MockSensuClient();

            sut.EnrichWith(enricher);
            var enrichers = sut.GetEnrichers();

            Assert.Contains(enricher, enrichers);
        }
예제 #12
0
        public void Stop_WhileHeardbeatRunning_StopsHeartbeat()
        {
            var client = new MockSensuClient();

            _sut = new Pacemaker(client);
            _sut.Start(new Heartbeat("testApp", 1));
            Thread.Sleep(5);
            _sut.Stop();
            Thread.Sleep(2000);
            Assert.Equal(1, client.Messages.Count);
        }
예제 #13
0
        public void Heartbeat_WithOutput_SetsOutputOnHeartbeat()
        {
            var text   = "text";
            var client = new MockSensuClient();
            var sut    = new SensuMonitor(client, "testApp");

            sut.Heartbeat(message: text);
            var message = client.Messages.First() as Heartbeat;

            Assert.Equal(text, message.Output);
        }
예제 #14
0
        public void EnrichMessage_OnIHaveMeta_AddsMeta()
        {
            ISensuEnricher enricher = new HostInfoEnricher();
            var            sut      = new MockSensuClient();

            sut.EnrichWith(enricher);
            var message = new Ok("app_name", "some_metric");

            sut.Send(message);
            Assert.True(message.Meta.ContainsKey("host_name"));
        }