public void WhenAnEventIsWrittenToTheSinkItIsRetrievableFromTheDocumentStore()
        {
            using (var documentStore = new EmbeddableDocumentStore {RunInMemory = true}.Initialize())
            {
                var timestamp = new DateTimeOffset(2013, 05, 28, 22, 10, 20, 666, TimeSpan.FromHours(10));
                var exception = new ArgumentException("Mládek");
                const LogEventLevel level = LogEventLevel.Information;
                const string messageTemplate = "{Song}++";
                var properties = new List<LogEventProperty> { new LogEventProperty("Song", new ScalarValue("New Macabre")) };

                using (var ravenSink = new RavenDBSink(documentStore, 2, TinyWait, null))
                {
                    var template = new MessageTemplateParser().Parse(messageTemplate);
                    var logEvent = new Events.LogEvent(timestamp, level, exception, template, properties);
                    ravenSink.Emit(logEvent);
                }

                using (var session = documentStore.OpenSession())
                {
                    var events = session.Query<LogEvent>().Customize(x => x.WaitForNonStaleResults()).ToList();
                    Assert.AreEqual(1, events.Count);
                    var single = events.Single();
                    Assert.AreEqual(messageTemplate, single.MessageTemplate);
                    Assert.AreEqual("\"New Macabre\"++", single.RenderedMessage);
                    Assert.AreEqual(timestamp, single.Timestamp);
                    Assert.AreEqual(level, single.Level);
                    Assert.AreEqual(1, single.Properties.Count);
                    Assert.AreEqual("New Macabre", single.Properties["Song"]);
                    Assert.AreEqual(exception.Message, single.Exception.Message);
                }
            }
        }
Exemple #2
0
        public void WhenUsingConnectionStringInCtorInternalDocumentStoreIsCreated()
        {
            var timestamp                       = new DateTimeOffset(2013, 05, 28, 22, 10, 20, 666, TimeSpan.FromHours(10));
            var exception                       = new ArgumentException("Mládek");
            const LogEventLevel level           = LogEventLevel.Information;
            const string        messageTemplate = "{Song}++";
            var properties                      = new List <LogEventProperty> {
                new LogEventProperty("Song", new ScalarValue("New Macabre"))
            };
            var events = new Dictionary <string, LogEvent>();

            using (var store = Raven.Embedded.EmbeddedServer.Instance.GetDocumentStore(nameof(WhenUsingConnectionStringInCtorInternalDocumentStoreIsCreated)))
            {
                store.OnBeforeStore += (sender, e) => events[e.DocumentId] = (LogEvent)e.Entity;
                store.Initialize();

                using (var ravenSink = new RavenDBSink(store, 2, TinyWait, null))
                {
                    var template = new MessageTemplateParser().Parse(messageTemplate);
                    var logEvent = new Events.LogEvent(timestamp, level, exception, template, properties);
                    ravenSink.Emit(logEvent);
                }

                Assert.AreEqual(1, events.Count);
                var single = events.First().Value;
                Assert.AreEqual(messageTemplate, single.MessageTemplate);
                Assert.AreEqual("\"New Macabre\"++", single.RenderedMessage);
                Assert.AreEqual(timestamp, single.Timestamp);
                Assert.AreEqual(level, single.Level);
                Assert.AreEqual(1, single.Properties.Count);
                Assert.AreEqual("New Macabre", single.Properties["Song"]);
                Assert.AreEqual(exception.Message, single.Exception.Message);
            }
        }
Exemple #3
0
        public void WnenAnErrorEventIsWrittenWithExpirationItHasProperMetadata()
        {
            using (var documentStore = Raven.Embedded.EmbeddedServer.Instance.GetDocumentStore(nameof(WhenErrorExpirationSetToInfiniteErrorsDontExpire)))
            {
                documentStore.Initialize();

                var timestamp                       = new DateTimeOffset(2013, 05, 28, 22, 10, 20, 666, TimeSpan.FromHours(10));
                var errorExpiration                 = TimeSpan.FromDays(1);
                var expiration                      = TimeSpan.FromMinutes(15);
                var targetExpiration                = DateTime.UtcNow.Add(errorExpiration);
                var exception                       = new ArgumentException("Mládek");
                const LogEventLevel level           = LogEventLevel.Error;
                const string        messageTemplate = "{Song}++";
                var properties                      = new List <LogEventProperty> {
                    new LogEventProperty("Song", new ScalarValue("New Macabre"))
                };

                using (var ravenSink = new RavenDBSink(documentStore, 2, TinyWait, null, expiration: expiration, errorExpiration: errorExpiration))
                {
                    var template = new MessageTemplateParser().Parse(messageTemplate);
                    var logEvent = new Events.LogEvent(timestamp, level, exception, template, properties);
                    ravenSink.Emit(logEvent);
                }

                using (var session = documentStore.OpenSession())
                {
                    var logEvent         = session.Query <LogEvent>().Customize(x => x.WaitForNonStaleResults()).First();
                    var metaData         = session.Advanced.GetMetadataFor(logEvent)[RavenDBSink.RavenExpirationDate].ToString();
                    var actualExpiration = Convert.ToDateTime(metaData).ToUniversalTime();
                    Assert.GreaterOrEqual(actualExpiration, targetExpiration, "The document should expire on or after {0} but expires {1}", targetExpiration, actualExpiration);
                }
            }
        }
