public void TryCreatingCache(string resourceGroupName, string cacheName, string location)
        {
            var redisClient = RedisCacheManagementTestUtilities.GetRedisManagementClient(_testBase, _context);
            var createResponse = redisClient.Redis.Create(resourceGroupName: resourceGroupName, name: cacheName,
                                    parameters: new RedisCreateParameters
                                    {
                                        Location = location,
                                        Sku = new Microsoft.Azure.Management.Redis.Models.Sku()
                                        {
                                            Name = SkuName.Basic,
                                            Family = SkuFamily.C,
                                            Capacity = 0
                                        }
                                    });

            RedisResource response = redisClient.Redis.Get(resourceGroupName: resourceGroupName, name: cacheName);
            ThrowIfTrue(!response.Id.Contains(cacheName), "Cache name not found inside Id.");
            ThrowIfTrue(!response.Name.Equals(cacheName), string.Format("Cache name is not equal to {0}", cacheName));
            ThrowIfTrue(!response.HostName.Contains(cacheName), "Cache name not found inside host name.");

            // wait for maximum 30 minutes for cache to create
            for (int i = 0; i < 60; i++)
            {
                TestUtilities.Wait(new TimeSpan(0, 0, 30));
                RedisResource responseGet = redisClient.Redis.Get(resourceGroupName: resourceGroupName, name: cacheName);
                if ("succeeded".Equals(responseGet.ProvisioningState, StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }
                ThrowIfTrue(i == 60, "Cache is not in succeeded state even after 30 min.");
            }
        }
        public RedisResource UpdateCache(string resourceGroupName, string cacheName, string skuFamily, int skuCapacity, string skuName,
                                         Hashtable redisConfiguration, bool?enableNonSslPort, Hashtable tenantSettings, int?shardCount, string MinimumTlsVersion, Hashtable tags)
        {
            _resourceManagementClient.Providers.Register("Microsoft.Cache");
            var parameters = new RedisUpdateParameters
            {
                Sku = new Microsoft.Azure.Management.Redis.Models.Sku
                {
                    Name     = skuName,
                    Family   = skuFamily,
                    Capacity = skuCapacity
                }
            };

            if (tags != null)
            {
                parameters.Tags = new Dictionary <string, string>();
                foreach (object key in tags.Keys)
                {
                    parameters.Tags.Add(key.ToString(), tags[key].ToString());
                }
            }

            if (redisConfiguration != null)
            {
                parameters.RedisConfiguration = new Dictionary <string, string>();
                foreach (object key in redisConfiguration.Keys)
                {
                    parameters.RedisConfiguration.Add(key.ToString(), redisConfiguration[key].ToString());
                }
            }

            parameters.EnableNonSslPort = enableNonSslPort;

            if (tenantSettings != null)
            {
                parameters.TenantSettings = new Dictionary <string, string>();
                foreach (object key in tenantSettings.Keys)
                {
                    // RP should disregard "InternalDependencyList" passed from user (it happens because of piping scenario)
                    string stringKey = key.ToString();
                    if (stringKey.Equals("InternalDependencyList", StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }
                    parameters.TenantSettings.Add(key.ToString(), tenantSettings[key].ToString());
                }
            }

            parameters.ShardCount = shardCount;

            if (!string.IsNullOrEmpty(MinimumTlsVersion))
            {
                parameters.MinimumTlsVersion = MinimumTlsVersion;
            }

            RedisResource response = _client.Redis.Update(resourceGroupName: resourceGroupName, name: cacheName, parameters: parameters);

            return(response);
        }
        public RedisCacheAttributesWithAccessKeys(RedisResource cache, RedisAccessKeys accessKeys, string resourceGroupName)
        {
            Id                 = cache.Id;
            Location           = cache.Location;
            Name               = cache.Name;
            Type               = cache.Type;
            HostName           = cache.HostName;
            Port               = cache.Port.HasValue ? cache.Port.Value : 0;
            ProvisioningState  = cache.ProvisioningState;
            SslPort            = cache.SslPort.HasValue ? cache.SslPort.Value : 0;
            RedisConfiguration = cache.RedisConfiguration;
            EnableNonSslPort   = cache.EnableNonSslPort.Value;
            RedisVersion       = cache.RedisVersion;
            Size               = SizeConverter.GetSizeInUserSpecificFormat(cache.Sku.Family, cache.Sku.Capacity);
            Sku                = cache.Sku.Name;

            PrimaryKey        = accessKeys.PrimaryKey;
            SecondaryKey      = accessKeys.SecondaryKey;
            ResourceGroupName = resourceGroupName;

            SubnetId       = cache.SubnetId;
            StaticIP       = cache.StaticIP;
            TenantSettings = cache.TenantSettings;
            ShardCount     = cache.ShardCount;
        }
示例#4
0
        public override void ExecuteCmdlet()
        {
            Utility.ValidateResourceGroupAndResourceName(null, PrimaryServerName);
            Utility.ValidateResourceGroupAndResourceName(null, SecondaryServerName);

            RedisResource primaryCache   = CacheClient.GetCache(PrimaryServerName);
            RedisResource secondaryCache = CacheClient.GetCache(SecondaryServerName);

            ConfirmAction(
                string.Format(Resources.LinkingRedisCache, SecondaryServerName, PrimaryServerName),
                PrimaryServerName,
                () =>
            {
                RedisLinkedServerWithProperties redisLinkedServer = CacheClient.SetLinkedServer(
                    resourceGroupName: Utility.GetResourceGroupNameFromRedisCacheId(primaryCache.Id),
                    cacheName: primaryCache.Name,
                    linkedCacheName: secondaryCache.Name,
                    linkedCacheId: secondaryCache.Id,
                    linkedCacheLocation: secondaryCache.Location,
                    serverRole: ReplicationRole.Secondary);

                if (redisLinkedServer == null)
                {
                    throw new CloudException(string.Format(Resources.LinkedServerCreationFailed, SecondaryServerName, PrimaryServerName));
                }
                WriteObject(new PSRedisLinkedServer(redisLinkedServer));
            }
                );
        }
        public void BeginCreateFunctionalTest()
        {
            using (var context = MockContext.Start(this.GetType()))
            {
                var _redisCacheManagementHelper = new RedisCacheManagementHelper(this, context);
                _redisCacheManagementHelper.TryRegisterSubscriptionForResource();

                var resourceGroupName = TestUtilities.GenerateName("RedisBegin");
                var redisCacheName    = TestUtilities.GenerateName("RedisBegin");

                var _client = RedisCacheManagementTestUtilities.GetRedisManagementClient(this, context);
                _redisCacheManagementHelper.TryCreateResourceGroup(resourceGroupName, RedisCacheManagementHelper.Location);
                RedisResource response = _client.Redis.BeginCreate(resourceGroupName, redisCacheName,
                                                                   parameters: new RedisCreateParameters
                {
                    Location = RedisCacheManagementHelper.Location,
                    Sku      = new Sku()
                    {
                        Name     = SkuName.Premium,
                        Family   = SkuFamily.P,
                        Capacity = 1
                    },
                    MinimumTlsVersion = TlsVersion.OneFullStopTwo,
                    ReplicasPerMaster = 2,
                    RedisVersion      = "6",
                });

                Assert.Contains(redisCacheName, response.Id);
                Assert.Equal(redisCacheName, response.Name);
                Assert.Equal(ProvisioningState.Creating, response.ProvisioningState, ignoreCase: true);
                Assert.Equal(SkuName.Premium, response.Sku.Name);
                Assert.Equal(SkuFamily.P, response.Sku.Family);
                Assert.Equal(TlsVersion.OneFullStopTwo, response.MinimumTlsVersion);
                Assert.Equal(2, response.ReplicasPerMaster);
                Assert.Equal("6", response.RedisVersion.Split(".")[0]);

                Assert.Equal(3, response.Instances.Count);
                for (int i = 0; i < response.Instances.Count; i++)
                {
                    Assert.Equal(15000 + i, response.Instances[i].SslPort);
                    Assert.Null(response.Instances[i].NonSslPort);
                    Assert.Null(response.Instances[i].ShardId);
                    Assert.Null(response.Instances[i].Zone);
                }

                for (int i = 0; i < 60; i++)
                {
                    response = _client.Redis.Get(resourceGroupName, redisCacheName);
                    if (ProvisioningState.Succeeded.Equals(response.ProvisioningState, StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                    TestUtilities.Wait(new TimeSpan(0, 0, 30));
                }

                _client.Redis.Delete(resourceGroupName: resourceGroupName, name: redisCacheName);
                _redisCacheManagementHelper.DeleteResourceGroup(resourceGroupName);
            }
        }
 public string GetResourceGroupNameIfNotProvided(string resourceGroupName, string cacheName)
 {
     if (string.IsNullOrEmpty(resourceGroupName))
     {
         RedisResource response = GetCache(cacheName);
         return(Utility.GetResourceGroupNameFromRedisCacheId(response.Id));
     }
     return(resourceGroupName);
 }
示例#7
0
        public override void ExecuteCmdlet()
        {
            Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name);
            RedisResource response = null;

            if (string.IsNullOrEmpty(ResourceGroupName))
            {
                response          = CacheClient.GetCache(Name);
                ResourceGroupName = Utility.GetResourceGroupNameFromRedisCacheId(response.Id);
            }
            else
            {
                response = CacheClient.GetCache(ResourceGroupName, Name);
            }

            string skuName;
            string skuFamily;
            int    skuCapacity;

            if (string.IsNullOrEmpty(Sku))
            {
                skuName = response.Sku.Name;
            }
            else
            {
                skuName = Sku;
            }

            if (string.IsNullOrEmpty(Size))
            {
                skuFamily   = response.Sku.Family;
                skuCapacity = response.Sku.Capacity;
            }
            else
            {
                Size = SizeConverter.GetSizeInRedisSpecificFormat(Size, SkuStrings.Premium.Equals(Sku));
                SizeConverter.ValidateSize(Size.ToUpper(), SkuStrings.Premium.Equals(Sku));
                skuFamily = Size.Substring(0, 1);
                int.TryParse(Size.Substring(1), out skuCapacity);
            }

            if (!ShardCount.HasValue && response.ShardCount.HasValue)
            {
                ShardCount = response.ShardCount;
            }

            ConfirmAction(
                string.Format(Resources.UpdateRedisCache, Name),
                Name,
                () =>
            {
                var redisResource = CacheClient.UpdateCache(ResourceGroupName, Name, skuFamily, skuCapacity,
                                                            skuName, RedisConfiguration, EnableNonSslPort, TenantSettings, ShardCount, Tag);
                var redisAccessKeys = CacheClient.GetAccessKeys(ResourceGroupName, Name);
                WriteObject(new RedisCacheAttributesWithAccessKeys(redisResource, redisAccessKeys, ResourceGroupName));
            });
        }
示例#8
0
        public void Get_EmptyJSONFromCSM()
        {
            string responseString          = (@"{}");
            RedisManagementClient client   = Utility.GetRedisManagementClient(responseString, null, HttpStatusCode.OK);
            RedisResource         response = client.Redis.Get(resourceGroupName: "resource-group", name: "cachename");

            Assert.Null(response.Id);
            Assert.Null(response.Location);
            Assert.Null(response.Name);
            Assert.Null(response.Type);
        }
示例#9
0
                public void AzAsyncHeader200(string inlineHttpMethod)
                {
                    var           handler    = new PlaybackTestHandler(LroRules.PUTResponses.AzAsync200());
                    var           fakeClient = GetClient(handler);
                    RedisResource redisRes   = ExecuteOperation(inlineHttpMethod, fakeClient);

                    VerifyHttpMethod(inlineHttpMethod, handler);
                    VerifyRequestUrl(PutOriginalResourceRequestUrl, handler, 0);
                    VerifyRequestUrl(Put202_AzAsyncOperationHeaderUrl, handler, requestIndex: 1);
                    VerifyRequestUrl(PutOriginalResourceRequestUrl, handler, requestIndex: 3);

                    Assert.Equal(4, handler.Requests.Count);
                    Assert.NotNull(redisRes.Location);
                }
示例#10
0
                public void NoHeader200PassThrough(string inlineHttpMethod)
                {
                    var           handler    = new PlaybackTestHandler(LroRules.PUTResponses.NoHeader200PassThrough());
                    var           fakeClient = GetClient(handler);
                    RedisResource redisRes   = ExecuteOperation(inlineHttpMethod, fakeClient);

                    VerifyHttpMethod(inlineHttpMethod, handler);
                    VerifyRequestUrl(PutOriginalResourceRequestUrl, handler, 0);
                    VerifyRequestUrl(PutOriginalResourceRequestUrl, handler, requestIndex: 1);

                    //Verify we do not execute Final GET on original resource URI
                    Assert.Equal(2, handler.Requests.Count);

                    Assert.Null(redisRes.Id);
                }
示例#11
0
        public void Get_Basic()
        {
            string responseString = (@"
            {
	            ""id"" : ""/subscriptions/a559b6fd-3a84-40bb-a450-b0db5ed37dfe/resourceGroups/HydraTest07152014/providers/Microsoft.Cache/Redis/hydraradiscache"",
	            ""location"" : ""North Europe"",
	            ""name"" : ""hydraradiscache"",
	            ""type"" : ""Microsoft.Cache/Redis"",
	            ""tags"" : {""update"": ""done""},
	            ""properties"" : {
		            ""provisioningState"" : ""Succeeded"",
		            ""sku"": {
                            ""name"": ""Basic"",
                            ""family"": ""C"",
                            ""capacity"": 1
                        },
		            ""redisVersion"" : ""2.8"",
		            ""redisConfiguration"": {""maxmemory-policy"": ""allkeys-lru""},
		            ""accessKeys"" : null,
		            ""hostName"" : ""hydraradiscache.cache.icbbvt.windows-int.net"",
		            ""port"" : 6379,
		            ""sslPort"" : 6380,
                    ""minimumTlsVersion"": ""1.2""
	            }
            }
            ");

            string requestIdHeader         = "0d33aff8-8a4e-4565-b893-a10e52260de0";
            RedisManagementClient client   = Utility.GetRedisManagementClient(responseString, requestIdHeader, HttpStatusCode.OK);
            RedisResource         response = client.Redis.Get(resourceGroupName: "resource-group", name: "cachename");

            Assert.Equal("/subscriptions/a559b6fd-3a84-40bb-a450-b0db5ed37dfe/resourceGroups/HydraTest07152014/providers/Microsoft.Cache/Redis/hydraradiscache", response.Id);
            Assert.Equal("North Europe", response.Location);
            Assert.Equal("hydraradiscache", response.Name);
            Assert.Equal("Microsoft.Cache/Redis", response.Type);

            Assert.Equal(ProvisioningState.Succeeded, response.ProvisioningState);
            Assert.Equal(SkuName.Basic, response.Sku.Name);
            Assert.Equal(SkuFamily.C, response.Sku.Family);
            Assert.Equal(1, response.Sku.Capacity);
            Assert.Equal("2.8", response.RedisVersion);
            Assert.Equal("allkeys-lru", response.RedisConfiguration["maxmemory-policy"]);

            Assert.Equal("hydraradiscache.cache.icbbvt.windows-int.net", response.HostName);
            Assert.Equal(6379, response.Port);
            Assert.Equal(6380, response.SslPort);
            Assert.Equal(TlsVersion.OneFullStopTwo, response.MinimumTlsVersion);
        }
示例#12
0
                public void LocationHeader200(string inlineHttpMethod)
                {
                    var           handler    = new PlaybackTestHandler(LroRules.PUTResponses.Location200());
                    var           fakeClient = GetClient(handler);
                    RedisResource redisRes   = ExecuteOperation(inlineHttpMethod, fakeClient);

                    VerifyHttpMethod(inlineHttpMethod, handler);
                    VerifyRequestUrl(PutOriginalResourceRequestUrl, handler, 0);
                    VerifyRequestUrl(Put202_LocationHeaderUrl, handler, requestIndex: 1);

                    //Verify we do not execute Final GET on original resource URI
                    Assert.Equal(2, handler.Requests.Count);
                    //VerifyRequestCount(inlineHttpMethod, handler, putCount: 2, patchCount: 1);

                    Assert.NotNull(redisRes.Location);
                }
 public RedisCacheAttributes(RedisResource cache, string resourceGroupName)
 {
     Id                = cache.Id;
     Location          = cache.Location;
     Name              = cache.Name;
     Type              = cache.Type;
     HostName          = cache.Properties.HostName;
     Port              = cache.Properties.Port;
     ProvisioningState = cache.Properties.ProvisioningState;
     SslPort           = cache.Properties.SslPort;
     MaxMemoryPolicy   = cache.Properties.MaxMemoryPolicy;
     RedisVersion      = cache.Properties.RedisVersion;
     Size              = SizeConverter.GetSizeInUserSpecificFormat(cache.Properties.Sku.Family, cache.Properties.Sku.Capacity);
     Sku               = cache.Properties.Sku.Name;
     ResourceGroupName = resourceGroupName;
 }
        public override void ExecuteCmdlet()
        {
            Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name);
            if (!string.IsNullOrEmpty(MaxMemoryPolicy))
            {
                throw new ArgumentException(Resources.MaxMemoryPolicyException);
            }

            RedisResource response = CacheClient.GetCache(ResourceGroupName, Name);

            string skuName;
            string skuFamily;
            int    skuCapacity;

            if (string.IsNullOrEmpty(Sku))
            {
                skuName = response.Sku.Name;
            }
            else
            {
                skuName = Sku;
            }

            if (string.IsNullOrEmpty(Size))
            {
                skuFamily   = response.Sku.Family;
                skuCapacity = response.Sku.Capacity;
            }
            else
            {
                Size      = SizeConverter.GetSizeInRedisSpecificFormat(Size, SkuStrings.Premium.Equals(Sku));
                skuFamily = Size.Substring(0, 1);
                int.TryParse(Size.Substring(1), out skuCapacity);
            }

            if (!ShardCount.HasValue && response.ShardCount.HasValue)
            {
                ShardCount = response.ShardCount;
            }


            WriteObject(new RedisCacheAttributesWithAccessKeys(
                            CacheClient.CreateOrUpdateCache(ResourceGroupName, Name, response.Location, skuFamily, skuCapacity, skuName, RedisConfiguration, EnableNonSslPort,
                                                            TenantSettings, ShardCount, response.SubnetId, response.StaticIP, response.Tags),
                            ResourceGroupName));
        }
        public void BeginCreateFunctionalTest()
        {
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                var _redisCacheManagementHelper = new RedisCacheManagementHelper(this, context);
                _redisCacheManagementHelper.TryRegisterSubscriptionForResource();

                var resourceGroupName = TestUtilities.GenerateName("RedisBegin");
                var redisCacheName    = TestUtilities.GenerateName("RedisBegin");

                var _client = RedisCacheManagementTestUtilities.GetRedisManagementClient(this, context);
                _redisCacheManagementHelper.TryCreateResourceGroup(resourceGroupName, RedisCacheManagementHelper.Location);
                RedisResource response = _client.Redis.BeginCreate(resourceGroupName, redisCacheName,
                                                                   parameters: new RedisCreateParameters
                {
                    Location = RedisCacheManagementHelper.Location,
                    Sku      = new Sku()
                    {
                        Name     = SkuName.Premium,
                        Family   = SkuFamily.P,
                        Capacity = 1
                    }
                });

                Assert.Contains(redisCacheName, response.Id);
                Assert.Equal(redisCacheName, response.Name);
                Assert.Equal("creating", response.ProvisioningState, ignoreCase: true);
                Assert.Equal(SkuName.Premium, response.Sku.Name);
                Assert.Equal(SkuFamily.P, response.Sku.Family);

                for (int i = 0; i < 60; i++)
                {
                    response = _client.Redis.Get(resourceGroupName, redisCacheName);
                    if ("succeeded".Equals(response.ProvisioningState, StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                    TestUtilities.Wait(new TimeSpan(0, 0, 30));
                }

                _client.Redis.Delete(resourceGroupName: resourceGroupName, name: redisCacheName);
                _redisCacheManagementHelper.DeleteResourceGroup(resourceGroupName);
            }
        }
示例#16
0
        public void GetTest()
        {
            using (var context = MockContext.Start(this.GetType()))
            {
                var           _client  = RedisCacheManagementTestUtilities.GetRedisManagementClient(this, context);
                RedisResource response = _client.Redis.Get(resourceGroupName: fixture.ResourceGroupName, name: fixture.RedisCacheName);
                Assert.Contains(fixture.RedisCacheName, response.Id);
                Assert.Equal(fixture.RedisCacheName, response.Name);

                Assert.Equal(ProvisioningState.Succeeded, response.ProvisioningState, ignoreCase: true);
                Assert.Equal(SkuName.Basic, response.Sku.Name);
                Assert.Equal(SkuFamily.C, response.Sku.Family);
                Assert.Equal(0, response.Sku.Capacity);

                Assert.Contains(fixture.RedisCacheName, response.HostName);
                Assert.Equal(6379, response.Port);
                Assert.Equal(6380, response.SslPort);
            }
        }
示例#17
0
        public void RebootBothNodesTest()
        {
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                var _client = RedisCacheManagementTestUtilities.GetRedisManagementClient(this, context);

                // First try to get cache and verify that it is premium cache
                RedisResource response = _client.Redis.Get(resourceGroupName: "MyResourceGroup", name: "sunnyprimary");
                Assert.Contains("sunnyprimary", response.Id);
                Assert.Equal("sunnyprimary", response.Name);
                Assert.True("succeeded".Equals(response.ProvisioningState, StringComparison.OrdinalIgnoreCase));
                Assert.Equal(SkuName.Premium, response.Sku.Name);
                Assert.Equal(SkuFamily.P, response.Sku.Family);

                RedisRebootParameters rebootParameter = new RedisRebootParameters {
                    RebootType = RebootType.AllNodes
                };
                _client.Redis.ForceReboot(resourceGroupName: "MyResourceGroup", name: "sunnyprimary", parameters: rebootParameter);
            }
        }
        public override void ExecuteCmdlet()
        {
            Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name);
            if (!string.IsNullOrEmpty(Name))
            {
                if (!string.IsNullOrEmpty(ResourceGroupName))
                {
                    // Get single cache directly by RP call
                    WriteObject(new RedisCacheAttributes(CacheClient.GetCache(ResourceGroupName, Name), ResourceGroupName));
                }
                else
                {
                    // Get single cache from list of caches
                    RedisResource response = CacheClient.GetCache(Name);
                    WriteObject(new RedisCacheAttributes(response, Utility.GetResourceGroupNameFromRedisCacheId(response.Id)));
                }
            }
            else
            {
                // List all cache in given resource group if avaliable otherwise all cache in given subscription
                IPage <RedisResource>       response = CacheClient.ListCaches(ResourceGroupName);
                List <RedisCacheAttributes> list     = new List <RedisCacheAttributes>();
                foreach (RedisResource resource in response)
                {
                    list.Add(new RedisCacheAttributes(resource, ResourceGroupName));
                }
                WriteObject(list, true);

                while (!string.IsNullOrEmpty(response.NextPageLink))
                {
                    // List using next link
                    response = CacheClient.ListCachesUsingNextLink(ResourceGroupName, response.NextPageLink);
                    list     = new List <RedisCacheAttributes>();
                    foreach (RedisResource resource in response)
                    {
                        list.Add(new RedisCacheAttributes(resource, ResourceGroupName));
                    }
                    WriteObject(list, true);
                }
            }
        }
        public RedisResource UpdateCache(string resourceGroupName, string cacheName, string skuFamily, int skuCapacity, string skuName,
                                         Hashtable redisConfiguration, bool?enableNonSslPort, Hashtable tenantSettings, int?shardCount)
        {
            _resourceManagementClient.Providers.Register("Microsoft.Cache");
            var parameters = new RedisUpdateParameters
            {
                Sku = new Microsoft.Azure.Management.Redis.Models.Sku
                {
                    Name     = skuName,
                    Family   = skuFamily,
                    Capacity = skuCapacity
                }
            };

            if (redisConfiguration != null)
            {
                parameters.RedisConfiguration = new Dictionary <string, string>();
                foreach (object key in redisConfiguration.Keys)
                {
                    parameters.RedisConfiguration.Add(key.ToString(), redisConfiguration[key].ToString());
                }
            }

            parameters.EnableNonSslPort = enableNonSslPort;

            if (tenantSettings != null)
            {
                parameters.TenantSettings = new Dictionary <string, string>();
                foreach (object key in tenantSettings.Keys)
                {
                    parameters.TenantSettings.Add(key.ToString(), tenantSettings[key].ToString());
                }
            }

            parameters.ShardCount = shardCount;

            RedisResource response = _client.Redis.BeginUpdate(resourceGroupName: resourceGroupName, name: cacheName, parameters: parameters);

            return(response);
        }
示例#20
0
 public RedisCacheAttributes(RedisResource cache, string resourceGroupName)
 {
     Id                 = cache.Id;
     Location           = cache.Location;
     Name               = cache.Name;
     Type               = cache.Type;
     HostName           = cache.HostName;
     Port               = cache.Port.HasValue? cache.Port.Value : 0;
     ProvisioningState  = cache.ProvisioningState;
     SslPort            = cache.SslPort.HasValue ? cache.SslPort.Value : 0;
     RedisConfiguration = cache.RedisConfiguration;
     EnableNonSslPort   = cache.EnableNonSslPort.Value;
     RedisVersion       = cache.RedisVersion;
     Size               = SizeConverter.GetSizeInUserSpecificFormat(cache.Sku.Family, cache.Sku.Capacity);
     Sku                = cache.Sku.Name;
     ResourceGroupName  = resourceGroupName;
     VirtualNetwork     = cache.VirtualNetwork;
     Subnet             = cache.Subnet;
     StaticIP           = cache.StaticIP;
     TenantSettings     = cache.TenantSettings;
     ShardCount         = cache.ShardCount;
 }
        public void RebootBothNodesTest()
        {
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                var _redisCacheManagementHelper = new RedisCacheManagementHelper(this, context);
                _redisCacheManagementHelper.TryRegisterSubscriptionForResource();

                var resourceGroupName = TestUtilities.GenerateName("RedisReboot");
                var redisCacheName    = TestUtilities.GenerateName("RedisReboot");

                var _client = RedisCacheManagementTestUtilities.GetRedisManagementClient(this, context);
                _redisCacheManagementHelper.TryCreateResourceGroup(resourceGroupName, RedisCacheManagementHelper.Location);
                _client.Redis.Create(resourceGroupName, redisCacheName,
                                     parameters: new RedisCreateParameters
                {
                    Location = RedisCacheManagementHelper.Location,
                    Sku      = new Sku()
                    {
                        Name     = SkuName.Premium,
                        Family   = SkuFamily.P,
                        Capacity = 1
                    }
                });

                // First try to get cache and verify that it is premium cache
                RedisResource response = _client.Redis.Get(resourceGroupName, redisCacheName);
                Assert.Contains(redisCacheName, response.Id);
                Assert.Equal(redisCacheName, response.Name);
                Assert.Equal("succeeded", response.ProvisioningState, ignoreCase: true);
                Assert.Equal(SkuName.Premium, response.Sku.Name);
                Assert.Equal(SkuFamily.P, response.Sku.Family);

                RedisRebootParameters rebootParameter = new RedisRebootParameters {
                    RebootType = RebootType.AllNodes
                };
                _client.Redis.ForceReboot(resourceGroupName, redisCacheName, parameters: rebootParameter);
            }
        }
示例#22
0
        public void PatchSchedules_PutGetDelete()
        {
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                var _client = RedisCacheManagementTestUtilities.GetRedisManagementClient(this, context);

                // First try to get cache and verify that it is premium cache
                RedisResource response = _client.Redis.Get(resourceGroupName: "sunnyjapan", name: "sunny-scheduling-dv2");
                Assert.Contains("sunny-scheduling-dv2", response.Id);
                Assert.Equal("sunny-scheduling-dv2", response.Name);
                Assert.True("succeeded".Equals(response.ProvisioningState, StringComparison.OrdinalIgnoreCase));
                Assert.Equal(SkuName.Premium, response.Sku.Name);
                Assert.Equal(SkuFamily.P, response.Sku.Family);

                ScheduleEntry[] entries = new ScheduleEntry[]
                {
                    new ScheduleEntry
                    {
                        DayOfWeek         = DayOfWeekEnum.Monday,
                        StartHourUtc      = 10,
                        MaintenanceWindow = TimeSpan.FromHours(10)
                    },
                    new ScheduleEntry
                    {
                        DayOfWeek         = DayOfWeekEnum.Tuesday,
                        StartHourUtc      = 11,
                        MaintenanceWindow = TimeSpan.FromHours(11)
                    }
                };

                ValidateResponseForSchedulePatch(_client.PatchSchedules.CreateOrUpdate(resourceGroupName: "sunnyjapan", name: "sunny-scheduling-dv2", parameters: new RedisPatchSchedulesRequest(entries)));
                ValidateResponseForSchedulePatch(_client.PatchSchedules.Get(resourceGroupName: "sunnyjapan", name: "sunny-scheduling-dv2"));
                _client.PatchSchedules.Delete(resourceGroupName: "sunnyjapan", name: "sunny-scheduling-dv2");
                var ex = Assert.Throws <CloudException>(() => _client.PatchSchedules.Get(resourceGroupName: "sunnyjapan", name: "sunny-scheduling-dv2"));
                Assert.Contains("There are no patch schedules found for redis cache 'sunny-scheduling-dv2'", ex.Message);
                Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode);
            }
        }
