Exemplo n.º 1
0
        public void RemoveListShardMapNoCacheUpdate()
        {
            // Counting store that does not perform deletions of shard maps.
            CountingCacheStore cacheStore =
                new CountingCacheStore(
                    new StubCacheStore()
            {
                CallBase = true,
                DeleteShardMapIStoreShardMap = (csm) => { }
            }
                    );

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

            ShardMap sm = smm.CreateListShardMap <int>(ShardMapManagerTests.s_shardMapName);

            Assert.IsNotNull(sm);

            Assert.AreEqual(ShardMapManagerTests.s_shardMapName, sm.Name);

            smm.DeleteShardMap(sm);

            Assert.AreEqual(1, cacheStore.DeleteShardMapCount);

            ShardMap smLookup = smm.LookupShardMapByName("LookupShardMapByName", ShardMapManagerTests.s_shardMapName, true);

            Assert.IsNotNull(smLookup);
            Assert.AreEqual(1, cacheStore.LookupShardMapHitCount);
        }
Exemplo n.º 2
0
        public void CreateRangeShardMapDefault()
        {
            CountingCacheStore cacheStore =
                new CountingCacheStore(
                    new CacheStore());

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

            RangeShardMap <int> rsm = smm.CreateRangeShardMap <int>(ShardMapManagerTests.s_shardMapName);

            Assert.IsNotNull(rsm);
            Assert.AreEqual(ShardMapManagerTests.s_shardMapName, rsm.Name);

            ShardMap smLookup = smm.LookupShardMapByName("LookupShardMapByName", ShardMapManagerTests.s_shardMapName, true);

            Assert.IsNotNull(smLookup);
            Assert.AreEqual(ShardMapManagerTests.s_shardMapName, smLookup.Name);
            Assert.AreEqual(1, cacheStore.LookupShardMapCount);
            Assert.AreEqual(1, cacheStore.LookupShardMapHitCount);
        }
Exemplo n.º 3
0
        public void AddListShardMapNoCacheUpdate()
        {
            // Create a cache store that always misses.
            CountingCacheStore cacheStore =
                new CountingCacheStore(
                    new StubCacheStore()
            {
                CallBase = true,
                LookupMappingByKeyIStoreShardMapShardKey = (ssm, sk) => null,
                LookupShardMapByNameString = (n) => null
            });

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

            ShardMap sm = smm.CreateListShardMap <int>(ShardMapManagerTests.s_shardMapName);

            Assert.IsNotNull(sm);
            Assert.AreEqual(ShardMapManagerTests.s_shardMapName, sm.Name);
            Assert.AreEqual(1, cacheStore.AddShardMapCount);
            cacheStore.ResetCounters();

            ShardMap smLookup = smm.LookupShardMapByName("LookupShardMapByName", ShardMapManagerTests.s_shardMapName, true);

            Assert.IsNotNull(smLookup);
            Assert.AreEqual(1, cacheStore.AddShardMapCount);
            Assert.AreEqual(1, cacheStore.LookupShardMapMissCount);
        }
Exemplo n.º 4
0
        public void DeleteListShardMap()
        {
            CountingCacheStore cacheStore =
                new CountingCacheStore(
                    new CacheStore());

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

            ShardMap sm = smm.CreateListShardMap <int>(ShardMapManagerTests.s_shardMapName);

            Assert.IsNotNull(sm);

            Assert.AreEqual(ShardMapManagerTests.s_shardMapName, sm.Name);

            ShardMap smLookup = smm.LookupShardMapByName("LookupShardMapByName", ShardMapManagerTests.s_shardMapName, true);

            Assert.IsNotNull(smLookup);
            Assert.AreEqual(1, cacheStore.LookupShardMapCount);
            Assert.AreEqual(1, cacheStore.LookupShardMapHitCount);

            smm.DeleteShardMap(sm);

            Assert.AreEqual(1, cacheStore.DeleteShardMapCount);

            cacheStore.ResetCounters();

            // Verify that shard map is removed from cache.
            ShardMap smLookupFailure = smm.LookupShardMapByName("LookupShardMapByName", ShardMapManagerTests.s_shardMapName, true);

            Assert.IsNull(smLookupFailure);
            Assert.AreEqual(1, cacheStore.LookupShardMapCount);
            Assert.AreEqual(1, cacheStore.LookupShardMapMissCount);
        }
