|  | 
| 20 | 20 | import java.io.IOException; | 
| 21 | 21 | import java.sql.SQLException; | 
| 22 | 22 | import java.sql.Statement; | 
|  | 23 | +import java.time.Duration; | 
| 23 | 24 | import java.util.Properties; | 
| 24 | 25 | 
 | 
| 25 | 26 | import javax.sql.DataSource; | 
| 26 | 27 | 
 | 
|  | 28 | +import com.zaxxer.hikari.HikariDataSource; | 
|  | 29 | +import com.zaxxer.hikari.HikariPoolMXBean; | 
| 27 | 30 | import org.apache.derby.jdbc.EmbeddedDriver; | 
|  | 31 | +import org.awaitility.Awaitility; | 
| 28 | 32 | import org.junit.jupiter.api.AfterEach; | 
| 29 | 33 | import org.junit.jupiter.api.BeforeEach; | 
| 30 | 34 | import org.junit.jupiter.api.Test; | 
| 31 |  | -import org.junit.jupiter.api.condition.DisabledOnOs; | 
| 32 |  | -import org.junit.jupiter.api.condition.OS; | 
| 33 | 35 | import org.junit.jupiter.api.io.TempDir; | 
| 34 | 36 | 
 | 
| 35 | 37 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | 
| @@ -123,13 +125,17 @@ void derbyClientIsNotShutdown() throws Exception { | 
| 123 | 125 | 	} | 
| 124 | 126 | 
 | 
| 125 | 127 | 	@Test | 
| 126 |  | -	@DisabledOnOs(OS.WINDOWS) | 
| 127 | 128 | 	void inMemoryDerbyIsShutdown() throws Exception { | 
| 128 | 129 | 		ConfigurableApplicationContext context = getContext( | 
| 129 | 130 | 				() -> createContext("org.apache.derby.jdbc.EmbeddedDriver", "jdbc:derby:memory:test;create=true", | 
| 130 | 131 | 						DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class)); | 
| 131 |  | -		JdbcTemplate jdbc = new JdbcTemplate(context.getBean(DataSource.class)); | 
|  | 132 | +		HikariDataSource dataSource = context.getBean(HikariDataSource.class); | 
|  | 133 | +		JdbcTemplate jdbc = new JdbcTemplate(dataSource); | 
| 132 | 134 | 		jdbc.execute("SELECT 1 FROM SYSIBM.SYSDUMMY1"); | 
|  | 135 | +		HikariPoolMXBean pool = dataSource.getHikariPoolMXBean(); | 
|  | 136 | +		// Prevent a race between Hikari's initialization and Derby shutdown | 
|  | 137 | +		Awaitility.await().atMost(Duration.ofSeconds(30)).until(pool::getIdleConnections, | 
|  | 138 | +				(idle) -> idle == dataSource.getMinimumIdle()); | 
| 133 | 139 | 		context.close(); | 
| 134 | 140 | 		// Connect should fail as DB no longer exists | 
| 135 | 141 | 		assertThatExceptionOfType(SQLException.class) | 
|  | 
0 commit comments