コード例 #1
0
        public RedisCacheAttributesWithAccessKeys(RedisResourceWithAccessKey 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;

            PrimaryKey        = cache.AccessKeys.PrimaryKey;
            SecondaryKey      = cache.AccessKeys.SecondaryKey;
            ResourceGroupName = resourceGroupName;

            VirtualNetwork = cache.VirtualNetwork;
            Subnet         = cache.Subnet;
            StaticIP       = cache.StaticIP;
            TenantSettings = cache.TenantSettings;
            ShardCount     = cache.ShardCount;
        }
コード例 #2
0
        public void TryCreatingCache(string resourceGroupName, string cacheName, string location)
        {
            var redisClient = RedisCacheManagementTestUtilities.GetRedisManagementClient(_testBase, _context);
            RedisResourceWithAccessKey createResponse = redisClient.Redis.CreateOrUpdate(resourceGroupName: resourceGroupName, name: cacheName,
                                                                                         parameters: new RedisCreateOrUpdateParameters
            {
                Location     = location,
                RedisVersion = "2.8",
                Sku          = new 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.");
            }
        }
コード例 #3
0
        public void CreateOrUpdate_EmptyJSONFromCSM()
        {
            string responseString               = (@"{}");
            RedisManagementClient      client   = Utility.GetRedisManagementClient(responseString, null, HttpStatusCode.OK);
            RedisResourceWithAccessKey response = client.Redis.CreateOrUpdate(resourceGroupName: "resource-group", name: "cachename",
                                                                              parameters: new RedisCreateOrUpdateParameters
            {
                Location     = "North Europe",
                RedisVersion = "2.8",
                Sku          = new Sku()
                {
                    Name     = SkuName.Basic,
                    Family   = SkuFamily.C,
                    Capacity = 1
                }
            });

            Assert.Null(response.Id);
            Assert.Null(response.Location);
            Assert.Null(response.Name);
            Assert.Null(response.Type);
        }
コード例 #4
0
        public void CreateOrUpdate_BasicWithTagsAndConfig()
        {
            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"" : ""creating"",
		            ""sku"": {
                            ""name"": ""Basic"",
                            ""family"": ""C"",
                            ""capacity"": 1
                        },
		            ""redisVersion"" : ""2.8"",
                    ""redisConfiguration"": {""maxmemory-policy"": ""allkeys-lru""},
		            ""accessKeys"" : {
			            ""primaryKey"" : ""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa="",
			            ""secondaryKey"" : ""bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb=""
		            },
		            ""hostName"" : ""hydraradiscache.cache.icbbvt.windows-int.net"",
		            ""port"" : 6379,
		            ""sslPort"" : 6380
	            }
            }
            ");

            string requestIdHeader = "0d33aff8-8a4e-4565-b893-a10e52260de0";

            RedisManagementClient      client   = Utility.GetRedisManagementClient(responseString, requestIdHeader, HttpStatusCode.Created);
            RedisResourceWithAccessKey response = client.Redis.CreateOrUpdate(resourceGroupName: "resource-group", name: "cachename",
                                                                              parameters: new RedisCreateOrUpdateParameters
            {
                Location     = "North Europe",
                RedisVersion = "2.8",
                Sku          = new Sku()
                {
                    Name     = SkuName.Basic,
                    Family   = SkuFamily.C,
                    Capacity = 1
                },
                RedisConfiguration = new Dictionary <string, string>()
                {
                    { "maxmemory-policy", "allkeys-lru" }
                }
            });

            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("creating", 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.NotNull(response.AccessKeys);
            Assert.Equal("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa=", response.AccessKeys.PrimaryKey);
            Assert.Equal("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb=", response.AccessKeys.SecondaryKey);

            Assert.Equal("hydraradiscache.cache.icbbvt.windows-int.net", response.HostName);
            Assert.Equal(6379, response.Port);
            Assert.Equal(6380, response.SslPort);
        }
