当前位置: 首页>>代码示例>>C#>>正文


C# ShardMapManager.GetRangeShardMap方法代码示例

本文整理汇总了C#中ShardMapManager.GetRangeShardMap方法的典型用法代码示例。如果您正苦于以下问题:C# ShardMapManager.GetRangeShardMap方法的具体用法?C# ShardMapManager.GetRangeShardMap怎么用?C# ShardMapManager.GetRangeShardMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ShardMapManager的用法示例。


在下文中一共展示了ShardMapManager.GetRangeShardMap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddRangeMappingDefault

        public void AddRangeMappingDefault()
        {
            CountingCacheStore countingCache = new CountingCacheStore(new CacheStore());

            ShardMapManager smm = new ShardMapManager(
                new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
                new SqlStoreConnectionFactory(),
                new StoreOperationFactory(),
                countingCache,
                ShardMapManagerLoadPolicy.Lazy,
                new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior);

            RangeShardMap<int> rsm = smm.GetRangeShardMap<int>(ShardMapperTests.s_rangeShardMapName);

            Assert.IsNotNull(rsm);

            ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]);

            Shard s = rsm.CreateShard(sl);

            Assert.IsNotNull(s);

            RangeMapping<int> r1 = rsm.CreateRangeMapping(new Range<int>(1, 10), s);

            Assert.IsNotNull(r1);

            RangeMapping<int> rLookup = rsm.GetMappingForKey(1);

            Assert.AreEqual(ShardKeyType.Int32, rLookup.Range.KeyType);

            Assert.IsNotNull(rLookup);
            Assert.AreEqual(0, countingCache.LookupMappingHitCount);
        }
开发者ID:xdansmith,项目名称:elastic-db-tools,代码行数:33,代码来源:ShardMapperTests.cs

示例2: UpdateRangeMappingLocationAbortGSMPostLocalDoAndLSMTargetUndo

        public void UpdateRangeMappingLocationAbortGSMPostLocalDoAndLSMTargetUndo()
        {
            bool shouldThrow = false;

            IStoreOperationFactory sof = new StubStoreOperationFactory()
            {
                CallBase = true,
                CreateUpdateMappingOperationShardMapManagerStoreOperationCodeIStoreShardMapIStoreMappingIStoreMappingStringGuid =
                (_smm, _opcode, _ssm, _sms, _smt, _p, _loid) =>
                {
                    StubUpdateMappingOperation op = new StubUpdateMappingOperation(_smm, _opcode, _ssm, _sms, _smt, _p, _loid);
                    op.CallBase = true;
                    op.DoGlobalPostLocalExecuteIStoreTransactionScope = (ts) =>
                    {
                        if (shouldThrow)
                        {
                            throw new StoreException("", ShardMapFaultHandlingTests.TransientSqlException);
                        }
                        else
                        {
                            // Call the base function, hack for this behavior is to save current operation, set current to null, restore current operation.
                            var original = op.DoGlobalPostLocalExecuteIStoreTransactionScope;

                            op.DoGlobalPostLocalExecuteIStoreTransactionScope = null;
                            try
                            {
                                return op.DoGlobalPostLocalExecute(ts);
                            }
                            finally
                            {
                                op.DoGlobalPostLocalExecuteIStoreTransactionScope = original;
                            }
                        }
                    };

                    op.UndoLocalTargetExecuteIStoreTransactionScope = (ts) =>
                    {
                        if (shouldThrow)
                        {
                            throw new StoreException("", ShardMapFaultHandlingTests.TransientSqlException);
                        }
                        else
                        {
                            // Call the base function, hack for this behavior is to save current operation, set current to null, restore current operation.
                            var original = op.UndoLocalTargetExecuteIStoreTransactionScope;

                            op.UndoLocalTargetExecuteIStoreTransactionScope = null;
                            try
                            {
                                return op.UndoLocalTargetExecute(ts);
                            }
                            finally
                            {
                                op.UndoLocalTargetExecuteIStoreTransactionScope = original;
                            }
                        }
                    };

                    return op;
                }
            };

            ShardMapManager smm = new ShardMapManager(
                new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
                new SqlStoreConnectionFactory(),
                sof,
                new CacheStore(),
                ShardMapManagerLoadPolicy.Lazy,
                new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior);

            RangeShardMap<int> rsm = smm.GetRangeShardMap<int>(ShardMapperTests.s_rangeShardMapName);

            Assert.IsNotNull(rsm);

            ShardLocation sl1 = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]);
            Shard s1 = rsm.CreateShard(sl1);
            Assert.IsNotNull(s1);

            ShardLocation sl2 = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[1]);
            Shard s2 = rsm.CreateShard(sl2);
            Assert.IsNotNull(s2);

            RangeMapping<int> r1 = rsm.CreateRangeMapping(new Range<int>(1, 20), s1);

            RangeMappingUpdate ru1 = new RangeMappingUpdate();
            // Take the mapping offline first.
            ru1.Status = MappingStatus.Offline;
            RangeMapping<int> rNew = rsm.UpdateMapping(r1, ru1);
            Assert.IsNotNull(rNew);

            RangeMappingUpdate ru2 = new RangeMappingUpdate();
            ru2.Shard = s2;

            shouldThrow = true;

            bool storeOperationFailed = false;
            try
            {
                rNew = rsm.UpdateMapping(rNew, ru2);
                Assert.IsNotNull(rNew);
//.........这里部分代码省略.........
开发者ID:xdansmith,项目名称:elastic-db-tools,代码行数:101,代码来源:ShardMapperTests.cs

示例3: MergeRangeMappingAbortSourceLocalDoAndGSMPostLocalUndo

        public void MergeRangeMappingAbortSourceLocalDoAndGSMPostLocalUndo()
        {
            bool shouldThrow = true;

            IStoreOperationFactory sof = new StubStoreOperationFactory()
            {
                CallBase = true,
                CreateReplaceMappingsOperationShardMapManagerStoreOperationCodeIStoreShardMapTupleOfIStoreMappingGuidArrayTupleOfIStoreMappingGuidArray =
                (_smm, _opcode, _ssm, _smo, _smn) =>
                {
                    StubReplaceMappingsOperation op = new StubReplaceMappingsOperation(_smm, _opcode, _ssm, _smo, _smn);
                    op.CallBase = true;
                    op.DoLocalSourceExecuteIStoreTransactionScope = (ts) =>
                    {
                        if (shouldThrow)
                        {
                            throw new StoreException("", ShardMapFaultHandlingTests.TransientSqlException);
                        }
                        else
                        {
                            // Call the base function, hack for this behavior is to save current operation, set current to null, restore current operation.
                            var original = op.DoLocalSourceExecuteIStoreTransactionScope;

                            op.DoLocalSourceExecuteIStoreTransactionScope = null;
                            try
                            {
                                return op.DoLocalSourceExecute(ts);
                            }
                            finally
                            {
                                op.DoLocalSourceExecuteIStoreTransactionScope = original;
                            }
                        }
                    };

                    op.UndoGlobalPostLocalExecuteIStoreTransactionScope = (ts) =>
                    {
                        if (shouldThrow)
                        {
                            throw new StoreException("", ShardMapFaultHandlingTests.TransientSqlException);
                        }
                        else
                        {
                            // Call the base function, hack for this behavior is to save current operation, set current to null, restore current operation.
                            var original = op.UndoGlobalPostLocalExecuteIStoreTransactionScope;

                            op.UndoGlobalPostLocalExecuteIStoreTransactionScope = null;
                            try
                            {
                                return op.UndoGlobalPostLocalExecute(ts);
                            }
                            finally
                            {
                                op.UndoGlobalPostLocalExecuteIStoreTransactionScope = original;
                            }
                        }
                    };

                    return op;
                }
            };

            ShardMapManager smm = new ShardMapManager(
                new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
                new SqlStoreConnectionFactory(),
                sof,
                new CacheStore(),
                ShardMapManagerLoadPolicy.Lazy,
                new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior);

            RangeShardMap<int> rsm = smm.GetRangeShardMap<int>(ShardMapperTests.s_rangeShardMapName);

            Assert.IsNotNull(rsm);

            ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]);

            Shard s = rsm.CreateShard(sl);

            Assert.IsNotNull(s);

            RangeMapping<int> r1 = rsm.CreateRangeMapping(new Range<int>(1, 20), s);
            RangeMapping<int> r2 = rsm.CreateRangeMapping(new Range<int>(20, 40), s);

            bool storeOperationFailed = false;
            try
            {
                RangeMapping<int> rMerged = rsm.MergeMappings(r1, r2);
            }
            catch (ShardManagementException sme)
            {
                Assert.AreEqual(ShardManagementErrorCategory.RangeShardMap, sme.ErrorCategory);
                Assert.AreEqual(ShardManagementErrorCode.StorageOperationFailure, sme.ErrorCode);
                storeOperationFailed = true;
            }

            Assert.IsTrue(storeOperationFailed);

            // Obtain the pending operations.
            var pendingOperations = ShardMapperTests.GetPendingStoreOperations();
            Assert.AreEqual(pendingOperations.Count(), 1);
//.........这里部分代码省略.........
开发者ID:xdansmith,项目名称:elastic-db-tools,代码行数:101,代码来源:ShardMapperTests.cs

