forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make DataSource beans application-scoped
So that we'll be able to postpone initialization to first access in some cases, instead of doing it on startup. This could be useful in particular for deactivated datasources: we don't want to initialize those on startup, but we do want them to fail on first use. An alternative would have been to represent deactivated datasources with a custom implementation of AgroalDataSource, like we currently do with UnconfiguredDataSource, but that solution has serious problems, in particular when we "forget" to implement some methods: see quarkusio#36666
- Loading branch information
Showing
5 changed files
with
70 additions
and
23 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
41 changes: 41 additions & 0 deletions
41
extensions/agroal/deployment/src/test/java/io/quarkus/agroal/test/EagerStartupTest.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,41 @@ | ||
package io.quarkus.agroal.test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import jakarta.inject.Singleton; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.agroal.runtime.DataSources; | ||
import io.quarkus.arc.Arc; | ||
import io.quarkus.datasource.common.runtime.DataSourceUtil; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
/** | ||
* Check that datasources are created eagerly on application startup. | ||
* <p> | ||
* This has always been the case historically, so we want to keep it that way. | ||
*/ | ||
public class EagerStartupTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withConfigurationResource("base.properties"); | ||
|
||
@Test | ||
public void shouldStartEagerly() { | ||
var container = Arc.container(); | ||
var instanceHandle = container.instance(DataSources.class); | ||
// Check that the following call won't trigger a lazy initialization: | ||
// the DataSources bean must be eagerly initialized. | ||
assertThat(container.getActiveContext(Singleton.class).getState() | ||
.getContextualInstances().get(instanceHandle.getBean())) | ||
.as("Eagerly instantiated DataSources bean") | ||
.isNotNull(); | ||
// Check that the datasource has already been eagerly created. | ||
assertThat(instanceHandle.get().isDataSourceCreated(DataSourceUtil.DEFAULT_DATASOURCE_NAME)) | ||
.isTrue(); | ||
} | ||
|
||
} |
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