コード例 #5
0
        public RedisResourceWithAccessKey CreateOrUpdateCache(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");
            RedisCreateOrUpdateParameters parameters = new RedisCreateOrUpdateParameters
            {
                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;
            }

            RedisResourceWithAccessKey response = _client.Redis.CreateOrUpdate(resourceGroupName: resourceGroupName, name: cacheName, parameters: parameters);

            return(response);
        }
コード例 #6
0
        public void CreateUpdateDeleteTest()
        {
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                var _client = RedisCacheManagementTestUtilities.GetRedisManagementClient(this, context);

                RedisResourceWithAccessKey responseCreate = _client.Redis.CreateOrUpdate(resourceGroupName: fixture.ResourceGroupName, name: fixture.RedisCacheName,
                                                                                         parameters: new RedisCreateOrUpdateParameters
                {
                    Location = fixture.Location,
                    Sku      = new Sku()
                    {
                        Name     = SkuName.Basic,
                        Family   = SkuFamily.C,
                        Capacity = 0
                    }
                });

                Assert.Contains(fixture.RedisCacheName, responseCreate.Id);
                Assert.Equal(fixture.Location, responseCreate.Location);
                Assert.Equal(fixture.RedisCacheName, responseCreate.Name);
                Assert.Equal("Microsoft.Cache/Redis", responseCreate.Type);

                Assert.True("creating".Equals(responseCreate.ProvisioningState, StringComparison.OrdinalIgnoreCase));
                Assert.Equal(SkuName.Basic, responseCreate.Sku.Name);
                Assert.Equal(SkuFamily.C, responseCreate.Sku.Family);
                Assert.Equal(0, responseCreate.Sku.Capacity);

                Assert.Contains(fixture.RedisCacheName, responseCreate.HostName);
                Assert.Equal(6379, responseCreate.Port);
                Assert.Equal(6380, responseCreate.SslPort);
                Assert.False(responseCreate.EnableNonSslPort);

                // 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 = _client.Redis.Get(resourceGroupName: fixture.ResourceGroupName, name: fixture.RedisCacheName);
                    if ("succeeded".Equals(responseGet.ProvisioningState, StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                    Assert.False(i == 60, "Cache is not in succeeded state even after 30 min.");
                }

                RedisResourceWithAccessKey responseUpdate = _client.Redis.CreateOrUpdate(resourceGroupName: fixture.ResourceGroupName, name: fixture.RedisCacheName,
                                                                                         parameters: new RedisCreateOrUpdateParameters
                {
                    Location = fixture.Location,
                    Sku      = new Sku()
                    {
                        Name     = SkuName.Basic,
                        Family   = SkuFamily.C,
                        Capacity = 0
                    },
                    RedisConfiguration = new Dictionary <string, string>()
                    {
                        { "maxmemory-policy", "allkeys-lru" }
                    },
                    EnableNonSslPort = true
                });

                Assert.Contains(fixture.RedisCacheName, responseUpdate.Id);
                Assert.Equal(fixture.Location, responseUpdate.Location);
                Assert.Equal(fixture.RedisCacheName, responseUpdate.Name);
                Assert.Equal("Microsoft.Cache/Redis", responseUpdate.Type);

                Assert.Equal(SkuName.Basic, responseUpdate.Sku.Name);
                Assert.Equal(SkuFamily.C, responseUpdate.Sku.Family);
                Assert.Equal(0, responseUpdate.Sku.Capacity);
                Assert.Equal("allkeys-lru", responseUpdate.RedisConfiguration["maxmemory-policy"]);

                Assert.Contains(fixture.RedisCacheName, responseUpdate.HostName);
                Assert.Equal(6379, responseUpdate.Port);
                Assert.Equal(6380, responseUpdate.SslPort);
                Assert.True(responseUpdate.EnableNonSslPort);

                _client.Redis.Delete(resourceGroupName: fixture.ResourceGroupName, name: fixture.RedisCacheName);
            }
        }