Пример #1
0
        public void TestListElasticPoolActivity()
        {
            using (SqlManagementTestContext context = new SqlManagementTestContext(this))
            {
                ResourceGroup       resourceGroup = context.CreateResourceGroup();
                Server              server        = context.CreateServer(resourceGroup);
                SqlManagementClient sqlClient     = context.GetClient <SqlManagementClient>();

                Dictionary <string, string> tags = new Dictionary <string, string>()
                {
                    { "tagKey1", "TagValue1" }
                };

                // Create a elastic pool
                //
                string epName  = SqlManagementTestUtilities.GenerateName();
                var    epInput = new ElasticPool()
                {
                    Location       = server.Location,
                    Tags           = tags,
                    DatabaseDtuMax = 5,
                    DatabaseDtuMin = 0
                };
                var returnedEp = sqlClient.ElasticPools.CreateOrUpdate(resourceGroup.Name, server.Name, epName, epInput);
                SqlManagementTestUtilities.ValidateElasticPool(epInput, returnedEp, epName);

                // Get the Elastic Pool Activity List
                var activity = sqlClient.ElasticPoolActivities.ListByElasticPool(resourceGroup.Name, server.Name, epName);

                Assert.Equal(1, activity.Where(a => a.ElasticPoolName == epName).Count());
                Assert.Equal(1, activity.Where(a => a.Operation == "CREATE").Count());
            }
        }
Пример #2
0
        public void TestListElasticPoolDatabaseActivity()
        {
            using (SqlManagementTestContext context = new SqlManagementTestContext(this))
            {
                ResourceGroup       resourceGroup = context.CreateResourceGroup();
                Server              server        = context.CreateServer(resourceGroup);
                SqlManagementClient sqlClient     = context.GetClient <SqlManagementClient>();

                Dictionary <string, string> tags = new Dictionary <string, string>()
                {
                    { "tagKey1", "TagValue1" }
                };

                // Create a elastic pool
                //
                string epName  = SqlManagementTestUtilities.GenerateName();
                var    epInput = new ElasticPool()
                {
                    Location       = server.Location,
                    Sku            = SqlTestConstants.DefaultElasticPoolSku(),
                    Tags           = tags,
                    DatabaseDtuMax = 5,
                    DatabaseDtuMin = 0
                };
                var returnedEp = sqlClient.ElasticPools.CreateOrUpdate(resourceGroup.Name, server.Name, epName, epInput);
                SqlManagementTestUtilities.ValidateElasticPool(epInput, returnedEp, epName);

                // Create a database
                string dbName  = SqlManagementTestUtilities.GenerateName();
                var    dbInput = new Database()
                {
                    Location = server.Location
                };
                sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, dbInput);

                // Add database to elastic pool - should have CREATE and UPDATE records
                // This is because we moved existing DB to elastic pool instead of creating in Elastic Pool
                dbInput = new Database()
                {
                    Location      = server.Location,
                    ElasticPoolId = returnedEp.Id
                };
                sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, dbInput);

                // Get the Elastic Pool Database Activity List
                var activity = sqlClient.ElasticPoolDatabaseActivities.ListByElasticPool(resourceGroup.Name, server.Name, epName);

                Assert.Equal(2, activity.Where(a => a.DatabaseName == dbName).Count());
                Assert.Equal(1, activity.Where(a => a.DatabaseName == dbName && a.Operation == "CREATE").Count());
                Assert.Equal(1, activity.Where(a => a.DatabaseName == dbName && a.Operation == "UPDATE").Count());
            }
        }
