KEYCLOAK-2795 Testsuite fails sometimes with NPE in LockServiceFactory.getLockService

This commit is contained in:
mposolda 2016-04-11 10:05:32 +02:00
parent dccc338622
commit 65f94fdf84

View file

@ -69,6 +69,7 @@ public class DefaultLiquibaseConnectionProvider implements LiquibaseConnectionPr
protected void baseLiquibaseInitialization() { protected void baseLiquibaseInitialization() {
ServiceLocator sl = ServiceLocator.getInstance(); ServiceLocator sl = ServiceLocator.getInstance();
sl.setResourceAccessor(new ClassLoaderResourceAccessor(getClass().getClassLoader()));
if (!System.getProperties().containsKey("liquibase.scan.packages")) { if (!System.getProperties().containsKey("liquibase.scan.packages")) {
if (sl.getPackages().remove("liquibase.core")) { if (sl.getPackages().remove("liquibase.core")) {
@ -85,6 +86,10 @@ public class DefaultLiquibaseConnectionProvider implements LiquibaseConnectionPr
sl.getPackages().remove("liquibase.ext"); sl.getPackages().remove("liquibase.ext");
sl.getPackages().remove("liquibase.sdk"); sl.getPackages().remove("liquibase.sdk");
String lockPackageName = DummyLockService.class.getPackage().getName();
logger.debugf("Added package %s to liquibase", lockPackageName);
sl.addPackageToScan(lockPackageName);
} }
LogFactory.setInstance(new LogWrapper()); LogFactory.setInstance(new LogWrapper());
@ -129,10 +134,6 @@ public class DefaultLiquibaseConnectionProvider implements LiquibaseConnectionPr
String changelog = (database instanceof DB2Database) ? LiquibaseJpaUpdaterProvider.DB2_CHANGELOG : LiquibaseJpaUpdaterProvider.CHANGELOG; String changelog = (database instanceof DB2Database) ? LiquibaseJpaUpdaterProvider.DB2_CHANGELOG : LiquibaseJpaUpdaterProvider.CHANGELOG;
logger.debugf("Using changelog file: %s", changelog); logger.debugf("Using changelog file: %s", changelog);
// We wrap liquibase update in CustomLockService provided by DBLockProvider. No need to lock inside liquibase itself.
// NOTE: This can't be done in baseLiquibaseInitialization() as liquibase always restarts lock service
LockServiceFactory.getInstance().register(new DummyLockService());
return new Liquibase(changelog, new ClassLoaderResourceAccessor(getClass().getClassLoader()), database); return new Liquibase(changelog, new ClassLoaderResourceAccessor(getClass().getClassLoader()), database);
} }