Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,23 @@
import org.bitrepository.pillar.integration.perf.metrics.Metrics;
import org.bitrepository.pillar.messagefactories.GetFileMessageFactory;
import org.bitrepository.protocol.bus.MessageReceiver;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIf;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.junit.jupiter.api.io.TempDir;

import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import static org.bitrepository.common.utils.AllureTestUtils.addDescription;
import static org.bitrepository.common.utils.AllureTestUtils.addStep;

@EnabledIfSystemProperty(named = "runStressTests", matches = "true")
public class GetFileStressIT extends PillarPerformanceIT {
public static final String FOLDER_NAME = "src/test/resources";
@TempDir
static Path tempDir;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than a field here would we want to reduce the scope by making it a parameter to the method that uses it? See my comment to the method header.

protected GetFileClient getFileClient;

@BeforeEach
Expand All @@ -61,22 +59,6 @@ settingsForTestClient, createSecurityManager(), settingsForTestClient.getCompone
);
}

@AfterAll
static void removeUnnecessaryFiles() throws IOException {
removeFiles("noIdentfy", FOLDER_NAME);
removeFiles("parallel", FOLDER_NAME);
removeFiles("single", FOLDER_NAME);
}

private static void removeFiles(String fileStartsWith, String folderName) throws IOException {
Path directory = Paths.get(folderName);
try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory, fileStartsWith + "*")) {
for (Path entry : stream) {
Files.delete(entry);
}
}
}

@Test
@Tag(PillarTestGroups.PILLAR_STRESS_TEST)
void singleGetFilePerformanceTest() throws Exception {
Expand Down Expand Up @@ -116,6 +98,7 @@ void parallelGetFilePerformanceTest() throws Exception {
EventHandler eventHandler = new OperationEventHandlerForMetrics(metrics, getLimiter);
for (int i = 1; i <= numberOfFiles; i++) {
getLimiter.addJob(defaultFileId);
URL testUrl = httpServerConfiguration.getURL(nonDefaultFileId + "-" + i);
getFileClient.getFileFromSpecificPillar(
collectionID, defaultFileId, null, httpServerConfiguration.getURL(nonDefaultFileId + "-" + i),
getPillarID(), eventHandler, " performing parallelGetFilePerformance");
Expand Down Expand Up @@ -146,11 +129,23 @@ void noIdentfyGetFilePerformanceTest() throws Exception {
for (int i = 1; i <= numberOfFiles; i++) {
String correlationID = msgFactory.getNewCorrelationID();
getLimiter.addJob(correlationID);
String fileName = nonDefaultFileId + "-" + i;

// Ensure the source file exists in the temp directory so the server can serve it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? The test is also green without it.

Path sourceFile = tempDir.resolve(fileName);
if (!Files.exists(sourceFile)) {
Files.createFile(sourceFile);
}

// Create a unique destination path for each file within the temp directory
Path destinationFile = tempDir.resolve("noIdentfy-dest-" + i);
GetFileRequest getRequest =
msgFactory.createGetFileRequest("noIdentfyGetFilePerformanceTest", correlationID,
httpServerConfiguration.getURL(nonDefaultFileId + "-" + i).toExternalForm(),
msgFactory.createGetFileRequest(destinationFile.toAbsolutePath().toString(),
correlationID,
httpServerConfiguration.getURL(fileName).toExternalForm(),
defaultFileId, null, getPillarID(), getPillarID(),
settingsForTestClient.getReceiverDestinationID(), pillarDestination);
getRequest.setFileAddress("file:" + tempDir.toAbsolutePath().toString()+"/"+fileName);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? The test is also green without it.

If we want it (for one reason or another), conventions say to put a space before and after each +, which I also find nicer to read.

Matter of taste, we don’t need the toString() call since toString() is implicitly called in the string concatenation.

messageBus.sendMessage(getRequest);
}

Expand All @@ -171,4 +166,4 @@ public String lookupGetFileDestination() {
}
return pillarDestination;
}
}
}