-
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.
Merge pull request #41929 from yrodiere/datasource-arc-inactive-beans
Use Arc features in datasource extensions for eager startup and active/inactive
- Loading branch information
Showing
149 changed files
with
2,013 additions
and
2,154 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
31 changes: 15 additions & 16 deletions
31
...st/java/io/quarkus/agroal/test/ConfigActiveFalseDefaultDatasourceStaticInjectionTest.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 |
---|---|---|
@@ -1,47 +1,46 @@ | ||
package io.quarkus.agroal.test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import java.sql.SQLException; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.CreationException; | ||
import jakarta.inject.Inject; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.InactiveBeanException; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ConfigActiveFalseDefaultDatasourceStaticInjectionTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.overrideConfigKey("quarkus.datasource.active", "false"); | ||
.overrideConfigKey("quarkus.datasource.active", "false") | ||
.assertException(e -> assertThat(e) | ||
// Can't use isInstanceOf due to weird classloading in tests | ||
.satisfies(t -> assertThat(t.getClass().getName()).isEqualTo(InactiveBeanException.class.getName())) | ||
.hasMessageContainingAll("Datasource '<default>' was deactivated through configuration properties.", | ||
"To avoid this exception while keeping the bean inactive", // Message from Arc with generic hints | ||
"To activate the datasource, set configuration property 'quarkus.datasource.active'" | ||
+ " to 'true' and configure datasource '<default>'", | ||
"Refer to https://quarkus.io/guides/datasource for guidance.", | ||
"This bean is injected into", | ||
MyBean.class.getName() + "#ds")); | ||
|
||
@Inject | ||
MyBean myBean; | ||
|
||
@Test | ||
public void test() { | ||
assertThatThrownBy(() -> myBean.useDatasource()) | ||
.isInstanceOf(CreationException.class) | ||
.hasMessageContainingAll("Datasource '<default>' was deactivated through configuration properties.", | ||
"To solve this, avoid accessing this datasource at runtime, for instance by deactivating consumers (persistence units, ...).", | ||
"Alternatively, activate the datasource by setting configuration property 'quarkus.datasource.active'" | ||
+ " to 'true' and configure datasource '<default>'", | ||
"Refer to https://quarkus.io/guides/datasource for guidance."); | ||
Assertions.fail("Startup should have failed"); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class MyBean { | ||
@Inject | ||
DataSource ds; | ||
|
||
public void useDatasource() throws SQLException { | ||
ds.getConnection(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.