diff --git a/client/src/main/java/io/split/client/SplitClientConfig.java b/client/src/main/java/io/split/client/SplitClientConfig.java index 6cb9632a..5c8c9c36 100644 --- a/client/src/main/java/io/split/client/SplitClientConfig.java +++ b/client/src/main/java/io/split/client/SplitClientConfig.java @@ -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); } @@ -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); @@ -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); } @@ -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"); @@ -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"); } @@ -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) { diff --git a/client/src/main/java/io/split/client/SplitFactoryImpl.java b/client/src/main/java/io/split/client/SplitFactoryImpl.java index 8a134826..e43d1404 100644 --- a/client/src/main/java/io/split/client/SplitFactoryImpl.java +++ b/client/src/main/java/io/split/client/SplitFactoryImpl.java @@ -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; @@ -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."; @@ -519,7 +517,7 @@ protected static SplitHttpClient buildSplitHttpClient(String apiToken, SplitClie logging.setLevel(HttpLoggingInterceptor.Level.NONE); } - Map kerberosOptions = new HashMap(); + Map kerberosOptions = new HashMap<>(); kerberosOptions.put("com.sun.security.auth.module.Krb5LoginModule", "required"); kerberosOptions.put("refreshKrb5Config", "false"); kerberosOptions.put("doNotPrompt", "false"); diff --git a/client/src/main/java/io/split/service/HTTPKerberosAuthInterceptor.java b/client/src/main/java/io/split/service/HTTPKerberosAuthInterceptor.java index bbe6448b..a11f9db9 100644 --- a/client/src/main/java/io/split/service/HTTPKerberosAuthInterceptor.java +++ b/client/src/main/java/io/split/service/HTTPKerberosAuthInterceptor.java @@ -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; @@ -54,7 +53,7 @@ public HTTPKerberosAuthInterceptor(String host, Map krbOptions) t * Login Module to be used for authentication. * */ - static private class KerberosLoginConfiguration extends Configuration { + private static class KerberosLoginConfiguration extends Configuration { Map krbOptions = null; public KerberosLoginConfiguration() {} @@ -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; } @@ -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; diff --git a/client/src/test/java/io/split/client/SplitFactoryImplTest.java b/client/src/test/java/io/split/client/SplitFactoryImplTest.java index 5cd96547..85defb82 100644 --- a/client/src/test/java/io/split/client/SplitFactoryImplTest.java +++ b/client/src/test/java/io/split/client/SplitFactoryImplTest.java @@ -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; @@ -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) @@ -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); } } \ No newline at end of file