diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/Microsoft.Azure.Devices.Edge.Agent.Core.csproj b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/Microsoft.Azure.Devices.Edge.Agent.Core.csproj index 2b133a42846..f7a4d301773 100644 --- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/Microsoft.Azure.Devices.Edge.Agent.Core.csproj +++ b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/Microsoft.Azure.Devices.Edge.Agent.Core.csproj @@ -10,7 +10,7 @@ - + diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Diagnostics/Microsoft.Azure.Devices.Edge.Agent.Diagnostics.csproj b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Diagnostics/Microsoft.Azure.Devices.Edge.Agent.Diagnostics.csproj index 75afe4295b6..a4f7119b1ca 100644 --- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Diagnostics/Microsoft.Azure.Devices.Edge.Agent.Diagnostics.csproj +++ b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Diagnostics/Microsoft.Azure.Devices.Edge.Agent.Diagnostics.csproj @@ -9,8 +9,8 @@ - - + + diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/Microsoft.Azure.Devices.Edge.Agent.Docker.csproj b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/Microsoft.Azure.Devices.Edge.Agent.Docker.csproj index b08892c05d8..3594f0baa52 100644 --- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/Microsoft.Azure.Devices.Edge.Agent.Docker.csproj +++ b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/Microsoft.Azure.Devices.Edge.Agent.Docker.csproj @@ -9,7 +9,7 @@ - + diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Edgelet/Microsoft.Azure.Devices.Edge.Agent.Edgelet.csproj b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Edgelet/Microsoft.Azure.Devices.Edge.Agent.Edgelet.csproj index ac10a9d9cb6..c3365331ebd 100644 --- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Edgelet/Microsoft.Azure.Devices.Edge.Agent.Edgelet.csproj +++ b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Edgelet/Microsoft.Azure.Devices.Edge.Agent.Edgelet.csproj @@ -1,4 +1,4 @@ - + @@ -9,7 +9,7 @@ - + diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.IoTHub/Microsoft.Azure.Devices.Edge.Agent.IoTHub.csproj b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.IoTHub/Microsoft.Azure.Devices.Edge.Agent.IoTHub.csproj index 38bb8a07ea0..b45febe91bf 100644 --- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.IoTHub/Microsoft.Azure.Devices.Edge.Agent.IoTHub.csproj +++ b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.IoTHub/Microsoft.Azure.Devices.Edge.Agent.IoTHub.csproj @@ -9,8 +9,8 @@ - - + + diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Service/Microsoft.Azure.Devices.Edge.Agent.Service.csproj b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Service/Microsoft.Azure.Devices.Edge.Agent.Service.csproj index 2908392868b..21e3805ffee 100644 --- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Service/Microsoft.Azure.Devices.Edge.Agent.Service.csproj +++ b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Service/Microsoft.Azure.Devices.Edge.Agent.Service.csproj @@ -10,9 +10,9 @@ - - - + + + diff --git a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Docker.E2E.Test/Microsoft.Azure.Devices.Edge.Agent.Docker.E2E.Test.csproj b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Docker.E2E.Test/Microsoft.Azure.Devices.Edge.Agent.Docker.E2E.Test.csproj index c73886bcf3e..6e038ae13dd 100644 --- a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Docker.E2E.Test/Microsoft.Azure.Devices.Edge.Agent.Docker.E2E.Test.csproj +++ b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Docker.E2E.Test/Microsoft.Azure.Devices.Edge.Agent.Docker.E2E.Test.csproj @@ -9,8 +9,8 @@ - - + + diff --git a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Integration.Test/Microsoft.Azure.Devices.Edge.Agent.Integration.Test.csproj b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Integration.Test/Microsoft.Azure.Devices.Edge.Agent.Integration.Test.csproj index 6e76f9cf96d..cc39a4e7966 100644 --- a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Integration.Test/Microsoft.Azure.Devices.Edge.Agent.Integration.Test.csproj +++ b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Integration.Test/Microsoft.Azure.Devices.Edge.Agent.Integration.Test.csproj @@ -9,8 +9,8 @@ - - + + diff --git a/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.Amqp/Microsoft.Azure.Devices.Edge.Hub.Amqp.csproj b/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.Amqp/Microsoft.Azure.Devices.Edge.Hub.Amqp.csproj index d4fdc488d69..a57a3dfbb0e 100644 --- a/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.Amqp/Microsoft.Azure.Devices.Edge.Hub.Amqp.csproj +++ b/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.Amqp/Microsoft.Azure.Devices.Edge.Hub.Amqp.csproj @@ -9,7 +9,7 @@ - + diff --git a/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.CloudProxy/Microsoft.Azure.Devices.Edge.Hub.CloudProxy.csproj b/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.CloudProxy/Microsoft.Azure.Devices.Edge.Hub.CloudProxy.csproj index 61eeb483eb7..f4f23e052c5 100644 --- a/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.CloudProxy/Microsoft.Azure.Devices.Edge.Hub.CloudProxy.csproj +++ b/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.CloudProxy/Microsoft.Azure.Devices.Edge.Hub.CloudProxy.csproj @@ -9,7 +9,7 @@ - + diff --git a/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.CloudProxy/TokenHelper.cs b/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.CloudProxy/TokenHelper.cs index 8ad95fb610b..050b5a339dc 100644 --- a/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.CloudProxy/TokenHelper.cs +++ b/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.CloudProxy/TokenHelper.cs @@ -2,7 +2,7 @@ namespace Microsoft.Azure.Devices.Edge.Hub.CloudProxy { using System; - using Microsoft.Azure.Devices.Common.Security; + using Microsoft.Azure.Devices.Edge.Util; class TokenHelper { diff --git a/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.Core/Microsoft.Azure.Devices.Edge.Hub.Core.csproj b/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.Core/Microsoft.Azure.Devices.Edge.Hub.Core.csproj index 9d718c9f9d2..7f8d8a3e3c9 100644 --- a/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.Core/Microsoft.Azure.Devices.Edge.Hub.Core.csproj +++ b/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.Core/Microsoft.Azure.Devices.Edge.Hub.Core.csproj @@ -18,7 +18,7 @@ - + diff --git a/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.Http/Microsoft.Azure.Devices.Edge.Hub.Http.csproj b/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.Http/Microsoft.Azure.Devices.Edge.Hub.Http.csproj index 26f438a8082..9d17bc4df75 100644 --- a/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.Http/Microsoft.Azure.Devices.Edge.Hub.Http.csproj +++ b/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.Http/Microsoft.Azure.Devices.Edge.Hub.Http.csproj @@ -13,7 +13,7 @@ - + diff --git a/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/Microsoft.Azure.Devices.Edge.Hub.Mqtt.csproj b/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/Microsoft.Azure.Devices.Edge.Hub.Mqtt.csproj index 98bdfff096b..7ee29268bf5 100644 --- a/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/Microsoft.Azure.Devices.Edge.Hub.Mqtt.csproj +++ b/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.Mqtt/Microsoft.Azure.Devices.Edge.Hub.Mqtt.csproj @@ -10,7 +10,7 @@ - + diff --git a/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.Service/Microsoft.Azure.Devices.Edge.Hub.Service.csproj b/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.Service/Microsoft.Azure.Devices.Edge.Hub.Service.csproj index 52984c31a1f..6b99da8ab59 100644 --- a/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.Service/Microsoft.Azure.Devices.Edge.Hub.Service.csproj +++ b/edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.Service/Microsoft.Azure.Devices.Edge.Hub.Service.csproj @@ -31,8 +31,8 @@ - - + + diff --git a/edge-hub/core/src/Microsoft.Azure.Devices.Routing.Core/Microsoft.Azure.Devices.Routing.Core.csproj b/edge-hub/core/src/Microsoft.Azure.Devices.Routing.Core/Microsoft.Azure.Devices.Routing.Core.csproj index 844b3c2e683..38736701d63 100644 --- a/edge-hub/core/src/Microsoft.Azure.Devices.Routing.Core/Microsoft.Azure.Devices.Routing.Core.csproj +++ b/edge-hub/core/src/Microsoft.Azure.Devices.Routing.Core/Microsoft.Azure.Devices.Routing.Core.csproj @@ -20,7 +20,7 @@ - + diff --git a/edge-hub/core/test/Microsoft.Azure.Devices.Edge.Hub.CloudProxy.Test/EventHubReceiver.cs b/edge-hub/core/test/Microsoft.Azure.Devices.Edge.Hub.CloudProxy.Test/EventHubReceiver.cs index b5750afc620..15d29730f52 100644 --- a/edge-hub/core/test/Microsoft.Azure.Devices.Edge.Hub.CloudProxy.Test/EventHubReceiver.cs +++ b/edge-hub/core/test/Microsoft.Azure.Devices.Edge.Hub.CloudProxy.Test/EventHubReceiver.cs @@ -4,7 +4,7 @@ namespace Microsoft.Azure.Devices.Edge.Hub.CloudProxy.Test using System; using System.Collections.Generic; using System.Threading.Tasks; - using Microsoft.Azure.Devices.Common; + using Microsoft.Azure.Devices.Edge.Test.Common; using Microsoft.Azure.EventHubs; public class EventHubReceiver diff --git a/edge-hub/core/test/Microsoft.Azure.Devices.Edge.Hub.CloudProxy.Test/Microsoft.Azure.Devices.Edge.Hub.CloudProxy.Test.csproj b/edge-hub/core/test/Microsoft.Azure.Devices.Edge.Hub.CloudProxy.Test/Microsoft.Azure.Devices.Edge.Hub.CloudProxy.Test.csproj index 40d88e14dbf..c81296efcbd 100644 --- a/edge-hub/core/test/Microsoft.Azure.Devices.Edge.Hub.CloudProxy.Test/Microsoft.Azure.Devices.Edge.Hub.CloudProxy.Test.csproj +++ b/edge-hub/core/test/Microsoft.Azure.Devices.Edge.Hub.CloudProxy.Test/Microsoft.Azure.Devices.Edge.Hub.CloudProxy.Test.csproj @@ -10,7 +10,7 @@ - + @@ -24,6 +24,7 @@ + diff --git a/edge-modules/MetricsCollector/MetricsCollector.csproj b/edge-modules/MetricsCollector/MetricsCollector.csproj index ca25d92f770..d42bb290c13 100644 --- a/edge-modules/MetricsCollector/MetricsCollector.csproj +++ b/edge-modules/MetricsCollector/MetricsCollector.csproj @@ -14,13 +14,13 @@ - - - - - - - + + + + + + + diff --git a/edge-modules/SimulatedTemperatureSensor/SimulatedTemperatureSensor.csproj b/edge-modules/SimulatedTemperatureSensor/SimulatedTemperatureSensor.csproj index 6db6ef665f2..123eaafd67b 100644 --- a/edge-modules/SimulatedTemperatureSensor/SimulatedTemperatureSensor.csproj +++ b/edge-modules/SimulatedTemperatureSensor/SimulatedTemperatureSensor.csproj @@ -14,13 +14,13 @@ - - - - - - - + + + + + + + diff --git a/edge-modules/functions/binding/src/Microsoft.Azure.WebJobs.Extensions.EdgeHub/Microsoft.Azure.WebJobs.Extensions.EdgeHub.csproj b/edge-modules/functions/binding/src/Microsoft.Azure.WebJobs.Extensions.EdgeHub/Microsoft.Azure.WebJobs.Extensions.EdgeHub.csproj index 9969f105229..698ac8c54de 100644 --- a/edge-modules/functions/binding/src/Microsoft.Azure.WebJobs.Extensions.EdgeHub/Microsoft.Azure.WebJobs.Extensions.EdgeHub.csproj +++ b/edge-modules/functions/binding/src/Microsoft.Azure.WebJobs.Extensions.EdgeHub/Microsoft.Azure.WebJobs.Extensions.EdgeHub.csproj @@ -27,7 +27,7 @@ - + diff --git a/edge-modules/functions/samples/EdgeHubTrigger-Csharp/EdgeHubTriggerCSharp.csproj b/edge-modules/functions/samples/EdgeHubTrigger-Csharp/EdgeHubTriggerCSharp.csproj index 34893cf831a..1a417b6a3aa 100644 --- a/edge-modules/functions/samples/EdgeHubTrigger-Csharp/EdgeHubTriggerCSharp.csproj +++ b/edge-modules/functions/samples/EdgeHubTrigger-Csharp/EdgeHubTriggerCSharp.csproj @@ -25,7 +25,7 @@ - + diff --git a/edge-modules/iotedge-diagnostics-dotnet/IotedgeDiagnosticsDotnet.csproj b/edge-modules/iotedge-diagnostics-dotnet/IotedgeDiagnosticsDotnet.csproj index 4052b001635..b3d055326c7 100644 --- a/edge-modules/iotedge-diagnostics-dotnet/IotedgeDiagnosticsDotnet.csproj +++ b/edge-modules/iotedge-diagnostics-dotnet/IotedgeDiagnosticsDotnet.csproj @@ -15,13 +15,13 @@ - - - - - - - + + + + + + + diff --git a/edge-util/src/Microsoft.Azure.Devices.Edge.Util/Microsoft.Azure.Devices.Edge.Util.csproj b/edge-util/src/Microsoft.Azure.Devices.Edge.Util/Microsoft.Azure.Devices.Edge.Util.csproj index 853bfd51d7a..73854fabc1a 100644 --- a/edge-util/src/Microsoft.Azure.Devices.Edge.Util/Microsoft.Azure.Devices.Edge.Util.csproj +++ b/edge-util/src/Microsoft.Azure.Devices.Edge.Util/Microsoft.Azure.Devices.Edge.Util.csproj @@ -11,7 +11,8 @@ - + + diff --git a/edge-util/test/Microsoft.Azure.Devices.Edge.Util.Test.Common/Microsoft.Azure.Devices.Edge.Util.Test.Common.csproj b/edge-util/test/Microsoft.Azure.Devices.Edge.Util.Test.Common/Microsoft.Azure.Devices.Edge.Util.Test.Common.csproj index a857b70e52b..0cecb77d268 100644 --- a/edge-util/test/Microsoft.Azure.Devices.Edge.Util.Test.Common/Microsoft.Azure.Devices.Edge.Util.Test.Common.csproj +++ b/edge-util/test/Microsoft.Azure.Devices.Edge.Util.Test.Common/Microsoft.Azure.Devices.Edge.Util.Test.Common.csproj @@ -11,9 +11,9 @@ - - - + + + diff --git a/nuget.config b/nuget.config index 9dbf7698df7..75f9065469e 100644 --- a/nuget.config +++ b/nuget.config @@ -3,6 +3,5 @@ - \ No newline at end of file diff --git a/samples/dotnet/EdgeDownstreamDevice/EdgeDownstreamDevice.csproj b/samples/dotnet/EdgeDownstreamDevice/EdgeDownstreamDevice.csproj index f3f131cd666..e5fbe3dd70b 100644 --- a/samples/dotnet/EdgeDownstreamDevice/EdgeDownstreamDevice.csproj +++ b/samples/dotnet/EdgeDownstreamDevice/EdgeDownstreamDevice.csproj @@ -9,6 +9,6 @@ - + diff --git a/samples/dotnet/EdgeX509AuthDownstreamDevice/EdgeX509AuthDownstreamDevice.csproj b/samples/dotnet/EdgeX509AuthDownstreamDevice/EdgeX509AuthDownstreamDevice.csproj index 0c0aa879fb7..4c8543a7163 100644 --- a/samples/dotnet/EdgeX509AuthDownstreamDevice/EdgeX509AuthDownstreamDevice.csproj +++ b/samples/dotnet/EdgeX509AuthDownstreamDevice/EdgeX509AuthDownstreamDevice.csproj @@ -9,7 +9,7 @@ - + diff --git a/smoke/IotEdgeQuickstart/IotEdgeQuickstart.csproj b/smoke/IotEdgeQuickstart/IotEdgeQuickstart.csproj index d84a60eb01e..867fcd1ef2a 100644 --- a/smoke/IotEdgeQuickstart/IotEdgeQuickstart.csproj +++ b/smoke/IotEdgeQuickstart/IotEdgeQuickstart.csproj @@ -10,7 +10,7 @@ - + @@ -19,6 +19,7 @@ + diff --git a/smoke/IotEdgeQuickstart/details/Details.cs b/smoke/IotEdgeQuickstart/details/Details.cs index 0b8db21c69f..0e65ba08e30 100644 --- a/smoke/IotEdgeQuickstart/details/Details.cs +++ b/smoke/IotEdgeQuickstart/details/Details.cs @@ -10,7 +10,7 @@ namespace IotEdgeQuickstart.Details using System.Threading; using System.Threading.Tasks; using Microsoft.Azure.Devices; - using Microsoft.Azure.Devices.Common; + using Microsoft.Azure.Devices.Edge.Test.Common; using Microsoft.Azure.Devices.Edge.Util; using Microsoft.Azure.Devices.Shared; using Microsoft.Azure.EventHubs; @@ -528,7 +528,7 @@ async Task CreateEdgeDeviceIdentity(RegistryManager rm) await this.parentEdgeDevice.ForEachAsync(async p => { var parentDevice = await rm.GetDeviceAsync(p); - device.ParentScopes = new[] { parentDevice.Scope }; + device.ParentScopes.Add(parentDevice.Scope); }); IotHubConnectionStringBuilder builder = IotHubConnectionStringBuilder.Create(this.iothubConnectionString); diff --git a/smoke/LeafDevice/LeafDevice.csproj b/smoke/LeafDevice/LeafDevice.csproj index 370e2d111dd..46090749bf9 100644 --- a/smoke/LeafDevice/LeafDevice.csproj +++ b/smoke/LeafDevice/LeafDevice.csproj @@ -10,8 +10,8 @@ - - + + @@ -19,6 +19,7 @@ + diff --git a/smoke/LeafDevice/details/Details.cs b/smoke/LeafDevice/details/Details.cs index 5b9066aaa9a..15ae31b2112 100644 --- a/smoke/LeafDevice/details/Details.cs +++ b/smoke/LeafDevice/details/Details.cs @@ -16,6 +16,7 @@ namespace LeafDeviceTest using Microsoft.Azure.Devices.Client; using Microsoft.Azure.Devices.Client.Transport.Mqtt; using Microsoft.Azure.Devices.Common; + using Microsoft.Azure.Devices.Edge.Test.Common; using Microsoft.Azure.Devices.Edge.Util; using Microsoft.Azure.Devices.Shared; using Microsoft.Azure.EventHubs; diff --git a/test/Microsoft.Azure.Devices.Edge.Test.Common/EdgeDevice.cs b/test/Microsoft.Azure.Devices.Edge.Test.Common/EdgeDevice.cs index aa410158d44..ae6f247ea7f 100644 --- a/test/Microsoft.Azure.Devices.Edge.Test.Common/EdgeDevice.cs +++ b/test/Microsoft.Azure.Devices.Edge.Test.Common/EdgeDevice.cs @@ -98,7 +98,7 @@ public static async Task> GetIdentityAsync( await nestedEdgeConfig.ParentDeviceId.ForEachAsync(async p => { Device parentDevice = await iotHub.GetDeviceIdentityAsync(p, token); - device.ParentScopes = new[] { parentDevice.Scope }; + device.ParentScopes.Add(parentDevice.Scope); }); } diff --git a/test/Microsoft.Azure.Devices.Edge.Test.Common/EventHubPartitionKeyResolver.cs b/test/Microsoft.Azure.Devices.Edge.Test.Common/EventHubPartitionKeyResolver.cs new file mode 100644 index 00000000000..f4a911f7106 --- /dev/null +++ b/test/Microsoft.Azure.Devices.Edge.Test.Common/EventHubPartitionKeyResolver.cs @@ -0,0 +1,187 @@ +// Copyright (c) Microsoft. All rights reserved. +namespace Microsoft.Azure.Devices.Edge.Test.Common +{ + using System; + using System.Globalization; + using System.Text; + + public static class EventHubPartitionKeyResolver + { + const short DefaultLogicalPartitionCount = short.MaxValue; + + public static string ResolveToPartition(string partitionKey, int partitionCount) + { + if (string.IsNullOrWhiteSpace(partitionKey)) + { + throw new ArgumentNullException("partitionKey"); + } + + if (partitionCount < 1 || partitionCount > DefaultLogicalPartitionCount) + { + throw new ArgumentOutOfRangeException("partitionCount", partitionCount, string.Format(CultureInfo.InvariantCulture, "Should be between {0} and {1}", 1, DefaultLogicalPartitionCount)); + } + + short logicalPartition = Math.Abs((short)(PerfectHash.HashToShort(partitionKey) % DefaultLogicalPartitionCount)); + + int shortRangeWidth = (int)Math.Floor((decimal)DefaultLogicalPartitionCount / (decimal)partitionCount); + int remainingLogicalPartitions = DefaultLogicalPartitionCount - (partitionCount * shortRangeWidth); + int largeRangeWidth = shortRangeWidth + 1; + int largeRangesLogicalPartitions = largeRangeWidth * remainingLogicalPartitions; + int partitionIndex = logicalPartition < largeRangesLogicalPartitions + ? logicalPartition / largeRangeWidth + : remainingLogicalPartitions + ((logicalPartition - largeRangesLogicalPartitions) / shortRangeWidth); + + return partitionIndex.ToString(NumberFormatInfo.InvariantInfo); + } + + private static class PerfectHash + { + public static long HashToLong(string data) + { + uint hash1; + uint hash2; + +#if NETSTANDARD1_3 + string upper = data.ToUpper(); +#else + string upper = data.ToUpper(CultureInfo.InvariantCulture); +#endif + PerfectHash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(upper), seed1: 0, seed2: 0, hash1: out hash1, hash2: out hash2); + long hashedValue = ((long)hash1 << 32) | (long)hash2; + + return hashedValue; + } + + public static short HashToShort(string data) + { + uint hash1; + uint hash2; + +#if NETSTANDARD1_3 + string upper = data.ToUpper(); +#else + string upper = data.ToUpper(CultureInfo.InvariantCulture); +#endif + PerfectHash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(upper), seed1: 0, seed2: 0, hash1: out hash1, hash2: out hash2); + long hashedValue = hash1 ^ hash2; + + return (short)hashedValue; + } + + // Perfect hashing implementation. source: distributed cache team + static void ComputeHash(byte[] data, uint seed1, uint seed2, out uint hash1, out uint hash2) + { + uint a, b, c; + + a = b = c = (uint)(0xdeadbeef + data.Length + seed1); + c += seed2; + + int index = 0, size = data.Length; + while (size > 12) + { + a += BitConverter.ToUInt32(data, index); + b += BitConverter.ToUInt32(data, index + 4); + c += BitConverter.ToUInt32(data, index + 8); + + a -= c; + a ^= (c << 4) | (c >> 28); + c += b; + + b -= a; + b ^= (a << 6) | (a >> 26); + a += c; + + c -= b; + c ^= (b << 8) | (b >> 24); + b += a; + + a -= c; + a ^= (c << 16) | (c >> 16); + c += b; + + b -= a; + b ^= (a << 19) | (a >> 13); + a += c; + + c -= b; + c ^= (b << 4) | (b >> 28); + b += a; + + index += 12; + size -= 12; + } + + switch (size) + { + case 12: + a += BitConverter.ToUInt32(data, index); + b += BitConverter.ToUInt32(data, index + 4); + c += BitConverter.ToUInt32(data, index + 8); + break; + case 11: + c += ((uint)data[index + 10]) << 16; + goto case 10; + case 10: + c += ((uint)data[index + 9]) << 8; + goto case 9; + case 9: + c += (uint)data[index + 8]; + goto case 8; + case 8: + b += BitConverter.ToUInt32(data, index + 4); + a += BitConverter.ToUInt32(data, index); + break; + case 7: + b += ((uint)data[index + 6]) << 16; + goto case 6; + case 6: + b += ((uint)data[index + 5]) << 8; + goto case 5; + case 5: + b += (uint)data[index + 4]; + goto case 4; + case 4: + a += BitConverter.ToUInt32(data, index); + break; + case 3: + a += ((uint)data[index + 2]) << 16; + goto case 2; + case 2: + a += ((uint)data[index + 1]) << 8; + goto case 1; + case 1: + a += (uint)data[index]; + break; + case 0: + hash1 = c; + hash2 = b; + return; + } + + c ^= b; + c -= (b << 14) | (b >> 18); + + a ^= c; + a -= (c << 11) | (c >> 21); + + b ^= a; + b -= (a << 25) | (a >> 7); + + c ^= b; + c -= (b << 16) | (b >> 16); + + a ^= c; + a -= (c << 4) | (c >> 28); + + b ^= a; + b -= (a << 14) | (a >> 18); + + c ^= b; + c -= (b << 24) | (b >> 8); + + hash1 = c; + hash2 = b; + } + } + } +} diff --git a/test/Microsoft.Azure.Devices.Edge.Test.Common/IotHub.cs b/test/Microsoft.Azure.Devices.Edge.Test.Common/IotHub.cs index d217ab2968b..6fc017b5836 100644 --- a/test/Microsoft.Azure.Devices.Edge.Test.Common/IotHub.cs +++ b/test/Microsoft.Azure.Devices.Edge.Test.Common/IotHub.cs @@ -91,19 +91,20 @@ public async Task CreateEdgeDeviceIdentityAsync(string deviceId, Option< Device parentDevice = await this.GetDeviceIdentityAsync(p, token); string parentDeviceScope = parentDevice == null ? string.Empty : parentDevice.Scope; Log.Verbose($"Parent scope: {parentDeviceScope}"); - return new Device(deviceId) - { - Authentication = new AuthenticationMechanism() - { - Type = authType, - X509Thumbprint = x509Thumbprint - }, - Capabilities = new DeviceCapabilities() - { - IotEdge = true - }, - ParentScopes = new[] { parentDeviceScope } - }; + var result = new Device(deviceId) + { + Authentication = new AuthenticationMechanism() + { + Type = authType, + X509Thumbprint = x509Thumbprint + }, + Capabilities = new DeviceCapabilities() + { + IotEdge = true + } + }; + result.ParentScopes.Add(parentDeviceScope); + return result; }, () => { diff --git a/test/Microsoft.Azure.Devices.Edge.Test.Common/Microsoft.Azure.Devices.Edge.Test.Common.csproj b/test/Microsoft.Azure.Devices.Edge.Test.Common/Microsoft.Azure.Devices.Edge.Test.Common.csproj index bca9d2c5181..49387f24c26 100644 --- a/test/Microsoft.Azure.Devices.Edge.Test.Common/Microsoft.Azure.Devices.Edge.Test.Common.csproj +++ b/test/Microsoft.Azure.Devices.Edge.Test.Common/Microsoft.Azure.Devices.Edge.Test.Common.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/test/Microsoft.Azure.Devices.Edge.Test.Common/ProcessEx.cs b/test/Microsoft.Azure.Devices.Edge.Test.Common/ProcessEx.cs index 00a0747902d..973d52438c8 100644 --- a/test/Microsoft.Azure.Devices.Edge.Test.Common/ProcessEx.cs +++ b/test/Microsoft.Azure.Devices.Edge.Test.Common/ProcessEx.cs @@ -2,7 +2,7 @@ // Copyright (c) 2013 James Manning // Adapted from https://github.com/jamesmanning/RunProcessAsTask -namespace RunProcessAsTask +namespace Microsoft.Azure.Devices.Edge.Test.Common.RunProcessAsTask { using System; using System.Collections.Generic; diff --git a/test/Microsoft.Azure.Devices.Edge.Test.Common/ProcessResults.cs b/test/Microsoft.Azure.Devices.Edge.Test.Common/ProcessResults.cs index d377f757835..7a59a6708aa 100644 --- a/test/Microsoft.Azure.Devices.Edge.Test.Common/ProcessResults.cs +++ b/test/Microsoft.Azure.Devices.Edge.Test.Common/ProcessResults.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. // Copyright (c) 2013 James Manning -namespace RunProcessAsTask +namespace Microsoft.Azure.Devices.Edge.Test.Common.RunProcessAsTask { using System; using System.Diagnostics; diff --git a/test/Microsoft.Azure.Devices.Edge.Test/Microsoft.Azure.Devices.Edge.Test.csproj b/test/Microsoft.Azure.Devices.Edge.Test/Microsoft.Azure.Devices.Edge.Test.csproj index d1721ce71ad..adb0870b476 100644 --- a/test/Microsoft.Azure.Devices.Edge.Test/Microsoft.Azure.Devices.Edge.Test.csproj +++ b/test/Microsoft.Azure.Devices.Edge.Test/Microsoft.Azure.Devices.Edge.Test.csproj @@ -10,9 +10,9 @@ - - - + + + diff --git a/test/connectivity/modules/NetworkController/NetworkController.csproj b/test/connectivity/modules/NetworkController/NetworkController.csproj index 71337ccd532..a564dbfeb04 100644 --- a/test/connectivity/modules/NetworkController/NetworkController.csproj +++ b/test/connectivity/modules/NetworkController/NetworkController.csproj @@ -23,10 +23,10 @@ - - - - + + + + diff --git a/test/modules/CloudToDeviceMessageTester/CloudToDeviceMessageTester.csproj b/test/modules/CloudToDeviceMessageTester/CloudToDeviceMessageTester.csproj index cc6b346b2de..c1ff877a30b 100644 --- a/test/modules/CloudToDeviceMessageTester/CloudToDeviceMessageTester.csproj +++ b/test/modules/CloudToDeviceMessageTester/CloudToDeviceMessageTester.csproj @@ -14,14 +14,14 @@ - - - - - - - - + + + + + + + + diff --git a/test/modules/DeploymentTester/DeploymentTester.csproj b/test/modules/DeploymentTester/DeploymentTester.csproj index e622911c0cc..3a1fe1379ec 100644 --- a/test/modules/DeploymentTester/DeploymentTester.csproj +++ b/test/modules/DeploymentTester/DeploymentTester.csproj @@ -14,14 +14,14 @@ - - - - - - - - + + + + + + + + diff --git a/test/modules/DirectMethodReceiver/DirectMethodReceiver.csproj b/test/modules/DirectMethodReceiver/DirectMethodReceiver.csproj index 2c3e8b472bf..87354390dc1 100644 --- a/test/modules/DirectMethodReceiver/DirectMethodReceiver.csproj +++ b/test/modules/DirectMethodReceiver/DirectMethodReceiver.csproj @@ -13,13 +13,13 @@ - - - - - - - + + + + + + + diff --git a/test/modules/DirectMethodSender/DirectMethodSender.csproj b/test/modules/DirectMethodSender/DirectMethodSender.csproj index b3cbc9546a9..7c2312ab26b 100644 --- a/test/modules/DirectMethodSender/DirectMethodSender.csproj +++ b/test/modules/DirectMethodSender/DirectMethodSender.csproj @@ -14,14 +14,14 @@ - - - - - - - - + + + + + + + + diff --git a/test/modules/EdgeHubRestartTester/EdgeHubRestartTester.csproj b/test/modules/EdgeHubRestartTester/EdgeHubRestartTester.csproj index 895df4b15df..25afa94975d 100644 --- a/test/modules/EdgeHubRestartTester/EdgeHubRestartTester.csproj +++ b/test/modules/EdgeHubRestartTester/EdgeHubRestartTester.csproj @@ -27,14 +27,14 @@ - - - - - - - - + + + + + + + + diff --git a/test/modules/MetricsValidator/MetricsValidator.csproj b/test/modules/MetricsValidator/MetricsValidator.csproj index eb64fffe71f..547a0b0acec 100644 --- a/test/modules/MetricsValidator/MetricsValidator.csproj +++ b/test/modules/MetricsValidator/MetricsValidator.csproj @@ -14,13 +14,13 @@ - - - - - - - + + + + + + + diff --git a/test/modules/ModuleLib/Microsoft.Azure.Devices.Edge.ModuleUtil.csproj b/test/modules/ModuleLib/Microsoft.Azure.Devices.Edge.ModuleUtil.csproj index 7d5ac0038ae..95b0d8c4ef6 100644 --- a/test/modules/ModuleLib/Microsoft.Azure.Devices.Edge.ModuleUtil.csproj +++ b/test/modules/ModuleLib/Microsoft.Azure.Devices.Edge.ModuleUtil.csproj @@ -3,7 +3,7 @@ - + diff --git a/test/modules/ModuleRestarter/ModuleRestarter.csproj b/test/modules/ModuleRestarter/ModuleRestarter.csproj index b1db3a90f6b..5ca93a1aa25 100644 --- a/test/modules/ModuleRestarter/ModuleRestarter.csproj +++ b/test/modules/ModuleRestarter/ModuleRestarter.csproj @@ -14,14 +14,14 @@ - - - - - - - - + + + + + + + + diff --git a/test/modules/Relayer/Relayer.csproj b/test/modules/Relayer/Relayer.csproj index 97889c2893d..52cf7c6269e 100644 --- a/test/modules/Relayer/Relayer.csproj +++ b/test/modules/Relayer/Relayer.csproj @@ -14,14 +14,14 @@ - - - - - - - - + + + + + + + + diff --git a/test/modules/TemperatureFilter/TemperatureFilter.csproj b/test/modules/TemperatureFilter/TemperatureFilter.csproj index 49719941c20..fff734b1926 100644 --- a/test/modules/TemperatureFilter/TemperatureFilter.csproj +++ b/test/modules/TemperatureFilter/TemperatureFilter.csproj @@ -14,12 +14,12 @@ - - - - - - + + + + + + diff --git a/test/modules/TestAnalyzer/Program.cs b/test/modules/TestAnalyzer/Program.cs index 24f5cd852b0..4c8ea9b909c 100644 --- a/test/modules/TestAnalyzer/Program.cs +++ b/test/modules/TestAnalyzer/Program.cs @@ -10,6 +10,7 @@ namespace TestAnalyzer using Microsoft.AspNetCore.Hosting; using Microsoft.Azure.Devices.Common; using Microsoft.Azure.Devices.Edge.ModuleUtil; + using Microsoft.Azure.Devices.Edge.Test.Common; using Microsoft.Azure.EventHubs; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; diff --git a/test/modules/TestAnalyzer/TestAnalyzer.csproj b/test/modules/TestAnalyzer/TestAnalyzer.csproj index 9ef8c973669..c1acc11c1ab 100644 --- a/test/modules/TestAnalyzer/TestAnalyzer.csproj +++ b/test/modules/TestAnalyzer/TestAnalyzer.csproj @@ -19,19 +19,20 @@ - + - - - - - + + + + + + diff --git a/test/modules/TestResultCoordinator/Services/TestResultEventReceivingService.cs b/test/modules/TestResultCoordinator/Services/TestResultEventReceivingService.cs index 05eb980e49b..da813df91bf 100644 --- a/test/modules/TestResultCoordinator/Services/TestResultEventReceivingService.cs +++ b/test/modules/TestResultCoordinator/Services/TestResultEventReceivingService.cs @@ -4,8 +4,8 @@ namespace TestResultCoordinator.Services using System; using System.Threading; using System.Threading.Tasks; - using Microsoft.Azure.Devices.Common; using Microsoft.Azure.Devices.Edge.ModuleUtil; + using Microsoft.Azure.Devices.Edge.Test.Common; using Microsoft.Azure.Devices.Edge.Util; using Microsoft.Azure.EventHubs; using Microsoft.Extensions.Hosting; diff --git a/test/modules/TestResultCoordinator/TestResultCoordinator.csproj b/test/modules/TestResultCoordinator/TestResultCoordinator.csproj index cd8a63aa944..581049f5563 100644 --- a/test/modules/TestResultCoordinator/TestResultCoordinator.csproj +++ b/test/modules/TestResultCoordinator/TestResultCoordinator.csproj @@ -20,9 +20,9 @@ - + - + @@ -30,6 +30,7 @@ + diff --git a/test/modules/TwinTester/TwinTester.csproj b/test/modules/TwinTester/TwinTester.csproj index 5bce0077707..1b58888fd04 100644 --- a/test/modules/TwinTester/TwinTester.csproj +++ b/test/modules/TwinTester/TwinTester.csproj @@ -14,15 +14,15 @@ - - - - - - - - - + + + + + + + + + diff --git a/test/modules/load-gen/load-gen.csproj b/test/modules/load-gen/load-gen.csproj index f6ae00f8b15..d2a46f1c03a 100644 --- a/test/modules/load-gen/load-gen.csproj +++ b/test/modules/load-gen/load-gen.csproj @@ -15,14 +15,14 @@ - - - - - - - - + + + + + + + +