示例#23
0
        public void SubnetResourceNavigationLinksTest()
        {
            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler2 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler3 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient         = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(context, handler1);
                var networkManagementClient = NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2);
                var redisClient             = RedisCacheManagementTestUtilities.GetRedisManagementClientWithHandler(context, handler3);

                var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient,
                                                                                  "Microsoft.Network/virtualNetworks");

                string resourceGroupName = TestUtilities.GenerateName("csmrg");
                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = location
                });

                string vnetName   = TestUtilities.GenerateName();
                string subnetName = TestUtilities.GenerateName();
                string redisName  = TestUtilities.GenerateName();

                var vnet = new VirtualNetwork()
                {
                    Location = location,

                    AddressSpace = new AddressSpace()
                    {
                        AddressPrefixes = new List <string>()
                        {
                            "10.0.0.0/16",
                        }
                    },
                    DhcpOptions = new DhcpOptions()
                    {
                        DnsServers = new List <string>()
                        {
                            "10.1.1.1",
                            "10.1.2.4"
                        }
                    },
                    Subnets = new List <Subnet>()
                    {
                        new Subnet()
                        {
                            Name          = subnetName,
                            AddressPrefix = "10.0.0.0/24",
                        }
                    }
                };

                var putVnetResponse = networkManagementClient.VirtualNetworks.CreateOrUpdate(resourceGroupName, vnetName, vnet);

                var getSubnetResponse = networkManagementClient.Subnets.Get(resourceGroupName, vnetName, subnetName);
                Assert.Null(getSubnetResponse.ResourceNavigationLinks);

                redisClient.Redis.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, redisName, parameters: new RedisCreateOrUpdateParameters
                {
                    Location = location,
                    Sku      = new Sku()
                    {
                        Name     = SkuName.Premium,
                        Family   = SkuFamily.P,
                        Capacity = 1
                    },
                    SubnetId = getSubnetResponse.Id
                }).Wait();

                // wait for maximum 30 minutes for cache to create
                for (int i = 0; i < 60; i++)
                {
                    TestUtilities.Wait(new TimeSpan(0, 0, 30));
                    RedisResource responseGet = redisClient.Redis.Get(resourceGroupName: resourceGroupName, name: redisName);
                    if ("succeeded".Equals(responseGet.ProvisioningState, StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                    Assert.False(i == 60, "Cache is not in succeeded state even after 30 min.");
                }

                getSubnetResponse = networkManagementClient.Subnets.Get(resourceGroupName, vnetName, subnetName);
                Assert.Equal(1, getSubnetResponse.ResourceNavigationLinks.Count);
            }
        }
示例#24
0
        public override void ExecuteCmdlet()
        {
            Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name);
            if (string.IsNullOrEmpty(Sku))
            {
                Sku = SkuStrings.Standard;
            }


            if (string.IsNullOrEmpty(Size))
            {
                if (SkuStrings.Premium.Equals(Sku, StringComparison.OrdinalIgnoreCase))
                {
                    Size = SizeConverter.P1String;
                }
                else
                {
                    Size = SizeConverter.C1String;
                }
            }
            else
            {
                Size = SizeConverter.GetSizeInRedisSpecificFormat(Size, SkuStrings.Premium.Equals(Sku));
                SizeConverter.ValidateSize(Size.ToUpper(), SkuStrings.Premium.Equals(Sku));
            }

            int skuCapacity = 1;
            // Size to SkuFamily and SkuCapacity conversion
            string skuFamily = Size.Substring(0, 1);

            int.TryParse(Size.Substring(1), out skuCapacity);


            // If Force flag is not avaliable than check if cache is already available or not
            try
            {
                RedisResource availableCache = CacheClient.GetCache(ResourceGroupName, Name);
                if (availableCache != null)
                {
                    throw new CloudException(string.Format(Resources.RedisCacheExists, Name));
                }
            }
            catch (CloudException ex)
            {
                if (ex.Body.Code == "ResourceNotFound" || ex.Message.Contains("ResourceNotFound"))
                {
                    // cache does not exists so go ahead and create one
                }
                else if (ex.Body.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound"))
                {
                    // resource group not found, let create throw error don't throw from here
                }
                else
                {
                    // all other exceptions should be thrown
                    throw;
                }
            }
            catch (ErrorResponseException ex)
            {
                if (ex.Body.Error.Code == "ResourceNotFound" || ex.Message.Contains("ResourceNotFound"))
                {
                    // cache does not exists so go ahead and create one
                }
                else if (ex.Body.Error.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound"))
                {
                    // resource group not found, let create throw error don't throw from here
                }
                else
                {
                    // all other exceptions should be thrown
                    throw;
                }
            }

            ConfirmAction(
                string.Format(Resources.CreateRedisCache, Name),
                Name,
                () =>
            {
                var redisResource = CacheClient.CreateCache(ResourceGroupName, Name, Location, skuFamily, skuCapacity, Sku,
                                                            RedisConfiguration, EnableNonSslPort, TenantSettings, ShardCount, MinimumTlsVersion, SubnetId, StaticIP, Tag, Zone, RedisVersion, IdentityType, UserAssignedIdentity);
                var redisAccessKeys = CacheClient.GetAccessKeys(ResourceGroupName, Name);
                WriteObject(new RedisCacheAttributesWithAccessKeys(redisResource, redisAccessKeys, ResourceGroupName));
            });
        }
        public RedisCacheAttributes(RedisResource cache, string resourceGroupName)
        {
            Id                = cache.Id;
            Location          = cache.Location;
            Name              = cache.Name;
            Type              = cache.Type;
            HostName          = cache.HostName;
            Port              = cache.Port.HasValue ? cache.Port.Value : 0;
            ProvisioningState = cache.ProvisioningState;
            SslPort           = cache.SslPort.HasValue ? cache.SslPort.Value : 0;

            EnableNonSslPort = cache.EnableNonSslPort.Value;
            RedisVersion     = cache.RedisVersion;
            Size             = SizeConverter.GetSizeInUserSpecificFormat(cache.Sku.Family, cache.Sku.Capacity);
            Sku = cache.Sku.Name;
            ResourceGroupName = resourceGroupName;
            SubnetId          = cache.SubnetId;
            StaticIP          = cache.StaticIP;
            TenantSettings    = cache.TenantSettings;
            ShardCount        = cache.ShardCount;
            MinimumTlsVersion = cache.MinimumTlsVersion;
            Tag  = cache.Tags;
            Zone = cache.Zones;
            RedisConfiguration = new Dictionary <string, string>();

            // Converting cache.RedisConfiguration Object into a readable dictionary using the json attributes
            if (cache.RedisConfiguration != null)
            {
                foreach (PropertyInfo property in cache.RedisConfiguration.GetType().GetProperties())
                {
                    System.Attribute attr = property.GetCustomAttribute(typeof(JsonPropertyAttribute));
                    if (property.GetValue(cache.RedisConfiguration) != null && attr != null)
                    {
                        JsonPropertyAttribute jsonAttr = (JsonPropertyAttribute)attr;
                        RedisConfiguration[jsonAttr.PropertyName] = (string)property.GetValue(cache.RedisConfiguration);
                    }
                }
                if (cache.RedisConfiguration.AdditionalProperties != null)
                {
                    foreach (KeyValuePair <string, object> kvPair in cache.RedisConfiguration.AdditionalProperties)
                    {
                        RedisConfiguration[kvPair.Key] = (string)kvPair.Value;
                    }
                }
            }

            // Converting cache.Identity Object into a readable SystemAssignedIdenty dictionary and UserAssignedIdentities list
            if (cache.Identity != null)
            {
                IdentityType = "";
                if (cache.Identity.PrincipalId != null)
                {
                    SystemAssignedIdentity = new Dictionary <string, string>
                    {
                        { nameof(cache.Identity.PrincipalId), cache.Identity.PrincipalId.ToString() },
                        { nameof(cache.Identity.TenantId), cache.Identity.TenantId.ToString() }
                    };
                    IdentityType = nameof(ManagedServiceIdentityType.SystemAssigned);
                }
                if (cache.Identity.UserAssignedIdentities?.Count > 0)
                {
                    UserAssignedIdentity = new List <string>();
                    foreach (var identity in cache.Identity.UserAssignedIdentities)
                    {
                        UserAssignedIdentity.Add(identity.Key);
                    }
                    if (nameof(ManagedServiceIdentityType.SystemAssigned).Equals(IdentityType))
                    {
                        IdentityType = nameof(ManagedServiceIdentityType.SystemAssignedUserAssigned);
                    }
                    else
                    {
                        IdentityType = nameof(ManagedServiceIdentityType.UserAssigned);
                    }
                }
            }
        }
        public void PatchSchedules_PutGetDelete()
        {
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                var _redisCacheManagementHelper = new RedisCacheManagementHelper(this, context);
                _redisCacheManagementHelper.TryRegisterSubscriptionForResource();

                var resourceGroupName = TestUtilities.GenerateName("RedisSchedules");
                var redisCacheName    = TestUtilities.GenerateName("RedisSchedules");

                var _client = RedisCacheManagementTestUtilities.GetRedisManagementClient(this, context);
                _redisCacheManagementHelper.TryCreateResourceGroup(resourceGroupName, RedisCacheManagementHelper.Location);
                _client.Redis.Create(resourceGroupName, redisCacheName,
                                     parameters: new RedisCreateParameters
                {
                    Location = RedisCacheManagementHelper.Location,
                    Sku      = new Sku()
                    {
                        Name     = SkuName.Premium,
                        Family   = SkuFamily.P,
                        Capacity = 1
                    }
                });

                // First try to get cache and verify that it is premium cache
                RedisResource response = _client.Redis.Get(resourceGroupName, redisCacheName);
                Assert.Contains(redisCacheName, response.Id);
                Assert.Equal(redisCacheName, response.Name);
                Assert.Equal("succeeded", response.ProvisioningState, ignoreCase: true);
                Assert.Equal(SkuName.Premium, response.Sku.Name);
                Assert.Equal(SkuFamily.P, response.Sku.Family);

                ScheduleEntry[] entries = new ScheduleEntry[]
                {
                    new ScheduleEntry
                    {
                        DayOfWeek         = DayOfWeekEnum.Monday,
                        StartHourUtc      = 10,
                        MaintenanceWindow = TimeSpan.FromHours(10)
                    },
                    new ScheduleEntry
                    {
                        DayOfWeek         = DayOfWeekEnum.Tuesday,
                        StartHourUtc      = 11,
                        MaintenanceWindow = TimeSpan.FromHours(11)
                    }
                };

                ValidateResponseForSchedulePatch(
                    _client.PatchSchedules.CreateOrUpdate(
                        resourceGroupName,
                        redisCacheName,
                        parameters:
                        new RedisPatchSchedule(entries)),
                    redisCacheName);
                ValidateResponseForSchedulePatch(
                    _client.PatchSchedules.Get(resourceGroupName, redisCacheName),
                    redisCacheName);

                _client.PatchSchedules.Delete(resourceGroupName, redisCacheName);

                var ex = Assert.Throws <CloudException>(() => _client.PatchSchedules.Get(resourceGroupName, redisCacheName));
                Assert.Contains("There are no patch schedules found for redis cache", ex.Message);
            }
        }
        public void FirewallFunctionalTest()
        {
            using (var context = MockContext.Start(this.GetType()))
            {
                var _redisCacheManagementHelper = new RedisCacheManagementHelper(this, context);
                _redisCacheManagementHelper.TryRegisterSubscriptionForResource();

                var resourceGroupName = TestUtilities.GenerateName("RedisFirewall");
                var redisCacheName    = TestUtilities.GenerateName("RedisFirewall");

                var _client = RedisCacheManagementTestUtilities.GetRedisManagementClient(this, context);
                _redisCacheManagementHelper.TryCreateResourceGroup(resourceGroupName, RedisCacheManagementHelper.Location);
                _client.Redis.Create(resourceGroupName, redisCacheName,
                                     parameters: new RedisCreateParameters
                {
                    Location = RedisCacheManagementHelper.Location,
                    Sku      = new Sku()
                    {
                        Name     = SkuName.Premium,
                        Family   = SkuFamily.P,
                        Capacity = 1
                    }
                });

                // First try to get cache and verify that it is premium cache
                RedisResource response = _client.Redis.Get(resourceGroupName, redisCacheName);
                Assert.Contains(redisCacheName, response.Id);
                Assert.Equal(redisCacheName, response.Name);
                Assert.Equal(ProvisioningState.Succeeded, response.ProvisioningState, ignoreCase: true);
                Assert.Equal(SkuName.Premium, response.Sku.Name);
                Assert.Equal(SkuFamily.P, response.Sku.Family);

                // Set firewall rule for 10.0.0.0 to 10.0.0.32
                RedisFirewallRule ruleOne = _client.FirewallRules.CreateOrUpdate(resourceGroupName, redisCacheName, "RuleOne", new RedisFirewallRuleCreateParameters
                {
                    StartIP = "10.0.0.0",
                    EndIP   = "10.0.0.32"
                });
                Assert.Equal("10.0.0.0", ruleOne.StartIP);
                Assert.Equal("10.0.0.32", ruleOne.EndIP);

                // Set firewall rule for 10.0.0.64 to 10.0.0.128
                RedisFirewallRule ruleTwo = _client.FirewallRules.CreateOrUpdate(resourceGroupName, redisCacheName, "RuleTwo", new RedisFirewallRuleCreateParameters
                {
                    StartIP = "10.0.0.64",
                    EndIP   = "10.0.0.128"
                });
                Assert.Equal("10.0.0.64", ruleTwo.StartIP);
                Assert.Equal("10.0.0.128", ruleTwo.EndIP);

                // Get test
                ruleOne = _client.FirewallRules.Get(resourceGroupName, redisCacheName, "RuleOne");
                Assert.Equal("10.0.0.0", ruleOne.StartIP);
                Assert.Equal("10.0.0.32", ruleOne.EndIP);

                ruleTwo = _client.FirewallRules.Get(resourceGroupName, redisCacheName, "RuleTwo");
                Assert.Equal("10.0.0.64", ruleTwo.StartIP);
                Assert.Equal("10.0.0.128", ruleTwo.EndIP);

                // List test
                IPage <RedisFirewallRule> rules = _client.FirewallRules.List(resourceGroupName, redisCacheName);
                Assert.Equal(2, rules.Count());

                // Delete
                _client.FirewallRules.Delete(resourceGroupName, redisCacheName, "RuleTwo");


                if (Utility.IsLiveTest())
                {
                    Thread.Sleep(6000);
                }
                rules = _client.FirewallRules.List(resourceGroupName, redisCacheName);
                Assert.Single(rules);
                Assert.Equal("10.0.0.0", rules.First().StartIP);
                Assert.Equal("10.0.0.32", rules.First().EndIP);
            }
        }
