-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DevDB allows for zero configuration databases in dev and test mode, either starting the databases using testcontainers, or creating them in process.
- Loading branch information
1 parent
071a720
commit c1203d1
Showing
70 changed files
with
2,228 additions
and
113 deletions.
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
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
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
57 changes: 57 additions & 0 deletions
57
...l/deployment/src/test/java/io/quarkus/agroal/test/MultipleDevDBDataSourcesConfigTest.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,57 @@ | ||
package io.quarkus.agroal.test; | ||
|
||
import static io.quarkus.agroal.test.MultipleDataSourcesTestUtil.testDataSource; | ||
|
||
import java.sql.SQLException; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.agroal.api.AgroalDataSource; | ||
import io.quarkus.agroal.DataSource; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class MultipleDevDBDataSourcesConfigTest { | ||
|
||
//tag::injection[] | ||
@Inject | ||
AgroalDataSource defaultDataSource; | ||
|
||
@Inject | ||
@DataSource("users") | ||
AgroalDataSource dataSource1; | ||
|
||
@Inject | ||
@DataSource("inventory") | ||
AgroalDataSource dataSource2; | ||
//end::injection[] | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClass(MultipleDataSourcesTestUtil.class)) | ||
.withConfigurationResource("application-multiple-devdb-datasources.properties"); | ||
|
||
@Test | ||
public void testDataSourceInjection() throws SQLException { | ||
testDataSource("default", defaultDataSource, | ||
"jdbc:h2:tcp://localhost:" + extractPort(defaultDataSource) + "/mem:default;DB_CLOSE_DELAY=-1", "sa", 20); | ||
testDataSource("users", dataSource1, | ||
"jdbc:h2:tcp://localhost:" + extractPort(dataSource1) + "/mem:users;DB_CLOSE_DELAY=-1", "sa", 20); | ||
testDataSource("inventory", dataSource2, | ||
"jdbc:h2:tcp://localhost:" + extractPort(dataSource2) + "/mem:inventory;DB_CLOSE_DELAY=-1", "sa", 20); | ||
} | ||
|
||
public int extractPort(AgroalDataSource ds) { | ||
String url = ds.getConfiguration().connectionPoolConfiguration().connectionFactoryConfiguration().jdbcUrl(); | ||
Matcher matcher = Pattern.compile("jdbc:h2:tcp://localhost:(\\d+)/").matcher(url); | ||
matcher.find(); | ||
return Integer.parseInt(matcher.group(1)); | ||
} | ||
} |
Oops, something went wrong.