示例4: DeleteRangeMappingAbortLSMDoAndGSMUndo

        public void DeleteRangeMappingAbortLSMDoAndGSMUndo()
        {
            bool shouldThrow = true;

            IStoreOperationFactory sof = new StubStoreOperationFactory()
            {
                CallBase = true,
                CreateRemoveMappingOperationShardMapManagerStoreOperationCodeIStoreShardMapIStoreMappingGuid =
                (_smm, _opcode, _ssm, _sm, _loid) =>
                {
                    StubRemoveMappingOperation op = new StubRemoveMappingOperation(_smm, _opcode, _ssm, _sm, _loid);
                    op.CallBase = true;
                    op.DoLocalSourceExecuteIStoreTransactionScope = (ts) =>
                    {
                        if (shouldThrow)
                        {
                            throw new StoreException("", ShardMapFaultHandlingTests.TransientSqlException);
                        }
                        else
                        {
                            // Call the base function, hack for this behavior is to save current operation, set current to null, restore current operation.
                            var original = op.DoLocalSourceExecuteIStoreTransactionScope;

                            op.DoLocalSourceExecuteIStoreTransactionScope = null;
                            try
                            {
                                return op.DoLocalSourceExecute(ts);
                            }
                            finally
                            {
                                op.DoLocalSourceExecuteIStoreTransactionScope = original;
                            }
                        }
                    };
                    op.UndoGlobalPostLocalExecuteIStoreTransactionScope = (ts) =>
                    {
                        if (shouldThrow)
                        {
                            throw new StoreException("", ShardMapFaultHandlingTests.TransientSqlException);
                        }
                        else
                        {
                            // Call the base function, hack for this behavior is to save current operation, set current to null, restore current operation.
                            var original = op.UndoGlobalPostLocalExecuteIStoreTransactionScope;

                            op.UndoGlobalPostLocalExecuteIStoreTransactionScope = null;
                            try
                            {
                                return op.UndoGlobalPostLocalExecute(ts);
                            }
                            finally
                            {
                                op.UndoGlobalPostLocalExecuteIStoreTransactionScope = original;
                            }
                        }
                    };

                    return op;
                }
            };

            ShardMapManager smm = new ShardMapManager(
                new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
                new SqlStoreConnectionFactory(),
                sof,
                new CacheStore(),
                ShardMapManagerLoadPolicy.Lazy,
                new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior);

            RangeShardMap<int> rsm = smm.GetRangeShardMap<int>(ShardMapperTests.s_rangeShardMapName);

            Assert.IsNotNull(rsm);

            ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]);

            Shard s = rsm.CreateShard(sl);

            Assert.IsNotNull(s);

            RangeMapping<int> r1 = rsm.CreateRangeMapping(new Range<int>(1, 10), s);

            Assert.IsNotNull(r1);

            RangeMappingUpdate ru = new RangeMappingUpdate();
            ru.Status = MappingStatus.Offline;

            // The mapping must be made offline before it can be deleted.
            r1 = rsm.UpdateMapping(r1, ru);
            Assert.AreEqual(MappingStatus.Offline, r1.Status);

            bool storeOperationFailed = false;
            try
            {
                rsm.DeleteMapping(r1);
            }
            catch (ShardManagementException sme)
            {
                Assert.AreEqual(ShardManagementErrorCategory.RangeShardMap, sme.ErrorCategory);
                Assert.AreEqual(ShardManagementErrorCode.StorageOperationFailure, sme.ErrorCode);
                storeOperationFailed = true;
//.........这里部分代码省略.........
开发者ID:xdansmith,项目名称:elastic-db-tools,代码行数:101,代码来源:ShardMapperTests.cs

示例5: UpdateRangeMappingOfflineAbortGSMDoAndGSMUndoPostLocal

        public void UpdateRangeMappingOfflineAbortGSMDoAndGSMUndoPostLocal()
        {
            bool shouldThrow = true;

            IStoreOperationFactory sof = new StubStoreOperationFactory()
            {
                CallBase = true,
                CreateUpdateMappingOperationShardMapManagerStoreOperationCodeIStoreShardMapIStoreMappingIStoreMappingStringGuid =
                (_smm, _opcode, _ssm, _sms, _smt, _p, _loid) =>
                {
                    StubUpdateMappingOperation op = new StubUpdateMappingOperation(_smm, _opcode, _ssm, _sms, _smt, _p, _loid);
                    op.CallBase = true;
                    op.DoGlobalPostLocalExecuteIStoreTransactionScope = (ts) =>
                    {
                        if (shouldThrow)
                        {
                            throw new StoreException("", ShardMapFaultHandlingTests.TransientSqlException);
                        }
                        else
                        {
                            // Call the base function, hack for this behavior is to save current operation, set current to null, restore current operation.
                            var original = op.DoGlobalPostLocalExecuteIStoreTransactionScope;

                            op.DoGlobalPostLocalExecuteIStoreTransactionScope = null;
                            try
                            {
                                return op.DoGlobalPostLocalExecute(ts);
                            }
                            finally
                            {
                                op.DoGlobalPostLocalExecuteIStoreTransactionScope = original;
                            }
                        }
                    };

                    op.UndoLocalSourceExecuteIStoreTransactionScope = (ts) =>
                    {
                        if (shouldThrow)
                        {
                            throw new StoreException("", ShardMapFaultHandlingTests.TransientSqlException);
                        }
                        else
                        {
                            // Call the base function, hack for this behavior is to save current operation, set current to null, restore current operation.
                            var original = op.UndoLocalSourceExecuteIStoreTransactionScope;

                            op.UndoLocalSourceExecuteIStoreTransactionScope = null;
                            try
                            {
                                return op.UndoLocalSourceExecute(ts);
                            }
                            finally
                            {
                                op.UndoLocalSourceExecuteIStoreTransactionScope = original;
                            }
                        }
                    };

                    return op;
                }
            };
            ShardMapManager smm = new ShardMapManager(
                new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
                new SqlStoreConnectionFactory(),
                sof,
                new CacheStore(),
                ShardMapManagerLoadPolicy.Lazy,
                new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior);

            RangeShardMap<int> rsm = smm.GetRangeShardMap<int>(ShardMapperTests.s_rangeShardMapName);

            Assert.IsNotNull(rsm);

            ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]);

            Shard s = rsm.CreateShard(sl);

            Assert.IsNotNull(s);

            RangeMapping<int> r1 = rsm.CreateRangeMapping(new Range<int>(1, 20), s);

            RangeMappingUpdate ru = new RangeMappingUpdate()
            {
                Status = MappingStatus.Offline
            };

            RangeMapping<int> rNew;

            bool storeOperationFailed = false;
            try
            {
                rNew = rsm.UpdateMapping(r1, ru);
            }
            catch (ShardManagementException sme)
            {
                Assert.AreEqual(ShardManagementErrorCategory.RangeShardMap, sme.ErrorCategory);
                Assert.AreEqual(ShardManagementErrorCode.StorageOperationFailure, sme.ErrorCode);
                storeOperationFailed = true;
            }

