From 9d8de14209ff1e0f0953e177ddbb8dee90f916a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Wed, 3 Nov 2021 09:06:15 +0100 Subject: [PATCH] Avoid failures caused by invalid configuration when Hibernate Search is disabled because there are no indexed entities --- ...ateSearchOrmElasticsearchAwsProcessor.java | 12 ++++----- .../MissingRegionSigningDisabledTest.java | 7 ++--- ...gionSigningEnabledNoIndexedEntityTest.java | 22 ++++++++++++++++ .../MissingRegionSigningEnabledTest.java | 5 ++-- .../test/configuration/NonIndexedEntity.java | 26 +++++++++++++++++++ ...missing-region-signing-disabled.properties | 15 ----------- ...bled.properties => application.properties} | 2 -- ...HibernateSearchElasticsearchProcessor.java | 8 +++--- 8 files changed, 65 insertions(+), 32 deletions(-) create mode 100644 extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/java/io/quarkus/hibernate/search/elasticsearch/aws/test/configuration/MissingRegionSigningEnabledNoIndexedEntityTest.java create mode 100644 extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/java/io/quarkus/hibernate/search/elasticsearch/aws/test/configuration/NonIndexedEntity.java delete mode 100644 extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/resources/application-missing-region-signing-disabled.properties rename extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/resources/{application-missing-region-signing-enabled.properties => application.properties} (90%) diff --git a/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/aws/HibernateSearchOrmElasticsearchAwsProcessor.java b/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/aws/HibernateSearchOrmElasticsearchAwsProcessor.java index 7398e07dc1744..26d058f857ee9 100644 --- a/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/aws/HibernateSearchOrmElasticsearchAwsProcessor.java +++ b/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/aws/HibernateSearchOrmElasticsearchAwsProcessor.java @@ -6,8 +6,8 @@ import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.annotations.ExecutionTime; import io.quarkus.deployment.annotations.Record; -import io.quarkus.hibernate.orm.deployment.PersistenceUnitDescriptorBuildItem; import io.quarkus.hibernate.orm.deployment.integration.HibernateOrmIntegrationRuntimeConfiguredBuildItem; +import io.quarkus.hibernate.search.orm.elasticsearch.HibernateSearchElasticsearchPersistenceUnitConfiguredBuildItem; import io.quarkus.hibernate.search.orm.elasticsearch.aws.runtime.HibernateSearchOrmElasticsearchAwsRecorder; import io.quarkus.hibernate.search.orm.elasticsearch.aws.runtime.HibernateSearchOrmElasticsearchAwsRuntimeConfig; @@ -19,14 +19,14 @@ class HibernateSearchOrmElasticsearchAwsProcessor { @Record(ExecutionTime.RUNTIME_INIT) void setRuntimeConfig(HibernateSearchOrmElasticsearchAwsRecorder recorder, HibernateSearchOrmElasticsearchAwsRuntimeConfig runtimeConfig, - List persistenceUnitDescriptorBuildItems, + List configuredPersistenceUnits, BuildProducer runtimeConfigured) { - for (PersistenceUnitDescriptorBuildItem puDescriptor : persistenceUnitDescriptorBuildItems) { + for (HibernateSearchElasticsearchPersistenceUnitConfiguredBuildItem configuredPersistenceUnit : configuredPersistenceUnits) { + String puName = configuredPersistenceUnit.getPersistenceUnitName(); runtimeConfigured.produce(new HibernateOrmIntegrationRuntimeConfiguredBuildItem( - HIBERNATE_SEARCH_ORM_ELASTICSEARCH_AWS, - puDescriptor.getPersistenceUnitName()) + HIBERNATE_SEARCH_ORM_ELASTICSEARCH_AWS, puName) .setInitListener( - recorder.createRuntimeInitListener(runtimeConfig, puDescriptor.getPersistenceUnitName()))); + recorder.createRuntimeInitListener(runtimeConfig, puName))); } } diff --git a/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/java/io/quarkus/hibernate/search/elasticsearch/aws/test/configuration/MissingRegionSigningDisabledTest.java b/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/java/io/quarkus/hibernate/search/elasticsearch/aws/test/configuration/MissingRegionSigningDisabledTest.java index 192c8963461a9..37007c8f35a18 100644 --- a/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/java/io/quarkus/hibernate/search/elasticsearch/aws/test/configuration/MissingRegionSigningDisabledTest.java +++ b/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/java/io/quarkus/hibernate/search/elasticsearch/aws/test/configuration/MissingRegionSigningDisabledTest.java @@ -11,11 +11,12 @@ public class MissingRegionSigningDisabledTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest().setArchiveProducer( - () -> ShrinkWrap.create(JavaArchive.class).addClass(IndexedEntity.class) - .addAsResource("application-missing-region-signing-disabled.properties", "application.properties")); + () -> ShrinkWrap.create(JavaArchive.class).addClass(IndexedEntity.class)) + .withConfigurationResource("application.properties") + .overrideConfigKey("quarkus.hibernate-search-orm.elasticsearch.aws.signing.enabled", "false"); @Test public void testNoConfig() { - // Just check there are no exceptions on startup, on contrary to MissingRegionTest + // Just check there are no exceptions on startup, on contrary to MissingRegionSigningEnabledTest } } diff --git a/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/java/io/quarkus/hibernate/search/elasticsearch/aws/test/configuration/MissingRegionSigningEnabledNoIndexedEntityTest.java b/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/java/io/quarkus/hibernate/search/elasticsearch/aws/test/configuration/MissingRegionSigningEnabledNoIndexedEntityTest.java new file mode 100644 index 0000000000000..c26cb53f69527 --- /dev/null +++ b/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/java/io/quarkus/hibernate/search/elasticsearch/aws/test/configuration/MissingRegionSigningEnabledNoIndexedEntityTest.java @@ -0,0 +1,22 @@ +package io.quarkus.hibernate.search.elasticsearch.aws.test.configuration; + +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.test.QuarkusUnitTest; + +public class MissingRegionSigningEnabledNoIndexedEntityTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest().setArchiveProducer( + () -> ShrinkWrap.create(JavaArchive.class).addClass(NonIndexedEntity.class)) + .withConfigurationResource("application.properties") + .overrideConfigKey("quarkus.hibernate-search-orm.elasticsearch.aws.signing.enabled", "true"); + + @Test + public void testNoConfig() { + // Just check there are no exceptions on startup, on contrary to MissingRegionSigningEnabledTest + } +} diff --git a/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/java/io/quarkus/hibernate/search/elasticsearch/aws/test/configuration/MissingRegionSigningEnabledTest.java b/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/java/io/quarkus/hibernate/search/elasticsearch/aws/test/configuration/MissingRegionSigningEnabledTest.java index fc13cfc4965c6..82610d6fa7d05 100644 --- a/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/java/io/quarkus/hibernate/search/elasticsearch/aws/test/configuration/MissingRegionSigningEnabledTest.java +++ b/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/java/io/quarkus/hibernate/search/elasticsearch/aws/test/configuration/MissingRegionSigningEnabledTest.java @@ -14,8 +14,9 @@ public class MissingRegionSigningEnabledTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest().setArchiveProducer( - () -> ShrinkWrap.create(JavaArchive.class).addClass(IndexedEntity.class) - .addAsResource("application-missing-region-signing-enabled.properties", "application.properties")) + () -> ShrinkWrap.create(JavaArchive.class).addClass(IndexedEntity.class)) + .withConfigurationResource("application.properties") + .overrideConfigKey("quarkus.hibernate-search-orm.elasticsearch.aws.signing.enabled", "true") .assertException(throwable -> assertThat(throwable) .isInstanceOf(RuntimeException.class) .hasMessageContainingAll( diff --git a/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/java/io/quarkus/hibernate/search/elasticsearch/aws/test/configuration/NonIndexedEntity.java b/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/java/io/quarkus/hibernate/search/elasticsearch/aws/test/configuration/NonIndexedEntity.java new file mode 100644 index 0000000000000..52a4c2f48b72b --- /dev/null +++ b/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/java/io/quarkus/hibernate/search/elasticsearch/aws/test/configuration/NonIndexedEntity.java @@ -0,0 +1,26 @@ +package io.quarkus.hibernate.search.elasticsearch.aws.test.configuration; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; + +/** + * A non-indexed entity. + */ +@Entity +public class NonIndexedEntity { + + @Id + @GeneratedValue + private Long id; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } +} diff --git a/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/resources/application-missing-region-signing-disabled.properties b/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/resources/application-missing-region-signing-disabled.properties deleted file mode 100644 index ebc6438d55156..0000000000000 --- a/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/resources/application-missing-region-signing-disabled.properties +++ /dev/null @@ -1,15 +0,0 @@ -quarkus.datasource.db-kind=h2 -quarkus.datasource.jdbc.url=jdbc:h2:mem:default;DB_CLOSE_DELAY=-1 - -quarkus.hibernate-orm.dialect=org.hibernate.dialect.H2Dialect -quarkus.hibernate-orm.database.generation=drop-and-create - -quarkus.hibernate-search-orm.elasticsearch.version=7.10 -quarkus.hibernate-search-orm.automatic-indexing.synchronization.strategy=sync - -# Testing offline, so that we don't have to start an Elasticsearch container. -# Use integration tests if you really need to communicate with Elasticsearch. -quarkus.hibernate-search-orm.schema-management.strategy=none -quarkus.hibernate-search-orm.elasticsearch.version-check.enabled=false - -quarkus.hibernate-search-orm.elasticsearch.aws.signing.enabled=false diff --git a/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/resources/application-missing-region-signing-enabled.properties b/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/resources/application.properties similarity index 90% rename from extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/resources/application-missing-region-signing-enabled.properties rename to extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/resources/application.properties index f0c038c67967d..d8eea12c8a02d 100644 --- a/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/resources/application-missing-region-signing-enabled.properties +++ b/extensions/hibernate-search-orm-elasticsearch-aws/deployment/src/test/resources/application.properties @@ -11,5 +11,3 @@ quarkus.hibernate-search-orm.automatic-indexing.synchronization.strategy=sync # Use integration tests if you really need to communicate with Elasticsearch. quarkus.hibernate-search-orm.schema-management.strategy=none quarkus.hibernate-search-orm.elasticsearch.version-check.enabled=false - -quarkus.hibernate-search-orm.elasticsearch.aws.signing.enabled=true \ No newline at end of file diff --git a/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/HibernateSearchElasticsearchProcessor.java b/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/HibernateSearchElasticsearchProcessor.java index a9764dafb1f85..3527874ce3439 100644 --- a/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/HibernateSearchElasticsearchProcessor.java +++ b/extensions/hibernate-search-orm-elasticsearch/deployment/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/HibernateSearchElasticsearchProcessor.java @@ -143,10 +143,10 @@ void registerBeans(List integrationRuntimeConfigBuildItems, - List persistenceUnitDescriptorBuildItems, + List configuredPersistenceUnits, BuildProducer runtimeConfigured) { - for (PersistenceUnitDescriptorBuildItem puDescriptor : persistenceUnitDescriptorBuildItems) { - String puName = puDescriptor.getPersistenceUnitName(); + for (HibernateSearchElasticsearchPersistenceUnitConfiguredBuildItem configuredPersistenceUnit : configuredPersistenceUnits) { + String puName = configuredPersistenceUnit.getPersistenceUnitName(); List integrationRuntimeInitListeners = new ArrayList<>(); for (HibernateSearchIntegrationRuntimeConfiguredBuildItem item : integrationRuntimeConfigBuildItems) { if (item.getPersistenceUnitName().equals(puName)) { @@ -156,7 +156,7 @@ void setRuntimeConfig(HibernateSearchElasticsearchRecorder recorder, runtimeConfigured.produce( new HibernateOrmIntegrationRuntimeConfiguredBuildItem(HIBERNATE_SEARCH_ELASTICSEARCH, puName) .setInitListener( - recorder.createRuntimeInitListener(runtimeConfig, puDescriptor.getPersistenceUnitName(), + recorder.createRuntimeInitListener(runtimeConfig, puName, integrationRuntimeInitListeners))); } }