You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by pt...@apache.org on 2025/05/02 10:46:30 UTC

(ignite-3) branch ignite-25178 updated: IGNITE-25178 .NET: Add synchronous Dispose method to ITransaction

This is an automated email from the ASF dual-hosted git repository.

ptupitsyn pushed a commit to branch ignite-25178
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/ignite-25178 by this push:
     new 3f7014ec4ec IGNITE-25178 .NET: Add synchronous Dispose method to ITransaction
3f7014ec4ec is described below

commit 3f7014ec4ec566b9e7503c659ee45763fcceb419
Author: Pavel Tupitsyn <pt...@apache.org>
AuthorDate: Fri May 2 13:46:21 2025 +0300

    IGNITE-25178 .NET: Add synchronous Dispose method to ITransaction
---
 .../Transactions/TransactionsTests.cs              | 31 ++++++++++++++--------
 .../Internal/Transactions/LazyTransaction.cs       |  3 +++
 .../Apache.Ignite/Transactions/ITransaction.cs     |  2 +-
 3 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/Transactions/TransactionsTests.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/Transactions/TransactionsTests.cs
index 78beb7be8ff..d002ddd07ed 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/Transactions/TransactionsTests.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/Transactions/TransactionsTests.cs
@@ -18,6 +18,7 @@
 namespace Apache.Ignite.Tests.Transactions
 {
     using System;
+    using System.Diagnostics.CodeAnalysis;
     using System.Linq;
     using System.Threading.Tasks;
     using Ignite.Transactions;
@@ -108,12 +109,24 @@ namespace Apache.Ignite.Tests.Transactions
         }
 
         [Test]
+        [SuppressMessage("ReSharper", "UseAwaitUsing", Justification = "Testing synchronous Dispose.")]
         public async Task TestDisposeDoesNotUpdateData()
+        {
+            using (var tx = await Client.Transactions.BeginAsync())
+            {
+                await TupleView.UpsertAsync(tx, GetTuple(1, "2"));
+            }
+
+            var (_, hasValue) = await TupleView.GetAsync(null, GetTuple(1));
+            Assert.IsFalse(hasValue);
+        }
+
+        [Test]
+        public async Task TestDisposeAsyncDoesNotUpdateData()
         {
             await using (var tx = await Client.Transactions.BeginAsync())
             {
                 await TupleView.UpsertAsync(tx, GetTuple(1, "2"));
-                await tx.RollbackAsync();
             }
 
             var (_, hasValue) = await TupleView.GetAsync(null, GetTuple(1));
@@ -341,20 +354,16 @@ namespace Apache.Ignite.Tests.Transactions
         {
             public bool IsReadOnly => false;
 
-            public ValueTask DisposeAsync()
-            {
-                return new ValueTask(Task.CompletedTask);
-            }
+            public ValueTask DisposeAsync() => new(Task.CompletedTask);
 
-            public Task CommitAsync()
+            public void Dispose()
             {
-                return Task.CompletedTask;
+                // No-op.
             }
 
-            public Task RollbackAsync()
-            {
-                return Task.CompletedTask;
-            }
+            public Task CommitAsync() => Task.CompletedTask;
+
+            public Task RollbackAsync() => Task.CompletedTask;
         }
     }
 }
diff --git a/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/LazyTransaction.cs b/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/LazyTransaction.cs
index c72f36f4eed..80d2d9a85b1 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/LazyTransaction.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/LazyTransaction.cs
@@ -105,6 +105,9 @@ internal sealed class LazyTransaction : ITransaction
     /// <inheritdoc/>
     public async ValueTask DisposeAsync() => await RollbackAsync().ConfigureAwait(false);
 
+    /// <inheritdoc/>
+    public void Dispose() => DisposeAsync().AsTask().GetAwaiter().GetResult();
+
     /// <inheritdoc/>
     public override string ToString()
     {
diff --git a/modules/platforms/dotnet/Apache.Ignite/Transactions/ITransaction.cs b/modules/platforms/dotnet/Apache.Ignite/Transactions/ITransaction.cs
index f1d9c0e9a89..8bdce4ef126 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Transactions/ITransaction.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Transactions/ITransaction.cs
@@ -25,7 +25,7 @@ namespace Apache.Ignite.Transactions
     /// <para />
     /// Use <see cref="ITransactions.BeginAsync()"/> to start a new transaction.
     /// </summary>
-    public interface ITransaction : IAsyncDisposable
+    public interface ITransaction : IAsyncDisposable, IDisposable
     {
         /// <summary>
         /// Gets a value indicating whether this transaction is read-only.