public void DeleteShardMapNonExisting() { ShardMapManager smm = ShardMapManagerFactory.GetSqlShardMapManager( Globals.ShardMapManagerConnectionString, ShardMapManagerLoadPolicy.Lazy); ShardMap sm = smm.CreateListShardMap <int>(ShardMapManagerTests.s_shardMapName); Assert.IsNotNull(sm); Assert.AreEqual(ShardMapManagerTests.s_shardMapName, sm.Name); smm.DeleteShardMap(sm); smm.DeleteShardMap(sm); }
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 ShardMapManagerTestInitialize() { ShardMapManager smm = ShardMapManagerFactory.GetSqlShardMapManager( Globals.ShardMapManagerConnectionString, ShardMapManagerLoadPolicy.Lazy); try { ShardMap sm = smm.GetShardMap(ShardMapManagerTests.s_shardMapName); smm.DeleteShardMap(sm); } catch (ShardManagementException smme) { Assert.IsTrue(smme.ErrorCode == ShardManagementErrorCode.ShardMapLookupFailure); } }
public bool DeleteShardListMap() { try { if (ShardMapManager == null) { return(false); } Shard tempShard = null; PointMapping <long> tempMapping = null; if (ShardMapManager.TryGetListShardMap(mapManagerName, out lsm)) { foreach (Shard shard in lsm.GetShards()) { // delete all mappings var allMappings = lsm.GetMappings(shard); for (int i = 0; i < allMappings.Count; i++) { lsm.MarkMappingOffline(allMappings[i]); if (lsm.TryGetMappingForKey(allMappings[i].Value, out tempMapping)) { lsm.DeleteMapping(tempMapping); } } // delete shard if (lsm.TryGetShard(shard.Location, out tempShard)) { lsm.DeleteShard(tempShard); } } } // clear shard map manager if (ShardMapManager.TryGetListShardMap(mapManagerName, out lsm)) { ShardMapManager.DeleteShardMap(lsm); } return(true); } catch { return(false); } }
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 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 ConcurrencyScenarioListShardMap() { bool operationFailed; // variable to track status of negative test scenarios // Create 2 SMM objects representing management and client ShardMapManager smmMgmt = ShardMapManagerFactory.GetSqlShardMapManager( Globals.ShardMapManagerConnectionString, ShardMapManagerLoadPolicy.Lazy); ShardMapManager smmClient = ShardMapManagerFactory.GetSqlShardMapManager( Globals.ShardMapManagerConnectionString, ShardMapManagerLoadPolicy.Lazy); #region CreateShardMap // Add a shard map from management SMM. ShardMap smMgmt = smmMgmt.CreateListShardMap <int>(ShardMapManagerConcurrencyTests.s_shardMapName); Assert.AreEqual(ShardMapManagerConcurrencyTests.s_shardMapName, smMgmt.Name); // Lookup shard map from client SMM. ShardMap smClient = smmClient.GetShardMap(ShardMapManagerConcurrencyTests.s_shardMapName); Assert.IsNotNull(smClient); #endregion CreateShardMap #region ConvertToListShardMap ListShardMap <int> lsmMgmt = smmMgmt.GetListShardMap <int>(ShardMapManagerConcurrencyTests.s_shardMapName); Assert.IsNotNull(lsmMgmt); // look up shard map again, it will ListShardMap <int> lsmClient = smmClient.GetListShardMap <int>(ShardMapManagerConcurrencyTests.s_shardMapName); Assert.IsNotNull(lsmClient); #endregion ConvertToListShardMap #region DeleteShardMap // verify that smClient is accessible IEnumerable <Shard> shardClient = lsmClient.GetShards(); smmMgmt.DeleteShardMap(lsmMgmt); operationFailed = false; try { // smClient does not exist, below call will fail. IEnumerable <Shard> sCNew = lsmClient.GetShards(); } catch (ShardManagementException sme) { Assert.AreEqual(ShardManagementErrorCategory.ShardMap, sme.ErrorCategory); Assert.AreEqual(ShardManagementErrorCode.ShardMapDoesNotExist, sme.ErrorCode); operationFailed = true; } Assert.IsTrue(operationFailed); #endregion DeleteShardMap }