-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Bugs in new v12 Azure Storage (#868)
Also merges in the latest changes from the main branch.
- Loading branch information
Showing
35 changed files
with
1,169 additions
and
313 deletions.
There are no files selected for viewing
151 changes: 151 additions & 0 deletions
151
Test/DurableTask.AzureStorage.Tests/MessageManagerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright Microsoft Corporation | ||
// Licensed 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. | ||
// ---------------------------------------------------------------------------------- | ||
#nullable enable | ||
namespace DurableTask.AzureStorage.Tests | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using DurableTask.AzureStorage.Storage; | ||
using DurableTask.Core.History; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Newtonsoft.Json; | ||
|
||
[TestClass] | ||
public class MessageManagerTests | ||
{ | ||
[DataTestMethod] | ||
[DataRow("System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib],[System.String, System.Private.CoreLib]]")] | ||
[DataRow("System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.String, mscorlib]]")] | ||
public void DeserializesStandardTypes(string dictionaryType) | ||
{ | ||
// Given | ||
var message = GetMessage(dictionaryType); | ||
var messageManager = SetupMessageManager(new PrimitiveTypeBinder()); | ||
|
||
// When | ||
var deserializedMessage = messageManager.DeserializeMessageData(message); | ||
|
||
// Then | ||
Assert.IsInstanceOfType(deserializedMessage.TaskMessage.Event, typeof(ExecutionStartedEvent)); | ||
ExecutionStartedEvent startedEvent = (ExecutionStartedEvent)deserializedMessage.TaskMessage.Event; | ||
Assert.AreEqual("tagValue", startedEvent.Tags["tag1"]); | ||
} | ||
|
||
[TestMethod] | ||
public void FailsDeserializingUnknownTypes() | ||
{ | ||
// Given | ||
var message = GetMessage("RandomType"); | ||
var messageManager = SetupMessageManager(new KnownTypeBinder()); | ||
|
||
// When/Then | ||
Assert.ThrowsException<JsonSerializationException>(() => messageManager.DeserializeMessageData(message)); | ||
} | ||
|
||
|
||
[TestMethod] | ||
public void DeserializesCustomTypes() | ||
{ | ||
// Given | ||
var message = GetMessage("KnownType"); | ||
var messageManager = SetupMessageManager(new KnownTypeBinder()); | ||
|
||
// When | ||
var deserializedMessage = messageManager.DeserializeMessageData(message); | ||
|
||
// Then | ||
Assert.IsInstanceOfType(deserializedMessage.TaskMessage.Event, typeof(ExecutionStartedEvent)); | ||
ExecutionStartedEvent startedEvent = (ExecutionStartedEvent)deserializedMessage.TaskMessage.Event; | ||
Assert.AreEqual("tagValue", startedEvent.Tags["tag1"]); | ||
} | ||
|
||
[DataTestMethod] | ||
[DataRow("blob.bin")] | ||
[DataRow("@#$%!")] | ||
[DataRow("foo/bar/[email protected]")] | ||
public void GetBlobUrlUnescaped(string blob) | ||
{ | ||
var settings = new AzureStorageOrchestrationServiceSettings | ||
{ | ||
StorageAccountClientProvider = new StorageAccountClientProvider("UseDevelopmentStorage=true"), | ||
}; | ||
|
||
const string container = "@entity12345"; | ||
var manager = new MessageManager(settings, new AzureStorageClient(settings), container); | ||
var expected = $"http://127.0.0.1:10000/devstoreaccount1/{container}/{blob}"; | ||
Assert.AreEqual(expected, manager.GetBlobUrl(blob)); | ||
} | ||
|
||
private string GetMessage(string dictionaryType) | ||
=> "{\"$type\":\"DurableTask.AzureStorage.MessageData\",\"ActivityId\":\"5406d369-4369-4673-afae-6671a2fa1e57\",\"TaskMessage\":{\"$type\":\"DurableTask.Core.TaskMessage\",\"Event\":{\"$type\":\"DurableTask.Core.History.ExecutionStartedEvent\",\"OrchestrationInstance\":{\"$type\":\"DurableTask.Core.OrchestrationInstance\",\"InstanceId\":\"2.2-34a2c9d4-306e-4467-8470-a8018b2e4f11\",\"ExecutionId\":\"aae324dcc8f943e490b37ec5e5bbf9da\"},\"EventType\":0,\"ParentInstance\":null,\"Name\":\"OrchestrationName\",\"Version\":\"2.0\",\"Input\":\"input\",\"Tags\":{\"$type\":\"" | ||
+ dictionaryType | ||
+ "\",\"tag1\":\"tagValue\"},\"Correlation\":null,\"ScheduledStartTime\":null,\"Generation\":0,\"EventId\":-1,\"IsPlayed\":false,\"Timestamp\":\"2023-03-24T20:53:05.9093518Z\"},\"SequenceNumber\":0,\"OrchestrationInstance\":{\"$type\":\"DurableTask.Core.OrchestrationInstance\",\"InstanceId\":\"2.2-34a2c9d4-306e-4467-8470-a8018b2e4f11\",\"ExecutionId\":\"aae324dcc8f943e490b37ec5e5bbf9da\"}},\"CompressedBlobName\":null,\"SequenceNumber\":40,\"Sender\":{\"InstanceId\":\"\",\"ExecutionId\":\"\"},\"SerializableTraceContext\":null}\r\n\r\n"; | ||
|
||
private MessageManager SetupMessageManager(ICustomTypeBinder binder) | ||
{ | ||
var azureStorageClient = new AzureStorageClient( | ||
new AzureStorageOrchestrationServiceSettings | ||
{ | ||
StorageAccountClientProvider = new StorageAccountClientProvider("UseDevelopmentStorage=true"), | ||
}); | ||
|
||
return new MessageManager( | ||
new AzureStorageOrchestrationServiceSettings { CustomMessageTypeBinder = binder }, | ||
azureStorageClient, | ||
"$root"); | ||
} | ||
} | ||
|
||
internal class KnownTypeBinder : ICustomTypeBinder | ||
{ | ||
public void BindToName(Type serializedType, out string assemblyName, out string typeName) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Type? BindToType(string assemblyName, string typeName) | ||
{ | ||
if (typeName == "KnownType") | ||
{ | ||
return typeof(Dictionary<string, string>); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
|
||
internal class PrimitiveTypeBinder : ICustomTypeBinder | ||
{ | ||
readonly bool hasStandardLib; | ||
|
||
public PrimitiveTypeBinder() | ||
{ | ||
hasStandardLib = typeof(string).AssemblyQualifiedName!.Contains("mscorlib"); | ||
} | ||
|
||
public void BindToName(Type serializedType, out string assemblyName, out string typeName) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public Type BindToType(string assemblyName, string typeName) | ||
{ | ||
if (hasStandardLib) | ||
{ | ||
return Type.GetType(typeName.Replace("System.Private.CoreLib", "mscorlib"))!; | ||
} | ||
|
||
return Type.GetType(typeName.Replace("mscorlib", "System.Private.CoreLib"))!; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright Microsoft Corporation | ||
// Licensed 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. | ||
// ---------------------------------------------------------------------------------- | ||
#nullable enable | ||
namespace DurableTask.AzureStorage.Net | ||
{ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
[TestClass] | ||
public class UriPathTests | ||
{ | ||
[DataTestMethod] | ||
[DataRow("", "", "")] | ||
[DataRow("", "bar/baz", "bar/baz")] | ||
[DataRow("foo", "", "foo")] | ||
[DataRow("foo", "/", "foo/")] | ||
[DataRow("foo", "bar", "foo/bar")] | ||
[DataRow("foo", "/bar", "foo/bar")] | ||
[DataRow("foo/", "", "foo/")] | ||
[DataRow("foo/", "/", "foo/")] | ||
[DataRow("foo/", "bar", "foo/bar")] | ||
[DataRow("foo/", "/bar", "foo/bar")] | ||
[DataRow("/foo//", "//bar/baz", "/foo///bar/baz")] | ||
public void Combine(string path1, string path2, string expected) | ||
{ | ||
Assert.AreEqual(expected, UriPath.Combine(path1, path2)); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
Test/DurableTask.AzureStorage.Tests/Storage/TableClientExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright Microsoft Corporation | ||
// Licensed 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 DurableTask.AzureStorage.Tests.Storage | ||
{ | ||
using System; | ||
using Azure.Data.Tables; | ||
using DurableTask.AzureStorage.Storage; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
[TestClass] | ||
public class TableClientExtensionsTests | ||
{ | ||
const string EmulatorAccountKey = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="; | ||
|
||
[TestMethod] | ||
public void GetUri_ConnectionString() | ||
{ | ||
TableClient client; | ||
|
||
client = new TableClient("UseDevelopmentStorage=true", "bar"); | ||
Assert.AreEqual(new Uri("http://127.0.0.1:10002/devstoreaccount1/bar"), client.GetUri()); | ||
|
||
client = new TableClient($"DefaultEndpointsProtocol=https;AccountName=foo;AccountKey={EmulatorAccountKey};TableEndpoint=https://foo.table.core.windows.net/;", "bar"); | ||
Assert.AreEqual(new Uri("https://foo.table.core.windows.net/bar"), client.GetUri()); | ||
} | ||
|
||
[TestMethod] | ||
public void GetUri_ServiceEndpoint() | ||
{ | ||
var client = new TableClient(new Uri("https://foo.table.core.windows.net/"), "bar", new TableSharedKeyCredential("foo", EmulatorAccountKey)); | ||
Assert.AreEqual(new Uri("https://foo.table.core.windows.net/bar"), client.GetUri()); | ||
} | ||
|
||
[TestMethod] | ||
public void GetUri_TableEndpoint() | ||
{ | ||
var client = new TableClient(new Uri("https://foo.table.core.windows.net/bar")); | ||
Assert.AreEqual(new Uri("https://foo.table.core.windows.net/bar"), client.GetUri()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.