Skip to content

Commit

Permalink
[SQL] Check if DB is created by log replay before dropping it (#18409)
Browse files Browse the repository at this point in the history
* check if db created by log replay before dropping it

* Add test

* Bump err string

* Bump changelog
  • Loading branch information
ostojicb committed Jun 9, 2022
1 parent 0302f7c commit 386cc46
Show file tree
Hide file tree
Showing 7 changed files with 2,866 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,12 @@ public void TestPipingCompleteCancelManagedDatabaseLogReplayService()
{
RunPowerShellTest("Test-PipingCompleteCancelManagedDatabaseLogReplay");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestCancelManagedDatabaseLogReplayFailForWrongDatabase()
{
RunPowerShellTest("Test-CancelManagedDatabaseLogReplayFailForWrongDatabase");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,36 @@ function Test-PipingCompleteCancelManagedDatabaseLogReplay
}
}

<#
.SYNOPSIS
Tests Managed Database Log Replay cancel on a wrong database
#>
function Test-CancelManagedDatabaseLogReplayFailForWrongDatabase
{
# Setup
$rg = Create-ResourceGroupForTest
$managedInstance = Create-ManagedInstanceForTest $rg

$rgName = $rg.ResourceGroupName
$managedInstance = $managedInstance.ManagedInstanceName

try
{
# Start log replay
$managedDatabaseName = Get-ManagedDatabaseName
$db = New-AzSqlInstanceDatabase -ResourceGroupName $rgName -InstanceName $managedInstance -Name $managedDatabaseName

# Stop log replay on a DB that's not created with log replay should fail
Assert-ThrowsContains { $db | Stop-AzSqlInstanceDatabaseLogReplay -Force } "error"
$notDeletedDB = Get-AzSqlInstanceDatabase -ResourceGroupName $rgName -InstanceName $managedInstance -Name $managedDatabaseName
Assert-NotNull $notDeletedDB
}
finally
{
Remove-ResourceGroupForTest $rg
}
}

function Generate-SasToken ($rgname)
{
$key = Get-AzStorageAccountKey -ResourceGroupName $rgname -Name $stoname;
Expand Down
Loading

0 comments on commit 386cc46

Please sign in to comment.