public void LoadTestRemoveShardFromListShardMap() { try { ShardMapManager smm = ShardMapManagerFactory.GetSqlShardMapManager( Globals.ShardMapManagerConnectionString, ShardMapManagerLoadPolicy.Lazy); ListShardMap <int> lsm = smm.GetListShardMap <int>(ShardMapManagerLoadTests.s_listShardMapName); Assert.IsNotNull(lsm); List <Shard> existingShards = lsm.GetShards().ToList(); if (existingShards.Count == 0) { return; } // If there is already a shard marked as offline, chose that one to delete. // This can happend if earlier remove operation was terminated for some reason - ex. killing connections. Shard offlineShard = existingShards.Find(e => e.Status == ShardStatus.Offline); if (offlineShard == null) { offlineShard = existingShards[_r.Next(existingShards.Count)]; // First mark shard as offline so that other test threads will not add new mappings to it. offlineShard = lsm.UpdateShard(offlineShard, new ShardUpdate { Status = ShardStatus.Offline }); } Debug.WriteLine("Trying to remove shard at location {0}", offlineShard.Location); PointMappingUpdate pu = new PointMappingUpdate(); pu.Status = MappingStatus.Offline; // Remove all mappings from this shard for given shard map. foreach (PointMapping <int> p in lsm.GetMappings(offlineShard)) { PointMapping <int> mappingToDelete = lsm.UpdateMapping(p, pu); lsm.DeleteMapping(mappingToDelete); } // Shard object is changed as mappings are removed, get it again. Shard deleteShard = lsm.GetShard(offlineShard.Location); // now remove shard. lsm.DeleteShard(deleteShard); Debug.WriteLine("Removed shard at location {0} from shard map {1}", deleteShard.Location, lsm); } catch (ShardManagementException sme) { Debug.WriteLine("Exception caught: {0}", sme.Message); } }