Skip to content

Commit

Permalink
ISPN-11819 Prevent wrong server state when running tests with Contain…
Browse files Browse the repository at this point in the history
…erInfinispanServerDriver
  • Loading branch information
diegolovison committed May 12, 2020
1 parent 6d81531 commit 71caf74
Showing 1 changed file with 27 additions and 1 deletion.
Expand Up @@ -138,7 +138,7 @@ protected void start(String name, File rootDir, String configurationFile) {
image
.withFileFromPath("target", serverOutputPath.getParent())
.withFileFromPath("src", serverOutputPath.getParent().getParent().resolve("src"))
.withFileFromPath("build", serverOutputPath);
.withFileFromPath("build", validateServerOutput(serverOutputPath));
prebuiltImage = false;
log.infof("Using local image from server built at '%s'", serverOutputPath);
}
Expand Down Expand Up @@ -215,6 +215,32 @@ protected void start(String name, File rootDir, String configurationFile) {
}
}

/*
* Once you built the server, you can try to start it and it will create files under the data directory.
* Later, you decided to run some tests and it will take ages to find out that the tests are broken because there
* are files under the data directory.
*/
private Path validateServerOutput(Path serverOutputPath) {
File serverFolder = new File(serverOutputPath.toFile(), "server");
if (serverFolder.exists()) {
File dataFoler = new File(serverFolder, "data");
if (dataFoler.exists()) {
File[] files = dataFoler.listFiles();
if (files.length > 0) {
throw new IllegalStateException("The data directory must be empty.");
}
}
File logFolder = new File(serverFolder, "log");
if (logFolder.exists()) {
File[] files = dataFoler.listFiles();
if (files.length > 0) {
throw new IllegalStateException("Clean the log directory.");
}
}
}
return serverOutputPath;
}

private GenericContainer createContainer(int i) {

if (this.volumes[i] == null) {
Expand Down

0 comments on commit 71caf74

Please sign in to comment.