Merge branch 'rel_5_7'

This commit is contained in:
Tadgh 2022-02-04 22:22:02 -08:00
commit 1af4912603
3 changed files with 16 additions and 11 deletions

View File

@ -524,8 +524,8 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> extends BaseStora
.map(Throwable::getMessage) .map(Throwable::getMessage)
.collect(Collectors.joining(", ")); .collect(Collectors.joining(", "));
throw new InternalErrorException( throw new InternalErrorException(
Msg.code(2019) + Msg.code(2023)
"Tag get/create failed after " + "Tag get/create failed after "
+ TOTAL_TAG_READ_ATTEMPTS + TOTAL_TAG_READ_ATTEMPTS
+ " attempts with error(s): " + " attempts with error(s): "
+ msg + msg

View File

@ -15,7 +15,6 @@ import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
@ -149,7 +148,6 @@ public class BaseHapiFhirDaoTest {
return from; return from;
} }
@Disabled
@Test @Test
public void getTagOrNull_raceCondition_wontUpsertDuplicates() throws InterruptedException, ExecutionException { public void getTagOrNull_raceCondition_wontUpsertDuplicates() throws InterruptedException, ExecutionException {
/* /*
@ -179,7 +177,6 @@ public class BaseHapiFhirDaoTest {
String scheme = "http://localhost"; String scheme = "http://localhost";
String term = "code123"; String term = "code123";
String label = "hollow world"; String label = "hollow world";
TransactionDetails transactionDetails = new TransactionDetails();
String raceConditionError = "Entity exists; if this is logged, you have race condition issues!"; String raceConditionError = "Entity exists; if this is logged, you have race condition issues!";
TagDefinition tagDefinition = new TagDefinition(tagType, TagDefinition tagDefinition = new TagDefinition(tagType,
@ -275,7 +272,7 @@ public class BaseHapiFhirDaoTest {
Runnable task = () -> { Runnable task = () -> {
latch.countDown(); latch.countDown();
try { try {
TagDefinition retTag = myTestDao.getTagOrNull(transactionDetails, tagType, scheme, term, label); TagDefinition retTag = myTestDao.getTagOrNull(new TransactionDetails(), tagType, scheme, term, label);
outcomes.put(retTag.hashCode(), retTag); outcomes.put(retTag.hashCode(), retTag);
counter.incrementAndGet(); counter.incrementAndGet();
} catch (Exception ex) { } catch (Exception ex) {
@ -367,7 +364,7 @@ public class BaseHapiFhirDaoTest {
fail(); fail();
} catch (Exception ex) { } catch (Exception ex) {
// verify // verify
assertEquals("HAPI-2019: Tag get/create failed after 10 attempts with error(s): " + exMsg, ex.getMessage()); assertTrue(ex.getMessage().contains("Tag get/create failed after 10 attempts with error(s): " + exMsg));
ArgumentCaptor<ILoggingEvent> appenderCaptor = ArgumentCaptor.forClass(ILoggingEvent.class); ArgumentCaptor<ILoggingEvent> appenderCaptor = ArgumentCaptor.forClass(ILoggingEvent.class);
verify(myAppender, Mockito.times(10)) verify(myAppender, Mockito.times(10))

View File

@ -3,6 +3,7 @@ package ca.uhn.fhir.jpa.dao.r4;
import ca.uhn.fhir.i18n.Msg; import ca.uhn.fhir.i18n.Msg;
import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.api.config.DaoConfig;
import ca.uhn.fhir.jpa.api.model.DaoMethodOutcome; import ca.uhn.fhir.jpa.api.model.DaoMethodOutcome;
import ca.uhn.fhir.jpa.config.TestR4Config;
import ca.uhn.fhir.jpa.model.entity.ModelConfig; import ca.uhn.fhir.jpa.model.entity.ModelConfig;
import ca.uhn.fhir.jpa.model.entity.NormalizedQuantitySearchLevel; import ca.uhn.fhir.jpa.model.entity.NormalizedQuantitySearchLevel;
import ca.uhn.fhir.jpa.model.entity.ResourceHistoryTable; import ca.uhn.fhir.jpa.model.entity.ResourceHistoryTable;
@ -60,7 +61,10 @@ import java.util.concurrent.Future;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.matchesPattern;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
@ -1009,8 +1013,10 @@ public class FhirResourceDaoR4CreateTest extends BaseJpaR4Test {
@Test @Test
public void testResourceWithTagCreationNoFailures() throws ExecutionException, InterruptedException { public void testResourceWithTagCreationNoFailures() throws ExecutionException, InterruptedException {
// this was 5, but our random connection pool runs as small as 3, and this solution needs a spare connection to be safe. // we need to leave at least one free thread
ExecutorService pool = Executors.newFixedThreadPool(2); // due to a REQUIRED_NEW transaction internally
int maxThreadsUsed = TestR4Config.ourMaxThreads - 1;
ExecutorService pool = Executors.newFixedThreadPool(Math.min(maxThreadsUsed, 5));
try { try {
Coding tag = new Coding(); Coding tag = new Coding();
tag.setCode("code123"); tag.setCode("code123");
@ -1035,7 +1041,9 @@ public class FhirResourceDaoR4CreateTest extends BaseJpaR4Test {
try { try {
myPatientDao.update(updatePatient); myPatientDao.update(updatePatient);
} catch (ResourceVersionConflictException e) { } catch (ResourceVersionConflictException e) {
assertThat(e.getMessage(), startsWith(Msg.code(550) + Msg.code(823))); assertTrue(e.getMessage().contains(
"The operation has failed with a version constraint failure. This generally means that two clients/threads were trying to update the same resource at the same time, and this request was chosen as the failing request."
));
} }
} catch (Exception e) { } catch (Exception e) {
ourLog.error("Failure", e); ourLog.error("Failure", e);