public void TestEventProcessorWithBatchEventProcessorObj()
        {
            var eventDispatcher      = new DefaultEventDispatcher(LoggerMock.Object);
            var notificationCenter   = new NotificationCenter();
            var projectConfigManager = new HttpProjectConfigManager.Builder()
                                       .WithSdkKey("10192104166")
                                       .Build(true);

            var batchEventProcessor = new BatchEventProcessor.Builder()
                                      .WithLogger(LoggerMock.Object)
                                      .WithMaxBatchSize(20)
                                      .WithFlushInterval(TimeSpan.FromSeconds(3))
                                      .WithEventDispatcher(eventDispatcher)
                                      .WithNotificationCenter(notificationCenter)
                                      .Build();

            var optimizely = OptimizelyFactory.NewDefaultInstance(projectConfigManager, notificationCenter, eventProcessor: batchEventProcessor);

            var actualbatchEventProcessor   = Reflection.GetFieldValue <BatchEventProcessor, Optimizely>(optimizely, "EventProcessor");
            var actualEventProcessorProps   = new EventProcessorProps(actualbatchEventProcessor);
            var expectedEventProcessorProps = new EventProcessorProps(batchEventProcessor);

            Assert.AreEqual(actualEventProcessorProps, expectedEventProcessorProps);
            optimizely.Dispose();
        }
示例#2
0
        public void TestGetFeatureVariableJSONEmptyDatafileTest()
        {
            var httpClientMock = new Mock <HttpProjectConfigManager.HttpClient>();
            var task           = TestHttpProjectConfigManagerUtil.MockSendAsync(httpClientMock, TestData.EmptyDatafile, TimeSpan.Zero, System.Net.HttpStatusCode.OK);

            TestHttpProjectConfigManagerUtil.SetClientFieldValue(httpClientMock.Object);

            var optimizely = OptimizelyFactory.NewDefaultInstance("sdk-key");

            Assert.Null(optimizely.GetFeatureVariableJSON("no-feature-variable", "no-variable-key", "userId"));
            optimizely.Dispose();
        }
        public void TestEventProcessorWithDefaultEventBatching()
        {
            var optimizely = OptimizelyFactory.NewDefaultInstance();

            var batchEventProcessor         = Reflection.GetFieldValue <BatchEventProcessor, Optimizely>(optimizely, "EventProcessor");
            var actualEventProcessorProps   = new EventProcessorProps(batchEventProcessor);
            var expectedEventProcessorProps = new EventProcessorProps
            {
                BatchSize       = 10,
                FlushInterval   = TimeSpan.FromSeconds(2),
                TimeoutInterval = TimeSpan.FromSeconds(10)
            };

            Assert.AreEqual(actualEventProcessorProps, expectedEventProcessorProps);
            optimizely.Dispose();
        }
        public void TestEventProcessorWithEventBatchingBatchSizeAndInterval()
        {
            OptimizelyFactory.SetBatchSize(2);
            OptimizelyFactory.SetFlushInterval(TimeSpan.FromSeconds(4));

            var optimizely = OptimizelyFactory.NewDefaultInstance("sdk-Key");

            var batchEventProcessor         = Reflection.GetFieldValue <BatchEventProcessor, Optimizely>(optimizely, "EventProcessor");
            var actualEventProcessorProps   = new EventProcessorProps(batchEventProcessor);
            var expectedEventProcessorProps = new EventProcessorProps
            {
                BatchSize       = 2,
                FlushInterval   = TimeSpan.FromSeconds(4),
                TimeoutInterval = TimeSpan.FromMinutes(5)
            };

            Assert.AreEqual(actualEventProcessorProps, expectedEventProcessorProps);
            optimizely.Dispose();
        }
        public void TestProjectConfigManagerWithCustomProjectConfigManager()
        {
            var projectConfigManager = new HttpProjectConfigManager.Builder()
                                       .WithSdkKey("10192104166")
                                       .WithFormat("https://optimizely.com/json/{0}.json")
                                       .WithPollingInterval(TimeSpan.FromMilliseconds(3000))
                                       .WithBlockingTimeoutPeriod(TimeSpan.FromMilliseconds(4500))
                                       .WithStartByDefault()
                                       .WithAccessToken("access-token")
                                       .Build(true);

            var optimizely = OptimizelyFactory.NewDefaultInstance(projectConfigManager);
            var actualProjectConfigManager = optimizely.ProjectConfigManager as HttpProjectConfigManager;
            var actualConfigManagerProps   = new ProjectConfigManagerProps(actualProjectConfigManager);
            var expectedConfigManagerProps = new ProjectConfigManagerProps(projectConfigManager);

            Assert.AreEqual(actualConfigManagerProps, expectedConfigManagerProps);
            optimizely.Dispose();
        }
        public void TestProjectConfigManagerUsingSDKKey()
        {
            var optimizely = OptimizelyFactory.NewDefaultInstance("my-sdk-key");

            // Check values are loaded from app.config or not.
            var projectConfigManager = optimizely.ProjectConfigManager as HttpProjectConfigManager;

            Assert.NotNull(projectConfigManager);

            var actualConfigManagerProps   = new ProjectConfigManagerProps(projectConfigManager);
            var expectedConfigManagerProps = new ProjectConfigManagerProps
            {
                Url             = "https://cdn.optimizely.com/datafiles/my-sdk-key.json",
                LastModified    = "",
                AutoUpdate      = true,
                BlockingTimeout = TimeSpan.FromSeconds(15),
                PollingInterval = TimeSpan.FromMinutes(5)
            };

            Assert.AreEqual(actualConfigManagerProps, expectedConfigManagerProps);
            optimizely.Dispose();
        }
        public void TestOptimizelyInstanceUsingConfigFile()
        {
            var optimizely = OptimizelyFactory.NewDefaultInstance();
            // Check values are loaded from app.config or not.
            var projectConfigManager = optimizely.ProjectConfigManager as HttpProjectConfigManager;

            Assert.NotNull(projectConfigManager);

            var actualConfigManagerProps   = new ProjectConfigManagerProps(projectConfigManager);
            var expectedConfigManagerProps = new ProjectConfigManagerProps
            {
                Url                 = "www.testurl.com",
                LastModified        = "",
                AutoUpdate          = true,
                DatafileAccessToken = "testingtoken123",
                BlockingTimeout     = TimeSpan.FromSeconds(10),
                PollingInterval     = TimeSpan.FromSeconds(2)
            };

            Assert.AreEqual(actualConfigManagerProps, expectedConfigManagerProps);
            optimizely.Dispose();
        }