示例#28
0
 public FederatedRedisSchemaTests(StitchingTestContext context, RedisResource redisResource)
 {
     Context     = context;
     _connection = redisResource.GetConnection();
 }
        public RedisResource CreateCache(string resourceGroupName, string cacheName, string location, string skuFamily, int skuCapacity, string skuName,
                                         Hashtable redisConfiguration, bool?enableNonSslPort, Hashtable tenantSettings, int?shardCount, string subnetId, string staticIP, IDictionary <string, string> tags = null)
        {
            _resourceManagementClient.Providers.Register("Microsoft.Cache");
            var parameters = new RedisCreateParameters
            {
                Location = location,
                Sku      = new Microsoft.Azure.Management.Redis.Models.Sku
                {
                    Name     = skuName,
                    Family   = skuFamily,
                    Capacity = skuCapacity
                }
            };

            if (tags != null)
            {
                parameters.Tags = tags;
            }

            if (redisConfiguration != null)
            {
                parameters.RedisConfiguration = new Dictionary <string, string>();
                foreach (object key in redisConfiguration.Keys)
                {
                    parameters.RedisConfiguration.Add(key.ToString(), redisConfiguration[key].ToString());
                }
            }

            if (enableNonSslPort.HasValue)
            {
                parameters.EnableNonSslPort = enableNonSslPort.Value;
            }

            if (tenantSettings != null)
            {
                parameters.TenantSettings = new Dictionary <string, string>();
                foreach (object key in tenantSettings.Keys)
                {
                    parameters.TenantSettings.Add(key.ToString(), tenantSettings[key].ToString());
                }
            }

            if (shardCount.HasValue)
            {
                parameters.ShardCount = shardCount.Value;
            }

            if (!string.IsNullOrWhiteSpace(subnetId))
            {
                parameters.SubnetId = subnetId;
            }

            if (!string.IsNullOrWhiteSpace(staticIP))
            {
                parameters.StaticIP = staticIP;
            }

            RedisResource response = _client.Redis.BeginCreate(resourceGroupName: resourceGroupName, name: cacheName, parameters: parameters);

            return(response);
        }
        public void GeoReplicationFunctionalTest()
        {
            using (var context = MockContext.Start(this.GetType()))
            {
                var resourceGroupName = TestUtilities.GenerateName("RedisGeo");
                var redisCacheName1   = TestUtilities.GenerateName("RedisGeo1");
                var redisCacheName2   = TestUtilities.GenerateName("RedisGeo2");

                var _redisCacheManagementHelper = new RedisCacheManagementHelper(this, context);
                _redisCacheManagementHelper.TryRegisterSubscriptionForResource();
                _redisCacheManagementHelper.TryCreateResourceGroup(resourceGroupName, RedisCacheManagementHelper.Location);

                var _client = RedisCacheManagementTestUtilities.GetRedisManagementClient(this, context);
                // Create cache in ncus
                RedisResource ncResponse = _client.Redis.BeginCreate(resourceGroupName, redisCacheName1,
                                                                     parameters: new RedisCreateParameters
                {
                    Location = RedisCacheManagementHelper.Location,
                    Sku      = new Sku()
                    {
                        Name     = SkuName.Premium,
                        Family   = SkuFamily.P,
                        Capacity = 1
                    }
                });

                Assert.Contains(redisCacheName1, ncResponse.Id);
                Assert.Equal(redisCacheName1, ncResponse.Name);
                Assert.Equal("creating", ncResponse.ProvisioningState, ignoreCase: true);
                Assert.Equal(SkuName.Premium, ncResponse.Sku.Name);
                Assert.Equal(SkuFamily.P, ncResponse.Sku.Family);

                // Create cache in scus
                RedisResource scResponse = _client.Redis.BeginCreate(resourceGroupName, redisCacheName2,
                                                                     parameters: new RedisCreateParameters
                {
                    Location = RedisCacheManagementHelper.SecondaryLocation,
                    Sku      = new Sku()
                    {
                        Name     = SkuName.Premium,
                        Family   = SkuFamily.P,
                        Capacity = 1
                    }
                });

                Assert.Contains(redisCacheName2, scResponse.Id);
                Assert.Equal(redisCacheName2, scResponse.Name);
                Assert.Equal("creating", scResponse.ProvisioningState, ignoreCase: true);
                Assert.Equal(SkuName.Premium, scResponse.Sku.Name);
                Assert.Equal(SkuFamily.P, scResponse.Sku.Family);

                // Wait for both cache creation to comeplete
                for (int i = 0; i < 120; i++)
                {
                    ncResponse = _client.Redis.Get(resourceGroupName, redisCacheName1);
                    scResponse = _client.Redis.Get(resourceGroupName, redisCacheName2);
                    if ("succeeded".Equals(ncResponse.ProvisioningState, StringComparison.OrdinalIgnoreCase) &&
                        "succeeded".Equals(scResponse.ProvisioningState, StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                    TestUtilities.Wait(new TimeSpan(0, 0, 30));
                }

                // Fail if any of 2 cache is not created successfully
                Assert.Equal("succeeded", ncResponse.ProvisioningState, ignoreCase: true);
                Assert.Equal("succeeded", scResponse.ProvisioningState, ignoreCase: true);

                // Set up replication link
                RedisLinkedServerWithProperties linkServerWithProperties = _client.LinkedServer.Create(resourceGroupName, redisCacheName1, redisCacheName2, new RedisLinkedServerCreateParameters
                {
                    LinkedRedisCacheId       = scResponse.Id,
                    LinkedRedisCacheLocation = RedisCacheManagementHelper.SecondaryLocation,
                    ServerRole = ReplicationRole.Secondary
                });

                Assert.Equal(redisCacheName2, linkServerWithProperties.Name);
                Assert.Equal(scResponse.Id, linkServerWithProperties.LinkedRedisCacheId);
                Assert.Equal(RedisCacheManagementHelper.SecondaryLocation, linkServerWithProperties.LinkedRedisCacheLocation);
                Assert.Equal(ReplicationRole.Secondary, linkServerWithProperties.ServerRole);
                Assert.Equal("succeeded", linkServerWithProperties.ProvisioningState, ignoreCase: true);

                // test get response from primary
                RedisLinkedServerWithProperties primaryLinkProperties = _client.LinkedServer.Get(resourceGroupName, redisCacheName1, redisCacheName2);
                Assert.Equal(scResponse.Id, primaryLinkProperties.LinkedRedisCacheId);
                Assert.Equal(RedisCacheManagementHelper.SecondaryLocation, primaryLinkProperties.LinkedRedisCacheLocation);
                Assert.Equal(ReplicationRole.Secondary, primaryLinkProperties.ServerRole);

                // test list response from primary
                IPage <RedisLinkedServerWithProperties> allPrimaryLinkProperties = _client.LinkedServer.List(resourceGroupName, redisCacheName1);
                Assert.Single(allPrimaryLinkProperties);

                // test get response from secondary
                RedisLinkedServerWithProperties secondaryLinkProperties = _client.LinkedServer.Get(resourceGroupName, redisCacheName2, redisCacheName1);
                Assert.Equal(ncResponse.Id, secondaryLinkProperties.LinkedRedisCacheId);
                Assert.Equal(RedisCacheManagementHelper.Location, secondaryLinkProperties.LinkedRedisCacheLocation);
                Assert.Equal(ReplicationRole.Primary, secondaryLinkProperties.ServerRole);

                // test list response from secondary
                IPage <RedisLinkedServerWithProperties> allSecondaryLinkProperties = _client.LinkedServer.List(resourceGroupName, redisCacheName2);
                Assert.Single(allSecondaryLinkProperties);

                // Delete link on primary
                _client.LinkedServer.Delete(resourceGroupName, redisCacheName1, redisCacheName2);

                // links should disappear in 5 min
                IPage <RedisLinkedServerWithProperties> afterDeletePrimaryLinkProperties   = null;
                IPage <RedisLinkedServerWithProperties> afterDeleteSecondaryLinkProperties = null;
                for (int i = 0; i < 10; i++)
                {
                    TestUtilities.Wait(new TimeSpan(0, 0, 30));
                    afterDeletePrimaryLinkProperties   = _client.LinkedServer.List(resourceGroupName, redisCacheName1);
                    afterDeleteSecondaryLinkProperties = _client.LinkedServer.List(resourceGroupName, redisCacheName2);
                    if (afterDeletePrimaryLinkProperties.Count() == 0 && afterDeleteSecondaryLinkProperties.Count() == 0)
                    {
                        break;
                    }
                }
                Assert.NotNull(afterDeletePrimaryLinkProperties);
                Assert.Empty(afterDeletePrimaryLinkProperties);
                Assert.NotNull(afterDeleteSecondaryLinkProperties);
                Assert.Empty(afterDeleteSecondaryLinkProperties);

                // Clean up both caches and delete resource group
                _client.Redis.Delete(resourceGroupName: resourceGroupName, name: redisCacheName1);
                _client.Redis.Delete(resourceGroupName: resourceGroupName, name: redisCacheName2);
                _redisCacheManagementHelper.DeleteResourceGroup(resourceGroupName);
            }
        }