示例#1
0
        static void Main(string[] args)
        {
            var unleashConfig = new UnleashConfig.Builder()
                                .AppName("c-sharp-test")
                                .InstanceId("instance y")
                                .UnleashAPI("https://unleash.herokuapp.com/api/")
                                .FetchTogglesInterval(1)
                                .SendMetricsInterval(2)
                                .Build();

            var context = UnleashContext.CreateBuilder()
                          .SessionId(new Random().Next(10000) + "")
                          .UserId(new Random().Next(10000) + "")
                          .RemoteAddress("192.168.1.1")
                          .Build();

            // var executor = new UnleashScheduledExecutorImpl();
            // var repository = new FeatureToggleRepository(
            //         unleashConfig,
            //         executor,
            //         new HttpToggleFetcher(unleashConfig),
            //         new ToggleBackupHandlerFile(unleashConfig));
            var unleash = new DefaultUnleash(unleashConfig,
                                             //repository,
                                             new ActiveForUserWithIdStrategy()
                                             );


            //var test =  executor.SetInterval(s => repository.UpdateToggles(s).Wait(), 0, unleashConfig.FetchTogglesInterval);

            Run(unleash, context, "test", 200);
        }
示例#2
0
        public void feature_toggles_should_be_updated()
        {
            var toggleFetcher       = A.Fake <IToggleFetcher>();
            var toggleBackupHandler = A.Fake <IToggleBackupHandler>();

            var toggleCollection = PopulatedToggleCollection(
                new FeatureToggle("toggleFetcherCalled", false, new[] { new ActivationStrategy("custom", null) }));

            A.CallTo(() => toggleBackupHandler.Read()).Returns(toggleCollection);

            //setup fetcher
            toggleCollection = PopulatedToggleCollection(
                new FeatureToggle("toggleFetcherCalled", true, new[] { new ActivationStrategy("custom", null) }));
            var response = FeatureToggleResponse.Changed(toggleCollection);

            A.CallTo(() => toggleFetcher.FetchToggles()).Returns(response);

            //init
            var executor = A.Fake <IUnleashScheduledExecutor>();
            //ArgumentCaptor<Runnable> runnableArgumentCaptor = ArgumentCaptor.forClass(Runnable.class);
            var callback = new Capture <TimerCallback>();


            UnleashConfig config = new UnleashConfig.Builder()
                                   .AppName("test")
                                   .UnleashAPI("http://localhost:4242/api/")
                                   .FetchTogglesInterval(200L)
                                   .Build();

            //run the toggle fetcher callback
            A.CallTo(() => executor.SetInterval(callback, A <long> .Ignored, A <long> .Ignored)).Returns(new AutoResetEvent(false));

            var toggleRepository = new FeatureToggleRepository(config, executor, toggleFetcher, toggleBackupHandler);


            A.CallTo(() => toggleFetcher.FetchToggles()).MustNotHaveHappened();
            callback.Value(null);
            A.CallTo(() => toggleBackupHandler.Read()).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => toggleFetcher.FetchToggles()).MustHaveHappened(Repeated.Exactly.Once);
            Assert.True(toggleRepository.GetToggle("toggleFetcherCalled").IsEnabled);
        }