Skip to content

Commit e2ba4d4

Browse files
committed
Merge pull request #951 from SiddharthChatrolaMs/dev
MaxMemoryPolicy should exists as deprecated parameter and throw proper exception when used
2 parents 3bec578 + 23b6bb7 commit e2ba4d4

File tree

7 files changed

+95
-2
lines changed

7 files changed

+95
-2
lines changed

src/ResourceManager/RedisCache/Commands.RedisCache.Test/ScenarioTests/RedisCacheTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,12 @@ public void TestSetRedisCacheBugFixTest()
4747
{
4848
RunPowerShellTest("Test-SetRedisCacheBugFixTest");
4949
}
50+
51+
[Fact]
52+
[Trait(Category.AcceptanceType, Category.CheckIn)]
53+
public void TestMaxMemoryPolicyErrorCheck()
54+
{
55+
RunPowerShellTest("Test-MaxMemoryPolicyErrorCheck");
56+
}
5057
}
5158
}

src/ResourceManager/RedisCache/Commands.RedisCache.Test/ScenarioTests/RedisCacheTests.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,20 @@ function Test-SetRedisCacheBugFixTest
258258
$cacheUpdated2 = Set-AzureRmRedisCache -ResourceGroupName $resourceGroupName -Name $cacheName -RedisConfiguration @{"maxmemory-policy" = "allkeys-lru"}
259259
Assert-AreEqual "allkeys-lru" $cacheUpdated2.RedisConfiguration.Item("maxmemory-policy")
260260
Assert-True { $cacheUpdated2.EnableNonSslPort }
261+
}
262+
263+
<#
264+
.SYNOPSIS
265+
Tests MaxMemoryPolicy error check
266+
#>
267+
function Test-MaxMemoryPolicyErrorCheck
268+
{
269+
# Setup
270+
# resource group should exists
271+
$resourceGroupName = "DummyResourceGroup"
272+
$cacheName = "dummycache"
273+
$location = "North Central US"
274+
275+
# Updating Cache
276+
Assert-ThrowsContains {New-AzureRMRedisCache -ResourceGroupName $resourceGroupName -Name $cacheName -Location $location -MaxMemoryPolicy AllKeysRandom} "The 'MaxMemoryPolicy' setting has been deprecated"
261277
}

src/ResourceManager/RedisCache/Commands.RedisCache/Commands/NewAzureRedisCache.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace Microsoft.Azure.Commands.RedisCache
2222
using SkuStrings = Microsoft.Azure.Management.Redis.Models.SkuName;
2323
using Hyak.Common;
2424
using System.Collections;
25+
using System;
2526

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

54+
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false, HelpMessage = "MaxMemoryPolicy is deprecated. Please use RedisConfiguration instead.")]
55+
public string MaxMemoryPolicy { get; set; }
56+
5357
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false, HelpMessage = "A hash table which represents redis configuration properties.")]
5458
public Hashtable RedisConfiguration { get; set; }
5559

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

72+
if (!string.IsNullOrEmpty(MaxMemoryPolicy))
73+
{
74+
throw new ArgumentException(Resources.MaxMemoryPolicyException);
75+
}
76+
6877
string skuFamily;
6978

7079
int skuCapacity = 1;

src/ResourceManager/RedisCache/Commands.RedisCache/Commands/SetAzureRedisCache.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
namespace Microsoft.Azure.Commands.RedisCache
1616
{
1717
using Microsoft.Azure.Commands.RedisCache.Models;
18+
using Microsoft.Azure.Commands.RedisCache.Properties;
1819
using Microsoft.Azure.Management.Redis.Models;
1920
using System.Collections;
2021
using System.Management.Automation;
2122
using SkuStrings = Microsoft.Azure.Management.Redis.Models.SkuName;
22-
23+
using Hyak.Common;
24+
using System;
25+
2326
[Cmdlet(VerbsCommon.Set, "AzureRmRedisCache", DefaultParameterSetName = MaxMemoryParameterSetName), OutputType(typeof(RedisCacheAttributesWithAccessKeys))]
2427
public class SetAzureRedisCache : RedisCacheCmdletBase
2528
{
@@ -42,6 +45,9 @@ public class SetAzureRedisCache : RedisCacheCmdletBase
4245
[ValidateSet(SkuStrings.Basic, SkuStrings.Standard, IgnoreCase = false)]
4346
public string Sku { get; set; }
4447

48+
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false, HelpMessage = "MaxMemoryPolicy is deprecated. Please use RedisConfiguration instead.")]
49+
public string MaxMemoryPolicy { get; set; }
50+
4551
[Parameter(ValueFromPipelineByPropertyName = true, Mandatory = false, HelpMessage = "A hash table which represents redis configuration properties.")]
4652
public Hashtable RedisConfiguration { get; set; }
4753

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

