Skip to content

Commit af189f8

Browse files
chrfwowaepfli
andauthored
feat: Add vmlens checks (#1567)
* Add vmlens Signed-off-by: christian.lutnik <[email protected]> * fix test and gitignore Signed-off-by: christian.lutnik <[email protected]> * remove vmlens agent binary Signed-off-by: christian.lutnik <[email protected]> * remove unused import Signed-off-by: christian.lutnik <[email protected]> * remove vmlens from gitignore, add failing test to check if vmlens still works Signed-off-by: christian.lutnik <[email protected]> * remove failing test Signed-off-by: christian.lutnik <[email protected]> * remove volatile Signed-off-by: christian.lutnik <[email protected]> * update vmlens Signed-off-by: christian.lutnik <[email protected]> --------- Signed-off-by: christian.lutnik <[email protected]> Co-authored-by: Simon Schrottner <[email protected]>
1 parent b693390 commit af189f8

File tree

3 files changed

+101
-3
lines changed

3 files changed

+101
-3
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@a7ab372554b6eb1a8eb25e7d9aec1cc9f3ea1a76
2626
with:
2727
java-version: ${{ matrix.build.java }}

pom.xml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@
193193
<scope>test</scope>
194194
</dependency>
195195

196+
<dependency>
197+
<groupId>com.vmlens</groupId>
198+
<artifactId>api</artifactId>
199+
<version>1.2.13</version>
200+
<scope>test</scope>
201+
</dependency>
202+
196203
</dependencies>
197204

198205
<dependencyManagement>
@@ -239,7 +246,6 @@
239246
<type>pom</type>
240247
<scope>import</scope>
241248
</dependency>
242-
243249
</dependencies>
244250
</dependencyManagement>
245251

@@ -331,7 +337,6 @@
331337
</archive>
332338
</configuration>
333339
</plugin>
334-
335340
</plugins>
336341
</build>
337342

@@ -343,6 +348,22 @@
343348
</activation>
344349
<build>
345350
<plugins>
351+
<plugin>
352+
<groupId>com.vmlens</groupId>
353+
<artifactId>vmlens-maven-plugin</artifactId>
354+
<version>1.2.13</version>
355+
<executions>
356+
<execution>
357+
<id>test</id>
358+
<goals>
359+
<goal>test</goal>
360+
</goals>
361+
<configuration>
362+
<failIfNoTests>true</failIfNoTests>
363+
</configuration>
364+
</execution>
365+
</executions>
366+
</plugin>
346367
<plugin>
347368
<artifactId>maven-dependency-plugin</artifactId>
348369
<version>3.8.1</version>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package dev.openfeature.sdk.vmlens;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
6+
7+
import com.vmlens.api.AllInterleavings;
8+
import com.vmlens.api.Runner;
9+
import dev.openfeature.sdk.ImmutableContext;
10+
import dev.openfeature.sdk.OpenFeatureAPI;
11+
import dev.openfeature.sdk.OpenFeatureAPITestUtil;
12+
import dev.openfeature.sdk.Value;
13+
import dev.openfeature.sdk.providers.memory.Flag;
14+
import dev.openfeature.sdk.providers.memory.InMemoryProvider;
15+
import java.util.HashMap;
16+
import java.util.Map;
17+
import org.junit.jupiter.api.AfterEach;
18+
import org.junit.jupiter.api.BeforeEach;
19+
import org.junit.jupiter.api.Test;
20+
21+
class VmLensTest {
22+
final OpenFeatureAPI api = OpenFeatureAPITestUtil.createAPI();
23+
24+
@BeforeEach
25+
void setUp() {
26+
var flags = new HashMap<String, Flag<?>>();
27+
flags.put("a", Flag.builder().variant("a", "def").defaultVariant("a").build());
28+
flags.put("b", Flag.builder().variant("a", "as").defaultVariant("a").build());
29+
api.setProviderAndWait(new InMemoryProvider(flags));
30+
}
31+
32+
@AfterEach
33+
void tearDown() {
34+
api.clearHooks();
35+
api.shutdown();
36+
}
37+
38+
@Test
39+
void concurrentClientCreations() {
40+
try (AllInterleavings allInterleavings = new AllInterleavings("Concurrent creations of the Client")) {
41+
while (allInterleavings.hasNext()) {
42+
Runner.runParallel(api::getClient, api::getClient);
43+
}
44+
}
45+
// keep the linter happy
46+
assertTrue(true);
47+
}
48+
49+
@Test
50+
void concurrentFlagEvaluations() {
51+
var client = api.getClient();
52+
try (AllInterleavings allInterleavings = new AllInterleavings("Concurrent evaluations")) {
53+
while (allInterleavings.hasNext()) {
54+
Runner.runParallel(
55+
() -> assertEquals("def", client.getStringValue("a", "a")),
56+
() -> assertEquals("as", client.getStringValue("b", "b")));
57+
}
58+
}
59+
}
60+
61+
@Test
62+
void concurrentContextSetting() {
63+
var client = api.getClient();
64+
var contextA = new ImmutableContext(Map.of("a", new Value("b")));
65+
var contextB = new ImmutableContext(Map.of("c", new Value("d")));
66+
try (AllInterleavings allInterleavings =
67+
new AllInterleavings("Concurrently setting the context and evaluating a flag")) {
68+
while (allInterleavings.hasNext()) {
69+
Runner.runParallel(
70+
() -> assertEquals("def", client.getStringValue("a", "a")),
71+
() -> client.setEvaluationContext(contextA),
72+
() -> client.setEvaluationContext(contextB));
73+
assertThat(client.getEvaluationContext()).isIn(contextA, contextB);
74+
}
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)