You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by pp...@apache.org on 2022/06/24 09:20:04 UTC

[ignite] branch master updated: IGNITE-17204 .NET: Service call context should be accessible from async methods (#10107)

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

ppa pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new d2cf4e5381a IGNITE-17204 .NET: Service call context should be accessible from async methods (#10107)
d2cf4e5381a is described below

commit d2cf4e5381a521a31ee7a5c37bf22f8573c66250
Author: Pavel Pereslegin <xx...@gmail.com>
AuthorDate: Fri Jun 24 12:19:55 2022 +0300

    IGNITE-17204 .NET: Service call context should be accessible from async methods (#10107)
---
 .../Services/ServicesTest.cs                       | 23 ++++++++++++++++++++++
 .../Impl/Services/ServiceContext.cs                |  2 +-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs
index 69a794c82e9..113f1fe7087 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTest.cs
@@ -24,6 +24,7 @@ namespace Apache.Ignite.Core.Tests.Services
     using System.Net;
     using System.Runtime.Serialization.Formatters.Binary;
     using System.Threading;
+    using System.Threading.Tasks;
     using Apache.Ignite.Core.Binary;
     using Apache.Ignite.Core.Client;
     using Apache.Ignite.Core.Cluster;
@@ -360,6 +361,11 @@ namespace Apache.Ignite.Core.Tests.Services
                 Assert.AreEqual(attrValue, stickyProxy.ContextAttribute(attrName));
                 Assert.AreEqual(attrValue, dynamicProxy.ContextAttribute(attrName));
                 Assert.AreEqual(attrValue, dynamicStickyProxy.ContextAttribute(attrName));
+                
+                Assert.AreEqual(attrValue, proxy.ContextAttributeWithAsync(attrName));
+                Assert.AreEqual(attrValue, stickyProxy.ContextAttributeWithAsync(attrName));
+                Assert.AreEqual(attrValue, dynamicProxy.ContextAttributeWithAsync(attrName));
+                Assert.AreEqual(attrValue, dynamicStickyProxy.ContextAttributeWithAsync(attrName));
 
                 Assert.AreEqual(attrBinValue, proxy.ContextBinaryAttribute(attrBinName));
                 Assert.AreEqual(attrBinValue, stickyProxy.ContextBinaryAttribute(attrBinName));
@@ -1785,6 +1791,9 @@ namespace Apache.Ignite.Core.Tests.Services
 
             /** */
             object ContextAttribute(string name);
+            
+            /** */
+            object ContextAttributeWithAsync(string name);
 
             /** */
             object ContextBinaryAttribute(string name);
@@ -1921,6 +1930,20 @@ namespace Apache.Ignite.Core.Tests.Services
                 return ctx == null ? null : ctx.GetAttribute(name);
             }
 
+            /** <inheritdoc /> */
+            public object ContextAttributeWithAsync(string name)
+            {
+                return ContextAttributeAsync(name).GetResult();
+            }
+
+            /** */
+            private async Task<object> ContextAttributeAsync(string name)
+            {
+                await Task.Delay(1);
+
+                return ContextAttribute(name);
+            }
+
             /** <inheritdoc /> */
             public object ContextBinaryAttribute(string name)
             {
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Services/ServiceContext.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Services/ServiceContext.cs
index 3c9276fc217..6a507665e87 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Services/ServiceContext.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Services/ServiceContext.cs
@@ -29,7 +29,7 @@ namespace Apache.Ignite.Core.Impl.Services
     internal class ServiceContext : IServiceContext
     {
         /** Service call context of the current thread. */
-        private static readonly ThreadLocal<IServiceCallContext> LocalCallContext = new ThreadLocal<IServiceCallContext>();
+        private static readonly AsyncLocal<IServiceCallContext> LocalCallContext = new AsyncLocal<IServiceCallContext>();
 
         /// <summary>
         /// Initializes a new instance of the <see cref="ServiceContext"/> class.