-
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 #26840 from yrodiere/hsearch-enabled-started
Rename quarkus.hibernate-search-orm.enabled to quarkus.hibernate-search-orm.active and repurpose quarkus.hibernate-search-orm.enabled to disable Hibernate Search at build time
- Loading branch information
Showing
14 changed files
with
264 additions
and
53 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
24 changes: 24 additions & 0 deletions
24
...java/io/quarkus/hibernate/search/orm/elasticsearch/deployment/HibernateSearchEnabled.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,24 @@ | ||
package io.quarkus.hibernate.search.orm.elasticsearch.deployment; | ||
|
||
import java.util.function.BooleanSupplier; | ||
|
||
import io.quarkus.hibernate.search.orm.elasticsearch.runtime.HibernateSearchElasticsearchBuildTimeConfig; | ||
|
||
/** | ||
* Supplier that can be used to only run build steps | ||
* if the Hibernate Search extension is enabled. | ||
*/ | ||
public class HibernateSearchEnabled implements BooleanSupplier { | ||
|
||
private final HibernateSearchElasticsearchBuildTimeConfig config; | ||
|
||
HibernateSearchEnabled(HibernateSearchElasticsearchBuildTimeConfig config) { | ||
this.config = config; | ||
} | ||
|
||
@Override | ||
public boolean getAsBoolean() { | ||
return config.enabled; | ||
} | ||
|
||
} |
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
63 changes: 63 additions & 0 deletions
63
...nate/search/orm/elasticsearch/test/configuration/ConfigEnabledFalseAndActiveTrueTest.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,63 @@ | ||
package io.quarkus.hibernate.search.orm.elasticsearch.test.configuration; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.hibernate.Session; | ||
import org.hibernate.SessionFactory; | ||
import org.hibernate.search.mapper.orm.Search; | ||
import org.hibernate.search.mapper.orm.mapping.SearchMapping; | ||
import org.hibernate.search.mapper.orm.session.SearchSession; | ||
import org.hibernate.search.util.common.SearchException; | ||
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.quarkus.arc.Arc; | ||
import io.quarkus.runtime.configuration.ConfigurationException; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ConfigEnabledFalseAndActiveTrueTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest().setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class).addClass(IndexedEntity.class)) | ||
.withConfigurationResource("application.properties") | ||
.overrideConfigKey("quarkus.hibernate-search-orm.enabled", "false") | ||
.overrideConfigKey("quarkus.hibernate-search-orm.active", "true") | ||
.assertException(throwable -> assertThat(throwable) | ||
.isInstanceOf(ConfigurationException.class) | ||
.hasMessageContaining( | ||
"Hibernate Search activated explicitly, but Hibernate Search was disabled at build time", | ||
"If you want Hibernate Search to be active at runtime, you must set 'quarkus.hibernate-search-orm.enabled' to 'true' at build time", | ||
"If you don't want Hibernate Search to be active at runtime, you must leave 'quarkus.hibernate-search-orm.active' unset or set it to 'false'")); | ||
|
||
@Inject | ||
SessionFactory sessionFactory; | ||
|
||
@Test | ||
public void test() { | ||
assertThatThrownBy(() -> Arc.container().instance(SearchMapping.class).get()) | ||
.isInstanceOf(IllegalStateException.class) | ||
.hasMessageContaining( | ||
"Cannot retrieve the SearchMapping: Hibernate Search was disabled through configuration properties"); | ||
|
||
assertThatThrownBy(() -> Search.mapping(sessionFactory)) | ||
.isInstanceOf(SearchException.class) | ||
.hasMessageContaining("Hibernate Search was not initialized."); | ||
|
||
assertThatThrownBy(() -> Arc.container().instance(SearchSession.class).get()) | ||
.isInstanceOf(IllegalStateException.class) | ||
.hasMessageContaining( | ||
"Cannot retrieve the SearchSession: Hibernate Search was disabled through configuration properties"); | ||
|
||
try (Session session = sessionFactory.openSession()) { | ||
assertThatThrownBy(() -> Search.session(session).search(IndexedEntity.class)) | ||
.isInstanceOf(SearchException.class) | ||
.hasMessageContaining("Hibernate Search was not initialized."); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...e/search/orm/elasticsearch/test/configuration/ConfigEnabledFalseAndIndexedEntityTest.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,51 @@ | ||
package io.quarkus.hibernate.search.orm.elasticsearch.test.configuration; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.hibernate.Session; | ||
import org.hibernate.SessionFactory; | ||
import org.hibernate.search.mapper.orm.Search; | ||
import org.hibernate.search.mapper.orm.mapping.SearchMapping; | ||
import org.hibernate.search.mapper.orm.session.SearchSession; | ||
import org.hibernate.search.util.common.SearchException; | ||
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.quarkus.arc.Arc; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ConfigEnabledFalseAndIndexedEntityTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest().setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class).addClass(IndexedEntity.class)) | ||
.withConfigurationResource("application.properties") | ||
.overrideConfigKey("quarkus.hibernate-search-orm.enabled", "false"); | ||
|
||
@Inject | ||
SessionFactory sessionFactory; | ||
|
||
@Test | ||
public void test() { | ||
assertThat(Arc.container().instance(SearchMapping.class).get()) | ||
.isNull(); | ||
|
||
assertThatThrownBy(() -> Search.mapping(sessionFactory)) | ||
.isInstanceOf(SearchException.class) | ||
.hasMessageContaining("Hibernate Search was not initialized."); | ||
|
||
assertThat(Arc.container().instance(SearchSession.class).get()) | ||
.isNull(); | ||
|
||
try (Session session = sessionFactory.openSession()) { | ||
assertThatThrownBy(() -> Search.session(session).search(IndexedEntity.class)) | ||
.isInstanceOf(SearchException.class) | ||
.hasMessageContaining("Hibernate Search was not initialized."); | ||
} | ||
} | ||
} |
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.