Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PersistentStorage.FileSystem] Nullable #1085

Merged
merged 2 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
<TargetFrameworks Condition="'$(Configuration)' == 'Debug'">net6.0;$(TargetFrameworks)</TargetFrameworks> <!-- Added just to get proper nullable analysis in IDE -->
<Description>OpenTelemetry Persistent Storage Abstractions</Description>
<MinVerTagPrefix>Extensions.PersistentStorage.Abstractions-</MinVerTagPrefix>
<NoWarn>$(NoWarn),CA1031</NoWarn>
</PropertyGroup>

<PropertyGroup>
<NoWarn>$(NoWarn),1591</NoWarn>
<Nullable>enable</Nullable>
<EnableAnalysis>true</EnableAnalysis>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#nullable enable
Original file line number Diff line number Diff line change
@@ -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<OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob>
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<OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob!>!
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#nullable enable
Original file line number Diff line number Diff line change
@@ -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<OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob>
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<OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob!>!
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#nullable enable
Original file line number Diff line number Diff line change
@@ -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<OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob>
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<OpenTelemetry.PersistentStorage.Abstractions.PersistentBlob!>!
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,28 +137,28 @@ protected override IEnumerable<PersistentBlob> 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
{
Expand Down Expand Up @@ -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())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<PropertyGroup>
<NoWarn>$(NoWarn),1591</NoWarn>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ public void FileBlobProvider_CreateBlobReturnsNullIfblobProviderIsFull()
testDirectory.Delete(true);
}

[Fact]
public void FileBlobProvider_PathIsRequired()
{
Assert.Throws<ArgumentNullException>(() => new FileBlobProvider(null));
}

[Fact]
public void FileBlobProvider_TestRetentionPeriod()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.
// </copyright>

using System;
using System.IO;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -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<byte>()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<!-- OmniSharp/VS Code requires TargetFrameworks to be in descending order for IntelliSense and analysis. -->
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<TargetFrameworks Condition="$(OS) == 'Windows_NT'">$(TargetFrameworks);net462</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down