public void TryGetShardMapManager_Success()
        {
            ShardMapManagerFactory.CreateSqlShardMapManager(
                Globals.ShardMapManagerConnectionString,
                ShardMapManagerCreateMode.ReplaceExisting);

            foreach (ShardMapManagerLoadPolicy loadPolicy in Enum.GetValues(typeof(ShardMapManagerLoadPolicy)))
            {
                ShardMapManager smm;
                bool            success;

                success = ShardMapManagerFactory.TryGetSqlShardMapManager(
                    Globals.ShardMapManagerConnectionString,
                    loadPolicy,
                    out smm);
                Assert.IsTrue(success);
                Assert.IsNotNull(smm);

                success = ShardMapManagerFactory.TryGetSqlShardMapManager(
                    Globals.ShardMapManagerConnectionString,
                    loadPolicy,
                    RetryBehavior.DefaultRetryBehavior,
                    out smm);
                Assert.IsTrue(success);
                Assert.IsNotNull(smm);

                // Cover all the overloads
                var sqlAuthLogin = new SqlAuthenticationLogin(Globals.ShardMapManagerConnectionString, Globals.SqlLoginTestUser, Globals.SqlLoginTestPassword);

                if (sqlAuthLogin.Create())
                {
                    success = ShardMapManagerFactory.TryGetSqlShardMapManager(
                        Globals.ShardMapManagerConnectionStringForSqlAuth,
                        Globals.ShardUserCredentialForSqlAuth(sqlAuthLogin.UniquifiedUserName),
                        loadPolicy,
                        RetryBehavior.DefaultRetryBehavior,
                        out smm);
                    Assert.IsTrue(success);
                    Assert.IsNotNull(smm);

                    success = ShardMapManagerFactory.TryGetSqlShardMapManager(
                        Globals.ShardMapManagerConnectionStringForSqlAuth,
                        Globals.ShardUserCredentialForSqlAuth(sqlAuthLogin.UniquifiedUserName),
                        loadPolicy,
                        RetryBehavior.DefaultRetryBehavior,
                        null,
                        out smm);
                    Assert.IsTrue(success);
                    Assert.IsNotNull(smm);
                }
                else
                {
                    Assert.Inconclusive("Failed to create sql login, test skipped");
                }
            }
        }
        public void GetShardMapManager_Success()
        {
            ShardMapManagerFactory.CreateSqlShardMapManager(
                Globals.ShardMapManagerConnectionString,
                ShardMapManagerCreateMode.ReplaceExisting);

            foreach (ShardMapManagerLoadPolicy loadPolicy in Enum.GetValues(typeof(ShardMapManagerLoadPolicy)))
            {
                ShardMapManager smm1 = ShardMapManagerFactory.GetSqlShardMapManager(
                    Globals.ShardMapManagerConnectionString,
                    loadPolicy);
                Assert.IsNotNull(smm1);

                ShardMapManager smm2 = ShardMapManagerFactory.GetSqlShardMapManager(
                    Globals.ShardMapManagerConnectionString,
                    loadPolicy,
                    RetryBehavior.DefaultRetryBehavior);
                Assert.IsNotNull(smm2);

                var sqlAuthLogin = new SqlAuthenticationLogin(Globals.ShardMapManagerConnectionString, Globals.SqlLoginTestUser, Globals.SqlLoginTestPassword);

                if (sqlAuthLogin.Create())
                {
                    // Cover all the GetSqlShardMapManager overloads
                    ShardMapManager smm3 = ShardMapManagerFactory.GetSqlShardMapManager(
                        Globals.ShardMapManagerConnectionStringForSqlAuth,
                        Globals.ShardUserCredentialForSqlAuth(sqlAuthLogin.UniquifiedUserName),
                        loadPolicy,
                        RetryBehavior.DefaultRetryBehavior);
                    Assert.IsNotNull(smm3);

                    ShardMapManager smm4 = ShardMapManagerFactory.GetSqlShardMapManager(
                        Globals.ShardMapManagerConnectionStringForSqlAuth,
                        Globals.ShardUserCredentialForSqlAuth(sqlAuthLogin.UniquifiedUserName),
                        loadPolicy,
                        RetryBehavior.DefaultRetryBehavior,
                        null);
                    Assert.IsNotNull(smm4);

                    ShardMapManager smm5 = ShardMapManagerFactory.GetSqlShardMapManager(
                        Globals.ShardMapManagerConnectionStringForSqlAuth,
                        Globals.ShardUserCredentialForSqlAuth(sqlAuthLogin.UniquifiedUserName),
                        loadPolicy);
                    Assert.IsNotNull(smm5);

                    // Drop test login
                    sqlAuthLogin.Drop();
                }
                else
                {
                    Assert.Inconclusive("Failed to create sql login, test skipped");
                }
            }
        }
        public void CreateShardMapManager_Overwrite()
        {
            var sqlAuthLogin = new SqlAuthenticationLogin(Globals.ShardMapManagerConnectionString, Globals.SqlLoginTestUser, Globals.SqlLoginTestPassword);

            if (sqlAuthLogin.Create())
            {
                ShardMapManagerFactory.CreateSqlShardMapManager(
                    Globals.ShardMapManagerConnectionString,
                    ShardMapManagerCreateMode.ReplaceExisting);

                // Cover all the CreateSqlShardMapManager overloads
                ShardMapManagerFactory.CreateSqlShardMapManager(
                    Globals.ShardMapManagerConnectionStringForSqlAuth,
                    Globals.ShardUserCredentialForSqlAuth(sqlAuthLogin.UniquifiedUserName),
                    ShardMapManagerCreateMode.ReplaceExisting);

                // This overload should fail with a ShardManagementException, because the manager already exists (but the Auth should work)
                try
                {
                    ShardMapManagerFactory.CreateSqlShardMapManager(
                        Globals.ShardMapManagerConnectionStringForSqlAuth,
                        Globals.ShardUserCredentialForSqlAuth(sqlAuthLogin.UniquifiedUserName));
                    Assert.Fail("This should have thrown, because the manager already exists");
                }
                catch (ShardManagementException)
                {
                }

                // This overload should fail with a ShardManagementException, because the manager already exists (but the Auth should work)
                try
                {
                    ShardMapManagerFactory.CreateSqlShardMapManager(Globals.ShardMapManagerConnectionString);
                    Assert.Fail("This should have thrown, because the manager already exists");
                }
                catch (ShardManagementException)
                {
                }

                // This overload should fail with a ShardManagementException, because the manager already exists (but the Auth should work)
                try
                {
                    ShardMapManagerFactory.CreateSqlShardMapManager(
                        Globals.ShardMapManagerConnectionString,
                        RetryBehavior.DefaultRetryBehavior);
                    Assert.Fail("This should have thrown, because the manager already exists");
                }
                catch (ShardManagementException)
                {
                }

                ShardMapManagerFactory.CreateSqlShardMapManager(
                    Globals.ShardMapManagerConnectionString,
                    ShardMapManagerCreateMode.ReplaceExisting,
                    RetryBehavior.DefaultRetryBehavior);

                ShardMapManagerFactory.CreateSqlShardMapManager(
                    Globals.ShardMapManagerConnectionStringForSqlAuth,
                    Globals.ShardUserCredentialForSqlAuth(sqlAuthLogin.UniquifiedUserName),
                    ShardMapManagerCreateMode.ReplaceExisting,
                    RetryBehavior.DefaultRetryBehavior);

                ShardMapManagerFactory.CreateSqlShardMapManager(
                    Globals.ShardMapManagerConnectionString,
                    ShardMapManagerCreateMode.ReplaceExisting,
                    RetryBehavior.DefaultRetryBehavior,
                    null);

                ShardMapManagerFactory.CreateSqlShardMapManager(
                    Globals.ShardMapManagerConnectionStringForSqlAuth,
                    Globals.ShardUserCredentialForSqlAuth(sqlAuthLogin.UniquifiedUserName),
                    ShardMapManagerCreateMode.ReplaceExisting,
                    RetryBehavior.DefaultRetryBehavior,
                    null);

                // Drop test login
                sqlAuthLogin.Drop();
            }
            else
            {
                Assert.Inconclusive("Failed to create sql login, test skipped");
            }
        }
Example #4
0
        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");
            }
        }