Пример #3
0
        public void TestRemoveDatabaseFromPool()
        {
            using (SqlManagementTestContext context = new SqlManagementTestContext(this))
            {
                ResourceGroup       resourceGroup = context.CreateResourceGroup();
                Server              server        = context.CreateServer(resourceGroup);
                SqlManagementClient sqlClient     = context.GetClient <SqlManagementClient>();

                Dictionary <string, string> tags = new Dictionary <string, string>()
                {
                    { "tagKey1", "TagValue1" }
                };

                // Create an elastic pool
                //
                string epName  = SqlManagementTestUtilities.GenerateName();
                var    epInput = new ElasticPool()
                {
                    Location       = server.Location,
                    Sku            = SqlTestConstants.DefaultElasticPoolSku(),
                    Tags           = tags,
                    DatabaseDtuMax = 5,
                    DatabaseDtuMin = 0
                };
                var returnedEp = sqlClient.ElasticPools.CreateOrUpdate(resourceGroup.Name, server.Name, epName, epInput);
                SqlManagementTestUtilities.ValidateElasticPool(epInput, returnedEp, epName);

                // Create a database in first elastic pool
                string dbName  = SqlManagementTestUtilities.GenerateName();
                var    dbInput = new Database()
                {
                    Location      = server.Location,
                    ElasticPoolId = returnedEp.Id
                };
                sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, dbInput);

                // Remove the database from the pool
                dbInput = new Database()
                {
                    Sku      = new Microsoft.Azure.Management.Sql.Models.Sku(ServiceObjectiveName.Basic),
                    Location = server.Location,
                };
                var dbResult = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, dbInput);

                Assert.Equal(null, dbResult.ElasticPoolName);
            }
        }
        public void TestGetAndListElasticPool()
        {
            using (SqlManagementTestContext context = new SqlManagementTestContext(this))
            {
                ResourceGroup       resourceGroup = context.CreateResourceGroup();
                Server              server        = context.CreateServer(resourceGroup);
                SqlManagementClient sqlClient     = context.GetClient <SqlManagementClient>();

                Dictionary <string, ElasticPool> inputs = new Dictionary <string, ElasticPool>();

                // Create elastic pools to run the get/List tests on.
                for (int i = 0; i < 3; i++)
                {
                    string name = SqlManagementTestUtilities.GenerateName();
                    inputs.Add(name, new ElasticPool()
                    {
                        Location = server.Location,
                        Sku      = SqlTestConstants.DefaultElasticPoolSku(),
                    });
                    sqlClient.ElasticPools.CreateOrUpdate(resourceGroup.Name, server.Name, name, inputs[name]);
                }

                // Get each database and compare to the results of create database
                //
                foreach (var ep in inputs)
                {
                    var response = sqlClient.ElasticPools.Get(resourceGroup.Name, server.Name, ep.Key);
                    SqlManagementTestUtilities.ValidateElasticPool(ep.Value, response, ep.Key);
                }

                var listResponse = sqlClient.ElasticPools.ListByServer(resourceGroup.Name, server.Name);
                Assert.Equal(inputs.Count(), listResponse.Count());

                foreach (var ep in listResponse)
                {
                    SqlManagementTestUtilities.ValidateElasticPool(inputs[ep.Name], ep, ep.Name);
                }

                foreach (var ep in inputs)
                {
                    SqlManagementTestUtilities.ValidateElasticPool(ep.Value, listResponse.Single(e => e.Name == ep.Key), ep.Key);
                }
            }
        }
Пример #5
0
        public void TestMoveOutOfHyperscalePoolAndGetActivity()
        {
            using (SqlManagementTestContext context = new SqlManagementTestContext(this))
            {
                ResourceGroup       resourceGroup = context.CreateResourceGroup(TestEnvironmentUtilities.DefaultStagePrimaryLocation);
                Server              server        = context.CreateServer(resourceGroup, TestEnvironmentUtilities.DefaultStagePrimaryLocation);
                SqlManagementClient sqlClient     = context.GetClient <SqlManagementClient>();

                // Create a Hyperscale elasticPool with specified replica count of 2
                //
                string epName  = SqlManagementTestUtilities.GenerateName();
                var    epInput = new ElasticPool()
                {
                    Location = server.Location,
                    Sku      = new Microsoft.Azure.Management.Sql.Models.Sku("HS_Gen5_4"),
                    HighAvailabilityReplicaCount = 2
                };

                var returnedEp = sqlClient.ElasticPools.CreateOrUpdate(resourceGroup.Name, server.Name, epName, epInput);
                SqlManagementTestUtilities.ValidateElasticPool(epInput, returnedEp, epName);

                // Create a database in elastic pool
                string dbName  = SqlManagementTestUtilities.GenerateName();
                var    dbInput = new Database()
                {
                    Location      = server.Location,
                    ElasticPoolId = returnedEp.Id
                };
                sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, dbInput);

                // Move database out of elastic pool
                dbInput = new Database()
                {
                    Location = server.Location,
                    Sku      = new Microsoft.Azure.Management.Sql.Models.Sku("HS_Gen5_4")
                };
                var returnedDb = sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, dbInput);

                // Verify database has the same value for replica count as pool
                Assert.Equal(2, returnedDb.HighAvailabilityReplicaCount);
            }
        }
        private void TestUpdateElasticPool <TUpdateModel>(
            SqlManagementClient sqlClient,
            ResourceGroup resourceGroup,
            Server server,
            Func <TUpdateModel> createModelFunc,
            Func <string, string, string, TUpdateModel, ElasticPool> updateFunc)
        {
            Dictionary <string, string> tags = new Dictionary <string, string>()
            {
                { "tagKey1", "TagValue1" }
            };

            // Create a elasticPool with parameters Tags
            //
            string epName  = SqlManagementTestUtilities.GenerateName();
            var    epInput = new ElasticPool()
            {
                Location       = server.Location,
                Sku            = new Microsoft.Azure.Management.Sql.Models.Sku("StandardPool"),
                Tags           = tags,
                DatabaseDtuMax = 20,
                DatabaseDtuMin = 0
            };
            var returnedEp = sqlClient.ElasticPools.CreateOrUpdate(resourceGroup.Name, server.Name, epName, epInput);

            SqlManagementTestUtilities.ValidateElasticPool(epInput, returnedEp, epName);
            var epa = sqlClient.ElasticPoolActivities.ListByElasticPool(resourceGroup.Name, server.Name, epName);

            Assert.NotNull(epa);
            Assert.Equal(1, epa.Count());
            Assert.Equal(1, epa.Where(a => a.Operation == "CREATE").Count());

            // Update elasticPool Dtu
            //
            dynamic epInput2 = createModelFunc();

            epInput2.Sku          = returnedEp.Sku;
            epInput2.Sku.Capacity = 200;

            returnedEp = updateFunc(resourceGroup.Name, server.Name, epName, epInput2);
            SqlManagementTestUtilities.ValidateElasticPool(epInput2, returnedEp, epName);
            epa = sqlClient.ElasticPoolActivities.ListByElasticPool(resourceGroup.Name, server.Name, epName);
            Assert.NotNull(epa);
            Assert.Equal(2, epa.Count());
            Assert.Equal(1, epa.Where(a => a.Operation == "CREATE").Count());
            Assert.Equal(1, epa.Where(a => a.Operation == "UPDATE").Count());

            // Update elasticPool Dtu Max
            //
            dynamic epInput3 = createModelFunc();

            epInput3.DatabaseDtuMax = 100;

            returnedEp = updateFunc(resourceGroup.Name, server.Name, epName, epInput3);
            SqlManagementTestUtilities.ValidateElasticPool(epInput3, returnedEp, epName);
            epa = sqlClient.ElasticPoolActivities.ListByElasticPool(resourceGroup.Name, server.Name, epName);
            Assert.NotNull(epa);
            Assert.Equal(3, epa.Count());
            Assert.Equal(1, epa.Where(a => a.Operation == "CREATE").Count());
            Assert.Equal(2, epa.Where(a => a.Operation == "UPDATE").Count());

            // Update elasticPool Dtu Min
            //
            dynamic epInput4 = createModelFunc();

            epInput4.DatabaseDtuMin = 10;

            returnedEp = updateFunc(resourceGroup.Name, server.Name, epName, epInput4);
            SqlManagementTestUtilities.ValidateElasticPool(epInput4, returnedEp, epName);
            epa = sqlClient.ElasticPoolActivities.ListByElasticPool(resourceGroup.Name, server.Name, epName);
            Assert.NotNull(epa);
            Assert.Equal(4, epa.Count());
            Assert.Equal(1, epa.Where(a => a.Operation == "CREATE").Count());
            Assert.Equal(3, epa.Where(a => a.Operation == "UPDATE").Count());
        }
        public async Task TestCancelUpdateElasticPoolOperation()
        {
            /* *
             * In this test we only test the cancel operation on resize pool from Premium to Premium
             *    since currently we only support Cancel pool resize operation on Premium <-> Premium
             * */
            string testPrefix = "sqlelasticpoollistcanceloperation-";

            using (SqlManagementTestContext context = new SqlManagementTestContext(this))
            {
                ResourceGroup               resourceGroup = context.CreateResourceGroup("West Europe");
                Server                      server        = context.CreateServer(resourceGroup, "westeurope");
                SqlManagementClient         sqlClient     = context.GetClient <SqlManagementClient>();
                Dictionary <string, string> tags          = new Dictionary <string, string>()
                {
                    { "tagKey1", "TagValue1" }
                };

                // Create a premium elastic pool with required parameters
                string epName  = SqlManagementTestUtilities.GenerateName();
                var    epInput = new ElasticPool()
                {
                    Location = server.Location,
                    Sku      = new Microsoft.Azure.Management.Sql.Models.Sku(ElasticPoolEdition.Premium + "Pool"),
                    Tags     = tags,
                };
                var elasticPool = sqlClient.ElasticPools.CreateOrUpdate(resourceGroup.Name, server.Name, epName, epInput);
                SqlManagementTestUtilities.ValidateElasticPool(epInput, elasticPool, epName);
                Assert.NotNull(elasticPool);

                // Update elastic pool to Premium with 250 DTU
                var epUpdateReponse = sqlClient.ElasticPools.BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroup.Name, server.Name, epName, new ElasticPool()
                {
                    Location = server.Location,
                    Sku      = new Microsoft.Azure.Management.Sql.Models.Sku(ElasticPoolEdition.Premium + "Pool")
                    {
                        Capacity = 250,
                    },
                    Tags = tags
                });

                if (HttpMockServer.Mode == HttpRecorderMode.Record)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(15));
                }

                // Get the pool update operation for new added properties on elastic pool operations: ETA, Operation Description and IsCancellable
                //   Expected they have null value since not been updated by operation progress
                AzureOperationResponse <IPage <ElasticPoolOperation> > response = sqlClient.ElasticPoolOperations.ListByElasticPoolWithHttpMessagesAsync(resourceGroup.Name, server.Name, epName).Result;
                Assert.Equal(HttpStatusCode.OK, response.Response.StatusCode);
                IList <ElasticPoolOperation> responseObject = response.Body.ToList();
                Assert.Single(responseObject);
                Assert.NotNull(responseObject[0].PercentComplete);
                Assert.NotNull(responseObject[0].EstimatedCompletionTime);
                Assert.NotNull(responseObject[0].Description);
                Assert.NotNull(responseObject[0].IsCancellable);

                // Cancel the elastic pool update operation
                string requestId = responseObject[0].Name;
                sqlClient.ElasticPoolOperations.Cancel(resourceGroup.Name, server.Name, epName, Guid.Parse(requestId));
                CloudException ex = await Assert.ThrowsAsync <CloudException>(() => sqlClient.GetPutOrPatchOperationResultAsync(epUpdateReponse.Result, new Dictionary <string, List <string> >(), CancellationToken.None));

                Assert.Contains("OperationCancelled", ex.Body.Code);

                // Make sure the elastic pool is not updated due to cancel operation
                var epGetResponse = sqlClient.ElasticPools.Get(resourceGroup.Name, server.Name, epName);
                Assert.Equal(125, epGetResponse.Dtu);
                Assert.Equal(DatabaseEdition.Premium, epGetResponse.Edition);
            }
        }
Пример #8
0
        public void TestMoveBetweenPoolsAndGetActivity()
        {
            using (SqlManagementTestContext context = new SqlManagementTestContext(this))
            {
                ResourceGroup       resourceGroup = context.CreateResourceGroup();
                Server              server        = context.CreateServer(resourceGroup);
                SqlManagementClient sqlClient     = context.GetClient <SqlManagementClient>();

                Dictionary <string, string> tags = new Dictionary <string, string>()
                {
                    { "tagKey1", "TagValue1" }
                };

                // Create two elastic pools
                //
                string epName  = SqlManagementTestUtilities.GenerateName();
                var    epInput = new ElasticPool()
                {
                    Location       = server.Location,
                    Tags           = tags,
                    DatabaseDtuMax = 5,
                    DatabaseDtuMin = 0
                };
                var returnedEp1 = sqlClient.ElasticPools.CreateOrUpdate(resourceGroup.Name, server.Name, epName, epInput);
                SqlManagementTestUtilities.ValidateElasticPool(epInput, returnedEp1, epName);

                string epName2 = SqlManagementTestUtilities.GenerateName();
                epInput = new ElasticPool()
                {
                    Location       = server.Location,
                    Tags           = tags,
                    DatabaseDtuMax = 5,
                    DatabaseDtuMin = 0
                };
                var returnedEp2 = sqlClient.ElasticPools.CreateOrUpdate(resourceGroup.Name, server.Name, epName2, epInput);
                SqlManagementTestUtilities.ValidateElasticPool(epInput, returnedEp2, epName2);

                // Create a database in first elastic pool
                string dbName  = SqlManagementTestUtilities.GenerateName();
                var    dbInput = new Database()
                {
                    Location      = server.Location,
                    ElasticPoolId = returnedEp1.Id
                };
                sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, dbInput);

                // Get the Elastic Pool Database Activity List for first pool
                var activity = sqlClient.ElasticPoolDatabaseActivities.ListByElasticPool(resourceGroup.Name, server.Name, epName);
                Assert.Equal(1, activity.Where(a => a.DatabaseName == dbName).Count());
                Assert.Equal(1, activity.Where(a => a.DatabaseName == dbName && a.Operation == "CREATE").Count());

                // Move database to second elastic pool
                dbInput = new Database()
                {
                    Location      = server.Location,
                    ElasticPoolId = returnedEp2.Id
                };
                sqlClient.Databases.CreateOrUpdate(resourceGroup.Name, server.Name, dbName, dbInput);

                // Get the Elastic Pool Database Activity List for second pool
                activity = sqlClient.ElasticPoolDatabaseActivities.ListByElasticPool(resourceGroup.Name, server.Name, epName2);
                Assert.Equal(2, activity.Where(a => a.DatabaseName == dbName).Count());
                Assert.Equal(1, activity.Where(a => a.DatabaseName == dbName && a.Operation == "CREATE").Count());
                Assert.Equal(1, activity.Where(a => a.DatabaseName == dbName && a.Operation == "UPDATE").Count());
            }
        }
Пример #9
0
        private void TestUpdateHyperscaleElasticPool <TUpdateModel>(
            SqlManagementClient sqlClient,
            ResourceGroup resourceGroup,
            Server server,
            Func <TUpdateModel> createModelFunc,
            Func <string, string, string, TUpdateModel, ElasticPool> updateFunc)
        {
            // Create a Hyperscale elasticPool
            //
            string epName  = SqlManagementTestUtilities.GenerateName();
            var    epInput = new ElasticPool()
            {
                Location = server.Location,
                Sku      = new Microsoft.Azure.Management.Sql.Models.Sku("HS_Gen5_4")
            };
            var returnedEp = sqlClient.ElasticPools.CreateOrUpdate(resourceGroup.Name, server.Name, epName, epInput);

            SqlManagementTestUtilities.ValidateElasticPool(epInput, returnedEp, epName);
            var epa = sqlClient.ElasticPoolActivities.ListByElasticPool(resourceGroup.Name, server.Name, epName);

            Assert.NotNull(epa);
            Assert.Equal(1, epa.Count());
            Assert.Equal(1, epa.Where(a => a.Operation == "CREATE").Count());

            // Verify pool has default HighAvailabilityReplicaCount
            Assert.Equal(1, returnedEp.HighAvailabilityReplicaCount);

            // Update HighAvailabilityReplicaCount
            //
            dynamic epInput2 = createModelFunc();

            epInput2.HighAvailabilityReplicaCount = 2;

            updateFunc(resourceGroup.Name, server.Name, epName, epInput2);

            returnedEp = sqlClient.ElasticPools.Get(resourceGroup.Name, server.Name, epName);

            SqlManagementTestUtilities.ValidateElasticPool(epInput2, returnedEp, epName);
            epa = sqlClient.ElasticPoolActivities.ListByElasticPool(resourceGroup.Name, server.Name, epName);
            Assert.NotNull(epa);
            Assert.Equal(2, epa.Count());
            Assert.Equal(1, epa.Where(a => a.Operation == "CREATE").Count());
            Assert.Equal(1, epa.Where(a => a.Operation == "UPDATE").Count());

            // Verify pool has updated HighAvailabilityReplicaCount
            //
            Assert.Equal(2, returnedEp.HighAvailabilityReplicaCount);

            // Update Hyperscale pool SLO
            //
            dynamic epInput3 = createModelFunc();

            epInput3.Sku = new Microsoft.Azure.Management.Sql.Models.Sku("HS_Gen5_8");

            returnedEp = updateFunc(resourceGroup.Name, server.Name, epName, epInput3);
            SqlManagementTestUtilities.ValidateElasticPool(epInput2, returnedEp, epName);
            epa = sqlClient.ElasticPoolActivities.ListByElasticPool(resourceGroup.Name, server.Name, epName);
            Assert.NotNull(epa);
            Assert.Equal(3, epa.Count());
            Assert.Equal(1, epa.Where(a => a.Operation == "CREATE").Count());
            Assert.Equal(2, epa.Where(a => a.Operation == "UPDATE").Count());

            // Verify pool has same HighAvailabilityReplicaCount
            //
            Assert.Equal(2, returnedEp.HighAvailabilityReplicaCount);

            // Verify pool has updated SLO
            //
            Assert.Equal(8, returnedEp.Sku.Capacity);
        }