Skip to content

Changes to support "ReplicasPerMaster" and "Instances" #10659

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
Dec 8, 2019
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
2 changes: 1 addition & 1 deletion src/RedisCache/RedisCache.Test/RedisCache.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Insights" Version="0.16.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Redis" Version="5.0.0" />
<PackageReference Include="Microsoft.Azure.Management.Redis" Version="6.0.0-preview.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,12 @@ public void TestZones()
{
RedisCacheController.NewInstance.RunPowerShellTest(_logger, "Test-Zones");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestZoneRedundancy()
{
RedisCacheController.NewInstance.RunPowerShellTest(_logger, "Test-ZoneRedundancy");
}
}
}
154 changes: 154 additions & 0 deletions src/RedisCache/RedisCache.Test/ScenarioTests/RedisCacheTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ function Test-RedisCache

Assert-NotNull $cacheCreated.PrimaryKey "PrimaryKey do not exists"
Assert-NotNull $cacheCreated.SecondaryKey "SecondaryKey do not exists"

Assert-AreEqual 2 $cacheCreated.Instances.Count
for($i = 0; $i -lt $cacheCreated.Instances.Count; $i++)
{
Assert-AreEqual (15000+$i) $cacheCreated.Instances[$i].SslPort
Assert-Null $cacheCreated.Instances[$i].NonSslPort
Assert-Null $cacheCreated.Instances[$i].ShardId
Assert-Null $cacheCreated.Instances[$i].Zone
}

# In loop to check if cache exists
for ($i = 0; $i -le 60; $i++)
Expand Down Expand Up @@ -57,6 +66,15 @@ function Test-RedisCache
Assert-NotNull $cacheUpdated.PrimaryKey "PrimaryKey do not exists"
Assert-NotNull $cacheUpdated.SecondaryKey "SecondaryKey do not exists"

Assert-AreEqual 2 $cacheUpdated.Instances.Count
for($i = 0; $i -lt $cacheUpdated.Instances.Count; $i++)
{
Assert-AreEqual (15000+$i) $cacheUpdated.Instances[$i].SslPort
Assert-AreEqual (13000+$i) $cacheUpdated.Instances[$i].NonSslPort
Assert-Null $cacheUpdated.Instances[$i].ShardId
Assert-Null $cacheUpdated.Instances[$i].Zone
}

# List all cache in resource group
$cachesInResourceGroup = Get-AzRedisCache -ResourceGroupName $resourceGroupName
Assert-True {$cachesInResourceGroup.Count -ge 1}
Expand Down Expand Up @@ -87,6 +105,14 @@ function Test-RedisCache
$found = 1
Assert-AreEqual $location $cachesInSubscription[$i].Location
Assert-AreEqual $resourceGroupName $cachesInSubscription[$i].ResourceGroupName
Assert-AreEqual 2 $cachesInSubscription[$i].Instances.Count
for($j = 0; $j -lt $cachesInSubscription[$i].Instances.Count; $j++)
{
Assert-AreEqual (15000+$j) $cachesInSubscription[$i].Instances[$j].SslPort
Assert-AreEqual (13000+$j) $cachesInSubscription[$i].Instances[$j].NonSslPort
Assert-Null $cachesInSubscription[$i].Instances[$j].ShardId
Assert-Null $cachesInSubscription[$i].Instances[$j].Zone
}
break
}
}
Expand Down Expand Up @@ -231,6 +257,16 @@ function Test-RedisCacheClustering

Assert-NotNull $cacheCreated.PrimaryKey "PrimaryKey do not exists"
Assert-NotNull $cacheCreated.SecondaryKey "SecondaryKey do not exists"

Assert-AreEqual ($cacheCreated.ShardCount*2) $cacheCreated.Instances.Count

for($i = 0; $i -lt $cacheCreated.Instances.Count; $i++)
{
Assert-AreEqual (15000+$i) $cacheCreated.Instances[$i].SslPort
Assert-Null $cacheCreated.Instances[$i].NonSslPort
# ShardId check should be added here in future
Assert-Null $cacheCreated.Instances[$i].Zone
}

# In loop to check if cache exists
for ($i = 0; $i -le 60; $i++)
Expand Down Expand Up @@ -863,6 +899,124 @@ function Test-Zones
Remove-AzResourceGroup -Name $resourceGroupName -Force
}

