Skip to content

Commit

Permalink
Merge pull request #451 from splitio/SDKS-7676
Browse files Browse the repository at this point in the history
[SDKS-7676] Add ThreadFactory in the config builder
  • Loading branch information
nmayorsplit authored Oct 27, 2023
2 parents 7c16859 + 7bd580b commit fb66059
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 26 deletions.
11 changes: 11 additions & 0 deletions client/src/main/java/io/split/client/SplitClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,17 @@ public Builder customStorageWrapper(CustomStorageWrapper customStorageWrapper) {
return this;
}

/**
* Thread Factory
*
* @param threadFactory
* @return this builder
*/
public Builder threadFactory(ThreadFactory threadFactory) {
_threadFactory = threadFactory;
return this;
}

public SplitClientConfig build() {
if (_featuresRefreshRate < 5 ) {
throw new IllegalArgumentException("featuresRefreshRate must be >= 5: " + _featuresRefreshRate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public synchronized boolean track(String featureFlagName, String key) {
}
value.add(key);
uniqueKeysTracker.put(featureFlagName, value);
_logger.debug("The feature flag" + featureFlagName + " and key " + key + " was added");
_logger.debug("The feature flag " + featureFlagName + " and key " + key + " was added");
if (uniqueKeysTracker.size() == MAX_AMOUNT_OF_TRACKED_UNIQUE_KEYS){
_logger.warn("The UniqueKeysTracker size reached the maximum limit");
try {
Expand Down
65 changes: 40 additions & 25 deletions client/src/test/java/io/split/client/SplitClientConfigTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.split.client;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import io.split.client.impressions.Impression;
import io.split.client.impressions.ImpressionListener;
import io.split.client.impressions.ImpressionsManager;
import io.split.integrations.IntegrationsConfig;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -15,14 +15,14 @@
public class SplitClientConfigTest {

@Test(expected = IllegalArgumentException.class)
public void cannot_set_feature_refresh_rate_to_less_than_5() {
public void cannotSetFeatureRefreshRateToLessThan5() {
SplitClientConfig.builder()
.featuresRefreshRate(4)
.build();
}

@Test(expected = IllegalArgumentException.class)
public void cannot_set_segment_refresh_rate_to_less_than_30() {
public void cannotSetSegmentRefreshRateToLessThan30() {
SplitClientConfig.builder()
.segmentsRefreshRate(29)
.build();
Expand Down Expand Up @@ -77,58 +77,62 @@ public void testImpressionRefreshRateConstraints() {
}

@Test
public void set_impression_refresh_rate_works() {
SplitClientConfig.builder()
.impressionsRefreshRate(1)
public void setImpressionRefreshRateWorks() {
SplitClientConfig config = SplitClientConfig.builder()
.impressionsRefreshRate(65)
.build();
Assert.assertEquals(65, config.impressionsRefreshRate());
}

@Test(expected = IllegalArgumentException.class)
public void cannot_set_events_flush_rate_to_equal_to_1000() {
public void cannotSetEventsFlushRateToEqualTo1000() {
SplitClientConfig.builder()
.eventFlushIntervalInMillis(999)
.build();
}

@Test
public void events_flush_rate_works() {
SplitClientConfig.builder()
public void eventsFlushRateWorks() {
SplitClientConfig config = SplitClientConfig.builder()
.eventFlushIntervalInMillis(1000)
.build();
Assert.assertEquals(1000, config.eventSendIntervalInMillis());
}

@Test(expected = IllegalArgumentException.class)
public void cannot_set_metrics_refresh_rate_to_less_than_30() {
public void cannotSetMetricsRefreshRateToLessThan30() {
SplitClientConfig.builder()
.metricsRefreshRate(29)
.build();
}

@Test
public void can_set_refresh_rates_to__30() {
SplitClientConfig.builder()
public void canSetRefreshRatesTo30() {
SplitClientConfig cfg = SplitClientConfig.builder()
.featuresRefreshRate(30)
.segmentsRefreshRate(30)
.impressionsRefreshRate(30)
.metricsRefreshRate(30)
.impressionsRefreshRate(65)
.metricsRefreshRate(65)
.build();
Assert.assertEquals(30, cfg.featuresRefreshRate());
Assert.assertEquals(30, cfg.segmentsRefreshRate());
Assert.assertEquals(65, cfg.impressionsRefreshRate());
Assert.assertEquals(65, cfg.metricsRefreshRate());
}

@Test
public void config_does_not_crash_if_new_relic_class_not_present() {
public void configDoesNotCrashIfNewRelicClassNotPresent() {
SplitClientConfig cfg = SplitClientConfig.builder()
.integrations(IntegrationsConfig.builder()
.newRelicImpressionListener()
.build())
.build();

Assert.assertThat(
cfg.integrationsConfig().getImpressionsListeners(IntegrationsConfig.Execution.SYNC).size(),
is(equalTo(0)));
Assert.assertEquals(0, cfg.integrationsConfig().getImpressionsListeners(IntegrationsConfig.Execution.SYNC).size());
}

@Test
public void old_impression_listener_config_still_works() {
public void oldImpressionListenerConfigStillWorks() {
SplitClientConfig cfg = SplitClientConfig.builder()
.impressionListener(new ImpressionListener() {
@Override
Expand All @@ -139,18 +143,16 @@ public void close() { /* noop */ }
}, 1000)
.build();

Assert.assertThat(
cfg.integrationsConfig().getImpressionsListeners(IntegrationsConfig.Execution.ASYNC).size(),
is(equalTo(1)));
Assert.assertEquals(1, cfg.integrationsConfig().getImpressionsListeners(IntegrationsConfig.Execution.ASYNC).size());
}

@Test
public void testVersion() {
SplitClientConfig config = SplitClientConfig.builder()
.build();

Assert.assertThat(config.splitSdkVersion, Matchers.not(Matchers.equalTo("undefined")));
Assert.assertThat(config.splitSdkVersion, Matchers.startsWith("java-"));
Assert.assertNotEquals("undefined", config.splitSdkVersion);
Assert.assertTrue(config.splitSdkVersion.startsWith("java-"));
}

@Test(expected = IllegalArgumentException.class)
Expand Down Expand Up @@ -179,6 +181,7 @@ public void streamingReconnectBackoffBaseAllowed() {
SplitClientConfig cfg = SplitClientConfig.builder()
.streamingReconnectBackoffBase(1)
.build();
Assert.assertEquals(1, cfg.streamingReconnectBackoffBase());
}

@Test
Expand All @@ -187,4 +190,16 @@ public void checkDefaultRateForFeatureAndSegment(){
Assert.assertEquals(60, config.featuresRefreshRate());
Assert.assertEquals(60, config.segmentsRefreshRate());
}
}

@Test
public void threadFactoryNull() {
SplitClientConfig config = SplitClientConfig.builder().build();
Assert.assertNull(config.getThreadFactory());
}

@Test
public void threadFactoryNotNull() {
SplitClientConfig config = SplitClientConfig.builder().threadFactory(new ThreadFactoryBuilder().build()).build();
Assert.assertNotNull(config.getThreadFactory());
}
}

0 comments on commit fb66059

Please sign in to comment.