Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilal Al committed Aug 30, 2024
1 parent fe52d1c commit f0e9d22
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 49 deletions.
79 changes: 43 additions & 36 deletions client/src/main/java/io/split/client/SplitClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ public Builder threadFactory(ThreadFactory threadFactory) {
return this;
}

public SplitClientConfig build() {
private void verifyRates() {
if (_featuresRefreshRate < 5 ) {
throw new IllegalArgumentException("featuresRefreshRate must be >= 5: " + _featuresRefreshRate);
}
Expand All @@ -1015,6 +1015,47 @@ public SplitClientConfig build() {
throw new IllegalArgumentException("segmentsRefreshRate must be >= 30: " + _segmentsRefreshRate);
}

if (_eventSendIntervalInMillis < 1000) {
throw new IllegalArgumentException("_eventSendIntervalInMillis must be >= 1000: " + _eventSendIntervalInMillis);
}

if (_metricsRefreshRate < 30) {
throw new IllegalArgumentException("metricsRefreshRate must be >= 30: " + _metricsRefreshRate);
}
if(_telemetryRefreshRate < 60) {
throw new IllegalStateException("_telemetryRefreshRate must be >= 60");
}
}

private void verifyEndPoints() {
if (_endpoint == null) {
throw new IllegalArgumentException("endpoint must not be null");
}

if (_eventsEndpoint == null) {
throw new IllegalArgumentException("events endpoint must not be null");
}

if (_endpointSet && !_eventsEndpointSet) {
throw new IllegalArgumentException("If endpoint is set, you must also set the events endpoint");
}

if (_authServiceURL == null) {
throw new IllegalArgumentException("authServiceURL must not be null");
}

if (_streamingServiceURL == null) {
throw new IllegalArgumentException("streamingServiceURL must not be null");
}

if (_telemetryURl == null) {
throw new IllegalArgumentException("telemetryURl must not be null");
}
}

public SplitClientConfig build() {
verifyRates();

switch (_impressionsMode) {
case OPTIMIZED:
_impressionsRefreshRate = (_impressionsRefreshRate <= 0) ? 300 : Math.max(60, _impressionsRefreshRate);
Expand All @@ -1024,14 +1065,6 @@ public SplitClientConfig build() {
break;
}

if (_eventSendIntervalInMillis < 1000) {
throw new IllegalArgumentException("_eventSendIntervalInMillis must be >= 1000: " + _eventSendIntervalInMillis);
}

if (_metricsRefreshRate < 30) {
throw new IllegalArgumentException("metricsRefreshRate must be >= 30: " + _metricsRefreshRate);
}

if (_impressionsQueueSize <=0 ) {
throw new IllegalArgumentException("impressionsQueueSize must be > 0: " + _impressionsQueueSize);
}
Expand All @@ -1044,17 +1077,7 @@ public SplitClientConfig build() {
throw new IllegalArgumentException("readTimeout must be > 0: " + _readTimeout);
}

if (_endpoint == null) {
throw new IllegalArgumentException("endpoint must not be null");
}

if (_eventsEndpoint == null) {
throw new IllegalArgumentException("events endpoint must not be null");
}

if (_endpointSet && !_eventsEndpointSet) {
throw new IllegalArgumentException("If endpoint is set, you must also set the events endpoint");
}
verifyEndPoints();

if (_numThreadsForSegmentFetch <= 0) {
throw new IllegalArgumentException("Number of threads for fetching segments MUST be greater than zero");
Expand All @@ -1068,18 +1091,6 @@ public SplitClientConfig build() {
throw new IllegalArgumentException("streamingReconnectBackoffBase: must be >= 1");
}

if (_authServiceURL == null) {
throw new IllegalArgumentException("authServiceURL must not be null");
}

if (_streamingServiceURL == null) {
throw new IllegalArgumentException("streamingServiceURL must not be null");
}

if (_telemetryURl == null) {
throw new IllegalArgumentException("telemetryURl must not be null");
}

if (_onDemandFetchRetryDelayMs <= 0) {
throw new IllegalStateException("streamingRetryDelay must be > 0");
}
Expand All @@ -1091,10 +1102,6 @@ public SplitClientConfig build() {
if(_storageMode == null) {
_storageMode = StorageMode.MEMORY;
}

if(_telemetryRefreshRate < 60) {
throw new IllegalStateException("_telemetryRefreshRate must be >= 60");
}

if(OperationMode.CONSUMER.equals(_operationMode)){
if(_customStorageWrapper == null) {
Expand Down
6 changes: 2 additions & 4 deletions client/src/main/java/io/split/client/SplitFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,9 @@
import pluggable.CustomStorageWrapper;

import okhttp3.Authenticator;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.OkHttpClient.Builder;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Logger;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -134,7 +132,7 @@
import static io.split.client.utils.SplitExecutorFactory.buildExecutorService;

public class SplitFactoryImpl implements SplitFactory {
private static final org.slf4j.Logger _log = LoggerFactory.getLogger(SplitFactory.class);
private static final org.slf4j.Logger _log = LoggerFactory.getLogger(SplitFactoryImpl.class);
private static final String LEGACY_LOG_MESSAGE = "The sdk initialize in localhost mode using Legacy file. The splitFile or "
+
"inputStream doesn't add it to the config.";
Expand Down Expand Up @@ -519,7 +517,7 @@ protected static SplitHttpClient buildSplitHttpClient(String apiToken, SplitClie
logging.setLevel(HttpLoggingInterceptor.Level.NONE);
}

Map<String, String> kerberosOptions = new HashMap<String, String>();
Map<String, String> kerberosOptions = new HashMap<>();
kerberosOptions.put("com.sun.security.auth.module.Krb5LoginModule", "required");
kerberosOptions.put("refreshKrb5Config", "false");
kerberosOptions.put("doNotPrompt", "false");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.ietf.jgss.GSSName;
import org.ietf.jgss.Oid;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.Authenticator;
Expand Down Expand Up @@ -54,7 +53,7 @@ public HTTPKerberosAuthInterceptor(String host, Map<String,String> krbOptions) t
* Login Module to be used for authentication.
*
*/
static private class KerberosLoginConfiguration extends Configuration {
private static class KerberosLoginConfiguration extends Configuration {
Map<String,String> krbOptions = null;

public KerberosLoginConfiguration() {}
Expand Down Expand Up @@ -147,7 +146,7 @@ private String buildAuthorizationHeader(String serverPrincipalName) throws Login
if (privateCred instanceof KerberosTicket) {
String serverPrincipalTicketName = ((KerberosTicket) privateCred).getServer().getName();
if ((serverPrincipalTicketName.startsWith("krbtgt"))
&& ((KerberosTicket) privateCred).getEndTime().compareTo(new Date()) == -1) {
&& ((KerberosTicket) privateCred).getEndTime().compareTo(new Date()) < 0) {
buildSubjectCredentials();
break;
}
Expand Down Expand Up @@ -176,7 +175,8 @@ private static class CreateAuthorizationHeaderAction implements PrivilegedAction
String clientPrincipalName;
String serverPrincipalName;

private StringBuffer outputToken = new StringBuffer();
// private StringBuffer outputToken = new StringBuffer();
private StringBuilder outputToken = new StringBuilder();

private CreateAuthorizationHeaderAction(final String clientPrincipalName, final String serverPrincipalName) {
this.clientPrincipalName = clientPrincipalName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,17 @@
import org.mockito.BDDMockito;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import pluggable.CustomStorageWrapper;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URISyntaxException;
import java.util.HashMap;
Expand All @@ -42,7 +39,6 @@
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;

import static io.split.client.SplitClientConfig.splitSdkVersion;
import static org.mockito.Mockito.when;

@RunWith(PowerMockRunner.class)
Expand Down Expand Up @@ -411,7 +407,7 @@ public void testFactoryKerberosInstance() throws NoSuchMethodException, Invocati
SplitFactoryImpl.buildOkHttpClient(proxyCaptor.capture(), configCaptor.capture(),logCaptor.capture(), authCaptor.capture());

Assert.assertTrue(splitHttpClient instanceof SplitHttpClientKerberosImpl);
Assert.assertEquals(proxyCaptor.getValue().toString(), "HTTP @ https://sdk.split-stage.io:6060");
Assert.assertEquals("HTTP @ https://sdk.split-stage.io:6060", proxyCaptor.getValue().toString());
Assert.assertTrue(logCaptor.getValue() instanceof okhttp3.logging.HttpLoggingInterceptor);
}
}

0 comments on commit f0e9d22

Please sign in to comment.