From c9f10c048449775b2f24ecc7460a7026860c12c9 Mon Sep 17 00:00:00 2001 From: Nadia Mayor Date: Wed, 1 Nov 2023 12:13:52 -0300 Subject: [PATCH 1/2] Create FlagSetFilter with empty sets in consumer mode --- .../java/io/split/client/SplitClientImpl.java | 9 +- .../io/split/client/SplitFactoryImpl.java | 16 +- .../client/interceptors/FlagSetsFilter.java | 4 +- .../interceptors/FlagSetsFilterImpl.java | 4 +- .../client/utils/FeatureFlagProcessor.java | 3 +- .../storages/memory/InMemoryCacheImp.java | 2 +- .../pluggable/domain/UserPipelineWrapper.java | 4 +- .../io/split/client/SplitClientImplTest.java | 159 ++++++++++++------ .../interceptors/FlagSetsFilterImplTest.java | 12 +- 9 files changed, 138 insertions(+), 75 deletions(-) diff --git a/client/src/main/java/io/split/client/SplitClientImpl.java b/client/src/main/java/io/split/client/SplitClientImpl.java index 2b2bcd534..16a6c5ae1 100644 --- a/client/src/main/java/io/split/client/SplitClientImpl.java +++ b/client/src/main/java/io/split/client/SplitClientImpl.java @@ -7,7 +7,6 @@ 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; @@ -59,6 +58,7 @@ public final class SplitClientImpl implements SplitClient { private final Evaluator _evaluator; private final TelemetryEvaluationProducer _telemetryEvaluationProducer; private final TelemetryConfigProducer _telemetryConfigProducer; + private final FlagSetsFilter _flagSetsFilter; public SplitClientImpl(SplitFactory container, SplitCacheConsumer splitCacheConsumer, @@ -68,7 +68,8 @@ public SplitClientImpl(SplitFactory container, SDKReadinessGates gates, Evaluator evaluator, TelemetryEvaluationProducer telemetryEvaluationProducer, - TelemetryConfigProducer telemetryConfigProducer) { + TelemetryConfigProducer telemetryConfigProducer, + FlagSetsFilter flagSetsFilter) { _container = container; _splitCacheConsumer = checkNotNull(splitCacheConsumer); _impressionManager = checkNotNull(impressionManager); @@ -78,6 +79,7 @@ public SplitClientImpl(SplitFactory container, _evaluator = checkNotNull(evaluator); _telemetryEvaluationProducer = checkNotNull(telemetryEvaluationProducer); _telemetryConfigProducer = checkNotNull(telemetryConfigProducer); + _flagSetsFilter = flagSetsFilter; } @Override @@ -444,10 +446,9 @@ private Map validateBeforeEvaluate(List featureFlag return null; } private List filterSetsAreInConfig(Set sets, MethodEnum methodEnum) { - FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(_config.getSetsFilter()); List setsToReturn = new ArrayList<>(); for (String set : sets) { - if (!flagSetsFilter.Intersect(set)) { + if (!_flagSetsFilter.intersect(set)) { _log.warn(String.format("%s: you passed %s which is not part of the configured FlagSetsFilter, " + "ignoring Flag Set.", methodEnum, 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 bcb032bbb..c4bbf84ae 100644 --- a/client/src/main/java/io/split/client/SplitFactoryImpl.java +++ b/client/src/main/java/io/split/client/SplitFactoryImpl.java @@ -111,6 +111,7 @@ 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; @@ -240,7 +241,8 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn _gates, _evaluator, _telemetryStorageProducer, //TelemetryEvaluation instance - _telemetryStorageProducer); //TelemetryConfiguration instance + _telemetryStorageProducer, //TelemetryConfiguration instance + flagSetsFilter); // SplitManager _manager = new SplitManagerImpl(splitCache, config, _gates, _telemetryStorageProducer); @@ -318,7 +320,11 @@ protected SplitFactoryImpl(String apiToken, SplitClientConfig config, CustomStor // Synchronizer Synchronizer synchronizer = new ConsumerSynchronizer(splitTasks); - + FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(new HashSet<>()); + if(!config.getSetsFilter().isEmpty()) { + _log.warn("FlagSets filter is not applicable for Consumer modes where the SDK does keep rollout data in sync. FlagSet " + + "filter was discarded"); + } _client = new SplitClientImpl(this, userCustomSplitAdapterConsumer, _impressionsManager, @@ -327,7 +333,8 @@ protected SplitFactoryImpl(String apiToken, SplitClientConfig config, CustomStor _gates, _evaluator, _telemetryStorageProducer, //TelemetryEvaluation instance - _telemetryStorageProducer); //TelemetryConfiguration instance + _telemetryStorageProducer, //TelemetryConfiguration instance + flagSetsFilter); // SyncManager @@ -405,7 +412,8 @@ protected SplitFactoryImpl(SplitClientConfig config) { _gates, _evaluator, _telemetryStorageProducer, //TelemetryEvaluation instance - _telemetryStorageProducer); //TelemetryConfiguration instance + _telemetryStorageProducer, //TelemetryConfiguration instance + flagSetsFilter); // Synchronizer Synchronizer synchronizer = new LocalhostSynchronizer(splitTasks, _splitFetcher, config.localhostRefreshEnabled()); diff --git a/client/src/main/java/io/split/client/interceptors/FlagSetsFilter.java b/client/src/main/java/io/split/client/interceptors/FlagSetsFilter.java index 20a7d1449..f571f1342 100644 --- a/client/src/main/java/io/split/client/interceptors/FlagSetsFilter.java +++ b/client/src/main/java/io/split/client/interceptors/FlagSetsFilter.java @@ -4,6 +4,6 @@ public interface FlagSetsFilter { - boolean Intersect(Set sets); - boolean Intersect(String set); + boolean intersect(Set sets); + boolean intersect(String set); } \ No newline at end of file diff --git a/client/src/main/java/io/split/client/interceptors/FlagSetsFilterImpl.java b/client/src/main/java/io/split/client/interceptors/FlagSetsFilterImpl.java index ff6178958..e97da9f6c 100644 --- a/client/src/main/java/io/split/client/interceptors/FlagSetsFilterImpl.java +++ b/client/src/main/java/io/split/client/interceptors/FlagSetsFilterImpl.java @@ -12,7 +12,7 @@ public FlagSetsFilterImpl(Set flagSets) { _flagSets = flagSets; } @Override - public boolean Intersect(Set sets) { + public boolean intersect(Set sets) { if (!_shouldFilter) { return true; } @@ -28,7 +28,7 @@ public boolean Intersect(Set sets) { } @Override - public boolean Intersect(String set) { + public boolean intersect(String set) { if (!_shouldFilter) { return true; } 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 497f37140..f6e4878a9 100644 --- a/client/src/main/java/io/split/client/utils/FeatureFlagProcessor.java +++ b/client/src/main/java/io/split/client/utils/FeatureFlagProcessor.java @@ -3,7 +3,6 @@ import io.split.client.dtos.Split; import io.split.client.dtos.Status; import io.split.client.interceptors.FlagSetsFilter; -import io.split.client.interceptors.FlagSetsFilterImpl; import io.split.engine.experiments.ParsedSplit; import io.split.engine.experiments.SplitParser; import org.slf4j.Logger; @@ -27,7 +26,7 @@ public static FeatureFlagsToUpdate processFeatureFlagChanges(SplitParser splitPa toRemove.add(split.name); continue; } - if (!flagSetsFilter.Intersect(split.sets)) { + if (!flagSetsFilter.intersect(split.sets)) { toRemove.add(split.name); continue; } 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 8c688fa1e..7920a6af0 100644 --- a/client/src/main/java/io/split/storages/memory/InMemoryCacheImp.java +++ b/client/src/main/java/io/split/storages/memory/InMemoryCacheImp.java @@ -190,7 +190,7 @@ private void addToFlagSets(ParsedSplit featureFlag) { return; } for (String set: sets) { - if (!_flagSetsFilter.Intersect(set)) { + if (!_flagSetsFilter.intersect(set)) { continue; } HashSet features = _flagSets.get(set); diff --git a/client/src/main/java/io/split/storages/pluggable/domain/UserPipelineWrapper.java b/client/src/main/java/io/split/storages/pluggable/domain/UserPipelineWrapper.java index d49f31507..505fe11c6 100644 --- a/client/src/main/java/io/split/storages/pluggable/domain/UserPipelineWrapper.java +++ b/client/src/main/java/io/split/storages/pluggable/domain/UserPipelineWrapper.java @@ -20,12 +20,12 @@ public UserPipelineWrapper(Pipeline pipeline) { } @Override - public List exec() { + public List exec() throws Exception { try{ return _pipeline.exec(); } catch (Exception e) { _logger.warn("Exception calling Pipeline exec", e); - return new ArrayList<>(); + throw e; } } diff --git a/client/src/test/java/io/split/client/SplitClientImplTest.java b/client/src/test/java/io/split/client/SplitClientImplTest.java index af740f982..59d5cc066 100644 --- a/client/src/test/java/io/split/client/SplitClientImplTest.java +++ b/client/src/test/java/io/split/client/SplitClientImplTest.java @@ -12,6 +12,8 @@ import io.split.client.events.NoopEventsStorageImp; 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.storages.SegmentCacheConsumer; import io.split.storages.SplitCacheConsumer; import io.split.engine.evaluator.EvaluatorImp; @@ -69,6 +71,7 @@ public class SplitClientImplTest { private static TelemetryStorage TELEMETRY_STORAGE = Mockito.mock(InMemoryTelemetryStorage.class); private SplitClientConfig config = SplitClientConfig.builder().setBlockUntilReadyTimeout(100).flagSetsFilter(new ArrayList<>( Arrays.asList("set1", "set2", "set3"))).build(); + private FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(new HashSet<>(Arrays.asList("set1", "set2", "set3"))); @Before public void updateTelemetryStorage() { @@ -96,7 +99,8 @@ public void nullKeyResultsInControl() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); assertEquals(Treatments.CONTROL, client.getTreatment(null, "test1")); @@ -124,7 +128,8 @@ public void nullTestResultsInControl() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); assertEquals(Treatments.CONTROL, client.getTreatment("adil@relateiq.com", null)); @@ -145,7 +150,8 @@ public void exceptionsResultInControl() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); assertEquals(Treatments.CONTROL, client.getTreatment("adil@relateiq.com", "test1")); @@ -175,7 +181,8 @@ public void works() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); int numKeys = 5; @@ -211,7 +218,8 @@ public void worksNullConfig() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); String randomKey = RandomStringUtils.random(10); SplitResult result = client.getTreatmentWithConfig(randomKey, test); @@ -245,7 +253,8 @@ public void worksAndHasConfig() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); int numKeys = 5; @@ -280,7 +289,8 @@ public void lastConditionIsAlwaysDefault() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); assertEquals(Treatments.OFF, client.getTreatment("pato@codigo.com", test)); @@ -318,7 +328,8 @@ public void lastConditionIsAlwaysDefaultButWithTreatment() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); SplitResult result = client.getTreatmentWithConfig("pato@codigo.com", test); @@ -352,7 +363,8 @@ public void multipleConditionsWork() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); assertEquals("on", client.getTreatment("adil@codigo.com", test)); @@ -384,7 +396,8 @@ public void killedTestAlwaysGoesToDefault() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); assertEquals(Treatments.OFF, client.getTreatment("adil@codigo.com", test)); @@ -422,7 +435,8 @@ public void killedTestAlwaysGoesToDefaultHasConfig() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); SplitResult result = client.getTreatmentWithConfig("adil@codigo.com", test); @@ -458,7 +472,8 @@ public void dependencyMatcherOn() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); assertEquals(Treatments.ON, client.getTreatment("key", parent)); @@ -491,7 +506,8 @@ public void dependencyMatcherOff() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); assertEquals(Treatments.ON, client.getTreatment("key", parent)); @@ -518,7 +534,8 @@ public void dependencyMatcherControl() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); assertEquals(Treatments.ON, client.getTreatment("key", dependent)); @@ -546,7 +563,8 @@ public void attributesWork() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); assertEquals("on", client.getTreatment("adil@codigo.com", test)); @@ -579,7 +597,8 @@ public void attributesWork2() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); assertEquals("off", client.getTreatment("adil@codigo.com", test)); @@ -613,7 +632,8 @@ public void attributesGreaterThanNegativeNumber() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); assertEquals("off", client.getTreatment("adil@codigo.com", test)); @@ -649,7 +669,8 @@ public void attributesForSets() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer ,segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer ,segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); assertEquals("off", client.getTreatment("adil@codigo.com", test)); @@ -692,7 +713,8 @@ public void labelsArePopulated() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); Map attributes = ImmutableMap.of("age", -20, "acv", "1000000"); @@ -793,7 +815,8 @@ private void trafficAllocation(String key, int trafficAllocation, int trafficAll NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); assertEquals(expected_treatment_on_or_off, client.getTreatment(key, test)); @@ -845,7 +868,8 @@ public void notInTrafficAllocationDefaultConfig() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); assertEquals(Treatments.OFF, client.getTreatment("pato@split.io", test)); @@ -887,7 +911,8 @@ public void matchingBucketingKeysWork() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); Key bad_key = new Key("adil", "aijaz"); @@ -928,7 +953,8 @@ public void matchingBucketingKeysByFlagSetWork() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); Key bad_key = new Key("adil", "aijaz"); @@ -967,7 +993,8 @@ public void matchingBucketingKeysByFlagSetsWork() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); Key bad_key = new Key("adil", "aijaz"); @@ -1003,7 +1030,8 @@ public void impressionMetadataIsPropagated() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); Map attributes = ImmutableMap.of("age", -20, "acv", "1000000"); @@ -1044,7 +1072,8 @@ public void blockUntilReadyDoesNotTimeWhenSdkIsReady() throws TimeoutException, NoopEventsStorageImp.create(), config, ready, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); client.blockUntilReady(); @@ -1064,7 +1093,8 @@ public void blockUntilReadyTimesWhenSdkIsNotReady() throws TimeoutException, Int NoopEventsStorageImp.create(), config, ready, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); client.blockUntilReady(); @@ -1083,7 +1113,8 @@ public void trackWithValidParameters() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); assertTrue(client.track("validKey", "valid_traffic_type", "valid_event")); @@ -1107,7 +1138,8 @@ public void trackWithInvalidEventTypeIds() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); Assert.assertFalse(client.track("validKey", "valid_traffic_type", "")); Assert.assertFalse(client.track("validKey", "valid_traffic_type", null)); @@ -1130,7 +1162,8 @@ public void trackWithInvalidTrafficTypeNames() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); Assert.assertFalse(client.track("validKey", "", "valid")); @@ -1150,7 +1183,8 @@ public void trackWithInvalidKeys() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); Assert.assertFalse(client.track("", "valid_traffic_type", "valid")); @@ -1180,7 +1214,8 @@ public void getTreatmentWithInvalidKeys() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); Assert.assertNotEquals(Treatments.CONTROL, client.getTreatment("valid", "split")); assertEquals(Treatments.CONTROL, client.getTreatment("", "split")); @@ -1229,7 +1264,8 @@ public void trackWithProperties() { eventClientMock, config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); HashMap properties = new HashMap<>(); @@ -1351,7 +1387,8 @@ public void clientCannotPerformActionsWhenDestroyed() throws InterruptedExceptio NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); assertEquals(Treatments.ON, client.getTreatment("valid", "split")); @@ -1390,7 +1427,8 @@ public void worksAndHasConfigTryKetTreatmentWithKey() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); int numKeys = 5; @@ -1439,7 +1477,8 @@ public void worksAndHasConfigByFlagSetTryKetTreatmentWithKey() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); int numKeys = 5; @@ -1485,7 +1524,8 @@ public void worksAndHasConfigByFlagSetsTryKetTreatmentWithKey() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); int numKeys = 5; @@ -1521,7 +1561,8 @@ public void blockUntilReadyException() throws TimeoutException, InterruptedExcep NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); client.blockUntilReady(); @@ -1549,7 +1590,8 @@ public void nullKeyResultsInControlGetTreatments() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); assertEquals(Treatments.CONTROL, client.getTreatments(null, Collections.singletonList("test1")).get("test1")); @@ -1578,7 +1620,8 @@ public void nullSplitsResultsInEmptyGetTreatments() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); assertEquals(0, client.getTreatments("key", null).size()); @@ -1599,7 +1642,8 @@ public void exceptionsResultInControlGetTreatments() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); Map result = client.getTreatments("adil@relateiq.com", Arrays.asList("test1", "test2")); assertEquals(2, result.values().size()); @@ -1631,7 +1675,8 @@ public void getTreatmentsWorks() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); Map result = client.getTreatments("randomKey", Arrays.asList(test, "test2")); assertEquals("on", result.get(test)); @@ -1660,7 +1705,8 @@ public void emptySplitsResultsInNullGetTreatments() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); Map result = client.getTreatments("key", new ArrayList<>()); assertNotNull(result); @@ -1683,7 +1729,8 @@ public void exceptionsResultInControlTreatments() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); Map result = client.getTreatments("adil@relateiq.com", Arrays.asList("test1")); assertEquals(1, result.size()); @@ -1719,7 +1766,8 @@ public void worksTreatments() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); Map result = client.getTreatments("anyKey", Arrays.asList(test, test2)); assertNotNull(result); @@ -1755,7 +1803,8 @@ public void worksOneControlTreatments() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); Map result = client.getTreatments("anyKey", Arrays.asList(test, test2)); @@ -1798,7 +1847,8 @@ public void treatmentsWorksAndHasConfig() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); Map attributes = new HashMap<>(); Map result = client.getTreatmentsWithConfig("randomKey", Arrays.asList(test, test2, "", null), attributes); @@ -1839,7 +1889,8 @@ public void testTreatmentsByFlagSet() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); int numKeys = 5; @@ -1876,7 +1927,8 @@ public void testTreatmentsByFlagSetInvalid() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); assertTrue(client.getTreatmentsByFlagSet(RandomStringUtils.random(10), "", null).isEmpty()); } @@ -1918,7 +1970,8 @@ public void testTreatmentsByFlagSets() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); int numKeys = 5; Map getTreatmentResult; @@ -1969,7 +2022,8 @@ public void treatmentsWorksAndHasConfigFlagSet() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); Map attributes = new HashMap<>(); Map result = client.getTreatmentsWithConfigByFlagSet("randomKey", "set1", attributes); @@ -2018,7 +2072,8 @@ public void treatmentsWorksAndHasConfigFlagSets() { NoopEventsStorageImp.create(), config, gates, - new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE + new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE, + flagSetsFilter ); Map attributes = new HashMap<>(); Map result = client.getTreatmentsWithConfigByFlagSets("randomKey", new ArrayList<>(Arrays.asList("set1")), attributes); diff --git a/client/src/test/java/io/split/client/interceptors/FlagSetsFilterImplTest.java b/client/src/test/java/io/split/client/interceptors/FlagSetsFilterImplTest.java index c9f4b384d..c0467e298 100644 --- a/client/src/test/java/io/split/client/interceptors/FlagSetsFilterImplTest.java +++ b/client/src/test/java/io/split/client/interceptors/FlagSetsFilterImplTest.java @@ -11,16 +11,16 @@ public class FlagSetsFilterImplTest { @Test public void testIntersectSetsWithShouldFilter() { FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(new HashSet<>(Arrays.asList("a", "b"))); - Assert.assertTrue(flagSetsFilter.Intersect("a")); - Assert.assertTrue(flagSetsFilter.Intersect(new HashSet<>(Arrays.asList("a", "c")))); - Assert.assertFalse(flagSetsFilter.Intersect("c")); - Assert.assertFalse(flagSetsFilter.Intersect(new HashSet<>(Arrays.asList("d", "c")))); + Assert.assertTrue(flagSetsFilter.intersect("a")); + Assert.assertTrue(flagSetsFilter.intersect(new HashSet<>(Arrays.asList("a", "c")))); + Assert.assertFalse(flagSetsFilter.intersect("c")); + Assert.assertFalse(flagSetsFilter.intersect(new HashSet<>(Arrays.asList("d", "c")))); } @Test public void testIntersectSetsWithShouldNotFilter() { FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(new HashSet<>()); - Assert.assertTrue(flagSetsFilter.Intersect("a")); - Assert.assertTrue(flagSetsFilter.Intersect(new HashSet<>(Arrays.asList("a", "c")))); + Assert.assertTrue(flagSetsFilter.intersect("a")); + Assert.assertTrue(flagSetsFilter.intersect(new HashSet<>(Arrays.asList("a", "c")))); } } \ No newline at end of file From 6c9aecb9435f5c10e2ab9c33586fe64da313abb2 Mon Sep 17 00:00:00 2001 From: nmayorsplit <104373752+nmayorsplit@users.noreply.github.com> Date: Wed, 1 Nov 2023 18:21:47 -0300 Subject: [PATCH 2/2] Update client/src/main/java/io/split/client/SplitFactoryImpl.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Gastón Thea --- client/src/main/java/io/split/client/SplitFactoryImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/main/java/io/split/client/SplitFactoryImpl.java b/client/src/main/java/io/split/client/SplitFactoryImpl.java index c4bbf84ae..aab089b69 100644 --- a/client/src/main/java/io/split/client/SplitFactoryImpl.java +++ b/client/src/main/java/io/split/client/SplitFactoryImpl.java @@ -322,7 +322,7 @@ protected SplitFactoryImpl(String apiToken, SplitClientConfig config, CustomStor Synchronizer synchronizer = new ConsumerSynchronizer(splitTasks); FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(new HashSet<>()); if(!config.getSetsFilter().isEmpty()) { - _log.warn("FlagSets filter is not applicable for Consumer modes where the SDK does keep rollout data in sync. FlagSet " + + _log.warn("FlagSets filter is not applicable for Consumer modes where the SDK does not keep rollout data in sync. FlagSet " + "filter was discarded"); } _client = new SplitClientImpl(this,