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
11 changes: 5 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ plugins {
id 'jacoco-report-aggregation'
id "com.github.spotbugs" version libs.versions.spotbugs
id "org.owasp.dependencycheck" version libs.versions.depcheck
id 'me.champeau.jmh' version '0.6.8' // Added JMH plugin
id "com.vanniktech.maven.publish" version "0.33.0"
id "com.vanniktech.maven.publish" version libs.versions.maven.publish
}


Expand Down Expand Up @@ -57,10 +56,6 @@ dependencies {

compileOnly libs.lombok
annotationProcessor libs.lombok

// JMH dependencies
implementation 'org.openjdk.jmh:jmh-core:1.37'
annotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:1.37'
}

group = 'io.harness'
Expand Down Expand Up @@ -113,6 +108,10 @@ testing {
implementation libs.okhttp3.mockwebserver
compileOnly libs.lombok
annotationProcessor libs.lombok

// JMH dependencies
implementation libs.jmh.core
annotationProcessor libs.jmh.annotations
}

targets {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-rc-3-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
12 changes: 8 additions & 4 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dependencyResolutionManagement {
versionCatalogs {
libs {
// main sdk version
version('sdk', '1.8.3');
version('sdk', '1.9.0-SNAPSHOT');

// sdk deps
version('okhttp3', '4.12.0')
Expand All @@ -17,7 +17,7 @@ dependencyResolutionManagement {
library('swagger-annotations', 'io.swagger:swagger-annotations:1.6.2')
library('javax-annotation-api', 'javax.annotation:javax.annotation-api:1.2')
library('slf4j-api', 'org.slf4j:slf4j-api:1.7.36')
library('lombok', 'org.projectlombok:lombok:1.18.30')
library('lombok', 'org.projectlombok:lombok:1.18.38')
library('google-findbugs', 'com.google.code.findbugs:jsr305:3.0.2')

// test libs
Expand All @@ -26,6 +26,9 @@ dependencyResolutionManagement {
library('junit-bom', 'org.junit:junit-bom:5.10.1')
library('mockito-junit5', 'org.mockito:mockito-junit-jupiter:4.8.1')
library('okhttp3-mockwebserver', 'com.squareup.okhttp3', 'mockwebserver').versionRef('okhttp3')
version('jmh', '1.37')
library('jmh-core', 'org.openjdk.jmh', 'jmh-core').versionRef('jmh')
library('jmh-annotations', 'org.openjdk.jmh', 'jmh-generator-annprocess').versionRef('jmh')

// examples
library('bc', 'org.bouncycastle:bcpkix-jdk18on:1.78.1')
Expand All @@ -35,10 +38,11 @@ dependencyResolutionManagement {
// do not upgrade openapi, doing so will break compatibility with customers using SpringBoot 2.5.x
// (newer 5.x.x generators use APIs not present in okhttp 3.14.9)
version('openapi.generator', '4.3.1')
version('spotless', '6.23.3')
version('spotless', '7.1.0')
version('depsize', '0.2.0')
version('spotbugs', '6.0.4')
version('spotbugs', '6.1.5')
version('depcheck', '9.0.7')
version('maven.publish', '0.33.0')
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/harness/cf/client/api/PollingProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public CompletableFuture<List<Segment>> retrieveSegments() {
completableFuture.complete(segments);
} catch (Throwable e) {
log.error(
"Exception was raised when fetching segments data with the message {}", e.getMessage(), e);
"Exception was raised when fetching segments data with the message {}",
e.getMessage(),
e);
completableFuture.completeExceptionally(e);
}
return completableFuture;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
package io.harness.cf.client.connector;

import javax.net.SocketFactory;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import javax.net.SocketFactory;

final class DelegatingSocketFactory extends SocketFactory {
private final SocketFactory delegate;

public DelegatingSocketFactory(SocketFactory delegate) {
this.delegate = delegate;
}

@Override
public Socket createSocket() throws IOException {
return configureSocket(delegate.createSocket());
}

@Override
public Socket createSocket(String host, int port) throws IOException {
return configureSocket(delegate.createSocket(host, port));
}

@Override
public Socket createSocket(String host, int port, InetAddress localAddress,
int localPort) throws IOException {
return configureSocket(delegate.createSocket(host, port, localAddress, localPort));
}

@Override
public Socket createSocket(InetAddress host, int port) throws IOException {
return configureSocket(delegate.createSocket(host, port));
}

@Override
public Socket createSocket(InetAddress host, int port, InetAddress localAddress,
int localPort) throws IOException {
return configureSocket(delegate.createSocket(host, port, localAddress, localPort));
}

Socket configureSocket(Socket socket) {
return socket;
}
}
private final SocketFactory delegate;

public DelegatingSocketFactory(SocketFactory delegate) {
this.delegate = delegate;
}

@Override
public Socket createSocket() throws IOException {
return configureSocket(delegate.createSocket());
}

@Override
public Socket createSocket(String host, int port) throws IOException {
return configureSocket(delegate.createSocket(host, port));
}

@Override
public Socket createSocket(String host, int port, InetAddress localAddress, int localPort)
throws IOException {
return configureSocket(delegate.createSocket(host, port, localAddress, localPort));
}

@Override
public Socket createSocket(InetAddress host, int port) throws IOException {
return configureSocket(delegate.createSocket(host, port));
}

@Override
public Socket createSocket(InetAddress host, int port, InetAddress localAddress, int localPort)
throws IOException {
return configureSocket(delegate.createSocket(host, port, localAddress, localPort));
}

Socket configureSocket(Socket socket) {
return socket;
}
}
18 changes: 10 additions & 8 deletions src/main/java/io/harness/cf/client/connector/HarnessConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,20 @@ ApiClient makeApiClient(int retryBackOfDelay) {

setupTls(apiClient);

final OkHttpClient.Builder builder = apiClient
.getHttpClient()
.newBuilder();
final OkHttpClient.Builder builder = apiClient.getHttpClient().newBuilder();

ProxyConfig.configureTls(builder);

// if http client response is 403 we need to reauthenticate
apiClient.setHttpClient(builder.proxy(ProxyConfig.getProxyConfig())
.proxyAuthenticator(ProxyConfig.getProxyAuthentication())
.addInterceptor(this::reauthInterceptor)
.addInterceptor(new NewRetryInterceptor(options.getMaxRequestRetry(), retryBackOfDelay, isShuttingDown))
.build());
apiClient.setHttpClient(
builder
.proxy(ProxyConfig.getProxyConfig())
.proxyAuthenticator(ProxyConfig.getProxyAuthentication())
.addInterceptor(this::reauthInterceptor)
.addInterceptor(
new NewRetryInterceptor(
options.getMaxRequestRetry(), retryBackOfDelay, isShuttingDown))
.build());

return apiClient;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ int getRetryAfterHeaderInSeconds(Response response) {
seconds = (int) Duration.between(Instant.now(), then.toInstant()).getSeconds();
}
} catch (ParseException ignored) {
log.warn("Unable to parse Retry-After header value: `{}` as integer or date", retryAfterValue);
log.warn(
"Unable to parse Retry-After header value: `{}` as integer or date", retryAfterValue);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import java.net.InetSocketAddress;
import java.net.Proxy;
import javax.net.ssl.SSLSocketFactory;
import lombok.extern.slf4j.Slf4j;
import okhttp3.Authenticator;
import okhttp3.Credentials;
import okhttp3.OkHttpClient;

import javax.net.ssl.SSLSocketFactory;

@Slf4j
public class ProxyConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public List<DynamicTest> getTestCases() throws Exception {

assertTrue(
testCasesDirectory.exists(),
"ff-test-cases folder missing - please check 'git submodule init' has been run");
"ff-test-cases folder missing - please check 'git submodule update --init' has been run");

try (Stream<Path> pathStream = Files.walk(Paths.get(testCasesBasePath))) {
pathStream
Expand Down
20 changes: 10 additions & 10 deletions src/test/java/io/harness/cf/client/api/StorageRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void shouldStoreCurrentConfig() throws Exception {
assertNotNull(current);

// check if the current version is correct
assertEquals(current.getVersion(), new Long(2));
assertEquals(current.getVersion(), 2L);
}

@Test
Expand Down Expand Up @@ -84,7 +84,7 @@ void shouldStoreCurrentConfigWithFileStore() throws Exception {
assertNotNull(current);

// check if the current version is correct
assertEquals(current.getVersion(), new Long(2));
assertEquals(current.getVersion(), 2L);
}

@Test
Expand Down Expand Up @@ -118,8 +118,8 @@ void shouldStorePreviousAndCurrentConfigWithFileStore() throws Exception {
assertNotNull(current);

// check if the current version is correct
assertEquals(previous.getVersion(), new Long(1));
assertEquals(current.getVersion(), new Long(2));
assertEquals(previous.getVersion(), 1L);
assertEquals(current.getVersion(), 2L);
}

@Test
Expand All @@ -146,8 +146,8 @@ void shouldStorePreviousAndCurrentConfig() throws Exception {
assertNotNull(current);

// check if the current version is correct
assertEquals(previous.getVersion(), new Long(1));
assertEquals(current.getVersion(), new Long(2));
assertEquals(previous.getVersion(), 1L);
assertEquals(current.getVersion(), 2L);
}

@Test
Expand Down Expand Up @@ -176,8 +176,8 @@ void shouldDeletePreviousAndCurrentConfig() throws Exception {
assertNotNull(current);

// check if the current version is correct
assertEquals(previous.getVersion(), new Long(1));
assertEquals(current.getVersion(), new Long(2));
assertEquals(previous.getVersion(), 1L);
assertEquals(current.getVersion(), 2L);

// delete config
repository.deleteFlag(featureIdentifier);
Expand Down Expand Up @@ -233,7 +233,7 @@ private List<FeatureConfig> makeFeatureList(FeatureConfig fc) {

private FeatureConfig GetUpdatedFeatureConfigFromFile() throws Exception {
FeatureConfig fc = GetFeatureConfigFromFile();
fc.setVersion(new Long(2));
fc.setVersion(2L);
return fc;
}

Expand Down Expand Up @@ -262,7 +262,7 @@ private List<FeatureConfig> createBenchmarkData(int flagNumber, int version) thr
for (int i = 1; i <= flagNumber; i++) {
FeatureConfig f = fg;
f.setFeature("simpleBool" + i);
f.setVersion(new Long(version));
f.setVersion((long) version);
list.add(f);
}
// System.out.println(list);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/harness/cf/client/api/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public List<FeatureConfig> CreateBenchmarkData(int size, int version) throws Exc
for (int i = 1; i <= size; i++) {
FeatureConfig f = fg;
f.setFeature("simpleBool" + i);
f.setVersion(new Long(version));
f.setVersion((long) version);
// we are copying objects
FeatureConfig df = gson.fromJson(gson.toJson(f), FeatureConfig.class);
list.add(df);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public MockResponse dispatch(@NotNull RecordedRequest recordedRequest) {
case SIMPLE_BOOL_FLAG_ENDPOINT:
assertHeaders(recordedRequest);
return makeMockSingleBoolFlagResponse(200, "simplebool", "off", version.get());
// TODO add metrics here
// TODO add metrics here
default:
throw new UnsupportedOperationException(
"ERROR: url not mapped " + recordedRequest.getPath());
Expand Down
Loading