Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.quarkus.hibernate.orm.offline;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.hibernate.orm.MyEntity;
import io.quarkus.test.QuarkusDevModeTest;
import io.restassured.RestAssured;

/**
* Test that an application is running
* even if the database is offline when the application starts
* in DEV mode
*/
public class StartOfflineDevModeTest {

@RegisterExtension
static QuarkusDevModeTest runner = new QuarkusDevModeTest()
.withApplicationRoot((jar) -> jar
.addClass(MyEntity.class)
.addClass(GreetingResource.class)
.addAsResource("application-start-offline.properties", "application.properties"))
.setLogRecordPredicate(record -> true);

@Test
public void testUnitSchemaManagementStrategyIsNone() {
RestAssured.when().get("/hello").then()
.statusCode(200)
.body(is("DB is offline but application is running"));

assertThat(runner.getLogRecords())
.map(l -> l.getMessage())
.doesNotContain("Failed to run post-boot validation");
}

@Path("/hello")
public static class GreetingResource {

@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "DB is offline but application is running";
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,10 @@ public void doValidation(String puName) {
String schemaManagementStrategy = hibernateOrmRuntimeConfigPersistenceUnit.database().generation().generation()
.orElse(hibernateOrmRuntimeConfigPersistenceUnit.schemaManagement().strategy());

//if hibernate is already managing the schema we don't do this
if (!"none".equals(schemaManagementStrategy)) {
boolean startsOffline = hibernateOrmRuntimeConfigPersistenceUnit.database().startOffline();

//if hibernate is already managing the schema or if we're in offline mode we don't do this
if (!"none".equals(schemaManagementStrategy) || startsOffline) {
return;
}
new Thread(new Runnable() {
Expand Down
Loading