Commit 841667fb authored by mamunozgil's avatar mamunozgil
Browse files

Add dynamic paths to test

No related merge requests found
Pipeline #10915 passed with stage
in 18 seconds
Showing with 44 additions and 15 deletions
+44 -15
...@@ -33,14 +33,14 @@ public class TaskUpload { ...@@ -33,14 +33,14 @@ public class TaskUpload {
private static final Logger LOG = LogManager.getLogger(TaskUpload.class); private static final Logger LOG = LogManager.getLogger(TaskUpload.class);
private final RepoUtil repoUtil; private final RepoUtil repoUtil;
private final Path testTmpPath; private final Path assignmentSubmissionsPath;
private final ExecuteTestUtil executeTestUtil; private final ExecuteTestUtil executeTestUtil;
private final Tika tika; private final Tika tika;
public TaskUpload(Environment env, RepoUtil repoUtil, ExecuteTestUtil executeTestUtil) { public TaskUpload(Environment env, RepoUtil repoUtil, ExecuteTestUtil executeTestUtil) {
this.repoUtil = repoUtil; this.repoUtil = repoUtil;
this.executeTestUtil = executeTestUtil; this.executeTestUtil = executeTestUtil;
this.testTmpPath = Paths.get(env.getProperty("tests.tmp.dir")); this.assignmentSubmissionsPath = Paths.get(env.getProperty("tests.tmp.dir"));
this.tika = new Tika(); this.tika = new Tika();
} }
...@@ -68,7 +68,7 @@ public class TaskUpload { ...@@ -68,7 +68,7 @@ public class TaskUpload {
private Path createWorkDirectory() throws IOException { private Path createWorkDirectory() throws IOException {
LOG.debug("Creating new temporary directory"); LOG.debug("Creating new temporary directory");
Path workDirectory = Files.createTempDirectory(testTmpPath, "dta-submission"); Path workDirectory = Files.createTempDirectory(assignmentSubmissionsPath, "dta-submission");
LOG.debug("Working directory for test: {}", workDirectory.toAbsolutePath()); LOG.debug("Working directory for test: {}", workDirectory.toAbsolutePath());
return workDirectory; return workDirectory;
} }
......
...@@ -63,11 +63,40 @@ public class DockerUtil { ...@@ -63,11 +63,40 @@ public class DockerUtil {
LOG.debug("creating container"); LOG.debug("creating container");
CreateContainerResponse containerResponse; CreateContainerResponse containerResponse;
try { try {
// Extract paths from binds
String testPath = null;
String srcPath = null;
String resultPath = null;
for (Bind bind : binds) {
Volume volume = bind.getVolume();
if (volume.getPath().contains("test")) {
testPath = bind.getPath();
} else if (volume.getPath().contains("src")) {
srcPath = bind.getPath();
} else if (volume.getPath().contains("result")) {
resultPath = bind.getPath();
}
}
if (testPath == null || srcPath == null || resultPath == null) {
throw new IllegalArgumentException("All required paths (testPath, srcPath, resultPath) must be provided.");
}
containerResponse = dockerClient.createContainerCmd("testcontainer") containerResponse = dockerClient.createContainerCmd("testcontainer")
.withImage(image) .withImage(image)
.withHostConfig( .withHostConfig(
HostConfig.newHostConfig() HostConfig.newHostConfig()
.withBinds(binds)) .withBinds(binds)
)
.withCmd(
"java",
"-Djava.security.egd=file:/dev/./urandom",
"-jar",
"/data/app.jar",
String.format("%s:%s", srcPath, testPath),
"/data/libs/*:/data/test/libs/*",
resultPath
)
.exec(); .exec();
} catch (DockerException e) { } catch (DockerException e) {
LOG.error(String.format( LOG.error(String.format(
......
...@@ -104,9 +104,9 @@ public class ExecuteTestUtil { ...@@ -104,9 +104,9 @@ public class ExecuteTestUtil {
// Start the test-container with professor-given image and submission-specific volume mounts // Start the test-container with professor-given image and submission-specific volume mounts
dockerUtil.runContainer( dockerUtil.runContainer(
image, image,
new Bind(testPath.toString(), new Volume("/data/test")), new Bind(testPath.toString(), new Volume("test")),
new Bind(srcPath.toString(), new Volume("/data/src")), new Bind(srcPath.toString(), new Volume("src")),
new Bind(resultPath.toString(), new Volume("/data/result")) new Bind(resultPath.toString(), new Volume("result"))
); );
return generateResult(assignmentId, resultPath, testPath); return generateResult(assignmentId, resultPath, testPath);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment