Ejemplo n.º 1
0
        public void TestDateTimeOffsetOrdering()
        {
            ShardKeyInfo[] dateTimeOffsetShardKeyInfos =
                ShardKeyInfo.AllTestShardKeyInfosGroupedByType[ShardKeyType.DateTimeOffset]
                .ToArray();

            for (int i = 0; i < dateTimeOffsetShardKeyInfos.Length - 1; i++)
            {
                ShardKeyInfo low  = dateTimeOffsetShardKeyInfos[i];
                ShardKeyInfo high = dateTimeOffsetShardKeyInfos[i + 1];

                Console.WriteLine("({0}) < ({1})", low, high);

                // https://github.com/Azure/elastic-db-tools/issues/117
                // Bug? DateTimeOffsets with the same universal time but different offset are equal as ShardKeys.
                // According to SQL (and our normalization format), they should be unequal, although according to .NET they should be equal.
                if (high.Value != null && ((DateTimeOffset)low.Value).UtcDateTime == ((DateTimeOffset)high.Value).UtcDateTime)
                {
                    Assert.AreEqual(low.ShardKeyFromValue, high.ShardKeyFromValue);
                }
                else
                {
                    AssertExtensions.AssertGreaterThan(low.ShardKeyFromValue, high.ShardKeyFromValue);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets a command that fails on one shard, but succeeds on others
        /// </summary>
        private string GetPartialFailureQuery()
        {
            IEnumerable <ShardLocation> shardLocations = _shardMap.GetShards().Select(s => s.Location);

            // Pick an arbitrary one of those shards
            ShardLocation chosenShardLocation = shardLocations.First();

            // This query assumes that the chosen shard location's db name is distinct from all others
            // In other words, only one shard location should have a database equal to the chosen location
            Assert.AreEqual(1, shardLocations.Count(l => l.Database.Equals(chosenShardLocation.Database)));

            // We also assume that there is more than one shard
            AssertExtensions.AssertGreaterThan(1, shardLocations.Count());

            // The command will fail only on the chosen shard
            return(string.Format("if db_name() = '{0}' raiserror('blah', 16, 0) else select 1",
                                 shardLocations.First().Database));
        }