//.........这里部分代码省略.........
开发者ID:xdansmith,项目名称:elastic-db-tools,代码行数:101,代码来源:ShardMapperTests.cs

示例6: UpdateRangeMappingDefault

        public void UpdateRangeMappingDefault()
        {
            CountingCacheStore countingCache = new CountingCacheStore(new CacheStore());

            ShardMapManager smm = new ShardMapManager(
                new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
                new SqlStoreConnectionFactory(),
                new StoreOperationFactory(),
                countingCache,
                ShardMapManagerLoadPolicy.Lazy,
                new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior);

            RangeShardMap<int> rsm = smm.GetRangeShardMap<int>(ShardMapperTests.s_rangeShardMapName);

            Assert.IsNotNull(rsm);

            ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]);

            Shard s = rsm.CreateShard(sl);

            Assert.IsNotNull(s);

            RangeMapping<int> r1 = rsm.CreateRangeMapping(new Range<int>(1, 20), s);

            // Lock the mapping
            MappingLockToken mappingLockToken = MappingLockToken.Create();
            rsm.LockMapping(r1, mappingLockToken);

            RangeMappingUpdate ru = new RangeMappingUpdate()
            {
                Status = MappingStatus.Offline
            };

            RangeMapping<int> rNew = rsm.UpdateMapping(r1, ru, mappingLockToken);

            Assert.IsNotNull(rNew);

            MappingLockToken storeMappingLockToken = rsm.GetMappingLockOwner(rNew);
            Assert.AreEqual(storeMappingLockToken, mappingLockToken, "LockownerId does not match that in store!");

            rsm.UnlockMapping(rNew, mappingLockToken);
            RangeMapping<int> r2 = rsm.GetMappingForKey(1);
            Assert.AreEqual(0, countingCache.LookupMappingHitCount);
            Assert.AreNotEqual(r1.Id, r2.Id);
        }
开发者ID:xdansmith,项目名称:elastic-db-tools,代码行数:45,代码来源:ShardMapperTests.cs

示例7: MergeRangeMappingsAbortLSM

        public void MergeRangeMappingsAbortLSM()
        {
            IStoreOperationFactory sof = new StubStoreOperationFactory()
            {
                CallBase = true,
                CreateReplaceMappingsOperationShardMapManagerStoreOperationCodeIStoreShardMapTupleOfIStoreMappingGuidArrayTupleOfIStoreMappingGuidArray =
                (_smm, _opcode, _ssm, _smo, _smn) =>
                {
                    StubReplaceMappingsOperation op = new StubReplaceMappingsOperation(_smm, _opcode, _ssm, _smo, _smn);
                    op.CallBase = true;
                    op.DoLocalSourceExecuteIStoreTransactionScope = (ts) =>
                    {
                        throw new StoreException("", ShardMapFaultHandlingTests.TransientSqlException);
                    };

                    return op;
                }
            };

            ShardMapManager smm = new ShardMapManager(
                new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
                new SqlStoreConnectionFactory(),
                sof,
                new CacheStore(),
                ShardMapManagerLoadPolicy.Lazy,
                new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior);

            RangeShardMap<int> rsm = smm.GetRangeShardMap<int>(ShardMapperTests.s_rangeShardMapName);

            Assert.IsNotNull(rsm);

            Shard s1 = rsm.CreateShard(new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]));
            Assert.IsNotNull(s1);

            RangeMapping<int> r1 = rsm.CreateRangeMapping(new Range<int>(1, 10), s1);

            RangeMapping<int> r2 = rsm.CreateRangeMapping(new Range<int>(10, 20), s1);

            bool storeOperationFailed = false;
            try
            {
                RangeMapping<int> rMerged = rsm.MergeMappings(r1, r2);
                Assert.IsNotNull(rMerged);
            }
            catch (ShardManagementException sme)
            {
                Assert.AreEqual(ShardManagementErrorCategory.RangeShardMap, sme.ErrorCategory);
                Assert.AreEqual(ShardManagementErrorCode.StorageOperationFailure, sme.ErrorCode);
                storeOperationFailed = true;
            }

            Assert.IsTrue(storeOperationFailed);

            // Validation: get all mappings for [1,20) should return 2 mappings.
            Assert.AreEqual(2, rsm.GetMappings().Count());
        }
