Skip to content

Commit 0cf4092

Browse files
committed
Support Java 8
Same language level as OpenFeature SDK
1 parent f7861de commit 0cf4092

File tree

7 files changed

+37
-23
lines changed

7 files changed

+37
-23
lines changed

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
<description>OpenFeature bundle for Dropwizard</description>
1616

1717
<properties>
18-
<java.version>21</java.version>
18+
<!-- Support Java 8 as the same language level supported by the Openfeature SDK -->
19+
<java.version>8</java.version>
1920
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2021
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2122
<dropwizard.version>4.0.13</dropwizard.version>

src/main/java/io/github/sideshowcoder/dropwizard_openfeature/FlagdConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class FlagdConfiguration {
6565
private int offlinePollIntervalMs;
6666

6767
public FlagdOptions getFlagdOptions() {
68-
var builder = FlagdOptions.builder();
68+
FlagdOptions.FlagdOptionsBuilder builder = FlagdOptions.builder();
6969
if (resolver != null) {
7070
builder.resolverType(Config.Resolver.valueOf(resolver.toUpperCase()));
7171
}
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
package io.github.sideshowcoder.dropwizard_openfeature;
22

33
import dev.openfeature.contrib.providers.flagd.FlagdProvider;
4+
import dev.openfeature.sdk.Client;
45
import dev.openfeature.sdk.FeatureProvider;
56
import dev.openfeature.sdk.OpenFeatureAPI;
67
import dev.openfeature.sdk.providers.memory.InMemoryProvider;
78
import io.dropwizard.core.ConfiguredBundle;
89
import io.dropwizard.core.setup.Environment;
910
import io.github.sideshowcoder.dropwizard_openfeature.health.OpenFeatureHealthCheck;
1011

11-
import java.util.Map;
12+
import java.util.HashMap;
1213

1314
public class OpenFeatureBundle implements ConfiguredBundle<OpenFeatureBundleConfiguration> {
1415

1516
private FeatureProvider featureProvider;
1617

1718
@Override
1819
public void run(OpenFeatureBundleConfiguration configuration, Environment environment) {
19-
var config = configuration.getOpenFeatureConfiguration();
20+
OpenFeatureConfiguration config = configuration.getOpenFeatureConfiguration();
2021
initializeFeatureProvider(config);
21-
var manager = new OpenFeatureAPIManager(getFeatureProvider());
22+
OpenFeatureAPIManager manager = new OpenFeatureAPIManager(getFeatureProvider());
2223
environment.lifecycle().manage(manager);
2324

2425
if (config.getHealthcheck().isEnabled()) {
25-
var client = OpenFeatureAPI.getInstance().getClient(config.getHealthcheck().getClientDomain());
26-
var healthcheck = new OpenFeatureHealthCheck(client);
26+
Client client = OpenFeatureAPI.getInstance().getClient(config.getHealthcheck().getClientDomain());
27+
OpenFeatureHealthCheck healthcheck = new OpenFeatureHealthCheck(client);
2728
environment.healthChecks().register(config.getHealthcheck().getName(), healthcheck);
2829
}
2930
}
@@ -36,9 +37,13 @@ public FeatureProvider getFeatureProvider() {
3637
}
3738

3839
private synchronized void initializeFeatureProvider(OpenFeatureConfiguration config) {
39-
featureProvider = switch (config.getProviderType()) {
40-
case FLAGD -> new FlagdProvider(config.getFlagd().getFlagdOptions());
41-
case INMEMORY -> new InMemoryProvider(Map.of());
42-
};
40+
switch (config.getProviderType()) {
41+
case INMEMORY:
42+
featureProvider = new InMemoryProvider(new HashMap<>());
43+
break;
44+
case FLAGD:
45+
featureProvider = new FlagdProvider(config.getFlagd().getFlagdOptions());
46+
break;
47+
}
4348
}
4449
}

src/test/java/io/github/sideshowcoder/dropwizard_openfeature/FlagdConfigurationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class FlagdConfigurationTest {
2222

2323
@Test
2424
public void providesFlagdOptions() throws Exception {
25-
var configuration = factory.build(new ResourceConfigurationSourceProvider(), "basic-flagd-config.yml");
25+
FlagdConfiguration configuration = factory.build(new ResourceConfigurationSourceProvider(), "basic-flagd-config.yml");
2626
assertEquals("flagd", configuration.getFlagdOptions().getHost());
2727
assertEquals(8082, configuration.getFlagdOptions().getPort());
2828
assertEquals(Config.Resolver.RPC, configuration.getFlagdOptions().getResolverType());

src/test/java/io/github/sideshowcoder/dropwizard_openfeature/OpenFeatureBundleFlagdProviderTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.github.sideshowcoder.dropwizard_openfeature;
22

3+
import com.codahale.metrics.health.HealthCheck;
4+
import dev.openfeature.sdk.Client;
35
import dev.openfeature.sdk.OpenFeatureAPI;
46
import io.dropwizard.testing.ResourceHelpers;
57
import io.dropwizard.testing.junit5.DropwizardAppExtension;
@@ -21,14 +23,14 @@ public class OpenFeatureBundleFlagdProviderTest {
2123

2224
@Test
2325
public void initializesHealthCheck() throws Exception {
24-
var healthcheckResult = APP.getEnvironment().healthChecks().runHealthCheck("openfeature-health-check");
26+
HealthCheck.Result healthcheckResult = APP.getEnvironment().healthChecks().runHealthCheck("openfeature-health-check");
2527
assertTrue(healthcheckResult.isHealthy());
2628
}
2729

2830
@Test
2931
public void providesFeatureFlagsViaInMemoryProvider() throws Exception {
3032
// See flagd-test-flags.json for flag definitions used!
31-
var client = OpenFeatureAPI.getInstance().getClient("flagd-client");
33+
Client client = OpenFeatureAPI.getInstance().getClient("flagd-client");
3234
assertEquals("red", client.getStringValue("static-string-flag", "not-expected-value"));
3335
}
3436

src/test/java/io/github/sideshowcoder/dropwizard_openfeature/OpenFeatureBundleInMemoryProviderTest.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.github.sideshowcoder.dropwizard_openfeature;
22

3+
import com.codahale.metrics.health.HealthCheck;
4+
import dev.openfeature.sdk.Client;
35
import dev.openfeature.sdk.OpenFeatureAPI;
46
import dev.openfeature.sdk.providers.memory.Flag;
57
import dev.openfeature.sdk.providers.memory.InMemoryProvider;
@@ -11,6 +13,7 @@
1113
import org.junit.jupiter.api.Test;
1214
import org.junit.jupiter.api.extension.ExtendWith;
1315

16+
import java.util.HashMap;
1417
import java.util.Map;
1518

1619
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -25,23 +28,25 @@ public class OpenFeatureBundleInMemoryProviderTest {
2528

2629
@Test
2730
public void initializesHealthCheck() throws Exception {
28-
var healthcheckResult = APP.getEnvironment().healthChecks().runHealthCheck("openfeature-health-check");
31+
HealthCheck.Result healthcheckResult = APP.getEnvironment().healthChecks().runHealthCheck("openfeature-health-check");
2932
assertTrue(healthcheckResult.isHealthy());
3033
}
3134

3235
@Test
3336
public void providesFeatureFlagsViaInMemoryProvider() throws Exception {
34-
var expectedValue = "expected-value";
35-
var flagKey = "flag-key";
36-
var flag = Flag.builder().variant("variant-key", expectedValue).defaultVariant("variant-key").build();
37-
var flags = Map.<String, Flag<?>>of(flagKey, flag);
37+
String expectedValue = "expected-value";
38+
39+
String flagKey = "flag-key";
40+
Flag<Object> flag = Flag.builder().variant("variant-key", expectedValue).defaultVariant("variant-key").build();
41+
Map<String, Flag<?>> flags = new HashMap<>();
42+
flags.put(flagKey, flag);
3843

3944
// set the in memory flags
40-
var bundle = ((App) APP.getApplication()).getOpenFeatureBundle();
41-
var provider = (InMemoryProvider) bundle.getFeatureProvider();
45+
OpenFeatureBundle bundle = ((App) APP.getApplication()).getOpenFeatureBundle();
46+
InMemoryProvider provider = (InMemoryProvider) bundle.getFeatureProvider();
4247
provider.updateFlags(flags);
4348

44-
var client = OpenFeatureAPI.getInstance().getClient("in-memory-provider-client");
49+
Client client = OpenFeatureAPI.getInstance().getClient("in-memory-provider-client");
4550
assertEquals(expectedValue, client.getStringValue(flagKey, "not-expected-value"));
4651
}
4752
}

src/test/java/io/github/sideshowcoder/dropwizard_openfeature/health/OpenFeatureHealthCheckTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.sideshowcoder.dropwizard_openfeature.health;
22

3+
import com.codahale.metrics.health.HealthCheck;
34
import dev.openfeature.sdk.Client;
45
import dev.openfeature.sdk.ClientMetadata;
56
import dev.openfeature.sdk.ProviderState;
@@ -41,7 +42,7 @@ public void testProviderUnhealthy() throws Exception {
4142
when(client.getMetadata()).thenReturn(metadata);
4243
when(metadata.getDomain()).thenReturn("domain");
4344

44-
var result = healthCheck.check();
45+
HealthCheck.Result result = healthCheck.check();
4546

4647
assertFalse(result.isHealthy());
4748
}

0 commit comments

Comments
 (0)