Test fixes

This commit is contained in:
jamesagnew 2018-08-19 16:12:35 -04:00
parent 6511545d25
commit 77e35f5a56
5 changed files with 55 additions and 36 deletions

View File

@ -76,6 +76,7 @@ public abstract class BaseSubscriptionInterceptor<S extends IBaseResource> exten
static final String SUBSCRIPTION_STATUS = "Subscription.status"; static final String SUBSCRIPTION_STATUS = "Subscription.status";
static final String SUBSCRIPTION_TYPE = "Subscription.channel.type"; static final String SUBSCRIPTION_TYPE = "Subscription.channel.type";
private static final Integer MAX_SUBSCRIPTION_RESULTS = 1000; private static final Integer MAX_SUBSCRIPTION_RESULTS = 1000;
private final Object myInitSubscriptionsLock = new Object();
private SubscribableChannel myProcessingChannel; private SubscribableChannel myProcessingChannel;
private Map<String, SubscribableChannel> myDeliveryChannel; private Map<String, SubscribableChannel> myDeliveryChannel;
private ExecutorService myProcessingExecutor; private ExecutorService myProcessingExecutor;
@ -362,6 +363,7 @@ public abstract class BaseSubscriptionInterceptor<S extends IBaseResource> exten
} }
public Integer doInitSubscriptions() { public Integer doInitSubscriptions() {
synchronized (myInitSubscriptionsLock) {
ourLog.debug("Starting init subscriptions"); ourLog.debug("Starting init subscriptions");
SearchParameterMap map = new SearchParameterMap(); SearchParameterMap map = new SearchParameterMap();
map.add(Subscription.SP_TYPE, new TokenParam(null, getChannelType().toCode())); map.add(Subscription.SP_TYPE, new TokenParam(null, getChannelType().toCode()));
@ -396,6 +398,7 @@ public abstract class BaseSubscriptionInterceptor<S extends IBaseResource> exten
return changesCount; return changesCount;
} }
}
@SuppressWarnings("unused") @SuppressWarnings("unused")
@PreDestroy @PreDestroy

View File

@ -4,6 +4,7 @@ import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.jpa.dao.SearchParameterMap; import ca.uhn.fhir.jpa.dao.SearchParameterMap;
import ca.uhn.fhir.jpa.dao.data.ISearchDao; import ca.uhn.fhir.jpa.dao.data.ISearchDao;
import ca.uhn.fhir.jpa.entity.Search; import ca.uhn.fhir.jpa.entity.Search;
import ca.uhn.fhir.jpa.entity.SearchStatusEnum;
import ca.uhn.fhir.jpa.search.StaleSearchDeletingSvcImpl; import ca.uhn.fhir.jpa.search.StaleSearchDeletingSvcImpl;
import ca.uhn.fhir.util.StopWatch; import ca.uhn.fhir.util.StopWatch;
import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.api.server.IBundleProvider;
@ -32,6 +33,7 @@ import static ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast;
import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@SuppressWarnings("Duplicates")
public class FhirResourceDaoR4SearchPageExpiryTest extends BaseJpaR4Test { public class FhirResourceDaoR4SearchPageExpiryTest extends BaseJpaR4Test {
private static final Logger ourLog = LoggerFactory.getLogger(FhirResourceDaoR4SearchPageExpiryTest.class); private static final Logger ourLog = LoggerFactory.getLogger(FhirResourceDaoR4SearchPageExpiryTest.class);
@ -404,7 +406,7 @@ public class FhirResourceDaoR4SearchPageExpiryTest extends BaseJpaR4Test {
Search search = null; Search search = null;
for (int i = 0; i < 20 && search == null; i++) { for (int i = 0; i < 20 && search == null; i++) {
search = theSearchEntityDao.findByUuid(theUuid); search = theSearchEntityDao.findByUuid(theUuid);
if (search == null) { if (search == null || search.getStatus() == SearchStatusEnum.LOADING) {
sleepAtLeast(100); sleepAtLeast(100);
} }
} }

View File

@ -15,6 +15,7 @@ import ca.uhn.fhir.rest.client.api.IGenericClient;
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException;
import ca.uhn.fhir.rest.server.interceptor.CorsInterceptor; import ca.uhn.fhir.rest.server.interceptor.CorsInterceptor;
import ca.uhn.fhir.util.PortUtil; import ca.uhn.fhir.util.PortUtil;
import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.TestUtil;
@ -46,6 +47,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.junit.Assert.fail;
public abstract class BaseResourceProviderR4Test extends BaseJpaR4Test { public abstract class BaseResourceProviderR4Test extends BaseJpaR4Test {
@ -205,6 +207,18 @@ public abstract class BaseResourceProviderR4Test extends BaseJpaR4Test {
} }
protected void waitForRegisteredSubscriptionCount(int theSize) throws Exception { protected void waitForRegisteredSubscriptionCount(int theSize) throws Exception {
for (int i = 0; i++;) {
if (i == 10) {
fail("Failed to init subscriptions");
}
try {
getRestHookSubscriptionInterceptor().doInitSubscriptions();
break;
} catch (ResourceVersionConflictException e) {
Thread.sleep(250);
}
}
SubscriptionRestHookInterceptor interceptor = getRestHookSubscriptionInterceptor(); SubscriptionRestHookInterceptor interceptor = getRestHookSubscriptionInterceptor();
TestUtil.waitForSize(theSize, () -> interceptor.getRegisteredSubscriptions().size()); TestUtil.waitForSize(theSize, () -> interceptor.getRegisteredSubscriptions().size());
Thread.sleep(500); Thread.sleep(500);