11package eu .antidotedb .client .test ;
22
3- import eu .antidotedb .client .AntidoteStaticTransaction ;
4- import eu .antidotedb .client .FlagKey ;
5- import eu .antidotedb .client .Key ;
3+ import eu .antidotedb .client .*;
64import org .junit .Test ;
75
6+ import java .util .List ;
7+
8+ import static java .util .Collections .singletonList ;
89import static org .junit .Assert .assertEquals ;
910
1011public class FlagTests extends AbstractAntidoteTest {
@@ -31,4 +32,98 @@ public void flagdwTest() {
3132 Boolean flagVal = bucket .read (antidoteClient .noTransaction (), flagKey );
3233 assertEquals (true , flagVal );
3334 }
35+
36+ @ Test
37+ public void flagModifyInTx () {
38+ FlagKey flagKey = Key .flag_dw ("flag3" );
39+
40+ InteractiveTransaction txn = antidoteClient .startTransaction ();
41+ bucket .update (txn , flagKey .assign (false ));
42+ Boolean valInsideTx1 = bucket .read (txn , flagKey );
43+ txn .commitTransaction ();
44+
45+ txn = antidoteClient .startTransaction ();
46+ bucket .update (txn , flagKey .assign (true ));
47+ Boolean valInsideTx2 = bucket .read (txn , flagKey );
48+ txn .commitTransaction ();
49+
50+ Boolean valOutsideTx = bucket .read (antidoteClient .noTransaction (), flagKey );
51+
52+ assertEquals (false , valInsideTx1 );
53+ assertEquals (true , valInsideTx2 );
54+ assertEquals (true , valOutsideTx );
55+ }
56+
57+ @ Test
58+ public void flagInMap () {
59+ MapKey mapWithFlag = Key .map_g ("map" );
60+
61+ InteractiveTransaction txn = antidoteClient .startTransaction ();
62+
63+ // read initial state
64+ MapKey .MapReadResult initialRead = bucket .read (txn , mapWithFlag );
65+
66+ FlagKey flagKey = Key .flag_dw ("innerFlag" );
67+ bucket .update (txn , mapWithFlag .update (
68+ flagKey .assign (false )
69+ ));
70+
71+
72+ bucket .update (txn , mapWithFlag .update (flagKey .assign (true )));
73+
74+ Boolean valInsideTx2 = bucket .read (txn , mapWithFlag ).get (flagKey );
75+
76+ txn .commitTransaction ();
77+ Boolean valOutsideTx = bucket .read (antidoteClient .noTransaction (), mapWithFlag ).get (flagKey );
78+
79+ assertEquals (true , valInsideTx2 );
80+ assertEquals (true , valOutsideTx );
81+ }
82+
83+ @ Test
84+ public void regInMap () {
85+ MapKey mapWithFlag = Key .map_g ("map" );
86+
87+ InteractiveTransaction txn = antidoteClient .startTransaction ();
88+
89+ // read initial state
90+ MapKey .MapReadResult initialRead = bucket .read (txn , mapWithFlag );
91+
92+ MVRegisterKey <String > regKey = Key .multiValueRegister ("innerFlag" );
93+ bucket .update (txn , mapWithFlag .update (
94+ regKey .assign ("test1" )
95+ ));
96+
97+
98+ bucket .update (txn , mapWithFlag .update (regKey .assign ("test2" )));
99+
100+ List <String > valInsideTx2 = bucket .read (txn , mapWithFlag ).get (regKey );
101+
102+ txn .commitTransaction ();
103+ List <String > valOutsideTx = bucket .read (antidoteClient .noTransaction (), mapWithFlag ).get (regKey );
104+
105+ assertEquals (singletonList ("test2" ), valInsideTx2 );
106+ assertEquals (singletonList ("test2" ), valOutsideTx );
107+ }
108+
109+ @ Test
110+ public void readWriteWriteReg () {
111+ MVRegisterKey <String > regKey = Key .multiValueRegister ("testReg" );
112+ InteractiveTransaction txn = antidoteClient .startTransaction ();
113+
114+ // read initial state
115+ List <String > initialRead = bucket .read (txn , regKey );
116+
117+ bucket .update (txn , regKey .assign ("test1" ));
118+
119+ bucket .update (txn , regKey .assign ("test2" ));
120+
121+ List <String > valInsideTx2 = bucket .read (txn , regKey );
122+
123+ txn .commitTransaction ();
124+ List <String > valOutsideTx = bucket .read (antidoteClient .noTransaction (), regKey );
125+
126+ assertEquals (singletonList ("test2" ), valInsideTx2 );
127+ assertEquals (singletonList ("test2" ), valOutsideTx );
128+ }
34129}
0 commit comments