Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: In-memory provider for e2e testing and minimal usage #546

Merged
merged 15 commits into from
Aug 15, 2023
Merged
Prev Previous commit
Next Next commit
minor updates
Signed-off-by: liran2000 <[email protected]>
liran2000 committed Aug 14, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 071fa03faff30e6b95db5fcca9a30b84860c67c0
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -20,6 +20,11 @@ If you're adding tests to cover something in the spec, use the `@Specification`

The continuous integration runs a set of [gherkin e2e tests](https://github.com/open-feature/test-harness/blob/main/features/evaluation.feature) using `InMemoryProvider`.

to run alone:
```
mvn test -P e2e-test
```

## Releasing

See [releasing](./docs/release.md).
15 changes: 0 additions & 15 deletions src/main/java/dev/openfeature/sdk/MutableStructure.java
Original file line number Diff line number Diff line change
@@ -10,8 +10,6 @@
import java.util.Set;
import java.util.stream.Collectors;

import static dev.openfeature.sdk.Value.objectToValue;

/**
* {@link MutableStructure} represents a potentially nested object type which is used to represent
* structured data.
@@ -110,17 +108,4 @@ public Map<String, Object> asObjectMap() {
e -> convertValue(getValue(e.getKey()))
));
}

/**
* Transform an object map to a {@link Structure} type.
*
* @param map map of objects
* @return a Structure object in the SDK format
*/
public static Structure mapToStructure(Map<String, Object> map) {
return new MutableStructure(
map.entrySet().stream()
.filter(e -> e.getValue() != null)
.collect(Collectors.toMap(Map.Entry::getKey, e -> objectToValue(e.getValue()))));
}
}
14 changes: 14 additions & 0 deletions src/main/java/dev/openfeature/sdk/Structure.java
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import static dev.openfeature.sdk.Value.objectToValue;

/**
* {@link Structure} represents a potentially nested object type which is used to represent
* structured data.
@@ -123,4 +125,16 @@ default <T extends Structure> Map<String, Value> merge(Function<Map<String, Valu
}
return merged;
}

/**
* Transform an object map to a {@link Structure} type.
*
* @param map map of objects
* @return a Structure object in the SDK format
*/
static Structure mapToStructure(Map<String, Object> map) {
return new MutableStructure(map.entrySet().stream()
.filter(e -> e.getValue() != null)
.collect(Collectors.toMap(Map.Entry::getKey, e -> objectToValue(e.getValue()))));
}
}
2 changes: 1 addition & 1 deletion src/main/java/dev/openfeature/sdk/Value.java
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
import lombok.SneakyThrows;
import lombok.ToString;

import static dev.openfeature.sdk.MutableStructure.mapToStructure;
import static dev.openfeature.sdk.Structure.mapToStructure;

/**
* Values serve as a generic return type for structure data from providers.
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
import java.util.Map;

/**
* Flag representation.
* Flag representation for the in-memory provider.
*/
@ToString
@Builder
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ public InMemoryProvider(Map<String, Flag<?>> flags) {
public void initialize(EvaluationContext evaluationContext) throws Exception {
super.initialize(evaluationContext);
state = ProviderState.READY;
log.info("finished initializing provider, state: {}", state);
log.debug("finished initializing provider, state: {}", state);
ProviderEventDetails details = ProviderEventDetails.builder()
.message("provider is ready")
.build();
2 changes: 1 addition & 1 deletion src/test/java/dev/openfeature/sdk/StructureTest.java
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
import java.util.List;
import java.util.Map;

import static dev.openfeature.sdk.MutableStructure.mapToStructure;
import static dev.openfeature.sdk.Structure.mapToStructure;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

import static dev.openfeature.sdk.MutableStructure.mapToStructure;
import static dev.openfeature.sdk.Structure.mapToStructure;
import static dev.openfeature.sdk.testutils.TestFlagsUtils.buildFlags;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
import java.util.HashMap;
import java.util.Map;

import static dev.openfeature.sdk.MutableStructure.mapToStructure;
import static dev.openfeature.sdk.Structure.mapToStructure;

/**
* Test flags utils.