diff --git a/Microsoft.Azure.Cosmos.Encryption/src/AssemblyInfo.cs b/Microsoft.Azure.Cosmos.Encryption/src/AssemblyKeys.cs similarity index 100% rename from Microsoft.Azure.Cosmos.Encryption/src/AssemblyInfo.cs rename to Microsoft.Azure.Cosmos.Encryption/src/AssemblyKeys.cs diff --git a/Microsoft.Azure.Cosmos/src/Batch/BatchAsyncContainerExecutorCache.cs b/Microsoft.Azure.Cosmos/src/Batch/BatchAsyncContainerExecutorCache.cs index f8141cffd4..a16683b400 100644 --- a/Microsoft.Azure.Cosmos/src/Batch/BatchAsyncContainerExecutorCache.cs +++ b/Microsoft.Azure.Cosmos/src/Batch/BatchAsyncContainerExecutorCache.cs @@ -14,6 +14,8 @@ namespace Microsoft.Azure.Cosmos /// internal class BatchAsyncContainerExecutorCache : IDisposable { + // Keeping same performance tuned value of Bulk V2. + internal const int DefaultMaxBulkRequestBodySizeInBytes = 220201; private ConcurrentDictionary executorsPerContainer = new ConcurrentDictionary(); public BatchAsyncContainerExecutor GetExecutorForContainer( @@ -35,7 +37,7 @@ public BatchAsyncContainerExecutor GetExecutorForContainer( container, cosmosClientContext, Constants.MaxOperationsInDirectModeBatchRequest, - Constants.MaxDirectModeBatchRequestBodySizeInBytes); + DefaultMaxBulkRequestBodySizeInBytes); if (!this.executorsPerContainer.TryAdd(containerLink, newExecutor)) { newExecutor.Dispose(); diff --git a/Microsoft.Azure.Cosmos/src/Routing/GatewayAddressCache.cs b/Microsoft.Azure.Cosmos/src/Routing/GatewayAddressCache.cs index cf7bc63d67..25970fee34 100644 --- a/Microsoft.Azure.Cosmos/src/Routing/GatewayAddressCache.cs +++ b/Microsoft.Azure.Cosmos/src/Routing/GatewayAddressCache.cs @@ -248,7 +248,7 @@ public async Task TryGetAddressesAsync( } } - public async Task TryUpdateAddressAsync( + public Task TryRemoveAddressesAsync( ServerKey serverKey, CancellationToken cancellationToken) { @@ -263,21 +263,12 @@ public async Task TryUpdateAddressAsync( { foreach (PartitionKeyRangeIdentity pkRangeId in pkRangeIds) { - DefaultTrace.TraceInformation("Refresh addresses for collectionRid :{0}, pkRangeId: {1}, serviceEndpoint: {2}", + DefaultTrace.TraceInformation("Remove addresses for collectionRid :{0}, pkRangeId: {1}, serviceEndpoint: {2}", pkRangeId.CollectionRid, pkRangeId.PartitionKeyRangeId, this.serviceEndpoint); - tasks.Add(this.serverPartitionAddressCache.GetAsync( - pkRangeId, - null, - () => this.GetAddressesForRangeIdAsync( - null, - pkRangeId.CollectionRid, - pkRangeId.PartitionKeyRangeId, - forceRefresh: true), - cancellationToken, - forceRefresh: true)); + tasks.Add(this.serverPartitionAddressCache.RemoveAsync(pkRangeId)); } // remove the server key from the map since we are updating the addresses @@ -285,7 +276,7 @@ public async Task TryUpdateAddressAsync( this.serverPartitionAddressToPkRangeIdMap.TryRemove(serverKey, out ignorePkRanges); } - await Task.WhenAll(tasks); + return Task.WhenAll(tasks); } public async Task UpdateAsync( diff --git a/Microsoft.Azure.Cosmos/src/Routing/GlobalAddressResolver.cs b/Microsoft.Azure.Cosmos/src/Routing/GlobalAddressResolver.cs index a3537602ba..6614115f93 100644 --- a/Microsoft.Azure.Cosmos/src/Routing/GlobalAddressResolver.cs +++ b/Microsoft.Azure.Cosmos/src/Routing/GlobalAddressResolver.cs @@ -135,8 +135,8 @@ public async Task UpdateAsync( foreach (KeyValuePair addressCache in this.addressCacheByEndpoint) { - // since we don't know which address cache contains the pkRanges mapped to this node, we do a tryUpdate on all AddressCaches of all regions - tasks.Add(addressCache.Value.AddressCache.TryUpdateAddressAsync(serverKey, cancellationToken)); + // since we don't know which address cache contains the pkRanges mapped to this node, we do a tryRemove on all AddressCaches of all regions + tasks.Add(addressCache.Value.AddressCache.TryRemoveAddressesAsync(serverKey, cancellationToken)); } await Task.WhenAll(tasks); diff --git a/Microsoft.Azure.Cosmos/src/SqlObjects/SqlFunctionCallScalarExpression.cs b/Microsoft.Azure.Cosmos/src/SqlObjects/SqlFunctionCallScalarExpression.cs index c9c91d460a..4f4b147b19 100644 --- a/Microsoft.Azure.Cosmos/src/SqlObjects/SqlFunctionCallScalarExpression.cs +++ b/Microsoft.Azure.Cosmos/src/SqlObjects/SqlFunctionCallScalarExpression.cs @@ -20,6 +20,14 @@ sealed class SqlFunctionCallScalarExpression : SqlScalarExpression { { Names.InternalCompareBsonBinaryData, Identifiers.InternalCompareBsonBinaryData }, { Names.InternalCompareObjects, Identifiers.InternalCompareObjects }, + { Names.InternalEvalEq, Identifiers.InternalEvalEq }, + { Names.InternalEvalGt, Identifiers.InternalEvalGt }, + { Names.InternalEvalGte, Identifiers.InternalEvalGte }, + { Names.InternalEvalIn, Identifiers.InternalEvalIn }, + { Names.InternalEvalLt, Identifiers.InternalEvalLt }, + { Names.InternalEvalLte, Identifiers.InternalEvalLte }, + { Names.InternalEvalNeq, Identifiers.InternalEvalNeq }, + { Names.InternalEvalNin, Identifiers.InternalEvalNin }, { Names.InternalObjectToArray, Identifiers.InternalObjectToArray }, { Names.InternalProxyProjection, Identifiers.InternalProxyProjection }, { Names.InternalRegexMatch, Identifiers.InternalRegexMatch }, @@ -40,17 +48,45 @@ sealed class SqlFunctionCallScalarExpression : SqlScalarExpression { Names.Atan, Identifiers.Atan }, { Names.Atn2, Identifiers.Atn2 }, { Names.Avg, Identifiers.Avg }, + { Names.Binary, Identifiers.Binary }, + { Names.Float32, Identifiers.Float32 }, + { Names.Float64, Identifiers.Float64 }, + { Names.Guid, Identifiers.Guid }, + { Names.Int16, Identifiers.Int16 }, + { Names.Int32, Identifiers.Int32 }, + { Names.Int64, Identifiers.Int64 }, + { Names.Int8, Identifiers.Int8 }, + { Names.List, Identifiers.List }, + { Names.ListContains, Identifiers.ListContains }, + { Names.Map, Identifiers.Map }, + { Names.MapContains, Identifiers.MapContains }, + { Names.MapContainsKey, Identifiers.MapContainsKey }, + { Names.MapContainsValue, Identifiers.MapContainsValue }, + { Names.Set, Identifiers.Set }, + { Names.SetContains, Identifiers.SetContains }, + { Names.Tuple, Identifiers.Tuple }, + { Names.Udt, Identifiers.Udt }, + { Names.UInt32, Identifiers.UInt32 }, { Names.Ceiling, Identifiers.Ceiling }, { Names.Concat, Identifiers.Concat }, { Names.Contains, Identifiers.Contains }, { Names.Cos, Identifiers.Cos }, { Names.Cot, Identifiers.Cot }, { Names.Count, Identifiers.Count }, + { Names.DateTimeAdd, Identifiers.DateTimeAdd }, + { Names.DateTimeDiff, Identifiers.DateTimeDiff }, + { Names.DateTimeFromParts, Identifiers.DateTimeFromParts }, + { Names.DateTimePart, Identifiers.DateTimePart }, + { Names.DateTimeToTicks, Identifiers.DateTimeToTicks }, + { Names.DateTimeToTimestamp, Identifiers.DateTimeToTimestamp }, { Names.Degrees, Identifiers.Degrees }, { Names.Documentid, Identifiers.Documentid }, { Names.Endswith, Identifiers.Endswith }, { Names.Exp, Identifiers.Exp }, { Names.Floor, Identifiers.Floor }, + { Names.GetCurrentDateTime, Identifiers.GetCurrentDateTime }, + { Names.GetCurrentTicks, Identifiers.GetCurrentTicks }, + { Names.GetCurrentTimestamp, Identifiers.GetCurrentTimestamp }, { Names.IndexOf, Identifiers.IndexOf }, { Names.IsArray, Identifiers.IsArray }, { Names.IsBool, Identifiers.IsBool }, @@ -70,6 +106,7 @@ sealed class SqlFunctionCallScalarExpression : SqlScalarExpression { Names.Ltrim, Identifiers.Ltrim }, { Names.Max, Identifiers.Max }, { Names.Min, Identifiers.Min }, + { Names.ObjectToArray, Identifiers.ObjectToArray }, { Names.Pi, Identifiers.Pi }, { Names.Power, Identifiers.Power }, { Names.Radians, Identifiers.Radians }, @@ -90,9 +127,19 @@ sealed class SqlFunctionCallScalarExpression : SqlScalarExpression { Names.StIsvalid, Identifiers.StIsvalid }, { Names.StIsvaliddetailed, Identifiers.StIsvaliddetailed }, { Names.StWithin, Identifiers.StWithin }, + { Names.StringEquals, Identifiers.StringEquals }, + { Names.StringToArray, Identifiers.StringToArray }, + { Names.StringToBoolean, Identifiers.StringToBoolean }, + { Names.StringToNull, Identifiers.StringToNull }, + { Names.StringToNumber, Identifiers.StringToNumber }, + { Names.StringToObject, Identifiers.StringToObject }, { Names.Substring, Identifiers.Substring }, { Names.Sum, Identifiers.Sum }, { Names.Tan, Identifiers.Tan }, + { Names.TicksToDateTime, Identifiers.TicksToDateTime }, + { Names.TimestampToDateTime, Identifiers.TimestampToDateTime }, + { Names.ToString, Identifiers.ToString }, + { Names.Trim, Identifiers.Trim }, { Names.Trunc, Identifiers.Trunc }, { Names.Upper, Identifiers.Upper }, }; @@ -194,6 +241,14 @@ public static class Names { public const string InternalCompareBsonBinaryData = "_COMPARE_BSON_BINARYDATA"; public const string InternalCompareObjects = "_COMPARE_OBJECTS"; + public const string InternalEvalEq = "_M_EVAL_EQ"; + public const string InternalEvalGt = "_M_EVAL_GT"; + public const string InternalEvalGte = "_M_EVAL_GTE"; + public const string InternalEvalIn = "_M_EVAL_IN"; + public const string InternalEvalLt = "_M_EVAL_LT"; + public const string InternalEvalLte = "_M_EVAL_LTE"; + public const string InternalEvalNeq = "_M_EVAL_NEQ"; + public const string InternalEvalNin = "_M_EVAL_NIN"; public const string InternalObjectToArray = "_ObjectToArray"; public const string InternalProxyProjection = "_PROXY_PROJECTION"; public const string InternalRegexMatch = "_REGEX_MATCH"; @@ -201,7 +256,6 @@ public static class Names public const string InternalStIntersects = "_ST_INTERSECTS"; public const string InternalStWithin = "_ST_WITHIN"; public const string InternalTryArrayContains = "_TRY_ARRAY_CONTAINS"; - public const string Abs = "ABS"; public const string Acos = "ACOS"; public const string All = "ALL"; @@ -215,17 +269,45 @@ public static class Names public const string Atan = "ATAN"; public const string Atn2 = "ATN2"; public const string Avg = "AVG"; + public const string Binary = "C_BINARY"; + public const string Float32 = "C_FLOAT32"; + public const string Float64 = "C_FLOAT64"; + public const string Guid = "C_GUID"; + public const string Int16 = "C_INT16"; + public const string Int32 = "C_INT32"; + public const string Int64 = "C_INT64"; + public const string Int8 = "C_INT8"; + public const string List = "C_LIST"; + public const string ListContains = "C_LISTCONTAINS"; + public const string Map = "C_MAP"; + public const string MapContains = "C_MAPCONTAINS"; + public const string MapContainsKey = "C_MAPCONTAINSKEY"; + public const string MapContainsValue = "C_MAPCONTAINSVALUE"; + public const string Set = "C_SET"; + public const string SetContains = "C_SETCONTAINS"; + public const string Tuple = "C_TUPLE"; + public const string Udt = "C_UDT"; + public const string UInt32 = "C_UINT32"; public const string Ceiling = "CEILING"; public const string Concat = "CONCAT"; public const string Contains = "CONTAINS"; public const string Cos = "COS"; public const string Cot = "COT"; public const string Count = "COUNT"; + public const string DateTimeAdd = "DateTimeAdd"; + public const string DateTimeDiff = "DateTimeDiff"; + public const string DateTimeFromParts = "DateTimeFromParts"; + public const string DateTimePart = "DateTimePart"; + public const string DateTimeToTicks = "DateTimeToTicks"; + public const string DateTimeToTimestamp = "DateTimeToTimestamp"; public const string Degrees = "DEGREES"; public const string Documentid = "DOCUMENTID"; public const string Endswith = "ENDSWITH"; public const string Exp = "EXP"; public const string Floor = "FLOOR"; + public const string GetCurrentDateTime = "GetCurrentDateTime"; + public const string GetCurrentTicks = "GetCurrentTicks"; + public const string GetCurrentTimestamp = "GetCurrentTimestamp"; public const string IndexOf = "INDEX_OF"; public const string IsArray = "IS_ARRAY"; public const string IsBool = "IS_BOOL"; @@ -245,6 +327,7 @@ public static class Names public const string Ltrim = "LTRIM"; public const string Max = "MAX"; public const string Min = "MIN"; + public const string ObjectToArray = "ObjectToArray"; public const string Pi = "PI"; public const string Power = "POWER"; public const string Radians = "RADIANS"; @@ -265,9 +348,21 @@ public static class Names public const string StIsvalid = "ST_ISVALID"; public const string StIsvaliddetailed = "ST_ISVALIDDETAILED"; public const string StWithin = "ST_WITHIN"; + public const string StringEquals = "StringEquals"; + public const string StringToArray = "StringToArray"; + public const string StringToBoolean = "StringToBoolean"; + public const string StringToNull = "StringToNull"; + public const string StringToNumber = "StringToNumber"; + public const string StringToObject = "StringToObject"; public const string Substring = "SUBSTRING"; public const string Sum = "SUM"; - public const string Tan = "TAN"; + public const string Tan = "TAN"; + public const string TicksToDateTime = "TicksToDateTime"; + public const string TimestampToDateTime = "TimestampToDateTime"; +#pragma warning disable CS0108 // Member hides inherited member; missing new keyword + public const string ToString = "ToString"; +#pragma warning restore CS0108 // Member hides inherited member; missing new keyword + public const string Trim = "TRIM"; public const string Trunc = "TRUNC"; public const string Upper = "UPPER"; } @@ -276,6 +371,14 @@ public static class Identifiers { public static readonly SqlIdentifier InternalCompareBsonBinaryData = SqlIdentifier.Create(Names.InternalCompareBsonBinaryData); public static readonly SqlIdentifier InternalCompareObjects = SqlIdentifier.Create(Names.InternalCompareObjects); + public static readonly SqlIdentifier InternalEvalEq = SqlIdentifier.Create(Names.InternalEvalEq); + public static readonly SqlIdentifier InternalEvalGt = SqlIdentifier.Create(Names.InternalEvalGt); + public static readonly SqlIdentifier InternalEvalGte = SqlIdentifier.Create(Names.InternalEvalGte); + public static readonly SqlIdentifier InternalEvalIn = SqlIdentifier.Create(Names.InternalEvalIn); + public static readonly SqlIdentifier InternalEvalLt = SqlIdentifier.Create(Names.InternalEvalLt); + public static readonly SqlIdentifier InternalEvalLte = SqlIdentifier.Create(Names.InternalEvalLte); + public static readonly SqlIdentifier InternalEvalNeq = SqlIdentifier.Create(Names.InternalEvalNeq); + public static readonly SqlIdentifier InternalEvalNin = SqlIdentifier.Create(Names.InternalEvalNin); public static readonly SqlIdentifier InternalObjectToArray = SqlIdentifier.Create(Names.InternalObjectToArray); public static readonly SqlIdentifier InternalProxyProjection = SqlIdentifier.Create(Names.InternalProxyProjection); public static readonly SqlIdentifier InternalRegexMatch = SqlIdentifier.Create(Names.InternalRegexMatch); @@ -283,7 +386,6 @@ public static class Identifiers public static readonly SqlIdentifier InternalStIntersects = SqlIdentifier.Create(Names.InternalStIntersects); public static readonly SqlIdentifier InternalStWithin = SqlIdentifier.Create(Names.InternalStWithin); public static readonly SqlIdentifier InternalTryArrayContains = SqlIdentifier.Create(Names.InternalTryArrayContains); - public static readonly SqlIdentifier Abs = SqlIdentifier.Create(Names.Abs); public static readonly SqlIdentifier Acos = SqlIdentifier.Create(Names.Acos); public static readonly SqlIdentifier All = SqlIdentifier.Create(Names.All); @@ -297,17 +399,45 @@ public static class Identifiers public static readonly SqlIdentifier Atan = SqlIdentifier.Create(Names.Atan); public static readonly SqlIdentifier Atn2 = SqlIdentifier.Create(Names.Atn2); public static readonly SqlIdentifier Avg = SqlIdentifier.Create(Names.Avg); + public static readonly SqlIdentifier Binary = SqlIdentifier.Create(Names.Binary); + public static readonly SqlIdentifier Float32 = SqlIdentifier.Create(Names.Float32); + public static readonly SqlIdentifier Float64 = SqlIdentifier.Create(Names.Float64); + public static readonly SqlIdentifier Guid = SqlIdentifier.Create(Names.Guid); + public static readonly SqlIdentifier Int16 = SqlIdentifier.Create(Names.Int16); + public static readonly SqlIdentifier Int32 = SqlIdentifier.Create(Names.Int32); + public static readonly SqlIdentifier Int64 = SqlIdentifier.Create(Names.Int64); + public static readonly SqlIdentifier Int8 = SqlIdentifier.Create(Names.Int8); + public static readonly SqlIdentifier List = SqlIdentifier.Create(Names.List); + public static readonly SqlIdentifier ListContains = SqlIdentifier.Create(Names.ListContains); + public static readonly SqlIdentifier Map = SqlIdentifier.Create(Names.Map); + public static readonly SqlIdentifier MapContains = SqlIdentifier.Create(Names.MapContains); + public static readonly SqlIdentifier MapContainsKey = SqlIdentifier.Create(Names.MapContainsKey); + public static readonly SqlIdentifier MapContainsValue = SqlIdentifier.Create(Names.MapContainsValue); + public static readonly SqlIdentifier Set = SqlIdentifier.Create(Names.Set); + public static readonly SqlIdentifier SetContains = SqlIdentifier.Create(Names.SetContains); + public static readonly SqlIdentifier Tuple = SqlIdentifier.Create(Names.Tuple); + public static readonly SqlIdentifier Udt = SqlIdentifier.Create(Names.Udt); + public static readonly SqlIdentifier UInt32 = SqlIdentifier.Create(Names.UInt32); public static readonly SqlIdentifier Ceiling = SqlIdentifier.Create(Names.Ceiling); public static readonly SqlIdentifier Concat = SqlIdentifier.Create(Names.Concat); public static readonly SqlIdentifier Contains = SqlIdentifier.Create(Names.Contains); public static readonly SqlIdentifier Cos = SqlIdentifier.Create(Names.Cos); public static readonly SqlIdentifier Cot = SqlIdentifier.Create(Names.Cot); public static readonly SqlIdentifier Count = SqlIdentifier.Create(Names.Count); + public static readonly SqlIdentifier DateTimeAdd = SqlIdentifier.Create(Names.DateTimeAdd); + public static readonly SqlIdentifier DateTimeDiff = SqlIdentifier.Create(Names.DateTimeDiff); + public static readonly SqlIdentifier DateTimeFromParts = SqlIdentifier.Create(Names.DateTimeFromParts); + public static readonly SqlIdentifier DateTimePart = SqlIdentifier.Create(Names.DateTimePart); + public static readonly SqlIdentifier DateTimeToTicks = SqlIdentifier.Create(Names.DateTimeToTicks); + public static readonly SqlIdentifier DateTimeToTimestamp = SqlIdentifier.Create(Names.DateTimeToTimestamp); public static readonly SqlIdentifier Degrees = SqlIdentifier.Create(Names.Degrees); public static readonly SqlIdentifier Documentid = SqlIdentifier.Create(Names.Documentid); public static readonly SqlIdentifier Endswith = SqlIdentifier.Create(Names.Endswith); public static readonly SqlIdentifier Exp = SqlIdentifier.Create(Names.Exp); public static readonly SqlIdentifier Floor = SqlIdentifier.Create(Names.Floor); + public static readonly SqlIdentifier GetCurrentDateTime = SqlIdentifier.Create(Names.GetCurrentDateTime); + public static readonly SqlIdentifier GetCurrentTicks = SqlIdentifier.Create(Names.GetCurrentTicks); + public static readonly SqlIdentifier GetCurrentTimestamp = SqlIdentifier.Create(Names.GetCurrentTimestamp); public static readonly SqlIdentifier IndexOf = SqlIdentifier.Create(Names.IndexOf); public static readonly SqlIdentifier IsArray = SqlIdentifier.Create(Names.IsArray); public static readonly SqlIdentifier IsBool = SqlIdentifier.Create(Names.IsBool); @@ -327,6 +457,7 @@ public static class Identifiers public static readonly SqlIdentifier Ltrim = SqlIdentifier.Create(Names.Ltrim); public static readonly SqlIdentifier Max = SqlIdentifier.Create(Names.Max); public static readonly SqlIdentifier Min = SqlIdentifier.Create(Names.Min); + public static readonly SqlIdentifier ObjectToArray = SqlIdentifier.Create(Names.ObjectToArray); public static readonly SqlIdentifier Pi = SqlIdentifier.Create(Names.Pi); public static readonly SqlIdentifier Power = SqlIdentifier.Create(Names.Power); public static readonly SqlIdentifier Radians = SqlIdentifier.Create(Names.Radians); @@ -347,9 +478,21 @@ public static class Identifiers public static readonly SqlIdentifier StIsvalid = SqlIdentifier.Create(Names.StIsvalid); public static readonly SqlIdentifier StIsvaliddetailed = SqlIdentifier.Create(Names.StIsvaliddetailed); public static readonly SqlIdentifier StWithin = SqlIdentifier.Create(Names.StWithin); + public static readonly SqlIdentifier StringEquals = SqlIdentifier.Create(Names.StringEquals); + public static readonly SqlIdentifier StringToArray = SqlIdentifier.Create(Names.StringToArray); + public static readonly SqlIdentifier StringToBoolean = SqlIdentifier.Create(Names.StringToBoolean); + public static readonly SqlIdentifier StringToNull = SqlIdentifier.Create(Names.StringToNull); + public static readonly SqlIdentifier StringToNumber = SqlIdentifier.Create(Names.StringToNumber); + public static readonly SqlIdentifier StringToObject = SqlIdentifier.Create(Names.StringToObject); public static readonly SqlIdentifier Substring = SqlIdentifier.Create(Names.Substring); public static readonly SqlIdentifier Sum = SqlIdentifier.Create(Names.Sum); - public static readonly SqlIdentifier Tan = SqlIdentifier.Create(Names.Tan); + public static readonly SqlIdentifier Tan = SqlIdentifier.Create(Names.Tan); + public static readonly SqlIdentifier TicksToDateTime = SqlIdentifier.Create(Names.TicksToDateTime); + public static readonly SqlIdentifier TimestampToDateTime = SqlIdentifier.Create(Names.TimestampToDateTime); +#pragma warning disable CS0108 // Member hides inherited member; missing new keyword + public static readonly SqlIdentifier ToString = SqlIdentifier.Create(Names.ToString); +#pragma warning restore CS0108 // Member hides inherited member; missing new keyword + public static readonly SqlIdentifier Trim = SqlIdentifier.Create(Names.Trim); public static readonly SqlIdentifier Trunc = SqlIdentifier.Create(Names.Trunc); public static readonly SqlIdentifier Upper = SqlIdentifier.Create(Names.Upper); } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestSpecialMethods.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestSpecialMethods.xml index 07664c0daf..d090874a64 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestSpecialMethods.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestSpecialMethods.xml @@ -17,7 +17,7 @@ FROM root]]> diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemLinqTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemLinqTests.cs index d3c8d7d3ef..4879691737 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemLinqTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemLinqTests.cs @@ -749,7 +749,7 @@ async Task TestSearch(Expression> expression, string ex await TestSearch(x => x.description.EndsWith("activity"), "ENDSWITH", false, 0); await TestSearch(x => x.description.EndsWith("AcTiViTy", StringComparison.OrdinalIgnoreCase), "ENDSWITH", true, 200); - await TestSearch(x => x.description.Equals("createrandomtodoactivity", StringComparison.OrdinalIgnoreCase), "STRINGEQUALS", true, 200); + await TestSearch(x => x.description.Equals("createrandomtodoactivity", StringComparison.OrdinalIgnoreCase), "StringEquals", true, 200); await TestSearch(x => x.description.Contains("todo"), "CONTAINS", false, 0); await TestSearch(x => x.description.Contains("tOdO", StringComparison.OrdinalIgnoreCase), "CONTAINS", true, 200); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/SqlObjectVisitorBaselineTests.SqlFunctionCalls.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/SqlObjectVisitorBaselineTests.SqlFunctionCalls.xml index a06b3ee271..4bf6c8e0d1 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/SqlObjectVisitorBaselineTests.SqlFunctionCalls.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/BaselineTest/TestBaseline/SqlObjectVisitorBaselineTests.SqlFunctionCalls.xml @@ -1,2322 +1,3908 @@ - - - - _COMPARE_BSON_BINARYDATA - - - - - - -1302450251 - - - - - - _COMPARE_OBJECTS - - - - - - 1834671385 - - - - - - _ObjectToArray - - - - - - -236268680 - - - - - - _PROXY_PROJECTION - - - - - - 610013180 - - - - - - _REGEX_MATCH - - - - - - -962904190 - - - - - - _ST_DISTANCE - - - - - - -1605852852 - - - - - - _ST_INTERSECTS - - - - - - -652359528 - - - - - - _ST_WITHIN - - - - - - 172593400 - - - - - - _TRY_ARRAY_CONTAINS - - - - - - 1151335009 - - - - - - ABS - - - - - - 948101022 - - - - - - ACOS - - - - - - 1660875890 - - - - - - ALL - - - - - - 948025334 - - - - - - ANY - - - - - - 948017723 - - - - - - ARRAY - - - - - - 1424287333 - - - - - - ARRAY_CONCAT - - - - - - -1615943767 - - - - - - ARRAY_CONTAINS - - - - - - -854810616 - - - - - - ARRAY_LENGTH - - - - - - -2104916661 - - - - - - ARRAY_SLICE - - - - - - -1823352982 - - - - - - ASIN - - - - - - 1734029734 - - - - - - ATAN - - - - - - 1730393998 - - - - - - ATN2 - - - - - - 1730444475 - - - - - - AVG - - - - - - 950772724 - - - - - - CEILING - - - - - - 326203514 - - - - - - CONCAT - - - - - - -551258348 - - - - - - CONTAINS - - - - - - -1074519824 - - - - - - COS - - - - - - 950901151 - - - - - - COT - - - - - - 950887618 - - - - - - COUNT - - - - - - 1275248890 - - - - - - DEGREES - - - - - - -1010818131 - - - - - - DOCUMENTID - - - - - - -1119491048 - - - - - - ENDSWITH - - - - - - 1310545128 - - - - - - EXP - - - - - - 1188489945 - - - - - - FLOOR - - - - - - 1595010801 - - - - - - INDEX_OF - - - - - - -490611053 - - - - - - IS_ARRAY - - - - - - -605857869 - - - - - - IS_BOOL - - - - - - -1031205701 - - - - - - IS_DEFINED - - - - - - -673974177 - - - - - - IS_FINITE_NUMBER - - - - - - 1858549009 - - - - - - IS_NULL - - - - - - 1695544283 - - - - - - IS_NUMBER - - - - - - 499272998 - - - - - - IS_OBJECT - - - - - - 1190524845 - - - - - - IS_PRIMITIVE - - - - - - -25700510 - - - - - - IS_STRING - - - - - - 197369964 - - - - - - LEFT - - - - - - 677167842 - - - - - - LENGTH - - - - - - 189371521 - - - - - - LIKE - - - - - - -535385742 - - - - - - LOG - - - - - - 951983273 - - - - - - LOG10 - - - - - - -1007856584 - - - - - - LOWER - - - - - - -1008756110 - - - - - - LTRIM - - - - - - -1298153349 - - - - - - MAX - - - - - - 951557458 - - - - - - MIN - - - - - - 951572494 - - - - - - PI - - - - - - 759877112 - - - - - - POWER - - - - - - -2065410283 - - - - - - RADIANS - - - - - - 2096097273 - - - - - - RAND - - - - - - -1422123156 - - - - - - REPLACE - - - - - - 611232669 - - - - - - REPLICATE - - - - - - -1759231678 - - - - - - REVERSE - - - - - - -716026956 - - - - - - RIGHT - - - - - - 891700551 - - - - - - ROUND - - - - - - 1845634331 - - - - - - RTRIM - - - - - - -1534507744 - - - - - - SIGN - - - - - - 1835961124 - - - - - - SIN - - - - - - 951887607 - - - - - - SQRT - - - - - - 2142163143 - - - - - - SQUARE - - - - - - -67058548 - - - - - - STARTSWITH - - - - - - 820442350 - - - - - - ST_DISTANCE - - - - - - 1233749487 - - - - - - ST_INTERSECTS - - - - - - 1992127418 - - - - - - ST_ISVALID - - - - - - -488760339 - - - - - - ST_ISVALIDDETAILED - - - - - - 202371336 - - - - - - ST_WITHIN - - - - - - 1288817159 - - - - - - SUBSTRING - - - - - - -1893316890 - - - - - - SUM - - - - - - 1189519259 - - - - - - TAN - - - - - - 1189160248 - - - - - - TRUNC - - - - - - -1614924416 - - - - - - UPPER - - - - - - 2018810216 - - - + + + + _COMPARE_BSON_BINARYDATA + + + + + + -1302450251 + + + + + + _COMPARE_OBJECTS + + + + + + 1834671385 + + + + + + _M_EVAL_EQ + + + + + + -937798776 + + + + + + _M_EVAL_GT + + + + + + -937689624 + + + + + + _M_EVAL_GTE + + + + + + 148219533 + + + + + + _M_EVAL_IN + + + + + + -1737483201 + + + + + + _M_EVAL_LT + + + + + + -934760921 + + + + + + _M_EVAL_LTE + + + + + + 30540149 + + + + + + _M_EVAL_NEQ + + + + + + 49027154 + + + + + + _M_EVAL_NIN + + + + + + -258213395 + + + + + + _ObjectToArray + + + + + + -236268680 + + + + + + _PROXY_PROJECTION + + + + + + 610013180 + + + + + + _REGEX_MATCH + + + + + + -962904190 + + + + + + _ST_DISTANCE + + + + + + -1605852852 + + + + + + _ST_INTERSECTS + + + + + + -652359528 + + + + + + _ST_WITHIN + + + + + + 172593400 + + + + + + _TRY_ARRAY_CONTAINS + + + + + + 1151335009 + + + + + + ABS + + + + + + 948101022 + + + + + + ACOS + + + + + + 1660875890 + + + + + + ALL + + + + + + 948025334 + + + + + + ANY + + + + + + 948017723 + + + + + + ARRAY + + + + + + 1424287333 + + + + + + ARRAY_CONCAT + + + + + + -1615943767 + + + + + + ARRAY_CONTAINS + + + + + + -854810616 + + + + + + ARRAY_LENGTH + + + + + + -2104916661 + + + + + + ARRAY_SLICE + + + + + + -1823352982 + + + + + + ASIN + + + + + + 1734029734 + + + + + + ATAN + + + + + + 1730393998 + + + + + + ATN2 + + + + + + 1730444475 + + + + + + AVG + + + + + + 950772724 + + + + + + C_BINARY + + + + + + 1210908139 + + + + + + C_FLOAT32 + + + + + + -472685730 + + + + + + C_FLOAT64 + + + + + + -472681688 + + + + + + C_GUID + + + + + + -1807738202 + + + + + + C_INT16 + + + + + + -384520670 + + + + + + C_INT32 + + + + + + -384524651 + + + + + + C_INT64 + + + + + + -384155345 + + + + + + C_INT8 + + + + + + -1805552873 + + + + + + C_LIST + + + + + + 1591190418 + + + + + + C_LISTCONTAINS + + + + + + 1693035758 + + + + + + C_MAP + + + + + + 1391965105 + + + + + + C_MAPCONTAINS + + + + + + 893948196 + + + + + + C_MAPCONTAINSKEY + + + + + + -1848028241 + + + + + + C_MAPCONTAINSVALUE + + + + + + -1676685015 + + + + + + C_SET + + + + + + 1490943678 + + + + + + C_SETCONTAINS + + + + + + -1431746769 + + + + + + C_TUPLE + + + + + + 1511703250 + + + + + + C_UDT + + + + + + -1775923376 + + + + + + C_UINT32 + + + + + + 1491911555 + + + + + + CEILING + + + + + + 326203514 + + + + + + CONCAT + + + + + + -551258348 + + + + + + CONTAINS + + + + + + -1074519824 + + + + + + COS + + + + + + 950901151 + + + + + + COT + + + + + + 950887618 + + + + + + COUNT + + + + + + 1275248890 + + + + + + DateTimeAdd + + + + + + 1570860718 + + + + + + DateTimeDiff + + + + + + 702180380 + + + + + + DateTimeFromParts + + + + + + 1715858645 + + + + + + DateTimePart + + + + + + 77619208 + + + + + + DateTimeToTicks + + + + + + -447006820 + + + + + + DateTimeToTimestamp + + + + + + 292597322 + + + + + + DEGREES + + + + + + -1010818131 + + + + + + DOCUMENTID + + + + + + -1119491048 + + + + + + ENDSWITH + + + + + + 1310545128 + + + + + + EXP + + + + + + 1188489945 + + + + + + FLOOR + + + + + + 1595010801 + + + + + + GetCurrentDateTime + + + + + + 628961137 + + + + + + GetCurrentTicks + + + + + + 767789568 + + + + + + GetCurrentTimestamp + + + + + + -108724186 + + + + + + INDEX_OF + + + + + + -490611053 + + + + + + IS_ARRAY + + + + + + -605857869 + + + + + + IS_BOOL + + + + + + -1031205701 + + + + + + IS_DEFINED + + + + + + -673974177 + + + + + + IS_FINITE_NUMBER + + + + + + 1858549009 + + + + + + IS_NULL + + + + + + 1695544283 + + + + + + IS_NUMBER + + + + + + 499272998 + + + + + + IS_OBJECT + + + + + + 1190524845 + + + + + + IS_PRIMITIVE + + + + + + -25700510 + + + + + + IS_STRING + + + + + + 197369964 + + + + + + LEFT + + + + + + 677167842 + + + + + + LENGTH + + + + + + 189371521 + + + + + + LIKE + + + + + + -535385742 + + + + + + LOG + + + + + + 951983273 + + + + + + LOG10 + + + + + + -1007856584 + + + + + + LOWER + + + + + + -1008756110 + + + + + + LTRIM + + + + + + -1298153349 + + + + + + MAX + + + + + + 951557458 + + + + + + MIN + + + + + + 951572494 + + + + + + ObjectToArray + + + + + + 1958364769 + + + + + + PI + + + + + + 759877112 + + + + + + POWER + + + + + + -2065410283 + + + + + + RADIANS + + + + + + 2096097273 + + + + + + RAND + + + + + + -1422123156 + + + + + + REPLACE + + + + + + 611232669 + + + + + + REPLICATE + + + + + + -1759231678 + + + + + + REVERSE + + + + + + -716026956 + + + + + + RIGHT + + + + + + 891700551 + + + + + + ROUND + + + + + + 1845634331 + + + + + + RTRIM + + + + + + -1534507744 + + + + + + SIGN + + + + + + 1835961124 + + + + + + SIN + + + + + + 951887607 + + + + + + SQRT + + + + + + 2142163143 + + + + + + SQUARE + + + + + + -67058548 + + + + + + STARTSWITH + + + + + + 820442350 + + + + + + ST_DISTANCE + + + + + + 1233749487 + + + + + + ST_INTERSECTS + + + + + + 1992127418 + + + + + + ST_ISVALID + + + + + + -488760339 + + + + + + ST_ISVALIDDETAILED + + + + + + 202371336 + + + + + + ST_WITHIN + + + + + + 1288817159 + + + + + + StringEquals + + + + + + 67992629 + + + + + + StringToArray + + + + + + 470263213 + + + + + + StringToBoolean + + + + + + -1874642418 + + + + + + StringToNull + + + + + + -970438357 + + + + + + StringToNumber + + + + + + 1152869235 + + + + + + StringToObject + + + + + + 72615192 + + + + + + SUBSTRING + + + + + + -1893316890 + + + + + + SUM + + + + + + 1189519259 + + + + + + TAN + + + + + + 1189160248 + + + + + + TicksToDateTime + + + + + + 688550720 + + + + + + TimestampToDateTime + + + + + + -721974150 + + + + + + ToString + + + + + + -1554853341 + + + + + + TRIM + + + + + + -1513216505 + + + + + + TRUNC + + + + + + -1614924416 + + + + + + UPPER + + + + + + 2018810216 + + + \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Batch/BatchAsyncContainerExecutorTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Batch/BatchAsyncContainerExecutorTests.cs index cc6a4af9eb..eb514d979b 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Batch/BatchAsyncContainerExecutorTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Batch/BatchAsyncContainerExecutorTests.cs @@ -57,7 +57,7 @@ public async Task RetryOnSplit() }, string.Empty); mockContainer.Setup(x => x.GetRoutingMapAsync(It.IsAny())).Returns(Task.FromResult(routingMap)); - BatchAsyncContainerExecutor executor = new BatchAsyncContainerExecutor(mockContainer.Object, mockedContext.Object, 20, Constants.MaxDirectModeBatchRequestBodySizeInBytes); + BatchAsyncContainerExecutor executor = new BatchAsyncContainerExecutor(mockContainer.Object, mockedContext.Object, 20, BatchAsyncContainerExecutorCache.DefaultMaxBulkRequestBodySizeInBytes); TransactionalBatchOperationResult result = await executor.AddAsync(itemBatchOperation); Mock.Get(mockContainer.Object) @@ -117,7 +117,7 @@ public async Task RetryOnNameStale() }, string.Empty); mockContainer.Setup(x => x.GetRoutingMapAsync(It.IsAny())).Returns(Task.FromResult(routingMap)); - BatchAsyncContainerExecutor executor = new BatchAsyncContainerExecutor(mockContainer.Object, mockedContext.Object, 20, Constants.MaxDirectModeBatchRequestBodySizeInBytes); + BatchAsyncContainerExecutor executor = new BatchAsyncContainerExecutor(mockContainer.Object, mockedContext.Object, 20, BatchAsyncContainerExecutorCache.DefaultMaxBulkRequestBodySizeInBytes); TransactionalBatchOperationResult result = await executor.AddAsync(itemBatchOperation); Mock.Get(mockContainer.Object) @@ -177,7 +177,7 @@ public async Task RetryOn429() }, string.Empty); mockContainer.Setup(x => x.GetRoutingMapAsync(It.IsAny())).Returns(Task.FromResult(routingMap)); - BatchAsyncContainerExecutor executor = new BatchAsyncContainerExecutor(mockContainer.Object, mockedContext.Object, 20, Constants.MaxDirectModeBatchRequestBodySizeInBytes); + BatchAsyncContainerExecutor executor = new BatchAsyncContainerExecutor(mockContainer.Object, mockedContext.Object, 20, BatchAsyncContainerExecutorCache.DefaultMaxBulkRequestBodySizeInBytes); TransactionalBatchOperationResult result = await executor.AddAsync(itemBatchOperation); Mock.Get(mockContainer.Object) @@ -236,7 +236,7 @@ public async Task DoesNotRecalculatePartitionKeyRangeOnNoSplits() }, string.Empty); mockContainer.Setup(x => x.GetRoutingMapAsync(It.IsAny())).Returns(Task.FromResult(routingMap)); - BatchAsyncContainerExecutor executor = new BatchAsyncContainerExecutor(mockContainer.Object, mockedContext.Object, 20, Constants.MaxDirectModeBatchRequestBodySizeInBytes); + BatchAsyncContainerExecutor executor = new BatchAsyncContainerExecutor(mockContainer.Object, mockedContext.Object, 20, BatchAsyncContainerExecutorCache.DefaultMaxBulkRequestBodySizeInBytes); TransactionalBatchOperationResult result = await executor.AddAsync(itemBatchOperation); Mock.Get(mockContainer.Object) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GatewayAddressCacheTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GatewayAddressCacheTests.cs new file mode 100644 index 0000000000..f487017628 --- /dev/null +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GatewayAddressCacheTests.cs @@ -0,0 +1,236 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ + +namespace Microsoft.Azure.Cosmos +{ + using System; + using System.Net.Http; + using Microsoft.VisualStudio.TestTools.UnitTesting; + using Moq; + using Microsoft.Azure.Documents; + using Microsoft.Azure.Cosmos.Routing; + using System.Threading.Tasks; + using System.Threading; + using System.Net; + using System.Text; + using System.Collections.ObjectModel; + using System.Collections.Generic; + using System.Linq; + + /// + /// Tests for . + /// + [TestClass] + public class GatewayAddressCacheTests + { + private const string DatabaseAccountApiEndpoint = "https://endpoint.azure.com"; + private Mock mockTokenProvider; + private Mock mockServiceConfigReader; + private int targetReplicaSetSize = 4; + private PartitionKeyRangeIdentity testPartitionKeyRangeIdentity; + private ServiceIdentity serviceIdentity; + private Uri serviceName; + + public GatewayAddressCacheTests() + { + this.mockTokenProvider = new Mock(); + string payload; + this.mockTokenProvider.Setup(foo => foo.GetUserAuthorizationToken(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), out payload)) + .Returns("token!"); + this.mockServiceConfigReader = new Mock(); + this.mockServiceConfigReader.Setup(foo => foo.SystemReplicationPolicy).Returns(new ReplicationPolicy() { MaxReplicaSetSize = this.targetReplicaSetSize }); + this.mockServiceConfigReader.Setup(foo => foo.UserReplicationPolicy).Returns(new ReplicationPolicy() { MaxReplicaSetSize = this.targetReplicaSetSize }); + this.testPartitionKeyRangeIdentity = new PartitionKeyRangeIdentity("YxM9ANCZIwABAAAAAAAAAA==", "YxM9ANCZIwABAAAAAAAAAA=="); + this.serviceName = new Uri(GatewayAddressCacheTests.DatabaseAccountApiEndpoint); + this.serviceIdentity = new ServiceIdentity("federation1", this.serviceName, false); + } + + [TestMethod] + public void TestGatewayAddressCacheAutoRefreshOnSuboptimalPartition() + { + FakeMessageHandler messageHandler = new FakeMessageHandler(); + HttpClient httpClient = new HttpClient(messageHandler); + httpClient.Timeout = TimeSpan.FromSeconds(120); + GatewayAddressCache cache = new GatewayAddressCache( + new Uri(GatewayAddressCacheTests.DatabaseAccountApiEndpoint), + Documents.Client.Protocol.Https, + this.mockTokenProvider.Object, + this.mockServiceConfigReader.Object, + httpClient, + suboptimalPartitionForceRefreshIntervalInSeconds: 2); + + int initialAddressesCount = cache.TryGetAddressesAsync( + DocumentServiceRequest.Create(OperationType.Invalid, ResourceType.Address, AuthorizationTokenType.Invalid), + this.testPartitionKeyRangeIdentity, + this.serviceIdentity, + false, + CancellationToken.None).Result.AllAddresses.Count(); + + Assert.IsTrue(initialAddressesCount < this.targetReplicaSetSize); + + Task.Delay(3000).Wait(); + + int finalAddressCount = cache.TryGetAddressesAsync( + DocumentServiceRequest.Create(OperationType.Invalid, ResourceType.Address, AuthorizationTokenType.Invalid), + this.testPartitionKeyRangeIdentity, + this.serviceIdentity, + false, + CancellationToken.None).Result.AllAddresses.Count(); + + Assert.IsTrue(finalAddressCount == this.targetReplicaSetSize); + } + + [TestMethod] + public async Task TestGatewayAddressCacheUpdateOnConnectionResetAsync() + { + FakeMessageHandler messageHandler = new FakeMessageHandler(); + HttpClient httpClient = new HttpClient(messageHandler); + httpClient.Timeout = TimeSpan.FromSeconds(120); + GatewayAddressCache cache = new GatewayAddressCache( + new Uri(GatewayAddressCacheTests.DatabaseAccountApiEndpoint), + Documents.Client.Protocol.Https, + this.mockTokenProvider.Object, + this.mockServiceConfigReader.Object, + httpClient, + suboptimalPartitionForceRefreshIntervalInSeconds: 2, + enableTcpConnectionEndpointRediscovery: true); + + PartitionAddressInformation addresses = cache.TryGetAddressesAsync( + DocumentServiceRequest.Create(OperationType.Invalid, ResourceType.Address, AuthorizationTokenType.Invalid), + this.testPartitionKeyRangeIdentity, + this.serviceIdentity, + false, + CancellationToken.None).Result; + + Assert.IsNotNull(addresses.AllAddresses.Select(address => address.PhysicalUri == "https://blabla.com")); + + // call updateAddress + await cache.TryRemoveAddressesAsync(new Documents.Rntbd.ServerKey(new Uri("https://blabla.com")), CancellationToken.None); + + // check if the addresss is updated + addresses = cache.TryGetAddressesAsync( + DocumentServiceRequest.Create(OperationType.Invalid, ResourceType.Address, AuthorizationTokenType.Invalid), + this.testPartitionKeyRangeIdentity, + this.serviceIdentity, + false, + CancellationToken.None).Result; + + Assert.IsNotNull(addresses.AllAddresses.Select(address => address.PhysicalUri == "https://blabla5.com")); + } + + [TestMethod] + [Timeout(2000)] + public void GlobalAddressResolverUpdateAsyncSynchronizationTest() + { + SynchronizationContext prevContext = SynchronizationContext.Current; + try + { + TestSynchronizationContext syncContext = new TestSynchronizationContext(); + SynchronizationContext.SetSynchronizationContext(syncContext); + syncContext.Post(_ => + { + UserAgentContainer container = new UserAgentContainer(); + FakeMessageHandler messageHandler = new FakeMessageHandler(); + + AccountProperties databaseAccount = new AccountProperties(); + Mock mockDocumentClient = new Mock(); + mockDocumentClient.Setup(owner => owner.ServiceEndpoint).Returns(new Uri("https://blabla.com/")); + mockDocumentClient.Setup(owner => owner.GetDatabaseAccountInternalAsync(It.IsAny(), It.IsAny())).ReturnsAsync(databaseAccount); + + GlobalEndpointManager globalEndpointManager = new GlobalEndpointManager(mockDocumentClient.Object, new ConnectionPolicy()); + + ConnectionPolicy connectionPolicy = new ConnectionPolicy + { + RequestTimeout = TimeSpan.FromSeconds(10) + }; + + GlobalAddressResolver globalAddressResolver = new GlobalAddressResolver(globalEndpointManager, Documents.Client.Protocol.Tcp, this.mockTokenProvider.Object, null, null, this.mockServiceConfigReader.Object, connectionPolicy, new HttpClient(messageHandler)); + + ConnectionStateListener connectionStateListener = new ConnectionStateListener(globalAddressResolver); + connectionStateListener.OnConnectionEvent(ConnectionEvent.ReadEof, DateTime.Now, new Documents.Rntbd.ServerKey(new Uri("https://endpoint.azure.com:4040/"))); + + }, state: null); + } + finally + { + SynchronizationContext.SetSynchronizationContext(prevContext); + } + } + + private class FakeMessageHandler : HttpMessageHandler + { + private bool returnFullReplicaSet; + private bool returnUpdatedAddresses; + + public FakeMessageHandler() + { + this.returnFullReplicaSet = false; + this.returnUpdatedAddresses = false; + } + + protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + { + List
addresses = new List
() + { + new Address() { IsPrimary = true, PhysicalUri = "https://blabla.com", Protocol = RuntimeConstants.Protocols.HTTPS, PartitionKeyRangeId = "YxM9ANCZIwABAAAAAAAAAA==" }, + new Address() { IsPrimary = false, PhysicalUri = "https://blabla3.com", Protocol = RuntimeConstants.Protocols.HTTPS, PartitionKeyRangeId = "YxM9ANCZIwABAAAAAAAAAA==" }, + new Address() { IsPrimary = false, PhysicalUri = "https://blabla2.com", Protocol = RuntimeConstants.Protocols.HTTPS, PartitionKeyRangeId = "YxM9ANCZIwABAAAAAAAAAA==" }, + }; + + if (this.returnFullReplicaSet) + { + addresses.Add(new Address() { IsPrimary = false, PhysicalUri = "https://blabla4.com", Protocol = RuntimeConstants.Protocols.HTTPS, PartitionKeyRangeId = "YxM9ANCZIwABAAAAAAAAAA==" }); + this.returnFullReplicaSet = false; + } + else + { + this.returnFullReplicaSet = true; + } + + if (this.returnUpdatedAddresses) + { + addresses.RemoveAll(address => address.IsPrimary == true); + addresses.Add(new Address() { IsPrimary = true, PhysicalUri = "https://blabla5.com", Protocol = RuntimeConstants.Protocols.HTTPS, PartitionKeyRangeId = "YxM9ANCZIwABAAAAAAAAAA==" }); + this.returnUpdatedAddresses = false; + } + else + { + this.returnUpdatedAddresses = true; + } + + FeedResource
addressFeedResource = new FeedResource
() + { + Id = "YxM9ANCZIwABAAAAAAAAAA==", + SelfLink = "dbs/YxM9AA==/colls/YxM9ANCZIwA=/docs/YxM9ANCZIwABAAAAAAAAAA==/", + Timestamp = DateTime.Now, + InnerCollection = new Collection
(addresses), + }; + + StringBuilder feedResourceString = new StringBuilder(); + addressFeedResource.SaveTo(feedResourceString); + + StringContent content = new StringContent(feedResourceString.ToString()); + HttpResponseMessage responseMessage = new HttpResponseMessage() + { + StatusCode = HttpStatusCode.OK, + Content = content, + }; + + return Task.FromResult(responseMessage); + } + } + + public class TestSynchronizationContext : SynchronizationContext + { + private object locker = new object(); + public override void Post(SendOrPostCallback d, object state) + { + lock (this.locker) + { + d(state); + } + } + } + } +} diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/SqlObjects/SqlObjectVisitorBaselineTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/SqlObjects/SqlObjectVisitorBaselineTests.cs index 7db730f88f..42c183e1af 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/SqlObjects/SqlObjectVisitorBaselineTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/SqlObjects/SqlObjectVisitorBaselineTests.cs @@ -6,7 +6,8 @@ namespace Microsoft.Azure.Cosmos.Test.SqlObjects { using System; - using System.Collections.Generic; + using System.Collections.Generic; + using System.Data.SqlTypes; using System.Globalization; using System.Linq; using System.Text.RegularExpressions; @@ -285,8 +286,70 @@ public void SqlFunctionCalls() SqlFunctionCallScalarExpression.CreateBuiltin( SqlFunctionCallScalarExpression.Identifiers.InternalCompareObjects, SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(42)), - SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(1337))))); - + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(1337))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.InternalEvalEq, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.InternalEvalEq, + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("field")), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(42))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.InternalEvalGt, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.InternalEvalGt, + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("field")), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(42))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.InternalEvalGte, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.InternalEvalGte, + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("field")), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(42))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.InternalEvalIn, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.InternalEvalIn, + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("field")), + SqlArrayCreateScalarExpression.Create( + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(1)), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(2)), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(3)))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.InternalEvalLt, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.InternalEvalLt, + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("field")), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(42))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.InternalEvalLte, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.InternalEvalLte, + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("field")), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(42))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.InternalEvalNeq, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.InternalEvalNeq, + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("field")), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(42))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.InternalEvalNin, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.InternalEvalNin, + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("field")), + SqlArrayCreateScalarExpression.Create( + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(1)), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(2)), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(3)))))); + inputs.Add(new SqlObjectVisitorInput( SqlFunctionCallScalarExpression.Names.InternalObjectToArray, SqlFunctionCallScalarExpression.CreateBuiltin( @@ -434,6 +497,156 @@ public void SqlFunctionCalls() SqlFunctionCallScalarExpression.Identifiers.Avg, SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(42))))); + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.Binary, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.Binary, + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(42))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.Float32, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.Float32, + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(4.08))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.Float64, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.Float64, + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(4.08))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.Guid, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.Guid, + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(12345))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.Int16, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.Int16, + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(42))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.Int32, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.Int32, + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(42))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.Int64, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.Int64, + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(42))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.Int8, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.Int8, + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(4))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.List, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.List, + SqlArrayCreateScalarExpression.Create( + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(1)), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(2)), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(3)))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.ListContains, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.ListContains, + SqlArrayCreateScalarExpression.Create( + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(1)), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(2)), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(3))), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(2))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.Map, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.Map, + SqlArrayCreateScalarExpression.Create( + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("hi:1")), + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("hello:2")), + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("sup:3")))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.MapContains, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.MapContains, + SqlArrayCreateScalarExpression.Create( + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("hi:1")), + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("hello:2")), + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("sup:3"))), + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("key")), + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("Value"))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.MapContainsKey, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.MapContainsKey, + SqlArrayCreateScalarExpression.Create( + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("hi:1")), + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("hello:2")), + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("sup:3"))), + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("key"))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.MapContainsValue, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.MapContainsValue, + SqlArrayCreateScalarExpression.Create( + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("hi:1")), + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("hello:2")), + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("sup:3"))), + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("value"))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.Set, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.Set, + SqlArrayCreateScalarExpression.Create( + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(1)), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(2)), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(3)))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.SetContains, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.SetContains, + SqlArrayCreateScalarExpression.Create( + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(1)), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(2)), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(3))), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(2))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.Tuple, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.Tuple, + SqlArrayCreateScalarExpression.Create( + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(1)), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(2)), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(3)))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.Udt, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.Udt, + SqlArrayCreateScalarExpression.Create( + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("random")), + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("type")), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(3)))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.UInt32, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.UInt32, + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(42))))); + inputs.Add(new SqlObjectVisitorInput( SqlFunctionCallScalarExpression.Names.Ceiling, SqlFunctionCallScalarExpression.CreateBuiltin( @@ -472,6 +685,49 @@ public void SqlFunctionCalls() SqlFunctionCallScalarExpression.Identifiers.Count, SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(42))))); + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.DateTimeAdd, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.DateTimeAdd, + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("Year")), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(2020)), + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("YYYY"))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.DateTimeDiff, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.DateTimeAdd, + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("Year")), + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("2020-08-06T20:45:22.1234567Z")), + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("2020-08-06T20:45:22.1234567Z"))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.DateTimeFromParts, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.DateTimeFromParts, + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(2020)), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(08)), + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(06))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.DateTimePart, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.DateTimePart, + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("Year")), + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("2020-08-06T20:45:22.1234567Z"))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.DateTimeToTicks, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.DateTimeToTicks, + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("2020-08-06T20:45:22.1234567Z"))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.DateTimeToTimestamp, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.DateTimeToTimestamp, + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("2020-08-06T20:45:22.1234567Z"))))); + inputs.Add(new SqlObjectVisitorInput( SqlFunctionCallScalarExpression.Names.Degrees, SqlFunctionCallScalarExpression.CreateBuiltin( @@ -501,7 +757,22 @@ public void SqlFunctionCalls() SqlFunctionCallScalarExpression.Names.Floor, SqlFunctionCallScalarExpression.CreateBuiltin( SqlFunctionCallScalarExpression.Identifiers.Floor, - SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(42))))); + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(42))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.GetCurrentDateTime, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.GetCurrentDateTime))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.GetCurrentTicks, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.GetCurrentTicks))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.GetCurrentTimestamp, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.GetCurrentTimestamp))); inputs.Add(new SqlObjectVisitorInput( SqlFunctionCallScalarExpression.Names.IndexOf, @@ -621,6 +892,12 @@ public void SqlFunctionCalls() SqlFunctionCallScalarExpression.Identifiers.Min, SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(42))))); + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.ObjectToArray, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.ObjectToArray, + SqlLiteralScalarExpression.Create(SqlNullLiteral.Singleton)))); + inputs.Add(new SqlObjectVisitorInput( SqlFunctionCallScalarExpression.Names.Pi, SqlFunctionCallScalarExpression.CreateBuiltin( @@ -748,6 +1025,43 @@ public void SqlFunctionCalls() SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(42)), SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(42))))); + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.StringEquals, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.StringEquals, + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("hi")), + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("hello"))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.StringToArray, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.StringToArray, + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("[1, 2, 3]"))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.StringToBoolean, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.StringToBoolean, + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("true"))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.StringToNull, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.StringToNull, + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("null"))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.StringToNumber, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.StringToNumber, + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("420"))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.StringToObject, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.StringToObject, + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("object"))))); + inputs.Add(new SqlObjectVisitorInput( SqlFunctionCallScalarExpression.Names.Substring, SqlFunctionCallScalarExpression.CreateBuiltin( @@ -768,6 +1082,30 @@ public void SqlFunctionCalls() SqlFunctionCallScalarExpression.Identifiers.Tan, SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(42))))); + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.TicksToDateTime, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.TicksToDateTime, + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(123456))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.TimestampToDateTime, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.TimestampToDateTime, + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("2020-08-06T20:45:22.1234567Z"))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.ToString, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.ToString, + SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(123456))))); + + inputs.Add(new SqlObjectVisitorInput( + SqlFunctionCallScalarExpression.Names.Trim, + SqlFunctionCallScalarExpression.CreateBuiltin( + SqlFunctionCallScalarExpression.Identifiers.Trim, + SqlLiteralScalarExpression.Create(SqlStringLiteral.Create(" hair "))))); + inputs.Add(new SqlObjectVisitorInput( SqlFunctionCallScalarExpression.Names.Trunc, SqlFunctionCallScalarExpression.CreateBuiltin( diff --git a/UpdateContracts.ps1 b/UpdateContracts.ps1 index 2af13c332b..bbbf192d2c 100644 --- a/UpdateContracts.ps1 +++ b/UpdateContracts.ps1 @@ -5,7 +5,7 @@ #Run the Cosmos DB SDK GA contract tests $projResult = dotnet test '.\Microsoft.Azure.Cosmos\tests\Microsoft.Azure.Cosmos.Tests\Microsoft.Azure.Cosmos.Tests.csproj' --filter "TestCategory=UpdateContract" --configuration Release -$updatedContractFile = ".\Microsoft.Azure.Cosmos\tests\Microsoft.Azure.Cosmos.Tests\bin\Release\netcoreapp2.0\Contracts\DotNetSDKAPIChanges.json" +$updatedContractFile = ".\Microsoft.Azure.Cosmos\tests\Microsoft.Azure.Cosmos.Tests\bin\Release\netcoreapp2.1\Contracts\DotNetSDKAPIChanges.json" if(!(Test-Path -Path $updatedContractFile)){ Write-Error ("The contract file did not get updated with the build. Please fix the test to output the contract file: " + $updatedContractFile) }else{ @@ -13,7 +13,7 @@ if(!(Test-Path -Path $updatedContractFile)){ Write-Output ("Updated contract " + $updatedContractFile) } -$updatedContractFolder = ".\Microsoft.Azure.Cosmos\tests\Microsoft.Azure.Cosmos.Tests\bin\Release\netcoreapp2.0\BaselineTest\TestOutput\*" +$updatedContractFolder = ".\Microsoft.Azure.Cosmos\tests\Microsoft.Azure.Cosmos.Tests\bin\Release\netcoreapp2.1\BaselineTest\TestOutput\*" if(!(Test-Path -Path $updatedContractFolder)){ Write-Error ("The contract file did not get updated with the build. Please fix the test to output the contract file: " + $updatedContractFile) }else{ @@ -24,7 +24,7 @@ if(!(Test-Path -Path $updatedContractFolder)){ #Run the Cosmos DB SDK Preview contract tests $projResult = dotnet test '.\Microsoft.Azure.Cosmos\tests\Microsoft.Azure.Cosmos.Tests\Microsoft.Azure.Cosmos.Tests.csproj' --filter "TestCategory=UpdateContract" --configuration Release -p:IsPreview=true -$updatedContractFile = ".\Microsoft.Azure.Cosmos\tests\Microsoft.Azure.Cosmos.Tests\bin\Release\netcoreapp2.0\Contracts\DotNetPreviewSDKAPIChanges.json" +$updatedContractFile = ".\Microsoft.Azure.Cosmos\tests\Microsoft.Azure.Cosmos.Tests\bin\Release\netcoreapp2.1\Contracts\DotNetPreviewSDKAPIChanges.json" if(!(Test-Path -Path $updatedContractFile)){ Write-Error ("The contract file did not get updated with the preview build. Please fix the test to output the contract file: " + $updatedContractFile) }else{ @@ -35,7 +35,7 @@ if(!(Test-Path -Path $updatedContractFile)){ #Run the Encryption SDK contract tests $projResult = dotnet test '.\Microsoft.Azure.Cosmos.Encryption\tests\Microsoft.Azure.Cosmos.Encryption.Tests\Microsoft.Azure.Cosmos.Encryption.Tests.csproj' --filter "TestCategory=UpdateContract" --configuration Release -$updatedContractFile = ".\Microsoft.Azure.Cosmos.Encryption\tests\Microsoft.Azure.Cosmos.Encryption.Tests\bin\Release\netcoreapp2.0\Contracts\DotNetSDKEncryptionAPIChanges.json" +$updatedContractFile = ".\Microsoft.Azure.Cosmos.Encryption\tests\Microsoft.Azure.Cosmos.Encryption.Tests\bin\Release\netcoreapp2.1\Contracts\DotNetSDKEncryptionAPIChanges.json" if(!(Test-Path -Path $updatedContractFile)){ Write-Error ("The contract file did not get updated with the build. Please fix the test to output the contract file: " + $updatedContractFile) }else{