Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDKS-7514] Add flagSetFilter config #432

Merged
merged 3 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 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,9 @@
import pluggable.CustomStorageWrapper;

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

Expand Down Expand Up @@ -80,6 +83,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 +137,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 +187,7 @@ private SplitClientConfig(String endpoint,
_customStorageWrapper = customStorageWrapper;
_lastSeenCacheSize = lastSeenCacheSize;
_threadFactory = threadFactory;
_flagSetsFilter = flagSetsFilter;


Properties props = new Properties();
Expand Down Expand Up @@ -363,6 +369,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 +426,7 @@ public static final class Builder {
private StorageMode _storageMode = StorageMode.MEMORY;
private final long _lastSeenCacheSize = 500000;
private ThreadFactory _threadFactory;
private List<String> _flagSetsFilter = Collections.emptyList();

public Builder() {
}
Expand Down Expand Up @@ -882,6 +892,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 +1049,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());
}
}