public void then_defaults_EventSourceName_property() { var entry = CreateValidEntry(providerName: null); sink.OnNext(entry); sink.FlushAsync().Wait(TimeSpan.FromSeconds(5)); using (var cmd = new SqlCommand("SELECT [ProviderName] FROM Traces", this.localDbConnection)) { Assert.AreEqual(string.Empty, (string)cmd.ExecuteScalar()); } }
public void when_cannot_connect_to_database_then_on_completed_should_not_stall_or_throw() { const string ValidNotExisting = @"Data Source=(localdb)\MSSQLLocalDB; AttachDBFilename='|DataDirectory|\DoesNotExist.mdf';Initial Catalog=SemanticLoggingTests;Integrated Security=True"; using (var sink = new SqlDatabaseSink("test", ValidNotExisting, "tableName", "storedProcedureName", Buffering.DefaultBufferingInterval, Buffering.DefaultBufferingCount, Buffering.DefaultMaxBufferSize, TimeSpan.FromSeconds(20))) using (var collectErrorsListener = new MockEventListener()) { collectErrorsListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Error, Keywords.All); sink.OnNext(EventEntryTestHelper.Create()); Assert.IsTrue(Task.Run(() => sink.OnCompleted()).Wait(TimeSpan.FromSeconds(5))); Assert.IsTrue(collectErrorsListener.WrittenEntries.Any(x => x.EventId == 101)); } }
public void when_cannot_connect_to_database_then_on_completed_should_not_stall_or_throw() { const string ValidNotExisting = @"Data Source=(localdb)\v11.0; AttachDBFilename='|DataDirectory|\DoesNotExist.mdf';Initial Catalog=SemanticLoggingTests;Integrated Security=True"; using (var sink = new SqlDatabaseSink("test", ValidNotExisting, "tableName", Buffering.DefaultBufferingInterval, Buffering.DefaultBufferingCount, Buffering.DefaultMaxBufferSize, TimeSpan.FromSeconds(20))) using (var collectErrorsListener = new MockEventListener()) { collectErrorsListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Error, Keywords.All); sink.OnNext(EventEntryTestHelper.Create()); Assert.IsTrue(Task.Run(() => sink.OnCompleted()).Wait(TimeSpan.FromSeconds(5))); Assert.IsTrue(collectErrorsListener.WrittenEntries.Any(x => x.EventId == 101)); } }
public void when_cannot_connect_to_database_then_flush_should_finish_faulted() { const string ValidNotExisting = @"Data Source=(localdb)\v11.0; AttachDBFilename='|DataDirectory|\DoesNotExist.mdf';Initial Catalog=SemanticLoggingTests;Integrated Security=True"; using (var sink = new SqlDatabaseSink("test", ValidNotExisting, "tableName", Buffering.DefaultBufferingInterval, Buffering.DefaultBufferingCount, Buffering.DefaultMaxBufferSize, TimeSpan.FromSeconds(20))) using (var collectErrorsListener = new MockEventListener()) { collectErrorsListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Error, Keywords.All); sink.OnNext(EventEntryTestHelper.Create()); try { Assert.IsTrue(sink.FlushAsync().Wait(TimeSpan.FromSeconds(5))); Assert.Fail("Exception should be thrown."); } catch (AggregateException ex) { Assert.IsInstanceOfType(ex.InnerException, typeof(FlushFailedException)); } Assert.IsTrue(collectErrorsListener.WrittenEntries.Any(x => x.EventId == 101)); } }
public void when_cannot_connect_to_database_then_flush_should_finish_faulted() { const string ValidNotExisting = @"Data Source=(localdb)\MSSQLLocalDB; AttachDBFilename='|DataDirectory|\DoesNotExist.mdf';Initial Catalog=SemanticLoggingTests;Integrated Security=True"; using (var sink = new SqlDatabaseSink("test", ValidNotExisting, "tableName", "storedProcedureName", Buffering.DefaultBufferingInterval, Buffering.DefaultBufferingCount, Buffering.DefaultMaxBufferSize, TimeSpan.FromSeconds(20))) using (var collectErrorsListener = new MockEventListener()) { collectErrorsListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Error, Keywords.All); sink.OnNext(EventEntryTestHelper.Create()); try { Assert.IsTrue(sink.FlushAsync().Wait(TimeSpan.FromSeconds(5))); Assert.Fail("Exception should be thrown."); } catch (AggregateException ex) { Assert.IsInstanceOfType(ex.InnerException, typeof(FlushFailedException)); } Assert.IsTrue(collectErrorsListener.WrittenEntries.Any(x => x.EventId == 101)); } }
public void when_cannot_connect_to_database_then_flush_should_finish_faulted() { const string ValidNotExisting = @"Data Source=(localdb)\v11.0; AttachDBFilename='|DataDirectory|\DoesNotExist.mdf';Initial Catalog=SemanticLoggingTests;Integrated Security=True"; using (var sink = new SqlDatabaseSink("test", ValidNotExisting, "tableName", Buffering.DefaultBufferingInterval, Buffering.DefaultBufferingCount, Buffering.DefaultMaxBufferSize, TimeSpan.FromSeconds(20))) using (var collectErrorsListener = new MockEventListener()) { collectErrorsListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Error, Keywords.All); sink.OnNext(EventEntryTestHelper.Create()); //ERH 6.26.2015: there is volatility around the delay when under load; the longer the delay the more likely the test will pass. // This probably indicates some kind of missed case or a bad assumption about the underlying implementation const int waitTimeInSeconds = 10; try { Assert.IsTrue(sink.FlushAsync().Wait(TimeSpan.FromSeconds(waitTimeInSeconds))); Assert.Fail("Exception should be thrown."); } catch (AggregateException ex) { Console.WriteLine(ex.GetType()); Assert.IsNotNull(ex.InnerException, "ex.InnerException != null"); Console.WriteLine(ex.InnerException.GetType()); Assert.IsInstanceOfType(ex.InnerException, typeof(FlushFailedException), "exception should be of type FlushFailedException"); } Assert.IsTrue( collectErrorsListener.WrittenEntries.Any( x => x.EventId == 101 ), "should have entries for eventid 101" ); } }