Skip to content

Commit

Permalink
Change AzureEngine validation of files to overcome current issue when…
Browse files Browse the repository at this point in the history
… validating test
  • Loading branch information
rabelenda-abstracta committed Aug 21, 2023
1 parent fa6b186 commit 64f6e9d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ Call<Void> updateAppComponents(@Path("testId") String testId,
Call<Void> uploadTestFile(@Path("testId") String testId, @Path("fileName") String fileName,
@Body RequestBody testFile);

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

@PATCH("test-runs/{testRunId}" + API_VERSION)
@Headers(MERGE_PATCH_CONTENT_TYPE_HEADER)
Expand Down Expand Up @@ -334,7 +334,6 @@ public LoadTest findTestByName(String testName, LoadTestResource testResource)
}

public void updateTest(LoadTest loadTest) throws IOException {
loadTest.clearInputArtifacts();
execApiCall(loadTestApi.updateTest(loadTest.getTestId(), loadTest));
}

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

public LoadTest findTestById(String testId) throws IOException {
return execApiCall(loadTestApi.findTestById(testId));
public FileInfo findTestFile(String fileName, String testId) throws IOException {
return execApiCall(loadTestApi.findTestFile(testId, fileName));
}

public TestRun createTestRun(TestRun testRun) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import us.abstracta.jmeter.javadsl.azure.api.AppComponents;
import us.abstracta.jmeter.javadsl.azure.api.FileInfo;
import us.abstracta.jmeter.javadsl.azure.api.LoadTest;
import us.abstracta.jmeter.javadsl.azure.api.LoadTestResource;
import us.abstracta.jmeter.javadsl.azure.api.Location;
Expand Down Expand Up @@ -361,7 +362,6 @@ protected AzureTestPlanStats run(File jmxFile, HashTree tree, BuildTreeContext c
updateAppComponents(loadTest);
}
uploadTestFiles(jmxFile, tree, context, loadTest);
awaitValidatedTestFile(loadTest);
TestRun testRun = new TestRun(loadTest.getTestId(), solveTestRunName());
if (isAutoStoppableTest(tree)) {
AzureTestStopper.setupTestRun(testRun, tenantId, clientId, clientSecret,
Expand Down Expand Up @@ -414,10 +414,11 @@ private <T> void awaitStatus(T entity, EntityProvider<T> entityProvider,
+ "You may try executing again, or create an issue in jmeter-java-dsl GitHub repository "
+ "with %s details.", waitName, prettyDuration(timeout), detailsName));
} else if (!checkSuccessStatus.test(entity)) {
String failureDetails =
failureDetailExtractor != null ? failureDetailExtractor.apply(entity) : null;
throw new IllegalArgumentException(String.format("%s failed%s. "
+ "Create an issue in jmeter-java-dsl GitHub repository with %s details.",
firstLetterToUpper(waitName),
failureDetailExtractor != null ? " due to: " + failureDetailExtractor.apply(entity) : "",
firstLetterToUpper(waitName), failureDetails != null ? " due to: " + failureDetails : "",
detailsName));
}
}
Expand Down Expand Up @@ -481,7 +482,7 @@ private void updateAppComponents(LoadTest loadTest) throws IOException {
}

