Skip to content

[#265]: Validator to properly shutdown, so not to fail further invocations on the same JVM process. #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 21, 2024
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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,9 @@ See the [documentation on Initializer's logging properties](readme/rtprops.md#lo
#### Version 2.7.0
* Added support for 'queues' domain.
* Added support for 'addresshierarchy' domain.
* Fix for Liquibase Loader to ensure compatibility with OpenMRS versions 2.5.5+
* Fix for OCL Loader to ensure it throws an Exception if the OCL import fails
* Fix for Liquibase Loader to ensure compatibility with OpenMRS versions 2.5.5+.
* Fix for OCL Loader to ensure it throws an Exception if the OCL import fails.
* Fix for Validator to not encounter failure upon repeated execution on the same JVM process.

#### Version 2.6.0
* Added support for 'cohorttypes' and 'cohortattributetypes' domains.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import java.util.Optional;
import java.util.Properties;
import java.util.stream.Stream;

import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.Rollback;
import org.apache.commons.lang.StringUtils;
import org.dbunit.DatabaseUnitException;
Expand Down Expand Up @@ -53,12 +56,15 @@
import org.testcontainers.containers.MySQLContainer;
import ch.vorburger.exec.ManagedProcessException;

@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this annotation does anything because of how BaseContextSenstitiveTest is defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually does, as it forces the recreation of a new Spring application context on the next run. Also BaseContextSenstitiveTest extends AbstractJUnit4SpringContextTests which theoretically means being able to hook into the Spring context life-cycle.

public class ConfigurationTester extends DomainBaseModuleContextSensitiveTest {

protected static final Logger log = LoggerFactory.getLogger(ConfigurationTester.class);

private static MySQLContainer mysqlContainer = new MySQLContainer("mysql:5.7.31");

private static ConfigurableApplicationContext storedApplicationContext;

private String configDirPath;

private String cielFilePath;
Expand All @@ -74,6 +80,7 @@ public static void setupMySqlDb() throws IOException {
mysqlContainer.withPassword("");
mysqlContainer.withCommand("mysqld --character-set-server=utf8 --collation-server=utf8_general_ci");
mysqlContainer.start();

}

protected void setupDatabaseProps(Properties props) throws ManagedProcessException, URISyntaxException {
Expand Down Expand Up @@ -233,12 +240,16 @@ public void conclude() throws URISyntaxException {
}
Assert.assertThat(sb.toString(), Validator.errors, is(empty()));
super.getConnection();
storedApplicationContext = (ConfigurableApplicationContext) applicationContext;
}

@AfterClass
public static void tearDownAfterClass() throws Exception {
if (null != mysqlContainer) {
mysqlContainer.stop();
}
if (null != storedApplicationContext) {
storedApplicationContext.close();
}
}
}
Loading