public void CreateShardDefault() { ShardMapManager smm = ShardMapManagerFactory.GetSqlShardMapManager( Globals.ShardMapManagerConnectionString, ShardMapManagerLoadPolicy.Lazy); ShardMap sm = smm.GetShardMap(ShardMapTests.s_defaultShardMapName); Assert.IsNotNull(sm); ShardLocation sl = new ShardLocation( Globals.ShardMapManagerTestsDatasourceName, ShardMapTests.s_shardedDBs[0], SqlProtocol.Tcp, 1433); Shard sNew = sm.CreateShard(sl); Assert.IsNotNull(sNew); // Validate that the shard location is round-tripped correctly Assert.AreEqual(sl, sNew.Location); Assert.AreEqual(sl, sm.GetShard(sl).Location); // Validate that we can connect to the shard using (SqlConnection conn = sNew.OpenConnection( Globals.ShardUserConnectionString, ConnectionOptions.Validate)) { } }
public void DeleteShardDuplicate() { ShardMapManager smm = ShardMapManagerFactory.GetSqlShardMapManager( Globals.ShardMapManagerConnectionString, ShardMapManagerLoadPolicy.Lazy); ShardMap sm = smm.GetShardMap(ShardMapTests.s_defaultShardMapName); Assert.IsNotNull(sm); ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapTests.s_shardedDBs[0]); Shard sNew = sm.CreateShard(sl); Assert.IsNotNull(sNew); sm.DeleteShard(sNew); Assert.IsNotNull(sNew); bool removeFailed = false; try { sm.DeleteShard(sNew); } catch (ShardManagementException sme) { Assert.AreEqual(ShardManagementErrorCategory.ShardMap, sme.ErrorCategory); Assert.AreEqual(ShardManagementErrorCode.ShardDoesNotExist, sme.ErrorCode); removeFailed = true; } Assert.IsTrue(removeFailed); }
public void GetDistinctLocations() { // Get shard map manager and 2 shard maps. ShardMapManager smm = ShardMapManagerFactory.GetSqlShardMapManager( Globals.ShardMapManagerConnectionString, ShardMapManagerLoadPolicy.Lazy); // Upgrade GSM to latest version smm.UpgradeGlobalStore(); // create shard maps foreach (string name in ShardMapManagerUpgradeTests.s_shardMapNames) { ShardMap sm = smm.CreateListShardMap <int>(name); Assert.IsNotNull(sm); } ShardMap sm1 = smm.GetShardMap(ShardMapManagerUpgradeTests.s_shardMapNames[0]); Assert.IsNotNull(sm1); ShardMap sm2 = smm.GetShardMap(ShardMapManagerUpgradeTests.s_shardMapNames[1]); Assert.IsNotNull(sm2); // Add shards to the shard maps. ShardLocation sl1 = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapManagerUpgradeTests.s_shardedDBs[0]); ShardLocation sl2 = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapManagerUpgradeTests.s_shardedDBs[1]); ShardLocation sl3 = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapManagerUpgradeTests.s_shardedDBs[2]); Shard s1 = sm1.CreateShard(sl1); Shard s2 = sm1.CreateShard(sl2); Shard s3 = sm1.CreateShard(sl3); Shard s4 = sm2.CreateShard(sl2); Shard s5 = sm2.CreateShard(sl3); int count = 0; foreach (ShardLocation sl in smm.GetDistinctShardLocations()) { count++; } Assert.AreEqual(3, count); }
public void ValidateShard() { ShardMapManager smm = ShardMapManagerFactory.GetSqlShardMapManager( Globals.ShardMapManagerConnectionString, ShardMapManagerLoadPolicy.Lazy); ShardMap sm = smm.GetShardMap(ShardMapTests.s_defaultShardMapName); Assert.IsNotNull(sm); ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapTests.s_shardedDBs[0]); Shard sNew = sm.CreateShard(new ShardCreationInfo(sl, ShardStatus.Online)); ShardUpdate su = new ShardUpdate(); su.Status = ShardStatus.Offline; Shard sUpdated = sm.UpdateShard(sNew, su); Assert.IsNotNull(sUpdated); bool validationFailed = false; try { using (SqlConnection conn = sNew.OpenConnection( Globals.ShardUserConnectionString, ConnectionOptions.Validate)) { } } catch (ShardManagementException sme) { validationFailed = true; Assert.AreEqual(ShardManagementErrorCategory.Validation, sme.ErrorCategory); Assert.AreEqual(ShardManagementErrorCode.ShardVersionMismatch, sme.ErrorCode); } Assert.IsTrue(validationFailed); validationFailed = false; try { using (SqlConnection conn = sUpdated.OpenConnection( Globals.ShardUserConnectionString, ConnectionOptions.Validate)) { } } catch (ShardManagementException) { validationFailed = true; } Assert.IsFalse(validationFailed); }
public static void Main(string[] args) { try { // Parse command line arguments s_commandLine = new CommandLine(args); if (!s_commandLine.IsValid) { s_commandLine.WriteUsage(); return; } // Get Shard Map Manager ShardMapManager smm = ShardMapManagerFactory.GetSqlShardMapManager( GetConnectionString(), ShardMapManagerLoadPolicy.Eager); Console.WriteLine("Connected to Shard Map Manager"); // Get Shard Map ShardMap map = smm.GetShardMap(s_commandLine.ShardMap); Console.WriteLine("Found {0} shards", map.GetShards().Count()); // Create connection string for MultiShardConnection string connectionString = GetCredentialsConnectionString(); // REPL Console.WriteLine(); while (true) { // Read command from console string commandText = GetCommand(); if (commandText == null) { // Exit requested break; } // Evaluate command string output; using (MultiShardConnection conn = new MultiShardConnection(map.GetShards(), connectionString)) { output = ExecuteCommand(conn, commandText); } // Print output Console.WriteLine(output); } } catch (Exception e) { // Print exception and exit Console.WriteLine(e); return; } }
public void UpdateShardAbortGSM() { ShardMapManager smm = new ShardMapManager( new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString), new SqlStoreConnectionFactory(), new StubStoreOperationFactory() { CallBase = true, CreateUpdateShardOperationShardMapManagerIStoreShardMapIStoreShardIStoreShard = (_smm, _sm, _so, _sn) => new NTimeFailingUpdateShardOperation(10, _smm, _sm, _so, _sn) }, new CacheStore(), ShardMapManagerLoadPolicy.Lazy, new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior); ShardMap sm = smm.GetShardMap(ShardMapTests.s_defaultShardMapName); Assert.IsNotNull(sm); ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapTests.s_shardedDBs[0]); Shard sNew = sm.CreateShard(new ShardCreationInfo(sl, ShardStatus.Online)); ShardUpdate su = new ShardUpdate(); su.Status = ShardStatus.Offline; bool storeOperationFailed = false; try { Shard sUpdated = sm.UpdateShard(sNew, su); Assert.IsNotNull(sNew); } catch (ShardManagementException sme) { Assert.AreEqual(ShardManagementErrorCategory.ShardMap, sme.ErrorCategory); Assert.AreEqual(ShardManagementErrorCode.StorageOperationFailure, sme.ErrorCode); storeOperationFailed = true; } Assert.IsTrue(storeOperationFailed); // verify that shard status is not changed. Shard sValidate = sm.GetShard(sl); Assert.AreEqual(sNew.Status, sValidate.Status); }
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 void DeleteShardAbortGSM() { ShardMapManager smm = new ShardMapManager( new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString), new SqlStoreConnectionFactory(), new StubStoreOperationFactory() { CallBase = true, CreateRemoveShardOperationShardMapManagerIStoreShardMapIStoreShard = (_smm, _sm, _s) => new NTimeFailingRemoveShardOperation(10, _smm, _sm, _s) }, new CacheStore(), ShardMapManagerLoadPolicy.Lazy, new RetryPolicy(1, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior); ShardMap sm = smm.GetShardMap(ShardMapTests.s_defaultShardMapName); Assert.IsNotNull(sm); ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapTests.s_shardedDBs[0]); Shard sNew = sm.CreateShard(sl); Assert.IsNotNull(sNew); bool storeOperationFailed = false; try { sm.DeleteShard(sNew); } catch (ShardManagementException sme) { Assert.AreEqual(ShardManagementErrorCategory.ShardMap, sme.ErrorCategory); Assert.AreEqual(ShardManagementErrorCode.StorageOperationFailure, sme.ErrorCode); storeOperationFailed = true; } Assert.IsTrue(storeOperationFailed); // verify that the shard exists in store. Shard sValidate = sm.GetShard(sl); Assert.IsNotNull(sValidate); }
public void DeleteShardDefault() { ShardMapManager smm = ShardMapManagerFactory.GetSqlShardMapManager( Globals.ShardMapManagerConnectionString, ShardMapManagerLoadPolicy.Lazy); ShardMap sm = smm.GetShardMap(ShardMapTests.s_defaultShardMapName); Assert.IsNotNull(sm); ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapTests.s_shardedDBs[0]); Shard sNew = sm.CreateShard(sl); Assert.IsNotNull(sNew); sm.DeleteShard(sNew); }
public void UpdateShardVersionMismatch() { ShardMapManager smm = ShardMapManagerFactory.GetSqlShardMapManager( Globals.ShardMapManagerConnectionString, ShardMapManagerLoadPolicy.Lazy); ShardMap sm = smm.GetShardMap(ShardMapTests.s_defaultShardMapName); Assert.IsNotNull(sm); ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapTests.s_shardedDBs[0]); Shard sNew = sm.CreateShard(new ShardCreationInfo(sl, ShardStatus.Online)); // update shard once to increment version ShardUpdate su = new ShardUpdate(); su.Status = ShardStatus.Offline; Shard sUpdated = sm.UpdateShard(sNew, su); Assert.IsNotNull(sNew); // now try updating sNew shard again. bool updateFailed = false; try { Shard sUpdatedFail = sm.UpdateShard(sNew, su); } catch (ShardManagementException sme) { Assert.AreEqual(ShardManagementErrorCategory.ShardMap, sme.ErrorCategory); Assert.AreEqual(ShardManagementErrorCode.ShardVersionMismatch, sme.ErrorCode); updateFailed = true; } Assert.IsTrue(updateFailed); }
/// <summary> /// Helper function to clean default shard map. /// </summary> private static void CleanShardMapsHelper() { ShardMapManager smm = ShardMapManagerFactory.GetSqlShardMapManager( Globals.ShardMapManagerConnectionString, ShardMapManagerLoadPolicy.Lazy); // Remove all existing mappings from the list shard map. ShardMap sm = smm.GetShardMap(ShardMapTests.s_defaultShardMapName); Assert.IsNotNull(sm); // Remove all shards from list shard map IEnumerable <Shard> s = sm.GetShards(); using (IEnumerator <Shard> sEnum = s.GetEnumerator()) { while (sEnum.MoveNext()) { sm.DeleteShard(sEnum.Current); } } }
public void UpdateShard() { ShardMapManager smm = ShardMapManagerFactory.GetSqlShardMapManager( Globals.ShardMapManagerConnectionString, ShardMapManagerLoadPolicy.Lazy); ShardMap sm = smm.GetShardMap(ShardMapTests.s_defaultShardMapName); Assert.IsNotNull(sm); ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapTests.s_shardedDBs[0]); Shard sNew = sm.CreateShard(new ShardCreationInfo(sl, ShardStatus.Online)); ShardUpdate su = new ShardUpdate(); su.Status = ShardStatus.Offline; Shard sUpdated = sm.UpdateShard(sNew, su); Assert.IsNotNull(sNew); }
public void CreateShardNullLocation() { ShardMapManager smm = ShardMapManagerFactory.GetSqlShardMapManager( Globals.ShardMapManagerConnectionString, ShardMapManagerLoadPolicy.Lazy); ShardMap sm = smm.GetShardMap(ShardMapTests.s_defaultShardMapName); Assert.IsNotNull(sm); bool addFailed = false; try { ShardLocation sl = new ShardLocation("", ""); Shard sNew = sm.CreateShard(sl); } catch (ArgumentException) { addFailed = true; } Assert.IsTrue(addFailed); }
public void DeleteShardAbortGSMDoAndLSMUndo() { bool shouldThrow = true; IStoreOperationFactory sof = new StubStoreOperationFactory() { CallBase = true, CreateRemoveShardOperationShardMapManagerIStoreShardMapIStoreShard = (_smm, _sm, _s) => { StubRemoveShardOperation op = new StubRemoveShardOperation(_smm, _sm, _s); 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); ShardMap sm = smm.GetShardMap(ShardMapTests.s_defaultShardMapName); Assert.IsNotNull(sm); ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapTests.s_shardedDBs[0]); Shard sNew = sm.CreateShard(sl); Assert.IsNotNull(sNew); bool storeOperationFailed = false; try { sm.DeleteShard(sNew); } catch (ShardManagementException sme) { Assert.AreEqual(ShardManagementErrorCategory.ShardMap, sme.ErrorCategory); Assert.AreEqual(ShardManagementErrorCode.StorageOperationFailure, sme.ErrorCode); storeOperationFailed = true; } Assert.IsTrue(storeOperationFailed); // verify that the shard exists in store. Shard sValidate = sm.GetShard(sl); Assert.IsNotNull(sValidate); // Obtain the pending operations. var pendingOperations = ShardMapperTests.GetPendingStoreOperations(); Assert.AreEqual(pendingOperations.Count(), 1); shouldThrow = false; storeOperationFailed = false; try { sm.DeleteShard(sNew); } catch (ShardManagementException) { storeOperationFailed = true; } Assert.IsFalse(storeOperationFailed); Assert.AreEqual(0, sm.GetShards().Count()); }
public void CreateShardAbortGSM() { int retryCount = 0; EventHandler <RetryingEventArgs> eventHandler = (sender, arg) => { retryCount++; }; ShardMapManager smm = new ShardMapManager( new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString), new SqlStoreConnectionFactory(), new StubStoreOperationFactory() { CallBase = true, CreateAddShardOperationShardMapManagerIStoreShardMapIStoreShard = (_smm, _sm, _s) => new NTimeFailingAddShardOperation(10, _smm, _sm, _s) }, new CacheStore(), ShardMapManagerLoadPolicy.Lazy, new RetryPolicy(5, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior); ShardMap sm = smm.GetShardMap(ShardMapTests.s_defaultShardMapName); Assert.IsNotNull(sm); ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapTests.s_shardedDBs[0]); bool storeOperationFailed = false; smm.ShardMapManagerRetrying += eventHandler; try { Shard sNew = sm.CreateShard(sl); Assert.IsNotNull(sNew); } catch (ShardManagementException sme) { Assert.AreEqual(ShardManagementErrorCategory.ShardMap, sme.ErrorCategory); Assert.AreEqual(ShardManagementErrorCode.StorageOperationFailure, sme.ErrorCode); storeOperationFailed = true; } smm.ShardMapManagerRetrying -= eventHandler; Assert.AreEqual(5, retryCount); Assert.IsTrue(storeOperationFailed); // verify that shard map does not have any shards. int count = 0; IEnumerable <Shard> sList = sm.GetShards(); using (IEnumerator <Shard> sEnum = sList.GetEnumerator()) { while (sEnum.MoveNext()) { count++; } } Assert.AreEqual(0, count); }
public void DeleteShardAbortGSMDoAndLSMUndo() { bool shouldThrow = true; IStoreOperationFactory sof = new StubStoreOperationFactory() { CallBase = true, CreateRemoveShardOperationShardMapManagerIStoreShardMapIStoreShard = (_smm, _sm, _s) => { StubRemoveShardOperation op = new StubRemoveShardOperation(_smm, _sm, _s); 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); ShardMap sm = smm.GetShardMap(ShardMapTests.s_defaultShardMapName); Assert.IsNotNull(sm); ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapTests.s_shardedDBs[0]); Shard sNew = sm.CreateShard(sl); Assert.IsNotNull(sNew); bool storeOperationFailed = false; try { sm.DeleteShard(sNew); } catch (ShardManagementException sme) { Assert.AreEqual(ShardManagementErrorCategory.ShardMap, sme.ErrorCategory); Assert.AreEqual(ShardManagementErrorCode.StorageOperationFailure, sme.ErrorCode); storeOperationFailed = true; } Assert.IsTrue(storeOperationFailed); // verify that the shard exists in store. Shard sValidate = sm.GetShard(sl); Assert.IsNotNull(sValidate); // Obtain the pending operations. var pendingOperations = ShardMapperTests.GetPendingStoreOperations(); Assert.AreEqual(pendingOperations.Count(), 1); shouldThrow = false; storeOperationFailed = false; try { sm.DeleteShard(sNew); } catch (ShardManagementException) { storeOperationFailed = true; } Assert.IsFalse(storeOperationFailed); Assert.AreEqual(0, sm.GetShards().Count()); }
public void CreateShardAbortGSM() { int retryCount = 0; EventHandler<RetryingEventArgs> eventHandler = (sender, arg) => { retryCount++; }; ShardMapManager smm = new ShardMapManager( new SqlShardMapManagerCredentials(Globals.ShardMapManagerConnectionString), new SqlStoreConnectionFactory(), new StubStoreOperationFactory() { CallBase = true, CreateAddShardOperationShardMapManagerIStoreShardMapIStoreShard = (_smm, _sm, _s) => new NTimeFailingAddShardOperation(10, _smm, _sm, _s) }, new CacheStore(), ShardMapManagerLoadPolicy.Lazy, new RetryPolicy(5, TimeSpan.Zero, TimeSpan.Zero, TimeSpan.Zero), RetryBehavior.DefaultRetryBehavior); ShardMap sm = smm.GetShardMap(ShardMapTests.s_defaultShardMapName); Assert.IsNotNull(sm); ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapTests.s_shardedDBs[0]); bool storeOperationFailed = false; smm.ShardMapManagerRetrying += eventHandler; try { Shard sNew = sm.CreateShard(sl); Assert.IsNotNull(sNew); } catch (ShardManagementException sme) { Assert.AreEqual(ShardManagementErrorCategory.ShardMap, sme.ErrorCategory); Assert.AreEqual(ShardManagementErrorCode.StorageOperationFailure, sme.ErrorCode); storeOperationFailed = true; } smm.ShardMapManagerRetrying -= eventHandler; Assert.AreEqual(5, retryCount); Assert.IsTrue(storeOperationFailed); // verify that shard map does not have any shards. int count = 0; IEnumerable<Shard> sList = sm.GetShards(); using (IEnumerator<Shard> sEnum = sList.GetEnumerator()) { while (sEnum.MoveNext()) count++; } Assert.AreEqual(0, count); }
public void CreateShardDefault() { ShardMapManager smm = ShardMapManagerFactory.GetSqlShardMapManager( Globals.ShardMapManagerConnectionString, ShardMapManagerLoadPolicy.Lazy); ShardMap sm = smm.GetShardMap(ShardMapTests.s_defaultShardMapName); Assert.IsNotNull(sm); ShardLocation sl = new ShardLocation( Globals.ShardMapManagerTestsDatasourceName, ShardMapTests.s_shardedDBs[0], SqlProtocol.Tcp, 1433); Shard sNew = sm.CreateShard(sl); Assert.IsNotNull(sNew); // Validate that the shard location is round-tripped correctly Assert.AreEqual(sl, sNew.Location); Assert.AreEqual(sl, sm.GetShard(sl).Location); // Validate that we can connect to the shard (using all the overloads OpenConnection available) using (sNew.OpenConnection( Globals.ShardUserConnectionString)) { } // Validate that we can connect to the shard using (sNew.OpenConnection( Globals.ShardUserConnectionString, ConnectionOptions.Validate)) { } var sqlAuthLogin = new SqlAuthenticationLogin(Globals.ShardMapManagerConnectionString, Globals.SqlLoginTestUser, Globals.SqlLoginTestPassword); if (sqlAuthLogin.Create()) { // Validate that we can connect to the shard using Sql Auth using (sNew.OpenConnection(Globals.ShardUserConnectionStringForSqlAuth(sqlAuthLogin.UniquifiedUserName), ConnectionOptions.Validate)) { } // Validate that we can connect to the shard using a secure Sql Auth Credential using (sNew.OpenConnection(string.Empty, Globals.ShardUserCredentialForSqlAuth(sqlAuthLogin.UniquifiedUserName))) { } using (sNew.OpenConnection( string.Empty, Globals.ShardUserCredentialForSqlAuth(sqlAuthLogin.UniquifiedUserName), ConnectionOptions.Validate)) { } // Validate that we can connect to the shard using Sql Auth and a secure credential // This should fail with an ArgumentException (because you can't pass in both a SqlAuth connection string // and a secure credential. try { using (sNew.OpenConnection( Globals.ShardUserConnectionStringForSqlAuth(sqlAuthLogin.UniquifiedUserName), Globals.ShardUserCredentialForSqlAuth(sqlAuthLogin.UniquifiedUserName), ConnectionOptions.Validate)) { } Assert.Fail("This should have thrown, "); } catch (ArgumentException) { // Expected failure. you can't pass in both a SqlAuth connection string and a secure credential } // Drop test login sqlAuthLogin.Drop(); } else { Assert.Inconclusive("Failed to create sql login, test skipped"); } }
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 }