-
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 #16655 from yrodiere/start_offline
Hibernate Search: Add configuration property to skip the Elasticsearch version check
- Loading branch information
Showing
7 changed files
with
191 additions
and
6 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
17 changes: 17 additions & 0 deletions
17
...t/src/test/java/io/quarkus/hibernate/search/elasticsearch/test/offline/IndexedEntity.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,17 @@ | ||
package io.quarkus.hibernate.search.elasticsearch.test.offline; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
|
||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; | ||
|
||
@Entity | ||
@Indexed | ||
public class IndexedEntity { | ||
|
||
@Id | ||
@GeneratedValue | ||
public Long id; | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
...rc/test/java/io/quarkus/hibernate/search/elasticsearch/test/offline/StartOfflineTest.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.elasticsearch.test.offline; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import javax.inject.Inject; | ||
import javax.transaction.Transactional; | ||
|
||
import org.hibernate.search.mapper.orm.entity.SearchIndexedEntity; | ||
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.test.QuarkusUnitTest; | ||
|
||
/** | ||
* Test that an application can be configured to start successfully | ||
* even if the Elasticsearch cluster is offline when the application starts. | ||
*/ | ||
public class StartOfflineTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClass(IndexedEntity.class) | ||
.addAsResource("application-start-offline.properties", "application.properties")); | ||
|
||
@Inject | ||
SearchMapping searchMapping; | ||
|
||
@Inject | ||
SearchSession searchSession; | ||
|
||
@Test | ||
public void testHibernateSearchStarted() { | ||
assertThat(searchMapping.allIndexedEntities()) | ||
.hasSize(1) | ||
.element(0) | ||
.returns(IndexedEntity.class, SearchIndexedEntity::javaClass); | ||
} | ||
|
||
@Test | ||
@Transactional | ||
public void testSchemaManagementAvailableButFailsSinceElasticsearchNotStarted() { | ||
assertThatThrownBy(() -> searchSession.schemaManager(IndexedEntity.class).createIfMissing()) | ||
.isInstanceOf(SearchException.class) | ||
.hasMessageContaining("Elasticsearch request failed: Connection refused"); | ||
} | ||
|
||
@Test | ||
@Transactional | ||
public void testSearchAvailableButFailsSinceElasticsearchNotStarted() { | ||
assertThatThrownBy(() -> searchSession.search(IndexedEntity.class) | ||
.where(f -> f.matchAll()).fetchHits(20)) | ||
.isInstanceOf(SearchException.class) | ||
.hasMessageContaining("Elasticsearch request failed: Connection refused"); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...arch-orm-elasticsearch/deployment/src/test/resources/application-start-offline.properties
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,11 @@ | ||
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 | ||
# Simulate an offline Elasticsearch instance by pointing to a non-existing cluster | ||
quarkus.hibernate-search-orm.elasticsearch.hosts=localhost:14800 | ||
quarkus.hibernate-search-orm.schema-management.strategy=none | ||
quarkus.hibernate-search-orm.elasticsearch.version-check.enabled=false |
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