Fix test failures on Windows
Since the move to JUnit 5, a number of tests were failing on Windows. The majority were failing due to open file handles preventing the clean up of the tests' temporary directory. This commit addresses these failures by updating the tests to close JarFiles, InputStreams, OutputStreams etc. A change has also been made to CachingOperationInvokerTests to make a flakey test more robust. Due to System.currentTimeMillis() being less precise on Windows than it is on *nix platforms, the test could fail as it would not sleep for long enough for the TTL period to have expired.
This commit is contained in:
@@ -28,6 +28,8 @@ import org.apache.derby.jdbc.EmbeddedDriver;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.DisabledOnOs;
|
||||
import org.junit.jupiter.api.condition.OS;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
@@ -121,6 +123,7 @@ class DevToolsPooledDataSourceAutoConfigurationTests extends AbstractDevToolsDat
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisabledOnOs(OS.WINDOWS)
|
||||
void inMemoryDerbyIsShutdown() throws Exception {
|
||||
ConfigurableApplicationContext context = getContext(
|
||||
() -> createContext("org.apache.derby.jdbc.EmbeddedDriver", "jdbc:derby:memory:test;create=true",
|
||||
@@ -132,6 +135,9 @@ class DevToolsPooledDataSourceAutoConfigurationTests extends AbstractDevToolsDat
|
||||
assertThatExceptionOfType(SQLException.class)
|
||||
.isThrownBy(() -> new EmbeddedDriver().connect("jdbc:derby:memory:test", new Properties()))
|
||||
.satisfies((ex) -> assertThat(ex.getSQLState()).isEqualTo("XJ004"));
|
||||
// Shut Derby down fully so that it closes its log file
|
||||
assertThatExceptionOfType(SQLException.class)
|
||||
.isThrownBy(() -> new EmbeddedDriver().connect("jdbc:derby:;shutdown=true", new Properties()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.util.List;
|
||||
import java.util.jar.JarOutputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
@@ -72,6 +73,12 @@ class RestartClassLoaderTests {
|
||||
this.reloadClassLoader = new RestartClassLoader(this.parentClassLoader, urls, this.updatedFiles);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
this.reloadClassLoader.close();
|
||||
this.parentClassLoader.close();
|
||||
}
|
||||
|
||||
private File createSampleJarFile(File tempDir) throws IOException {
|
||||
File file = new File(tempDir, "sample.jar");
|
||||
JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(file));
|
||||
|
||||
Reference in New Issue
Block a user