private void uploadTestFiles(File jmxFile, HashTree tree, BuildTreeContext context,
LoadTest loadTest) throws IOException {
LoadTest loadTest) throws IOException, InterruptedException, TimeoutException {
LOG.info("Uploading test script and asset files");
for (File f : assets) {
context.processAssetFile(f.getPath());
Expand All @@ -492,16 +493,18 @@ private void uploadTestFiles(File jmxFile, HashTree tree, BuildTreeContext conte
context.processAssetFile(jmxFile.getPath());
for (Map.Entry<String, File> asset : context.getAssetFiles().entrySet()) {
apiClient.uploadTestFile(asset.getValue(), asset.getKey(), loadTest.getTestId());
awaitValidatedTestFile(asset.getKey(), loadTest.getTestId());
}
}

private void awaitValidatedTestFile(LoadTest loadTest)
throws TimeoutException, InterruptedException, IOException {
private void awaitValidatedTestFile(String fileName, String testId)
throws IOException, InterruptedException, TimeoutException {
LOG.info("Validating test script");
EntityProvider<LoadTest> testProvider = () -> apiClient.findTestById(loadTest.getTestId());
awaitStatus(testProvider.get(), testProvider, LoadTest::isPendingValidation,
LoadTest::isSuccessValidation, VALIDATION_TIMEOUT, "test script validation", "test plan",
LoadTest::getValidationFailureDetails);
EntityProvider<FileInfo> fileProvider = () -> apiClient.findTestFile(fileName, testId);
awaitStatus(fileProvider.get(), fileProvider, FileInfo::isPendingValidation,
FileInfo::isSuccessValidation, VALIDATION_TIMEOUT,
"test file '" + fileName + "' validation", "test plan",
FileInfo::getValidationFailureDetails);
}

private String solveTestRunName() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package us.abstracta.jmeter.javadsl.azure.api;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

public class FileInfo {
Expand Down Expand Up @@ -30,4 +31,16 @@ public String getValidationFailureDetails() {
return validationFailureDetails;
}

@JsonIgnore
public boolean isPendingValidation() {
return validationStatus == null || "VALIDATION_INITIATED".equals(validationStatus)
|| "NOT_VALIDATED".equals(validationStatus);
}

@JsonIgnore
public boolean isSuccessValidation() {
return validationStatus == null || "VALIDATION_SUCCESS".equals(validationStatus)
|| "VALIDATION_NOT_REQUIRED".equals(validationStatus);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,22 @@ public class LoadTest {
private final String testId;
private final String displayName;
private final LoadTestConfiguration loadTestConfiguration;
private final LoadTestInputArtifacts inputArtifacts;
@JsonIgnore
private LoadTestResource testResource;

@JsonCreator
public LoadTest(@JsonProperty("testId") String testId,
@JsonProperty("displayName") String displayName,
@JsonProperty("loadTestConfiguration") LoadTestConfiguration loadTestConfiguration,
@JsonProperty("inputArtifacts") LoadTestInputArtifacts inputArtifacts) {
@JsonProperty("loadTestConfiguration") LoadTestConfiguration loadTestConfiguration) {
this.testId = testId;
this.displayName = displayName;
this.loadTestConfiguration = loadTestConfiguration;
this.inputArtifacts = inputArtifacts;
}

public LoadTest(String displayName, int engineInstances, boolean splitAllCsvs,
LoadTestResource testResource) {
this(UUID.randomUUID().toString(), displayName,
new LoadTestConfiguration(engineInstances, splitAllCsvs),
new LoadTestInputArtifacts(null));
new LoadTestConfiguration(engineInstances, splitAllCsvs));
this.testResource = testResource;
}

Expand Down Expand Up @@ -64,10 +60,6 @@ public void setSplitCsvs(boolean splitCsvs) {
this.loadTestConfiguration.splitAllCSVs = splitCsvs;
}

public void clearInputArtifacts() {
inputArtifacts.testScriptFileInfo = null;
}

@JsonIgnore
public void setTestResource(LoadTestResource testResource) {
this.testResource = testResource;
Expand All @@ -85,29 +77,6 @@ public String getUrl() {
}
}

@JsonIgnore
public boolean isPendingValidation() {
String validationStatus = getValidationStatus();
return "VALIDATION_INITIATED".equals(validationStatus) || "NOT_VALIDATED".equals(
validationStatus);
}

@JsonIgnore
private String getValidationStatus() {
return inputArtifacts.testScriptFileInfo == null ? "VALIDATION_INITIATED"
: inputArtifacts.testScriptFileInfo.getValidationStatus();
}

@JsonIgnore
public boolean isSuccessValidation() {
String validationStatus = getValidationStatus();
return validationStatus == null || "VALIDATION_SUCCESS".equals(validationStatus);
}

public String getValidationFailureDetails() {
return inputArtifacts.testScriptFileInfo.getValidationFailureDetails();
}

public static class LoadTestConfiguration {

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

}

public static class LoadTestInputArtifacts {

private FileInfo testScriptFileInfo;

@JsonCreator
public LoadTestInputArtifacts(@JsonProperty("testScriptUrl") FileInfo testScriptFileInfo) {
this.testScriptFileInfo = testScriptFileInfo;
}

}

}

0 comments on commit 64f6e9d

Please sign in to comment.