diff --git a/Adaptors/LocalStorage/src/ObjectStorage.cs b/Adaptors/LocalStorage/src/ObjectStorage.cs index 2f9d99ac6..7ef35013f 100644 --- a/Adaptors/LocalStorage/src/ObjectStorage.cs +++ b/Adaptors/LocalStorage/src/ObjectStorage.cs @@ -19,6 +19,7 @@ using System.Collections.Generic; using System.IO; using System.Runtime.CompilerServices; +using System.Text; using System.Threading; using System.Threading.Tasks; @@ -97,10 +98,11 @@ public Task Check(HealthCheckTag tag) IAsyncEnumerable> valueChunks, CancellationToken cancellationToken = default) { - var id = Guid.NewGuid(); long size = 0; + var key = Guid.NewGuid() + .ToString(); var filename = Path.Combine(path_, - id.ToString()); + key); // Write to temporary file @@ -134,14 +136,14 @@ public Task Check(HealthCheckTag tag) await file.FlushAsync(cancellationToken) .ConfigureAwait(false); - return (id.ToByteArray(), size); + return (Encoding.UTF8.GetBytes(key), size); } /// public async IAsyncEnumerable GetValuesAsync(byte[] id, [EnumeratorCancellation] CancellationToken cancellationToken = default) { - var key = new Guid(id).ToString(); + var key = Encoding.UTF8.GetString(id); var filename = Path.Combine(path_, key); @@ -191,7 +193,7 @@ public async Task TryDeleteAsync(IEnumerable ids, { foreach (var id in ids) { - var key = new Guid(id).ToString(); + var key = Encoding.UTF8.GetString(id); await TryDeleteAsync(key, cancellationToken) .ConfigureAwait(false); diff --git a/Adaptors/Memory/src/ObjectStorage.cs b/Adaptors/Memory/src/ObjectStorage.cs index 2495ef11f..1e91b7e52 100644 --- a/Adaptors/Memory/src/ObjectStorage.cs +++ b/Adaptors/Memory/src/ObjectStorage.cs @@ -19,6 +19,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Runtime.CompilerServices; +using System.Text; using System.Threading; using System.Threading.Tasks; @@ -55,7 +56,8 @@ public Task Check(HealthCheckTag tag) { var array = new List(); - var id = Guid.NewGuid(); + var key = Guid.NewGuid() + .ToString(); await foreach (var val in valueChunks.WithCancellation(cancellationToken) .ConfigureAwait(false)) @@ -63,9 +65,9 @@ public Task Check(HealthCheckTag tag) array.AddRange(val.ToArray()); } - store_[id.ToString()] = array.ToArray(); + store_[key] = array.ToArray(); - return (id.ToByteArray(), array.Count); + return (Encoding.UTF8.GetBytes(key), array.Count); } #pragma warning disable CS1998 @@ -73,7 +75,7 @@ public async IAsyncEnumerable GetValuesAsync(byte[] id, #pragma warning restore CS1998 [EnumeratorCancellation] CancellationToken cancellationToken = default) { - var key = new Guid(id).ToString(); + var key = Encoding.UTF8.GetString(id); if (!store_.TryGetValue(key, out var value)) { @@ -91,7 +93,7 @@ public Task TryDeleteAsync(IEnumerable ids, { foreach (var id in ids) { - var key = new Guid(id).ToString(); + var key = Encoding.UTF8.GetString(id); store_.TryRemove(key, out _); diff --git a/Adaptors/Redis/src/ObjectStorage.cs b/Adaptors/Redis/src/ObjectStorage.cs index e80c27f6d..bb45932c1 100644 --- a/Adaptors/Redis/src/ObjectStorage.cs +++ b/Adaptors/Redis/src/ObjectStorage.cs @@ -19,6 +19,7 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; +using System.Text; using System.Threading; using System.Threading.Tasks; @@ -90,9 +91,10 @@ public Task Check(HealthCheckTag tag) IAsyncEnumerable> valueChunks, CancellationToken cancellationToken = default) { - var id = Guid.NewGuid(); + var key = Guid.NewGuid() + .ToString(); + var storageNameKey = objectStorageName_ + key; long size = 0; - var storageNameKey = objectStorageName_ + id; var idx = 0; var taskList = new List(); @@ -111,14 +113,14 @@ public Task Check(HealthCheckTag tag) await taskList.WhenAll() .ConfigureAwait(false); - return (id.ToByteArray(), size); + return (Encoding.UTF8.GetBytes(key), size); } /// public async IAsyncEnumerable GetValuesAsync(byte[] id, [EnumeratorCancellation] CancellationToken cancellationToken = default) { - var key = new Guid(id); + var key = Encoding.UTF8.GetString(id); var value = await PerformActionWithRetry(() => redis_.StringGetAsync(objectStorageName_ + key + "_count")) .ConfigureAwait(false); @@ -146,13 +148,15 @@ public async IAsyncEnumerable GetValuesAsync(byte[] /// public async Task TryDeleteAsync(IEnumerable ids, CancellationToken cancellationToken = default) - => await ids.ParallelForEach(key => TryDeleteAsync(new Guid(key).ToString(), - cancellationToken)) + => await ids.ParallelForEach(id => TryDeleteAsync(id, + cancellationToken)) .ConfigureAwait(false); - private async Task TryDeleteAsync(string key, + private async Task TryDeleteAsync(byte[] id, CancellationToken cancellationToken = default) { + var key = Encoding.UTF8.GetString(id); + var value = await PerformActionWithRetry(() => redis_.StringGetAsync(objectStorageName_ + key + "_count")) .ConfigureAwait(false); diff --git a/Adaptors/S3/src/ObjectStorage.cs b/Adaptors/S3/src/ObjectStorage.cs index 939a2bd4c..d63acb17a 100644 --- a/Adaptors/S3/src/ObjectStorage.cs +++ b/Adaptors/S3/src/ObjectStorage.cs @@ -20,6 +20,7 @@ using System.IO; using System.Linq; using System.Runtime.CompilerServices; +using System.Text; using System.Threading; using System.Threading.Tasks; @@ -98,7 +99,7 @@ public Task Check(HealthCheckTag tag) public async IAsyncEnumerable GetValuesAsync(byte[] id, [EnumeratorCancellation] CancellationToken cancellationToken = default) { - var key = new Guid(id); + var key = Encoding.UTF8.GetString(id); var objectStorageFullName = $"{objectStorageName_}{key}"; try @@ -173,8 +174,9 @@ await s3Client_.GetObjectAsync(options_.BucketName, { 0, }; - var id = Guid.NewGuid(); - var objectStorageFullName = $"{objectStorageName_}{id.ToString()}"; + var key = Guid.NewGuid() + .ToString(); + var objectStorageFullName = $"{objectStorageName_}{key}"; logger_.LogDebug("Upload object"); var initRequest = new InitiateMultipartUploadRequest @@ -226,19 +228,20 @@ await s3Client_.AbortMultipartUploadAsync(abortMpuRequest, throw; } - return (id.ToByteArray(), sizeBox[0]); + return (Encoding.UTF8.GetBytes(key), sizeBox[0]); } /// public async Task TryDeleteAsync(IEnumerable ids, CancellationToken cancellationToken = default) - => await ids.ParallelForEach(key => TryDeleteAsync(new Guid(key).ToString(), - cancellationToken)) + => await ids.ParallelForEach(id => TryDeleteAsync(id, + cancellationToken)) .ConfigureAwait(false); - private async Task TryDeleteAsync(string key, + private async Task TryDeleteAsync(byte[] id, CancellationToken cancellationToken = default) { + var key = Encoding.UTF8.GetString(id); var objectStorageFullName = $"{objectStorageName_}{key}"; var objectDeleteRequest = new DeleteObjectRequest diff --git a/Common/tests/TestBase/ObjectStorageTestBase.cs b/Common/tests/TestBase/ObjectStorageTestBase.cs index 7b06586ff..ef1b37cd3 100644 --- a/Common/tests/TestBase/ObjectStorageTestBase.cs +++ b/Common/tests/TestBase/ObjectStorageTestBase.cs @@ -224,8 +224,7 @@ public async Task GetValuesAsyncShouldFail() { if (RunTests) { - var id = Guid.NewGuid() - .ToByteArray(); + var id = Encoding.UTF8.GetBytes("IdThatShouldFail"); var data = new List(); try @@ -266,7 +265,8 @@ public async Task PayloadShouldBeEqual() var str = Encoding.ASCII.GetString(data.ToArray()); Console.WriteLine(str); - Assert.IsTrue(str.SequenceEqual("AAAABBBB")); + Assert.AreEqual("AAAABBBB", + str); } } @@ -286,7 +286,8 @@ public async Task Payload2ShouldBeEqual() var str = Encoding.ASCII.GetString(data.ToArray()); Console.WriteLine(str); - Assert.IsTrue(str.SequenceEqual("AAAABBBBCCCCDDDD")); + Assert.AreEqual("AAAABBBBCCCCDDDD", + str); } }