11package dev .openfeature .sdk .vmlens ;
22
3+ import static org .hamcrest .MatcherAssert .assertThat ;
4+ import static org .hamcrest .Matchers .anyOf ;
5+ import static org .hamcrest .Matchers .is ;
36import static org .junit .jupiter .api .Assertions .assertEquals ;
47import static org .junit .jupiter .api .Assertions .assertTrue ;
58
@@ -31,7 +34,6 @@ class VmLensTest {
3134
3235 @ BeforeEach
3336 void setUp () {
34- System .out .println ("VmLensTest.setUp" );
3537 var flags = new HashMap <String , Flag <?>>();
3638 flags .put ("a" , Flag .builder ().variant ("a" , "def" ).defaultVariant ("a" ).build ());
3739 flags .put ("b" , Flag .builder ().variant ("a" , "as" ).defaultVariant ("a" ).build ());
@@ -40,17 +42,14 @@ void setUp() {
4042
4143 @ AfterEach
4244 void tearDown () {
43- System .out .println ("VmLensTest.tearDown" );
4445 api .clearHooks ();
4546 api .shutdown ();
4647 }
4748
4849 @ Test
4950 void concurrentClientCreations () {
50- System .out .println ("VmLensTest.concurrentClientCreations" );
5151 try (AllInterleavings allInterleavings = new AllInterleavings ("Concurrent creations of the Client" )) {
5252 while (allInterleavings .hasNext ()) {
53- System .out .println ("iteration" );
5453 Runner .runParallel (api ::getClient , api ::getClient );
5554 }
5655 }
@@ -60,11 +59,9 @@ void concurrentClientCreations() {
6059
6160 @ Test
6261 void concurrentFlagEvaluations () {
63- System .out .println ("VmLensTest.concurrentFlagEvaluations" );
6462 var client = api .getClient ();
6563 try (AllInterleavings allInterleavings = new AllInterleavings ("Concurrent evaluations" )) {
6664 while (allInterleavings .hasNext ()) {
67- System .out .println ("iteration" );
6865 Runner .runParallel (
6966 () -> assertEquals ("def" , client .getStringValue ("a" , "a" )),
7067 () -> assertEquals ("as" , client .getStringValue ("b" , "b" )));
@@ -74,16 +71,38 @@ void concurrentFlagEvaluations() {
7471
7572 @ Test
7673 void concurrentContextSetting () {
77- System .out .println ("VmLensTest.concurrentContextSetting" );
7874 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" )));
7977 try (AllInterleavings allInterleavings =
8078 new AllInterleavings ("Concurrently setting the context and evaluating a flag" )) {
8179 while (allInterleavings .hasNext ()) {
82- System .out .println ("iteration" );
8380 Runner .runParallel (
8481 () -> 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 ]);
87106 }
88107 }
89108 }
0 commit comments