Exemplo n.º 5
0
        public void RemoveListShardMapAbortGSM()
        {
            ShardMapManager smm = new ShardMapManager(
                new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
                new SqlStoreConnectionFactory(),
                new StubStoreOperationFactory()
            {
                CallBase = true,
                CreateRemoveShardMapGlobalOperationShardMapManagerStringIStoreShardMap =
                    (_smm, _opname, _ssm) => new NTimeFailingRemoveShardMapGlobalOperation(10, _smm, _opname, _ssm)
            },
                new CacheStore(),
                ShardMapManagerLoadPolicy.Lazy,
                new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior);

            ShardMap sm = smm.CreateListShardMap <int>(ShardMapManagerTests.s_shardMapName);

            Assert.IsNotNull(sm);

            Assert.AreEqual(ShardMapManagerTests.s_shardMapName, sm.Name);

            bool storeOperationFailed = false;

            try
            {
                smm.DeleteShardMap(sm);
            }
            catch (ShardManagementException sme)
            {
                Assert.AreEqual(ShardManagementErrorCategory.ShardMapManager, sme.ErrorCategory);
                Assert.AreEqual(ShardManagementErrorCode.StorageOperationFailure, sme.ErrorCode);
                storeOperationFailed = true;
            }

            Assert.IsTrue(storeOperationFailed);

            // Verify that shard map still exist in store.
            ShardMap smNew = smm.LookupShardMapByName("LookupShardMapByName", ShardMapManagerTests.s_shardMapName, false);

            Assert.IsNotNull(smNew);
        }
        public void AddListShardMapNoCacheUpdate()
        {
            // Create a cache store that always misses.
            CountingCacheStore cacheStore =
                new CountingCacheStore(
                    new StubCacheStore()
                    {
                        CallBase = true,
                        LookupMappingByKeyIStoreShardMapShardKey = (ssm, sk) => null,
                        LookupShardMapByNameString = (n) => null
                    });

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

            ShardMap sm = smm.CreateListShardMap<int>(ShardMapManagerTests.s_shardMapName);
            Assert.IsNotNull(sm);
            Assert.AreEqual(ShardMapManagerTests.s_shardMapName, sm.Name);
            Assert.AreEqual(1, cacheStore.AddShardMapCount);
            cacheStore.ResetCounters();

            ShardMap smLookup = smm.LookupShardMapByName("LookupShardMapByName", ShardMapManagerTests.s_shardMapName, true);

            Assert.IsNotNull(smLookup);
            Assert.AreEqual(1, cacheStore.AddShardMapCount);
            Assert.AreEqual(1, cacheStore.LookupShardMapMissCount);
        }
        public void RemoveListShardMapNoCacheUpdate()
        {
            // Counting store that does not perform deletions of shard maps.
            CountingCacheStore cacheStore =
                new CountingCacheStore(
                    new StubCacheStore()
                    {
                        CallBase = true,
                        DeleteShardMapIStoreShardMap = (csm) => { }
                    }
                    );

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

            ShardMap sm = smm.CreateListShardMap<int>(ShardMapManagerTests.s_shardMapName);

            Assert.IsNotNull(sm);

            Assert.AreEqual(ShardMapManagerTests.s_shardMapName, sm.Name);

            smm.DeleteShardMap(sm);

            Assert.AreEqual(1, cacheStore.DeleteShardMapCount);

            ShardMap smLookup = smm.LookupShardMapByName("LookupShardMapByName", ShardMapManagerTests.s_shardMapName, true);

            Assert.IsNotNull(smLookup);
            Assert.AreEqual(1, cacheStore.LookupShardMapHitCount);
        }
        public void RemoveListShardMapAbortGSM()
        {
            ShardMapManager smm = new ShardMapManager(
                new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString),
                new SqlStoreConnectionFactory(),
                new StubStoreOperationFactory()
                {
                    CallBase = true,
                    CreateRemoveShardMapGlobalOperationShardMapManagerStringIStoreShardMap =
                        (_smm, _opname, _ssm) => new NTimeFailingRemoveShardMapGlobalOperation(10, _smm, _opname, _ssm)
                },
                new CacheStore(),
                ShardMapManagerLoadPolicy.Lazy,
                new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior);

            ShardMap sm = smm.CreateListShardMap<int>(ShardMapManagerTests.s_shardMapName);

            Assert.IsNotNull(sm);

            Assert.AreEqual(ShardMapManagerTests.s_shardMapName, sm.Name);

            bool storeOperationFailed = false;
            try
            {
                smm.DeleteShardMap(sm);
            }
            catch (ShardManagementException sme)
            {
                Assert.AreEqual(ShardManagementErrorCategory.ShardMapManager, sme.ErrorCategory);
                Assert.AreEqual(ShardManagementErrorCode.StorageOperationFailure, sme.ErrorCode);
                storeOperationFailed = true;
            }

            Assert.IsTrue(storeOperationFailed);

            // Verify that shard map still exist in store.
            ShardMap smNew = smm.LookupShardMapByName("LookupShardMapByName", ShardMapManagerTests.s_shardMapName, false);
            Assert.IsNotNull(smNew);
        }
        public void DeleteListShardMap()
        {
            CountingCacheStore cacheStore =
                new CountingCacheStore(
                    new CacheStore());

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

            ShardMap sm = smm.CreateListShardMap<int>(ShardMapManagerTests.s_shardMapName);

            Assert.IsNotNull(sm);

            Assert.AreEqual(ShardMapManagerTests.s_shardMapName, sm.Name);

            ShardMap smLookup = smm.LookupShardMapByName("LookupShardMapByName", ShardMapManagerTests.s_shardMapName, true);

            Assert.IsNotNull(smLookup);
            Assert.AreEqual(1, cacheStore.LookupShardMapCount);
            Assert.AreEqual(1, cacheStore.LookupShardMapHitCount);

            smm.DeleteShardMap(sm);

            Assert.AreEqual(1, cacheStore.DeleteShardMapCount);

            cacheStore.ResetCounters();

            // Verify that shard map is removed from cache.
            ShardMap smLookupFailure = smm.LookupShardMapByName("LookupShardMapByName", ShardMapManagerTests.s_shardMapName, true);

            Assert.IsNull(smLookupFailure);
            Assert.AreEqual(1, cacheStore.LookupShardMapCount);
            Assert.AreEqual(1, cacheStore.LookupShardMapMissCount);
        }
        public void CreateRangeShardMapDefault()
        {
            CountingCacheStore cacheStore =
                new CountingCacheStore(
                    new CacheStore());

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

            RangeShardMap<int> rsm = smm.CreateRangeShardMap<int>(ShardMapManagerTests.s_shardMapName);

            Assert.IsNotNull(rsm);
            Assert.AreEqual(ShardMapManagerTests.s_shardMapName, rsm.Name);

            ShardMap smLookup = smm.LookupShardMapByName("LookupShardMapByName", ShardMapManagerTests.s_shardMapName, true);

            Assert.IsNotNull(smLookup);
            Assert.AreEqual(ShardMapManagerTests.s_shardMapName, smLookup.Name);
            Assert.AreEqual(1, cacheStore.LookupShardMapCount);
            Assert.AreEqual(1, cacheStore.LookupShardMapHitCount);
        }