开发者ID:xdansmith,项目名称:elastic-db-tools,代码行数:56,代码来源:ShardMapperTests.cs

示例8: AddRangeMappingAbortLSM

        public void AddRangeMappingAbortLSM()
        {
            bool shouldThrow = true;

            IStoreOperationFactory sof = new StubStoreOperationFactory()
            {
                CallBase = true,
                CreateAddMappingOperationShardMapManagerStoreOperationCodeIStoreShardMapIStoreMapping =
                (_smm, _opcode, _ssm, _sm) =>
                {
                    StubAddMappingOperation op = new StubAddMappingOperation(_smm, _opcode, _ssm, _sm);
                    op.CallBase = true;
                    op.DoLocalSourceExecuteIStoreTransactionScope = (ts) =>
                    {
                        if (shouldThrow)
                        {
                            throw new StoreException("", ShardMapFaultHandlingTests.TransientSqlException);
                        }
                        else
                        {
                            // Call the base function, hack for this behavior is to save current operation, set current to null, restore current operation.
                            var original = op.DoLocalSourceExecuteIStoreTransactionScope;

                            op.DoLocalSourceExecuteIStoreTransactionScope = null;
                            try
                            {
                                return op.DoLocalSourceExecute(ts);
                            }
                            finally
                            {
                                op.DoLocalSourceExecuteIStoreTransactionScope = original;
                            }
                        }
                    };

                    return op;
                }
            };

            ShardMapManager smm = new ShardMapManager(
                new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
                new SqlStoreConnectionFactory(),
                sof,
                new CacheStore(),
                ShardMapManagerLoadPolicy.Lazy,
                new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior);

            RangeShardMap<int> rsm = smm.GetRangeShardMap<int>(ShardMapperTests.s_rangeShardMapName);

            Assert.IsNotNull(rsm);

            ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]);

            Shard s = rsm.CreateShard(sl);

            Assert.IsNotNull(s);

            bool storeOperationFailed = false;
            try
            {
                RangeMapping<int> r1 = rsm.CreateRangeMapping(new Range<int>(1, 10), s);
                Assert.IsNotNull(r1);
            }
            catch (ShardManagementException sme)
            {
                Assert.AreEqual(ShardManagementErrorCategory.RangeShardMap, sme.ErrorCategory);
                Assert.AreEqual(ShardManagementErrorCode.StorageOperationFailure, sme.ErrorCode);
                storeOperationFailed = true;
            }

            Assert.IsTrue(storeOperationFailed);

            shouldThrow = false;

            // validation: adding same range mapping again will succeed.
            RangeMapping<int> rValidate = rsm.CreateRangeMapping(new Range<int>(1, 10), s);
            Assert.IsNotNull(rValidate);
        }
开发者ID:xdansmith,项目名称:elastic-db-tools,代码行数:78,代码来源:ShardMapperTests.cs

示例9: DeleteRangeMappingAbortLSM

        public void DeleteRangeMappingAbortLSM()
        {
            IStoreOperationFactory sof = new StubStoreOperationFactory()
            {
                CallBase = true,
                CreateRemoveMappingOperationShardMapManagerStoreOperationCodeIStoreShardMapIStoreMappingGuid =
                (_smm, _opcode, _ssm, _sm, _loid) =>
                {
                    StubRemoveMappingOperation op = new StubRemoveMappingOperation(_smm, _opcode, _ssm, _sm, _loid);
                    op.CallBase = true;
                    op.DoLocalSourceExecuteIStoreTransactionScope = (ts) =>
                    {
                        throw new StoreException("", ShardMapFaultHandlingTests.TransientSqlException);
                    };

                    return op;
                }
            };

            ShardMapManager smm = new ShardMapManager(
                new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
                new SqlStoreConnectionFactory(),
                sof,
                new CacheStore(),
                ShardMapManagerLoadPolicy.Lazy,
                new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior);

            RangeShardMap<int> rsm = smm.GetRangeShardMap<int>(ShardMapperTests.s_rangeShardMapName);

            Assert.IsNotNull(rsm);

            ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]);

            Shard s = rsm.CreateShard(sl);

            Assert.IsNotNull(s);

            RangeMapping<int> r1 = rsm.CreateRangeMapping(new Range<int>(1, 10), s);

            Assert.IsNotNull(r1);

            RangeMappingUpdate ru = new RangeMappingUpdate();
            ru.Status = MappingStatus.Offline;

            // The mapping must be made offline before it can be deleted.
            r1 = rsm.UpdateMapping(r1, ru);
            Assert.AreEqual(MappingStatus.Offline, r1.Status);

            bool storeOperationFailed = false;
            try
            {
                rsm.DeleteMapping(r1);
            }
            catch (ShardManagementException sme)
            {
                Assert.AreEqual(ShardManagementErrorCategory.RangeShardMap, sme.ErrorCategory);
                Assert.AreEqual(ShardManagementErrorCode.StorageOperationFailure, sme.ErrorCode);
                storeOperationFailed = true;
            }

            Assert.IsTrue(storeOperationFailed);

            // Validation: lookup for 5 returns a valid mapping.
            RangeMapping<int> rValidate = rsm.GetMappingForKey(5);
            Assert.IsNotNull(rValidate);
        }
