forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configuration property quarkus.hibernate-search-orm.elasticsearch…
….query.shard-failure. See https://docs.jboss.org/hibernate/search/6.2/reference/en-US/html_single/#backend-elasticsearch-search-ignore-partial-shard-failure
- Loading branch information
Showing
7 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...va/io/quarkus/hibernate/search/orm/elasticsearch/test/search/shard_failure/MyEntity1.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,44 @@ | ||
package io.quarkus.hibernate.search.orm.elasticsearch.test.search.shard_failure; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
|
||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; | ||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.KeywordField; | ||
|
||
@Entity | ||
@Indexed | ||
public class MyEntity1 { | ||
|
||
@Id | ||
@GeneratedValue | ||
private Long id; | ||
|
||
@KeywordField | ||
private String text; | ||
|
||
public MyEntity1() { | ||
} | ||
|
||
public MyEntity1(String text) { | ||
this.text = text; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getText() { | ||
return text; | ||
} | ||
|
||
public void setText(String text) { | ||
this.text = text; | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...va/io/quarkus/hibernate/search/orm/elasticsearch/test/search/shard_failure/MyEntity2.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,44 @@ | ||
package io.quarkus.hibernate.search.orm.elasticsearch.test.search.shard_failure; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
|
||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; | ||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.KeywordField; | ||
|
||
@Entity | ||
@Indexed | ||
public class MyEntity2 { | ||
|
||
@Id | ||
@GeneratedValue | ||
private Long id; | ||
|
||
@KeywordField | ||
private String text; | ||
|
||
public MyEntity2() { | ||
} | ||
|
||
public MyEntity2(String text) { | ||
this.text = text; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getText() { | ||
return text; | ||
} | ||
|
||
public void setText(String text) { | ||
this.text = text; | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
...ate/search/orm/elasticsearch/test/search/shard_failure/ShardFailureIgnoreDefaultTest.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,50 @@ | ||
package io.quarkus.hibernate.search.orm.elasticsearch.test.search.shard_failure; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.hibernate.search.mapper.orm.session.SearchSession; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.hibernate.search.orm.elasticsearch.test.util.TransactionUtils; | ||
import io.quarkus.narayana.jta.QuarkusTransaction; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ShardFailureIgnoreDefaultTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClass(TransactionUtils.class) | ||
.addClass(MyEntity1.class) | ||
.addClass(MyEntity2.class) | ||
.addAsResource("hsearch-4915/index2.json")) | ||
.withConfigurationResource("application.properties") | ||
// 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", | ||
"hsearch-4915/index2.json"); | ||
|
||
@Inject | ||
SearchSession session; | ||
|
||
@Test | ||
public void testShardFailureIgnored() { | ||
QuarkusTransaction.joiningExisting().run(() -> { | ||
session.toEntityManager().persist(new MyEntity1("42")); | ||
session.toEntityManager().persist(new MyEntity2("42")); | ||
}); | ||
QuarkusTransaction.joiningExisting().run(() -> { | ||
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 that index (shard) to be ignored | ||
.hasSize(1); | ||
}); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...rnate/search/orm/elasticsearch/test/search/shard_failure/ShardFailureIgnoreFalseTest.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,53 @@ | ||
package io.quarkus.hibernate.search.orm.elasticsearch.test.search.shard_failure; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.hibernate.search.mapper.orm.session.SearchSession; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.hibernate.search.orm.elasticsearch.test.util.TransactionUtils; | ||
import io.quarkus.narayana.jta.QuarkusTransaction; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ShardFailureIgnoreFalseTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClass(TransactionUtils.class) | ||
.addClass(MyEntity1.class) | ||
.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") | ||
// 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", | ||
"hsearch-4915/index2.json"); | ||
|
||
@Inject | ||
SearchSession session; | ||
|
||
@Test | ||
public void testShardFailureIgnored() { | ||
QuarkusTransaction.joiningExisting().run(() -> { | ||
session.toEntityManager().persist(new MyEntity1("42")); | ||
session.toEntityManager().persist(new MyEntity2("42")); | ||
}); | ||
QuarkusTransaction.joiningExisting().run(() -> { | ||
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 an exception | ||
.hasMessageContaining("Elasticsearch request failed", | ||
"\"type\": \"query_shard_exception\""); | ||
}); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...hibernate-search-orm-elasticsearch/deployment/src/test/resources/hsearch-4915/index2.json
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,7 @@ | ||
{ | ||
"properties": { | ||
"text": { | ||
"type": "integer" | ||
} | ||
} | ||
} |
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