Пример #1
0
        public TestsFixture()
        {
            _context = new MockContext();
            MockContext.Start(this.GetType(), ".ctor");
            try
            {
                _redisEnterpriseCacheManagementHelper = new RedisEnterpriseCacheManagementHelper(this, _context);
                _redisEnterpriseCacheManagementHelper.TryRegisterSubscriptionForResource();

                ResourceGroupName        = TestUtilities.GenerateName("RedisEnterpriseCreateUpdate");
                RedisEnterpriseCacheName = TestUtilities.GenerateName("RedisEnterpriseCreateUpdate");
                DatabaseName             = "default";
                _redisEnterpriseCacheManagementHelper.TryCreateResourceGroup(ResourceGroupName, RedisEnterpriseCacheManagementHelper.Location);
            }
            catch (Exception)
            {
                Cleanup();
                throw;
            }
            finally
            {
                HttpMockServer.Flush();
            }
        }
        public void BeginCreateFunctionalTest()
        {
            using (var context = MockContext.Start(this.GetType()))
            {
                RedisEnterpriseCacheManagementHelper _redisEnterpriseCacheManagementHelper = new RedisEnterpriseCacheManagementHelper(this, context);
                _redisEnterpriseCacheManagementHelper.TryRegisterSubscriptionForResource();

                string resourceGroupName        = TestUtilities.GenerateName("RedisEnterpriseBegin");
                string redisEnterpriseCacheName = TestUtilities.GenerateName("RedisEnterpriseBegin");
                string databaseName             = "default";

                RedisEnterpriseManagementClient _client = RedisEnterpriseCacheManagementTestUtilities.GetRedisEnterpriseManagementClient(this, context);
                _redisEnterpriseCacheManagementHelper.TryCreateResourceGroup(resourceGroupName, RedisEnterpriseCacheManagementHelper.Location);
                Cluster clusterResponse = _client.RedisEnterprise.BeginCreate(resourceGroupName, redisEnterpriseCacheName,
                                                                              parameters: new Cluster
                {
                    Location = RedisEnterpriseCacheManagementHelper.Location,
                    Sku      = new Sku()
                    {
                        Name     = SkuName.EnterpriseE10,
                        Capacity = 2
                    },
                    MinimumTlsVersion = TlsVersion.OneFullStopTwo,
                    Zones             = new List <string> {
                        "1", "2", "3"
                    },
                });

                Assert.Contains(redisEnterpriseCacheName, clusterResponse.Id);
                Assert.Equal(RedisEnterpriseCacheManagementHelper.Location, clusterResponse.Location);
                Assert.Equal(redisEnterpriseCacheName, clusterResponse.Name);
                Assert.Equal("Microsoft.Cache/redisEnterprise", clusterResponse.Type);
                Assert.Equal(ProvisioningState.Creating, clusterResponse.ProvisioningState, ignoreCase: true);
                Assert.Equal(ResourceState.Creating, clusterResponse.ResourceState, ignoreCase: true);
                Assert.Equal(SkuName.EnterpriseE10, clusterResponse.Sku.Name);
                Assert.Equal(2, clusterResponse.Sku.Capacity);

                // Wait up to 30 minutes for cluster creation to succeed
                for (int i = 0; i < 60; i++)
                {
                    clusterResponse = _client.RedisEnterprise.Get(resourceGroupName, redisEnterpriseCacheName);
                    if (ProvisioningState.Succeeded.Equals(clusterResponse.ProvisioningState, StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                    TestUtilities.Wait(TimeSpan.FromSeconds(30));
                }
                Assert.Equal(ResourceState.Running, clusterResponse.ResourceState, ignoreCase: true);
                Assert.Equal(3, clusterResponse.Zones.Count);

                Database databaseResponse = _client.Databases.BeginCreate(resourceGroupName, redisEnterpriseCacheName, databaseName,
                                                                          parameters: new Database
                {
                    ClientProtocol   = Protocol.Encrypted,
                    ClusteringPolicy = ClusteringPolicy.OSSCluster,
                    EvictionPolicy   = EvictionPolicy.NoEviction,
                    Persistence      = new Persistence()
                    {
                        AofEnabled   = true,
                        AofFrequency = AofFrequency.OneSecond
                    },
                    Modules = new List <Module>()
                    {
                        new Module(name: "RedisBloom", args: "ERROR_RATE 0.01 INITIAL_SIZE 400"),
                        new Module(name: "RedisTimeSeries", args: "RETENTION_POLICY 20"),
                        new Module(name: "RediSearch")
                    },
                });

                // Wait up to 30 minutes for database creation to succeed
                for (int i = 0; i < 60; i++)
                {
                    databaseResponse = _client.Databases.Get(resourceGroupName, redisEnterpriseCacheName, databaseName);
                    if (ProvisioningState.Succeeded.Equals(databaseResponse.ProvisioningState, StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                    TestUtilities.Wait(TimeSpan.FromSeconds(30));
                }

                Assert.Contains(databaseName, databaseResponse.Id);
                Assert.Equal(databaseName, databaseResponse.Name);
                Assert.Equal("Microsoft.Cache/redisEnterprise/databases", databaseResponse.Type);
                Assert.Equal(ResourceState.Running, databaseResponse.ResourceState, ignoreCase: true);
                Assert.Equal(Protocol.Encrypted, databaseResponse.ClientProtocol);
                Assert.Equal(ClusteringPolicy.OSSCluster, databaseResponse.ClusteringPolicy);
                Assert.Equal(EvictionPolicy.NoEviction, databaseResponse.EvictionPolicy);
                Assert.Equal(3, databaseResponse.Modules.Count);

                _client.RedisEnterprise.Delete(resourceGroupName: resourceGroupName, clusterName: redisEnterpriseCacheName);
            }
        }
        public void BeginCreateFunctionalTest()
        {
            using (var context = MockContext.Start(this.GetType()))
            {
                var _redisEnterpriseCacheManagementHelper = new RedisEnterpriseCacheManagementHelper(this, context);
                _redisEnterpriseCacheManagementHelper.TryRegisterSubscriptionForResource();

                var resourceGroupName        = TestUtilities.GenerateName("RedisEnterpriseBegin");
                var redisEnterpriseCacheName = TestUtilities.GenerateName("RedisEnterpriseBegin");
                var databaseName             = "default";

                var _client = RedisEnterpriseCacheManagementTestUtilities.GetRedisEnterpriseManagementClient(this, context);
                _redisEnterpriseCacheManagementHelper.TryCreateResourceGroup(resourceGroupName, RedisEnterpriseCacheManagementHelper.Location);
                var response = _client.RedisEnterprise.BeginCreate(resourceGroupName, redisEnterpriseCacheName,
                                                                   parameters: new Cluster
                {
                    Location = RedisEnterpriseCacheManagementHelper.Location,
                    Sku      = new Sku()
                    {
                        Name     = SkuName.EnterpriseE10,
                        Capacity = 2
                    },
                    MinimumTlsVersion = "1.2",
                    Zones             = new List <string> {
                        "1", "2", "3"
                    },
                });

                Assert.Contains(redisEnterpriseCacheName, response.Id);
                Assert.Equal(RedisEnterpriseCacheManagementHelper.Location, response.Location);
                Assert.Equal(redisEnterpriseCacheName, response.Name);
                Assert.Equal("Microsoft.Cache/redisEnterprise", response.Type);
                Assert.Equal(ProvisioningState.Creating, response.ProvisioningState, ignoreCase: true);
                Assert.Equal(ResourceState.Creating, response.ResourceState, ignoreCase: true);
                Assert.Equal(SkuName.EnterpriseE10, response.Sku.Name);
                Assert.Equal(2, response.Sku.Capacity);

                for (int i = 0; i < 60; i++)
                {
                    response = _client.RedisEnterprise.GetMethod(resourceGroupName, redisEnterpriseCacheName);
                    if (ProvisioningState.Succeeded.Equals(response.ProvisioningState, StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                    TestUtilities.Wait(new TimeSpan(0, 0, 30));
                }
                Assert.Equal(ResourceState.Running, response.ResourceState, ignoreCase: true);
                Assert.Equal(3, response.Zones.Count);

                var responseDatabase = _client.Databases.BeginCreate(resourceGroupName, redisEnterpriseCacheName, databaseName,
                                                                     parameters: new Database
                {
                    ClientProtocol   = Protocol.Encrypted,
                    ClusteringPolicy = ClusteringPolicy.OSSCluster,
                    EvictionPolicy   = EvictionPolicy.NoEviction,
                    Modules          = new List <Module>()
                    {
                        new Module(name: "RedisBloom", args: "ERROR_RATE 0.00 INITIAL_SIZE 400"),
                        new Module(name: "RedisTimeSeries", args: "RETENTION_POLICY 20"),
                        new Module(name: "RediSearch")
                    },
                });

                Assert.Contains(databaseName, responseDatabase.Id);
                Assert.Equal(databaseName, responseDatabase.Name);
                Assert.Equal("Microsoft.Cache/redisEnterprise/databases", responseDatabase.Type);
                Assert.Equal(ProvisioningState.Succeeded, responseDatabase.ProvisioningState, ignoreCase: true);
                Assert.Equal(ResourceState.Running, responseDatabase.ResourceState, ignoreCase: true);
                Assert.Equal(Protocol.Encrypted, responseDatabase.ClientProtocol);
                Assert.Equal(ClusteringPolicy.OSSCluster, responseDatabase.ClusteringPolicy);
                Assert.Equal(EvictionPolicy.NoEviction, responseDatabase.EvictionPolicy);
                Assert.Equal(3, responseDatabase.Modules.Count);

                _client.RedisEnterprise.Delete(resourceGroupName: resourceGroupName, clusterName: redisEnterpriseCacheName);
            }
        }
Пример #4
0
        public void ActiveGeoReplicationFunctionalTest()
        {
            using (var context = MockContext.Start(this.GetType()))
            {
                var    resourceGroupName         = TestUtilities.GenerateName("RedisActiveGeo");
                var    redisEnterpriseCacheName1 = TestUtilities.GenerateName("RedisActiveGeo1");
                var    redisEnterpriseCacheName2 = TestUtilities.GenerateName("RedisActiveGeo2");
                string databaseName  = "default";
                string groupNickname = TestUtilities.GenerateName("activeGeoTesting");

                var _redisEnterpriseCacheManagementHelper = new RedisEnterpriseCacheManagementHelper(this, context);
                _redisEnterpriseCacheManagementHelper.TryRegisterSubscriptionForResource();
                _redisEnterpriseCacheManagementHelper.TryCreateResourceGroup(resourceGroupName, RedisEnterpriseCacheManagementHelper.Location);
                RedisEnterpriseManagementClient _client = RedisEnterpriseCacheManagementTestUtilities.GetRedisEnterpriseManagementClient(this, context);

                // Create cache in east us
                Cluster clusterResponse1 = _client.RedisEnterprise.BeginCreate(resourceGroupName, redisEnterpriseCacheName1,
                                                                               parameters: new Cluster
                {
                    Location = RedisEnterpriseCacheManagementHelper.Location,
                    Sku      = new Sku()
                    {
                        Name     = SkuName.EnterpriseE10,
                        Capacity = 2
                    }
                });
                Assert.Contains(redisEnterpriseCacheName1, clusterResponse1.Id);
                Assert.Equal(RedisEnterpriseCacheManagementHelper.Location, clusterResponse1.Location);
                Assert.Equal(redisEnterpriseCacheName1, clusterResponse1.Name);
                Assert.Equal("Microsoft.Cache/redisEnterprise", clusterResponse1.Type);
                Assert.Equal(ProvisioningState.Creating, clusterResponse1.ProvisioningState, ignoreCase: true);
                Assert.Equal(ResourceState.Creating, clusterResponse1.ResourceState, ignoreCase: true);
                Assert.Equal(SkuName.EnterpriseE10, clusterResponse1.Sku.Name);
                Assert.Equal(2, clusterResponse1.Sku.Capacity);

                // Create cache in west us
                Cluster clusterResponse2 = _client.RedisEnterprise.BeginCreate(resourceGroupName, redisEnterpriseCacheName2,
                                                                               parameters: new Cluster
                {
                    Location = RedisEnterpriseCacheManagementHelper.SecondaryLocation,
                    Sku      = new Sku()
                    {
                        Name     = SkuName.EnterpriseE10,
                        Capacity = 2
                    }
                });
                Assert.Contains(redisEnterpriseCacheName2, clusterResponse2.Id);
                Assert.Equal(RedisEnterpriseCacheManagementHelper.SecondaryLocation, clusterResponse2.Location);
                Assert.Equal(redisEnterpriseCacheName2, clusterResponse2.Name);
                Assert.Equal("Microsoft.Cache/redisEnterprise", clusterResponse2.Type);
                Assert.Equal(ProvisioningState.Creating, clusterResponse2.ProvisioningState, ignoreCase: true);
                Assert.Equal(ResourceState.Creating, clusterResponse2.ResourceState, ignoreCase: true);
                Assert.Equal(SkuName.EnterpriseE10, clusterResponse2.Sku.Name);
                Assert.Equal(2, clusterResponse2.Sku.Capacity);

                // Wait for both cache creation to complete
                for (int i = 0; i < 120; i++)
                {
                    clusterResponse1 = _client.RedisEnterprise.Get(resourceGroupName, redisEnterpriseCacheName1);
                    clusterResponse2 = _client.RedisEnterprise.Get(resourceGroupName, redisEnterpriseCacheName2);
                    if (ProvisioningState.Succeeded.Equals(clusterResponse1.ProvisioningState, StringComparison.OrdinalIgnoreCase) &&
                        ProvisioningState.Succeeded.Equals(clusterResponse2.ProvisioningState, StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                    TestUtilities.Wait(TimeSpan.FromSeconds(30));
                }
                Assert.Equal(ResourceState.Running, clusterResponse1.ResourceState, ignoreCase: true);
                Assert.Equal(ResourceState.Running, clusterResponse2.ResourceState, ignoreCase: true);

                // Fail if a cache is not created successfully
                Assert.Equal(ProvisioningState.Succeeded, clusterResponse1.ProvisioningState, ignoreCase: true);
                Assert.Equal(ProvisioningState.Succeeded, clusterResponse2.ProvisioningState, ignoreCase: true);

                // create db for cluster 1
                string   linkedDatabaseId1 = clusterResponse1.Id + "/databases/" + databaseName;
                Database databaseResponse1 = _client.Databases.BeginCreate(resourceGroupName, redisEnterpriseCacheName1, databaseName,
                                                                           parameters: new Database
                {
                    ClientProtocol   = Protocol.Encrypted,
                    ClusteringPolicy = ClusteringPolicy.EnterpriseCluster,
                    EvictionPolicy   = EvictionPolicy.NoEviction,
                    GeoReplication   = new DatabasePropertiesGeoReplication()
                    {
                        GroupNickname   = groupNickname,
                        LinkedDatabases = new List <LinkedDatabase>()
                        {
                            new LinkedDatabase(id: linkedDatabaseId1)
                        }
                    }
                });
                Assert.Equal(LinkState.Linking, databaseResponse1.GeoReplication.LinkedDatabases[0].State);

                // Wait up to 30 minutes for database creation to succeed
                for (int i = 0; i < 60; i++)
                {
                    databaseResponse1 = _client.Databases.Get(resourceGroupName, redisEnterpriseCacheName1, databaseName);
                    if (ProvisioningState.Succeeded.Equals(databaseResponse1.ProvisioningState, StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                    TestUtilities.Wait(TimeSpan.FromSeconds(30));
                }
                Assert.Contains(databaseName, databaseResponse1.Id);
                Assert.Equal(databaseName, databaseResponse1.Name);
                Assert.Equal("Microsoft.Cache/redisEnterprise/databases", databaseResponse1.Type);
                Assert.Equal(ResourceState.Running, databaseResponse1.ResourceState, ignoreCase: true);
                Assert.Equal(Protocol.Encrypted, databaseResponse1.ClientProtocol);
                Assert.Equal(ClusteringPolicy.EnterpriseCluster, databaseResponse1.ClusteringPolicy);
                Assert.Equal(EvictionPolicy.NoEviction, databaseResponse1.EvictionPolicy);
                Assert.Equal(groupNickname, databaseResponse1.GeoReplication.GroupNickname);
                Assert.Equal(linkedDatabaseId1, databaseResponse1.GeoReplication.LinkedDatabases[0].Id);
                Assert.Equal(LinkState.Linked, databaseResponse1.GeoReplication.LinkedDatabases[0].State);


                // create db for cluster 2
                string   linkedDatabaseId2 = clusterResponse2.Id + "/databases/" + databaseName;
                Database databaseResponse2 = _client.Databases.BeginCreate(resourceGroupName, redisEnterpriseCacheName2, databaseName,
                                                                           parameters: new Database
                {
                    ClientProtocol   = Protocol.Encrypted,
                    ClusteringPolicy = ClusteringPolicy.EnterpriseCluster,
                    EvictionPolicy   = EvictionPolicy.NoEviction,
                    GeoReplication   = new DatabasePropertiesGeoReplication()
                    {
                        GroupNickname   = groupNickname,
                        LinkedDatabases = new List <LinkedDatabase>()
                        {
                            new LinkedDatabase(id: linkedDatabaseId1),
                            new LinkedDatabase(id: linkedDatabaseId2)
                        }
                    }
                });
                Assert.Equal(LinkState.Linking, databaseResponse2.GeoReplication.LinkedDatabases[1].State);

                // Wait up to 30 minutes for database creation to succeed
                for (int i = 0; i < 60; i++)
                {
                    databaseResponse2 = _client.Databases.Get(resourceGroupName, redisEnterpriseCacheName2, databaseName);
                    if (ProvisioningState.Succeeded.Equals(databaseResponse2.ProvisioningState, StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                    TestUtilities.Wait(TimeSpan.FromSeconds(30));
                }
                Assert.Contains(databaseName, databaseResponse2.Id);
                Assert.Equal(databaseName, databaseResponse2.Name);
                Assert.Equal("Microsoft.Cache/redisEnterprise/databases", databaseResponse2.Type);
                Assert.Equal(ResourceState.Running, databaseResponse2.ResourceState, ignoreCase: true);
                Assert.Equal(Protocol.Encrypted, databaseResponse2.ClientProtocol);
                Assert.Equal(ClusteringPolicy.EnterpriseCluster, databaseResponse2.ClusteringPolicy);
                Assert.Equal(EvictionPolicy.NoEviction, databaseResponse2.EvictionPolicy);
                Assert.Equal(groupNickname, databaseResponse2.GeoReplication.GroupNickname);
                Assert.Equal(2, databaseResponse2.GeoReplication.LinkedDatabases.Count);
                Assert.Equal(linkedDatabaseId1, databaseResponse2.GeoReplication.LinkedDatabases[0].Id);
                Assert.Equal(LinkState.Linked, databaseResponse2.GeoReplication.LinkedDatabases[0].State);
                Assert.Equal(linkedDatabaseId2, databaseResponse2.GeoReplication.LinkedDatabases[1].Id);
                Assert.Equal(LinkState.Linked, databaseResponse2.GeoReplication.LinkedDatabases[1].State);

                // Check if all linked ids can be seen on database 1 as well
                databaseResponse1 = _client.Databases.Get(resourceGroupName, redisEnterpriseCacheName1, databaseName);
                Assert.Equal(2, databaseResponse1.GeoReplication.LinkedDatabases.Count);

                // Force unlink database 1 from active geo-replication group
                _client.Databases.ForceUnlink(resourceGroupName, redisEnterpriseCacheName2, databaseName, new List <string>()
                {
                    linkedDatabaseId1
                });

                // Wait for 5 min
                for (int i = 0; i < 10; i++)
                {
                    databaseResponse2 = _client.Databases.Get(resourceGroupName, redisEnterpriseCacheName2, databaseName);
                    if (databaseResponse2.GeoReplication.LinkedDatabases.Count.Equals(1))
                    {
                        break;
                    }
                    TestUtilities.Wait(TimeSpan.FromSeconds(30));
                }
                Assert.Equal(1, databaseResponse2.GeoReplication.LinkedDatabases.Count);
                Assert.Equal(linkedDatabaseId2, databaseResponse2.GeoReplication.LinkedDatabases[0].Id);
                Assert.Equal(LinkState.Linked, databaseResponse2.GeoReplication.LinkedDatabases[0].State);

                // Clean up resources
                _client.RedisEnterprise.Delete(resourceGroupName: resourceGroupName, clusterName: redisEnterpriseCacheName1);
                _client.RedisEnterprise.Delete(resourceGroupName: resourceGroupName, clusterName: redisEnterpriseCacheName2);
            }
        }