Exemple #4
0
        public void WhenErrorExpirationSetToInfiniteErrorsDontExpire()
        {
            using (var documentStore = Raven.Embedded.EmbeddedServer.Instance.GetDocumentStore(nameof(WhenErrorExpirationSetToInfiniteErrorsDontExpire)))
            {
                documentStore.Initialize();

                var timestamp                       = new DateTimeOffset(2013, 05, 28, 22, 10, 20, 666, TimeSpan.FromHours(10));
                var errorExpiration                 = Timeout.InfiniteTimeSpan;
                var targetExpiration                = DateTime.UtcNow.Add(errorExpiration);
                var exception                       = new ArgumentException("Mládek");
                const LogEventLevel level           = LogEventLevel.Information;
                const string        messageTemplate = "{Song}++";
                var properties                      = new List <LogEventProperty> {
                    new LogEventProperty("Song", new ScalarValue("New Macabre"))
                };

                using (var ravenSink = new RavenDBSink(documentStore, 2, TinyWait, null, errorExpiration: errorExpiration))
                {
                    var template = new MessageTemplateParser().Parse(messageTemplate);
                    var logEvent = new Events.LogEvent(timestamp, level, exception, template, properties);
                    ravenSink.Emit(logEvent);
                }

                using (var session = documentStore.OpenSession())
                {
                    var logEvent = session.Query <LogEvent>().Customize(x => x.WaitForNonStaleResults()).First();
                    Assert.IsFalse(session.Advanced.GetMetadataFor(logEvent).ContainsKey(RavenDBSink.RavenExpirationDate), "No expiration set");
                }
            }
        }
Exemple #5
0
        public void WhenNoExpirationIsProvidedMessagesDontExpire()
        {
            const string databaseName = nameof(WhenNoExpirationIsProvidedMessagesDontExpire);

            using (var documentStore = Raven.Embedded.EmbeddedServer.Instance.GetDocumentStore(databaseName))
            {
                documentStore.Initialize();
                var timestamp                       = new DateTimeOffset(2013, 05, 28, 22, 10, 20, 666, TimeSpan.FromHours(10));
                var exception                       = new ArgumentException("Mládek");
                const LogEventLevel level           = LogEventLevel.Error;
                const string        messageTemplate = "{Song}++";
                var properties                      = new List <LogEventProperty> {
                    new LogEventProperty("Song", new ScalarValue("New Macabre"))
                };

                using (var ravenSink = new RavenDBSink(documentStore, 2, TinyWait, null))
                {
                    var template = new MessageTemplateParser().Parse(messageTemplate);
                    var logEvent = new Events.LogEvent(timestamp, level, exception, template, properties);
                    ravenSink.Emit(logEvent);
                }

                using (var session = documentStore.OpenSession())
                {
                    var logEvent = session.Query <LogEvent>().Customize(x => x.WaitForNonStaleResults()).First();
                    Assert.False(session.Advanced.GetMetadataFor(logEvent).ContainsKey(Constants.Documents.Metadata.Expires), "No expiration set");
                }

                documentStore.Maintenance.Server.Send(new DeleteDatabasesOperation(databaseName, hardDelete: true, fromNode: null, timeToWaitForConfirmation: null));
            }
        }
Exemple #6
0
        public void WhenAnEventIsWrittenToTheSinkItIsRetrievableFromTheDocumentStore()
        {
            const string databaseName = nameof(WhenAnEventIsWrittenToTheSinkItIsRetrievableFromTheDocumentStore);

            using (var documentStore = Raven.Embedded.EmbeddedServer.Instance.GetDocumentStore(databaseName))
            {
                documentStore.Initialize();

                var timestamp                       = new DateTimeOffset(2013, 05, 28, 22, 10, 20, 666, TimeSpan.FromHours(10));
                var exception                       = new ArgumentException("Mládek");
                const LogEventLevel level           = LogEventLevel.Information;
                const string        messageTemplate = "{Song}++";
                var properties                      = new List <LogEventProperty> {
                    new LogEventProperty("Song", new ScalarValue("New Macabre"))
                };

                using (var ravenSink = new RavenDBSink(documentStore, 2, TinyWait, null))
                {
                    var template = new MessageTemplateParser().Parse(messageTemplate);
                    var logEvent = new Events.LogEvent(timestamp, level, exception, template, properties);
                    ravenSink.Emit(logEvent);
                }

                using (var session = documentStore.OpenSession())
                {
                    var events = session.Query <LogEvent>().Customize(x => x.WaitForNonStaleResults()).ToList();
                    Assert.Single(events);
                    var single = events.Single();
                    Assert.Equal(messageTemplate, single.MessageTemplate);
                    Assert.Equal("\"New Macabre\"++", single.RenderedMessage);
                    Assert.Equal(timestamp, single.Timestamp);
                    Assert.Equal(level, single.Level);
                    Assert.Equal(1, single.Properties.Count);
                    Assert.Equal("New Macabre", single.Properties["Song"]);
                    Assert.Equal(exception.Message, single.Exception.Message);
                }

                documentStore.Maintenance.Server.Send(new DeleteDatabasesOperation(databaseName, hardDelete: true, fromNode: null, timeToWaitForConfirmation: null));
            }
        }
