Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Check out the code
uses: actions/checkout@ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493

- name: Set up JDK 11
- name: Set up JDK ${{ matrix.build.java }}
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165
with:
java-version: ${{ matrix.build.java }}
Expand Down
25 changes: 23 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.vmlens</groupId>
<artifactId>api</artifactId>
<version>1.2.12</version>
<scope>test</scope>
</dependency>

</dependencies>

<dependencyManagement>
Expand Down Expand Up @@ -206,7 +213,6 @@
<type>pom</type>
<scope>import</scope>
</dependency>

</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -298,7 +304,6 @@
</archive>
</configuration>
</plugin>

</plugins>
</build>

Expand All @@ -310,6 +315,22 @@
</activation>
<build>
<plugins>
<plugin>
<groupId>com.vmlens</groupId>
<artifactId>vmlens-maven-plugin</artifactId>
<version>1.2.12</version>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<failIfNoTests>true</failIfNoTests>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.8.1</version>
Expand Down
77 changes: 77 additions & 0 deletions src/test/java/dev/openfeature/sdk/vmlens/VmLensTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package dev.openfeature.sdk.vmlens;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.vmlens.api.AllInterleavings;
import com.vmlens.api.Runner;
import dev.openfeature.sdk.ImmutableContext;
import dev.openfeature.sdk.OpenFeatureAPI;
import dev.openfeature.sdk.OpenFeatureAPITestUtil;
import dev.openfeature.sdk.Value;
import dev.openfeature.sdk.providers.memory.Flag;
import dev.openfeature.sdk.providers.memory.InMemoryProvider;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class VmLensTest {
final OpenFeatureAPI api = OpenFeatureAPITestUtil.createAPI();

@BeforeEach
void setUp() {
var flags = new HashMap<String, Flag<?>>();
flags.put("a", Flag.builder().variant("a", "def").defaultVariant("a").build());
flags.put("b", Flag.builder().variant("a", "as").defaultVariant("a").build());
api.setProviderAndWait(new InMemoryProvider(flags));
}

@AfterEach
void tearDown() {
api.clearHooks();
api.shutdown();
}

@Test
void concurrentClientCreations() {
try (AllInterleavings allInterleavings = new AllInterleavings("Concurrent creations of the Client")) {
while (allInterleavings.hasNext()) {
Runner.runParallel(api::getClient, api::getClient);
}
}
// keep the linter happy
assertTrue(true);
}

@Test
void concurrentFlagEvaluations() {
var client = api.getClient();
try (AllInterleavings allInterleavings = new AllInterleavings("Concurrent evaluations")) {
while (allInterleavings.hasNext()) {
Runner.runParallel(
() -> assertEquals("def", client.getStringValue("a", "a")),
() -> assertEquals("as", client.getStringValue("b", "b")));
}
}
}

@Test
void concurrentContextSetting() {
var client = api.getClient();
var contextA = new ImmutableContext(Map.of("a", new Value("b")));
var contextB = new ImmutableContext(Map.of("c", new Value("d")));
try (AllInterleavings allInterleavings =
new AllInterleavings("Concurrently setting the context and evaluating a flag")) {
while (allInterleavings.hasNext()) {
Runner.runParallel(
() -> assertEquals("def", client.getStringValue("a", "a")),
() -> client.setEvaluationContext(contextA),
() -> client.setEvaluationContext(contextB));
assertThat(client.getEvaluationContext()).isIn(contextA, contextB);
}
}
}
}
Loading