Skip to content

Commit 8285b2f

Browse files
committed
Reject withDurability(durabilityLevel) in transactions.
Closes #1492.
1 parent 751643d commit 8285b2f

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperationSupport.java

+3
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ private void rejectInvalidTransactionalOptions() {
127127
if (this.expiry != null) {
128128
throw new IllegalArgumentException("withExpiry is not supported in a transaction");
129129
}
130+
if (this.durabilityLevel != null && this.durabilityLevel != DurabilityLevel.NONE) {
131+
throw new IllegalArgumentException("withDurability is not supported in a transaction");
132+
}
130133
if (this.options != null) {
131134
throw new IllegalArgumentException("withOptions is not supported in a transaction");
132135
}

src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByIdOperationSupport.java

+3
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ private void rejectInvalidTransactionalOptions() {
134134
throw new IllegalArgumentException(
135135
"withDurability PersistTo and ReplicateTo overload is not supported in a transaction");
136136
}
137+
if (this.durabilityLevel != null && this.durabilityLevel != DurabilityLevel.NONE) {
138+
throw new IllegalArgumentException("withDurability is not supported in a transaction");
139+
}
137140
if (this.options != null) {
138141
throw new IllegalArgumentException("withOptions is not supported in a transaction");
139142
}

src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperationSupport.java

+3
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ private void rejectInvalidTransactionalOptions() {
146146
if (this.expiry != null) {
147147
throw new IllegalArgumentException("withExpiry is not supported in a transaction");
148148
}
149+
if (this.durabilityLevel != null && this.durabilityLevel != DurabilityLevel.NONE) {
150+
throw new IllegalArgumentException("withDurability is not supported in a transaction");
151+
}
149152
if (this.options != null) {
150153
throw new IllegalArgumentException("withOptions is not supported in a transaction");
151154
}

src/test/java/org/springframework/data/couchbase/transactions/CouchbaseTransactionalUnsettableParametersIntegrationTests.java

+26
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.function.Consumer;
2424
import java.util.function.Function;
2525

26+
import com.couchbase.client.core.msg.kv.DurabilityLevel;
2627
import org.junit.jupiter.api.BeforeAll;
2728
import org.junit.jupiter.api.BeforeEach;
2829
import org.junit.jupiter.api.DisplayName;
@@ -53,6 +54,7 @@
5354
* will be rejected at runtime.
5455
*
5556
* @author Graham Pople
57+
* @author Michael Reiche
5658
*/
5759
@IgnoreWhen(missesCapabilities = Capabilities.QUERY, clusterTypes = ClusterType.MOCKED)
5860
@SpringJUnitConfig(classes = { TransactionsConfig.class,
@@ -103,6 +105,14 @@ public void insertWithExpiry() {
103105
});
104106
}
105107

108+
@DisplayName("Using insertById().withDurability(durabilityLevel) in a transaction is rejected at runtime")
109+
@Test
110+
public void insertWithDurability2() {
111+
test((ops) -> {
112+
ops.insertById(Person.class).withDurability(DurabilityLevel.MAJORITY).one(WalterWhite);
113+
});
114+
}
115+
106116
@DisplayName("Using insertById().withOptions in a transaction is rejected at runtime")
107117
@Test
108118
public void insertWithOptions() {
@@ -127,6 +137,14 @@ public void replaceWithExpiry() {
127137
});
128138
}
129139

140+
@DisplayName("Using replaceById().withDurability(durabilityLevel) in a transaction is rejected at runtime")
141+
@Test
142+
public void replaceWithDurability2() {
143+
test((ops) -> {
144+
ops.replaceById(Person.class).withDurability(DurabilityLevel.MAJORITY).one(WalterWhite);
145+
});
146+
}
147+
130148
@DisplayName("Using replaceById().withOptions in a transaction is rejected at runtime")
131149
@Test
132150
public void replaceWithOptions() {
@@ -143,6 +161,14 @@ public void removeWithDurability() {
143161
});
144162
}
145163

164+
@DisplayName("Using removeById().withDurability(durabilityLevel) in a transaction is rejected at runtime")
165+
@Test
166+
public void removeWithDurability2() {
167+
test((ops) -> {
168+
ops.removeById(Person.class).withDurability(DurabilityLevel.MAJORITY).oneEntity(WalterWhite);
169+
});
170+
}
171+
146172
@DisplayName("Using removeById().withOptions in a transaction is rejected at runtime")
147173
@Test
148174
public void removeWithOptions() {

0 commit comments

Comments
 (0)