Skip to content

Commit 64f6e9d

Browse files
Change AzureEngine validation of files to overcome current issue when validating test
1 parent fa6b186 commit 64f6e9d

File tree

4 files changed

+32
-59
lines changed

4 files changed

+32
-59
lines changed

jmeter-java-dsl-azure/src/main/java/us/abstracta/jmeter/javadsl/azure/AzureClient.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ Call<Void> updateAppComponents(@Path("testId") String testId,
229229
Call<Void> uploadTestFile(@Path("testId") String testId, @Path("fileName") String fileName,
230230
@Body RequestBody testFile);
231231

232-
@GET("tests/{testId}" + API_VERSION)
233-
Call<LoadTest> findTestById(@Path("testId") String testId);
232+
@GET("tests/{testId}/files/{fileName}" + API_VERSION)
233+
Call<FileInfo> findTestFile(@Path("testId") String testId, @Path("fileName") String fileName);
234234

235235
@PATCH("test-runs/{testRunId}" + API_VERSION)
236236
@Headers(MERGE_PATCH_CONTENT_TYPE_HEADER)
@@ -334,7 +334,6 @@ public LoadTest findTestByName(String testName, LoadTestResource testResource)
334334
}
335335

336336
public void updateTest(LoadTest loadTest) throws IOException {
337-
loadTest.clearInputArtifacts();
338337
execApiCall(loadTestApi.updateTest(loadTest.getTestId(), loadTest));
339338
}
340339

@@ -363,8 +362,8 @@ public void uploadTestFile(File file, String fileName, String testId) throws IOE
363362
RequestBody.create(MediaType.get("application/octet-stream"), file)));
364363
}
365364

