Example #1
0
        public ICanAddEndpointOrLoggingOrCorrelationOrCreate <TMessage, TCommand, TEvent, TRequest, TResponse> ConnectToServer(string uri)
        {
            var monitorFactory = new ElasticSearchMonitorFactory <TMessage>(
                _indexPrefix, _types, _instanceName,
                _samplePeriod, Scheduler.Default,
                new ElasticClient(new ConnectionSettings(new Uri(uri))));

            _config.UsingMonitor(monitorFactory);
            return(_config);
        }
        public void ShouldBeAbleToCreateMonitor()
        {
            IElasticClient elasticClient = A.Fake<IElasticClient>();
            TestScheduler testScheduler = new TestScheduler();

            IMonitorFactory<TestMessage> factory = new ElasticSearchMonitorFactory<TestMessage>("indexName", new List<Type>(), "instanceName", TimeSpan.FromSeconds(1), testScheduler, elasticClient);

            IMonitor<TestMessage> monitor = factory.Create("SomeName");

            Assert.That(monitor, Is.Not.Null);
        }
Example #3
0
        public void ShouldBeAbleToCreateMonitor()
        {
            IElasticClient elasticClient = A.Fake <IElasticClient>();
            TestScheduler  testScheduler = new TestScheduler();

            IMonitorFactory <TestMessage> factory = new ElasticSearchMonitorFactory <TestMessage>("indexName", new List <Type>(), "instanceName", TimeSpan.FromSeconds(1), testScheduler, elasticClient);

            IMonitor <TestMessage> monitor = factory.Create("SomeName");

            Assert.NotNull(monitor);
        }
Example #4
0
        public void ShouldDisposeCleanly()
        {
            IElasticClient elasticClient = A.Fake <IElasticClient>();
            TestScheduler  testScheduler = new TestScheduler();

            IMonitorFactory <TestMessage> factory = new ElasticSearchMonitorFactory <TestMessage>("indexName", new List <Type>(), "instanceName", TimeSpan.FromSeconds(1), testScheduler, elasticClient);

            IMonitor <TestMessage> monitor = factory.Create("SomeName");

            monitor.Dispose();
        }
        public void ShouldAttemptToSaveIfMessagesReceived()
        {
            IElasticClient elasticClient = A.Fake<IElasticClient>();
            TestScheduler testScheduler = new TestScheduler();

            IMonitorFactory<TestMessage> factory = new ElasticSearchMonitorFactory<TestMessage>("indexName", new List<Type>(), "instanceName", TimeSpan.FromSeconds(1), testScheduler, elasticClient);

            IMonitor<TestMessage> monitor = factory.Create("SomeName");

            monitor.MessageReceived(new TestMessage(), TimeSpan.FromMilliseconds(1));

            testScheduler.AdvanceBy(TimeSpan.FromMinutes(1).Ticks);

            A.CallTo(() => elasticClient.Bulk(A<IBulkRequest>._)).MustHaveHappened(Repeated.Exactly.Once);
        }
        public void ShouldNotAttemptToSaveIfNoMessages()
        {
            IElasticClient elasticClient = A.Fake<IElasticClient>();
            TestScheduler testScheduler = new TestScheduler();

            IMonitorFactory<TestMessage> factory = new ElasticSearchMonitorFactory<TestMessage>("indexName", new List<Type>(), "instanceName", TimeSpan.FromSeconds(1), testScheduler, elasticClient);

            IMonitor<TestMessage> monitor = factory.Create("SomeName");

            Assert.That(monitor, Is.Not.Null);

            testScheduler.AdvanceBy(TimeSpan.FromMinutes(1).Ticks);

            A.CallTo(() => elasticClient.Bulk(A<IBulkRequest>._)).MustNotHaveHappened();
        }
