Skip to content

MaxMemoryPolicy should exists as deprecated parameter and throw proper exception when used #951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,12 @@ public void TestSetRedisCacheBugFixTest()
{
RunPowerShellTest("Test-SetRedisCacheBugFixTest");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestMaxMemoryPolicyErrorCheck()
{
RunPowerShellTest("Test-MaxMemoryPolicyErrorCheck");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,20 @@ function Test-SetRedisCacheBugFixTest
$cacheUpdated2 = Set-AzureRmRedisCache -ResourceGroupName $resourceGroupName -Name $cacheName -RedisConfiguration @{"maxmemory-policy" = "allkeys-lru"}
Assert-AreEqual "allkeys-lru" $cacheUpdated2.RedisConfiguration.Item("maxmemory-policy")
Assert-True { $cacheUpdated2.EnableNonSslPort }
}

<#
.SYNOPSIS
Tests MaxMemoryPolicy error check
#>
function Test-MaxMemoryPolicyErrorCheck
{
# Setup
# resource group should exists
$resourceGroupName = "DummyResourceGroup"
$cacheName = "dummycache"
$location = "North Central US"

# Updating Cache
Assert-ThrowsContains {New-AzureRMRedisCache -ResourceGroupName $resourceGroupName -Name $cacheName -Location $location -MaxMemoryPolicy AllKeysRandom} "The 'MaxMemoryPolicy' setting has been deprecated"
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace Microsoft.Azure.Commands.RedisCache
using SkuStrings = Microsoft.Azure.Management.Redis.Models.SkuName;
using Hyak.Common;
using System.Collections;
using System;

[Cmdlet(VerbsCommon.New, "AzureRmRedisCache"), OutputType(typeof(RedisCacheAttributesWithAccessKeys))]
public class NewAzureRedisCache : RedisCacheCmdletBase
Expand Down Expand Up @@ -50,6 +51,9 @@ public class NewAzureRedisCache : RedisCacheCmdletBase
[ValidateSet(SkuStrings.Basic, SkuStrings.Standard, IgnoreCase = false)]
public string Sku { get; set; }

[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false, HelpMessage = "MaxMemoryPolicy is deprecated. Please use RedisConfiguration instead.")]
public string MaxMemoryPolicy { get; set; }

[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false, HelpMessage = "A hash table which represents redis configuration properties.")]
public Hashtable RedisConfiguration { get; set; }

Expand All @@ -65,6 +69,11 @@ protected override void ProcessRecord()
WriteWarning("The RedisVersion parameter has been deprecated. As such, it is no longer necessary to provide this parameter and any value specified is ignored.");
}

if (!string.IsNullOrEmpty(MaxMemoryPolicy))
{
throw new ArgumentException(Resources.MaxMemoryPolicyException);
}

string skuFamily;

int skuCapacity = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
namespace Microsoft.Azure.Commands.RedisCache
{
using Microsoft.Azure.Commands.RedisCache.Models;
using Microsoft.Azure.Commands.RedisCache.Properties;
using Microsoft.Azure.Management.Redis.Models;
using System.Collections;
using System.Management.Automation;
using SkuStrings = Microsoft.Azure.Management.Redis.Models.SkuName;

using Hyak.Common;
using System;

[Cmdlet(VerbsCommon.Set, "AzureRmRedisCache", DefaultParameterSetName = MaxMemoryParameterSetName), OutputType(typeof(RedisCacheAttributesWithAccessKeys))]
public class SetAzureRedisCache : RedisCacheCmdletBase
{
Expand All @@ -42,6 +45,9 @@ public class SetAzureRedisCache : RedisCacheCmdletBase
[ValidateSet(SkuStrings.Basic, SkuStrings.Standard, IgnoreCase = false)]
public string Sku { get; set; }

[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false, HelpMessage = "MaxMemoryPolicy is deprecated. Please use RedisConfiguration instead.")]
public string MaxMemoryPolicy { get; set; }

[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false, HelpMessage = "A hash table which represents redis configuration properties.")]
public Hashtable RedisConfiguration { get; set; }

Expand All @@ -50,6 +56,11 @@ public class SetAzureRedisCache : RedisCacheCmdletBase

protected override void ProcessRecord()
{
if (!string.IsNullOrEmpty(MaxMemoryPolicy))
{
throw new ArgumentException(Resources.MaxMemoryPolicyException);
}

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

string skuName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="">
<maml:name>MaxMemoryPolicy</maml:name>
<maml:description>
<maml:para>The 'MaxMemoryPolicy' setting has been deprecated. Please use 'RedisConfiguration' setting to set MaxMemoryPolicy. e.g. -RedisConfiguration @{"maxmemory-policy" = "allkeys-lru"}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="">
<maml:name>RedisConfiguration</maml:name>
<maml:description>
Expand Down Expand Up @@ -408,6 +415,18 @@
</dev:type>
<dev:defaultValue>Standard</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="">
<maml:name>MaxMemoryPolicy</maml:name>
<maml:description>
<maml:para>The 'MaxMemoryPolicy' setting has been deprecated. Please use 'RedisConfiguration' setting to set MaxMemoryPolicy. e.g. -RedisConfiguration @{"maxmemory-policy" = "allkeys-lru"}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue></dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="">
<maml:name>RedisConfiguration</maml:name>
<maml:description>
Expand Down Expand Up @@ -1088,6 +1107,13 @@
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="">
<maml:name>MaxMemoryPolicy</maml:name>
<maml:description>
<maml:para>The 'MaxMemoryPolicy' setting has been deprecated. Please use 'RedisConfiguration' setting to set MaxMemoryPolicy. e.g. -RedisConfiguration @{"maxmemory-policy" = "allkeys-lru"}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="">
<maml:name>RedisConfiguration</maml:name>
<maml:description>
Expand Down Expand Up @@ -1155,6 +1181,18 @@
</dev:type>
<dev:defaultValue></dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="">
<maml:name>MaxMemoryPolicy</maml:name>
<maml:description>
<maml:para>The 'MaxMemoryPolicy' setting has been deprecated. Please use 'RedisConfiguration' setting to set MaxMemoryPolicy. e.g. -RedisConfiguration @{"maxmemory-policy" = "allkeys-lru"}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue></dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="">
<maml:name>RedisConfiguration</maml:name>
<maml:description>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="MaxMemoryPolicyException" xml:space="preserve">
<value>The 'MaxMemoryPolicy' setting has been deprecated. Please use 'RedisConfiguration' setting to set MaxMemoryPolicy. e.g. -RedisConfiguration @{"maxmemory-policy" = "allkeys-lru"}</value>
</data>
<data name="RedisCacheExists" xml:space="preserve">
<value>Redis cache with name '{0}' already exists.</value>
</data>
Expand Down