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 2022/09/30 07:51:09 UTC

[ignite-3] branch main updated: IGNITE-16994 .NET: Upgrade to SDK 6.0 (#1139)

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 76ee116dda IGNITE-16994 .NET: Upgrade to SDK 6.0 (#1139)
76ee116dda is described below

commit 76ee116dda82bb1020cd735de8f5f8baa87dc684
Author: Pavel Tupitsyn <pt...@apache.org>
AuthorDate: Fri Sep 30 10:51:03 2022 +0300

    IGNITE-16994 .NET: Upgrade to SDK 6.0 (#1139)
    
    .NET Core 3.1 support ends in December. Upgrade all projects to .NET 6 (current LTS).
---
 .../Apache.Ignite.Benchmarks.csproj                |  3 +-
 .../Apache.Ignite.Tests/Apache.Ignite.Tests.csproj |  2 +-
 .../dotnet/Apache.Ignite.Tests/ExceptionsTests.cs  | 17 +++++++----
 .../dotnet/Apache.Ignite.Tests/FakeServer.cs       |  4 +--
 .../Table/RecordViewBinaryTests.cs                 |  4 +--
 .../dotnet/Apache.Ignite/Apache.Ignite.csproj      |  2 +-
 .../dotnet/Apache.Ignite/IgniteException.cs        |  2 +-
 .../Apache.Ignite/Internal/ClientFailoverSocket.cs |  4 +--
 .../dotnet/Apache.Ignite/Internal/ClientSocket.cs  |  4 +--
 .../Internal/Common/ThreadLocalRandom.cs           | 35 ----------------------
 .../Apache.Ignite/Internal/Compute/Compute.cs      |  2 +-
 .../Apache.Ignite/Internal/ConnectionContext.cs    |  3 --
 .../dotnet/Apache.Ignite/Internal/Table/Schema.cs  |  3 --
 .../dotnet/Apache.Ignite/Table/IgniteTuple.cs      |  2 +-
 modules/platforms/dotnet/DEVNOTES.md               |  8 -----
 modules/platforms/dotnet/Directory.Build.props     |  4 +--
 16 files changed, 27 insertions(+), 72 deletions(-)

diff --git a/modules/platforms/dotnet/Apache.Ignite.Benchmarks/Apache.Ignite.Benchmarks.csproj b/modules/platforms/dotnet/Apache.Ignite.Benchmarks/Apache.Ignite.Benchmarks.csproj
index 6932ac8957..5de2ffbcc4 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Benchmarks/Apache.Ignite.Benchmarks.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Benchmarks/Apache.Ignite.Benchmarks.csproj
@@ -19,8 +19,7 @@
 
     <PropertyGroup>
         <OutputType>Exe</OutputType>
-        <TargetFramework>netcoreapp3.1</TargetFramework>
-<!--        <TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>-->
+        <TargetFramework>net6.0</TargetFramework>
         <CodeAnalysisRuleSet>..\Apache.Ignite.Tests.ruleset</CodeAnalysisRuleSet>
         <SignAssembly>true</SignAssembly>
         <AssemblyOriginatorKeyFile>Apache.Ignite.Benchmarks.snk</AssemblyOriginatorKeyFile>
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/Apache.Ignite.Tests.csproj b/modules/platforms/dotnet/Apache.Ignite.Tests/Apache.Ignite.Tests.csproj
index df97bfe00c..970f612d3b 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/Apache.Ignite.Tests.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/Apache.Ignite.Tests.csproj
@@ -18,7 +18,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
     <PropertyGroup>
-        <TargetFramework>netcoreapp3.1</TargetFramework>
+        <TargetFramework>net6.0</TargetFramework>
         <IsPackable>false</IsPackable>
         <CodeAnalysisRuleSet>..\Apache.Ignite.Tests.ruleset</CodeAnalysisRuleSet>
         <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/ExceptionsTests.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/ExceptionsTests.cs
index ad15237cf6..439ae3ae5a 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/ExceptionsTests.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/ExceptionsTests.cs
@@ -22,9 +22,10 @@ namespace Apache.Ignite.Tests
     using System.Collections.Immutable;
     using System.IO;
     using System.Linq;
-    using System.Runtime.Serialization.Formatters.Binary;
+    using System.Runtime.Serialization;
     using System.Text.RegularExpressions;
     using NUnit.Framework;
+    using BindingFlags = System.Reflection.BindingFlags;
 
     /// <summary>
     /// Tests Ignite exceptions.
@@ -49,13 +50,17 @@ namespace Apache.Ignite.Tests
                 Assert.AreEqual("myMessage", ex.Message);
 
                 // Serialization.
-                var stream = new MemoryStream();
-                var formatter = new BinaryFormatter();
+                var serializationInfo = new SerializationInfo(ex.GetType(), new FormatterConverter());
+                ex.GetObjectData(serializationInfo, default);
 
-                formatter.Serialize(stream, ex);
-                stream.Seek(0, SeekOrigin.Begin);
+                var res = (IgniteException)FormatterServices.GetUninitializedObject(ex.GetType());
+
+                var ctor = res.GetType().GetConstructor(
+                    BindingFlags.Instance | BindingFlags.NonPublic,
+                    new[] { typeof(SerializationInfo), typeof(StreamingContext) });
+
+                ctor!.Invoke(res, new object[] { serializationInfo, default(StreamingContext) });
 
-                var res = (IgniteException) formatter.Deserialize(stream);
                 Assert.AreEqual("myMessage", res.Message);
                 Assert.AreEqual(traceId, res.TraceId);
                 Assert.AreEqual(123, res.Code);
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/FakeServer.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/FakeServer.cs
index 318612ff4e..60baa01f5d 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/FakeServer.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/FakeServer.cs
@@ -61,7 +61,7 @@ namespace Apache.Ignite.Tests
             _listener.Bind(new IPEndPoint(IPAddress.Loopback, 0));
             _listener.Listen(backlog: 1);
 
-            Node = new ClusterNode("id-" + nodeName, nodeName, (IPEndPoint)_listener.LocalEndPoint);
+            Node = new ClusterNode("id-" + nodeName, nodeName, (IPEndPoint)_listener.LocalEndPoint!);
 
             if (!disableOpsTracking)
             {
@@ -77,7 +77,7 @@ namespace Apache.Ignite.Tests
 
         public async Task<IIgniteClient> ConnectClientAsync(IgniteClientConfiguration? cfg = null)
         {
-            var port = ((IPEndPoint)_listener.LocalEndPoint).Port;
+            var port = ((IPEndPoint)_listener.LocalEndPoint!).Port;
 
             cfg ??= new IgniteClientConfiguration();
 
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/Table/RecordViewBinaryTests.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/Table/RecordViewBinaryTests.cs
index f65f4663b4..b9a000ac9f 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/Table/RecordViewBinaryTests.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/Table/RecordViewBinaryTests.cs
@@ -307,7 +307,7 @@ namespace Apache.Ignite.Tests.Table
         [Test]
         public async Task TestInsertAllDoesNotOverwriteExistingDataReturnsSkippedTuples()
         {
-            var existing = new[] { GetTuple(2, "x"), GetTuple(4, "y") }.ToDictionary(x => x[0]);
+            var existing = new[] { GetTuple(2, "x"), GetTuple(4, "y") }.ToDictionary(x => x[0]!);
             await TupleView.InsertAllAsync(null, existing.Values);
 
             var ids = Enumerable.Range(1, 10).ToList();
@@ -327,7 +327,7 @@ namespace Apache.Ignite.Tests.Table
             {
                 var res = await TupleView.GetAsync(null, GetTuple(id));
 
-                if (existing.TryGetValue(res![0], out var old))
+                if (existing.TryGetValue(res![0]!, out var old))
                 {
                     Assert.AreEqual(old[1], res[1]);
                 }
diff --git a/modules/platforms/dotnet/Apache.Ignite/Apache.Ignite.csproj b/modules/platforms/dotnet/Apache.Ignite/Apache.Ignite.csproj
index 1d4a5647f3..35905d96f2 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Apache.Ignite.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite/Apache.Ignite.csproj
@@ -18,7 +18,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
-    <TargetFramework>netstandard2.1</TargetFramework>
+    <TargetFramework>net6.0</TargetFramework>
     <CodeAnalysisRuleSet>..\Apache.Ignite.ruleset</CodeAnalysisRuleSet>
     <GenerateDocumentationFile>true</GenerateDocumentationFile>
     <SignAssembly>true</SignAssembly>
diff --git a/modules/platforms/dotnet/Apache.Ignite/IgniteException.cs b/modules/platforms/dotnet/Apache.Ignite/IgniteException.cs
index fb8136018b..a34216ed5e 100644
--- a/modules/platforms/dotnet/Apache.Ignite/IgniteException.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/IgniteException.cs
@@ -56,7 +56,7 @@ namespace Apache.Ignite
         {
             IgniteArgumentCheck.NotNull(serializationInfo, nameof(serializationInfo));
 
-            TraceId = (Guid)serializationInfo.GetValue(nameof(TraceId), typeof(Guid));
+            TraceId = (Guid)serializationInfo.GetValue(nameof(TraceId), typeof(Guid))!;
             Code = serializationInfo.GetInt32(nameof(Code));
         }
 
diff --git a/modules/platforms/dotnet/Apache.Ignite/Internal/ClientFailoverSocket.cs b/modules/platforms/dotnet/Apache.Ignite/Internal/ClientFailoverSocket.cs
index decaed76b8..89055b0cfc 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Internal/ClientFailoverSocket.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Internal/ClientFailoverSocket.cs
@@ -391,7 +391,7 @@ namespace Apache.Ignite.Internal
             }
 
             throw new AggregateException(
-                "Failed to establish Ignite thin client connection, examine inner exceptions for details.", errors);
+                "Failed to establish Ignite thin client connection, examine inner exceptions for details.", errors!);
         }
 
         /// <summary>
@@ -441,7 +441,7 @@ namespace Apache.Ignite.Internal
         {
             try
             {
-                IPAddress ip;
+                IPAddress? ip;
 
                 // GetHostEntry accepts IPs, but TryParse is a more efficient shortcut.
                 return IPAddress.TryParse(host, out ip) ? new[] {ip} : Dns.GetHostEntry(host).AddressList;
diff --git a/modules/platforms/dotnet/Apache.Ignite/Internal/ClientSocket.cs b/modules/platforms/dotnet/Apache.Ignite/Internal/ClientSocket.cs
index f3a2c1a0ca..d78d998aa7 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Internal/ClientSocket.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Internal/ClientSocket.cs
@@ -509,7 +509,7 @@ namespace Apache.Ignite.Internal
 
                     // Invoke response handler in another thread to continue the receive loop.
                     // Response buffer should be disposed by the task handler.
-                    ThreadPool.QueueUserWorkItem(r => HandleResponse((PooledBuffer)r), response);
+                    ThreadPool.QueueUserWorkItem(r => HandleResponse((PooledBuffer)r!), response);
                 }
             }
             catch (Exception e)
@@ -603,7 +603,7 @@ namespace Apache.Ignite.Internal
             {
                 foreach (var reqId in _requests.Keys.ToArray())
                 {
-                    if (_requests.TryRemove(reqId, out var req) && req != null)
+                    if (_requests.TryRemove(reqId, out var req))
                     {
                         req.TrySetException(ex);
                     }
diff --git a/modules/platforms/dotnet/Apache.Ignite/Internal/Common/ThreadLocalRandom.cs b/modules/platforms/dotnet/Apache.Ignite/Internal/Common/ThreadLocalRandom.cs
deleted file mode 100644
index 6e56df86ad..0000000000
--- a/modules/platforms/dotnet/Apache.Ignite/Internal/Common/ThreadLocalRandom.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-namespace Apache.Ignite.Internal.Common
-{
-    using System;
-    using System.Threading;
-
-    /// <summary>
-    /// Thread-local random.
-    /// </summary>
-    internal static class ThreadLocalRandom
-    {
-        private static readonly ThreadLocal<Random> TlRandom = new(() => new Random());
-
-        /// <summary>
-        /// Gets the <see cref="Random"/> instance for the current thread.
-        /// </summary>
-        public static Random Instance => TlRandom.Value;
-    }
-}
diff --git a/modules/platforms/dotnet/Apache.Ignite/Internal/Compute/Compute.cs b/modules/platforms/dotnet/Apache.Ignite/Internal/Compute/Compute.cs
index a019026ae3..54ef94a149 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Internal/Compute/Compute.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Internal/Compute/Compute.cs
@@ -110,7 +110,7 @@ namespace Apache.Ignite.Internal.Compute
 
             IgniteArgumentCheck.Ensure(nodesCol.Count > 0, nameof(nodes), "Nodes can't be empty.");
 
-            var idx = ThreadLocalRandom.Instance.Next(0, nodesCol.Count);
+            var idx = Random.Shared.Next(0, nodesCol.Count);
 
             return nodesCol.ElementAt(idx);
         }
diff --git a/modules/platforms/dotnet/Apache.Ignite/Internal/ConnectionContext.cs b/modules/platforms/dotnet/Apache.Ignite/Internal/ConnectionContext.cs
index 505eacb2c4..07ab956f5a 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Internal/ConnectionContext.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Internal/ConnectionContext.cs
@@ -15,9 +15,6 @@
  * limitations under the License.
  */
 
-// XMLDoc check fails on older SDKs: https://github.com/dotnet/roslyn/issues/44571.
-#pragma warning disable CS1572
-#pragma warning disable CS1573
 namespace Apache.Ignite.Internal
 {
     using System;
diff --git a/modules/platforms/dotnet/Apache.Ignite/Internal/Table/Schema.cs b/modules/platforms/dotnet/Apache.Ignite/Internal/Table/Schema.cs
index 836e32cd9f..f9af706204 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Internal/Table/Schema.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Internal/Table/Schema.cs
@@ -15,9 +15,6 @@
  * limitations under the License.
  */
 
-// XMLDoc check fails on older SDKs: https://github.com/dotnet/roslyn/issues/44571.
-#pragma warning disable CS1572
-#pragma warning disable CS1573
 namespace Apache.Ignite.Internal.Table
 {
     using System.Collections.Generic;
diff --git a/modules/platforms/dotnet/Apache.Ignite/Table/IgniteTuple.cs b/modules/platforms/dotnet/Apache.Ignite/Table/IgniteTuple.cs
index b3c37ee6ff..00074cfe8f 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Table/IgniteTuple.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Table/IgniteTuple.cs
@@ -109,7 +109,7 @@ namespace Apache.Ignite.Table
         }
 
         /// <inheritdoc />
-        public bool Equals(IgniteTuple other)
+        public bool Equals(IgniteTuple? other)
         {
             return IIgniteTuple.Equals(this, other);
         }
diff --git a/modules/platforms/dotnet/DEVNOTES.md b/modules/platforms/dotnet/DEVNOTES.md
index 745c2d1f4c..6188a61b6f 100644
--- a/modules/platforms/dotnet/DEVNOTES.md
+++ b/modules/platforms/dotnet/DEVNOTES.md
@@ -20,14 +20,6 @@ Specific test: `dotnet test --logger "console;verbosity=normal" --filter ClientS
 To debug or profile Java side of the tests, run `org.apache.ignite.internal.runner.app.PlatformTestNodeRunner` class in IDEA with a debugger or profiler,
 then run .NET tests with `dotnet test` or `dotnet test --filter TEST_NAME`. When a server node is present, .NET tests will use it instead of starting a new one.
 
-## .NET Core 3.1 and .NET Standard 2.1
-
-* Library project target `netstandard2.1`
-* Test projects target `netcoreapp3.1`
-* .NET 6 is required for source generators
-
-See [IEP-78 .NET Thin Client](https://cwiki.apache.org/confluence/display/IGNITE/IEP-78+.NET+Thin+Client) for design considerations.
-
 ## Static Code Analysis
 
 Static code analysis (Roslyn-based) runs as part of the build and includes code style check. Build fails on any warning.
diff --git a/modules/platforms/dotnet/Directory.Build.props b/modules/platforms/dotnet/Directory.Build.props
index c74a3886f2..77e7a664af 100644
--- a/modules/platforms/dotnet/Directory.Build.props
+++ b/modules/platforms/dotnet/Directory.Build.props
@@ -19,7 +19,7 @@
     <PropertyGroup>
         <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
         <WarningsAsErrors>CS8785</WarningsAsErrors>
-        <LangVersion>9</LangVersion>
+        <LangVersion>10</LangVersion>
         <Nullable>enable</Nullable>
         <Version>3.0.0-alpha3</Version>
 
@@ -37,7 +37,7 @@
     </PropertyGroup>
 
     <ItemGroup>
-        <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.1" PrivateAssets="all"/>
+        <PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0"/>
         <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="all"/>
     </ItemGroup>