From 13b80a294a45106cf2575802a76cea1d62f2a571 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Fri, 18 Oct 2019 07:13:11 -0400 Subject: [PATCH] Test fix --- .../FhirResourceDaoR4SearchOptimizedTest.java | 5 +++ .../jpa/migrate/taskdef/DropIndexTask.java | 31 ++++++++++--------- .../jpa/migrate/taskdef/DropTableTask.java | 9 ++++-- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchOptimizedTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchOptimizedTest.java index 896a8c07def..79ea77031dc 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchOptimizedTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchOptimizedTest.java @@ -302,6 +302,11 @@ public class FhirResourceDaoR4SearchOptimizedTest extends BaseJpaR4Test { * 20 should be prefetched since that's the initial page size */ + await().until(()-> runInTransaction(()->{ + Search search = mySearchEntityDao.findByUuidAndFetchIncludes(uuid).orElseThrow(() -> new InternalErrorException("")); + return search.getNumFound() >= 200; + })); + runInTransaction(() -> { Search search = mySearchEntityDao.findByUuidAndFetchIncludes(uuid).orElseThrow(() -> new InternalErrorException("")); assertEquals(200, search.getNumFound()); diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIndexTask.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIndexTask.java index dd42aa1cb2d..18da17ee023 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIndexTask.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIndexTask.java @@ -26,8 +26,8 @@ import org.apache.commons.lang3.Validate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.Nonnull; import java.sql.SQLException; +import java.util.Optional; import java.util.Set; public class DropIndexTask extends BaseTableTask { @@ -56,18 +56,27 @@ public class DropIndexTask extends BaseTableTask { boolean isUnique = JdbcUtils.isIndexUnique(getConnectionProperties(), getTableName(), myIndexName); String uniquenessString = isUnique ? "unique" : "non-unique"; - ourLog.info("Dropping {} index {} on table {}", uniquenessString, myIndexName, getTableName()); - - String sql = createDropIndexSql(getConnectionProperties(), getTableName(), myIndexName, getDriverType()); - executeSql(getTableName(), sql); + Optional sql = createDropIndexSql(getConnectionProperties(), getTableName(), myIndexName, getDriverType()); + if (sql.isPresent()) { + ourLog.info("Dropping {} index {} on table {}", uniquenessString, myIndexName, getTableName()); + executeSql(getTableName(), sql.get()); + } } - @Nonnull - static String createDropIndexSql(DriverTypeEnum.ConnectionProperties theConnectionProperties, String theTableName, String theIndexName, DriverTypeEnum theDriverType) throws SQLException { + public DropIndexTask setIndexName(String theIndexName) { + myIndexName = theIndexName; + return this; + } + + static Optional createDropIndexSql(DriverTypeEnum.ConnectionProperties theConnectionProperties, String theTableName, String theIndexName, DriverTypeEnum theDriverType) throws SQLException { Validate.notBlank(theIndexName, "theIndexName must not be blank"); Validate.notBlank(theTableName, "theTableName must not be blank"); + if (!JdbcUtils.getIndexNames(theConnectionProperties, theTableName).contains(theIndexName)) { + return Optional.empty(); + } + boolean isUnique = JdbcUtils.isIndexUnique(theConnectionProperties, theTableName, theIndexName); String sql = null; @@ -109,12 +118,6 @@ public class DropIndexTask extends BaseTableTask { break; } } - return sql; - } - - - public DropIndexTask setIndexName(String theIndexName) { - myIndexName = theIndexName; - return this; + return Optional.of(sql); } } diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropTableTask.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropTableTask.java index d628fc99799..135c5544681 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropTableTask.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropTableTask.java @@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory; import java.sql.SQLException; import java.util.List; +import java.util.Optional; import java.util.Set; public class DropTableTask extends BaseTableTask { @@ -53,9 +54,11 @@ public class DropTableTask extends BaseTableTask { } for (String nextIndex : indexNames) { - String sql = DropIndexTask.createDropIndexSql(getConnectionProperties(), getTableName(), nextIndex, getDriverType()); - ourLog.info("Dropping index {} on table {} in preparation for table delete", nextIndex, getTableName()); - executeSql(getTableName(), sql); + Optional sql = DropIndexTask.createDropIndexSql(getConnectionProperties(), getTableName(), nextIndex, getDriverType()); + if (sql.isPresent()) { + ourLog.info("Dropping index {} on table {} in preparation for table delete", nextIndex, getTableName()); + executeSql(getTableName(), sql.get()); + } } ourLog.info("Dropping table: {}", getTableName());