Example #7
0
        public void ShouldAttemptToSaveIfMessagesReceived()
        {
            IElasticClient elasticClient = A.Fake <IElasticClient>();
            TestScheduler  testScheduler = new TestScheduler();

            IMonitorFactory <TestMessage> factory = new ElasticSearchMonitorFactory <TestMessage>("indexName", new List <Type>(), "instanceName", TimeSpan.FromSeconds(1), testScheduler, elasticClient);

            IMonitor <TestMessage> monitor = factory.Create("SomeName");

            monitor.MessageReceived(new TestMessage(), TimeSpan.FromMilliseconds(1));

            testScheduler.AdvanceBy(TimeSpan.FromMinutes(1).Ticks);

            A.CallTo(() => elasticClient.Bulk(A <IBulkRequest> ._)).MustHaveHappened(1, Times.Exactly);
        }
Example #8
0
        public void ShouldNotAttemptToSaveIfNoMessages()
        {
            IElasticClient elasticClient = A.Fake <IElasticClient>();
            TestScheduler  testScheduler = new TestScheduler();

            IMonitorFactory <TestMessage> factory = new ElasticSearchMonitorFactory <TestMessage>("indexName", new List <Type>(), "instanceName", TimeSpan.FromSeconds(1), testScheduler, elasticClient);

            IMonitor <TestMessage> monitor = factory.Create("SomeName");

            Assert.NotNull(monitor);

            testScheduler.AdvanceBy(TimeSpan.FromMinutes(1).Ticks);

            A.CallTo(() => elasticClient.Bulk(A <IBulkRequest> ._)).MustNotHaveHappened();
        }
        public void ShouldAttemptToSaveMultipleCountersIfMessagesSent()
        {
            IElasticClient elasticClient = A.Fake<IElasticClient>();
            TestScheduler testScheduler = new TestScheduler();

            var types = new List<Type> { typeof(TestMessage) };
            IMonitorFactory<TestMessage> factory = new ElasticSearchMonitorFactory<TestMessage>("indexName", types, "instanceName", TimeSpan.FromSeconds(1), testScheduler, elasticClient);

            IMonitor<TestMessage> monitor = factory.Create("SomeName");

            monitor.MessageSent(new TestMessage(), TimeSpan.FromMilliseconds(1));

            testScheduler.AdvanceBy(TimeSpan.FromMinutes(1).Ticks);

            A.CallTo(() => elasticClient.Bulk(A<IBulkRequest>.That.Matches(request => request.Operations.Count == 1 + types.Count))).MustHaveHappened(Repeated.Exactly.Once);
        }
Example #10
0
        public void ShouldAttemptToSaveMultipleCountersIfMessagesReceived()
        {
            IElasticClient elasticClient = A.Fake <IElasticClient>();
            TestScheduler  testScheduler = new TestScheduler();

            var types = new List <Type> {
                typeof(TestMessage)
            };
            IMonitorFactory <TestMessage> factory = new ElasticSearchMonitorFactory <TestMessage>("indexName", types, "instanceName", TimeSpan.FromSeconds(1), testScheduler, elasticClient);

            IMonitor <TestMessage> monitor = factory.Create("SomeName");

            monitor.MessageReceived(new TestMessage(), TimeSpan.FromMilliseconds(1));

            testScheduler.AdvanceBy(TimeSpan.FromMinutes(1).Ticks);

            A.CallTo(() => elasticClient.Bulk(A <IBulkRequest> .That.Matches(request => request.Operations.Count == 1 + types.Count))).MustHaveHappened(1, Times.Exactly);
        }
        public void ShouldDisposeCleanly()
        {
            IElasticClient elasticClient = A.Fake<IElasticClient>();
            TestScheduler testScheduler = new TestScheduler();

            IMonitorFactory<TestMessage> factory = new ElasticSearchMonitorFactory<TestMessage>("indexName", new List<Type>(), "instanceName", TimeSpan.FromSeconds(1), testScheduler, elasticClient);

            IMonitor<TestMessage> monitor = factory.Create("SomeName");

            monitor.Dispose();
        }