From ab4459f93c7cca7df8ea7018ffe5f66fca407fe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Fri, 17 Nov 2023 16:33:15 +0100 Subject: [PATCH] Align Hibernate Search configuration defaults on Hibernate Search 7 --- .../ShardFailureIgnoreDefaultTest.java | 9 +++++---- ...eTest.java => ShardFailureIgnoreTrueTest.java} | 15 +++++++-------- ...ElasticsearchRuntimeConfigPersistenceUnit.java | 4 +--- 3 files changed, 13 insertions(+), 15 deletions(-) rename extensions/hibernate-search-orm-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/orm/elasticsearch/test/search/shard_failure/{ShardFailureIgnoreFalseTest.java => ShardFailureIgnoreTrueTest.java} (77%) diff --git a/extensions/hibernate-search-orm-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/orm/elasticsearch/test/search/shard_failure/ShardFailureIgnoreDefaultTest.java b/extensions/hibernate-search-orm-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/orm/elasticsearch/test/search/shard_failure/ShardFailureIgnoreDefaultTest.java index ad3623a7ebae5c..bdffa9df0b5917 100644 --- a/extensions/hibernate-search-orm-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/orm/elasticsearch/test/search/shard_failure/ShardFailureIgnoreDefaultTest.java +++ b/extensions/hibernate-search-orm-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/orm/elasticsearch/test/search/shard_failure/ShardFailureIgnoreDefaultTest.java @@ -1,6 +1,6 @@ package io.quarkus.hibernate.search.orm.elasticsearch.test.search.shard_failure; -import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.List; @@ -39,12 +39,13 @@ public void testShardFailureIgnored() { session.toEntityManager().persist(new MyEntity2("42")); }); QuarkusTransaction.joiningExisting().run(() -> { - assertThat(session.search(List.of(MyEntity1.class, MyEntity2.class)) + assertThatThrownBy(() -> session.search(List.of(MyEntity1.class, MyEntity2.class)) .where(f -> f.wildcard().field("text").matching("4*")) .fetchHits(20)) // MyEntity2 fails because "text" is an integer field there - // We expect that index (shard) to be ignored - .hasSize(1); + // We expect an exception + .hasMessageContaining("Elasticsearch request failed", + "\"type\": \"query_shard_exception\""); }); } } diff --git a/extensions/hibernate-search-orm-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/orm/elasticsearch/test/search/shard_failure/ShardFailureIgnoreFalseTest.java b/extensions/hibernate-search-orm-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/orm/elasticsearch/test/search/shard_failure/ShardFailureIgnoreTrueTest.java similarity index 77% rename from extensions/hibernate-search-orm-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/orm/elasticsearch/test/search/shard_failure/ShardFailureIgnoreFalseTest.java rename to extensions/hibernate-search-orm-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/orm/elasticsearch/test/search/shard_failure/ShardFailureIgnoreTrueTest.java index dca03bec0ad4e0..0f4fb1d1bbe9a6 100644 --- a/extensions/hibernate-search-orm-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/orm/elasticsearch/test/search/shard_failure/ShardFailureIgnoreFalseTest.java +++ b/extensions/hibernate-search-orm-elasticsearch/deployment/src/test/java/io/quarkus/hibernate/search/orm/elasticsearch/test/search/shard_failure/ShardFailureIgnoreTrueTest.java @@ -1,6 +1,6 @@ package io.quarkus.hibernate.search.orm.elasticsearch.test.search.shard_failure; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.assertThat; import java.util.List; @@ -14,7 +14,7 @@ import io.quarkus.narayana.jta.QuarkusTransaction; import io.quarkus.test.QuarkusUnitTest; -public class ShardFailureIgnoreFalseTest { +public class ShardFailureIgnoreTrueTest { @RegisterExtension static QuarkusUnitTest runner = new QuarkusUnitTest() @@ -24,8 +24,8 @@ public class ShardFailureIgnoreFalseTest { .addClass(MyEntity2.class) .addAsResource("hsearch-4915/index2.json")) .withConfigurationResource("application.properties") - // Request that shard failures cause an exception instead of being ignored - .overrideConfigKey("quarkus.hibernate-search-orm.elasticsearch.query.shard-failure.ignore", "false") + // Request that shard failures be ignored + .overrideConfigKey("quarkus.hibernate-search-orm.elasticsearch.query.shard-failure.ignore", "true") // Override the type of the keyword field to integer, to create an error in one shard only. .overrideConfigKey( "quarkus.hibernate-search-orm.elasticsearch.indexes.\"MyEntity2\".schema-management.mapping-file", @@ -41,13 +41,12 @@ public void testShardFailureIgnored() { session.toEntityManager().persist(new MyEntity2("42")); }); QuarkusTransaction.joiningExisting().run(() -> { - assertThatThrownBy(() -> session.search(List.of(MyEntity1.class, MyEntity2.class)) + assertThat(session.search(List.of(MyEntity1.class, MyEntity2.class)) .where(f -> f.wildcard().field("text").matching("4*")) .fetchHits(20)) // MyEntity2 fails because "text" is an integer field there - // We expect an exception - .hasMessageContaining("Elasticsearch request failed", - "\"type\": \"query_shard_exception\""); + // We expect that index (shard) to be ignored + .hasSize(1); }); } } diff --git a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRuntimeConfigPersistenceUnit.java b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRuntimeConfigPersistenceUnit.java index 7eef01aa32e978..c9b5b62c1f9d1b 100644 --- a/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRuntimeConfigPersistenceUnit.java +++ b/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/HibernateSearchElasticsearchRuntimeConfigPersistenceUnit.java @@ -523,10 +523,8 @@ interface ElasticsearchQueryShardFailureConfig { /** * Whether partial shard failures are ignored (`true`) * or lead to Hibernate Search throwing an exception (`false`). - *

- * Will default to `false` in Hibernate Search 7. */ - @WithDefault("true") + @WithDefault("false") boolean ignore(); }