366-
public LoadTest findTestById(String testId) throws IOException {
367-
return execApiCall(loadTestApi.findTestById(testId));
365+
public FileInfo findTestFile(String fileName, String testId) throws IOException {
366+
return execApiCall(loadTestApi.findTestFile(testId, fileName));
368367
}
369368

370369
public TestRun createTestRun(TestRun testRun) throws IOException {

jmeter-java-dsl-azure/src/main/java/us/abstracta/jmeter/javadsl/azure/AzureEngine.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.slf4j.Logger;
2020
import org.slf4j.LoggerFactory;
2121
import us.abstracta.jmeter.javadsl.azure.api.AppComponents;
22+
import us.abstracta.jmeter.javadsl.azure.api.FileInfo;
2223
import us.abstracta.jmeter.javadsl.azure.api.LoadTest;
2324
import us.abstracta.jmeter.javadsl.azure.api.LoadTestResource;
2425
import us.abstracta.jmeter.javadsl.azure.api.Location;
@@ -361,7 +362,6 @@ protected AzureTestPlanStats run(File jmxFile, HashTree tree, BuildTreeContext c
361362
updateAppComponents(loadTest);
362363
}
363364
uploadTestFiles(jmxFile, tree, context, loadTest);
364-
awaitValidatedTestFile(loadTest);
365365
TestRun testRun = new TestRun(loadTest.getTestId(), solveTestRunName());
366366
if (isAutoStoppableTest(tree)) {
367367
AzureTestStopper.setupTestRun(testRun, tenantId, clientId, clientSecret,
@@ -414,10 +414,11 @@ private <T> void awaitStatus(T entity, EntityProvider<T> entityProvider,
414414
+ "You may try executing again, or create an issue in jmeter-java-dsl GitHub repository "
415415
+ "with %s details.", waitName, prettyDuration(timeout), detailsName));
416416
} else if (!checkSuccessStatus.test(entity)) {
417+
String failureDetails =
418+
failureDetailExtractor != null ? failureDetailExtractor.apply(entity) : null;
417419
throw new IllegalArgumentException(String.format("%s failed%s. "
418420
+ "Create an issue in jmeter-java-dsl GitHub repository with %s details.",
419-
firstLetterToUpper(waitName),
420-
failureDetailExtractor != null ? " due to: " + failureDetailExtractor.apply(entity) : "",
421+
firstLetterToUpper(waitName), failureDetails != null ? " due to: " + failureDetails : "",
421422
detailsName));
422423
}
423424
}
@@ -481,7 +482,7 @@ private void updateAppComponents(LoadTest loadTest) throws IOException {
481482
}
482483

483484
private void uploadTestFiles(File jmxFile, HashTree tree, BuildTreeContext context,
484-
LoadTest loadTest) throws IOException {
485+
LoadTest loadTest) throws IOException, InterruptedException, TimeoutException {
485486
LOG.info("Uploading test script and asset files");
486487
for (File f : assets) {
487488
context.processAssetFile(f.getPath());
@@ -492,16 +493,18 @@ private void uploadTestFiles(File jmxFile, HashTree tree, BuildTreeContext conte
492493
context.processAssetFile(jmxFile.getPath());
493494
for (Map.Entry<String, File> asset : context.getAssetFiles().entrySet()) {
494495
apiClient.uploadTestFile(asset.getValue(), asset.getKey(), loadTest.getTestId());
496+
awaitValidatedTestFile(asset.getKey(), loadTest.getTestId());
495497
}
496498
}
497499

498-
private void awaitValidatedTestFile(LoadTest loadTest)
499-
throws TimeoutException, InterruptedException, IOException {
500+
private void awaitValidatedTestFile(String fileName, String testId)
501+
throws IOException, InterruptedException, TimeoutException {
500502
LOG.info("Validating test script");
501-
EntityProvider<LoadTest> testProvider = () -> apiClient.findTestById(loadTest.getTestId());
502-
awaitStatus(testProvider.get(), testProvider, LoadTest::isPendingValidation,
503-
LoadTest::isSuccessValidation, VALIDATION_TIMEOUT, "test script validation", "test plan",
504-
LoadTest::getValidationFailureDetails);
503+
EntityProvider<FileInfo> fileProvider = () -> apiClient.findTestFile(fileName, testId);
504+
awaitStatus(fileProvider.get(), fileProvider, FileInfo::isPendingValidation,
505+
FileInfo::isSuccessValidation, VALIDATION_TIMEOUT,
506+
"test file '" + fileName + "' validation", "test plan",
507+
FileInfo::getValidationFailureDetails);
505508
}
506509

507510
private String solveTestRunName() {

jmeter-java-dsl-azure/src/main/java/us/abstracta/jmeter/javadsl/azure/api/FileInfo.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package us.abstracta.jmeter.javadsl.azure.api;
22

33
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonIgnore;
45
import com.fasterxml.jackson.annotation.JsonProperty;
56

67
public class FileInfo {
@@ -30,4 +31,16 @@ public String getValidationFailureDetails() {
3031
return validationFailureDetails;
3132
}
3233

34+
@JsonIgnore
35+
public boolean isPendingValidation() {
36+
return validationStatus == null || "VALIDATION_INITIATED".equals(validationStatus)
37+
|| "NOT_VALIDATED".equals(validationStatus);
38+
}
39+
40+
@JsonIgnore
41+
public boolean isSuccessValidation() {
42+
return validationStatus == null || "VALIDATION_SUCCESS".equals(validationStatus)
43+
|| "VALIDATION_NOT_REQUIRED".equals(validationStatus);
44+
}
45+
3346
}

jmeter-java-dsl-azure/src/main/java/us/abstracta/jmeter/javadsl/azure/api/LoadTest.java

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,22 @@ public class LoadTest {
1313
private final String testId;
1414
private final String displayName;
1515
private final LoadTestConfiguration loadTestConfiguration;
16-
private final LoadTestInputArtifacts inputArtifacts;
1716
@JsonIgnore
1817
private LoadTestResource testResource;
1918

2019
@JsonCreator
2120
public LoadTest(@JsonProperty("testId") String testId,
2221
@JsonProperty("displayName") String displayName,
23-
@JsonProperty("loadTestConfiguration") LoadTestConfiguration loadTestConfiguration,
24-
@JsonProperty("inputArtifacts") LoadTestInputArtifacts inputArtifacts) {
22+
@JsonProperty("loadTestConfiguration") LoadTestConfiguration loadTestConfiguration) {
2523
this.testId = testId;
2624
this.displayName = displayName;
2725
this.loadTestConfiguration = loadTestConfiguration;
28-
this.inputArtifacts = inputArtifacts;
2926
}
3027

3128
public LoadTest(String displayName, int engineInstances, boolean splitAllCsvs,
3229
LoadTestResource testResource) {
3330
this(UUID.randomUUID().toString(), displayName,
34-
new LoadTestConfiguration(engineInstances, splitAllCsvs),
35-
new LoadTestInputArtifacts(null));
31+
new LoadTestConfiguration(engineInstances, splitAllCsvs));
3632
this.testResource = testResource;
3733
}
3834

@@ -64,10 +60,6 @@ public void setSplitCsvs(boolean splitCsvs) {
6460
this.loadTestConfiguration.splitAllCSVs = splitCsvs;
6561
}
6662

67-
public void clearInputArtifacts() {
68-
inputArtifacts.testScriptFileInfo = null;
69-
}
70-
7163
@JsonIgnore
7264
public void setTestResource(LoadTestResource testResource) {
7365
this.testResource = testResource;
@@ -85,29 +77,6 @@ public String getUrl() {
8577
}
8678
}
8779

88-
@JsonIgnore
89-
public boolean isPendingValidation() {
90-
String validationStatus = getValidationStatus();
91-
return "VALIDATION_INITIATED".equals(validationStatus) || "NOT_VALIDATED".equals(
92-
validationStatus);
93-
}
94-
95-
@JsonIgnore
96-
private String getValidationStatus() {
97-
return inputArtifacts.testScriptFileInfo == null ? "VALIDATION_INITIATED"
98-
: inputArtifacts.testScriptFileInfo.getValidationStatus();
99-
}
100-
101-
@JsonIgnore
102-
public boolean isSuccessValidation() {
103-
String validationStatus = getValidationStatus();
104-
return validationStatus == null || "VALIDATION_SUCCESS".equals(validationStatus);
105-
}
106-
107-
public String getValidationFailureDetails() {
108-
return inputArtifacts.testScriptFileInfo.getValidationFailureDetails();
109-
}
110-
11180
public static class LoadTestConfiguration {
11281

11382
private int engineInstances;
@@ -122,15 +91,4 @@ public LoadTestConfiguration(@JsonProperty("engineInstances") int engineInstance
12291

12392
}
12493

125-
public static class LoadTestInputArtifacts {
126-
127-
private FileInfo testScriptFileInfo;
128-
129-
@JsonCreator
130-
public LoadTestInputArtifacts(@JsonProperty("testScriptUrl") FileInfo testScriptFileInfo) {
131-
this.testScriptFileInfo = testScriptFileInfo;
132-
}
133-
134-
}
135-
13694
}

0 commit comments

Comments
 (0)