diff --git a/sdk/search/azure-search/src/test/java/com/azure/search/SearchServiceTestBase.java b/sdk/search/azure-search/src/test/java/com/azure/search/SearchServiceTestBase.java index c9885593952cf..82064398f30e5 100644 --- a/sdk/search/azure-search/src/test/java/com/azure/search/SearchServiceTestBase.java +++ b/sdk/search/azure-search/src/test/java/com/azure/search/SearchServiceTestBase.java @@ -113,11 +113,14 @@ public abstract class SearchServiceTestBase extends TestBase { @BeforeAll public static void beforeAll() { initializeAzureResources(); + if (!playbackMode()) { + azureSearchResources.initialize(); + azureSearchResources.createResourceGroup(); + } } @AfterAll public static void afterAll() { - azureSearchResources.deleteResourceGroup(); } @Override @@ -125,8 +128,6 @@ protected void beforeTest() { searchDnsSuffix = testEnvironment.equals("DOGFOOD") ? DOGFOOD_DNS_SUFFIX : DEFAULT_DNS_SUFFIX; if (!interceptorManager.isPlaybackMode()) { - azureSearchResources.initialize(); - azureSearchResources.createResourceGroup(testResourceNamer); azureSearchResources.createService(testResourceNamer); searchApiKeyCredential = new SearchApiKeyCredential(azureSearchResources.getSearchAdminKey()); } @@ -640,6 +641,10 @@ static boolean liveMode() { return setupTestMode() == TestMode.LIVE; } + static boolean playbackMode() { + return setupTestMode() == TestMode.PLAYBACK; + } + static TestMode setupTestMode() { String testMode = Configuration.getGlobalConfiguration().get(AZURE_TEST_MODE); diff --git a/sdk/search/azure-search/src/test/java/com/azure/search/test/environment/setup/AzureSearchResources.java b/sdk/search/azure-search/src/test/java/com/azure/search/test/environment/setup/AzureSearchResources.java index 90b9e81e20386..4cab54daee6b2 100644 --- a/sdk/search/azure-search/src/test/java/com/azure/search/test/environment/setup/AzureSearchResources.java +++ b/sdk/search/azure-search/src/test/java/com/azure/search/test/environment/setup/AzureSearchResources.java @@ -4,6 +4,7 @@ package com.azure.search.test.environment.setup; import com.azure.core.test.utils.TestResourceNamer; +import com.azure.core.util.Configuration; import com.azure.core.util.CoreUtils; import com.azure.storage.blob.BlobServiceClient; import com.azure.storage.blob.BlobServiceClientBuilder; @@ -22,6 +23,7 @@ public class AzureSearchResources { private static final String SEARCH_SERVICE_NAME_PREFIX = "azs-sdk"; private static final String BLOB_DATASOURCE_NAME_PREFIX = "azsblob"; private static final String STORAGE_NAME_PREFIX = "azsstor"; + private static final String AZURE_RESOURCEGROUP_NAME = "AZURE_RESOURCEGROUP_NAME"; private String searchServiceName; @@ -32,7 +34,7 @@ public class AzureSearchResources { private Region location; private Azure azure = null; - private ResourceGroup resourceGroup = null; + private static ResourceGroup resourceGroup; private SearchService searchService = null; /** @@ -113,9 +115,13 @@ public void deleteService() { /** * Creates the Resource Group in Azure. This should be run at @BeforeAll */ - public void createResourceGroup(TestResourceNamer testResourceNamer) { - if (resourceGroup == null) { - String resourceGroupName = testResourceNamer.randomName(RESOURCE_GROUP_NAME_PREFIX, 24); + public void createResourceGroup() { + String resourceGroupName = Configuration.getGlobalConfiguration().get(AZURE_RESOURCEGROUP_NAME); + if (azure.resourceGroups().checkExistence(resourceGroupName)) { + System.out.println("Fetching Resource Group: " + resourceGroupName); + resourceGroup = azure.resourceGroups() + .getByName(resourceGroupName); + } else { System.out.println("Creating Resource Group: " + resourceGroupName); resourceGroup = azure.resourceGroups() .define(resourceGroupName) diff --git a/sdk/search/test-resources.json b/sdk/search/test-resources.json new file mode 100644 index 0000000000000..772c0f3c993f1 --- /dev/null +++ b/sdk/search/test-resources.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": {}, + "variables": {}, + "resources": [], + "outputs": {} +}