This is an automated email from the ASF dual-hosted git repository.
ptupitsyn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new 58795a40c5 IGNITE-18893 .NET: Add Transaction.IsReadOnly (#1735)
58795a40c5 is described below
commit 58795a40c5bfe84c41bdbaa775cedcfa4137486e
Author: Pavel Tupitsyn <[email protected]>
AuthorDate: Thu Mar 2 10:09:52 2023 +0300
IGNITE-18893 .NET: Add Transaction.IsReadOnly (#1735)
---
.../Transactions/TransactionsTests.cs | 18 ++++++++++++++++++
.../Apache.Ignite/Internal/Transactions/Transaction.cs | 9 +++++++--
.../Internal/Transactions/Transactions.cs | 2 +-
.../dotnet/Apache.Ignite/Transactions/ITransaction.cs | 5 +++++
4 files changed, 31 insertions(+), 3 deletions(-)
diff --git
a/modules/platforms/dotnet/Apache.Ignite.Tests/Transactions/TransactionsTests.cs
b/modules/platforms/dotnet/Apache.Ignite.Tests/Transactions/TransactionsTests.cs
index f7f8762779..c7a0c3a699 100644
---
a/modules/platforms/dotnet/Apache.Ignite.Tests/Transactions/TransactionsTests.cs
+++
b/modules/platforms/dotnet/Apache.Ignite.Tests/Transactions/TransactionsTests.cs
@@ -244,8 +244,26 @@ namespace Apache.Ignite.Tests.Transactions
Assert.IsFalse(res.HasValue);
}
+ [Test]
+ public async Task TestReadOnlyTxAttributes()
+ {
+ await using var tx = await Client.Transactions.BeginAsync(new
TransactionOptions { ReadOnly = true });
+
+ Assert.IsTrue(tx.IsReadOnly);
+ }
+
+ [Test]
+ public async Task TestReadWriteTxAttributes()
+ {
+ await using var tx = await Client.Transactions.BeginAsync();
+
+ Assert.IsFalse(tx.IsReadOnly);
+ }
+
private class CustomTx : ITransaction
{
+ public bool IsReadOnly => false;
+
public ValueTask DisposeAsync()
{
return new ValueTask(Task.CompletedTask);
diff --git
a/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/Transaction.cs
b/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/Transaction.cs
index 50d35b586e..312d149392 100644
---
a/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/Transaction.cs
+++
b/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/Transaction.cs
@@ -27,7 +27,7 @@ namespace Apache.Ignite.Internal.Transactions
/// <summary>
/// Ignite transaction.
/// </summary>
- internal class Transaction : ITransaction
+ internal sealed class Transaction : ITransaction
{
/** Open state. */
private const int StateOpen = 0;
@@ -47,11 +47,13 @@ namespace Apache.Ignite.Internal.Transactions
/// <param name="id">Transaction id.</param>
/// <param name="socket">Associated connection.</param>
/// <param name="failoverSocket">Associated connection
multiplexer.</param>
- public Transaction(long id, ClientSocket socket, ClientFailoverSocket
failoverSocket)
+ /// <param name="isReadOnly">Read-only flag.</param>
+ public Transaction(long id, ClientSocket socket, ClientFailoverSocket
failoverSocket, bool isReadOnly)
{
Id = id;
Socket = socket;
FailoverSocket = failoverSocket;
+ IsReadOnly = isReadOnly;
}
/// <summary>
@@ -69,6 +71,9 @@ namespace Apache.Ignite.Internal.Transactions
/// </summary>
public long Id { get; }
+ /// <inheritdoc/>
+ public bool IsReadOnly { get; }
+
/// <inheritdoc/>
public async Task CommitAsync()
{
diff --git
a/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/Transactions.cs
b/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/Transactions.cs
index 2ea139d736..1c37c3f866 100644
---
a/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/Transactions.cs
+++
b/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/Transactions.cs
@@ -51,7 +51,7 @@ namespace Apache.Ignite.Internal.Transactions
{
var txId = resBuf.GetReader().ReadInt64();
- return new Transaction(txId, socket, _socket);
+ return new Transaction(txId, socket, _socket,
options.ReadOnly);
}
}
}
diff --git
a/modules/platforms/dotnet/Apache.Ignite/Transactions/ITransaction.cs
b/modules/platforms/dotnet/Apache.Ignite/Transactions/ITransaction.cs
index 36d36f59da..f1d9c0e9a8 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Transactions/ITransaction.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Transactions/ITransaction.cs
@@ -27,6 +27,11 @@ namespace Apache.Ignite.Transactions
/// </summary>
public interface ITransaction : IAsyncDisposable
{
+ /// <summary>
+ /// Gets a value indicating whether this transaction is read-only.
+ /// </summary>
+ bool IsReadOnly { get; }
+
/// <summary>
/// Commits the transaction.
/// </summary>