public void Logging() { var prop = _tester.Property(c => c.LoggingConfigurationFactory, (b, v) => b.Logging(v)); prop.AssertDefault(null); prop.AssertCanSet(Components.Logging(Logs.ToWriter(Console.Out))); }
public void DataSourceStatusProviderReturnsLatestStatus() { var testData = TestData.DataSource(); var config = Configuration.Builder("") .DataSource(testData) .Events(Components.NoEvents) .Logging(Components.Logging(testLogging)) .Build(); var timeBeforeStarting = DateTime.Now; using (var client = new LdClient(config)) { var initialStatus = client.DataSourceStatusProvider.Status; Assert.Equal(DataSourceState.Valid, initialStatus.State); Assert.InRange(initialStatus.StateSince, timeBeforeStarting, timeBeforeStarting.AddSeconds(1)); Assert.Null(initialStatus.LastError); var errorInfo = DataSourceStatus.ErrorInfo.FromHttpError(401); testData.UpdateStatus(DataSourceState.Off, errorInfo); var newStatus = client.DataSourceStatusProvider.Status; Assert.Equal(DataSourceState.Off, newStatus.State); Assert.InRange(newStatus.StateSince, errorInfo.Time, errorInfo.Time.AddSeconds(1)); Assert.Equal(errorInfo, newStatus.LastError); } }
public void DataSetIsPassedToDataStoreInCorrectOrder() { // The underlying functionality here is also covered in DataStoreSorterTest, but we want to verify that the // client object is actually *using* DataStoreSorter. var mockStore = new Mock <IDataStore>(); var store = mockStore.Object; FullDataSet <ItemDescriptor> receivedData = new FullDataSet <ItemDescriptor>(); mockStore.Setup(s => s.Init(It.IsAny <FullDataSet <ItemDescriptor> >())) .Callback((FullDataSet <ItemDescriptor> data) => { receivedData = data; }); mockDataSource.Setup(up => up.Start()).Returns(initTask); var config = Configuration.Builder(sdkKey) .DataStore(TestUtils.SpecificDataStore(store)) .DataSource(TestUtils.DataSourceWithData(DataStoreSorterTest.DependencyOrderingTestData)) .Events(Components.NoEvents) .Logging(Components.Logging(testLogging)) .Build(); using (var client = new LdClient(config)) { Assert.NotNull(receivedData); DataStoreSorterTest.VerifyDataSetOrder(receivedData, DataStoreSorterTest.DependencyOrderingTestData, DataStoreSorterTest.ExpectedOrderingForSortedDataSet); } }
public void DiagnosticInitEventIsSent() { var config = Configuration.Builder(sdkKey) .DataSource(Components.ExternalUpdatesOnly) .Events(Components.SendEvents().EventSender(testEventSender)) .Http( Components.HttpConfiguration().Wrapper(testWrapperName, testWrapperVersion) ) .Logging(Components.Logging(testLogging)) .Build(); using (var client = new LdClient(config)) { var payload = testEventSender.RequirePayload(); Assert.Equal(EventDataKind.DiagnosticEvent, payload.Kind); Assert.Equal(1, payload.EventCount); var data = LdValue.Parse(payload.Data); Assert.Equal("diagnostic-init", data.Get("kind").AsString); AssertHelpers.JsonEqual(ExpectedPlatform(), data.Get("platform")); AssertHelpers.JsonEqual(expectedSdk, data.Get("sdk")); Assert.Equal("DK_KEY", data.Get("id").Get("sdkKeySuffix").AsString); var timestamp = data.Get("creationDate").AsLong; Assert.NotEqual(0, timestamp); } }
private void TestDiagnosticConfig( Func <ConfigurationBuilder, ConfigurationBuilder> modConfig, Func <EventProcessorBuilder, EventProcessorBuilder> modEvents, LdValue.ObjectBuilder expected ) { var eventsBuilder = Components.SendEvents() .EventSender(testEventSender); modEvents?.Invoke(eventsBuilder); var configBuilder = Configuration.Builder(sdkKey) .Events(eventsBuilder) .Http(Components.HttpConfiguration().MessageHandler(new StubMessageHandler(HttpStatusCode.Unauthorized))) .Logging(Components.Logging(testLogging)) .StartWaitTime(testStartWaitTime); modConfig?.Invoke(configBuilder); using (var client = new LdClient(configBuilder.Build())) { var payload = testEventSender.RequirePayload(); Assert.Equal(EventDataKind.DiagnosticEvent, payload.Kind); Assert.Equal(1, payload.EventCount); var data = LdValue.Parse(payload.Data); Assert.Equal("diagnostic-init", data.Get("kind").AsString); AssertHelpers.JsonEqual(expected.Build(), data.Get("configuration")); } }
public void DiagnosticStoreNotPassedToFactoriesWhenOptedOut() { var epf = new Mock <IEventProcessorFactory>(); var dsf = new Mock <IDataSourceFactory>(); var config = Configuration.Builder(sdkKey) .DataSource(Components.ExternalUpdatesOnly) .StartWaitTime(TimeSpan.Zero) .Events(epf.Object) .DataSource(dsf.Object) .DiagnosticOptOut(true) .Logging(Components.Logging(testLogging)) .Build(); IDiagnosticStore eventProcessorDiagnosticStore = null; IDiagnosticStore dataSourceDiagnosticStore = null; epf.Setup(f => f.CreateEventProcessor(It.IsAny <LdClientContext>())) .Callback((LdClientContext ctx) => eventProcessorDiagnosticStore = ctx.DiagnosticStore) .Returns(new ComponentsImpl.NullEventProcessor()); dsf.Setup(f => f.CreateDataSource(It.IsAny <LdClientContext>(), It.IsAny <IDataSourceUpdates>())) .Callback((LdClientContext ctx, IDataSourceUpdates dsu) => dataSourceDiagnosticStore = ctx.DiagnosticStore) .Returns((LdClientContext ctx, IDataSourceUpdates dsu) => dataSource); using (var client = new LdClient(config)) { epf.Verify(f => f.CreateEventProcessor(It.IsNotNull <LdClientContext>()), Times.Once()); epf.VerifyNoOtherCalls(); dsf.Verify(f => f.CreateDataSource(It.IsNotNull <LdClientContext>(), It.IsNotNull <IDataSourceUpdates>()), Times.Once()); dsf.VerifyNoOtherCalls(); Assert.Null(eventProcessorDiagnosticStore); Assert.Null(dataSourceDiagnosticStore); } }
public LdClientEvaluationTest(ITestOutputHelper testOutput) : base(testOutput) { var config = Configuration.Builder("SDK_KEY") .DataSource(testData) .Events(Components.NoEvents) .Logging(Components.Logging(testLogging)) .Build(); client = new LdClient(config); }
public void OfflineReturnsDefaultValue() { var config = Configuration.Builder(sdkKey).Offline(true) .Logging(Components.Logging(testLogging)).Build(); using (var client = new LdClient(config)) { Assert.Equal("x", client.StringVariation("key", User.WithKey("user"), "x")); } }
public void OfflineClientIsInitialized() { var config = Configuration.Builder(sdkKey).Offline(true) .Logging(Components.Logging(testLogging)).Build(); using (var client = new LdClient(config)) { Assert.True(client.Initialized); } }
public void OfflineClientHasNullEventProcessor() { var config = Configuration.Builder(sdkKey).Offline(true) .Logging(Components.Logging(testLogging)).Build(); using (var client = new LdClient(config)) { Assert.IsType <ComponentsImpl.NullEventProcessor>(client._eventProcessor); } }
public void OfflineClientHasNullDataSource() { var config = Configuration.Builder(sdkKey).Offline(true) .Logging(Components.Logging(testLogging)).Build(); using (var client = new LdClient(config)) { Assert.IsType <ComponentsImpl.NullDataSource>(client._dataSource); } }
public LdClientEventTest(ITestOutputHelper testOutput) : base(testOutput) { var config = Configuration.Builder("SDK_KEY") .DataSource(testData) .Events(TestUtils.SpecificEventProcessor(eventSink)) .Logging(Components.Logging(testLogging)) .Build(); client = new LdClient(config); }
public void OfflineClientStartupMessage() { var config = Configuration.Builder(sdkKey).Offline(true) .Logging(Components.Logging(testLogging)).Build(); using (var client = new LdClient(config)) { Assert.True(logCapture.HasMessageWithText(LogLevel.Info, "Starting LaunchDarkly client in offline mode"), logCapture.ToString()); } }
public void TestSecureModeHash() { var config = Configuration.Builder("secret").Offline(true) .Logging(Components.Logging(testLogging)).Build(); using (var client = new LdClient(config)) { Assert.Equal("aa747c502a898200f9e4fa21bac68136f886a0e27aec70ba06daf2e2a5cb5597", client.SecureModeHash(User.WithKey("Message"))); } }
public void LddModeClientIsInitialized() { var config = Configuration.Builder(sdkKey) .DataSource(Components.ExternalUpdatesOnly) .Logging(Components.Logging(testLogging)) .Build(); using (var client = new LdClient(config)) { Assert.True(client.Initialized); } }
public void CanCustomizeBaseLoggerName() { var customLoggerName = "abcdef"; var config = BasicConfig() .Logging(Components.Logging(TestLogging).BaseLoggerName(customLoggerName)) .Build(); using (var client = new LdClient(config)) { Assert.All(LogCapture.GetMessages(), m => m.LoggerName.StartsWith(customLoggerName)); } }
public void LddModeClientHasNullDataSource() { var config = Configuration.Builder(sdkKey) .DataSource(Components.ExternalUpdatesOnly) .Logging(Components.Logging(testLogging)) .Build(); using (var client = new LdClient(config)) { Assert.IsType <ComponentsImpl.NullDataSource>(client._dataSource); } }
public void LddModeClientHasDefaultEventProcessor() { var config = Configuration.Builder(sdkKey) .DataSource(Components.ExternalUpdatesOnly) .Logging(Components.Logging(testLogging)) .Build(); using (var client = new LdClient(config)) { Assert.IsType <DefaultEventProcessorWrapper> (client._eventProcessor); } }
public void DataSourceCanTimeOut() { var config = Configuration.Builder(sdkKey).StartWaitTime(TimeSpan.FromMilliseconds(10)) .DataSource(TestUtils.SpecificDataSource(dataSource)) .Events(Components.NoEvents) .Logging(Components.Logging(testLogging)) .Build(); using (var client = new LdClient(config)) { Assert.False(client.Initialized); } }
public void NoWaitForDataSourceIfWaitMillisIsZero() { mockDataSource.Setup(up => up.Initialized).Returns(true); var config = Configuration.Builder(sdkKey).StartWaitTime(TimeSpan.Zero) .DataSource(TestUtils.SpecificDataSource(dataSource)) .Events(Components.NoEvents) .Logging(Components.Logging(testLogging)) .Build(); using (var client = new LdClient(config)) { Assert.True(client.Initialized); } }
public void StreamingClientHasStreamProcessor() { var config = Configuration.Builder(sdkKey) .DataSource(Components.StreamingDataSource().BaseUri(new Uri("http://fake"))) .Events(Components.NoEvents) .StartWaitTime(TimeSpan.Zero) .Logging(Components.Logging(testLogging)) .Build(); using (var client = new LdClient(config)) { Assert.IsType <StreamProcessor>(client._dataSource); } }
public void ClientHasDefaultEventProcessorByDefault() { var config = Configuration.Builder(sdkKey) .DataSource(Components.ExternalUpdatesOnly) .StartWaitTime(TimeSpan.Zero) .DiagnosticOptOut(true) .Logging(Components.Logging(testLogging)) .Build(); using (var client = new LdClient(config)) { Assert.IsType <DefaultEventProcessorWrapper>(client._eventProcessor); } }
public void NoDiagnosticInitEventIsSentIfOptedOut() { var config = Configuration.Builder(sdkKey) .DiagnosticOptOut(true) .DataSource(Components.ExternalUpdatesOnly) .Events(Components.SendEvents().EventSender(testEventSender)) .Logging(Components.Logging(testLogging)) .Build(); using (var client = new LdClient(config)) { testEventSender.RequireNoPayloadSent(TimeSpan.FromMilliseconds(100)); } }
public void CanCustomizeBaseLoggerName() { var customLoggerName = "abcdef"; var config = Configuration.Builder(sdkKey) .Logging(Components.Logging(testLogging).BaseLoggerName(customLoggerName)) .Events(Components.NoEvents) .StartWaitTime(TimeSpan.Zero) .Build(); using (var client = new LdClient(config)) { Assert.All(logCapture.GetMessages(), m => m.LoggerName.StartsWith(customLoggerName)); } }
public void ClientStartupMessage() { var config = Configuration.Builder(sdkKey) .Logging(Components.Logging(testLogging)) .Events(Components.NoEvents) .StartWaitTime(TimeSpan.Zero) .Build(); using (var client = new LdClient(config)) { Assert.True(logCapture.HasMessageWithText(LogLevel.Info, "Starting LaunchDarkly client " + AssemblyVersions.GetAssemblyVersionStringForType(typeof(LdClient))), logCapture.ToString()); Assert.All(logCapture.GetMessages(), m => m.LoggerName.StartsWith(LogNames.DefaultBase)); } }
public void StreamingClientStartupMessage() { var config = Configuration.Builder(sdkKey) .Logging(Components.Logging(testLogging)) .DataSource(Components.StreamingDataSource().BaseUri(new Uri("http://fake"))) .Events(Components.NoEvents) .StartWaitTime(TimeSpan.Zero) .Build(); using (var client = new LdClient(config)) { Assert.False(logCapture.HasMessageWithText(LogLevel.Warn, "You should only disable the streaming API if instructed to do so by LaunchDarkly support"), logCapture.ToString()); } }
public void LddModeClientGetsFlagFromDataStore() { var dataStore = new InMemoryDataStore(); TestUtils.UpsertFlag(dataStore, new FeatureFlagBuilder("key").OffWithValue(LdValue.Of(true)).Build()); var config = Configuration.Builder(sdkKey) .DataSource(Components.ExternalUpdatesOnly) .DataStore(TestUtils.SpecificDataStore(dataStore)) .Logging(Components.Logging(testLogging)) .Build(); using (var client = new LdClient(config)) { Assert.True(client.BoolVariation("key", User.WithKey("user"), false)); } }
public void ExceptionFromDataSourceTaskDoesNotCauseExceptionInInit() { TaskCompletionSource <bool> errorTaskSource = new TaskCompletionSource <bool>(); mockDataSource.Setup(up => up.Start()).Returns(errorTaskSource.Task); errorTaskSource.SetException(new Exception("bad")); var config = Configuration.Builder(sdkKey) .DataSource(TestUtils.SpecificDataSource(dataSource)) .Events(Components.NoEvents) .Logging(Components.Logging(testLogging)) .Build(); using (var client = new LdClient(config)) { Assert.False(client.Initialized); } }
public void EvaluationReturnsDefaultValueIfNeitherClientNorDataStoreIsInited() { var dataStore = new InMemoryDataStore(); var flag = new FeatureFlagBuilder("key").OffWithValue(LdValue.Of(1)).Build(); TestUtils.UpsertFlag(dataStore, flag); // note, the store is still not inited var config = Configuration.Builder(sdkKey).StartWaitTime(TimeSpan.Zero) .DataStore(TestUtils.SpecificDataStore(dataStore)) .DataSource(TestUtils.SpecificDataSource(dataSource)) .Events(Components.NoEvents) .Logging(Components.Logging(testLogging)) .Build(); using (var client = new LdClient(config)) { Assert.Equal(0, client.IntVariation("key", User.WithKey("user"), 0)); } }
public void EvaluationUsesDataStoreIfClientIsNotInitedButStoreIsInited() { var dataStore = new InMemoryDataStore(); dataStore.Init(FullDataSet <ItemDescriptor> .Empty()); var flag = new FeatureFlagBuilder("key").OffWithValue(LdValue.Of(1)).Build(); TestUtils.UpsertFlag(dataStore, flag); var config = Configuration.Builder(sdkKey).StartWaitTime(TimeSpan.Zero) .DataStore(TestUtils.SpecificDataStore(dataStore)) .DataSource(TestUtils.SpecificDataSource(dataSource)) .Events(Components.NoEvents) .Logging(Components.Logging(testLogging)) .Build(); using (var client = new LdClient(config)) { Assert.Equal(1, client.IntVariation("key", User.WithKey("user"), 0)); } }