-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to start daemon database container (#360)
* Allow to start daemon database container * Add documentation for TC_DAEMON parameter * Add tests for TC_DAEMON parameter * Update changelog
- Loading branch information
Showing
4 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
modules/jdbc-test/src/test/java/org/testcontainers/jdbc/DatabaseDriverShutdownTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.testcontainers.jdbc; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.Test; | ||
import org.testcontainers.containers.JdbcDatabaseContainer; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
|
||
import static org.rnorth.visibleassertions.VisibleAssertions.assertNotNull; | ||
import static org.rnorth.visibleassertions.VisibleAssertions.assertNull; | ||
import static org.rnorth.visibleassertions.VisibleAssertions.assertTrue; | ||
|
||
/** | ||
* Created by inikolaev on 08/06/2017. | ||
*/ | ||
public class DatabaseDriverShutdownTest { | ||
@AfterClass | ||
public static void testCleanup() { | ||
ContainerDatabaseDriver.killContainers(); | ||
} | ||
|
||
@Test | ||
public void shouldStopContainerWhenAllConnectionsClosed() throws SQLException { | ||
final String jdbcUrl = "jdbc:tc:postgresql://hostname/databasename"; | ||
|
||
getConnectionAndClose(jdbcUrl); | ||
|
||
JdbcDatabaseContainer<?> container = ContainerDatabaseDriver.getContainer(jdbcUrl); | ||
assertNull("Database container instance is null as expected", container); | ||
} | ||
|
||
@Test | ||
public void shouldNotStopDaemonContainerWhenAllConnectionsClosed() throws SQLException { | ||
final String jdbcUrl = "jdbc:tc:postgresql://hostname/databasename?TC_DAEMON=true"; | ||
|
||
getConnectionAndClose(jdbcUrl); | ||
|
||
JdbcDatabaseContainer<?> container = ContainerDatabaseDriver.getContainer(jdbcUrl); | ||
assertNotNull("Database container instance is not null as expected", container); | ||
assertTrue("Database container is running as expected", container.isRunning()); | ||
} | ||
|
||
private void getConnectionAndClose(String jdbcUrl) throws SQLException { | ||
try (Connection connection = DriverManager.getConnection(jdbcUrl)) { | ||
assertNotNull("Obtained connection as expected", connection); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters