|
12 | 12 | import java.util.Locale; |
13 | 13 | import java.util.Map; |
14 | 14 | import java.util.concurrent.TimeoutException; |
| 15 | +import java.util.function.Function; |
15 | 16 | import java.util.function.Predicate; |
16 | 17 | import org.apache.http.entity.ContentType; |
17 | 18 | import org.apache.jorphan.collections.HashTree; |
@@ -392,31 +393,32 @@ private void awaitProvisionedResourceGroup(ResourceGroup group) |
392 | 393 | throws IOException, InterruptedException, TimeoutException { |
393 | 394 | awaitStatus(group, () -> apiClient.findResourceGroup(group.getName(), group.getSubscription()), |
394 | 395 | ResourceGroup::isPendingProvisioning, ResourceGroup::isProvisioned, PROVISIONING_TIMEOUT, |
395 | | - "resource group provisioning", "Azure usage"); |
| 396 | + "resource group provisioning", "Azure usage", null); |
396 | 397 | } |
397 | 398 |
|
398 | 399 | private <T> void awaitStatus(T entity, EntityProvider<T> entityProvider, |
399 | 400 | Predicate<T> checkIntermediateStatus, Predicate<T> checkSuccessStatus, Duration timeout, |
400 | | - String waitName, String detailsName) |
| 401 | + String waitName, String detailsName, Function<T, String> failureDetailExtractor) |
401 | 402 | throws InterruptedException, TimeoutException, IOException { |
402 | 403 | if (checkSuccessStatus.test(entity)) { |
403 | 404 | return; |
404 | 405 | } |
405 | | - LOG.info("Waiting for " + waitName + "... "); |
| 406 | + LOG.info("Waiting for {}... ", waitName); |
406 | 407 | Instant start = Instant.now(); |
407 | 408 | while (!hasTimedOut(timeout, start) && checkIntermediateStatus.test(entity)) { |
408 | 409 | Thread.sleep(STATUS_POLL_PERIOD.toMillis()); |
409 | 410 | entity = entityProvider.get(); |
410 | 411 | } |
411 | 412 | if (checkIntermediateStatus.test(entity)) { |
412 | | - throw new TimeoutException( |
413 | | - "Timeout while waiting for " + waitName + " after " + prettyDuration(timeout) |
414 | | - + ". You may try executing again, or create an issue in jmeter-java-dsl GitHub " |
415 | | - + "repository with " + detailsName + " details."); |
| 413 | + throw new TimeoutException(String.format("Timeout while waiting for %s after %s. " |
| 414 | + + "You may try executing again, or create an issue in jmeter-java-dsl GitHub repository " |
| 415 | + + "with %s details.", waitName, prettyDuration(timeout), detailsName)); |
416 | 416 | } else if (!checkSuccessStatus.test(entity)) { |
417 | | - throw new IllegalArgumentException( |
418 | | - firstLetterToUpper(waitName) + " failed. Create an issue in jmeter-java-dsl GitHub " |
419 | | - + "repository with " + detailsName + " details."); |
| 417 | + throw new IllegalArgumentException(String.format("%s failed%s. " |
| 418 | + + "Create an issue in jmeter-java-dsl GitHub repository with %s details.", |
| 419 | + firstLetterToUpper(waitName), |
| 420 | + failureDetailExtractor != null ? " due to: " + failureDetailExtractor.apply(entity) : "", |
| 421 | + detailsName)); |
420 | 422 | } |
421 | 423 | } |
422 | 424 |
|
@@ -444,7 +446,7 @@ private void awaitProvisionedTestResource(LoadTestResource testResource) |
444 | 446 | awaitStatus(testResource, |
445 | 447 | () -> apiClient.findTestResource(testResource.getName(), testResource.getResourceGroup()), |
446 | 448 | LoadTestResource::isPendingProvisioning, LoadTestResource::isProvisioned, |
447 | | - PROVISIONING_TIMEOUT, "test resource provisioning", "Azure usage"); |
| 449 | + PROVISIONING_TIMEOUT, "test resource provisioning", "Azure usage", null); |
448 | 450 | } |
449 | 451 |
|
450 | 452 | private LoadTest createLoadTest(LoadTestResource testResource) throws IOException { |
@@ -498,7 +500,8 @@ private void awaitValidatedTestFile(LoadTest loadTest) |
498 | 500 | LOG.info("Validating test script"); |
499 | 501 | EntityProvider<LoadTest> testProvider = () -> apiClient.findTestById(loadTest.getTestId()); |
500 | 502 | awaitStatus(testProvider.get(), testProvider, LoadTest::isPendingValidation, |
501 | | - LoadTest::isSuccessValidation, VALIDATION_TIMEOUT, "test script validation", "test plan"); |
| 503 | + LoadTest::isSuccessValidation, VALIDATION_TIMEOUT, "test script validation", "test plan", |
| 504 | + LoadTest::getValidationFailureDetails); |
502 | 505 | } |
503 | 506 |
|
504 | 507 | private String solveTestRunName() { |
|
0 commit comments