开发者ID:xdansmith,项目名称:elastic-db-tools,代码行数:66,代码来源:ShardMapperTests.cs

示例10: UnavailableServerOpenConnectionForKeyRangeShardMapInternal


//.........这里部分代码省略.........
                TimeToLiveMillisecondsGet = () => currentMapping.TimeToLiveMilliseconds,
                ResetTimeToLive = () => currentMapping.ResetTimeToLive(),
                HasTimeToLiveExpired = () => currentMapping.HasTimeToLiveExpired()
            };

            scs = new StubCacheStore()
            {
                CallBase = true,
                LookupMappingByKeyIStoreShardMapShardKey = (_ssm, _sk) =>
                {
                    var original = scs.LookupMappingByKeyIStoreShardMapShardKey;
                    scs.LookupMappingByKeyIStoreShardMapShardKey = null;
                    try
                    {
                        currentMapping = scs.LookupMappingByKey(_ssm, _sk);

                        return sics;
                    }
                    finally
                    {
                        scs.LookupMappingByKeyIStoreShardMapShardKey = original;
                    }
                }
            };

            ShardMapManager smm = new ShardMapManager(
                new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
                scf,
                sof,
                scs,
                ShardMapManagerLoadPolicy.Lazy,
                RetryPolicy.DefaultRetryPolicy, RetryBehavior.DefaultRetryBehavior);

            RangeShardMap<int> rsm = smm.GetRangeShardMap<int>(ShardMapperTests.s_rangeShardMapName);
            Assert.IsNotNull(rsm);

            ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]);

            Shard s = rsm.CreateShard(sl);
            Assert.IsNotNull(s);

            RangeMapping<int> r1 = rsm.CreateRangeMapping(new Range<int>(5, 20), s);
            Assert.IsNotNull(r1);

            // Mapping is there, now let's try to abort the OpenConnectionForKey
            shouldThrow = true;

            bool failed = false;

            for (int i = 1; i <= 10; i++)
            {
                failed = false;

                try
                {
                    if (openConnectionAsync)
                    {
                        rsm.OpenConnectionForKeyAsync(10, Globals.ShardUserConnectionString).Wait();
                    }
                    else
                    {
                        rsm.OpenConnectionForKey(10, Globals.ShardUserConnectionString);
                    }
                }
                catch (Exception ex)
                {
开发者ID:xdansmith,项目名称:elastic-db-tools,代码行数:67,代码来源:ShardMapperTests.cs

示例11: AddRangeMappingNoCacheUpdate

        public void AddRangeMappingNoCacheUpdate()
        {
            // Create a cache store that never inserts.
            CountingCacheStore cacheStore =
                new CountingCacheStore(
                    new StubCacheStore()
                    {
                        CallBase = true,
                        AddOrUpdateMappingIStoreMappingCacheStoreMappingUpdatePolicy = (ssm, p) => { }
                    });

            ShardMapManager smm = new ShardMapManager(
                new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
                new SqlStoreConnectionFactory(),
                new StoreOperationFactory(),
                cacheStore,
                ShardMapManagerLoadPolicy.Lazy,
                RetryPolicy.DefaultRetryPolicy, RetryBehavior.DefaultRetryBehavior);

            RangeShardMap<int> rsm = smm.GetRangeShardMap<int>(ShardMapperTests.s_rangeShardMapName);
            Assert.IsNotNull(rsm);

            ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]);

            Shard s = rsm.CreateShard(sl);
            Assert.IsNotNull(s);

            RangeMapping<int> r1 = rsm.CreateRangeMapping(new Range<int>(1, 10), s);
            Assert.IsNotNull(r1);

            RangeMapping<int> r2 = rsm.GetMappingForKey(2);

            Assert.IsNotNull(r2);
            Assert.AreEqual(0, cacheStore.LookupMappingMissCount);
        }
开发者ID:xdansmith,项目名称:elastic-db-tools,代码行数:35,代码来源:ShardMapperTests.cs

