-
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.
DevServices allows for zero configuration databases in dev and test mode, either starting the databases using testcontainers, or creating them in process.
1 parent
56240a5
commit 8c6d022
Showing
78 changed files
with
2,293 additions
and
131 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
...oyment/src/test/java/io/quarkus/agroal/test/MultipleDevServicesDataSourcesConfigTest.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 MultipleDevServicesDataSourcesConfigTest { | ||
|
||
//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-devservices-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.