Skip to content

Support pagination for enumerating deleted items #26974

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

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 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 @@ -70,7 +70,7 @@ public void TestAdlsTrustedIdProvider()
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.AcceptanceType, Category.LiveOnly)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to remove the test cases?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#26974 (review) As mentioned here, passing the CustomDelegatingHAndler to adls client is not supported in the new .net sdk. Discussed this with @vidai-msft and marked the testcases as LiveOnly.

public void TestAdlsFileSystem()
{
var workingPath = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().Location).AbsolutePath);
Expand All @@ -79,7 +79,7 @@ public void TestAdlsFileSystem()
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.AcceptanceType, Category.LiveOnly)]
public void TestAdlsFileSystemPermissions()
{
TestRunner.RunTestScript($"Test-DataLakeStoreFileSystemPermissions -location '{TestFileSystemPermissionResourceGroupLocation}'");
Expand All @@ -93,7 +93,7 @@ public void TestNegativeAdlsAccount()
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.AcceptanceType, Category.LiveOnly)]
public void TestAdlsEnumerateAndRestoreDeletedItem()
{
TestRunner.RunTestScript($"Test-AdlsEnumerateAndRestoreDeletedItem -location '{ResourceGroupLocation}'");
Expand Down
16 changes: 12 additions & 4 deletions src/DataLakeStore/DataLakeStore.Test/ScenarioTests/AdlsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace Microsoft.Azure.Commands.DataLakeStore.Test.ScenarioTests

public class AdlsTests : DataLakeStoreTestRunner
{
private readonly string AccountName = "sss-datalakestore-test-c17";
private readonly string ResourceGroupLocation = "westus";
private readonly string TestFileSystemPermissionResourceGroupLocation = "ukwest";
private readonly string TestFileSystemResourceGroupLocation = "ukwest";
Expand Down Expand Up @@ -69,7 +70,7 @@ public void TestAdlsAccountTiers()
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.AcceptanceType, Category.LiveOnly)]
public void TestAdlsFileSystem()
{
var workingPath = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().Location).AbsolutePath);
Expand All @@ -78,7 +79,7 @@ public void TestAdlsFileSystem()
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.AcceptanceType, Category.LiveOnly)]
public void TestAdlsFileSystemPermissions()
{
TestRunner.RunTestScript($"Test-DataLakeStoreFileSystemPermissions -location '{TestFileSystemPermissionResourceGroupLocation}'");
Expand All @@ -92,10 +93,17 @@ public void TestNegativeAdlsAccount()
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.AcceptanceType, Category.LiveOnly)]
public void TestAdlsEnumerateDeletedItem()
{
TestRunner.RunTestScript($"Test-EnumerateDataLakeStoreDeletedItem -location '{ResourceGroupLocation}' -accountName '{AccountName}'");
}

[Fact]
[Trait(Category.AcceptanceType, Category.LiveOnly)]
public void TestAdlsEnumerateAndRestoreDeletedItem()
{
TestRunner.RunTestScript($"Test-EnumerateAndRestoreDataLakeStoreDeletedItem -location '{ResourceGroupLocation}'");
TestRunner.RunTestScript($"Test-EnumerateAndRestoreDataLakeStoreDeletedItem -location '{ResourceGroupLocation} '-accountName '{AccountName}'");
}
}
}
221 changes: 144 additions & 77 deletions src/DataLakeStore/DataLakeStore.Test/ScenarioTests/AdlsTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ function Test-DataLakeStoreFileSystem
Assert-True {Remove-AzDataLakeStoreItem -Account $accountName -paths $summaryFolder -force -recurse -passthru} "Remove folder failed"
Assert-Throws {Get-AzDataLakeStoreItem -Account $accountName -path $summaryFolder}
Assert-True {Remove-AzDataLakeStoreItem -Account $accountName -paths $encodingFolder -force -recurse -passthru} "Remove folder failed"
# Delete Data Lake account
Assert-True {Remove-AzDataLakeStoreAccount -ResourceGroupName $resourceGroupName -Name $accountName -Force -PassThru} "Remove Account failed."

