public void ClientFailsToStartInPollingModeWith401Error() { using (var pollServer = HttpServer.Start(Error401Response)) { var config = BasicConfig() .DataSource(Components.PollingDataSource()) .ServiceEndpoints(Components.ServiceEndpoints().Polling(pollServer.Uri)) .StartWaitTime(TimeSpan.FromSeconds(5)) .Build(); using (var client = new LdClient(config)) { Assert.False(client.Initialized); Assert.Equal(DataSourceState.Off, client.DataSourceStatusProvider.Status.State); var value = client.BoolVariation(AlwaysTrueFlag.Key, BasicUser, false); Assert.False(value); var request = pollServer.Recorder.RequireRequest(); Assert.Equal(BasicSdkKey, request.Headers.Get("Authorization")); Assert.NotEmpty(LogCapture.GetMessages().Where( m => m.Level == Logging.LogLevel.Error && m.Text.Contains("error 401") && m.Text.Contains("giving up permanently"))); } } }
public void ClientRetriesConnectionInPollingModeWithNonFatalError() { var failThenSucceedHandler = Handlers.Sequential(Error503Response, ValidPollingResponse); using (var pollServer = HttpServer.Start(failThenSucceedHandler)) { var config = BasicConfig() .DataSource(Components.PollingDataSource() .PollIntervalNoMinimum(TimeSpan.FromMilliseconds(50))) .ServiceEndpoints(Components.ServiceEndpoints().Polling(pollServer.Uri)) .StartWaitTime(TimeSpan.FromSeconds(5)) .Build(); using (var client = new LdClient(config)) { Assert.True(client.Initialized); Assert.Equal(DataSourceState.Valid, client.DataSourceStatusProvider.Status.State); var value = client.BoolVariation(AlwaysTrueFlag.Key, BasicUser, false); Assert.True(value); var request1 = pollServer.Recorder.RequireRequest(); var request2 = pollServer.Recorder.RequireRequest(); Assert.Equal(BasicSdkKey, request1.Headers.Get("Authorization")); Assert.Equal(BasicSdkKey, request2.Headers.Get("Authorization")); Assert.NotEmpty(LogCapture.GetMessages().Where( m => m.Level == Logging.LogLevel.Warn && m.Text.Contains("error 503") && m.Text.Contains("will retry"))); Assert.Empty(LogCapture.GetMessages().Where(m => m.Level == Logging.LogLevel.Error)); } } }
public void DefaultPollingDataSourceBaseUri() { using (var client = new LdClient( BasicConfig() .DataSource(Components.PollingDataSource()) .Http(Components.HttpConfiguration().MessageHandler(_stubHandler)) .Build())) { var req = _stubHandler.Requests.ExpectValue(); Assert.Equal(StandardEndpoints.DefaultPollingBaseUri, BaseUriOf(req.RequestUri)); } }
public void PollingClientHasPollingProcessor() { var config = BasicConfig() .DataSource(Components.PollingDataSource()) .ServiceEndpoints(FakeEndpoints) .Build(); using (var client = new LdClient(config)) { Assert.IsType <PollingProcessor>(client._dataSource); } }
public void PollingClientHasPollingProcessor() { var config = Configuration.Builder(sdkKey) .DataSource(Components.PollingDataSource().BaseUri(new Uri("http://fake"))) .Events(Components.NoEvents) .StartWaitTime(TimeSpan.Zero) .Logging(Components.Logging(testLogging)) .Build(); using (var client = new LdClient(config)) { Assert.IsType <PollingProcessor>(client._dataSource); } }
public void PollingClientStartupMessage() { var config = BasicConfig() .DataSource(Components.PollingDataSource()) .ServiceEndpoints(FakeEndpoints) .Build(); using (var client = new LdClient(config)) { AssertLogMessageRegex(true, LogLevel.Warn, "You should only disable the streaming API if instructed to do so by LaunchDarkly support"); AssertLogMessageRegex(true, LogLevel.Info, "^Starting LaunchDarkly polling"); } }
public void CustomPollingDataSourceBaseUriWithDeprecatedMethod() { using (var client = new LdClient( BasicConfig() .DataSource(Components.PollingDataSource().BaseUri(CustomUri)) .Http(Components.HttpConfiguration().MessageHandler(_stubHandler)) .Build())) { var req = _stubHandler.Requests.ExpectValue(); Assert.Equal(CustomUri, BaseUriOf(req.RequestUri)); AssertLogMessageRegex(false, LogLevel.Error, "You have set custom ServiceEndpoints without specifying"); } }
public void ErrorIsLoggedIfANecessaryUriIsNotSetWhenOtherCustomUrisAreSet() { var logCapture1 = Logs.Capture(); using (var client = new LdClient( BasicConfig() .DataSource(Components.StreamingDataSource()) .Http(Components.HttpConfiguration().MessageHandler(_stubHandler)) .Logging(logCapture1) .ServiceEndpoints(Components.ServiceEndpoints().Polling(CustomUri)) .Build())) { Assert.True(logCapture1.HasMessageWithRegex(LogLevel.Error, "You have set custom ServiceEndpoints without specifying the Streaming base URI")); } var logCapture2 = Logs.Capture(); using (var client = new LdClient( BasicConfig() .DataSource(Components.PollingDataSource()) .Http(Components.HttpConfiguration().MessageHandler(_stubHandler)) .Logging(logCapture2) .ServiceEndpoints(Components.ServiceEndpoints().Events(CustomUri)) .Build())) { Assert.True(logCapture2.HasMessageWithRegex(LogLevel.Error, "You have set custom ServiceEndpoints without specifying the Polling base URI")); } var logCapture3 = Logs.Capture(); using (var client = new LdClient( BasicConfig() .Events(Components.SendEvents()) .Http(Components.HttpConfiguration().MessageHandler(_stubHandler)) .Logging(logCapture3) .ServiceEndpoints(Components.ServiceEndpoints().Streaming(CustomUri)) .Build())) { Assert.True(logCapture3.HasMessageWithRegex(LogLevel.Error, "You have set custom ServiceEndpoints without specifying the Events base URI")); } }
public void PollingClientStartupMessage() { var config = Configuration.Builder(sdkKey) .Logging(Components.Logging(testLogging)) .Events(Components.NoEvents) .DataSource(Components.PollingDataSource().BaseUri(new Uri("http://fake"))) .StartWaitTime(TimeSpan.Zero) .Build(); using (var client = new LdClient(config)) { Assert.True(logCapture.HasMessageWithText(LogLevel.Warn, "You should only disable the streaming API if instructed to do so by LaunchDarkly support"), logCapture.ToString()); Assert.True(logCapture.HasMessageWithRegex(LogLevel.Info, "^Starting LaunchDarkly polling"), logCapture.ToString()); } }
public void HttpConfigurationIsAppliedToPolling() { TestHttpUtils.TestWithSpecialHttpConfigurations( ValidPollingResponse, (targetUri, httpConfig, server) => { var config = BasicConfig() .DataSource(Components.PollingDataSource()) .Http(httpConfig) .ServiceEndpoints(Components.ServiceEndpoints().Polling(targetUri)) .StartWaitTime(TimeSpan.FromSeconds(5)) .Build(); using (var client = new LdClient(config)) { VerifyClientStartedAndHasExpectedData(client, server); } }, TestLogger ); }
public void ClientStartsInPollingMode() { using (var pollServer = HttpServer.Start(ValidPollingResponse)) { var config = BasicConfig() .DataSource(Components.PollingDataSource()) .ServiceEndpoints(Components.ServiceEndpoints().Polling(pollServer.Uri)) .StartWaitTime(TimeSpan.FromSeconds(5)) .Build(); using (var client = new LdClient(config)) { VerifyClientStartedAndHasExpectedData(client, pollServer); Assert.NotEmpty(LogCapture.GetMessages().Where( m => m.Level == Logging.LogLevel.Warn && m.Text.Contains("You should only disable the streaming API if instructed to do so"))); Assert.Empty(LogCapture.GetMessages().Where(m => m.Level == Logging.LogLevel.Error)); } } }
public void CustomConfigForPolling() { TestDiagnosticConfig( c => c.DataSource(Components.PollingDataSource()) .Http(Components.HttpConfiguration().MessageHandler(StubMessageHandler.EmptyPollingResponse())), null, ExpectedConfigProps.Base() .WithPollingDefaults() ); TestDiagnosticConfig( c => c.DataSource( Components.PollingDataSource() .PollInterval(TimeSpan.FromSeconds(45)) ) .Http(Components.HttpConfiguration().MessageHandler(StubMessageHandler.EmptyPollingResponse())), null, ExpectedConfigProps.Base() .WithPollingDefaults() .Set("pollingIntervalMillis", 45000) ); }
public void CustomConfigForPolling() { TestDiagnosticConfig( c => c.DataSource( Components.PollingDataSource() .PollInterval(TimeSpan.FromSeconds(45)) ) .Http(Components.HttpConfiguration().MessageHandler(StubMessageHandler.EmptyPollingResponse())), null, ExpectedConfigProps.Base() .WithStoreDefaults() .WithEventsDefaults() .Add("customBaseURI", false) .Add("customStreamURI", false) .Add("pollingIntervalMillis", 45000) .Add("streamingDisabled", true) .Add("usingRelayDaemon", false) ); TestDiagnosticConfig( c => c.DataSource( Components.PollingDataSource() .BaseUri(new Uri("http://custom")) .PollInterval(TimeSpan.FromSeconds(45)) ) .Http(Components.HttpConfiguration().MessageHandler(StubMessageHandler.EmptyPollingResponse())), null, ExpectedConfigProps.Base() .WithStoreDefaults() .WithEventsDefaults() .Add("customBaseURI", true) .Add("customStreamURI", false) .Add("pollingIntervalMillis", 45000) .Add("streamingDisabled", true) .Add("usingRelayDaemon", false) ); }
public void TestConfigForServiceEndpoints() { TestDiagnosticConfig( c => c.ServiceEndpoints(Components.ServiceEndpoints().RelayProxy("http://custom")) .Http(Components.HttpConfiguration().MessageHandler(StubMessageHandler.EmptyStreamingResponse())), null, ExpectedConfigProps.Base() .Set("customBaseURI", false) // this is the polling base URI, not relevant in streaming mode .Set("customStreamURI", true) .Set("customEventsURI", true) ); TestDiagnosticConfig( c => c.ServiceEndpoints(Components.ServiceEndpoints().RelayProxy("http://custom")) .DataSource(Components.PollingDataSource()) .Http(Components.HttpConfiguration().MessageHandler(StubMessageHandler.EmptyPollingResponse())), null, ExpectedConfigProps.Base() .WithPollingDefaults() .Set("customBaseURI", true) .Set("customEventsURI", true) ); TestDiagnosticConfig( c => c.ServiceEndpoints(Components.ServiceEndpoints() .Streaming("http://custom-streaming") .Polling("http://custom-polling") .Events("http://custom-events")) .Http(Components.HttpConfiguration().MessageHandler(StubMessageHandler.EmptyStreamingResponse())), null, ExpectedConfigProps.Base() .Set("customBaseURI", false) // this is the polling base URI, not relevant in streaming mode .Set("customStreamURI", true) .Set("customEventsURI", true) ); TestDiagnosticConfig( c => c.DataSource( #pragma warning disable CS0618 // using deprecated symbol Components.StreamingDataSource() .BaseUri(new Uri("http://custom")) #pragma warning restore CS0618 ) .Http(Components.HttpConfiguration().MessageHandler(StubMessageHandler.EmptyStreamingResponse())), null, ExpectedConfigProps.Base() .Set("customStreamURI", true) ); TestDiagnosticConfig( c => c.DataSource( #pragma warning disable CS0618 // using deprecated symbol Components.PollingDataSource().BaseUri(new Uri("http://custom")) #pragma warning restore CS0618 ) .Http(Components.HttpConfiguration().MessageHandler(StubMessageHandler.EmptyPollingResponse())), null, ExpectedConfigProps.Base() .WithPollingDefaults() .Set("customBaseURI", true) ); }