示例#8
0
        public void TestProjectConfigManagerWithDatafileAccessToken()
        {
            var optimizely = OptimizelyFactory.NewDefaultInstance("my-sdk-key", null, "access-token");

            // Check values are loaded from app.config or not.
            var projectConfigManager = optimizely.ProjectConfigManager as HttpProjectConfigManager;

            Assert.NotNull(projectConfigManager);

            var actualConfigManagerProps   = new ProjectConfigManagerProps(projectConfigManager);
            var expectedConfigManagerProps = new ProjectConfigManagerProps
            {
                Url                 = "https://config.optimizely.com/datafiles/auth/my-sdk-key.json",
                LastModified        = "",
                DatafileAccessToken = "access-token",
                AutoUpdate          = true,
                BlockingTimeout     = TimeSpan.FromSeconds(30),
                PollingInterval     = TimeSpan.FromMilliseconds(2023)
            };

            Assert.AreEqual(actualConfigManagerProps, expectedConfigManagerProps);

            optimizely.Dispose();
        }
        private static Optimizely GetInstance()
        {
            try
            {
                var errorLogger   = ServiceLocator.Current.GetInstance <OptimizelySDK.Logger.ILogger>();
                var projectConfig = ServiceLocator.Current.GetInstance <ExperimentationProjectConfigManager>();

                var eventConfigManager = new BatchEventProcessor.Builder()
                                         .WithMaxBatchSize(1)
                                         .WithFlushInterval(TimeSpan.FromSeconds(5))
                                         .WithLogger(errorLogger)
                                         .Build();

                var instance = OptimizelyFactory.NewDefaultInstance(projectConfig, eventProcessor: eventConfigManager);
                return(instance);
            }
            catch (Exception e)
            {
                ServiceLocator.Current.TryGetExistingInstance(out ILogger epiErrorLogger);
                epiErrorLogger?.Log(Level.Error, "Optimizely initialization error", e);
            }

            return(null);
        }