Skip to content

Commit

Permalink
[SDKS-7514] Add flagSetFilter config
Browse files Browse the repository at this point in the history
  • Loading branch information
nmayorsplit committed Sep 6, 2023
1 parent d439f75 commit 9ff43e0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
25 changes: 23 additions & 2 deletions client/src/main/java/io/split/client/SplitClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pluggable.CustomStorageWrapper;

import java.io.IOException;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.ThreadFactory;

Expand Down Expand Up @@ -80,6 +81,7 @@ public class SplitClientConfig {
// To be set during startup
public static String splitSdkVersion;
private final long _lastSeenCacheSize;
private final List<String> _flagSetsFilter;


public static Builder builder() {
Expand Down Expand Up @@ -133,7 +135,8 @@ private SplitClientConfig(String endpoint,
int uniqueKeysRefreshRateRedis,
int filterUniqueKeysRefreshRate,
long lastSeenCacheSize,
ThreadFactory threadFactory) {
ThreadFactory threadFactory,
List<String> flagSetsFilter) {
_endpoint = endpoint;
_eventsEndpoint = eventsEndpoint;
_featuresRefreshRate = pollForFeatureChangesEveryNSeconds;
Expand Down Expand Up @@ -182,6 +185,7 @@ private SplitClientConfig(String endpoint,
_customStorageWrapper = customStorageWrapper;
_lastSeenCacheSize = lastSeenCacheSize;
_threadFactory = threadFactory;
_flagSetsFilter = flagSetsFilter;


Properties props = new Properties();
Expand Down Expand Up @@ -363,6 +367,9 @@ public long getLastSeenCacheSize() {
public ThreadFactory getThreadFactory() {
return _threadFactory;
}
public List<String> getSetsFilter() {
return _flagSetsFilter;
}

public static final class Builder {

Expand Down Expand Up @@ -417,6 +424,7 @@ public static final class Builder {
private StorageMode _storageMode = StorageMode.MEMORY;
private final long _lastSeenCacheSize = 500000;
private ThreadFactory _threadFactory;
private List<String> _flagSetsFilter = null;

public Builder() {
}
Expand Down Expand Up @@ -882,6 +890,18 @@ public Builder customStorageWrapper(CustomStorageWrapper customStorageWrapper) {
return this;
}

/**
* Flag Sets Filter
*
* @param flagSetsFilter
* @return this builder
*/
public Builder flagSetsFilter(List<String> flagSetsFilter) {
_flagSetsFilter = flagSetsFilter;
//TODO Apply validations
return this;
}

public SplitClientConfig build() {
if (_featuresRefreshRate < 5 ) {
throw new IllegalArgumentException("featuresRefreshRate must be >= 5: " + _featuresRefreshRate);
Expand Down Expand Up @@ -1027,7 +1047,8 @@ public SplitClientConfig build() {
_uniqueKeysRefreshRateRedis,
_filterUniqueKeysRefreshRate,
_lastSeenCacheSize,
_threadFactory);
_threadFactory,
_flagSetsFilter);
}
}
}
15 changes: 14 additions & 1 deletion client/src/test/java/io/split/client/SplitClientConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import org.junit.Assert;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -182,9 +187,17 @@ public void streamingReconnectBackoffBaseAllowed() {
}

@Test
public void checkDefaultRateForFeatureAndSegment(){
public void checkDefaultRateForFeatureAndSegment() {
SplitClientConfig config = SplitClientConfig.builder().build();
Assert.assertEquals(60, config.featuresRefreshRate());
Assert.assertEquals(60, config.segmentsRefreshRate());
}

@Test
public void checkSetFlagSetsFilter() {
List<String> sets = Stream.of("test1", "test2").collect(Collectors.toList());
SplitClientConfig config = SplitClientConfig.builder().flagSetsFilter(sets).build();
Assert.assertNotNull(config.getSetsFilter());
Assert.assertEquals(2, config.getSetsFilter().size());
}
}

0 comments on commit 9ff43e0

Please sign in to comment.