From 8a22adbd15cdbe3ccae90f7351067b3fa42c2de2 Mon Sep 17 00:00:00 2001 From: Piotr Bulawa Date: Mon, 2 Sep 2024 13:25:40 +0200 Subject: [PATCH] SNOW-1644121: Fix build warnings (#1011) --- .github/workflows/jira_close.yml | 2 +- .github/workflows/jira_issue.yml | 2 +- .github/workflows/linter.yml | 4 +- .github/workflows/main.yml | 41 +++++----- .github/workflows/snyk-issue.yml | 2 +- .github/workflows/snyk-pr.yml | 4 +- .../ConnectionSinglePoolCacheAsyncIT.cs | 2 + .../IntegrationTests/SFDbAdaptorIT.cs | 2 +- .../IntegrationTests/SFDbFactoryIT.cs | 4 +- .../Mock/MockRetryUntilRestTimeout.cs | 4 + .../UnitTests/ArrowResultChunkTest.cs | 79 ++++++++++--------- .../UnitTests/SFAzureClientTest.cs | 4 +- .../UnitTests/SFGCSClientTest.cs | 4 +- .../UnitTests/SFRemoteStorageClientTest.cs | 4 +- .../UnitTests/SFReusableChunkTest.cs | 30 +++---- .../UnitTests/SFS3ClientTest.cs | 8 +- .../Util/SessionParameterAlterer.cs | 4 +- Snowflake.Data.Tests/Util/TestDataHelpers.cs | 15 ++-- Snowflake.Data/Core/HttpUtil.cs | 19 ++--- snowflake-connector-net.sln.DotSettings | 5 ++ 20 files changed, 129 insertions(+), 110 deletions(-) diff --git a/.github/workflows/jira_close.yml b/.github/workflows/jira_close.yml index 643082e15..1329eab14 100644 --- a/.github/workflows/jira_close.yml +++ b/.github/workflows/jira_close.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: snowflakedb/gh-actions ref: jira_v1 diff --git a/.github/workflows/jira_issue.yml b/.github/workflows/jira_issue.yml index 3e1f1f2f0..1f3446876 100644 --- a/.github/workflows/jira_issue.yml +++ b/.github/workflows/jira_issue.yml @@ -14,7 +14,7 @@ jobs: if: ((github.event_name == 'issue_comment' && github.event.comment.body == 'recreate jira' && github.event.comment.user.login == 'sfc-gh-mkeller') || (github.event_name == 'issues' && github.event.pull_request.user.login != 'whitesource-for-github-com[bot]')) steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: snowflakedb/gh-actions ref: jira_v1 diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 1c00a29aa..153d4240a 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -25,9 +25,9 @@ jobs: runs-on: windows-latest steps: - name: Check out Git repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up .NET - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: dotnet-version: '8.0.x' dotnet-quality: 'ga' diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 55eef86c7..1e1b78850 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,7 +35,7 @@ jobs: cloud_env: ['AZURE', 'GCP', 'AWS'] steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Dotnet uses: actions/setup-dotnet@v4 with: @@ -44,7 +44,7 @@ jobs: 8.0.x dotnet-quality: 'ga' - name: Setup Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.x' - name: Setup dotnet-coverage @@ -69,17 +69,18 @@ jobs: snowflake_cloud_env: ${{ matrix.cloud_env }} net_version: ${{ matrix.dotnet }} - name: Upload Code Coverage Report - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: code-coverage-report + name: code-coverage-report_windows_${{ matrix.dotnet }}_${{ matrix.cloud_env }} path: Snowflake.Data.Tests\windows_${{ matrix.dotnet }}_${{ matrix.cloud_env }}_coverage.xml + - name: Upload Test Performance Report - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: tests-performance + name: tests-performance_windows_${{ matrix.dotnet }}_${{ matrix.cloud_env }} path: Snowflake.Data.Tests\windows_${{ matrix.dotnet }}_${{ matrix.cloud_env }}_performance.csv - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: # without the token code cov may fail because of Github limits https://github.com/codecov/codecov-action/issues/557 token: ${{ secrets.CODE_COV_UPLOAD_TOKEN }} @@ -95,7 +96,7 @@ jobs: dotnet: ['net6.0', 'net7.0', 'net8.0'] cloud_env: ['AZURE', 'GCP', 'AWS'] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Dotnet uses: actions/setup-dotnet@v4 with: @@ -104,7 +105,7 @@ jobs: 8.0.x dotnet-quality: 'ga' - name: Setup Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.x' - name: Setup dotnet-coverage @@ -128,17 +129,17 @@ jobs: snowflake_cloud_env: ${{ matrix.cloud_env }} net_version: ${{ matrix.dotnet }} - name: Upload Code Coverage Report - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: code-coverage-report + name: code-coverage-report_linux_${{ matrix.dotnet }}_${{ matrix.cloud_env }} path: Snowflake.Data.Tests/linux_${{ matrix.dotnet }}_${{ matrix.cloud_env }}_coverage.xml - name: Upload Test Performance Report - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: tests-performance + name: tests-performance_linux_${{ matrix.dotnet }}_${{ matrix.cloud_env }} path: Snowflake.Data.Tests/linux_${{ matrix.dotnet }}_${{ matrix.cloud_env }}_performance.csv - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: # without the token code cov may fail because of Github limits https://github.com/codecov/codecov-action/issues/557 token: ${{ secrets.CODE_COV_UPLOAD_TOKEN }} @@ -163,7 +164,7 @@ jobs: 8.0.x dotnet-quality: 'ga' - name: Setup Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.x' - name: Setup dotnet-coverage @@ -187,17 +188,17 @@ jobs: snowflake_cloud_env: ${{ matrix.cloud_env }} net_version: ${{ matrix.dotnet }} - name: Upload Code Coverage Report - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: code-coverage-report + name: code-coverage-report_macos_${{ matrix.dotnet }}_${{ matrix.cloud_env }} path: Snowflake.Data.Tests/macos_${{ matrix.dotnet }}_${{ matrix.cloud_env }}_coverage.xml - name: Upload Test Performance Report - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: tests-performance + name: tests-performance_macos_${{ matrix.dotnet }}_${{ matrix.cloud_env }} path: Snowflake.Data.Tests/macos_${{ matrix.dotnet }}_${{ matrix.cloud_env }}_performance.csv - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: # without the token code cov may fail because of Github limits https://github.com/codecov/codecov-action/issues/557 token: ${{ secrets.CODE_COV_UPLOAD_TOKEN }} diff --git a/.github/workflows/snyk-issue.yml b/.github/workflows/snyk-issue.yml index 2a3f6226a..03ea86f03 100644 --- a/.github/workflows/snyk-issue.yml +++ b/.github/workflows/snyk-issue.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest steps: - name: checkout action - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: snowflakedb/whitesource-actions token: ${{ secrets.WHITESOURCE_ACTION_TOKEN }} diff --git a/.github/workflows/snyk-pr.yml b/.github/workflows/snyk-pr.yml index d625f5722..c2720832f 100644 --- a/.github/workflows/snyk-pr.yml +++ b/.github/workflows/snyk-pr.yml @@ -16,13 +16,13 @@ jobs: if: ${{ github.event.pull_request.user.login == 'sfc-gh-snyk-sca-sa' }} steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.ref }} fetch-depth: 0 - name: checkout action - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: snowflakedb/whitesource-actions token: ${{ secrets.WHITESOURCE_ACTION_TOKEN }} diff --git a/Snowflake.Data.Tests/IntegrationTests/ConnectionSinglePoolCacheAsyncIT.cs b/Snowflake.Data.Tests/IntegrationTests/ConnectionSinglePoolCacheAsyncIT.cs index 1b0ac0cf8..2adb1a1e0 100644 --- a/Snowflake.Data.Tests/IntegrationTests/ConnectionSinglePoolCacheAsyncIT.cs +++ b/Snowflake.Data.Tests/IntegrationTests/ConnectionSinglePoolCacheAsyncIT.cs @@ -205,7 +205,9 @@ static async Task InvalidConnectionTaskAsync(string connectionString, int times) { // intentionally not using await so the connection // will be disposed with invalid underlying session +#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed conn.OpenAsync(); +#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed }; // wait 100ms each time so the invalid sessions are generated // roughly at the same speed as connections for query tasks diff --git a/Snowflake.Data.Tests/IntegrationTests/SFDbAdaptorIT.cs b/Snowflake.Data.Tests/IntegrationTests/SFDbAdaptorIT.cs index 4f71b9b1e..c8f84786a 100755 --- a/Snowflake.Data.Tests/IntegrationTests/SFDbAdaptorIT.cs +++ b/Snowflake.Data.Tests/IntegrationTests/SFDbAdaptorIT.cs @@ -16,7 +16,7 @@ class SFDbAdaptorIT : SFBaseTest private SnowflakeDbCommand _command; [SetUp] - public void BeforeTest() + public new void BeforeTest() { _adapter = new SnowflakeDbDataAdapter(); _command = new SnowflakeDbCommand(); diff --git a/Snowflake.Data.Tests/IntegrationTests/SFDbFactoryIT.cs b/Snowflake.Data.Tests/IntegrationTests/SFDbFactoryIT.cs index 580f16f7f..a9fb3b43f 100644 --- a/Snowflake.Data.Tests/IntegrationTests/SFDbFactoryIT.cs +++ b/Snowflake.Data.Tests/IntegrationTests/SFDbFactoryIT.cs @@ -16,7 +16,7 @@ class SFDbFactoryIT : SFBaseTest DbConnection _connection; [SetUp] - public void BeforeTest() + public new void BeforeTest() { #if NETFRAMEWORK _factory = DbProviderFactories.GetFactory("Snowflake.Data"); @@ -35,7 +35,7 @@ public void BeforeTest() } [TearDown] - public void AfterTest() + public new void AfterTest() { _connection.Close(); } diff --git a/Snowflake.Data.Tests/Mock/MockRetryUntilRestTimeout.cs b/Snowflake.Data.Tests/Mock/MockRetryUntilRestTimeout.cs index 17b0ffcfc..928d44e1b 100644 --- a/Snowflake.Data.Tests/Mock/MockRetryUntilRestTimeout.cs +++ b/Snowflake.Data.Tests/Mock/MockRetryUntilRestTimeout.cs @@ -36,7 +36,11 @@ protected override async Task SendAsync(HttpRequestMessage _forceTimeoutForNonLoginRequestsOnly && !message.RequestUri.AbsolutePath.Equals(RestPath.SF_LOGIN_PATH)) { // Override the http timeout and set to 1ms to force all http request to timeout and retry + // Disable warning as this is the way to be compliant with netstandard2.0 + // API reference: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httprequestmessage?view=netstandard-2.0 +#pragma warning disable CS0618 // Type or member is obsolete message.Properties[BaseRestRequest.HTTP_REQUEST_TIMEOUT_KEY] = TimeSpan.FromTicks(0); +#pragma warning restore CS0618 // Type or member is obsolete } return await (base.SendAsync(message, restTimeout, externalCancellationToken).ConfigureAwait(false)); diff --git a/Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs b/Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs index fd70c80c9..6c665b778 100755 --- a/Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs +++ b/Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs @@ -30,7 +30,7 @@ class ArrowResultChunkTest internal static readonly RecordBatch RecordBatchWithNullValue = new RecordBatch.Builder() .Append("Col_Int32", false, col => col.Int32(array => array.AppendNull())) .Build(); - + [Test] public void TestResultFormatIsArrow() { @@ -59,7 +59,7 @@ public void TestNextReturnsFalseIfNoData() public void TestNextIteratesThroughAllRecordsOfOneBatch() { var chunk = new ArrowResultChunk(_recordBatchOne); - + for (var i = 0; i < RowCountBatchOne; ++i) { Assert.IsTrue(chunk.Next()); @@ -72,7 +72,7 @@ public void TestNextIteratesThroughAllRecordsOfTwoBatches() { var chunk = new ArrowResultChunk(_recordBatchOne); chunk.AddRecordBatch(_recordBatchTwo); - + for (var i = 0; i < RowCountBatchOne + RowCountBatchTwo; ++i) { Assert.IsTrue(chunk.Next()); @@ -87,30 +87,30 @@ public void TestRewindIteratesThroughAllRecordsOfBatchOne() // move to the end of the batch while (chunk.Next()) {} - + for (var i = 0; i < RowCountBatchOne; ++i) { Assert.IsTrue(chunk.Rewind()); } Assert.IsFalse(chunk.Rewind()); } - + [Test] public void TestRewindIteratesThroughAllRecordsOfTwoBatches() { var chunk = new ArrowResultChunk(_recordBatchOne); chunk.AddRecordBatch(_recordBatchTwo); - + // move to the end of the batch while (chunk.Next()) {} - + for (var i = 0; i < RowCountBatchOne + RowCountBatchTwo; ++i) { Assert.IsTrue(chunk.Rewind()); } Assert.IsFalse(chunk.Rewind()); } - + [Test] public void TestResetClearsChunkData() { @@ -121,14 +121,14 @@ public void TestResetClearsChunkData() rowCount = 2 }; var chunk = new ArrowResultChunk(_recordBatchOne); - + chunk.Reset(chunkInfo, 0); - + Assert.AreEqual(0, chunk.ChunkIndex); Assert.AreEqual(chunkInfo.url, chunk.Url); Assert.AreEqual(chunkInfo.rowCount, chunk.RowCount); } - + [Test] public void TestRowCountReturnsNumberOfRows() { @@ -144,16 +144,19 @@ public void TestGetChunkIndexReturnsFirstChunk() Assert.AreEqual(-1, chunk.ChunkIndex); } - + [Test] public void TestUnusedExtractCellThrowsNotSupportedException() { var chunk = new ArrowResultChunk(_recordBatchOne); Assert.Throws(() => chunk.ExtractCell(0)); + // Disable warning as we are testing the obsolete method behavior +#pragma warning disable CS0618 // Type or member is obsolete Assert.Throws(() => chunk.ExtractCell(0, 0)); +#pragma warning restore CS0618 // Type or member is obsolete } - + [Test] public void TestExtractCellReturnsNull() { @@ -192,7 +195,7 @@ public void TestExtractCellThrowsExceptionForNoneType() { var chunk = new ArrowResultChunk(_recordBatchOne); chunk.Next(); - + Assert.Throws(() => chunk.ExtractCell(0, SFDataType.None, 0)); } @@ -201,7 +204,7 @@ public void TestExtractCellReturnsDecimal() { var testValues = new decimal[] { 0, 100, -100, Decimal.MaxValue, Decimal.MinValue }; var sfType = SFDataType.FIXED; - + for (var scale = 0; scale <= 9; ++scale) { TestExtractCell(testValues, sfType, scale, (long)Math.Pow(10, scale)); @@ -219,7 +222,7 @@ public void TestExtractCellReturnsNumber64() TestExtractCell(testValues, sfType, scale, (long)Math.Pow(10, scale)); } } - + [Test] public void TestExtractCellReturnsNumber32() { @@ -229,9 +232,9 @@ public void TestExtractCellReturnsNumber32() for (var scale = 0; scale <= 9; ++scale) { TestExtractCell(testValues, sfType, scale, (long)Math.Pow(10, scale)); - } + } } - + [Test] public void TestExtractCellReturnsNumber16() { @@ -243,7 +246,7 @@ public void TestExtractCellReturnsNumber16() TestExtractCell(testValues, sfType, scale, (long)Math.Pow(10, scale)); } } - + [Test] public void TestExtractCellReturnsNumber8() { @@ -255,7 +258,7 @@ public void TestExtractCellReturnsNumber8() TestExtractCell(testValues, sfType, scale, (long)Math.Pow(10, scale)); } } - + [Test] public void TestExtractCellReturnsBoolean() { @@ -265,7 +268,7 @@ public void TestExtractCellReturnsBoolean() TestExtractCell(testValues, sfType, scale); } - + [Test] public void TestExtractCellReturnsReal() { @@ -275,7 +278,7 @@ public void TestExtractCellReturnsReal() TestExtractCell(testValues, sfType, scale); } - + [Test] public void TestExtractCellReturnsText() { @@ -289,7 +292,7 @@ public void TestExtractCellReturnsText() TestExtractCell(testValues, sfType, scale); } - + [Test] public void TestExtractCellReturnsArray() { @@ -332,7 +335,7 @@ public void TestExtractCellReturnsDate() TestExtractCell(testValues, sfType, scale); } - + [Test] public void TestExtractCellReturnsTime() { @@ -343,14 +346,14 @@ public void TestExtractCellReturnsTime() DateTime.Parse("9999-12-31 23:59:59.9999999") }; var sfType = SFDataType.TIME; - + for (var scale = 0; scale <= 8; ++scale) { var values = TruncateValues(testValues, scale); TestExtractCell(values, sfType, scale); - } + } } - + [Test] public void TestExtractCellReturnsTimestampTz() { @@ -364,14 +367,14 @@ public void TestExtractCellReturnsTimestampTz() DateTimeOffset.Parse("9999-12-31 23:59:59.9999999 +0000"), }; var sfType = SFDataType.TIMESTAMP_TZ; - + for (var scale = 0; scale <= 9; ++scale) { var values = TruncateValues(testValues, scale); TestExtractCell(values, sfType, scale); } } - + [Test] public void TestExtractCellReturnsTimestampLtz() { @@ -389,7 +392,7 @@ public void TestExtractCellReturnsTimestampLtz() TestExtractCell(values, sfType, scale); } } - + [Test] public void TestExtractCellReturnsTimestampNtz() { @@ -400,14 +403,14 @@ public void TestExtractCellReturnsTimestampNtz() DateTime.Parse("9999-12-31 23:59:59.9999999") }; var sfType = SFDataType.TIMESTAMP_NTZ; - + for (var scale = 0; scale <= 9; ++scale) { var values = TruncateValues(testValues, scale); TestExtractCell(values, sfType, scale); } } - + void TestExtractCell(IEnumerable testValues, SFDataType sfType, long scale, long divider = 0) { var recordBatch = PrepareRecordBatch(sfType, scale, testValues); @@ -429,15 +432,15 @@ public static RecordBatch PrepareRecordBatch(SFDataType sfType, long scale, obje case SFDataType.FIXED: switch (values) { - case decimal[] val: + case decimal[] val: column = new Decimal128Array.Builder(new Decimal128Type(100, (int)scale)) .AppendRange(val.Select(v => v / (decimal)Math.Pow(10, scale))) .Build(); break; - case long[] val: + case long[] val: column = new Int64Array.Builder().AppendRange(val).Build(); break; - case int[] val: + case int[] val: column = new Int32Array.Builder().AppendRange(val).Build(); break; case short[] val: @@ -481,7 +484,7 @@ public static RecordBatch PrepareRecordBatch(SFDataType sfType, long scale, obje } break; - case SFDataType.BINARY: + case SFDataType.BINARY: column = new BinaryArray.Builder() .AppendRange(values as byte[][]) .Build(); @@ -615,7 +618,7 @@ public static RecordBatch PrepareRecordBatch(SFDataType sfType, long scale, obje .Append("TestColumn", false, column) .Build(); } - + private static long ConvertTicksToInt64(long ticks, long scale) { long ticksFromEpoch = ticks - SFDataConverter.UnixEpoch.Ticks; @@ -624,7 +627,7 @@ private static long ConvertTicksToInt64(long ticks, long scale) else return ticksFromEpoch * (long)Math.Pow(10, scale - 7); } - + public static DateTime[] TruncateValues(DateTime[] testValues, int scale) { DateTime[] ret = new DateTime[testValues.Length]; diff --git a/Snowflake.Data.Tests/UnitTests/SFAzureClientTest.cs b/Snowflake.Data.Tests/UnitTests/SFAzureClientTest.cs index f83351f99..a1c791071 100644 --- a/Snowflake.Data.Tests/UnitTests/SFAzureClientTest.cs +++ b/Snowflake.Data.Tests/UnitTests/SFAzureClientTest.cs @@ -60,10 +60,10 @@ class SFAzureClientTest : SFBaseTest SFFileMetadata _fileMetadata; [SetUp] - public void BeforeTest() + public new void BeforeTest() { t_downloadFileName = TestNameWithWorker + "_mockFileName.txt"; - + _fileMetadata = new SFFileMetadata() { stageInfo = new PutGetStageInfo() diff --git a/Snowflake.Data.Tests/UnitTests/SFGCSClientTest.cs b/Snowflake.Data.Tests/UnitTests/SFGCSClientTest.cs index da7c0cdf4..925ce4c98 100644 --- a/Snowflake.Data.Tests/UnitTests/SFGCSClientTest.cs +++ b/Snowflake.Data.Tests/UnitTests/SFGCSClientTest.cs @@ -53,10 +53,10 @@ class SFGCSClientTest : SFBaseTest SFFileMetadata _fileMetadata; [SetUp] - public void BeforeTest() + public new void BeforeTest() { t_downloadFileName = TestNameWithWorker + "_mockFileName.txt"; - + _fileMetadata = new SFFileMetadata() { stageInfo = new PutGetStageInfo() diff --git a/Snowflake.Data.Tests/UnitTests/SFRemoteStorageClientTest.cs b/Snowflake.Data.Tests/UnitTests/SFRemoteStorageClientTest.cs index fa7df6250..bef52a937 100644 --- a/Snowflake.Data.Tests/UnitTests/SFRemoteStorageClientTest.cs +++ b/Snowflake.Data.Tests/UnitTests/SFRemoteStorageClientTest.cs @@ -71,7 +71,7 @@ class SFRemoteStorageClientTest : SFBaseTest const bool IsAsync = true; [SetUp] - public void BeforeTest() + public new void BeforeTest() { t_realSourceFilePath = TestNameWithWorker + "_realSrcFilePath.txt"; t_downloadFileName = TestNameWithWorker + "_mockFileName.txt"; @@ -122,7 +122,7 @@ public void BeforeTest() } [TearDown] - public void AfterTest() + public new void AfterTest() { // Delete temporary files from upload if (File.Exists(_fileMetadata.realSrcFilePath)) diff --git a/Snowflake.Data.Tests/UnitTests/SFReusableChunkTest.cs b/Snowflake.Data.Tests/UnitTests/SFReusableChunkTest.cs index 4ca4eec79..6f021994b 100755 --- a/Snowflake.Data.Tests/UnitTests/SFReusableChunkTest.cs +++ b/Snowflake.Data.Tests/UnitTests/SFReusableChunkTest.cs @@ -23,13 +23,15 @@ public void TestExtractCellWithRowParameterReadsAllRows() string data = "[ [\"1\", \"1.234\", \"abcde\"], [\"2\", \"5.678\", \"fghi\"] ]"; var chunk = PrepareChunkAsync(data, 3, 2).Result; +#pragma warning disable CS0618 // Type or member is obsolete Assert.AreEqual("1", chunk.ExtractCell(0,0).SafeToString()); Assert.AreEqual("1.234", chunk.ExtractCell(0, 1).SafeToString()); Assert.AreEqual("abcde", chunk.ExtractCell(0, 2).SafeToString()); - + Assert.AreEqual("2", chunk.ExtractCell(1, 0).SafeToString()); Assert.AreEqual("5.678", chunk.ExtractCell(1, 1).SafeToString()); Assert.AreEqual("fghi", chunk.ExtractCell(1, 2).SafeToString()); +#pragma warning restore CS0618 // Type or member is obsolete } [Test] @@ -42,7 +44,7 @@ public void TestSimpleChunk() Assert.AreEqual("1", chunk.ExtractCell(0).SafeToString()); Assert.AreEqual("1.234", chunk.ExtractCell(1).SafeToString()); Assert.AreEqual("abcde", chunk.ExtractCell(2).SafeToString()); - + chunk.Next(); Assert.AreEqual("2", chunk.ExtractCell(0).SafeToString()); Assert.AreEqual("5.678", chunk.ExtractCell(1).SafeToString()); @@ -59,7 +61,7 @@ public void TestChunkWithNull() Assert.AreEqual(null, chunk.ExtractCell(0).SafeToString()); Assert.AreEqual("1.234", chunk.ExtractCell(1).SafeToString()); Assert.AreEqual(null, chunk.ExtractCell(2).SafeToString()); - + chunk.Next(); Assert.AreEqual("2", chunk.ExtractCell(0).SafeToString()); Assert.AreEqual(null, chunk.ExtractCell(1).SafeToString()); @@ -76,7 +78,7 @@ public void TestChunkWithDate() Assert.AreEqual(null, chunk.ExtractCell(0).SafeToString()); Assert.AreEqual("2019-08-21T11:58:00", chunk.ExtractCell(1).SafeToString()); Assert.AreEqual(null, chunk.ExtractCell(2).SafeToString()); - + chunk.Next(); Assert.AreEqual("2", chunk.ExtractCell(0).SafeToString()); Assert.AreEqual(null, chunk.ExtractCell(1).SafeToString()); @@ -93,7 +95,7 @@ public void TestChunkWithEscape() Assert.AreEqual("\\åäö\nÅÄÖ\r", chunk.ExtractCell(0).SafeToString()); Assert.AreEqual("1.234", chunk.ExtractCell(1).SafeToString()); Assert.AreEqual(null, chunk.ExtractCell(2).SafeToString()); - + chunk.Next(); Assert.AreEqual("2", chunk.ExtractCell(0).SafeToString()); Assert.AreEqual(null, chunk.ExtractCell(1).SafeToString()); @@ -111,7 +113,7 @@ public void TestChunkWithLongString() Assert.AreEqual("åäö\nÅÄÖ\r", chunk.ExtractCell(0).SafeToString()); Assert.AreEqual("1.234", chunk.ExtractCell(1).SafeToString()); Assert.AreEqual(null, chunk.ExtractCell(2).SafeToString()); - + chunk.Next(); Assert.AreEqual("2", chunk.ExtractCell(0).SafeToString()); Assert.AreEqual(null, chunk.ExtractCell(1).SafeToString()); @@ -140,7 +142,7 @@ public async Task TestParserError2() { // Unterminated string string data = "[ [\"åäö"; - + try { await PrepareChunkAsync(data, 1, 1); @@ -177,7 +179,7 @@ public void TestNextIteratesThroughAllRecords() } Assert.IsFalse(chunk.Next()); } - + [Test] public void TestRewindIteratesThroughAllRecords() { @@ -190,14 +192,14 @@ public void TestRewindIteratesThroughAllRecords() chunk.Next(); } chunk.Next(); - + for (var i = 0; i < RowCount; ++i) { Assert.IsTrue(chunk.Rewind()); } Assert.IsFalse(chunk.Rewind()); } - + [Test] public void TestResetClearsChunkData() { @@ -211,14 +213,14 @@ public void TestResetClearsChunkData() uncompressedSize = 100, rowCount = 200 }; - + chunk.Reset(chunkInfo, 0); - + Assert.AreEqual(0, chunk.ChunkIndex); Assert.AreEqual(chunkInfo.url, chunk.Url); Assert.AreEqual(chunkInfo.rowCount, chunk.RowCount); } - + private async Task PrepareChunkAsync(string stringData, int colCount, int rowCount) { byte[] bytes = Encoding.UTF8.GetBytes(stringData); @@ -234,7 +236,7 @@ private async Task PrepareChunkAsync(string stringData, int col SFReusableChunk chunk = new SFReusableChunk(colCount); chunk.Reset(chunkInfo, 0); - + await parser.ParseChunk(chunk); return chunk; } diff --git a/Snowflake.Data.Tests/UnitTests/SFS3ClientTest.cs b/Snowflake.Data.Tests/UnitTests/SFS3ClientTest.cs index da3baf531..50faae758 100644 --- a/Snowflake.Data.Tests/UnitTests/SFS3ClientTest.cs +++ b/Snowflake.Data.Tests/UnitTests/SFS3ClientTest.cs @@ -78,10 +78,10 @@ class SFS3ClientTest : SFBaseTest AmazonS3Config _clientConfig; [SetUp] - public void BeforeTest() + public new void BeforeTest() { t_downloadFileName = TestNameWithWorker + "_mockFileName.txt"; - + _fileMetadata = new SFFileMetadata() { stageInfo = new PutGetStageInfo() @@ -274,7 +274,7 @@ public async Task TestUploadFileAsync(string requestKey, ResultStatus expectedRe iv = MockS3Client.AmzIV, key = MockS3Client.AmzKey, matDesc = MockS3Client.AmzMatdesc - }, + }, _cancellationToken).ConfigureAwait(false); // Assert @@ -331,7 +331,7 @@ public async Task TestDownloadFileAsync(string requestKey, ResultStatus expected _client = new SFS3Client(_fileMetadata.stageInfo, MaxRetry, Parallel, _proxyCredentials, mockAmazonS3Client.Object); _fileMetadata.client = _client; _fileMetadata.stageInfo.location = requestKey; - + // Act await _client.DownloadFileAsync(_fileMetadata, t_downloadFileName, Parallel, _cancellationToken).ConfigureAwait(false); diff --git a/Snowflake.Data.Tests/Util/SessionParameterAlterer.cs b/Snowflake.Data.Tests/Util/SessionParameterAlterer.cs index 3a31dd508..f95d709c7 100644 --- a/Snowflake.Data.Tests/Util/SessionParameterAlterer.cs +++ b/Snowflake.Data.Tests/Util/SessionParameterAlterer.cs @@ -26,7 +26,7 @@ public static void SetResultFormat(IDbConnection conn, ResultFormat resultFormat { if (ex.Message.Contains("invalid parameter")) return; - throw ex; + throw; } } @@ -42,7 +42,7 @@ public static void RestoreResultFormat(IDbConnection conn) { if (ex.Message.Contains("invalid parameter")) return; - throw ex; + throw; } } diff --git a/Snowflake.Data.Tests/Util/TestDataHelpers.cs b/Snowflake.Data.Tests/Util/TestDataHelpers.cs index 170151c7f..e90642517 100644 --- a/Snowflake.Data.Tests/Util/TestDataHelpers.cs +++ b/Snowflake.Data.Tests/Util/TestDataHelpers.cs @@ -1,3 +1,4 @@ +#nullable enable using System.Linq; using System.Text; @@ -15,29 +16,29 @@ internal static string ByteArrayToHexString(byte[] ba) internal static T?[] NullEachNthValue(T?[] sourceColumn, int nullEachNthItem) where T : struct { - var destination = new T?[sourceColumn.Length]; + var destination = new T?[sourceColumn.Length]; foreach (var rowIndex in Enumerable.Range(0, sourceColumn.Length)) destination[rowIndex] = rowIndex % nullEachNthItem == 0 ? null : sourceColumn[rowIndex]; return destination; } - + internal static T?[] NullEachNthValue(T?[] sourceColumn, int nullEachNthItem) where T : class { - var destination = new T?[sourceColumn.Length]; + var destination = new T?[sourceColumn.Length]; foreach (var rowIndex in Enumerable.Range(0, sourceColumn.Length)) destination[rowIndex] = rowIndex % nullEachNthItem == 0 ? null : sourceColumn[rowIndex]; return destination; } - internal static object[] NullEachNthValueBesidesFirst(object[] sourceRow, int nullEachNthItem) + internal static object?[] NullEachNthValueBesidesFirst(object?[] sourceRow, int nullEachNthItem) { - var ret = new object[sourceRow.Length]; + object?[] ret = new object[sourceRow.Length]; foreach (var column in Enumerable.Range(0, sourceRow.Length)) ret[column] = column > 0 && nullEachNthItem % (column + 1) == 0 ? null : sourceRow[column]; return ret; } - - internal static string RemoveBlanks(string text) + + internal static string RemoveBlanks(string text) => text.Replace("\n", "").Replace(" ", ""); } diff --git a/Snowflake.Data/Core/HttpUtil.cs b/Snowflake.Data/Core/HttpUtil.cs index 531e76fd7..558ce252f 100755 --- a/Snowflake.Data/Core/HttpUtil.cs +++ b/Snowflake.Data/Core/HttpUtil.cs @@ -14,6 +14,7 @@ using System.Security.Authentication; using System.Linq; using Snowflake.Data.Core.Authenticator; +using static Snowflake.Data.Core.SFRestRequest; namespace Snowflake.Data.Core { @@ -87,7 +88,7 @@ public sealed class HttpUtil private HttpUtil() { - // This value is used by AWS SDK and can cause deadlock, + // This value is used by AWS SDK and can cause deadlock, // so we need to increase the default value of 2 // See: https://github.com/aws/aws-sdk-net/issues/152 ServicePointManager.DefaultConnectionLimit = 50; @@ -181,15 +182,15 @@ internal HttpMessageHandler SetupCustomHttpHandler(HttpClientConfig config) { // Get the original entry entry = bypassList[i].Trim(); - // . -> [.] because . means any char + // . -> [.] because . means any char entry = entry.Replace(".", "[.]"); // * -> .* because * is a quantifier and need a char or group to apply to entry = entry.Replace("*", ".*"); - + entry = entry.StartsWith("^") ? entry : $"^{entry}"; - + entry = entry.EndsWith("$") ? entry : $"{entry}$"; - + // Replace with the valid entry syntax bypassList[i] = entry; @@ -357,8 +358,8 @@ protected override async Task SendAsync(HttpRequestMessage p.UseNagleAlgorithm = false; // Saves about 200 ms per request p.ConnectionLimit = 20; // Default value is 2, we need more connections for performing multiple parallel queries - TimeSpan httpTimeout = (TimeSpan)requestMessage.Properties[SFRestRequest.HTTP_REQUEST_TIMEOUT_KEY]; - TimeSpan restTimeout = (TimeSpan)requestMessage.Properties[SFRestRequest.REST_REQUEST_TIMEOUT_KEY]; + TimeSpan httpTimeout = (TimeSpan)requestMessage.Properties[BaseRestRequest.HTTP_REQUEST_TIMEOUT_KEY]; + TimeSpan restTimeout = (TimeSpan)requestMessage.Properties[BaseRestRequest.REST_REQUEST_TIMEOUT_KEY]; if (logger.IsDebugEnabled()) { @@ -384,7 +385,7 @@ protected override async Task SendAsync(HttpRequestMessage if (httpTimeout.Ticks == 0) childCts.Cancel(); else - childCts.CancelAfter(httpTimeout); + childCts.CancelAfter(httpTimeout); } response = await base.SendAsync(requestMessage, childCts == null ? cancellationToken : childCts.Token).ConfigureAwait(false); @@ -503,7 +504,7 @@ static public bool isRetryableHTTPCode(int statusCode, bool forceRetryOn404) { if (forceRetryOn404 && statusCode == 404) return true; - return (500 <= statusCode) && (statusCode < 600) || + return (500 <= statusCode && statusCode < 600) || // Forbidden (statusCode == 403) || // Request timeout diff --git a/snowflake-connector-net.sln.DotSettings b/snowflake-connector-net.sln.DotSettings index c65f34a64..b3644095f 100644 --- a/snowflake-connector-net.sln.DotSettings +++ b/snowflake-connector-net.sln.DotSettings @@ -5,4 +5,9 @@ <Policy Inspect="True" Prefix="s_" Suffix="" Style="aaBb"><ExtraRule Prefix="t_" Suffix="" Style="aaBb" /></Policy> <Policy Inspect="True" Prefix="s_" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy><Descriptor Staticness="Static" AccessRightKinds="Private" Description="Static readonly fields (private)"><ElementKinds><Kind Name="READONLY_FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="s_" Suffix="" Style="aaBb" /></Policy> + <Policy><Descriptor Staticness="Any" AccessRightKinds="Any" Description="Local constants"><ElementKinds><Kind Name="LOCAL_CONSTANT" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></Policy> + <Policy><Descriptor Staticness="Static" AccessRightKinds="Protected, ProtectedInternal, Internal, Public, PrivateProtected" Description="Static readonly fields (not private)"><ElementKinds><Kind Name="READONLY_FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></Policy> + <Policy><Descriptor Staticness="Static" AccessRightKinds="Private" Description="Static fields (private)"><ElementKinds><Kind Name="FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="s_" Suffix="" Style="aaBb"><ExtraRule Prefix="t_" Suffix="" Style="aaBb" /></Policy></Policy> + True