diff --git a/client/src/main/java/io/split/client/SplitClientImpl.java b/client/src/main/java/io/split/client/SplitClientImpl.java index 58938b247..a8968bb14 100644 --- a/client/src/main/java/io/split/client/SplitClientImpl.java +++ b/client/src/main/java/io/split/client/SplitClientImpl.java @@ -6,6 +6,8 @@ import io.split.client.events.EventsStorageProducer; import io.split.client.impressions.Impression; import io.split.client.impressions.ImpressionsManager; +import io.split.client.interceptors.FlagSetsFilter; +import io.split.client.interceptors.FlagSetsFilterImpl; import io.split.engine.SDKReadinessGates; import io.split.engine.evaluator.Evaluator; import io.split.engine.evaluator.EvaluatorImp; @@ -332,13 +334,16 @@ private Map getTreatmentsWithConfigInternal(String matching _log.warn("The sets are not in flagSetsFilter config"); return new HashMap<>(); } - featureFlagNames = getAllFlags(cleanFlagSets); + featureFlagNames = new ArrayList<>(); } else if (featureFlagNames == null) { _log.error(String.format("%s: featureFlagNames must be a non-empty array", methodEnum.getMethod())); return new HashMap<>(); } try { checkSDKReady(methodEnum, featureFlagNames); + if (cleanFlagSets != null) { + featureFlagNames = getAllFlags(cleanFlagSets); + } if (_container.isDestroyed()) { _log.error("Client has already been destroyed - no calls possible"); return createMapControl(featureFlagNames); @@ -354,7 +359,7 @@ private Map getTreatmentsWithConfigInternal(String matching } Map evaluatorResult; if (cleanFlagSets != null) { - evaluatorResult = _evaluator.evaluateFeaturesByFlagSets(matchingKey, bucketingKey, new ArrayList<>(cleanFlagSets)); + evaluatorResult = _evaluator.evaluateFeaturesByFlagSets(matchingKey, bucketingKey, new ArrayList<>(cleanFlagSets), attributes); } else { featureFlagNames = SplitNameValidator.areValid(featureFlagNames, methodEnum.getMethod()); evaluatorResult = _evaluator.evaluateFeatures(matchingKey, bucketingKey, featureFlagNames, attributes); @@ -391,10 +396,10 @@ private Map getTreatmentsWithConfigInternal(String matching } private List filterSetsAreInConfig(Set sets) { - HashSet configSets = _config.getSetsFilter(); + FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(_config.getSetsFilter()); List setsToReturn = new ArrayList<>(); for (String set : sets) { - if (!configSets.contains(set)) { + if (!flagSetsFilter.Intersect(set)) { _log.warn(String.format("GetTreatmentsByFlagSets: you passed %s which is not part of the configured FlagSetsFilter, " + "ignoring Flag Set.", set)); continue; diff --git a/client/src/main/java/io/split/client/SplitFactoryImpl.java b/client/src/main/java/io/split/client/SplitFactoryImpl.java index c5d031b44..ffc513c12 100644 --- a/client/src/main/java/io/split/client/SplitFactoryImpl.java +++ b/client/src/main/java/io/split/client/SplitFactoryImpl.java @@ -28,6 +28,7 @@ import io.split.client.impressions.strategy.ProcessImpressionStrategy; import io.split.client.interceptors.AuthorizationInterceptorFilter; import io.split.client.interceptors.ClientKeyInterceptorFilter; +import io.split.client.interceptors.FlagSetsFilter; import io.split.client.interceptors.FlagSetsFilterImpl; import io.split.client.interceptors.GzipDecoderResponseInterceptor; import io.split.client.interceptors.GzipEncoderRequestInterceptor; @@ -110,7 +111,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.stream.Collectors; @@ -190,7 +190,8 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn // Cache Initialisations SegmentCache segmentCache = new SegmentCacheInMemoryImpl(); - SplitCache splitCache = new InMemoryCacheImp(config.getSetsFilter()); + FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(config.getSetsFilter()); + SplitCache splitCache = new InMemoryCacheImp(flagSetsFilter); ImpressionsStorage impressionsStorage = new InMemoryImpressionsStorage(config.impressionsQueueSize()); _splitCache = splitCache; _segmentCache = segmentCache; @@ -202,7 +203,7 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn SplitParser splitParser = new SplitParser(); // SplitFetcher - _splitFetcher = buildSplitFetcher(splitCache, splitParser, config.getSetsFilter()); + _splitFetcher = buildSplitFetcher(splitCache, splitParser, flagSetsFilter); // SplitSynchronizationTask _splitSynchronizationTask = new SplitSynchronizationTask(_splitFetcher, @@ -355,7 +356,8 @@ protected SplitFactoryImpl(SplitClientConfig config) { _telemetryStorageProducer = new NoopTelemetryStorage(); SegmentCache segmentCache = new SegmentCacheInMemoryImpl(); - SplitCache splitCache = new InMemoryCacheImp(config.getSetsFilter()); + FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(config.getSetsFilter()); + SplitCache splitCache = new InMemoryCacheImp(flagSetsFilter); _splitCache = splitCache; _gates = new SDKReadinessGates(); _segmentCache = segmentCache; @@ -379,7 +381,7 @@ protected SplitFactoryImpl(SplitClientConfig config) { SplitChangeFetcher splitChangeFetcher = createSplitChangeFetcher(config); SplitParser splitParser = new SplitParser(); - _splitFetcher = new SplitFetcherImp(splitChangeFetcher, splitParser, splitCache, _telemetryStorageProducer, config.getSetsFilter()); + _splitFetcher = new SplitFetcherImp(splitChangeFetcher, splitParser, splitCache, _telemetryStorageProducer, flagSetsFilter); // SplitSynchronizationTask _splitSynchronizationTask = new SplitSynchronizationTask(_splitFetcher, splitCache, config.featuresRefreshRate(), config.getThreadFactory()); @@ -561,11 +563,10 @@ private SegmentSynchronizationTaskImp buildSegments(SplitClientConfig config, Se config.getThreadFactory()); } - private SplitFetcher buildSplitFetcher(SplitCacheProducer splitCacheProducer, SplitParser splitParser, HashSet flagSets) throws + private SplitFetcher buildSplitFetcher(SplitCacheProducer splitCacheProducer, SplitParser splitParser, FlagSetsFilter flagSetsFilter) throws URISyntaxException { SplitChangeFetcher splitChangeFetcher = HttpSplitChangeFetcher.create(_httpclient, _rootTarget, _telemetryStorageProducer); - - return new SplitFetcherImp(splitChangeFetcher, splitParser, splitCacheProducer, _telemetryStorageProducer,flagSets); + return new SplitFetcherImp(splitChangeFetcher, splitParser, splitCacheProducer, _telemetryStorageProducer,flagSetsFilter); } private ImpressionsManagerImpl buildImpressionsManager(SplitClientConfig config, ImpressionsStorageConsumer impressionsStorageConsumer, diff --git a/client/src/main/java/io/split/client/utils/FeatureFlagProcessor.java b/client/src/main/java/io/split/client/utils/FeatureFlagProcessor.java index f17d328e9..497f37140 100644 --- a/client/src/main/java/io/split/client/utils/FeatureFlagProcessor.java +++ b/client/src/main/java/io/split/client/utils/FeatureFlagProcessor.java @@ -17,11 +17,10 @@ public class FeatureFlagProcessor { private static final Logger _log = LoggerFactory.getLogger(FeatureFlagProcessor.class); - public static FeatureFlagsToUpdate processFeatureFlagChanges(SplitParser splitParser, List splits, HashSet configSets) { + public static FeatureFlagsToUpdate processFeatureFlagChanges(SplitParser splitParser, List splits, FlagSetsFilter flagSetsFilter) { List toAdd = new ArrayList<>(); List toRemove = new ArrayList<>(); Set segments = new HashSet<>(); - FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(configSets); for (Split split : splits) { if (split.status != Status.ACTIVE) { // archive. diff --git a/client/src/main/java/io/split/engine/common/PushManagerImp.java b/client/src/main/java/io/split/engine/common/PushManagerImp.java index 86a32e9ea..ff3343ed4 100644 --- a/client/src/main/java/io/split/engine/common/PushManagerImp.java +++ b/client/src/main/java/io/split/engine/common/PushManagerImp.java @@ -1,6 +1,7 @@ package io.split.engine.common; import com.google.common.annotations.VisibleForTesting; +import io.split.client.interceptors.FlagSetsFilter; import io.split.engine.experiments.SplitParser; import io.split.engine.sse.AuthApiClient; import io.split.engine.sse.AuthApiClientImp; @@ -23,7 +24,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.HashSet; import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ScheduledExecutorService; @@ -76,9 +76,9 @@ public static PushManagerImp build(Synchronizer synchronizer, ThreadFactory threadFactory, SplitParser splitParser, SplitCacheProducer splitCacheProducer, - HashSet flagSets) { + FlagSetsFilter flagSetsFilter) { FeatureFlagsWorker featureFlagsWorker = new FeatureFlagWorkerImp(synchronizer, splitParser, splitCacheProducer, - telemetryRuntimeProducer, flagSets); + telemetryRuntimeProducer, flagSetsFilter); Worker segmentWorker = new SegmentsWorkerImp(synchronizer); PushStatusTracker pushStatusTracker = new PushStatusTrackerImp(statusMessages, telemetryRuntimeProducer); return new PushManagerImp(new AuthApiClientImp(authUrl, splitAPI.getHttpClient(), telemetryRuntimeProducer), diff --git a/client/src/main/java/io/split/engine/common/SyncManagerImp.java b/client/src/main/java/io/split/engine/common/SyncManagerImp.java index ac716a577..27fc18862 100644 --- a/client/src/main/java/io/split/engine/common/SyncManagerImp.java +++ b/client/src/main/java/io/split/engine/common/SyncManagerImp.java @@ -3,6 +3,7 @@ import com.google.common.annotations.VisibleForTesting; import io.split.client.ApiKeyCounter; import io.split.client.SplitClientConfig; +import io.split.client.interceptors.FlagSetsFilterImpl; import io.split.engine.SDKReadinessGates; import io.split.engine.experiments.SplitFetcher; import io.split.engine.experiments.SplitParser; @@ -108,7 +109,7 @@ public static SyncManagerImp build(SplitTasks splitTasks, config.getThreadFactory(), splitParser, splitCacheProducer, - config.getSetsFilter()); + new FlagSetsFilterImpl(config.getSetsFilter())); return new SyncManagerImp(splitTasks, config.streamingEnabled(), diff --git a/client/src/main/java/io/split/engine/evaluator/Evaluator.java b/client/src/main/java/io/split/engine/evaluator/Evaluator.java index cc1c1b3fd..f745b8d77 100644 --- a/client/src/main/java/io/split/engine/evaluator/Evaluator.java +++ b/client/src/main/java/io/split/engine/evaluator/Evaluator.java @@ -8,5 +8,6 @@ EvaluatorImp.TreatmentLabelAndChangeNumber evaluateFeature(String matchingKey, S Map attributes); Map evaluateFeatures(String matchingKey, String bucketingKey, List featureFlags, Map attributes); - Map evaluateFeaturesByFlagSets(String key, String bucketingKey, List flagSets); + Map evaluateFeaturesByFlagSets(String key, String bucketingKey, + List flagSets, Map attributes); } \ No newline at end of file diff --git a/client/src/main/java/io/split/engine/evaluator/EvaluatorImp.java b/client/src/main/java/io/split/engine/evaluator/EvaluatorImp.java index 8a2be81e2..709b97d8c 100644 --- a/client/src/main/java/io/split/engine/evaluator/EvaluatorImp.java +++ b/client/src/main/java/io/split/engine/evaluator/EvaluatorImp.java @@ -55,9 +55,9 @@ public Map evaluateFeatures(String matchi @Override public Map evaluateFeaturesByFlagSets(String key, String bucketingKey, - List flagSets) { + List flagSets, Map attributes) { List flagSetsWithNames = getFeatureFlagNamesByFlagSets(flagSets); - Map evaluations = evaluateFeatures(key, bucketingKey, flagSetsWithNames, null); + Map evaluations = evaluateFeatures(key, bucketingKey, flagSetsWithNames, attributes); return evaluations; } diff --git a/client/src/main/java/io/split/engine/experiments/SplitFetcherImp.java b/client/src/main/java/io/split/engine/experiments/SplitFetcherImp.java index 71f5e00c7..84b6a287d 100644 --- a/client/src/main/java/io/split/engine/experiments/SplitFetcherImp.java +++ b/client/src/main/java/io/split/engine/experiments/SplitFetcherImp.java @@ -2,6 +2,7 @@ import io.split.client.dtos.SplitChange; import io.split.client.exceptions.UriTooLongException; +import io.split.client.interceptors.FlagSetsFilter; import io.split.client.utils.FeatureFlagsToUpdate; import io.split.storages.SplitCacheProducer; import io.split.telemetry.domain.enums.LastSynchronizationRecordsEnum; @@ -30,7 +31,7 @@ public class SplitFetcherImp implements SplitFetcher { private final SplitCacheProducer _splitCacheProducer; private final Object _lock = new Object(); private final TelemetryRuntimeProducer _telemetryRuntimeProducer; - private final HashSet _flagSets; + private final FlagSetsFilter _flagSetsFilter; /** * Contains all the traffic types that are currently being used by the splits and also the count @@ -43,12 +44,12 @@ public class SplitFetcherImp implements SplitFetcher { */ public SplitFetcherImp(SplitChangeFetcher splitChangeFetcher, SplitParser parser, SplitCacheProducer splitCacheProducer, - TelemetryRuntimeProducer telemetryRuntimeProducer, HashSet sets) { + TelemetryRuntimeProducer telemetryRuntimeProducer, FlagSetsFilter flagSetsFilter) { _splitChangeFetcher = checkNotNull(splitChangeFetcher); _parser = checkNotNull(parser); _splitCacheProducer = checkNotNull(splitCacheProducer); _telemetryRuntimeProducer = checkNotNull(telemetryRuntimeProducer); - _flagSets = sets; + _flagSetsFilter = flagSetsFilter; } @Override @@ -119,7 +120,7 @@ private Set runWithoutExceptionHandling(FetchOptions options) throws Int // some other thread may have updated the shared state. exit return segments; } - FeatureFlagsToUpdate featureFlagsToUpdate = processFeatureFlagChanges(_parser, change.splits, _flagSets); + FeatureFlagsToUpdate featureFlagsToUpdate = processFeatureFlagChanges(_parser, change.splits, _flagSetsFilter); segments = featureFlagsToUpdate.getSegments(); _splitCacheProducer.update(featureFlagsToUpdate.getToAdd(), featureFlagsToUpdate.getToRemove(), change.till); _telemetryRuntimeProducer.recordSuccessfulSync(LastSynchronizationRecordsEnum.SPLITS, System.currentTimeMillis()); diff --git a/client/src/main/java/io/split/engine/sse/workers/FeatureFlagWorkerImp.java b/client/src/main/java/io/split/engine/sse/workers/FeatureFlagWorkerImp.java index caf8d04e3..f66656495 100644 --- a/client/src/main/java/io/split/engine/sse/workers/FeatureFlagWorkerImp.java +++ b/client/src/main/java/io/split/engine/sse/workers/FeatureFlagWorkerImp.java @@ -1,6 +1,7 @@ package io.split.engine.sse.workers; import io.split.client.dtos.Split; +import io.split.client.interceptors.FlagSetsFilter; import io.split.client.utils.FeatureFlagsToUpdate; import io.split.engine.common.Synchronizer; import io.split.engine.experiments.SplitParser; @@ -13,7 +14,6 @@ import org.slf4j.LoggerFactory; import java.util.Collections; -import java.util.HashSet; import java.util.Set; import static com.google.common.base.Preconditions.checkNotNull; @@ -25,16 +25,16 @@ public class FeatureFlagWorkerImp extends Worker private final SplitParser _splitParser; private final SplitCacheProducer _splitCacheProducer; private final TelemetryRuntimeProducer _telemetryRuntimeProducer; - private final HashSet _flagSets; + private final FlagSetsFilter _flagSetsFilter; public FeatureFlagWorkerImp(Synchronizer synchronizer, SplitParser splitParser, SplitCacheProducer splitCacheProducer, - TelemetryRuntimeProducer telemetryRuntimeProducer, HashSet flagSets) { + TelemetryRuntimeProducer telemetryRuntimeProducer, FlagSetsFilter flagSetsFilter) { super("Feature flags"); _synchronizer = checkNotNull(synchronizer); _splitParser = splitParser; _splitCacheProducer = splitCacheProducer; _telemetryRuntimeProducer = telemetryRuntimeProducer; - _flagSets = flagSets; + _flagSetsFilter = flagSetsFilter; } @Override @@ -65,7 +65,7 @@ private boolean addOrUpdateFeatureFlag(FeatureFlagChangeNotification featureFlag featureFlagChangeNotification.getPreviousChangeNumber() == _splitCacheProducer.getChangeNumber()) { Split featureFlag = featureFlagChangeNotification.getFeatureFlagDefinition(); FeatureFlagsToUpdate featureFlagsToUpdate = processFeatureFlagChanges(_splitParser, Collections.singletonList(featureFlag), - _flagSets); + _flagSetsFilter); _splitCacheProducer.update(featureFlagsToUpdate.getToAdd(), featureFlagsToUpdate.getToRemove(), featureFlagChangeNotification.getChangeNumber()); Set segments = featureFlagsToUpdate.getSegments(); diff --git a/client/src/main/java/io/split/storages/memory/InMemoryCacheImp.java b/client/src/main/java/io/split/storages/memory/InMemoryCacheImp.java index e9b779dc1..580f9b0a7 100644 --- a/client/src/main/java/io/split/storages/memory/InMemoryCacheImp.java +++ b/client/src/main/java/io/split/storages/memory/InMemoryCacheImp.java @@ -5,7 +5,6 @@ import com.google.common.collect.Multiset; import com.google.common.collect.Sets; import io.split.client.interceptors.FlagSetsFilter; -import io.split.client.interceptors.FlagSetsFilterImpl; import io.split.engine.experiments.ParsedSplit; import io.split.storages.SplitCache; import org.slf4j.Logger; @@ -33,16 +32,16 @@ public class InMemoryCacheImp implements SplitCache { private AtomicLong _changeNumber; - public InMemoryCacheImp(HashSet flagSets) { + public InMemoryCacheImp(FlagSetsFilter flagSets) { this(-1, flagSets); } - public InMemoryCacheImp(long startingChangeNumber, HashSet flagSets) { + public InMemoryCacheImp(long startingChangeNumber, FlagSetsFilter flagSets) { _concurrentMap = Maps.newConcurrentMap(); _changeNumber = new AtomicLong(startingChangeNumber); _concurrentTrafficTypeNameSet = ConcurrentHashMultiset.create(); _flagSets = Maps.newConcurrentMap(); - _flagSetsFilter = new FlagSetsFilterImpl(flagSets); + _flagSetsFilter = flagSets; } @Override diff --git a/client/src/test/java/io/split/client/CacheUpdaterServiceTest.java b/client/src/test/java/io/split/client/CacheUpdaterServiceTest.java index 1e3a708fd..5f8084f4e 100644 --- a/client/src/test/java/io/split/client/CacheUpdaterServiceTest.java +++ b/client/src/test/java/io/split/client/CacheUpdaterServiceTest.java @@ -1,5 +1,7 @@ package io.split.client; +import io.split.client.interceptors.FlagSetsFilter; +import io.split.client.interceptors.FlagSetsFilterImpl; import io.split.storages.memory.InMemoryCacheImp; import io.split.storages.SplitCache; import org.junit.Assert; @@ -18,7 +20,8 @@ public class CacheUpdaterServiceTest { @Test public void testCacheUpdate() { - SplitCache splitCache = new InMemoryCacheImp(new HashSet<>()); + FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(new HashSet<>()); + SplitCache splitCache = new InMemoryCacheImp(flagSetsFilter); CacheUpdaterService cacheUpdaterService = new CacheUpdaterService(splitCache); cacheUpdaterService.updateCache(getMap()); Assert.assertNotNull(splitCache.get(MY_FEATURE)); diff --git a/client/src/test/java/io/split/client/utils/FeatureFlagProcessorTest.java b/client/src/test/java/io/split/client/utils/FeatureFlagProcessorTest.java index 6ce470534..7a1b774a1 100644 --- a/client/src/test/java/io/split/client/utils/FeatureFlagProcessorTest.java +++ b/client/src/test/java/io/split/client/utils/FeatureFlagProcessorTest.java @@ -1,6 +1,8 @@ package io.split.client.utils; import io.split.client.dtos.Split; +import io.split.client.interceptors.FlagSetsFilter; +import io.split.client.interceptors.FlagSetsFilterImpl; import io.split.engine.experiments.SplitParser; import org.junit.Assert; import org.junit.Test; @@ -27,7 +29,8 @@ public void testProcessFeatureFlagChanges() { featureFlags.add(featureFlagTest1); featureFlags.add(featureFlagTest2); - FeatureFlagsToUpdate featureFlagsToUpdate = processFeatureFlagChanges(splitParser, featureFlags, new HashSet<>()); + FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(new HashSet<>()); + FeatureFlagsToUpdate featureFlagsToUpdate = processFeatureFlagChanges(splitParser, featureFlags, flagSetsFilter); Assert.assertEquals(1, featureFlagsToUpdate.toAdd.size()); Assert.assertEquals(1, featureFlagsToUpdate.toRemove.size()); @@ -47,7 +50,8 @@ public void testProcessFeatureFlagChangesWithSetsToAdd() { featureFlags.add(featureFlagTest1); featureFlags.add(featureFlagTest2); - FeatureFlagsToUpdate featureFlagsToUpdate = processFeatureFlagChanges(splitParser, featureFlags, new HashSet<>(Arrays.asList("set_1"))); + FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(new HashSet<>(Arrays.asList("set_1"))); + FeatureFlagsToUpdate featureFlagsToUpdate = processFeatureFlagChanges(splitParser, featureFlags, flagSetsFilter); Assert.assertEquals(1, featureFlagsToUpdate.toAdd.size()); Assert.assertEquals(1, featureFlagsToUpdate.toRemove.size()); @@ -67,7 +71,8 @@ public void testProcessFeatureFlagChangesWithSetsToRemove() { featureFlags.add(featureFlagTest1); featureFlags.add(featureFlagTest2); - FeatureFlagsToUpdate featureFlagsToUpdate = processFeatureFlagChanges(splitParser, featureFlags, new HashSet<>(Arrays.asList("set_3"))); + FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(new HashSet<>(Arrays.asList("set_3"))); + FeatureFlagsToUpdate featureFlagsToUpdate = processFeatureFlagChanges(splitParser, featureFlags, flagSetsFilter); Assert.assertEquals(0, featureFlagsToUpdate.toAdd.size()); Assert.assertEquals(2, featureFlagsToUpdate.toRemove.size()); diff --git a/client/src/test/java/io/split/engine/common/LocalhostSynchronizerTest.java b/client/src/test/java/io/split/engine/common/LocalhostSynchronizerTest.java index d7f8bcdf6..91be19f47 100644 --- a/client/src/test/java/io/split/engine/common/LocalhostSynchronizerTest.java +++ b/client/src/test/java/io/split/engine/common/LocalhostSynchronizerTest.java @@ -2,6 +2,8 @@ import io.split.client.LocalhostSegmentChangeFetcher; import io.split.client.JsonLocalhostSplitChangeFetcher; +import io.split.client.interceptors.FlagSetsFilter; +import io.split.client.interceptors.FlagSetsFilterImpl; import io.split.client.utils.FileInputStreamProvider; import io.split.client.utils.InputStreamProvider; import io.split.engine.experiments.SplitChangeFetcher; @@ -27,16 +29,17 @@ public class LocalhostSynchronizerTest { private static final TelemetryStorage TELEMETRY_STORAGE_NOOP = Mockito.mock(NoopTelemetryStorage.class); + private static final FlagSetsFilter FLAG_SETS_FILTER = new FlagSetsFilterImpl(new HashSet<>()); @Test public void testSyncAll(){ - SplitCache splitCacheProducer = new InMemoryCacheImp(new HashSet<>()); + SplitCache splitCacheProducer = new InMemoryCacheImp(FLAG_SETS_FILTER); InputStreamProvider inputStreamProvider = new FileInputStreamProvider("src/test/resources/split_init.json"); SplitChangeFetcher splitChangeFetcher = new JsonLocalhostSplitChangeFetcher(inputStreamProvider); SplitParser splitParser = new SplitParser(); - SplitFetcher splitFetcher = new SplitFetcherImp(splitChangeFetcher, splitParser, splitCacheProducer, TELEMETRY_STORAGE_NOOP, new HashSet<>()); + SplitFetcher splitFetcher = new SplitFetcherImp(splitChangeFetcher, splitParser, splitCacheProducer, TELEMETRY_STORAGE_NOOP, FLAG_SETS_FILTER); SplitSynchronizationTask splitSynchronizationTask = new SplitSynchronizationTask(splitFetcher, splitCacheProducer, 1000L, null); SegmentChangeFetcher segmentChangeFetcher = new LocalhostSegmentChangeFetcher("src/test/resources/"); @@ -53,12 +56,12 @@ public void testSyncAll(){ @Test public void testPeriodicFetching() throws InterruptedException { - SplitCache splitCacheProducer = new InMemoryCacheImp(new HashSet<>()); + SplitCache splitCacheProducer = new InMemoryCacheImp(FLAG_SETS_FILTER); SplitChangeFetcher splitChangeFetcher = Mockito.mock(JsonLocalhostSplitChangeFetcher.class); SplitParser splitParser = new SplitParser(); - SplitFetcher splitFetcher = new SplitFetcherImp(splitChangeFetcher, splitParser, splitCacheProducer, TELEMETRY_STORAGE_NOOP, new HashSet<>()); + SplitFetcher splitFetcher = new SplitFetcherImp(splitChangeFetcher, splitParser, splitCacheProducer, TELEMETRY_STORAGE_NOOP, FLAG_SETS_FILTER); SplitSynchronizationTask splitSynchronizationTask = new SplitSynchronizationTask(splitFetcher, splitCacheProducer, 1000L, null); FetchOptions fetchOptions = new FetchOptions.Builder().build(); @@ -80,11 +83,11 @@ public void testPeriodicFetching() throws InterruptedException { @Test public void testRefreshSplits() { - SplitCacheProducer splitCacheProducer = new InMemoryCacheImp(new HashSet<>()); + SplitCacheProducer splitCacheProducer = new InMemoryCacheImp(FLAG_SETS_FILTER); SplitChangeFetcher splitChangeFetcher = Mockito.mock(SplitChangeFetcher.class); SplitParser splitParser = new SplitParser(); - SplitFetcher splitFetcher = new SplitFetcherImp(splitChangeFetcher, splitParser, splitCacheProducer, TELEMETRY_STORAGE_NOOP, new HashSet<>()); + SplitFetcher splitFetcher = new SplitFetcherImp(splitChangeFetcher, splitParser, splitCacheProducer, TELEMETRY_STORAGE_NOOP, FLAG_SETS_FILTER); SplitSynchronizationTask splitSynchronizationTask = new SplitSynchronizationTask(splitFetcher, splitCacheProducer, 1000L, null); SplitTasks splitTasks = SplitTasks.build(splitSynchronizationTask, null, null, null, null, null); LocalhostSynchronizer localhostSynchronizer = new LocalhostSynchronizer(splitTasks, splitFetcher, false); diff --git a/client/src/test/java/io/split/engine/common/SynchronizerTest.java b/client/src/test/java/io/split/engine/common/SynchronizerTest.java index 574a67c03..7fc69b590 100644 --- a/client/src/test/java/io/split/engine/common/SynchronizerTest.java +++ b/client/src/test/java/io/split/engine/common/SynchronizerTest.java @@ -3,6 +3,8 @@ import io.split.client.events.EventsTask; import io.split.client.impressions.ImpressionsManager; import io.split.client.impressions.UniqueKeysTracker; +import io.split.client.interceptors.FlagSetsFilter; +import io.split.client.interceptors.FlagSetsFilterImpl; import io.split.engine.segments.SegmentChangeFetcher; import io.split.engine.segments.SegmentSynchronizationTaskImp; import io.split.storages.SegmentCache; @@ -36,6 +38,7 @@ import static org.mockito.Mockito.when; public class SynchronizerTest { + private static final FlagSetsFilter FLAG_SETS_FILTER = new FlagSetsFilterImpl(new HashSet<>()); private SplitSynchronizationTask _refreshableSplitFetcherTask; private SegmentSynchronizationTask _segmentFetcher; private SplitFetcherImp _splitFetcher; @@ -150,7 +153,7 @@ public void streamingRetryOnSplitAndSegment() { @Test public void testCDNBypassIsRequestedAfterNFailures() { - SplitCache cache = new InMemoryCacheImp(new HashSet<>()); + SplitCache cache = new InMemoryCacheImp(FLAG_SETS_FILTER); Synchronizer imp = new SynchronizerImp(_splitTasks, _splitFetcher, cache, @@ -183,7 +186,7 @@ public void testCDNBypassIsRequestedAfterNFailures() { @Test public void testCDNBypassRequestLimitAndBackoff() throws NoSuchFieldException, IllegalAccessException { - SplitCache cache = new InMemoryCacheImp(new HashSet<>()); + SplitCache cache = new InMemoryCacheImp(FLAG_SETS_FILTER); Synchronizer imp = new SynchronizerImp(_splitTasks, _splitFetcher, cache, @@ -239,7 +242,7 @@ public void testCDNBypassRequestLimitAndBackoff() throws NoSuchFieldException, I @Test public void testCDNBypassRequestLimitAndForSegmentsBackoff() throws NoSuchFieldException, IllegalAccessException { - SplitCache cache = new InMemoryCacheImp(new HashSet<>()); + SplitCache cache = new InMemoryCacheImp(FLAG_SETS_FILTER); Synchronizer imp = new SynchronizerImp(_splitTasks, _splitFetcher, cache, @@ -298,7 +301,7 @@ public void testCDNBypassRequestLimitAndForSegmentsBackoff() throws NoSuchFieldE @Test public void testDataRecording(){ - SplitCache cache = new InMemoryCacheImp(new HashSet<>()); + SplitCache cache = new InMemoryCacheImp(FLAG_SETS_FILTER); Synchronizer imp = new SynchronizerImp(_splitTasks, _splitFetcher, cache, diff --git a/client/src/test/java/io/split/engine/evaluator/EvaluatorIntegrationTest.java b/client/src/test/java/io/split/engine/evaluator/EvaluatorIntegrationTest.java index 6909e9bc8..2d583e942 100644 --- a/client/src/test/java/io/split/engine/evaluator/EvaluatorIntegrationTest.java +++ b/client/src/test/java/io/split/engine/evaluator/EvaluatorIntegrationTest.java @@ -4,6 +4,8 @@ import io.split.client.dtos.ConditionType; import io.split.client.dtos.MatcherCombiner; import io.split.client.dtos.Partition; +import io.split.client.interceptors.FlagSetsFilter; +import io.split.client.interceptors.FlagSetsFilterImpl; import io.split.engine.experiments.ParsedCondition; import io.split.engine.experiments.ParsedSplit; import io.split.engine.matchers.AttributeMatcher; @@ -151,7 +153,8 @@ public void evaluateFeaturesSplitsNull() { } private Evaluator buildEvaluatorAndLoadCache(boolean killed, int trafficAllocation) { - SplitCache splitCache = new InMemoryCacheImp(new HashSet<>()); + FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(new HashSet<>()); + SplitCache splitCache = new InMemoryCacheImp(flagSetsFilter); SegmentCache segmentCache = new SegmentCacheInMemoryImpl(); Evaluator evaluator = new EvaluatorImp(splitCache, segmentCache); @@ -180,4 +183,4 @@ private Evaluator buildEvaluatorAndLoadCache(boolean killed, int trafficAllocati splitCache.putMany(Stream.of(parsedSplit1, parsedSplit2, parsedSplit3, parsedSplit4).collect(Collectors.toList())); return evaluator; } -} +} \ No newline at end of file diff --git a/client/src/test/java/io/split/engine/evaluator/EvaluatorTest.java b/client/src/test/java/io/split/engine/evaluator/EvaluatorTest.java index 536965c18..272b5aa5b 100644 --- a/client/src/test/java/io/split/engine/evaluator/EvaluatorTest.java +++ b/client/src/test/java/io/split/engine/evaluator/EvaluatorTest.java @@ -161,7 +161,7 @@ public void evaluateWithSets() { parsedSplits.put(SPLIT_NAME, split); Mockito.when(_splitCacheConsumer.fetchMany(Arrays.asList(SPLIT_NAME))).thenReturn(parsedSplits); - Map result = _evaluator.evaluateFeaturesByFlagSets(MATCHING_KEY, BUCKETING_KEY, sets); + Map result = _evaluator.evaluateFeaturesByFlagSets(MATCHING_KEY, BUCKETING_KEY, sets, null); EvaluatorImp.TreatmentLabelAndChangeNumber treatmentLabelAndChangeNumber = result.get(SPLIT_NAME); @@ -179,7 +179,7 @@ public void evaluateWithSetsNotHaveFlags() { Map parsedSplits = new HashMap<>(); Mockito.when(_splitCacheConsumer.fetchMany(Arrays.asList(SPLIT_NAME))).thenReturn(parsedSplits); - Map result = _evaluator.evaluateFeaturesByFlagSets(MATCHING_KEY, BUCKETING_KEY, sets); + Map result = _evaluator.evaluateFeaturesByFlagSets(MATCHING_KEY, BUCKETING_KEY, sets, null); Assert.assertTrue(result.isEmpty()); } } \ No newline at end of file diff --git a/client/src/test/java/io/split/engine/experiments/SplitFetcherImpTest.java b/client/src/test/java/io/split/engine/experiments/SplitFetcherImpTest.java index b74e66c5d..8ddab8dad 100644 --- a/client/src/test/java/io/split/engine/experiments/SplitFetcherImpTest.java +++ b/client/src/test/java/io/split/engine/experiments/SplitFetcherImpTest.java @@ -1,6 +1,8 @@ package io.split.engine.experiments; import io.split.client.JsonLocalhostSplitChangeFetcher; +import io.split.client.interceptors.FlagSetsFilter; +import io.split.client.interceptors.FlagSetsFilterImpl; import io.split.client.utils.FileInputStreamProvider; import io.split.client.utils.InputStreamProvider; import io.split.engine.common.FetchOptions; @@ -29,13 +31,14 @@ public class SplitFetcherImpTest { @Test public void testLocalHost() { - SplitCacheProducer splitCacheProducer = new InMemoryCacheImp(new HashSet<>()); + FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(new HashSet<>()); + SplitCacheProducer splitCacheProducer = new InMemoryCacheImp(flagSetsFilter); InputStreamProvider inputStreamProvider = new FileInputStreamProvider("src/test/resources/split_init.json"); SplitChangeFetcher splitChangeFetcher = new JsonLocalhostSplitChangeFetcher(inputStreamProvider); SplitParser splitParser = new SplitParser(); FetchOptions fetchOptions = new FetchOptions.Builder().build(); - SplitFetcher splitFetcher = new SplitFetcherImp(splitChangeFetcher, splitParser, splitCacheProducer, TELEMETRY_STORAGE_NOOP, new HashSet<>()); + SplitFetcher splitFetcher = new SplitFetcherImp(splitChangeFetcher, splitParser, splitCacheProducer, TELEMETRY_STORAGE_NOOP, flagSetsFilter); FetchResult fetchResult = splitFetcher.forceRefresh(fetchOptions); @@ -50,12 +53,13 @@ public void testLocalHostFlagSets() throws IOException { com.google.common.io.Files.write(test, file); InputStreamProvider inputStreamProvider = new FileInputStreamProvider(file.getAbsolutePath()); - SplitCacheProducer splitCacheProducer = new InMemoryCacheImp(new HashSet<>(Arrays.asList("set_1"))); + FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(new HashSet<>(Arrays.asList("set_1"))); + SplitCacheProducer splitCacheProducer = new InMemoryCacheImp(flagSetsFilter); SplitChangeFetcher splitChangeFetcher = new JsonLocalhostSplitChangeFetcher(inputStreamProvider); SplitParser splitParser = new SplitParser(); FetchOptions fetchOptions = new FetchOptions.Builder().build(); - SplitFetcher splitFetcher = new SplitFetcherImp(splitChangeFetcher, splitParser, splitCacheProducer, TELEMETRY_STORAGE_NOOP, new HashSet<>(Arrays.asList("set_1"))); + SplitFetcher splitFetcher = new SplitFetcherImp(splitChangeFetcher, splitParser, splitCacheProducer, TELEMETRY_STORAGE_NOOP, flagSetsFilter); FetchResult fetchResult = splitFetcher.forceRefresh(fetchOptions); @@ -70,12 +74,13 @@ public void testLocalHostFlagSetsNotIntersect() throws IOException { com.google.common.io.Files.write(test, file); InputStreamProvider inputStreamProvider = new FileInputStreamProvider(file.getAbsolutePath()); - SplitCacheProducer splitCacheProducer = new InMemoryCacheImp(new HashSet<>(Arrays.asList("set_4"))); + FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(new HashSet<>(Arrays.asList("set_4"))); + SplitCacheProducer splitCacheProducer = new InMemoryCacheImp(flagSetsFilter); SplitChangeFetcher splitChangeFetcher = new JsonLocalhostSplitChangeFetcher(inputStreamProvider); SplitParser splitParser = new SplitParser(); FetchOptions fetchOptions = new FetchOptions.Builder().build(); - SplitFetcher splitFetcher = new SplitFetcherImp(splitChangeFetcher, splitParser, splitCacheProducer, TELEMETRY_STORAGE_NOOP, new HashSet<>(Arrays.asList("set_4"))); + SplitFetcher splitFetcher = new SplitFetcherImp(splitChangeFetcher, splitParser, splitCacheProducer, TELEMETRY_STORAGE_NOOP, flagSetsFilter); FetchResult fetchResult = splitFetcher.forceRefresh(fetchOptions); diff --git a/client/src/test/java/io/split/engine/experiments/SplitFetcherTest.java b/client/src/test/java/io/split/engine/experiments/SplitFetcherTest.java index cce518af6..12df851b4 100644 --- a/client/src/test/java/io/split/engine/experiments/SplitFetcherTest.java +++ b/client/src/test/java/io/split/engine/experiments/SplitFetcherTest.java @@ -1,6 +1,8 @@ package io.split.engine.experiments; import com.google.common.collect.Lists; +import io.split.client.interceptors.FlagSetsFilter; +import io.split.client.interceptors.FlagSetsFilterImpl; import io.split.storages.memory.InMemoryCacheImp; import io.split.storages.SegmentCache; import io.split.storages.memory.SegmentCacheInMemoryImpl; @@ -49,23 +51,24 @@ public class SplitFetcherTest { private static final Logger _log = LoggerFactory.getLogger(SplitFetcherTest.class); private static final TelemetryStorage TELEMETRY_STORAGE = Mockito.mock(InMemoryTelemetryStorage.class); + private static final FlagSetsFilter FLAG_SETS_FILTER = new FlagSetsFilterImpl(new HashSet<>()); @Test @Ignore //This test is ignore since is deprecated. We can review this in a future. - public void works_when_we_start_without_any_state() throws InterruptedException { + public void worksWhenWeStartWithoutAnyState() throws InterruptedException { works(0); } @Test @Ignore //This test is ignore since is deprecated. We can review this in a future. - public void works_when_we_start_with_any_state() throws InterruptedException { + public void worksWhenWeStartWithAnyState() throws InterruptedException { works(11L); } private void works(long startingChangeNumber) throws InterruptedException { AChangePerCallSplitChangeFetcher splitChangeFetcher = new AChangePerCallSplitChangeFetcher(); - SplitCache cache = new InMemoryCacheImp(startingChangeNumber, new HashSet<>()); - SplitFetcherImp fetcher = new SplitFetcherImp(splitChangeFetcher, new SplitParser(), cache, TELEMETRY_STORAGE, new HashSet<>()); + SplitCache cache = new InMemoryCacheImp(startingChangeNumber, FLAG_SETS_FILTER); + SplitFetcherImp fetcher = new SplitFetcherImp(splitChangeFetcher, new SplitParser(), cache, TELEMETRY_STORAGE, FLAG_SETS_FILTER); // execute the fetcher for a little bit. executeWaitAndTerminate(fetcher, 1, 3, TimeUnit.SECONDS); @@ -88,7 +91,7 @@ private void works(long startingChangeNumber) throws InterruptedException { } @Test - public void when_parser_fails_we_remove_the_experiment() throws InterruptedException { + public void whenParserFailsWeRemoveTheExperiment() throws InterruptedException { Split validSplit = new Split(); validSplit.status = Status.ACTIVE; validSplit.seed = (int) -1; @@ -131,12 +134,12 @@ public void when_parser_fails_we_remove_the_experiment() throws InterruptedExcep when(splitChangeFetcher.fetch(Mockito.eq(1L), Mockito.any())).thenReturn(noReturn); SegmentCache segmentCache = new SegmentCacheInMemoryImpl(); - SplitCache cache = new InMemoryCacheImp(-1, new HashSet<>()); + SplitCache cache = new InMemoryCacheImp(-1, FLAG_SETS_FILTER); SegmentChangeFetcher segmentChangeFetcher = mock(SegmentChangeFetcher.class); SegmentSynchronizationTask segmentSynchronizationTask = new SegmentSynchronizationTaskImp(segmentChangeFetcher, 1,10, segmentCache, TELEMETRY_STORAGE, cache, null); segmentSynchronizationTask.start(); - SplitFetcherImp fetcher = new SplitFetcherImp(splitChangeFetcher, new SplitParser(), cache, TELEMETRY_STORAGE, new HashSet<>()); + SplitFetcherImp fetcher = new SplitFetcherImp(splitChangeFetcher, new SplitParser(), cache, TELEMETRY_STORAGE, FLAG_SETS_FILTER); // execute the fetcher for a little bit. executeWaitAndTerminate(fetcher, 1, 5, TimeUnit.SECONDS); @@ -147,8 +150,8 @@ public void when_parser_fails_we_remove_the_experiment() throws InterruptedExcep } @Test - public void if_there_is_a_problem_talking_to_split_change_count_down_latch_is_not_decremented() throws Exception { - SplitCache cache = new InMemoryCacheImp(-1, new HashSet<>()); + public void ifThereIsAProblemTalkingToSplitChangeCountDownLatchIsNotDecremented() throws Exception { + SplitCache cache = new InMemoryCacheImp(-1, FLAG_SETS_FILTER); SplitChangeFetcher splitChangeFetcher = mock(SplitChangeFetcher.class); when(splitChangeFetcher.fetch(-1L, new FetchOptions.Builder().build())).thenThrow(new RuntimeException()); @@ -157,7 +160,7 @@ public void if_there_is_a_problem_talking_to_split_change_count_down_latch_is_no SegmentChangeFetcher segmentChangeFetcher = mock(SegmentChangeFetcher.class); SegmentSynchronizationTask segmentSynchronizationTask = new SegmentSynchronizationTaskImp(segmentChangeFetcher, 1,10, segmentCache, TELEMETRY_STORAGE, cache, null); segmentSynchronizationTask.start(); - SplitFetcherImp fetcher = new SplitFetcherImp(splitChangeFetcher, new SplitParser(), cache, TELEMETRY_STORAGE, new HashSet<>()); + SplitFetcherImp fetcher = new SplitFetcherImp(splitChangeFetcher, new SplitParser(), cache, TELEMETRY_STORAGE, FLAG_SETS_FILTER); // execute the fetcher for a little bit. executeWaitAndTerminate(fetcher, 1, 5, TimeUnit.SECONDS); @@ -186,11 +189,11 @@ private void executeWaitAndTerminate(Runnable runnable, long frequency, long wai @Test @Ignore //This test is ignore since is deprecated. We can review this in a future. - public void works_with_user_defined_segments() throws Exception { + public void worksWithUserDefinedSegments() throws Exception { long startingChangeNumber = -1; String segmentName = "foosegment"; AChangePerCallSplitChangeFetcher experimentChangeFetcher = new AChangePerCallSplitChangeFetcher(segmentName); - SplitCache cache = new InMemoryCacheImp(startingChangeNumber, new HashSet<>()); + SplitCache cache = new InMemoryCacheImp(startingChangeNumber, FLAG_SETS_FILTER); SegmentCache segmentCache = new SegmentCacheInMemoryImpl(); SegmentChangeFetcher segmentChangeFetcher = mock(SegmentChangeFetcher.class); @@ -198,7 +201,7 @@ public void works_with_user_defined_segments() throws Exception { when(segmentChangeFetcher.fetch(anyString(), anyLong(), any())).thenReturn(segmentChange); SegmentSynchronizationTask segmentSynchronizationTask = new SegmentSynchronizationTaskImp(segmentChangeFetcher, 1,10, segmentCache, Mockito.mock(TelemetryStorage.class), cache, null); segmentSynchronizationTask.start(); - SplitFetcherImp fetcher = new SplitFetcherImp(experimentChangeFetcher, new SplitParser(), cache, TELEMETRY_STORAGE, new HashSet<>()); + SplitFetcherImp fetcher = new SplitFetcherImp(experimentChangeFetcher, new SplitParser(), cache, TELEMETRY_STORAGE, FLAG_SETS_FILTER); // execute the fetcher for a little bit. executeWaitAndTerminate(fetcher, 1, 5, TimeUnit.SECONDS); @@ -217,8 +220,8 @@ public void works_with_user_defined_segments() throws Exception { public void testBypassCdnClearedAfterFirstHit() { SplitChangeFetcher mockFetcher = Mockito.mock(SplitChangeFetcher.class); SplitParser mockParser = new SplitParser(); - SplitCache mockCache = new InMemoryCacheImp(new HashSet<>()); - SplitFetcherImp fetcher = new SplitFetcherImp(mockFetcher, mockParser, mockCache, Mockito.mock(TelemetryRuntimeProducer.class), new HashSet<>()); + SplitCache mockCache = new InMemoryCacheImp(FLAG_SETS_FILTER); + SplitFetcherImp fetcher = new SplitFetcherImp(mockFetcher, mockParser, mockCache, Mockito.mock(TelemetryRuntimeProducer.class), FLAG_SETS_FILTER); SplitChange response1 = new SplitChange(); diff --git a/client/src/test/java/io/split/engine/experiments/SplitSynchronizationTaskTest.java b/client/src/test/java/io/split/engine/experiments/SplitSynchronizationTaskTest.java index 727caa8d4..ca7ceab77 100644 --- a/client/src/test/java/io/split/engine/experiments/SplitSynchronizationTaskTest.java +++ b/client/src/test/java/io/split/engine/experiments/SplitSynchronizationTaskTest.java @@ -1,6 +1,8 @@ package io.split.engine.experiments; import io.split.client.JsonLocalhostSplitChangeFetcher; +import io.split.client.interceptors.FlagSetsFilter; +import io.split.client.interceptors.FlagSetsFilterImpl; import io.split.engine.common.FetchOptions; import io.split.storages.SplitCacheProducer; import io.split.storages.memory.InMemoryCacheImp; @@ -14,15 +16,16 @@ public class SplitSynchronizationTaskTest { private static final TelemetryStorage TELEMETRY_STORAGE_NOOP = Mockito.mock(NoopTelemetryStorage.class); + private static final FlagSetsFilter FLAG_SETS_FILTER = new FlagSetsFilterImpl(new HashSet<>()); @Test public void testLocalhost() throws InterruptedException { - SplitCacheProducer splitCacheProducer = new InMemoryCacheImp(new HashSet<>()); + SplitCacheProducer splitCacheProducer = new InMemoryCacheImp(FLAG_SETS_FILTER); SplitChangeFetcher splitChangeFetcher = Mockito.mock(JsonLocalhostSplitChangeFetcher.class); SplitParser splitParser = new SplitParser(); FetchOptions fetchOptions = new FetchOptions.Builder().build(); - SplitFetcher splitFetcher = new SplitFetcherImp(splitChangeFetcher, splitParser, splitCacheProducer, TELEMETRY_STORAGE_NOOP, new HashSet<>()); + SplitFetcher splitFetcher = new SplitFetcherImp(splitChangeFetcher, splitParser, splitCacheProducer, TELEMETRY_STORAGE_NOOP, FLAG_SETS_FILTER); SplitSynchronizationTask splitSynchronizationTask = new SplitSynchronizationTask(splitFetcher, splitCacheProducer, 1000, null); @@ -35,7 +38,7 @@ public void testLocalhost() throws InterruptedException { @Test public void testStartAndStop() throws InterruptedException { - SplitCacheProducer splitCacheProducer = new InMemoryCacheImp(new HashSet<>()); + SplitCacheProducer splitCacheProducer = new InMemoryCacheImp(FLAG_SETS_FILTER); SplitFetcherImp splitFetcherImp = Mockito.mock(SplitFetcherImp.class); SplitSynchronizationTask splitSynchronizationTask = new SplitSynchronizationTask(splitFetcherImp, splitCacheProducer, 1000, null); splitSynchronizationTask.start(); diff --git a/client/src/test/java/io/split/engine/segments/SegmentSynchronizationTaskImpTest.java b/client/src/test/java/io/split/engine/segments/SegmentSynchronizationTaskImpTest.java index dba2ba979..027d09f5f 100644 --- a/client/src/test/java/io/split/engine/segments/SegmentSynchronizationTaskImpTest.java +++ b/client/src/test/java/io/split/engine/segments/SegmentSynchronizationTaskImpTest.java @@ -3,6 +3,8 @@ import com.google.common.collect.Maps; import io.split.client.LocalhostSegmentChangeFetcher; import io.split.client.JsonLocalhostSplitChangeFetcher; +import io.split.client.interceptors.FlagSetsFilter; +import io.split.client.interceptors.FlagSetsFilterImpl; import io.split.client.utils.InputStreamProvider; import io.split.client.utils.StaticContentInputStreamProvider; import io.split.engine.common.FetchOptions; @@ -152,14 +154,15 @@ public void testFetchAllAsynchronousAndGetTrue() throws NoSuchFieldException, Il @Test public void testLocalhostSegmentChangeFetcher() throws InterruptedException, FileNotFoundException { - SplitCache splitCacheProducer = new InMemoryCacheImp(new HashSet<>()); + FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(new HashSet<>()); + SplitCache splitCacheProducer = new InMemoryCacheImp(flagSetsFilter); InputStream inputStream = new FileInputStream("src/test/resources/split_init.json"); InputStreamProvider inputStreamProvider = new StaticContentInputStreamProvider(inputStream); SplitChangeFetcher splitChangeFetcher = new JsonLocalhostSplitChangeFetcher(inputStreamProvider); SplitParser splitParser = new SplitParser(); FetchOptions fetchOptions = new FetchOptions.Builder().build(); - SplitFetcher splitFetcher = new SplitFetcherImp(splitChangeFetcher, splitParser, splitCacheProducer, TELEMETRY_STORAGE_NOOP, new HashSet<>()); + SplitFetcher splitFetcher = new SplitFetcherImp(splitChangeFetcher, splitParser, splitCacheProducer, TELEMETRY_STORAGE_NOOP, flagSetsFilter); SplitSynchronizationTask splitSynchronizationTask = new SplitSynchronizationTask(splitFetcher, splitCacheProducer, 1000, null); diff --git a/client/src/test/java/io/split/engine/sse/workers/FeatureFlagWorkerImpTest.java b/client/src/test/java/io/split/engine/sse/workers/FeatureFlagWorkerImpTest.java index 12e2953e4..9be19b487 100644 --- a/client/src/test/java/io/split/engine/sse/workers/FeatureFlagWorkerImpTest.java +++ b/client/src/test/java/io/split/engine/sse/workers/FeatureFlagWorkerImpTest.java @@ -1,5 +1,7 @@ package io.split.engine.sse.workers; +import io.split.client.interceptors.FlagSetsFilter; +import io.split.client.interceptors.FlagSetsFilterImpl; import io.split.client.utils.Json; import io.split.engine.common.Synchronizer; import io.split.engine.common.SynchronizerImp; @@ -20,13 +22,15 @@ public class FeatureFlagWorkerImpTest { + private static final FlagSetsFilter FLAG_SETS_FILTER = new FlagSetsFilterImpl(new HashSet<>()); + @Test public void testRefreshSplitsWithCorrectFF() { SplitParser splitParser = new SplitParser(); Synchronizer synchronizer = Mockito.mock(SynchronizerImp.class); SplitCacheProducer splitCacheProducer = Mockito.mock(SplitCacheProducer.class); TelemetryStorage telemetryRuntimeProducer = new InMemoryTelemetryStorage(); - FeatureFlagWorkerImp featureFlagsWorker = new FeatureFlagWorkerImp(synchronizer, splitParser, splitCacheProducer, telemetryRuntimeProducer, new HashSet<>()); + FeatureFlagWorkerImp featureFlagsWorker = new FeatureFlagWorkerImp(synchronizer, splitParser, splitCacheProducer, telemetryRuntimeProducer, FLAG_SETS_FILTER); String notification = "{\"id\":\"vQQ61wzBRO:0:0\",\"clientId\":\"pri:MTUxNzg3MDg1OQ==\",\"timestamp\":1684265694676,\"encoding\":\"json\",\"channel\":\"NzM2MDI5Mzc0_MjkyNTIzNjczMw==_splits\",\"data\":\"{\\\"type\\\":\\\"SPLIT_UPDATE\\\",\\\"changeNumber\\\":1684265694505,\\\"pcn\\\":0,\\\"c\\\":2,\\\"d\\\":\\\"eJzMk99u2kwQxV8lOtdryQZj8N6hD5QPlThSTVNVEUKDPYZt1jZar1OlyO9emf8lVFWv2ss5zJyd82O8hTWUZSqZvW04opwhUVdsIKBSSKR+10vS1HWW7pIdz2NyBjRwHS8IXEopTLgbQqDYT+ZUm3LxlV4J4mg81LpMyKqygPRc94YeM6eQTtjphp4fegLVXvD6Qdjt9wPXF6gs2bqCxPC/2eRpDIEXpXXblpGuWCDljGptZ4bJ5lxYSJRZBoFkTcWKozpfsoH0goHfCXpB6PfcngDpVQnZEUjKIlOr2uwWqiC3zU5L1aF+3p7LFhUkPv8/mY2nk3gGgZxssmZzb8p6A9n25ktVtA9iGI3ODXunQ3HDp+AVWT6F+rZWlrWq7MN+YkSWWvuTDvkMSnNV7J6oTdl6qKTEvGnmjcCGjL2IYC/ovPYgUKnvvPtbmrmApiVryLM7p2jE++AfH6fTx09/HvuF32LWnNjStM0Xh3c8ukZcsZlEi3h8/zCObsBpJ0acqYLTmFdtqitK1V6NzrfpdPBbLmVx4uK26e27izpDu/r5yf/16AXun2Cr4u6w591xw7+LfDidLj6Mv8TXwP8xbofv/c7UmtHMmx8BAAD//0fclvU=\\\"}\"}"; RawMessageNotification rawMessageNotification = Json.fromJson(notification, RawMessageNotification.class); GenericNotificationData genericNotificationData = Json.fromJson(rawMessageNotification.getData(), GenericNotificationData.class); @@ -44,7 +48,7 @@ public void testRefreshSplitsWithEmptyData() { Synchronizer synchronizer = Mockito.mock(SynchronizerImp.class); SplitCacheProducer splitCacheProducer = Mockito.mock(SplitCacheProducer.class); TelemetryStorage telemetryRuntimeProducer = new InMemoryTelemetryStorage(); - FeatureFlagWorkerImp featureFlagsWorker = new FeatureFlagWorkerImp(synchronizer, splitParser, splitCacheProducer, telemetryRuntimeProducer, new HashSet<>()); + FeatureFlagWorkerImp featureFlagsWorker = new FeatureFlagWorkerImp(synchronizer, splitParser, splitCacheProducer, telemetryRuntimeProducer, FLAG_SETS_FILTER); String notification = "{\"id\":\"vQQ61wzBRO:0:0\",\"clientId\":\"pri:MTUxNzg3MDg1OQ==\",\"timestamp\":1684265694676,\"encoding\":\"json\",\"channel\":\"NzM2MDI5Mzc0_MjkyNTIzNjczMw==_splits\",\"data\":\"{\\\"type\\\":\\\"SPLIT_UPDATE\\\",\\\"changeNumber\\\":1684265694505}\"}"; RawMessageNotification rawMessageNotification = Json.fromJson(notification, RawMessageNotification.class); GenericNotificationData genericNotificationData = Json.fromJson(rawMessageNotification.getData(), GenericNotificationData.class); @@ -60,9 +64,9 @@ public void testRefreshSplitsWithEmptyData() { public void testRefreshSplitsArchiveFF() { SplitParser splitParser = new SplitParser(); Synchronizer synchronizer = Mockito.mock(SynchronizerImp.class); - SplitCacheProducer splitCacheProducer = new InMemoryCacheImp(1686165614090L, new HashSet<>()); + SplitCacheProducer splitCacheProducer = new InMemoryCacheImp(1686165614090L, FLAG_SETS_FILTER); TelemetryStorage telemetryRuntimeProducer = new InMemoryTelemetryStorage(); - FeatureFlagWorkerImp featureFlagsWorker = new FeatureFlagWorkerImp(synchronizer, splitParser, splitCacheProducer, telemetryRuntimeProducer, new HashSet<>()); + FeatureFlagWorkerImp featureFlagsWorker = new FeatureFlagWorkerImp(synchronizer, splitParser, splitCacheProducer, telemetryRuntimeProducer, FLAG_SETS_FILTER); String notification = "{\"id\":\"vQQ61wzBRO:0:0\",\"clientId\":\"pri:MTUxNzg3MDg1OQ==\",\"timestamp\":1684265694676,\"encoding\":\"json\",\"channel\":\"NzM2MDI5Mzc0_MjkyNTIzNjczMw==_splits\",\"data\":\"{\\\"type\\\":\\\"SPLIT_UPDATE\\\",\\\"changeNumber\\\":1686165617166,\\\"pcn\\\":1686165614090,\\\"c\\\":2,\\\"d\\\":\\\"eJxsUdFu4jAQ/JVqnx3JDjTh/JZCrj2JBh0EqtOBIuNswKqTIMeuxKH8+ykhiKrqiyXvzM7O7lzAGlEUSqbnEyaiRODgGjRAQOXAIQ/puPB96tHHIPQYQ/QmFNErxEgG44DKnI2AQHXtTOI0my6WcXZAmxoUtsTKvil7nNZVoQ5RYdFERh7VBwK5TY60rqWwqq6AM0q/qa8Qc+As/EHZ5HHMCDR9wQ/9kIajcEygscK6BjhEy+nLr008AwLvSuuOVgjdIIEcC+H03RZw2Hg/n88JEJBHUR0wceUeDXAWTAIWPAYsZEFAQOhDDdwnIPslnOk9NcAvNwEOly3IWtdmC3wLe+1wCy0Q2Hh/zNvTV9xg3sFtr5irQe3v5f7twgAOy8V8vlinQKAUVh7RPJvanbrBsi73qurMQpTM7oSrzjueV6hR2tp05E8J39MV1hq1d7YrWWxsZ2cQGYjzeLXK0pcoyRbLLP69juZZuuiyxoPo2oa7ukqYc+JKNEq+XgVmwopucC6sGMSS9etTvAQCH0I7BO7Ttt21BE7C2E8XsN+l06h/CJy25CveH/eGM0rbHQEt9qiHnR62jtKR7N/8wafQ7tr/AQAA//8S4fPB\\\"}\"}"; RawMessageNotification rawMessageNotification = Json.fromJson(notification, RawMessageNotification.class); GenericNotificationData genericNotificationData = Json.fromJson(rawMessageNotification.getData(), GenericNotificationData.class); diff --git a/client/src/test/java/io/split/engine/sse/workers/SplitsWorkerTest.java b/client/src/test/java/io/split/engine/sse/workers/SplitsWorkerTest.java index 78a30e43d..2ece6c550 100644 --- a/client/src/test/java/io/split/engine/sse/workers/SplitsWorkerTest.java +++ b/client/src/test/java/io/split/engine/sse/workers/SplitsWorkerTest.java @@ -1,5 +1,7 @@ package io.split.engine.sse.workers; +import io.split.client.interceptors.FlagSetsFilter; +import io.split.client.interceptors.FlagSetsFilterImpl; import io.split.engine.common.Synchronizer; import io.split.engine.experiments.SplitParser; import io.split.engine.sse.dtos.FeatureFlagChangeNotification; @@ -20,6 +22,8 @@ public class SplitsWorkerTest { + private static final FlagSetsFilter FLAG_SETS_FILTER = new FlagSetsFilterImpl(new HashSet<>()); + @Test public void addToQueueWithoutElementsWShouldNotTriggerFetch() throws InterruptedException { Synchronizer splitFetcherMock = Mockito.mock(Synchronizer.class); @@ -27,7 +31,7 @@ public void addToQueueWithoutElementsWShouldNotTriggerFetch() throws Interrupted SplitCacheProducer splitCacheProducer = Mockito.mock(SplitCacheProducer.class); TelemetryRuntimeProducer telemetryRuntimeProducer = Mockito.mock(InMemoryTelemetryStorage.class); - FeatureFlagsWorker featureFlagsWorker = new FeatureFlagWorkerImp(splitFetcherMock, splitParser, splitCacheProducer, telemetryRuntimeProducer, new HashSet<>()); + FeatureFlagsWorker featureFlagsWorker = new FeatureFlagWorkerImp(splitFetcherMock, splitParser, splitCacheProducer, telemetryRuntimeProducer, FLAG_SETS_FILTER); featureFlagsWorker.start(); Thread.sleep(500); @@ -42,7 +46,7 @@ public void addToQueueWithElementsWShouldTriggerFetch() throws InterruptedExcept SplitCacheProducer splitCacheProducer = Mockito.mock(SplitCacheProducer.class); TelemetryRuntimeProducer telemetryRuntimeProducer = Mockito.mock(InMemoryTelemetryStorage.class); - FeatureFlagsWorker featureFlagsWorker = new FeatureFlagWorkerImp(syncMock, splitParser, splitCacheProducer, telemetryRuntimeProducer, new HashSet<>()); + FeatureFlagsWorker featureFlagsWorker = new FeatureFlagWorkerImp(syncMock, splitParser, splitCacheProducer, telemetryRuntimeProducer, FLAG_SETS_FILTER); featureFlagsWorker.start(); ArgumentCaptor cnCaptor = ArgumentCaptor.forClass(Long.class); @@ -77,7 +81,7 @@ public void killShouldTriggerFetch() { SplitParser splitParser = new SplitParser(); SplitCacheProducer splitCacheProducer = Mockito.mock(SplitCacheProducer.class); TelemetryRuntimeProducer telemetryRuntimeProducer = Mockito.mock(InMemoryTelemetryStorage.class); - FeatureFlagsWorker featureFlagsWorker = new FeatureFlagWorkerImp(syncMock, splitParser, splitCacheProducer, telemetryRuntimeProducer, new HashSet<>()) { + FeatureFlagsWorker featureFlagsWorker = new FeatureFlagWorkerImp(syncMock, splitParser, splitCacheProducer, telemetryRuntimeProducer, FLAG_SETS_FILTER) { }; featureFlagsWorker.start(); SplitKillNotification splitKillNotification = new SplitKillNotification(GenericNotificationData.builder() @@ -97,7 +101,7 @@ public void messagesNotProcessedWhenWorkerStopped() throws InterruptedException SplitParser splitParser = new SplitParser(); SplitCacheProducer splitCacheProducer = Mockito.mock(SplitCacheProducer.class); TelemetryRuntimeProducer telemetryRuntimeProducer = Mockito.mock(InMemoryTelemetryStorage.class); - FeatureFlagsWorker featureFlagsWorker = new FeatureFlagWorkerImp(syncMock, splitParser, splitCacheProducer, telemetryRuntimeProducer, new HashSet<>()); + FeatureFlagsWorker featureFlagsWorker = new FeatureFlagWorkerImp(syncMock, splitParser, splitCacheProducer, telemetryRuntimeProducer, FLAG_SETS_FILTER); featureFlagsWorker.start(); featureFlagsWorker.addToQueue(new FeatureFlagChangeNotification(GenericNotificationData.builder() .changeNumber(1585956698457L) diff --git a/client/src/test/java/io/split/storages/memory/InMemoryCacheTest.java b/client/src/test/java/io/split/storages/memory/InMemoryCacheTest.java index 0b37bc0c6..5a42d2915 100644 --- a/client/src/test/java/io/split/storages/memory/InMemoryCacheTest.java +++ b/client/src/test/java/io/split/storages/memory/InMemoryCacheTest.java @@ -2,6 +2,8 @@ import com.google.common.collect.Lists; import io.split.client.dtos.Partition; +import io.split.client.interceptors.FlagSetsFilter; +import io.split.client.interceptors.FlagSetsFilterImpl; import io.split.engine.ConditionsTestUtil; import io.split.engine.experiments.ParsedCondition; import io.split.engine.experiments.ParsedSplit; @@ -30,7 +32,8 @@ public class InMemoryCacheTest { @Before public void before() { - _cache = new InMemoryCacheImp(new HashSet<>(Arrays.asList("set1", "set2"))); + FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(new HashSet<>(Arrays.asList("set1", "set2"))); + _cache = new InMemoryCacheImp(flagSetsFilter); } @Test