Expand Down Expand Up @@ -760,7 +760,7 @@ function Test-DataLakeStoreFileSystemPermissions
$accountName = Get-DataLakeStoreAccountName
New-AzResourceGroup -Name $resourceGroupName -Location $location
$accountCreated = New-AzDataLakeStoreAccount -ResourceGroupName $resourceGroupName -Name $accountName -Location $location -DisableEncryption
Assert-AreEqual $accountName $accountCreated.Name
Assert-AreEqual $location $accountCreated.Location
Assert-AreEqual "Microsoft.DataLakeStore/accounts" $accountCreated.Type
Expand Down Expand Up @@ -1000,101 +1000,168 @@ function CreateAndGetVirtualNetwork ($resourceGroupName, $vnetName, $location =

<#
.SYNOPSIS
Tests DataLakeStore deleted items operations (Enumerate, Restore).
Helper function to create files and folders in DataLakeStore account.
#>
function Test-EnumerateAndRestoreDataLakeStoreDeletedItem
function Create-FilesAndFolders
{
param
param
(
[string]$accountName
)

$folderToCreate1 = "/adlTestDir1"
$folderToCreate2 = "/adlTestDir2"
$fileToCreate1 = "/adlTestDir1/adlfile1"
$fileToCreate2 = "/adlTestDir2/adlfile2"

$result = New-AzDataLakeStoreItem -Account $accountName -path $folderToCreate1 -Folder
Assert-NotNull $result "No value was returned on folder creation"

$result = New-AzDataLakeStoreItem -Account $accountName -path $folderToCreate2 -Folder
Assert-NotNull $result "No value was returned on folder creation"

$result = New-AzDataLakeStoreItem -Account $accountName -path $fileToCreate1
Assert-NotNull $result "No value was returned on empty file creation"

$result = New-AzDataLakeStoreItem -Account $accountName -path $fileToCreate2
Assert-NotNull $result "No value was returned on empty file creation"
}

<#
.SYNOPSIS
Helper function to delete files and folders in DataLakeStore account.
#>
function Delete-FilesAndFolders
{
param
(
[string]$accountName
)

$itemsToDelete = @(
"/adlTestDir1/adlfile1",
"/adlTestDir2/adlfile2",
"/adlTestDir1",
"/adlTestDir2"
)

foreach ($item in $itemsToDelete) {
if (Test-AzDataLakeStoreItem -Account $accountName -Path $item) {
Write-Host "Deleting item: $item"
Assert-True { Remove-AzDataLakeStoreItem -Account $accountName -Paths $item -Force -Passthru } "Remove item failed: $item"
} else {
Write-Host "Item does not exist: $item"
}
}
}

<#
.SYNOPSIS
Tests DataLakeStore deleted items operations (Enumerate).
#>
function Test-EnumerateDataLakeStoreDeletedItem
{
param
(
$fileToCopy,
$location
$location,
$accountName

)

if ([string]::IsNullOrEmpty($location))
{
$location = Get-Location -providerNamespace "Microsoft.CognitiveServices" -resourceType "accounts" -preferredLocation "West US";
}

try
{
# Creating Account
$resourceGroupName = Get-ResourceGroupName
$accountName = Get-DataLakeStoreAccountName + "-c12" # testing accountname validation
New-AzResourceGroup -Name $resourceGroupName -Location $location
$accountCreated = New-AzDataLakeStoreAccount -ResourceGroupName $resourceGroupName -Name $accountName -Location $location

Assert-AreEqual $accountName $accountCreated.Name
Assert-AreEqual $location $accountCreated.Location
Assert-AreEqual "Microsoft.DataLakeStore/accounts" $accountCreated.Type
Assert-True {$accountCreated.Id -like "*$resourceGroupName*"}
try
{
Create-FilesAndFolders -accountName $accountName
Delete-FilesAndFolders -accountName $accountName

# In loop to check if account exists
for ($i = 0; $i -le 60; $i++)
{
[array]$accountGet = Get-AzDataLakeStoreAccount -ResourceGroupName $resourceGroupName -Name $accountName
if ($accountGet[0].ProvisioningState -like "Succeeded")
{
Assert-AreEqual $accountName $accountGet[0].Name
Assert-AreEqual $location $accountGet[0].Location
Assert-AreEqual "Microsoft.DataLakeStore/accounts" $accountGet[0].Type
Assert-True {$accountGet[0].Id -like "*$resourceGroupName*"}
break
}
$out = Get-AzDataLakeStoreDeletedItem -Account $accountName -filter "adlTestDir1" -Count 2

if ($out.ContinuationToken -ne $null)
{
$out = Get-AzDataLakeStoreDeletedItem -Account $accountName -filter "adlTestDir1" -Count 2 -ListAfter $out.ContinuationToken
Assert-NotNull $out "Failed to get deleted items with continuation token"
}

$out = Get-AzDataLakeStoreDeletedItem -Account $accountName -filter "adlTestDir2" -Count 2
Assert-NotNull $out "No deleted items found for adlTestDir2"

if ($out.ContinuationToken -ne $null)
{
$out = Get-AzDataLakeStoreDeletedItem -Account $accountName -filter "adlTestDir2" -Count 2 -ListAfter $out.ContinuationToken
Assert-NotNull $out "Failed to get deleted items with continuation token"
}
}
finally
{
# Skip cleanup for existing account and resource group
Write-Host "Skipping cleanup for existing account and resource group."
}
}

Write-Host "account not yet provisioned. current state: $($accountGet[0].ProvisioningState)"
[Microsoft.WindowsAzure.Commands.Utilities.Common.TestMockSupport]::Delay(30000)
Assert-False {$i -eq 60} " Data Lake Store account is not in succeeded state even after 30 min."
}
function Restore-DeletedItems {
param (
[string]$accountName,
[array]$items
)

# define all the files and folders
$folderToCreate1 = "/adlfolderTest1"
$folderToCreate2 = "/adlfolderTest2"
$fileToCreate1 = "/adlfolderTest1/adlfile1"
$fileToCreate2 = "/adlfolderTest2/adlfile2"
foreach ($item in $items) {
if ([string]::IsNullOrEmpty($item.TrashDirPath) -or [string]::IsNullOrEmpty($item.OriginalPath)) {
continue
}

# Check if the destination already exists
$relativeOriginalPath = $item.OriginalPath -replace "^adl://[^/]+", ""
if (Test-AzDataLakeStoreItem -Account $accountName -Path $relativeOriginalPath) {
continue
}

# Attempt to restore the item
Assert-True {
Restore-AzDataLakeStoreDeletedItem -Account $accountName -Path $item.TrashDirPath -Destination $item.OriginalPath -Type $item.Type -Force -Passthru
}
}
}

# Create and get Empty folder
$result = New-AzDataLakeStoreItem -Account $accountName -path $folderToCreate1 -Folder
Assert-NotNull $result "No value was returned on folder creation"
<#
.SYNOPSIS
Tests DataLakeStore deleted items operations (Enumerate, Restore).
#>
function Test-EnumerateAndRestoreDataLakeStoreDeletedItem
{
param
(
$fileToCopy,
$location,
$accountName

$result = New-AzDataLakeStoreItem -Account $accountName -path $folderToCreate2 -Folder
Assert-NotNull $result "No value was returned on folder creation"

# Create and get Empty File
$result = New-AzDataLakeStoreItem -Account $accountName -path $fileToCreate1
Assert-NotNull $result "No value was returned on empty file creation"
$result = New-AzDataLakeStoreItem -Account $accountName -path $fileToCreate2
Assert-NotNull $result "No value was returned on empty file creation"

# delete a file
Assert-True {Remove-AzDataLakeStoreItem -Account $accountName -paths $fileToCreate1 -force -passthru } "Remove File Failed"
Assert-Throws {Get-AzDataLakeStoreItem -Account $accountName -path $fileToCreate1}
Assert-True {Remove-AzDataLakeStoreItem -Account $accountName -paths $fileToCreate2 -force -passthru } "Remove File Failed"
Assert-Throws {Get-AzDataLakeStoreItem -Account $accountName -path $fileToCreate2}

# search delete folder
$out = Get-AzDataLakeStoreDeletedItem -Account $accountName -filter "adlfolderTest1" -Count 1000
foreach($item in $out)
{
Restore-AzDataLakeStoreDeletedItem -Account $accountName -Path $item.TrashDirPath -Destination $item.OriginalPath -Type "file" -Force -Passthru
Assert-True { Restore-AzDataLakeStoreDeletedItem -Account $accountName -Path $item.TrashDirPath -Destination $item.OriginalPath -Type "file" -Force -Passthru}
}
)

$out = Get-AzDataLakeStoreDeletedItem -Account $accountName -filter "adlfolderTest2" -Count 1000
foreach($item in $out)
{
Assert-True { Restore-AzDataLakeStoreDeletedItem -Account $accountName $item -Force -Passthru}
}

# Delete Data Lake account
Assert-True {Remove-AzDataLakeStoreAccount -ResourceGroupName $resourceGroupName -Name $accountName -Force -PassThru} "Remove Account failed."
if ([string]::IsNullOrEmpty($location))
{
$location = Get-Location -providerNamespace "Microsoft.CognitiveServices" -resourceType "accounts" -preferredLocation "West US";
}

# Verify that it is gone by trying to get it again
Assert-Throws {Get-AzDataLakeStoreAccount -ResourceGroupName $resourceGroupName -Name $accountName}
try
{
Create-FilesAndFolders -accountName $accountName
Delete-FilesAndFolders -accountName $accountName

# search deleted folder
$out = Get-AzDataLakeStoreDeletedItem -Account $accountName -filter "adlTestDir1" -Count 1000
Restore-DeletedItems -accountName $accountName -items $out

$out = Get-AzDataLakeStoreDeletedItem -Account $accountName -filter "adlTestDir2" -Count 1000
Restore-DeletedItems -accountName $accountName -items $out
}
finally
{
# cleanup the resource group that was used in case it still exists. This is a best effort task, we ignore failures here.
Invoke-HandledCmdlet -Command {Remove-AzDataLakeStoreAccount -ResourceGroupName $resourceGroupName -Name $accountName -Force -ErrorAction SilentlyContinue} -IgnoreFailures
Invoke-HandledCmdlet -Command {Remove-AzResourceGroup -Name $resourceGroupName -Force -ErrorAction SilentlyContinue} -IgnoreFailures
Delete-FilesAndFolders -accountName $accountName
# Skip cleanup for existing account and resource group
Write-Host "Skipping cleanup for existing account and resource group."
}
}
Loading