function Test-ZoneRedundancy
{
# Setup
$resourceGroupName = "PowerShellTest-10"
$cacheName = "redisteam010"
$location = Get-Location -providerNamespace "Microsoft.Cache" -resourceType "redis" -preferredLocation "Central US"
$zones = @("1","2")
$replicasPerMaster = 2

# Create resource group
New-AzResourceGroup -Name $resourceGroupName -Location $location

# Creating Cache
$cacheCreated = New-AzRedisCache -ResourceGroupName $resourceGroupName -Name $cacheName -Location $location -Size P1 -Sku Premium -ReplicasPerMaster $replicasPerMaster -Zone $zones

Assert-AreEqual $cacheName $cacheCreated.Name
Assert-AreEqual $location $cacheCreated.Location
Assert-AreEqual "Microsoft.Cache/Redis" $cacheCreated.Type
Assert-AreEqual $resourceGroupName $cacheCreated.ResourceGroupName
Assert-AreEqual 6379 $cacheCreated.Port
Assert-AreEqual 6380 $cacheCreated.SslPort
Assert-AreEqual "creating" $cacheCreated.ProvisioningState
Assert-AreEqual "6GB" $cacheCreated.Size
Assert-AreEqual "Premium" $cacheCreated.Sku

Assert-NotNull $cacheCreated.PrimaryKey "PrimaryKey do not exists"
Assert-NotNull $cacheCreated.SecondaryKey "SecondaryKey do not exists"

Assert-AreEqual $replicasPerMaster $cacheCreated.ReplicasPerMaster
Assert-AreEqual $zones[0] $cacheCreated.Zone[0]
Assert-AreEqual $zones[1] $cacheCreated.Zone[1]
Assert-AreEqual ($replicasPerMaster+1) $cacheCreated.Instances.Count

for($i = 0; $i -lt $cacheCreated.Instances.Count; $i++)
{
Assert-AreEqual (15000+$i) $cacheCreated.Instances[$i].SslPort
Assert-Null $cacheCreated.Instances[$i].NonSslPort
Assert-Null $cacheCreated.Instances[$i].ShardId
#Zone will be NULL initially and should be available post cache provisioing succeeds
Assert-Null $cacheCreated.Instances[$i].Zone
}

# In loop to check if cache exists
for ($i = 0; $i -le 60; $i++)
{
Start-TestSleep 30000
$cacheGet = Get-AzRedisCache -ResourceGroupName $resourceGroupName -Name $cacheName
if ([string]::Compare("succeeded", $cacheGet[0].ProvisioningState, $True) -eq 0)
{
Assert-AreEqual $cacheName $cacheGet[0].Name
Assert-AreEqual "succeeded" $cacheGet[0].ProvisioningState
break
}
Assert-False {$i -eq 60} "Cache is not in succeeded state even after 30 min."
}

# Updating Cache
$cacheUpdated = Set-AzRedisCache -Name $cacheName -EnableNonSslPort $true -MinimumTlsVersion 1.2

$replicasPerMaster = 2
Assert-AreEqual $cacheName $cacheUpdated.Name
Assert-AreEqual 6379 $cacheUpdated.Port
Assert-AreEqual 6380 $cacheUpdated.SslPort
Assert-AreEqual "succeeded" $cacheUpdated.ProvisioningState
Assert-True { $cacheUpdated.EnableNonSslPort }

Assert-NotNull $cacheUpdated.PrimaryKey "PrimaryKey do not exists"
Assert-NotNull $cacheUpdated.SecondaryKey "SecondaryKey do not exists"

Assert-AreEqual $replicasPerMaster $cacheUpdated.ReplicasPerMaster
Assert-AreEqual $zones[0] $cacheUpdated.Zone[0]
Assert-AreEqual $zones[1] $cacheUpdated.Zone[1]
Assert-AreEqual ($replicasPerMaster+1) $cacheUpdated.Instances.Count

for($i = 0; $i -lt $cacheUpdated.Instances.Count; $i++)
{
Assert-AreEqual (15000+$i) $cacheUpdated.Instances[$i].SslPort
Assert-AreEqual (13000+$i) $cacheUpdated.Instances[$i].NonSslPort
Assert-Null $cacheUpdated.Instances[$i].ShardId
Assert-NotNull $cacheUpdated.Instances[$i].Zone
}

# List all cache in resource group
$cachesInResourceGroup = Get-AzRedisCache -ResourceGroupName $resourceGroupName
Assert-True {$cachesInResourceGroup.Count -ge 1}

$found = 0
for ($i = 0; $i -lt $cachesInResourceGroup.Count; $i++)
{
if ($cachesInResourceGroup[$i].Name -eq $cacheName)
{
$found = 1
Assert-AreEqual $location $cachesInResourceGroup[$i].Location
Assert-AreEqual $resourceGroupName $cachesInResourceGroup[$i].ResourceGroupName
Assert-AreEqual $replicasPerMaster $cachesInResourceGroup[$i].ReplicasPerMaster
Assert-AreEqual $zones[0] $cachesInResourceGroup[$i].Zone[0]
Assert-AreEqual $zones[1] $cachesInResourceGroup[$i].Zone[1]
Assert-AreEqual ($replicasPerMaster+1) $cachesInResourceGroup[$i].Instances.Count

for($j = 0; $j -lt $cachesInResourceGroup[$j].Instances.Count; $j++)
{
Assert-AreEqual (15000+$j) $cachesInResourceGroup[$i].Instances[$j].SslPort
Assert-AreEqual (13000+$j) $cachesInResourceGroup[$i].Instances[$j].NonSslPort
Assert-Null $cachesInResourceGroup[$i].Instances[$j].ShardId
Assert-NotNull $cachesInResourceGroup[$i].Instances[$j].Zone
}
break
}
}
Assert-True {$found -eq 1} "Cache created earlier is not found."

# Delete cache
Assert-True {Remove-AzRedisCache -ResourceGroupName $resourceGroupName -Name $cacheName -Force -PassThru} "Remove cache failed."

# Delete resource group
Remove-AzResourceGroup -Name $resourceGroupName -Force
}


<#
.SYNOPSIS
Expand Down
Loading