From 8285b2f62a1fa0cd86c73292a809d47028b8c954 Mon Sep 17 00:00:00 2001 From: Michael Reiche <48999328+mikereiche@users.noreply.github.com> Date: Wed, 13 Jul 2022 13:55:22 -0700 Subject: [PATCH] Reject withDurability(durabilityLevel) in transactions. Closes #1492. --- .../ReactiveInsertByIdOperationSupport.java | 3 +++ .../ReactiveRemoveByIdOperationSupport.java | 3 +++ .../ReactiveReplaceByIdOperationSupport.java | 3 +++ ...lUnsettableParametersIntegrationTests.java | 26 +++++++++++++++++++ 4 files changed, 35 insertions(+) diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperationSupport.java index daa6287d..6aeb31a3 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperationSupport.java @@ -127,6 +127,9 @@ public class ReactiveInsertByIdOperationSupport implements ReactiveInsertByIdOpe if (this.expiry != null) { throw new IllegalArgumentException("withExpiry is not supported in a transaction"); } + if (this.durabilityLevel != null && this.durabilityLevel != DurabilityLevel.NONE) { + throw new IllegalArgumentException("withDurability is not supported in a transaction"); + } if (this.options != null) { throw new IllegalArgumentException("withOptions is not supported in a transaction"); } diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByIdOperationSupport.java index 9149f361..9b4756e2 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByIdOperationSupport.java @@ -134,6 +134,9 @@ public class ReactiveRemoveByIdOperationSupport implements ReactiveRemoveByIdOpe throw new IllegalArgumentException( "withDurability PersistTo and ReplicateTo overload is not supported in a transaction"); } + if (this.durabilityLevel != null && this.durabilityLevel != DurabilityLevel.NONE) { + throw new IllegalArgumentException("withDurability is not supported in a transaction"); + } if (this.options != null) { throw new IllegalArgumentException("withOptions is not supported in a transaction"); } diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperationSupport.java index 5cb54ce0..a4cc6706 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperationSupport.java @@ -146,6 +146,9 @@ public class ReactiveReplaceByIdOperationSupport implements ReactiveReplaceByIdO if (this.expiry != null) { throw new IllegalArgumentException("withExpiry is not supported in a transaction"); } + if (this.durabilityLevel != null && this.durabilityLevel != DurabilityLevel.NONE) { + throw new IllegalArgumentException("withDurability is not supported in a transaction"); + } if (this.options != null) { throw new IllegalArgumentException("withOptions is not supported in a transaction"); } diff --git a/src/test/java/org/springframework/data/couchbase/transactions/CouchbaseTransactionalUnsettableParametersIntegrationTests.java b/src/test/java/org/springframework/data/couchbase/transactions/CouchbaseTransactionalUnsettableParametersIntegrationTests.java index 2a1c18c3..1ff2dd29 100644 --- a/src/test/java/org/springframework/data/couchbase/transactions/CouchbaseTransactionalUnsettableParametersIntegrationTests.java +++ b/src/test/java/org/springframework/data/couchbase/transactions/CouchbaseTransactionalUnsettableParametersIntegrationTests.java @@ -23,6 +23,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; import java.util.function.Function; +import com.couchbase.client.core.msg.kv.DurabilityLevel; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -53,6 +54,7 @@ import com.couchbase.client.java.kv.ReplicateTo; * will be rejected at runtime. * * @author Graham Pople + * @author Michael Reiche */ @IgnoreWhen(missesCapabilities = Capabilities.QUERY, clusterTypes = ClusterType.MOCKED) @SpringJUnitConfig(classes = { TransactionsConfig.class, @@ -103,6 +105,14 @@ public class CouchbaseTransactionalUnsettableParametersIntegrationTests extends }); } + @DisplayName("Using insertById().withDurability(durabilityLevel) in a transaction is rejected at runtime") + @Test + public void insertWithDurability2() { + test((ops) -> { + ops.insertById(Person.class).withDurability(DurabilityLevel.MAJORITY).one(WalterWhite); + }); + } + @DisplayName("Using insertById().withOptions in a transaction is rejected at runtime") @Test public void insertWithOptions() { @@ -127,6 +137,14 @@ public class CouchbaseTransactionalUnsettableParametersIntegrationTests extends }); } + @DisplayName("Using replaceById().withDurability(durabilityLevel) in a transaction is rejected at runtime") + @Test + public void replaceWithDurability2() { + test((ops) -> { + ops.replaceById(Person.class).withDurability(DurabilityLevel.MAJORITY).one(WalterWhite); + }); + } + @DisplayName("Using replaceById().withOptions in a transaction is rejected at runtime") @Test public void replaceWithOptions() { @@ -143,6 +161,14 @@ public class CouchbaseTransactionalUnsettableParametersIntegrationTests extends }); } + @DisplayName("Using removeById().withDurability(durabilityLevel) in a transaction is rejected at runtime") + @Test + public void removeWithDurability2() { + test((ops) -> { + ops.removeById(Person.class).withDurability(DurabilityLevel.MAJORITY).oneEntity(WalterWhite); + }); + } + @DisplayName("Using removeById().withOptions in a transaction is rejected at runtime") @Test public void removeWithOptions() {