18
18
19
19
import static org .junit .jupiter .api .Assertions .assertTrue ;
20
20
import static org .junit .jupiter .api .Assertions .fail ;
21
- import static org .springframework .data .couchbase .transactions .util .TransactionTestUtil .assertNotInTransaction ;
21
+ import static org .springframework .data .couchbase .transactions .util .TransactionTestUtil .assertInTransaction ;
22
+ import static org .springframework .data .couchbase .transactions .util .TransactionTestUtil .assertInReactiveTransaction ;
23
+ import static org .springframework .data .couchbase .transactions .util .TransactionTestUtil .assertNotInReactiveTransaction ;
22
24
23
25
import org .springframework .data .couchbase .domain .PersonWithoutVersion ;
24
- import reactor .core .publisher .Mono ;
25
- import reactor .core .scheduler .Schedulers ;
26
26
27
27
import org .junit .jupiter .api .AfterEach ;
28
28
import org .junit .jupiter .api .BeforeEach ;
32
32
import org .springframework .data .couchbase .CouchbaseClientFactory ;
33
33
import org .springframework .data .couchbase .core .CouchbaseTemplate ;
34
34
import org .springframework .data .couchbase .core .ReactiveCouchbaseTemplate ;
35
- import org .springframework .data .couchbase .domain .Person ;
36
35
import org .springframework .data .couchbase .transactions .TransactionsConfig ;
37
36
import org .springframework .data .couchbase .util .Capabilities ;
38
37
import org .springframework .data .couchbase .util .ClusterType ;
@@ -55,45 +54,53 @@ public class SDKTransactionsSaveIntegrationTests extends JavaIntegrationTests {
55
54
@ BeforeEach
56
55
public void beforeEachTest () {
57
56
assertNotInTransaction ();
57
+ assertNotInReactiveTransaction ();
58
58
}
59
59
60
60
@ AfterEach
61
61
public void afterEachTest () {
62
62
assertNotInTransaction ();
63
+ assertNotInReactiveTransaction ();
63
64
}
64
65
66
+
65
67
@ DisplayName ("ReactiveCouchbaseTemplate.save() called inside a reactive SDK transaction should work" )
66
68
@ Test
67
69
public void reactiveSaveInReactiveTransaction () {
68
70
couchbaseClientFactory .getCluster ().reactive ().transactions ().run (ctx -> {
69
71
PersonWithoutVersion p = new PersonWithoutVersion ("Walter" , "White" );
70
- return reactiveOps .save (p );
72
+ return reactiveOps .save (p ). then ( assertInReactiveTransaction ()) ;
71
73
}).block ();
72
74
}
73
75
74
76
@ DisplayName ("ReactiveCouchbaseTemplate.save().block() called inside a non-reactive SDK transaction should work" )
75
77
@ Test
76
78
public void reactiveSaveInBlockingTransaction () {
77
79
couchbaseClientFactory .getCluster ().transactions ().run (ctx -> {
80
+ assertInTransaction ();
78
81
PersonWithoutVersion p = new PersonWithoutVersion ("Walter" , "White" );
79
82
reactiveOps .save (p ).block ();
80
83
});
81
84
}
82
85
86
+ // This should not work because ops.save(p) calls block() so everything in that call
87
+ // does not have the reactive context (which has the transaction context)
88
+ // what happens is the ops.save(p) is not in a transaction. (it will call upsert instead of insert)
83
89
@ DisplayName ("ReactiveCouchbaseTemplate.save() called inside a reactive SDK transaction should work" )
84
90
@ Test
85
91
public void blockingSaveInReactiveTransaction () {
86
92
couchbaseClientFactory .getCluster ().reactive ().transactions ().run (ctx -> {
87
93
PersonWithoutVersion p = new PersonWithoutVersion ("Walter" , "White" );
88
94
ops .save (p );
89
- return Mono . empty ();
95
+ return assertInReactiveTransaction ();
90
96
}).block ();
91
97
}
92
98
93
99
@ DisplayName ("ReactiveCouchbaseTemplate.save().block() called inside a non-reactive SDK transaction should work" )
94
100
@ Test
95
101
public void blockingSaveInBlockingTransaction () {
96
102
couchbaseClientFactory .getCluster ().transactions ().run (ctx -> {
103
+ assertInTransaction ();
97
104
PersonWithoutVersion p = new PersonWithoutVersion ("Walter" , "White" );
98
105
ops .save (p );
99
106
});
0 commit comments