Skip to content

Commit

Permalink
Avoid failures caused by invalid configuration when Hibernate Search …
Browse files Browse the repository at this point in the history
…is disabled because there are no indexed entities
  • Loading branch information
yrodiere committed Nov 3, 2021
1 parent 5fe014b commit 9d8de14
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -19,14 +19,14 @@ class HibernateSearchOrmElasticsearchAwsProcessor {
@Record(ExecutionTime.RUNTIME_INIT)
void setRuntimeConfig(HibernateSearchOrmElasticsearchAwsRecorder recorder,
HibernateSearchOrmElasticsearchAwsRuntimeConfig runtimeConfig,
List<PersistenceUnitDescriptorBuildItem> persistenceUnitDescriptorBuildItems,
List<HibernateSearchElasticsearchPersistenceUnitConfiguredBuildItem> configuredPersistenceUnits,
BuildProducer<HibernateOrmIntegrationRuntimeConfiguredBuildItem> 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)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ void registerBeans(List<HibernateSearchElasticsearchPersistenceUnitConfiguredBui
void setRuntimeConfig(HibernateSearchElasticsearchRecorder recorder,
HibernateSearchElasticsearchRuntimeConfig runtimeConfig,
List<HibernateSearchIntegrationRuntimeConfiguredBuildItem> integrationRuntimeConfigBuildItems,
List<PersistenceUnitDescriptorBuildItem> persistenceUnitDescriptorBuildItems,
List<HibernateSearchElasticsearchPersistenceUnitConfiguredBuildItem> configuredPersistenceUnits,
BuildProducer<HibernateOrmIntegrationRuntimeConfiguredBuildItem> runtimeConfigured) {
for (PersistenceUnitDescriptorBuildItem puDescriptor : persistenceUnitDescriptorBuildItems) {
String puName = puDescriptor.getPersistenceUnitName();
for (HibernateSearchElasticsearchPersistenceUnitConfiguredBuildItem configuredPersistenceUnit : configuredPersistenceUnits) {
String puName = configuredPersistenceUnit.getPersistenceUnitName();
List<HibernateOrmIntegrationRuntimeInitListener> integrationRuntimeInitListeners = new ArrayList<>();
for (HibernateSearchIntegrationRuntimeConfiguredBuildItem item : integrationRuntimeConfigBuildItems) {
if (item.getPersistenceUnitName().equals(puName)) {
Expand All @@ -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)));
}
}
Expand Down

0 comments on commit 9d8de14

Please sign in to comment.