Skip to content

Commit 14c6f8b

Browse files
committed
Add vmlens
Signed-off-by: christian.lutnik <[email protected]>
1 parent 532ad2f commit 14c6f8b

File tree

8 files changed

+108
-4
lines changed

8 files changed

+108
-4
lines changed

.github/workflows/pullrequest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Check out the code
2222
uses: actions/checkout@ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493
2323

24-
- name: Set up JDK 11
24+
- name: Set up JDK ${{ matrix.build.java }}
2525
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165
2626
with:
2727
java-version: ${{ matrix.build.java }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ target
1313

1414
# used for spec compliance tooling
1515
java-report.json
16+
17+
# vmlens stuff
18+
java-sdk/vmlens-agent/vmlens/

pom.xml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@
168168
<scope>test</scope>
169169
</dependency>
170170

171+
<dependency>
172+
<groupId>com.vmlens</groupId>
173+
<artifactId>api</artifactId>
174+
<version>1.2.12</version>
175+
<scope>test</scope>
176+
</dependency>
177+
171178
</dependencies>
172179

173180
<dependencyManagement>
@@ -206,7 +213,6 @@
206213
<type>pom</type>
207214
<scope>import</scope>
208215
</dependency>
209-
210216
</dependencies>
211217
</dependencyManagement>
212218

@@ -298,7 +304,6 @@
298304
</archive>
299305
</configuration>
300306
</plugin>
301-
302307
</plugins>
303308
</build>
304309

@@ -310,6 +315,23 @@
310315
</activation>
311316
<build>
312317
<plugins>
318+
<plugin>
319+
<groupId>com.vmlens</groupId>
320+
<artifactId>vmlens-maven-plugin</artifactId>
321+
<version>1.2.12</version>
322+
<executions>
323+
<execution>
324+
<id>test</id>
325+
<goals>
326+
<goal>test</goal>
327+
</goals>
328+
<configuration>
329+
<agentDirectory>vmlens-agent</agentDirectory>
330+
<failIfNoTests>true</failIfNoTests>
331+
</configuration>
332+
</execution>
333+
</executions>
334+
</plugin>
313335
<plugin>
314336
<artifactId>maven-dependency-plugin</artifactId>
315337
<version>3.8.1</version>

src/main/java/dev/openfeature/sdk/Awaitable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class Awaitable {
1010
*/
1111
public static final Awaitable FINISHED = new Awaitable(true);
1212

13-
private boolean isDone = false;
13+
private volatile boolean isDone = false;
1414

1515
public Awaitable() {}
1616

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package dev.openfeature.sdk.vmlens;
2+
3+
import static org.hamcrest.MatcherAssert.assertThat;
4+
import static org.hamcrest.Matchers.anyOf;
5+
import static org.hamcrest.Matchers.is;
6+
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
import static org.junit.jupiter.api.Assertions.assertTrue;
8+
9+
import com.vmlens.api.AllInterleavings;
10+
import com.vmlens.api.Runner;
11+
import dev.openfeature.sdk.ImmutableContext;
12+
import dev.openfeature.sdk.OpenFeatureAPI;
13+
import dev.openfeature.sdk.OpenFeatureAPITestUtil;
14+
import dev.openfeature.sdk.Value;
15+
import dev.openfeature.sdk.providers.memory.Flag;
16+
import dev.openfeature.sdk.providers.memory.InMemoryProvider;
17+
import java.util.HashMap;
18+
import java.util.Map;
19+
import org.junit.jupiter.api.AfterEach;
20+
import org.junit.jupiter.api.BeforeEach;
21+
import org.junit.jupiter.api.Test;
22+
23+
class VmLensTest {
24+
final OpenFeatureAPI api = OpenFeatureAPITestUtil.createAPI();
25+
26+
@BeforeEach
27+
void setUp() {
28+
var flags = new HashMap<String, Flag<?>>();
29+
flags.put("a", Flag.builder().variant("a", "def").defaultVariant("a").build());
30+
flags.put("b", Flag.builder().variant("a", "as").defaultVariant("a").build());
31+
api.setProviderAndWait(new InMemoryProvider(flags));
32+
}
33+
34+
@AfterEach
35+
void tearDown() {
36+
api.clearHooks();
37+
api.shutdown();
38+
}
39+
40+
@Test
41+
void concurrentClientCreations() {
42+
try (AllInterleavings allInterleavings = new AllInterleavings("Concurrent creations of the Client")) {
43+
while (allInterleavings.hasNext()) {
44+
Runner.runParallel(api::getClient, api::getClient);
45+
}
46+
}
47+
// keep the linter happy
48+
assertTrue(true);
49+
}
50+
51+
@Test
52+
void concurrentFlagEvaluations() {
53+
var client = api.getClient();
54+
try (AllInterleavings allInterleavings = new AllInterleavings("Concurrent evaluations")) {
55+
while (allInterleavings.hasNext()) {
56+
Runner.runParallel(
57+
() -> assertEquals("def", client.getStringValue("a", "a")),
58+
() -> assertEquals("as", client.getStringValue("b", "b")));
59+
}
60+
}
61+
}
62+
63+
@Test
64+
void concurrentContextSetting() {
65+
var client = api.getClient();
66+
var contextA = new ImmutableContext(Map.of("a", new Value("b")));
67+
var contextB = new ImmutableContext(Map.of("c", new Value("d")));
68+
try (AllInterleavings allInterleavings =
69+
new AllInterleavings("Concurrently setting the context and evaluating a flag")) {
70+
while (allInterleavings.hasNext()) {
71+
Runner.runParallel(
72+
() -> assertEquals("def", client.getStringValue("a", "a")),
73+
() -> client.setEvaluationContext(contextA),
74+
() -> client.setEvaluationContext(contextB));
75+
assertThat(client.getEvaluationContext(), anyOf(is(contextA), is(contextB)));
76+
}
77+
}
78+
}
79+
}

vmlens-agent/agent.jar

5.55 KB
Binary file not shown.

vmlens-agent/agent_bootstrap.jar

4.11 MB
Binary file not shown.

vmlens-agent/agent_runtime.jar

408 KB
Binary file not shown.

0 commit comments

Comments
 (0)