From 85ed6044c31c0eb413b4f3256f1c4b7b9f026f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Thu, 16 Mar 2023 09:06:50 +0100 Subject: [PATCH] [PersistentStorage.FileSystem] Nullable --- ...metry.PersistentStorage.Abstractions.csproj | 4 ---- .../.publicApi/net462/PublicAPI.Shipped.txt | 1 + .../.publicApi/net462/PublicAPI.Unshipped.txt | 18 +++++++++--------- .../.publicApi/net6.0/PublicAPI.Shipped.txt | 1 + .../.publicApi/net6.0/PublicAPI.Unshipped.txt | 18 +++++++++--------- .../netstandard2.0/PublicAPI.Shipped.txt | 1 + .../netstandard2.0/PublicAPI.Unshipped.txt | 18 +++++++++--------- .../FileBlob.cs | 2 +- .../FileBlobProvider.cs | 10 +++++----- ...lemetry.PersistentStorage.FileSystem.csproj | 1 + .../FileBlobProviderTests.cs | 6 ------ .../FileBlobTests.cs | 7 ++++--- ...y.PersistentStorage.FileSystem.Tests.csproj | 1 + 13 files changed, 42 insertions(+), 46 deletions(-) diff --git a/src/OpenTelemetry.PersistentStorage.Abstractions/OpenTelemetry.PersistentStorage.Abstractions.csproj b/src/OpenTelemetry.PersistentStorage.Abstractions/OpenTelemetry.PersistentStorage.Abstractions.csproj index 1e434c0cb4..3c2fc65c5c 100644 --- a/src/OpenTelemetry.PersistentStorage.Abstractions/OpenTelemetry.PersistentStorage.Abstractions.csproj +++ b/src/OpenTelemetry.PersistentStorage.Abstractions/OpenTelemetry.PersistentStorage.Abstractions.csproj @@ -7,10 +7,6 @@ net6.0;$(TargetFrameworks) OpenTelemetry Persistent Storage Abstractions Extensions.PersistentStorage.Abstractions- - $(NoWarn),CA1031 - - - $(NoWarn),1591 enable true diff --git a/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/net462/PublicAPI.Shipped.txt b/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/net462/PublicAPI.Shipped.txt index e69de29bb2..7dc5c58110 100644 --- a/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/net462/PublicAPI.Shipped.txt +++ b/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/net462/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/net462/PublicAPI.Unshipped.txt b/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/net462/PublicAPI.Unshipped.txt index d653ae4116..a3ca421004 100644 --- a/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/net462/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/net462/PublicAPI.Unshipped.txt @@ -1,15 +1,15 @@ OpenTelemetry.PersistentStorage.FileSystem.FileBlob -OpenTelemetry.PersistentStorage.FileSystem.FileBlob.FileBlob(string fullPath) -> void -OpenTelemetry.PersistentStorage.FileSystem.FileBlob.FullPath.get -> string +OpenTelemetry.PersistentStorage.FileSystem.FileBlob.FileBlob(string! fullPath) -> void +OpenTelemetry.PersistentStorage.FileSystem.FileBlob.FullPath.get -> string! OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.Dispose() -> void -OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.FileBlobProvider(string path, long maxSizeInBytes = 52428800, int maintenancePeriodInMilliseconds = 120000, long retentionPeriodInMilliseconds = 172800000, int writeTimeoutInMilliseconds = 60000) -> void +OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.FileBlobProvider(string! path, long maxSizeInBytes = 52428800, int maintenancePeriodInMilliseconds = 120000, long retentionPeriodInMilliseconds = 172800000, int writeTimeoutInMilliseconds = 60000) -> void override OpenTelemetry.PersistentStorage.FileSystem.FileBlob.OnTryDelete() -> bool override OpenTelemetry.PersistentStorage.FileSystem.FileBlob.OnTryLease(int leasePeriodMilliseconds) -> bool -override OpenTelemetry.PersistentStorage.FileSystem.FileBlob.OnTryRead(out byte[] buffer) -> bool -override OpenTelemetry.PersistentStorage.FileSystem.FileBlob.OnTryWrite(byte[] buffer, int leasePeriodMilliseconds = 0) -> bool -override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnGetBlobs() -> System.Collections.Generic.IEnumerable -override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnTryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, out OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob blob) -> bool -override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnTryCreateBlob(byte[] buffer, out OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob blob) -> bool -override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnTryGetBlob(out OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob blob) -> bool +override OpenTelemetry.PersistentStorage.FileSystem.FileBlob.OnTryRead(out byte[]? buffer) -> bool +override OpenTelemetry.PersistentStorage.FileSystem.FileBlob.OnTryWrite(byte[]! buffer, int leasePeriodMilliseconds = 0) -> bool +override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnGetBlobs() -> System.Collections.Generic.IEnumerable! +override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnTryCreateBlob(byte[]! buffer, int leasePeriodMilliseconds, out OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool +override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnTryCreateBlob(byte[]! buffer, out OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool +override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnTryGetBlob(out OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool virtual OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.Dispose(bool disposing) -> void diff --git a/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/net6.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/net6.0/PublicAPI.Shipped.txt index e69de29bb2..7dc5c58110 100644 --- a/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/net6.0/PublicAPI.Shipped.txt +++ b/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/net6.0/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/net6.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/net6.0/PublicAPI.Unshipped.txt index d653ae4116..a3ca421004 100644 --- a/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/net6.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/net6.0/PublicAPI.Unshipped.txt @@ -1,15 +1,15 @@ OpenTelemetry.PersistentStorage.FileSystem.FileBlob -OpenTelemetry.PersistentStorage.FileSystem.FileBlob.FileBlob(string fullPath) -> void -OpenTelemetry.PersistentStorage.FileSystem.FileBlob.FullPath.get -> string +OpenTelemetry.PersistentStorage.FileSystem.FileBlob.FileBlob(string! fullPath) -> void +OpenTelemetry.PersistentStorage.FileSystem.FileBlob.FullPath.get -> string! OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.Dispose() -> void -OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.FileBlobProvider(string path, long maxSizeInBytes = 52428800, int maintenancePeriodInMilliseconds = 120000, long retentionPeriodInMilliseconds = 172800000, int writeTimeoutInMilliseconds = 60000) -> void +OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.FileBlobProvider(string! path, long maxSizeInBytes = 52428800, int maintenancePeriodInMilliseconds = 120000, long retentionPeriodInMilliseconds = 172800000, int writeTimeoutInMilliseconds = 60000) -> void override OpenTelemetry.PersistentStorage.FileSystem.FileBlob.OnTryDelete() -> bool override OpenTelemetry.PersistentStorage.FileSystem.FileBlob.OnTryLease(int leasePeriodMilliseconds) -> bool -override OpenTelemetry.PersistentStorage.FileSystem.FileBlob.OnTryRead(out byte[] buffer) -> bool -override OpenTelemetry.PersistentStorage.FileSystem.FileBlob.OnTryWrite(byte[] buffer, int leasePeriodMilliseconds = 0) -> bool -override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnGetBlobs() -> System.Collections.Generic.IEnumerable -override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnTryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, out OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob blob) -> bool -override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnTryCreateBlob(byte[] buffer, out OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob blob) -> bool -override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnTryGetBlob(out OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob blob) -> bool +override OpenTelemetry.PersistentStorage.FileSystem.FileBlob.OnTryRead(out byte[]? buffer) -> bool +override OpenTelemetry.PersistentStorage.FileSystem.FileBlob.OnTryWrite(byte[]! buffer, int leasePeriodMilliseconds = 0) -> bool +override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnGetBlobs() -> System.Collections.Generic.IEnumerable! +override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnTryCreateBlob(byte[]! buffer, int leasePeriodMilliseconds, out OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool +override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnTryCreateBlob(byte[]! buffer, out OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool +override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnTryGetBlob(out OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool virtual OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.Dispose(bool disposing) -> void diff --git a/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/netstandard2.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/netstandard2.0/PublicAPI.Shipped.txt index e69de29bb2..7dc5c58110 100644 --- a/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/netstandard2.0/PublicAPI.Shipped.txt +++ b/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/netstandard2.0/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt index d653ae4116..a3ca421004 100644 --- a/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.PersistentStorage.FileSystem/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt @@ -1,15 +1,15 @@ OpenTelemetry.PersistentStorage.FileSystem.FileBlob -OpenTelemetry.PersistentStorage.FileSystem.FileBlob.FileBlob(string fullPath) -> void -OpenTelemetry.PersistentStorage.FileSystem.FileBlob.FullPath.get -> string +OpenTelemetry.PersistentStorage.FileSystem.FileBlob.FileBlob(string! fullPath) -> void +OpenTelemetry.PersistentStorage.FileSystem.FileBlob.FullPath.get -> string! OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.Dispose() -> void -OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.FileBlobProvider(string path, long maxSizeInBytes = 52428800, int maintenancePeriodInMilliseconds = 120000, long retentionPeriodInMilliseconds = 172800000, int writeTimeoutInMilliseconds = 60000) -> void +OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.FileBlobProvider(string! path, long maxSizeInBytes = 52428800, int maintenancePeriodInMilliseconds = 120000, long retentionPeriodInMilliseconds = 172800000, int writeTimeoutInMilliseconds = 60000) -> void override OpenTelemetry.PersistentStorage.FileSystem.FileBlob.OnTryDelete() -> bool override OpenTelemetry.PersistentStorage.FileSystem.FileBlob.OnTryLease(int leasePeriodMilliseconds) -> bool -override OpenTelemetry.PersistentStorage.FileSystem.FileBlob.OnTryRead(out byte[] buffer) -> bool -override OpenTelemetry.PersistentStorage.FileSystem.FileBlob.OnTryWrite(byte[] buffer, int leasePeriodMilliseconds = 0) -> bool -override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnGetBlobs() -> System.Collections.Generic.IEnumerable -override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnTryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, out OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob blob) -> bool -override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnTryCreateBlob(byte[] buffer, out OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob blob) -> bool -override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnTryGetBlob(out OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob blob) -> bool +override OpenTelemetry.PersistentStorage.FileSystem.FileBlob.OnTryRead(out byte[]? buffer) -> bool +override OpenTelemetry.PersistentStorage.FileSystem.FileBlob.OnTryWrite(byte[]! buffer, int leasePeriodMilliseconds = 0) -> bool +override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnGetBlobs() -> System.Collections.Generic.IEnumerable! +override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnTryCreateBlob(byte[]! buffer, int leasePeriodMilliseconds, out OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool +override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnTryCreateBlob(byte[]! buffer, out OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool +override OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.OnTryGetBlob(out OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob? blob) -> bool virtual OpenTelemetry.PersistentStorage.FileSystem.FileBlobProvider.Dispose(bool disposing) -> void diff --git a/src/OpenTelemetry.PersistentStorage.FileSystem/FileBlob.cs b/src/OpenTelemetry.PersistentStorage.FileSystem/FileBlob.cs index 3e07a4c1de..2b18bb87a4 100644 --- a/src/OpenTelemetry.PersistentStorage.FileSystem/FileBlob.cs +++ b/src/OpenTelemetry.PersistentStorage.FileSystem/FileBlob.cs @@ -40,7 +40,7 @@ public FileBlob(string fullPath) public string FullPath { get; private set; } - protected override bool OnTryRead([NotNullWhen(true)] out byte[] buffer) + protected override bool OnTryRead([NotNullWhen(true)] out byte[]? buffer) { try { diff --git a/src/OpenTelemetry.PersistentStorage.FileSystem/FileBlobProvider.cs b/src/OpenTelemetry.PersistentStorage.FileSystem/FileBlobProvider.cs index 1fcc2e2c8e..cf0477980d 100644 --- a/src/OpenTelemetry.PersistentStorage.FileSystem/FileBlobProvider.cs +++ b/src/OpenTelemetry.PersistentStorage.FileSystem/FileBlobProvider.cs @@ -137,28 +137,28 @@ protected override IEnumerable OnGetBlobs() } } - protected override bool OnTryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, [NotNullWhen(true)] out PersistentBlob blob) + protected override bool OnTryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, [NotNullWhen(true)] out PersistentBlob? blob) { blob = this.CreateFileBlob(buffer, leasePeriodMilliseconds); return blob != null; } - protected override bool OnTryCreateBlob(byte[] buffer, [NotNullWhen(true)] out PersistentBlob blob) + protected override bool OnTryCreateBlob(byte[] buffer, [NotNullWhen(true)] out PersistentBlob? blob) { blob = this.CreateFileBlob(buffer); return blob != null; } - protected override bool OnTryGetBlob([NotNullWhen(true)] out PersistentBlob blob) + protected override bool OnTryGetBlob([NotNullWhen(true)] out PersistentBlob? blob) { blob = this.OnGetBlobs().FirstOrDefault(); return blob != null; } - private void OnMaintenanceEvent(object source, ElapsedEventArgs e) + private void OnMaintenanceEvent(object? source, ElapsedEventArgs e) { try { @@ -191,7 +191,7 @@ private bool CheckStorageSize() return true; } - private PersistentBlob CreateFileBlob(byte[] buffer, int leasePeriodMilliseconds = 0) + private PersistentBlob? CreateFileBlob(byte[] buffer, int leasePeriodMilliseconds = 0) { if (!this.CheckStorageSize()) { diff --git a/src/OpenTelemetry.PersistentStorage.FileSystem/OpenTelemetry.PersistentStorage.FileSystem.csproj b/src/OpenTelemetry.PersistentStorage.FileSystem/OpenTelemetry.PersistentStorage.FileSystem.csproj index 9532d09d8c..9deb66221d 100644 --- a/src/OpenTelemetry.PersistentStorage.FileSystem/OpenTelemetry.PersistentStorage.FileSystem.csproj +++ b/src/OpenTelemetry.PersistentStorage.FileSystem/OpenTelemetry.PersistentStorage.FileSystem.csproj @@ -11,6 +11,7 @@ $(NoWarn),1591 + enable diff --git a/test/OpenTelemetry.PersistentStorage.FileSystem.Tests/FileBlobProviderTests.cs b/test/OpenTelemetry.PersistentStorage.FileSystem.Tests/FileBlobProviderTests.cs index aee39ba1d5..0a697050fe 100644 --- a/test/OpenTelemetry.PersistentStorage.FileSystem.Tests/FileBlobProviderTests.cs +++ b/test/OpenTelemetry.PersistentStorage.FileSystem.Tests/FileBlobProviderTests.cs @@ -66,12 +66,6 @@ public void FileBlobProvider_CreateBlobReturnsNullIfblobProviderIsFull() testDirectory.Delete(true); } - [Fact] - public void FileBlobProvider_PathIsRequired() - { - Assert.Throws(() => new FileBlobProvider(null)); - } - [Fact] public void FileBlobProvider_TestRetentionPeriod() { diff --git a/test/OpenTelemetry.PersistentStorage.FileSystem.Tests/FileBlobTests.cs b/test/OpenTelemetry.PersistentStorage.FileSystem.Tests/FileBlobTests.cs index ede8b0d2d9..8c6aeb938b 100644 --- a/test/OpenTelemetry.PersistentStorage.FileSystem.Tests/FileBlobTests.cs +++ b/test/OpenTelemetry.PersistentStorage.FileSystem.Tests/FileBlobTests.cs @@ -14,6 +14,7 @@ // limitations under the License. // +using System; using System.IO; using System.Text; using System.Threading; @@ -184,9 +185,9 @@ public void FileBlobTests_LeaseTimeIsUpdatedWhenLeasingAlreadyLeasedFile() [Fact] public void FileBlobTests_FailedWrite() { - var testFile = new FileInfo(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())); - FileBlob blob = new FileBlob(testFile.FullName); + var nonExistingPath = Path.Combine("FakePath:/", Path.GetRandomFileName()); + FileBlob blob = new FileBlob(nonExistingPath); - Assert.False(blob.TryWrite(null)); + Assert.False(blob.TryWrite(Array.Empty())); } } diff --git a/test/OpenTelemetry.PersistentStorage.FileSystem.Tests/OpenTelemetry.PersistentStorage.FileSystem.Tests.csproj b/test/OpenTelemetry.PersistentStorage.FileSystem.Tests/OpenTelemetry.PersistentStorage.FileSystem.Tests.csproj index 76d872a709..4e658387ac 100644 --- a/test/OpenTelemetry.PersistentStorage.FileSystem.Tests/OpenTelemetry.PersistentStorage.FileSystem.Tests.csproj +++ b/test/OpenTelemetry.PersistentStorage.FileSystem.Tests/OpenTelemetry.PersistentStorage.FileSystem.Tests.csproj @@ -4,6 +4,7 @@ net7.0;net6.0 $(TargetFrameworks);net462 + enable