public void ShouldRaiseFlushFailedOnFlushAsyncWhenHttpClientFails() { var httpClient = HttpClientTestHelper.Create(); httpClient.When(client => client.PostAsync(Arg.Any <string>(), Arg.Any <HttpContent>())).Do(action => { throw new Exception(); }); using (var sink = new EventHubHttpSink(httpClient, "eventHubNameNs", "eventhubName", "pubId", "token", Buffering.DefaultBufferingInterval, Buffering.DefaultBufferingCount, Buffering.DefaultMaxBufferSize, TimeSpan.Zero)) using (var collectErrorsListener = new MockEventListener()) { collectErrorsListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Error, Keywords.All); sink.OnNext(EventEntryTestHelper.Create()); try { sink.FlushAsync().Wait(); Assert.Fail("AggregateException should be thrown."); } catch (AggregateException ex) { Assert.IsInstanceOfType(ex.InnerException, typeof(FlushFailedException)); } Assert.IsTrue(collectErrorsListener.WrittenEntries.Any(x => x.EventId == 1)); } }
public void ShouldRaiseFlushFailedOnFlushAsyncWhenEventHubClientFails() { var eventHubClient = Substitute.For <IEventHubClient>(); using (var sink = new EventHubAmqpSink(eventHubClient, Buffering.DefaultBufferingInterval, Buffering.DefaultBufferingCount, Buffering.DefaultMaxBufferSize, TimeSpan.Zero)) using (var collectErrorsListener = new MockEventListener()) { collectErrorsListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Error, Keywords.All); eventHubClient.When(client => client.SendBatchAsync(Arg.Any <IEnumerable <EventData> >())) .Do(action => { throw new Exception(); }); sink.OnNext(EventEntryTestHelper.Create()); try { sink.FlushAsync().Wait(); Assert.Fail("AggregateException should be thrown."); } catch (AggregateException ex) { Assert.IsInstanceOfType(ex.InnerException, typeof(FlushFailedException)); } Assert.IsTrue(collectErrorsListener.WrittenEntries.Any(x => x.EventId == 1)); } }
protected override void Given() { base.Given(); this.sink = new SqlDatabaseSink(InstanceName, this.GetSqlConnectionString(), SqlDatabaseLog.DefaultTableName, Buffering.DefaultBufferingInterval, NumberOfEntries, Buffering.DefaultMaxBufferSize, Timeout.InfiniteTimeSpan); this.collectErrorsListener = new MockEventListener(); this.collectErrorsListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Error, Keywords.All); }
public void when_400_error_is_returned_then_batch_fails_and_logs_exception_without_timeout() { var mockHttpListener = new MockHttpListener(); using (var collectErrorsListener = new MockEventListener()) { collectErrorsListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Error, Keywords.All); var endpoint = mockHttpListener.Start(new MockHttpListenerResponse() { ResponseCode = 400, ContentType = "application/json", Content = "{ \"error\": \"InvalidIndexNameException[[log,stash] Invalid index name [log,stash], must not contain the following characters [\\\\, /, *, ?, \\\", <, >, |, , ,]]\",\"status\": 400}" }); var sink = new ElasticsearchSink("instance", endpoint, "slabtest", "etw", true, TimeSpan.FromSeconds(1), 100, 800, TimeSpan.FromMinutes(1)); sink.OnNext(EventEntryTestHelper.Create()); var flushCompleteInTime = sink.FlushAsync().Wait(TimeSpan.FromSeconds(45)); mockHttpListener.Stop(); // Make sure the exception is logged Assert.IsTrue(collectErrorsListener.WrittenEntries.First().Payload.Single(m => m.ToString().Contains("InvalidIndexNameException")) != null); Assert.IsTrue(flushCompleteInTime); } }
public void Setup() { _eventListener = new MockEventListener(); ctx = new Bunit.TestContext(); ctx.AddTestServices(); ctx.Services.AddSingleton <IEventListener>(_eventListener); }
protected override void Given() { this.collectErrorsListener = new MockEventListener(); this.collectErrorsListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Informational, SemanticLoggingEventSource.Keywords.Sink); this.sink = new TestableWindowsAzureTableSink("TestName", maxBufferSize: BufferSize); sink.WaitHandle.Reset(); }
public void testEchoNotification() { CountdownLatch latch = new CountdownLatch(); MockEventListener listener = new MockEventListener(latch); _service.addServiceListener(createVoidResponder(), listener); awaitVoidResult("addServiceListener"); _service.sendEchoNotification(createVoidResponder(), "whatever"); awaitVoidResult(); Assert.IsTrue(latch.Wait(), "Got timeout when waiting for the event"); Assert.IsNotNull(listener.receivedEvent); Assert.AreEqual("whatever", listener.receivedEvent.echoValue); }
// Ignoring because the storage client library considers inexistant account as transient so it retries and the exponential back-off could take time public void when_cannot_connect_to_storage_account_then_on_completed_should_not_stall_or_throw() { const string ValidNotExisting = "DefaultEndpointsProtocol=https;AccountName=InexistantDoesntReallyMatter;AccountKey=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa=="; using (var sink = new WindowsAzureTableSink("instanceName", ValidNotExisting, "Table", TimeSpan.FromSeconds(1), 5000, TimeSpan.FromSeconds(20))) using (var collectErrorsListener = new MockEventListener()) { collectErrorsListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Error, Keywords.All); sink.OnNext(new CloudEventEntry(EventEntryTestHelper.Create())); Assert.IsTrue(Task.Run(() => sink.OnCompleted()).Wait(TimeSpan.FromSeconds(15))); Assert.IsTrue(collectErrorsListener.WrittenEntries.Any(x => x.EventId == 500)); } }
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); var closure = sink; closure.OnNext(EventEntryTestHelper.Create()); Assert.IsTrue(Task.Run(() => closure.OnCompleted()).Wait(TimeSpan.FromSeconds(5))); Assert.IsTrue(collectErrorsListener.WrittenEntries.Any(x => x.EventId == 101)); } }
public void ShouldNotStallOrThrowWhenHttpClientFails() { var httpClient = HttpClientTestHelper.Create(); httpClient.PostAsync(Arg.Any <string>(), Arg.Any <HttpContent>()).Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.InternalServerError))); using (var sink = new EventHubHttpSink(httpClient, "eventHubNameNs", "eventhubName", "pubId", "token", Buffering.DefaultBufferingInterval, Buffering.DefaultBufferingCount, Buffering.DefaultMaxBufferSize, TimeSpan.Zero)) 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 == 1)); } }
public void ShouldNotStallOrThrowWhenEventHubClientFails() { var eventHubClient = Substitute.For <IEventHubClient>(); using (var sink = new EventHubAmqpSink(eventHubClient, Buffering.DefaultBufferingInterval, Buffering.DefaultBufferingCount, Buffering.DefaultMaxBufferSize, TimeSpan.Zero)) using (var collectErrorsListener = new MockEventListener()) { collectErrorsListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Error, Keywords.All); eventHubClient.When(client => client.SendBatchAsync(Arg.Any <IEnumerable <EventData> >())) .Do(action => { throw new Exception(); }); sink.OnNext(EventEntryTestHelper.Create()); Assert.IsTrue(Task.Run(() => sink.OnCompleted()).Wait(TimeSpan.FromSeconds(5))); Assert.IsTrue(collectErrorsListener.WrittenEntries.Any(x => x.EventId == 1)); } }
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)); } }
// Ignoring because the storage client library considers inexistant account as transient so it retries and the exponential back-off could take time public void when_cannot_connect_to_storage_account_then_flush_should_finish_faulted() { const string ValidNotExisting = "DefaultEndpointsProtocol=https;AccountName=InexistantDoesntReallyMatter;AccountKey=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa=="; using (var sink = new WindowsAzureTableSink("instanceName", ValidNotExisting, "Table", TimeSpan.FromSeconds(1), 5000, TimeSpan.FromSeconds(20))) using (var collectErrorsListener = new MockEventListener()) { collectErrorsListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Error, Keywords.All); sink.OnNext(new CloudEventEntry(EventEntryTestHelper.Create())); try { Assert.IsTrue(sink.FlushAsync().Wait(TimeSpan.FromSeconds(15))); Assert.Fail("Exception should be thrown."); } catch (AggregateException ex) { Assert.IsInstanceOfType(ex.InnerException, typeof(FlushFailedException)); } Assert.IsTrue(collectErrorsListener.WrittenEntries.Any(x => x.EventId == 500)); } }
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" ); } }
public void Then_events_are_raised_when_the_analysis_of_tests_begins() { MockEventListener.Verify( el => el.BeginCoverageAnalysisOfTestCase(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>()), Times.AtLeastOnce); }
public override void Setup() { _eventListener = new MockEventListener(); base.Setup(); Context.Services.AddSingleton <IEventListener>(_eventListener); }