-
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 #43762 from yrodiere/i43703-workaround
Add quarkus.hibernate-orm.database.version-check.enabled
- Loading branch information
Showing
16 changed files
with
341 additions
and
32 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
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
73 changes: 73 additions & 0 deletions
73
...s/hibernate/orm/config/dialect/DbVersionCheckDisabledAutomaticallyPersistenceXmlTest.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,73 @@ | ||
package io.quarkus.hibernate.orm.config.dialect; | ||
|
||
import static io.quarkus.hibernate.orm.ResourceUtil.loadResourceAndReplacePlaceholders; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Map; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.transaction.Transactional; | ||
|
||
import org.hibernate.Session; | ||
import org.hibernate.SessionFactory; | ||
import org.hibernate.engine.spi.SessionFactoryImplementor; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.hibernate.orm.MyEntity; | ||
import io.quarkus.hibernate.orm.SmokeTestUtils; | ||
import io.quarkus.hibernate.orm.runtime.config.DialectVersions; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
/** | ||
* Tests that the workaround for https://github.com/quarkusio/quarkus/issues/43703 / | ||
* https://github.com/quarkusio/quarkus/issues/42255 | ||
* is effective. | ||
*/ | ||
// TODO remove this test when change the default to "always enabled" when we solve version detection problems | ||
// See https://github.com/quarkusio/quarkus/issues/43703 | ||
// See https://github.com/quarkusio/quarkus/issues/42255 | ||
public class DbVersionCheckDisabledAutomaticallyPersistenceXmlTest { | ||
|
||
private static final String ACTUAL_H2_VERSION = DialectVersions.Defaults.H2; | ||
// We will set the DB version to something higher than the actual version: this is invalid. | ||
private static final String CONFIGURED_DB_VERSION = "999.999.0"; | ||
static { | ||
assertThat(ACTUAL_H2_VERSION) | ||
.as("Test setup - we need the required version to be different from the actual one") | ||
.doesNotStartWith(CONFIGURED_DB_VERSION); | ||
} | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClass(SmokeTestUtils.class) | ||
.addClass(MyEntity.class) | ||
.addAsManifestResource(new StringAsset(loadResourceAndReplacePlaceholders( | ||
"META-INF/some-persistence-with-h2-version-placeholder-and-explicit-dialect.xml", | ||
Map.of("H2_VERSION", "999.999"))), | ||
"persistence.xml")) | ||
.withConfigurationResource("application-datasource-only.properties"); | ||
|
||
@Inject | ||
SessionFactory sessionFactory; | ||
|
||
@Inject | ||
Session session; | ||
|
||
@Test | ||
public void dialectVersion() { | ||
var dialectVersion = sessionFactory.unwrap(SessionFactoryImplementor.class).getJdbcServices().getDialect().getVersion(); | ||
assertThat(DialectVersions.toString(dialectVersion)).isEqualTo(CONFIGURED_DB_VERSION); | ||
} | ||
|
||
@Test | ||
@Transactional | ||
public void smokeTest() { | ||
SmokeTestUtils.testSimplePersistRetrieveUpdateDelete(session, | ||
MyEntity.class, MyEntity::new, | ||
MyEntity::getId, | ||
MyEntity::setName, MyEntity::getName); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...java/io/quarkus/hibernate/orm/config/dialect/DbVersionCheckDisabledAutomaticallyTest.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,69 @@ | ||
package io.quarkus.hibernate.orm.config.dialect; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.transaction.Transactional; | ||
|
||
import org.hibernate.Session; | ||
import org.hibernate.SessionFactory; | ||
import org.hibernate.dialect.H2Dialect; | ||
import org.hibernate.engine.spi.SessionFactoryImplementor; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.hibernate.orm.MyEntity; | ||
import io.quarkus.hibernate.orm.SmokeTestUtils; | ||
import io.quarkus.hibernate.orm.runtime.config.DialectVersions; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
/** | ||
* Tests that the workaround for https://github.com/quarkusio/quarkus/issues/43703 / | ||
* https://github.com/quarkusio/quarkus/issues/42255 | ||
* is effective. | ||
*/ | ||
// TODO remove this test when change the default to "always enabled" when we solve version detection problems | ||
// See https://github.com/quarkusio/quarkus/issues/43703 | ||
// See https://github.com/quarkusio/quarkus/issues/42255 | ||
public class DbVersionCheckDisabledAutomaticallyTest { | ||
|
||
private static final String ACTUAL_H2_VERSION = DialectVersions.Defaults.H2; | ||
// We will set the DB version to something higher than the actual version: this is invalid. | ||
private static final String CONFIGURED_DB_VERSION = "999.999.0"; | ||
static { | ||
assertThat(ACTUAL_H2_VERSION) | ||
.as("Test setup - we need the required version to be different from the actual one") | ||
.doesNotStartWith(CONFIGURED_DB_VERSION); | ||
} | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClass(SmokeTestUtils.class) | ||
.addClass(MyEntity.class)) | ||
.withConfigurationResource("application.properties") | ||
.overrideConfigKey("quarkus.datasource.db-version", "999.999") | ||
// Setting a dialect should disable the version check, so Quarkus should boot just fine | ||
.overrideConfigKey("quarkus.hibernate-orm.dialect", H2Dialect.class.getName()); | ||
|
||
@Inject | ||
SessionFactory sessionFactory; | ||
|
||
@Inject | ||
Session session; | ||
|
||
@Test | ||
public void dialectVersion() { | ||
var dialectVersion = sessionFactory.unwrap(SessionFactoryImplementor.class).getJdbcServices().getDialect().getVersion(); | ||
assertThat(DialectVersions.toString(dialectVersion)).isEqualTo(CONFIGURED_DB_VERSION); | ||
} | ||
|
||
@Test | ||
@Transactional | ||
public void smokeTest() { | ||
SmokeTestUtils.testSimplePersistRetrieveUpdateDelete(session, | ||
MyEntity.class, MyEntity::new, | ||
MyEntity::getId, | ||
MyEntity::setName, MyEntity::getName); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...st/java/io/quarkus/hibernate/orm/config/dialect/DbVersionCheckDisabledExplicitlyTest.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,68 @@ | ||
package io.quarkus.hibernate.orm.config.dialect; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.transaction.Transactional; | ||
|
||
import org.hibernate.Session; | ||
import org.hibernate.SessionFactory; | ||
import org.hibernate.engine.spi.SessionFactoryImplementor; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.hibernate.orm.MyEntity; | ||
import io.quarkus.hibernate.orm.SmokeTestUtils; | ||
import io.quarkus.hibernate.orm.runtime.config.DialectVersions; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
/** | ||
* Tests that the workaround for https://github.com/quarkusio/quarkus/issues/43703 / | ||
* https://github.com/quarkusio/quarkus/issues/42255 | ||
* is effective. | ||
*/ | ||
// TODO remove this test when change the default to "always enabled" when we solve version detection problems | ||
// See https://github.com/quarkusio/quarkus/issues/43703 | ||
// See https://github.com/quarkusio/quarkus/issues/42255 | ||
public class DbVersionCheckDisabledExplicitlyTest { | ||
|
||
private static final String ACTUAL_H2_VERSION = DialectVersions.Defaults.H2; | ||
// We will set the DB version to something higher than the actual version: this is invalid. | ||
private static final String CONFIGURED_DB_VERSION = "999.999.0"; | ||
static { | ||
assertThat(ACTUAL_H2_VERSION) | ||
.as("Test setup - we need the required version to be different from the actual one") | ||
.doesNotStartWith(CONFIGURED_DB_VERSION); | ||
} | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClass(SmokeTestUtils.class) | ||
.addClass(MyEntity.class)) | ||
.withConfigurationResource("application.properties") | ||
.overrideConfigKey("quarkus.datasource.db-version", "999.999") | ||
// We disable the version check explicitly, so Quarkus should boot just fine | ||
.overrideConfigKey("quarkus.hibernate-orm.database.version-check.enabled", "false"); | ||
|
||
@Inject | ||
SessionFactory sessionFactory; | ||
|
||
@Inject | ||
Session session; | ||
|
||
@Test | ||
public void dialectVersion() { | ||
var dialectVersion = sessionFactory.unwrap(SessionFactoryImplementor.class).getJdbcServices().getDialect().getVersion(); | ||
assertThat(DialectVersions.toString(dialectVersion)).isEqualTo(CONFIGURED_DB_VERSION); | ||
} | ||
|
||
@Test | ||
@Transactional | ||
public void smokeTest() { | ||
SmokeTestUtils.testSimplePersistRetrieveUpdateDelete(session, | ||
MyEntity.class, MyEntity::new, | ||
MyEntity::getId, | ||
MyEntity::setName, MyEntity::getName); | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
.../resources/META-INF/some-persistence-with-h2-version-placeholder-and-explicit-dialect.xml
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,30 @@ | ||
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence | ||
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" | ||
version="2.1"> | ||
|
||
<persistence-unit name="templatePU" transaction-type="JTA"> | ||
|
||
<description>Hibernate test case template Persistence Unit</description> | ||
|
||
<class>io.quarkus.hibernate.orm.MyEntity</class> | ||
|
||
<properties> | ||
<property name="jakarta.persistence.database-product-name" value="H2"/> | ||
<!-- This placeholder is replaced programmatically in tests --> | ||
<property name="jakarta.persistence.database-product-version" value="${H2_VERSION}"/> | ||
|
||
<!-- | ||
Optimistically create the tables; | ||
will cause background errors being logged if they already exist, | ||
but is practical to retain existing data across runs (or create as needed) --> | ||
<property name="jakarta.persistence.schema-generation.database.action" value="drop-and-create"/> | ||
|
||
<property name="jakarta.persistence.validation.mode" value="NONE"/> | ||
|
||
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/> | ||
</properties> | ||
|
||
</persistence-unit> | ||
</persistence> |
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
Oops, something went wrong.