Skip to content

Commit 381c1b6

Browse files
committed
fixup: using toxiproxy
Signed-off-by: Simon Schrottner <[email protected]>
1 parent c506fea commit 381c1b6

File tree

11 files changed

+95
-103
lines changed

11 files changed

+95
-103
lines changed

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/FlagdContainer.java

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import com.github.dockerjava.api.command.SyncDockerCmd;
55
import com.github.dockerjava.api.command.UnpauseContainerCmd;
66
import dev.openfeature.contrib.providers.flagd.Config;
7+
import java.io.File;
8+
import java.nio.file.Files;
9+
import java.util.List;
710
import org.apache.logging.log4j.util.Strings;
811
import org.jetbrains.annotations.NotNull;
912
import org.testcontainers.containers.GenericContainer;
@@ -42,33 +45,18 @@ public FlagdContainer(String feature) {
4245
super(generateContainerName(feature));
4346
this.withReuse(true);
4447
this.feature = feature;
45-
if (!"socket".equals(this.feature))
46-
this.addExposedPorts(8013, 8014, 8015, 8016);
47-
}
48-
49-
50-
public int getPort(Config.Resolver resolver) {
51-
waitUntilContainerStarted();
52-
switch (resolver) {
53-
case RPC:
54-
return this.getMappedPort(8013);
55-
case IN_PROCESS:
56-
return this.getMappedPort(8015);
57-
default:
58-
throw new IllegalArgumentException("Unsupported resolver: " + resolver);
59-
}
48+
if (!"socket".equals(this.feature)) this.addExposedPorts(8013, 8014, 8015, 8016);
6049
}
6150

62-
6351
/**
6452
* @return a {@link org.testcontainers.containers.GenericContainer} instance of envoy container using
6553
* flagd sync service as backend expose on port 9211
6654
*/
6755
public static GenericContainer envoy() {
6856
final String container = "envoyproxy/envoy:v1.31.0";
6957
return new GenericContainer(DockerImageName.parse(container))
70-
.withCopyFileToContainer(MountableFile.forClasspathResource("/envoy-config/envoy-custom.yaml"),
71-
"/etc/envoy/envoy.yaml")
58+
.withCopyFileToContainer(
59+
MountableFile.forClasspathResource("/envoy-config/envoy-custom.yaml"), "/etc/envoy/envoy.yaml")
7260
.withExposedPorts(9211)
7361
.withNetwork(network)
7462
.withNetworkAliases("envoy");

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/RunInProcessTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package dev.openfeature.contrib.providers.flagd.e2e;
22

3+
import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
4+
import static io.cucumber.junit.platform.engine.Constants.OBJECT_FACTORY_PROPERTY_NAME;
5+
import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME;
6+
37
import dev.openfeature.contrib.providers.flagd.Config;
4-
import io.cucumber.junit.platform.engine.Constants;
58
import org.apache.logging.log4j.core.config.Order;
69
import org.junit.platform.suite.api.BeforeSuite;
710
import org.junit.platform.suite.api.ConfigurationParameter;
@@ -12,10 +15,6 @@
1215
import org.junit.platform.suite.api.Suite;
1316
import org.testcontainers.junit.jupiter.Testcontainers;
1417

15-
import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
16-
import static io.cucumber.junit.platform.engine.Constants.OBJECT_FACTORY_PROPERTY_NAME;
17-
import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME;
18-
1918
/**
2019
* Class for running the reconnection tests for the RPC provider
2120
*/
@@ -36,4 +35,3 @@ public static void before() {
3635
State.resolverType = Config.Resolver.IN_PROCESS;
3736
}
3837
}
39-
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
package dev.openfeature.contrib.providers.flagd.e2e;
22