示例12: UpdateRangeMappingIdempotency

        public void UpdateRangeMappingIdempotency()
        {
            ShardMapManager smm = new ShardMapManager(
                new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
                new SqlStoreConnectionFactory(),
                new StoreOperationFactory(),
                new CacheStore(),
                ShardMapManagerLoadPolicy.Lazy,
                new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior);

            RangeShardMap<int> rsm = smm.GetRangeShardMap<int>(ShardMapperTests.s_rangeShardMapName);

            Assert.IsNotNull(rsm);

            Shard s1 = rsm.CreateShard(new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]));
            Assert.IsNotNull(s1);

            Shard s2 = rsm.CreateShard(new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[1]));
            Assert.IsNotNull(s2);

            RangeMapping<int> r1 = rsm.CreateRangeMapping(new Range<int>(1, 20), s1);

            // Online -> Offline - No Location Change
            RangeMappingUpdate pu = new RangeMappingUpdate
            {
                Status = MappingStatus.Offline
            };

            RangeMapping<int> presult = rsm.UpdateMapping(r1, pu);
            Assert.IsNotNull(presult);
            Assert.IsTrue(presult.Status == MappingStatus.Offline);

            // Offline -> Offline - No Location Change
            pu = new RangeMappingUpdate
            {
                Status = MappingStatus.Offline
            };

            presult = rsm.UpdateMapping(presult, pu);
            Assert.IsNotNull(presult);
            Assert.IsTrue(presult.Status == MappingStatus.Offline);

            // Offline -> Offline - Location Change
            pu = new RangeMappingUpdate
            {
                Shard = s2
            };

            presult = rsm.UpdateMapping(presult, pu);
            Assert.IsNotNull(presult);
            Assert.IsTrue(presult.Status == MappingStatus.Offline);
            Assert.AreEqual(s2.Location, presult.Shard.Location);

            // Offline -> Online - No Location Change
            pu = new RangeMappingUpdate
            {
                Status = MappingStatus.Online
            };

            presult = rsm.UpdateMapping(presult, pu);
            Assert.IsNotNull(presult);
            Assert.IsTrue(presult.Status == MappingStatus.Online);

            // Online -> Offline - Location Change
            pu = new RangeMappingUpdate
            {
                Status = MappingStatus.Offline,
                Shard = s1
            };

            presult = rsm.UpdateMapping(presult, pu);
            Assert.IsNotNull(presult);
            Assert.IsTrue(presult.Status == MappingStatus.Offline);
            Assert.AreEqual(s1.Location, presult.Shard.Location);

            // Offline -> Online - Location Change
            pu = new RangeMappingUpdate
            {
                Status = MappingStatus.Online,
                Shard = s2
            };

            presult = rsm.UpdateMapping(presult, pu);
            Assert.IsNotNull(presult);
            Assert.IsTrue(presult.Status == MappingStatus.Online);
            Assert.AreEqual(s2.Location, presult.Shard.Location);

            // Online -> Online - No Location Change
            pu = new RangeMappingUpdate
            {
                Status = MappingStatus.Online
            };

            presult = rsm.UpdateMapping(presult, pu);
            Assert.IsNotNull(presult);
            Assert.IsTrue(presult.Status == MappingStatus.Online);

            // Online -> Online - Location Change
            pu = new RangeMappingUpdate
            {
//.........这里部分代码省略.........
开发者ID:xdansmith,项目名称:elastic-db-tools,代码行数:101,代码来源:ShardMapperTests.cs

示例13: UpdateRangeMappingLocation

        public void UpdateRangeMappingLocation()
        {
            CountingCacheStore countingCache = new CountingCacheStore(new CacheStore());

            ShardMapManager smm = new ShardMapManager(
                new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
                new SqlStoreConnectionFactory(),
                new StoreOperationFactory(),
                countingCache,
                ShardMapManagerLoadPolicy.Lazy,
                new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior);

            RangeShardMap<int> rsm = smm.GetRangeShardMap<int>(ShardMapperTests.s_rangeShardMapName);

            Assert.IsNotNull(rsm);

            ShardLocation sl1 = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]);
            Shard s1 = rsm.CreateShard(sl1);
            Assert.IsNotNull(s1);

            ShardLocation sl2 = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[1]);
            Shard s2 = rsm.CreateShard(sl2);
            Assert.IsNotNull(s2);

            RangeMapping<int> r1 = rsm.CreateRangeMapping(new Range<int>(1, 20), s1);

            RangeMappingUpdate ru = new RangeMappingUpdate();

            // Shard location in a mapping cannot be updated when online.
            ru.Status = MappingStatus.Offline;
            RangeMapping<int> rOffline = rsm.UpdateMapping(r1, ru);

            Assert.IsNotNull(rOffline);
            Assert.AreEqual(ru.Status, rOffline.Status);
            ru.Shard = s2;

            RangeMapping<int> rNew = rsm.UpdateMapping(rOffline, ru);
            Assert.IsNotNull(rNew);

            // Bring the mapping back online.
            ru.Status = MappingStatus.Online;

            rNew = rsm.UpdateMapping(rNew, ru);
            Assert.IsNotNull(rNew);

            RangeMapping<int> r2 = rsm.GetMappingForKey(1);

            Assert.IsNotNull(r2);
            Assert.AreEqual(0, countingCache.LookupMappingHitCount);
            Assert.AreEqual(s2.Id, r2.Shard.Id);
        }
