1
1
package dev .openfeature .sdk .vmlens ;
2
2
3
+ import static org .hamcrest .MatcherAssert .assertThat ;
4
+ import static org .hamcrest .Matchers .anyOf ;
5
+ import static org .hamcrest .Matchers .is ;
3
6
import static org .junit .jupiter .api .Assertions .assertEquals ;
4
7
import static org .junit .jupiter .api .Assertions .assertTrue ;
5
8
@@ -31,7 +34,6 @@ class VmLensTest {
31
34
32
35
@ BeforeEach
33
36
void setUp () {
34
- System .out .println ("VmLensTest.setUp" );
35
37
var flags = new HashMap <String , Flag <?>>();
36
38
flags .put ("a" , Flag .builder ().variant ("a" , "def" ).defaultVariant ("a" ).build ());
37
39
flags .put ("b" , Flag .builder ().variant ("a" , "as" ).defaultVariant ("a" ).build ());
@@ -40,17 +42,14 @@ void setUp() {
40
42
41
43
@ AfterEach
42
44
void tearDown () {
43
- System .out .println ("VmLensTest.tearDown" );
44
45
api .clearHooks ();
45
46
api .shutdown ();
46
47
}
47
48
48
49
@ Test
49
50
void concurrentClientCreations () {
50
- System .out .println ("VmLensTest.concurrentClientCreations" );
51
51
try (AllInterleavings allInterleavings = new AllInterleavings ("Concurrent creations of the Client" )) {
52
52
while (allInterleavings .hasNext ()) {
53
- System .out .println ("iteration" );
54
53
Runner .runParallel (api ::getClient , api ::getClient );
55
54
}
56
55
}
@@ -60,11 +59,9 @@ void concurrentClientCreations() {
60
59
61
60
@ Test
62
61
void concurrentFlagEvaluations () {
63
- System .out .println ("VmLensTest.concurrentFlagEvaluations" );
64
62
var client = api .getClient ();
65
63
try (AllInterleavings allInterleavings = new AllInterleavings ("Concurrent evaluations" )) {
66
64
while (allInterleavings .hasNext ()) {
67
- System .out .println ("iteration" );
68
65
Runner .runParallel (
69
66
() -> assertEquals ("def" , client .getStringValue ("a" , "a" )),
70
67
() -> assertEquals ("as" , client .getStringValue ("b" , "b" )));
@@ -74,16 +71,38 @@ void concurrentFlagEvaluations() {
74
71
75
72
@ Test
76
73
void concurrentContextSetting () {
77
- System .out .println ("VmLensTest.concurrentContextSetting" );
78
74
var client = api .getClient ();
75
+ var contextA = new ImmutableContext (Map .of ("a" , new Value ("b" )));
76
+ var contextB = new ImmutableContext (Map .of ("c" , new Value ("d" )));
79
77
try (AllInterleavings allInterleavings =
80
78
new AllInterleavings ("Concurrently setting the context and evaluating a flag" )) {
81
79
while (allInterleavings .hasNext ()) {
82
- System .out .println ("iteration" );
83
80
Runner .runParallel (
84
81
() -> assertEquals ("def" , client .getStringValue ("a" , "a" )),
85
- () -> client .setEvaluationContext (new ImmutableContext (Map .of ("a" , new Value ("b" )))),
86
- () -> client .setEvaluationContext (new ImmutableContext (Map .of ("c" , new Value ("d" )))));
82
+ () -> client .setEvaluationContext (contextA ),
83
+ () -> client .setEvaluationContext (contextB )
84
+ );
85
+ assertThat (
86
+ client .getEvaluationContext (),
87
+ anyOf (
88
+ is (contextA ),
89
+ is (contextB )
90
+ )
91
+ );
92
+ }
93
+ }
94
+ }
95
+
96
+ @ Test
97
+ void fails () {
98
+ int [] i = new int [] {0 };
99
+ try (AllInterleavings allInterleavings = new AllInterleavings ("pls fail!" )) {
100
+ while (allInterleavings .hasNext ()) {
101
+ Runner .runParallel (
102
+ () -> i [0 ]++,
103
+ () -> i [0 ]++
104
+ );
105
+ assertEquals (2 , i [0 ]);
87
106
}
88
107
}
89
108
}
0 commit comments