3+
import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
4+
import static io.cucumber.junit.platform.engine.Constants.OBJECT_FACTORY_PROPERTY_NAME;
5+
import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME;
6+
37
import dev.openfeature.contrib.providers.flagd.Config;
4-
import io.cucumber.junit.platform.engine.Constants;
58
import org.apache.logging.log4j.core.config.Order;
69
import org.junit.platform.suite.api.BeforeSuite;
710
import org.junit.platform.suite.api.ConfigurationParameter;
811
import org.junit.platform.suite.api.ExcludeTags;
912
import org.junit.platform.suite.api.IncludeEngines;
1013
import org.junit.platform.suite.api.IncludeTags;
11-
import org.junit.platform.suite.api.SelectDirectories;
14+
import org.junit.platform.suite.api.SelectFile;
1215
import org.junit.platform.suite.api.SelectFile;
1316
import org.junit.platform.suite.api.Suite;
1417
import org.testcontainers.junit.jupiter.Testcontainers;
1518

16-
import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
17-
import static io.cucumber.junit.platform.engine.Constants.OBJECT_FACTORY_PROPERTY_NAME;
18-
import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME;
19-
2019
/**
2120
* Class for running the reconnection tests for the RPC provider
2221
*/
2322
@Order(value = Integer.MAX_VALUE)
2423
@Suite
2524
@IncludeEngines("cucumber")
26-
//@SelectDirectories("test-harness/gherkin")
25+
// @SelectDirectories("test-harness/gherkin")
2726
@SelectFile("test-harness/gherkin/connection.feature")
2827
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
2928
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.contrib.providers.flagd.e2e.steps")
3029
@ConfigurationParameter(key = OBJECT_FACTORY_PROPERTY_NAME, value = "io.cucumber.picocontainer.PicoFactory")
31-
@IncludeTags({"rpc","reconnect"})
30+
@IncludeTags({"rpc", "reconnect"})
3231
@ExcludeTags({"targetURI", "customCert", "unixsocket"})
3332
@Testcontainers
3433
public class RunRpcTest {
@@ -37,6 +36,4 @@ public class RunRpcTest {
3736
public static void before() {
3837
State.resolverType = Config.Resolver.RPC;
3938
}
40-
4139
}
42-

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/State.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import dev.openfeature.sdk.Client;
99
import dev.openfeature.sdk.FlagEvaluationDetails;
1010
import dev.openfeature.sdk.MutableContext;
11-
12-
import java.util.ArrayList;
11+
import java.util.LinkedList;
12+
import java.util.List;
1313
import java.util.LinkedList;
1414
import java.util.List;
1515
import java.util.Optional;
@@ -20,12 +20,9 @@ public class State {
2020
public List<Event> events = new LinkedList<>();
2121
public Optional<Event> lastEvent;
2222
public FlagSteps.Flag flag;
23-
public MutableContext context
24-
= new MutableContext();
23+
public MutableContext context = new MutableContext();
2524
public FlagEvaluationDetails evaluation;
2625
public FlagdOptions options;
2726
public FlagdOptions.FlagdOptionsBuilder builder = FlagdOptions.builder();
2827
public static Config.Resolver resolverType;
29-
30-
3128
}

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/steps/AbstractSteps.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
abstract class AbstractSteps {
66
State state;
7+
78
public AbstractSteps(State state) {
89
this.state = state;
910
}

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/steps/ConfigSteps.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@
1414
import java.util.HashMap;
1515
import java.util.List;
1616
import java.util.Map;
17-
import java.util.Objects;
1817
import org.slf4j.Logger;
1918
import org.slf4j.LoggerFactory;
2019

21-
import static org.assertj.core.api.Assertions.assertThat;
22-
2320
public class ConfigSteps extends AbstractSteps {
2421
/**
2522
* Not all properties are correctly implemented, hence that we need to ignore them till this is
@@ -34,7 +31,6 @@ public class ConfigSteps extends AbstractSteps {
3431

3532
private static final Logger LOG = LoggerFactory.getLogger(ConfigSteps.class);
3633

37-
3834
public ConfigSteps(State state) {
3935
super(state);
4036
}
@@ -48,7 +44,8 @@ public void we_initialize_a_config() {
4844
public void we_initialize_a_config_for(String string) {
4945
switch (string.toLowerCase()) {
5046
case "in-process":
51-
state.options = state.builder.resolverType(Config.Resolver.IN_PROCESS).build();
47+
state.options =
48+
state.builder.resolverType(Config.Resolver.IN_PROCESS).build();
5249
break;
5350
case "rpc":
5451
state.options = state.builder.resolverType(Config.Resolver.RPC).build();
@@ -84,7 +81,6 @@ public void we_have_an_environment_variable_with_value(String varName, String va
8481
EnvironmentVariableUtils.set(varName, value);
8582
}
8683

87-
8884
@Then("the option {string} of type {string} should have the value {string}")
8985
public void the_option_of_type_should_have_the_value(String option, String type, String value) throws Throwable {
9086
Object convert = Utils.convert(value, type);

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/steps/ContextSteps.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,20 @@
55
import dev.openfeature.sdk.MutableContext;
66
import dev.openfeature.sdk.Value;
77
import io.cucumber.java.en.Given;
8-
import org.junit.jupiter.api.parallel.Isolated;
9-
108
import java.util.HashMap;
119
import java.util.Map;
12-
13-
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
10+
import org.junit.jupiter.api.parallel.Isolated;
1411

1512
@Isolated()
1613
public class ContextSteps extends AbstractSteps {
1714

18-
1915
public ContextSteps(State state) {
2016
super(state);
2117
}
2218

23-
2419
@Given("a context containing a key {string}, with type {string} and with value {string}")
25-
public void a_context_containing_a_key_with_type_and_with_value(String key, String type, String value) throws ClassNotFoundException, InstantiationException {
20+
public void a_context_containing_a_key_with_type_and_with_value(String key, String type, String value)
21+
throws ClassNotFoundException, InstantiationException {
2622
Map<String, Value> map = state.context.asMap();
2723
map.put(key, new Value(value));
2824
state.context = new MutableContext(state.context.getTargetingKey(), map);
@@ -34,10 +30,10 @@ public void a_context_containing_a_targeting_key_with_value(String string) {
3430
}
3531

3632
@Given("a context containing a nested property with outer key {string} and inner key {string}, with value {string}")
37-
public void a_context_containing_a_nested_property_with_outer_key_and_inner_key_with_value(String outer, String inner, String value) {
33+
public void a_context_containing_a_nested_property_with_outer_key_and_inner_key_with_value(
34+
String outer, String inner, String value) {
3835
Map<String, Value> innerMap = new HashMap<>();
3936
innerMap.put(inner, new Value(value));
4037
state.context.add(outer, new ImmutableStructure(innerMap));
4138
}
42-
4339
}

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/steps/EventSteps.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package dev.openfeature.contrib.providers.flagd.e2e.steps;
22

3+
import static java.util.concurrent.TimeUnit.MILLISECONDS;
4+
import static org.awaitility.Awaitility.await;
5+
36
import dev.openfeature.contrib.providers.flagd.e2e.State;
47
import dev.openfeature.sdk.ProviderEvent;
58
import io.cucumber.java.en.Given;
69
import io.cucumber.java.en.Then;
710
import io.cucumber.java.en.When;
11+
import java.util.LinkedList;
812
import org.jetbrains.annotations.NotNull;
913
import org.junit.jupiter.api.parallel.Isolated;
1014
import org.slf4j.Logger;
@@ -20,7 +24,6 @@
2024
public class EventSteps extends AbstractSteps {
2125
private static final Logger LOG = LoggerFactory.getLogger(EventSteps.class);
2226

23-
2427
public EventSteps(State state) {
2528
super(state);
2629
state.events = new LinkedList<>();
@@ -62,10 +65,11 @@ public void eventHandlerShouldBeExecuted(String eventType) {
6265
@Then("the {} event handler should have been executed within {int}ms")
6366
public void eventHandlerShouldBeExecutedWithin(String eventType, int ms) {
6467
LOG.info("waiting for eventtype: {}", eventType);
65-
await()
66-
.atMost(ms, MILLISECONDS)
68+
await().atMost(ms, MILLISECONDS)
6769
.until(() -> state.events.stream().anyMatch(event -> event.type.equals(eventType)));
68-
state.lastEvent = state.events.stream().filter(event -> event.type.equals(eventType)).findFirst();
70+
state.lastEvent = state.events.stream()
71+
.filter(event -> event.type.equals(eventType))
72+
.findFirst();
6973
state.events.removeIf(event -> event.type.equals(eventType));
7074
}
7175
}

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/steps/FlagSteps.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dev.openfeature.contrib.providers.flagd.e2e.steps;
22

3+
import static org.assertj.core.api.Assertions.assertThat;
4+
35
import dev.openfeature.contrib.providers.flagd.e2e.State;
46
import dev.openfeature.sdk.FlagEvaluationDetails;
57
import dev.openfeature.sdk.Value;
@@ -8,41 +10,41 @@
810
import io.cucumber.java.en.When;
911
import org.junit.jupiter.api.parallel.Isolated;
1012

11-
import static org.assertj.core.api.Assertions.assertThat;
12-
13-
1413
@Isolated()
1514
public class FlagSteps extends AbstractSteps {
1615

17-
1816
public FlagSteps(State state) {
1917
super(state);
2018
}
2119

2220
@Given("a {}-flag with key {string} and a default value {string}")
2321
public void givenAFlag(String type, String name, String defaultValue) throws ClassNotFoundException {
2422
state.flag = new Flag(type, name, Utils.convert(defaultValue, type));
25-
2623
}
2724

2825
@When("the flag was evaluated with details")
2926
public void the_flag_was_evaluated_with_details() {
3027
FlagEvaluationDetails details;
3128
switch (state.flag.type) {
3229
case "String":
33-
details = state.client.getStringDetails(state.flag.name, (String) state.flag.defaultValue, state.context);
30+
details =
31+
state.client.getStringDetails(state.flag.name, (String) state.flag.defaultValue, state.context);
3432
break;
3533
case "Boolean":
36-
details = state.client.getBooleanDetails(state.flag.name, (Boolean) state.flag.defaultValue, state.context);
34+
details = state.client.getBooleanDetails(
35+
state.flag.name, (Boolean) state.flag.defaultValue, state.context);
3736
break;
3837
case "Float":
39-
details = state.client.getDoubleDetails(state.flag.name, (Double) state.flag.defaultValue, state.context);
38+
details =
39+
state.client.getDoubleDetails(state.flag.name, (Double) state.flag.defaultValue, state.context);
4040
break;
4141
case "Integer":
42-
details = state.client.getIntegerDetails(state.flag.name, (Integer) state.flag.defaultValue, state.context);
42+
details = state.client.getIntegerDetails(
43+
state.flag.name, (Integer) state.flag.defaultValue, state.context);
4344
break;
4445
case "Object":
45-
details = state.client.getObjectDetails(state.flag.name, (Value) state.flag.defaultValue, state.context);
46+
details =
47+
state.client.getObjectDetails(state.flag.name, (Value) state.flag.defaultValue, state.context);
4648
break;
4749
default:
4850
throw new AssertionError();
@@ -59,10 +61,12 @@ public void the_resolved_details_value_should_be(String value) throws ClassNotFo
5961
public void the_reason_should_be(String reason) {
6062
assertThat(state.evaluation.getReason()).isEqualTo(reason);
6163
}
64+
6265
@Then("the variant should be {string}")
6366
public void the_variant_should_be(String variant) {
6467
assertThat(state.evaluation.getVariant()).isEqualTo(variant);
6568
}
69+
6670
@Then("the flag was modified")
6771
public void the_flag_was_modified() {
6872
assertThat(state.lastEvent).isPresent().hasValueSatisfying((event) -> {
@@ -71,7 +75,6 @@ public void the_flag_was_modified() {
7175
});
7276
}
7377

74-
7578
public class Flag {
7679
String name;
7780
Object defaultValue;

0 commit comments

Comments
 (0)