Skip to content
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
74 changes: 72 additions & 2 deletions client/src/test/java/io/split/client/SplitClientImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;

Expand Down Expand Up @@ -234,9 +235,10 @@ public void worksAndHasConfig() {

int numKeys = 5;
for (int i = 0; i < numKeys; i++) {
Map<String, Object> attributes = new HashMap<>();
String randomKey = RandomStringUtils.random(10);
assertThat(client.getTreatment(randomKey, test), is(equalTo("on")));
assertThat(client.getTreatmentWithConfig(randomKey, test).config(), is(equalTo(configurations.get("on"))));
assertThat(client.getTreatmentWithConfig(randomKey, test, attributes).config(), is(equalTo(configurations.get("on"))));
}

// Times 2 because we are calling getTreatment twice. Once for getTreatment and one for getTreatmentWithConfig
Expand Down Expand Up @@ -972,7 +974,7 @@ public void track_with_valid_parameters() {

String validEventSize = new String(new char[80]).replace('\0', 'a');
String validKeySize = new String(new char[250]).replace('\0', 'a');
Assert.assertThat(client.track(validKeySize, "valid_traffic_type", validEventSize),
Assert.assertThat(client.track(validKeySize, "valid_traffic_type", validEventSize, 10),
org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(true)));

}
Expand Down Expand Up @@ -1286,4 +1288,72 @@ public void client_cannot_perform_actions_when_destroyed() throws InterruptedExc
Assert.assertThat(client.track("validKey", "valid_traffic_type", "valid_event"),
org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(false)));
}

@Test
public void worksAndHasConfigTryKetTreatmentWithKey() {
String test = "test1";

ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition("on", 100)));
List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone);

// Add config for only one treatment
Map<String, String> configurations = new HashMap<>();
configurations.put(Treatments.ON, "{\"size\" : 30}");

ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1, configurations);

SDKReadinessGates gates = mock(SDKReadinessGates.class);
SplitCache splitCache = mock(InMemoryCacheImp.class);
when(splitCache.get(test)).thenReturn(parsedSplit);

SplitClientImpl client = new SplitClientImpl(
mock(SplitFactory.class),
splitCache,
new ImpressionsManager.NoOpImpressionsManager(),
new Metrics.NoopMetrics(),
NoopEventClient.create(),
config,
gates,
new EvaluatorImp(splitCache)
);

int numKeys = 5;
for (int i = 0; i < numKeys; i++) {
Map<String, Object> attributes = new HashMap<>();
String randomKey = RandomStringUtils.random(10);
Key key = new Key(randomKey, "BucketingKey");
assertThat(client.getTreatment(randomKey, test), is(equalTo("on")));
assertThat(client.getTreatmentWithConfig(key, test, attributes).config(), is(equalTo(configurations.get("on"))));
}

// Times 2 because we are calling getTreatment twice. Once for getTreatment and one for getTreatmentWithConfig
verify(splitCache, times(numKeys * 2)).get(test);
}

@Test(expected = IllegalArgumentException.class)
public void blockUntilReadyException() throws TimeoutException, InterruptedException {
String test = "test1";

ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition("on", 100)));
List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone);
ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1);

SDKReadinessGates gates = mock(SDKReadinessGates.class);
SplitCache splitCache = mock(InMemoryCacheImp.class);
when(splitCache.get(test)).thenReturn(parsedSplit);

SplitClientConfig config = SplitClientConfig.builder().setBlockUntilReadyTimeout(-100).build();
SplitClientImpl client = new SplitClientImpl(
mock(SplitFactory.class),
splitCache,
new ImpressionsManager.NoOpImpressionsManager(),
new Metrics.NoopMetrics(),
NoopEventClient.create(),
config,
gates,
new EvaluatorImp(splitCache)
);

client.blockUntilReady();
}
}
102 changes: 102 additions & 0 deletions client/src/test/java/io/split/client/SplitFactoryImplTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package io.split.client;

