public void FlagsAreNotLoadedUntilStart()
 {
     factory.WithFilePaths(ALL_DATA_JSON_FILE);
     using (var fp = factory.CreateUpdateProcessor(config, store))
     {
         Assert.False(store.Initialized());
         Assert.Equal(0, CountFlagsInStore());
         Assert.Equal(0, CountSegmentsInStore());
     }
 }
Example #2
0
        /// <inheritdoc/>
        public FeatureFlagsState AllFlagsState(User user, params FlagsStateOption[] options)
        {
            if (IsOffline())
            {
                Log.Warn("AllFlagsState() was called when client is in offline mode. Returning empty state.");
                return(new FeatureFlagsState(false));
            }
            if (!Initialized())
            {
                if (_featureStore.Initialized())
                {
                    Log.Warn("AllFlagsState() called before client initialized; using last known values from feature store");
                }
                else
                {
                    Log.Warn("AllFlagsState() called before client initialized; feature store unavailable, returning empty state");
                    return(new FeatureFlagsState(false));
                }
            }
            if (user == null || user.Key == null)
            {
                Log.Warn("AllFlagsState() called with null user or null user key. Returning empty state");
                return(new FeatureFlagsState(false));
            }

            var state                = new FeatureFlagsState(true);
            var clientSideOnly       = FlagsStateOption.HasOption(options, FlagsStateOption.ClientSideOnly);
            var withReasons          = FlagsStateOption.HasOption(options, FlagsStateOption.WithReasons);
            var detailsOnlyIfTracked = FlagsStateOption.HasOption(options, FlagsStateOption.DetailsOnlyForTrackedFlags);
            IDictionary <string, FeatureFlag> flags = _featureStore.All(VersionedDataKind.Features);

            foreach (KeyValuePair <string, FeatureFlag> pair in flags)
            {
                var flag = pair.Value;
                if (clientSideOnly && !flag.ClientSide)
                {
                    continue;
                }
                try
                {
                    FeatureFlag.EvalResult result = flag.Evaluate(user, _featureStore, EventFactory.Default);
                    state.AddFlag(flag, result.Result.Value.InnerValue, result.Result.VariationIndex,
                                  withReasons ? result.Result.Reason : null, detailsOnlyIfTracked);
                }
                catch (Exception e)
                {
                    Log.ErrorFormat("Exception caught for feature flag \"{0}\" when evaluating all flags: {1}", flag.Key, Util.ExceptionMessage(e));
                    Log.Debug(e.ToString(), e);
                    EvaluationReason reason = new EvaluationReason.Error(EvaluationErrorKind.EXCEPTION);
                    state.AddFlag(flag, null, null, withReasons ? reason : null, detailsOnlyIfTracked);
                }
            }
            return(state);
        }
Example #3
0
 public void StoreInitializedAfterInit()
 {
     InitStore();
     Assert.True(store.Initialized());
 }
Example #4
0
 public bool Initialized()
 {
     return(_store.Initialized());
 }