5157
protected override void ProcessRecord()
5258
{
59+
if (!string.IsNullOrEmpty(MaxMemoryPolicy))
60+
{
61+
throw new ArgumentException(Resources.MaxMemoryPolicyException);
62+
}
63+
5364
RedisGetResponse response = CacheClient.GetCache(ResourceGroupName, Name);
5465

5566
string skuName;

src/ResourceManager/RedisCache/Commands.RedisCache/Microsoft.Azure.Commands.RedisCache.dll-Help.xml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,13 @@
316316
</maml:description>
317317
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
318318
</command:parameter>
319+
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="">
320+
<maml:name>MaxMemoryPolicy</maml:name>
321+
<maml:description>
322+
<maml:para>The 'MaxMemoryPolicy' setting has been deprecated. Please use 'RedisConfiguration' setting to set MaxMemoryPolicy. e.g. -RedisConfiguration @{"maxmemory-policy" = "allkeys-lru"}</maml:para>
323+
</maml:description>
324+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
325+
</command:parameter>
319326
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="">
320327
<maml:name>RedisConfiguration</maml:name>
321328
<maml:description>
@@ -408,6 +415,18 @@
408415
</dev:type>
409416
<dev:defaultValue>Standard</dev:defaultValue>
410417
</command:parameter>
418+
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="">
419+
<maml:name>MaxMemoryPolicy</maml:name>
420+
<maml:description>
421+
<maml:para>The 'MaxMemoryPolicy' setting has been deprecated. Please use 'RedisConfiguration' setting to set MaxMemoryPolicy. e.g. -RedisConfiguration @{"maxmemory-policy" = "allkeys-lru"}</maml:para>
422+
</maml:description>
423+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
424+
<dev:type>
425+
<maml:name>String</maml:name>
426+
<maml:uri />
427+
</dev:type>
428+
<dev:defaultValue></dev:defaultValue>
429+
</command:parameter>
411430
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="">
412431
<maml:name>RedisConfiguration</maml:name>
413432
<maml:description>
@@ -1088,6 +1107,13 @@
10881107
</maml:description>
10891108
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
10901109
</command:parameter>
1110+
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="">
1111+
<maml:name>MaxMemoryPolicy</maml:name>
1112+
<maml:description>
1113+
<maml:para>The 'MaxMemoryPolicy' setting has been deprecated. Please use 'RedisConfiguration' setting to set MaxMemoryPolicy. e.g. -RedisConfiguration @{"maxmemory-policy" = "allkeys-lru"}</maml:para>
1114+
</maml:description>
1115+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
1116+
</command:parameter>
10911117
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="">
10921118
<maml:name>RedisConfiguration</maml:name>
10931119
<maml:description>
@@ -1155,6 +1181,18 @@
11551181
</dev:type>
11561182
<dev:defaultValue></dev:defaultValue>
11571183
</command:parameter>
1184+
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="">
1185+
<maml:name>MaxMemoryPolicy</maml:name>
1186+
<maml:description>
1187+
<maml:para>The 'MaxMemoryPolicy' setting has been deprecated. Please use 'RedisConfiguration' setting to set MaxMemoryPolicy. e.g. -RedisConfiguration @{"maxmemory-policy" = "allkeys-lru"}</maml:para>
1188+
</maml:description>
1189+
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
1190+
<dev:type>
1191+
<maml:name>String</maml:name>
1192+
<maml:uri />
1193+
</dev:type>
1194+
<dev:defaultValue></dev:defaultValue>
1195+
</command:parameter>
11581196
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="">
11591197
<maml:name>RedisConfiguration</maml:name>
11601198
<maml:description>

src/ResourceManager/RedisCache/Commands.RedisCache/Properties/Resources.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/RedisCache/Commands.RedisCache/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@
117117
<resheader name="writer">
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120+
<data name="MaxMemoryPolicyException" xml:space="preserve">
121+
<value>The 'MaxMemoryPolicy' setting has been deprecated. Please use 'RedisConfiguration' setting to set MaxMemoryPolicy. e.g. -RedisConfiguration @{"maxmemory-policy" = "allkeys-lru"}</value>
122+
</data>
120123
<data name="RedisCacheExists" xml:space="preserve">
121124
<value>Redis cache with name '{0}' already exists.</value>
122125
</data>

0 commit comments

Comments
 (0)