Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Unleash/unleash-client-java
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v10.1.0
Choose a base ref
...
head repository: Unleash/unleash-client-java
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v10.1.1
Choose a head ref
  • 4 commits
  • 9 files changed
  • 3 contributors

Commits on Mar 5, 2025

  1. chore(pom): update to next SNAPSHOT release

    chriswk committed Mar 5, 2025

    Verified

    This commit was signed with the committer’s verified signature.
    chriswk Christopher Kolstad
    Copy the full SHA
    69c294f View commit details

Commits on Mar 10, 2025

  1. chore: apply formatting (#291)

    sighphyre authored Mar 10, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    350ee01 View commit details
  2. fix: current time in context is respected for constraints (#292)

    sighphyre authored Mar 10, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    6fd9911 View commit details
  3. Releasing version 10.1.1

    github-actions[bot] committed Mar 10, 2025
    Copy the full SHA
    9734138 View commit details
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.getunleash</groupId>
<artifactId>unleash-client-java</artifactId>
<version>10.1.0</version>
<version>10.1.1</version>

<properties>
<version.slf4j>2.0.13</version.slf4j>
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.getunleash.metric;

import static io.getunleash.util.UnleashConfig.UNLEASH_INTERVAL;

import com.google.gson.*;
import io.getunleash.UnleashException;
import io.getunleash.event.EventDispatcher;
@@ -15,7 +17,6 @@
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.concurrent.atomic.AtomicLong;
import static io.getunleash.util.UnleashConfig.UNLEASH_INTERVAL;

public class DefaultHttpMetricsSender implements MetricSender {

@@ -83,7 +84,8 @@ private int post(URL url, Object o) throws UnleashException {
connection.setRequestMethod("POST");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty(UNLEASH_INTERVAL, this.unleashConfig.getSendMetricsIntervalMillis());
connection.setRequestProperty(
UNLEASH_INTERVAL, this.unleashConfig.getSendMetricsIntervalMillis());
UnleashConfig.setRequestProperties(connection, this.unleashConfig);
connection.setUseCaches(false);
connection.setDoInput(true);
13 changes: 8 additions & 5 deletions src/main/java/io/getunleash/metric/OkHttpMetricsSender.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.getunleash.metric;

import static io.getunleash.util.UnleashConfig.UNLEASH_INTERVAL;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.getunleash.UnleashException;
@@ -19,8 +21,6 @@
import okhttp3.RequestBody;
import okhttp3.Response;

import static io.getunleash.util.UnleashConfig.UNLEASH_INTERVAL;

public class OkHttpMetricsSender implements MetricSender {
private final UnleashConfig config;
private final MediaType JSON =
@@ -90,9 +90,12 @@ public int sendMetrics(ClientMetrics metrics) {

private int post(HttpUrl url, Object o) {
RequestBody body = RequestBody.create(gson.toJson(o), JSON);
Request request = new Request.Builder().url(url).post(body)
.addHeader(UNLEASH_INTERVAL, config.getSendMetricsIntervalMillis())
.build();
Request request =
new Request.Builder()
.url(url)
.post(body)
.addHeader(UNLEASH_INTERVAL, config.getSendMetricsIntervalMillis())
.build();
try (Response response = this.client.newCall(request).execute()) {
return response.code();
} catch (IOException ioEx) {
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.getunleash.repository;

import static io.getunleash.util.UnleashConfig.UNLEASH_INTERVAL;

import io.getunleash.UnleashException;
import io.getunleash.event.ClientFeaturesResponse;
import io.getunleash.util.UnleashConfig;
@@ -15,8 +17,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static io.getunleash.util.UnleashConfig.UNLEASH_INTERVAL;

public class HttpFeatureFetcher implements FeatureFetcher {
private static final Logger LOG = LoggerFactory.getLogger(HttpFeatureFetcher.class);
private Optional<String> etag = Optional.empty();
@@ -37,7 +37,8 @@ public ClientFeaturesResponse fetchFeatures() throws UnleashException {
HttpURLConnection connection = null;
try {
connection = openConnection(this.toggleUrl);
connection.setRequestProperty(UNLEASH_INTERVAL, this.config.getFetchTogglesIntervalMillis());
connection.setRequestProperty(
UNLEASH_INTERVAL, this.config.getFetchTogglesIntervalMillis());
connection.connect();

return getFeatureResponse(connection, true);
13 changes: 8 additions & 5 deletions src/main/java/io/getunleash/repository/OkHttpFeatureFetcher.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.getunleash.repository;

import static io.getunleash.util.UnleashConfig.UNLEASH_INTERVAL;

import com.google.gson.JsonSyntaxException;
import io.getunleash.UnleashException;
import io.getunleash.event.ClientFeaturesResponse;
@@ -16,8 +18,6 @@
import okhttp3.Request;
import okhttp3.Response;

import static io.getunleash.util.UnleashConfig.UNLEASH_INTERVAL;

public class OkHttpFeatureFetcher implements FeatureFetcher {
private final HttpUrl toggleUrl;
private final OkHttpClient client;
@@ -68,9 +68,12 @@ public OkHttpFeatureFetcher(UnleashConfig unleashConfig, OkHttpClient client) {

@Override
public ClientFeaturesResponse fetchFeatures() throws UnleashException {
Request request = new Request.Builder().url(toggleUrl).get()
.addHeader(UNLEASH_INTERVAL, interval)
.build();
Request request =
new Request.Builder()
.url(toggleUrl)
.get()
.addHeader(UNLEASH_INTERVAL, interval)
.build();
int code = 200;
try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful()) {
4 changes: 2 additions & 2 deletions src/main/java/io/getunleash/repository/YggdrasilAdapters.java
Original file line number Diff line number Diff line change
@@ -69,8 +69,8 @@ public static Context adapt(UnleashContext context) {
mapped.setRemoteAddress(context.getRemoteAddress().orElse(null));
mapped.setProperties(context.getProperties());
mapped.setCurrentTime(
DateTimeFormatter.ISO_DATE_TIME.format(
context.getCurrentTime().orElse(ZonedDateTime.now())));
DateTimeFormatter.ISO_INSTANT.format(
context.getCurrentTime().orElse(ZonedDateTime.now()).toInstant()));
return mapped;
}

2 changes: 1 addition & 1 deletion src/main/java/io/getunleash/util/UnleashConfig.java
Original file line number Diff line number Diff line change
@@ -240,11 +240,11 @@ public long getFetchTogglesInterval() {
public String getFetchTogglesIntervalMillis() {
return String.valueOf(fetchTogglesInterval * 1000);
}

public String getSendMetricsIntervalMillis() {
return String.valueOf(sendMetricsInterval * 1000);
}


public Duration getFetchTogglesConnectTimeout() {
return fetchTogglesConnectTimeout;
}
24 changes: 24 additions & 0 deletions src/test/java/io/getunleash/DefaultUnleashTest.java
Original file line number Diff line number Diff line change
@@ -132,6 +132,30 @@ public Optional<String> read() {
verify(fallback).isEnabled(any(), any());
}

@Test
public void not_setting_current_time_falls_back_to_correct_now_instant() {

ToggleBootstrapProvider bootstrapper =
new ToggleBootstrapProvider() {

@Override
public Optional<String> read() {
return Optional.of(loadMockFeatures("unleash-repo-v2-advanced.json"));
}
};

UnleashConfig unleashConfigWithFallback =
UnleashConfig.builder()
.unleashAPI("http://fakeAPI")
.appName("fakeApp")
.toggleBootstrapProvider(bootstrapper)
.build();
sut = new DefaultUnleash(unleashConfigWithFallback);

boolean enabled = sut.isEnabled("Test.currentTime");
assertThat(enabled).isTrue();
}

@Test
public void multiple_instantiations_of_the_same_config_gives_errors() {
ListAppender<ILoggingEvent> appender = new ListAppender();
33 changes: 29 additions & 4 deletions src/test/resources/unleash-repo-v2-advanced.json
Original file line number Diff line number Diff line change
@@ -44,7 +44,9 @@
{
"contextName": "single",
"operator": "STR_CONTAINS",
"values": ["true"],
"values": [
"true"
],
"inverted": false,
"caseInsensitive": true
}
@@ -58,7 +60,9 @@
{
"contextName": "catOrDog",
"operator": "STR_CONTAINS",
"values": ["cat"],
"values": [
"cat"
],
"inverted": false,
"caseInsensitive": true
}
@@ -74,7 +78,10 @@
{
"name": "default",
"segments": [
0,1,2,3
0,
1,
2,
3
]
}
],
@@ -89,6 +96,24 @@
}
],
"createdAt": "2019-01-24T10:41:45.236Z"
},
{
"name": "Test.currentTime",
"description": null,
"enabled": true,
"strategies": [
{
"name": "default",
"constraints": [
{
"contextName": "currentTime",
"operator": "DATE_AFTER",
"value": "2022-01-29T13:00:00.000Z"
}
]
}
],
"createdAt": "2019-01-24T10:41:45.236Z"
}
]
}
}