import io.split.client.impressions.ImpressionsManager;
import io.split.integrations.IntegrationsConfig;
import junit.framework.TestCase;
import org.junit.Test;

import java.net.URISyntaxException;

public class SplitFactoryImplTest extends TestCase {
public static final String API_KEY ="29013ionasdasd09u";
public static final String ENDPOINT = "https://sdk.split-stage.io";
public static final String EVENTS_ENDPOINT = "https://events.split-stage.io";
public static final String AUTH_SERVICE = "https://auth.split-stage.io/api/auth";


@Test
public void testFactoryInstantiation() throws URISyntaxException {
SplitClientConfig splitClientConfig = SplitClientConfig.builder()
.enableDebug()
.impressionsMode(ImpressionsManager.Mode.DEBUG)
.impressionsRefreshRate(1)
.endpoint(ENDPOINT,EVENTS_ENDPOINT)
.authServiceURL(AUTH_SERVICE)
.setBlockUntilReadyTimeout(10000)
.build();
SplitFactoryImpl splitFactory = new SplitFactoryImpl(API_KEY, splitClientConfig);

assertNotNull(splitFactory.client());
assertNotNull(splitFactory.manager());
}

@Test
public void testFactoryInstantiationWithoutBlockUntilReady() throws URISyntaxException {
SplitClientConfig splitClientConfig = SplitClientConfig.builder()
.enableDebug()
.impressionsMode(ImpressionsManager.Mode.DEBUG)
.impressionsRefreshRate(1)
.endpoint(ENDPOINT,EVENTS_ENDPOINT)
.authServiceURL(AUTH_SERVICE)
.build();
SplitFactoryImpl splitFactory = new SplitFactoryImpl(API_KEY, splitClientConfig);

assertNotNull(splitFactory.client());
assertNotNull(splitFactory.manager());
}

@Test
public void testFactoryInstantiationIntegrationsConfig() throws URISyntaxException {
IntegrationsConfig integrationsConfig = new IntegrationsConfig.Builder().build();
SplitClientConfig splitClientConfig = SplitClientConfig.builder()
.enableDebug()
.impressionsMode(ImpressionsManager.Mode.DEBUG)
.impressionsRefreshRate(1)
.endpoint(ENDPOINT,EVENTS_ENDPOINT)
.authServiceURL(AUTH_SERVICE)
.setBlockUntilReadyTimeout(1000)
.integrations(integrationsConfig)
.build();
SplitFactoryImpl splitFactory = new SplitFactoryImpl(API_KEY, splitClientConfig);

assertNotNull(splitFactory.client());
assertNotNull(splitFactory.manager());
}

@Test
public void testFactoryInstantiationWithProxy() throws URISyntaxException {
SplitClientConfig splitClientConfig = SplitClientConfig.builder()
.enableDebug()
.impressionsMode(ImpressionsManager.Mode.DEBUG)
.impressionsRefreshRate(1)
.endpoint(ENDPOINT,EVENTS_ENDPOINT)
.authServiceURL(AUTH_SERVICE)
.setBlockUntilReadyTimeout(1000)
.proxyPort(6060)
.proxyUsername("test")
.proxyPassword("password")
.proxyHost(ENDPOINT)
.build();
SplitFactoryImpl splitFactory = new SplitFactoryImpl(API_KEY, splitClientConfig);

assertNotNull(splitFactory.client());
assertNotNull(splitFactory.manager());
}

@Test
public void testFactoryDestroy() throws URISyntaxException {
SplitClientConfig splitClientConfig = SplitClientConfig.builder()
.enableDebug()
.impressionsMode(ImpressionsManager.Mode.DEBUG)
.impressionsRefreshRate(1)
.endpoint(ENDPOINT,EVENTS_ENDPOINT)
.authServiceURL(AUTH_SERVICE)
.setBlockUntilReadyTimeout(10000)
.build();
SplitFactoryImpl splitFactory = new SplitFactoryImpl(API_KEY, splitClientConfig);
splitFactory.destroy();

assertTrue(splitFactory.isDestroyed());
}

}