开发者ID:xdansmith,项目名称:elastic-db-tools,代码行数:51,代码来源:ShardMapperTests.cs

示例14: KillConnectionOnOfflineRangeMapping

        public void KillConnectionOnOfflineRangeMapping()
        {
            ShardMapManager smm = new ShardMapManager(
                new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
                new SqlStoreConnectionFactory(),
                new StoreOperationFactory(),
                new CacheStore(),
                ShardMapManagerLoadPolicy.Lazy,
                new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero),
                RetryBehavior.DefaultRetryBehavior);

            RangeShardMap<int> rsm = smm.GetRangeShardMap<int>(ShardMapperTests.s_rangeShardMapName);

            Assert.IsNotNull(rsm);

            ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapperTests.s_shardedDBs[0]);

            Shard s = rsm.CreateShard(sl);

            Assert.IsNotNull(s);

            RangeMapping<int> r1 = rsm.CreateRangeMapping(new Range<int>(1, 20), s);

            using (SqlConnection conn = rsm.OpenConnectionForKeyAsync(1, Globals.ShardUserConnectionString).Result)
            {
                Assert.AreEqual(ConnectionState.Open, conn.State);

                RangeMappingUpdate ru = new RangeMappingUpdate();
                ru.Status = MappingStatus.Offline;

                RangeMapping<int> rNew = rsm.UpdateMapping(r1, ru);
                Assert.IsNotNull(rNew);

                bool failed = false;

                try
                {
                    using (SqlCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = "select 1";
                        cmd.CommandType = CommandType.Text;

                        using (SqlDataReader rdr = cmd.ExecuteReader())
                        {
                        }
                    }
                }
                catch (SqlException)
                {
                    failed = true;
                }

                Assert.AreEqual(true, failed);
                Assert.AreEqual(ConnectionState.Closed, conn.State);

                failed = false;

                // Open 2nd connection.
                try
                {
                    using (SqlConnection conn2 = rsm.OpenConnectionForKeyAsync(1, Globals.ShardUserConnectionString).Result)
                    {
                    }
                }
                catch (AggregateException ex)
                {
                    var sme = ex.InnerException as ShardManagementException;
                    if (sme != null)
                    {
                        failed = true;
                        Assert.AreEqual(ShardManagementErrorCode.MappingIsOffline, sme.ErrorCode);
                    }
                }

                Assert.AreEqual(true, failed);

                // Mark the mapping online again so that it will be cleaned up
                ru.Status = MappingStatus.Online;
                RangeMapping<int> rUpdated = rsm.UpdateMapping(rNew, ru);
                Assert.IsNotNull(rUpdated);

                failed = false;

                // Open 3rd connection. This should succeed.
                try
                {
                    using (SqlConnection conn3 = rsm.OpenConnectionForKey(1, Globals.ShardUserConnectionString))
                    {
                    }
                }
                catch (ShardManagementException)
                {
                    failed = true;
                }

                Assert.AreEqual(false, failed);
            }
        }
开发者ID:xdansmith,项目名称:elastic-db-tools,代码行数:98,代码来源:ShardMapperTests.cs

示例15: AddRangeMappingFailGSMAfterSuccessLSMSingleRetry

        public void AddRangeMappingFailGSMAfterSuccessLSMSingleRetry()
        {
            ShardMapManager smm = new ShardMapManager(
                new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
                new SqlStoreConnectionFactory(),
                new StubStoreOperationFactory()
                {
                    CallBase = true,
                    CreateAddMappingOperationShardMapManagerStoreOperationCodeIStoreShardMapIStoreMapping =
                        (_smm, _opcode, _ssm, _sm) => new NTimeFailingAddMappingOperation(1, _smm, _opcode, _ssm, _sm)
                },
                new CacheStore(),
                ShardMapManagerLoadPolicy.Lazy,
                new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior);

            RangeShardMap<int> rsm = smm.GetRangeShardMap<int>(ShardMapFaultHandlingTests.s_rangeShardMapName);

            Assert.IsNotNull(rsm);

            Shard s = rsm.CreateShard(new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapFaultHandlingTests.s_shardedDBs[0]));

            Assert.IsNotNull(s);

            bool failed = false;

            try
            {
                // Inject GSM transaction failure at GSM commit time.
                RangeMapping<int> r1 = rsm.CreateRangeMapping(new Range<int>(1, 10), s);
            }
            catch (ShardManagementException)
            {
                failed = true;
            }

            Assert.IsFalse(failed);
        }
开发者ID:jaredmoo,项目名称:elastic-db-tools,代码行数:37,代码来源:ShardMapFaultHandlingTests.cs


注:本文中的ShardMapManager.GetRangeShardMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。