-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Added spock test framework and tests for queue service #4940
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
Changes from 13 commits
e4e81fc
25a0bbc
444b658
f4bd47b
62bd946
7f70869
7453724
1c1679d
0a1c956
1d33562
e759060
a5bf306
cf22ae3
4534e8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| import com.azure.storage.queue.models.SignedIdentifier; | ||
| import com.azure.storage.queue.models.StorageErrorException; | ||
| import com.azure.storage.queue.models.UpdatedMessage; | ||
| import java.util.Objects; | ||
| import reactor.core.publisher.Flux; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
|
|
@@ -62,6 +63,7 @@ public final class QueueAsyncClient { | |
| * @param queueName Name of the queue | ||
| */ | ||
| QueueAsyncClient(AzureQueueStorageImpl client, String queueName) { | ||
| Objects.requireNonNull(queueName); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check should be in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the entries which asked the queueName will fall into this constructor.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While that is true, having it remain in each individually will offer a closer indication to what went wrong and in the case of the client builder it will early out much sooner. |
||
| this.queueName = queueName; | ||
|
|
||
| this.client = new AzureQueueStorageBuilder().pipeline(client.getHttpPipeline()) | ||
|
|
@@ -79,6 +81,7 @@ public final class QueueAsyncClient { | |
| * @param queueName Name of the queue | ||
| */ | ||
| QueueAsyncClient(URL endpoint, HttpPipeline httpPipeline, String queueName) { | ||
| Objects.requireNonNull(queueName); | ||
|
alzimmermsft marked this conversation as resolved.
|
||
| this.queueName = queueName; | ||
|
|
||
| this.client = new AzureQueueStorageBuilder().pipeline(httpPipeline) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.storage.queue.spock | ||
|
|
||
| import com.azure.core.test.InterceptorManager | ||
| import com.azure.core.test.TestMode | ||
| import com.azure.core.test.utils.TestResourceNamer | ||
| import com.azure.core.util.configuration.ConfigurationManager | ||
| import com.azure.core.util.logging.ClientLogger | ||
| import com.azure.storage.queue.QueueClientBuilder | ||
| import com.azure.storage.queue.QueueServiceClient | ||
| import com.azure.storage.queue.QueueServiceClientBuilder | ||
| import com.azure.storage.queue.models.QueuesSegmentOptions | ||
| import spock.lang.Specification | ||
|
|
||
| class APISpec extends Specification { | ||
| // Field common used for all APIs. | ||
| def logger = new ClientLogger(APISpec.class) | ||
| def AZURE_TEST_MODE = "AZURE_TEST_MODE" | ||
| def interceptorManager | ||
| def testResourceName | ||
|
|
||
| // Clients for API tests | ||
| def primaryQueueServiceClient | ||
| def primaryQueueServiceAsyncClient | ||
|
|
||
|
|
||
| // Test name for test method name. | ||
| def methodName | ||
| def testMode = getTestMode() | ||
| def connectionString = ConfigurationManager.getConfiguration().get("AZURE_STORAGE_QUEUE_CONNECTION_STRING") | ||
|
|
||
| /** | ||
| * Setup the QueueServiceClient and QueueClient common used for the API tests. | ||
| */ | ||
| def setup() { | ||
|
alzimmermsft marked this conversation as resolved.
|
||
| String testName = refactorName(specificationContext.currentIteration.getName()) | ||
| String className = specificationContext.getCurrentSpec().getName() | ||
| methodName = className + testName | ||
| logger.info("Test Mode: {}, Name: {}", testMode, methodName) | ||
| interceptorManager = new InterceptorManager(methodName, testMode) | ||
| testResourceName = new TestResourceNamer(methodName, testMode, | ||
| interceptorManager.getRecordedData()) | ||
| } | ||
|
|
||
| /** | ||
| * Clean up the test queues and messages for the account. | ||
| */ | ||
| def cleanup() { | ||
|
|
||
| interceptorManager.close() | ||
| if (getTestMode() == TestMode.RECORD) { | ||
| QueueServiceClient cleanupQueueServiceClient = new QueueServiceClientBuilder() | ||
| .connectionString(connectionString) | ||
| .buildClient() | ||
| cleanupQueueServiceClient.listQueues(new QueuesSegmentOptions().prefix(methodName.toLowerCase())).each { | ||
| queueItem -> cleanupQueueServiceClient.deleteQueue(queueItem.name()) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Test mode is initialized whenever test is executed. Helper method which is used to determine what to do under | ||
| * certain test mode. | ||
| * @return The TestMode: | ||
| * <ul> | ||
| * <li>Playback: (default if no test mode setup)</li> | ||
| * </ul> | ||
| */ | ||
| def getTestMode() { | ||
| def azureTestMode = ConfigurationManager.getConfiguration().get(AZURE_TEST_MODE) | ||
|
|
||
| if (azureTestMode != null) { | ||
| try { | ||
| return TestMode.valueOf(azureTestMode.toUpperCase(Locale.US)) | ||
| } catch (IllegalArgumentException e) { | ||
| logger.error("Could not parse '{}' into TestEnum. Using 'Playback' mode.", azureTestMode) | ||
| return TestMode.PLAYBACK | ||
| } | ||
| } | ||
|
|
||
| logger.info("Environment variable '{}' has not been set yet. Using 'Playback' mode.", AZURE_TEST_MODE) | ||
| return TestMode.PLAYBACK | ||
| } | ||
|
|
||
| def queueServiceBuilderHelper(final InterceptorManager interceptorManager) { | ||
| if (testMode == TestMode.RECORD) { | ||
| return new QueueServiceClientBuilder() | ||
| .connectionString(connectionString) | ||
| .addPolicy(interceptorManager.getRecordPolicy()) | ||
| } else { | ||
| return new QueueServiceClientBuilder() | ||
| .connectionString(connectionString) | ||
| .httpClient(interceptorManager.getPlaybackClient()) | ||
| } | ||
| } | ||
|
|
||
| def queueBuilderHelper(final InterceptorManager interceptorManager) { | ||
| def queueName = testResourceName.randomName("queue", 16) | ||
| if (testMode == TestMode.RECORD) { | ||
| return new QueueClientBuilder() | ||
| .connectionString(connectionString) | ||
| .queueName(queueName) | ||
| .addPolicy(interceptorManager.getRecordPolicy()) | ||
| } else { | ||
| return new QueueClientBuilder() | ||
| .connectionString(connectionString) | ||
| .queueName(queueName) | ||
| .httpClient(interceptorManager.getPlaybackClient()) | ||
| } | ||
| } | ||
|
|
||
| private def refactorName(String text) { | ||
| def fullName = text.split(" ").collect { it.capitalize() }.join("") | ||
| def matcher = (fullName =~ /(.*)(\[)(.*)(\])/) | ||
|
|
||
| if (!matcher.find()) { | ||
| return fullName | ||
| } | ||
| return matcher[0][1] + matcher[0][3] | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.