Exemple #7
0
        public void WhenAnEventIsWrittenWithExpirationCallbackItHasProperMetadata()
        {
            const string databaseName = nameof(WhenAnErrorEventIsWrittenWithExpirationItHasProperMetadata);

            using (var documentStore = Raven.Embedded.EmbeddedServer.Instance.GetDocumentStore(databaseName))
            {
                documentStore.Initialize();

                var timestamp        = new DateTimeOffset(2013, 05, 28, 22, 10, 20, 666, TimeSpan.FromHours(10));
                var expiration       = TimeSpan.FromDays(1);
                var errorExpiration  = TimeSpan.FromMinutes(15);
                var targetExpiration = DateTime.UtcNow.Add(expiration);
                TimeSpan func(Events.LogEvent le) => le.Level == LogEventLevel.Information ? expiration : errorExpiration;

                var exception                       = new ArgumentException("Ml�dek");
                const LogEventLevel level           = LogEventLevel.Information;
                const string        messageTemplate = "{Song}++";
                var properties                      = new List <LogEventProperty> {
                    new LogEventProperty("Song", new ScalarValue("New Macabre"))
                };

                using (var ravenSink = new RavenDBSink(documentStore, 2, TinyWait, null, logExpirationCallback: func))
                {
                    var template = new MessageTemplateParser().Parse(messageTemplate);
                    var logEvent = new Events.LogEvent(timestamp, level, exception, template, properties);
                    ravenSink.Emit(logEvent);
                }

                using (var session = documentStore.OpenSession())
                {
                    var logEvent         = session.Query <LogEvent>().Customize(x => x.WaitForNonStaleResults()).First();
                    var metaData         = session.Advanced.GetMetadataFor(logEvent)[Constants.Documents.Metadata.Expires].ToString();
                    var actualExpiration = Convert.ToDateTime(metaData).ToUniversalTime();
                    Assert.True(actualExpiration >= targetExpiration, $"The document should expire on or after {targetExpiration} but expires {actualExpiration}");
                }

                documentStore.Maintenance.Server.Send(new DeleteDatabasesOperation(databaseName, hardDelete: true, fromNode: null, timeToWaitForConfirmation: null));
            }
        }
Exemple #8
0
        public void WhenAnEventIsWrittenToTheSinkItIsRetrievableFromTheDocumentStore()
        {
            using (var documentStore = Raven.Embedded.EmbeddedServer.Instance.GetDocumentStore(nameof(WhenAnEventIsWrittenToTheSinkItIsRetrievableFromTheDocumentStore)))
            {
                documentStore.Initialize();

                var timestamp                       = new DateTimeOffset(DateTime.UtcNow, TimeSpan.FromHours(0));
                var exception                       = new ArgumentException("Mládek");
                const LogEventLevel level           = LogEventLevel.Information;
                const string        messageTemplate = "{Song}++";
                var properties                      = new List <LogEventProperty> {
                    new LogEventProperty("Song", new ScalarValue("New Macabre"))
                };

                using (var ravenSink = new RavenDBSink(documentStore, 2, TinyWait, null))
                {
                    var template = new MessageTemplateParser().Parse(messageTemplate);
                    var logEvent = new Events.LogEvent(timestamp, level, exception, template, properties);
                    ravenSink.Emit(logEvent);
                }

                using (var session = documentStore.OpenSession())
                {
                    var events = session.Query <LogEvent>().Customize(x => x.WaitForNonStaleResults()).ToList();
                    Assert.GreaterOrEqual(events.Count, 1);

                    var single = events.First(f => f.Timestamp == timestamp);
                    Assert.AreEqual(messageTemplate, single.MessageTemplate);
                    Assert.AreEqual("\"New Macabre\"++", single.RenderedMessage);
                    Assert.AreEqual(timestamp, single.Timestamp);
                    Assert.AreEqual(level, single.Level);
                    Assert.AreEqual(1, single.Properties.Count);
                    Assert.AreEqual("New Macabre", single.Properties["Song"]);
                    Assert.AreEqual(exception.Message, single.Exception.Message);
                }
            }
        }