public StreamProcessorTest(ITestOutputHelper testOutput) : base(testOutput) { _mockEventSource = new Mock <IEventSource>(); _mockEventSource.Setup(es => es.StartAsync()).Returns(Task.CompletedTask).Callback(() => _esStartedReady.Set()); _eventSource = _mockEventSource.Object; _eventSourceFactory = new TestEventSourceFactory(_eventSource); _dataStore = new DelegatingDataStoreForStreamTests { WrappedStore = new InMemoryDataStore() }; _dataStoreUpdates = new DataStoreUpdatesImpl(new TaskExecutor(testLogger)); _dataStoreStatusProvider = new DataStoreStatusProviderImpl(_dataStore, _dataStoreUpdates); _dataSourceUpdates = new DataSourceUpdatesImpl( _dataStore, _dataStoreStatusProvider, new TaskExecutor(testLogger), testLogger, null ); _dataSourceStatusProvider = new DataSourceStatusProviderImpl(_dataSourceUpdates); _config = Configuration.Builder(SDK_KEY) .DataSource(Components.StreamingDataSource().EventSourceCreator(_eventSourceFactory.Create())) .DataStore(TestUtils.SpecificDataStore(_dataStore)) .Logging(Components.Logging(testLogging)) .Build(); }
public DataSourceStatusProviderImplTest(ITestOutputHelper testOutput) : base(testOutput) { var store = new InMemoryDataStore(); updates = new DataSourceUpdatesImpl( store, new DataStoreStatusProviderImpl(store, new DataStoreUpdatesImpl(BasicTaskExecutor, TestLogger)), BasicTaskExecutor, TestLogger, null ); statusProvider = new DataSourceStatusProviderImpl(updates); }
public void OutageTimeoutLogging() { var outageTimeout = TimeSpan.FromMilliseconds(100); var updates = new DataSourceUpdatesImpl( store, dataStoreStatusProvider, BasicTaskExecutor, TestLogger, outageTimeout ); // simulate an outage updates.UpdateStatus(DataSourceState.Interrupted, DataSourceStatus.ErrorInfo.FromHttpError(500)); // but recover from it immediately updates.UpdateStatus(DataSourceState.Valid, null); // wait until the timeout would have elapsed - no special message should be logged Thread.Sleep(outageTimeout.Add(TimeSpan.FromMilliseconds(50))); // simulate another outage updates.UpdateStatus(DataSourceState.Interrupted, DataSourceStatus.ErrorInfo.FromHttpError(501)); updates.UpdateStatus(DataSourceState.Interrupted, DataSourceStatus.ErrorInfo.FromHttpError(502)); updates.UpdateStatus(DataSourceState.Interrupted, DataSourceStatus.ErrorInfo.FromException(new IOException("x"))); updates.UpdateStatus(DataSourceState.Interrupted, DataSourceStatus.ErrorInfo.FromHttpError(501)); Thread.Sleep(outageTimeout); AssertEventually(TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(50), () => { var messages = LogCapture.GetMessages().Where(m => m.Level == LogLevel.Error).ToList(); if (messages.Count == 1) { var m = messages[0]; if (m.LoggerName == ".DataSource" && m.Text.Contains("NETWORK_ERROR (1 time)") && m.Text.Contains("ERROR_RESPONSE(501) (2 times)") && m.Text.Contains("ERROR_RESPONSE(502) (1 time)")) { return(true); } } return(false); } ); }
public void OutageTimeoutLogging() { var outageTimeout = TimeSpan.FromMilliseconds(100); var updates = new DataSourceUpdatesImpl( store, dataStoreStatusProvider, taskExecutor, testLogger, outageTimeout ); // simulate an outage updates.UpdateStatus(DataSourceState.Interrupted, DataSourceStatus.ErrorInfo.FromHttpError(500)); // but recover from it immediately updates.UpdateStatus(DataSourceState.Valid, null); // wait until the timeout would have elapsed - no special message should be logged Thread.Sleep(outageTimeout.Add(TimeSpan.FromMilliseconds(50))); // simulate another outage updates.UpdateStatus(DataSourceState.Interrupted, DataSourceStatus.ErrorInfo.FromHttpError(501)); updates.UpdateStatus(DataSourceState.Interrupted, DataSourceStatus.ErrorInfo.FromHttpError(502)); updates.UpdateStatus(DataSourceState.Interrupted, DataSourceStatus.ErrorInfo.FromException(new IOException("x"))); updates.UpdateStatus(DataSourceState.Interrupted, DataSourceStatus.ErrorInfo.FromHttpError(501)); Thread.Sleep(outageTimeout.Add(TimeSpan.FromMilliseconds(100))); var messages = logCapture.GetMessages(); Assert.Collection(messages, m => { Assert.Equal(LogLevel.Error, m.Level); Assert.Equal(".DataSource", m.LoggerName); Assert.Contains("NETWORK_ERROR (1 time)", m.Text); Assert.Contains("ERROR_RESPONSE(501) (2 times)", m.Text); Assert.Contains("ERROR_RESPONSE(502) (1 time)", m.Text); }); Assert.NotEmpty(messages); }
public StreamProcessorTest(ITestOutputHelper testOutput) : base(testOutput) { _mockEventSource = new Mock <IEventSource>(); _mockEventSource.Setup(es => es.StartAsync()).Returns(TestUtils.CompletedTask()).Callback(() => _esStartedReady.Set()); _eventSource = _mockEventSource.Object; _eventSourceFactory = new TestEventSourceFactory(_eventSource); _dataStore = new DelegatingDataStoreForStreamTests { WrappedStore = new InMemoryDataStore() }; _dataStoreUpdates = new DataStoreUpdatesImpl(BasicTaskExecutor, TestLogger); _dataStoreStatusProvider = new DataStoreStatusProviderImpl(_dataStore, _dataStoreUpdates); _dataSourceUpdates = new DataSourceUpdatesImpl( _dataStore, _dataStoreStatusProvider, BasicTaskExecutor, TestLogger, null ); _dataSourceStatusProvider = new DataSourceStatusProviderImpl(_dataSourceUpdates); _config = BasicConfig() .DataSource(Components.StreamingDataSource().EventSourceCreator(_eventSourceFactory.Create())) .DataStore(_dataStore.AsSingletonFactory()) .Build(); }
public DataSourceStatusProviderImplTest(ITestOutputHelper testOutput) : base(testOutput) { updates = TestUtils.BasicDataSourceUpdates(new InMemoryDataStore(), testLogger); statusProvider = new DataSourceStatusProviderImpl(updates); }
internal DataSourceStatusProviderImpl(DataSourceUpdatesImpl dataSourceUpdates) { _dataSourceUpdates = dataSourceUpdates; }