Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
Separate out loading run artifacts and only load artifacts where need…
Browse files Browse the repository at this point in the history
…ed to improve delete runs performance (#649)

* Separate loading run artifacts into IRunResult method, load artifacts only where needed

Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com>

* Rename mock run result variable and getter

Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com>

---------

Signed-off-by: Eamonn Mansour <47121388+eamansour@users.noreply.github.com>
  • Loading branch information
eamansour authored Sep 13, 2024
1 parent 1ee3194 commit 53b1517
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ private HttpServletResponse downloadArtifact(String runId, String artifactPath,
// Get run details in order to find artifacts
try {
run = getRunByRunId(runId);
run.loadArtifacts();
runName = run.getTestStructure().getRunName();
} catch (ResultArchiveStoreException e) {
ServletError error = new ServletError(GAL5002_INVALID_RUN_ID,runId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private String retrieveResults(String runId) throws InternalServletException {
JsonArray artifacts = new JsonArray();
try {
run = getRunByRunId(runId);
run.loadArtifacts();
} catch (ResultArchiveStoreException e) {
ServletError error = new ServletError(GAL5002_INVALID_RUN_ID, runId);
throw new InternalServletException(error, HttpServletResponse.SC_NOT_FOUND, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class MockRunResult implements IRunResult {
private Path artifactRoot;
private String log;
private boolean isDiscarded = false;
private boolean isLoadingArtifactsEnabled = false;

public MockRunResult(
String runId,
Expand Down Expand Up @@ -55,9 +56,17 @@ public String getLog() throws ResultArchiveStoreException {
public void discard() throws ResultArchiveStoreException {
isDiscarded = true;
}


@Override
public void loadArtifacts() throws ResultArchiveStoreException {
isLoadingArtifactsEnabled = true;
}

public boolean isDiscarded() {
return this.isDiscarded;
}

public boolean isLoadingArtifactsEnabled() {
return isLoadingArtifactsEnabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,10 @@ public void testDeleteRunNoReqPayloadWithGoodRunIdReturnsOK() throws Exception {
servlet.doDelete(req,resp);

// Then...
MockRunResult deletedRun = (MockRunResult) mockInputRunResults.get(0);
assertThat(resp.getStatus()).isEqualTo(204);
assertThat(((MockRunResult) mockInputRunResults.get(0)).isDiscarded()).as("The fake run result has not been discarded.").isTrue();
assertThat(deletedRun.isLoadingArtifactsEnabled()).as("The fake run result's artifacts should not have been loaded.").isFalse();
assertThat(deletedRun.isDiscarded()).as("The fake run result has not been discarded.").isTrue();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,9 @@ public void discard() throws ResultArchiveStoreException {
public String getRunId() {
return this.id;
}

@Override
public void loadArtifacts() throws ResultArchiveStoreException {
// Artifacts for local runs are already available on the filesystem so there is no need to load anything
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ public interface IRunResult {

void discard() throws ResultArchiveStoreException;

void loadArtifacts() throws ResultArchiveStoreException;

}

0 comments on commit 53b1517

Please sign in to comment.