Changes from code review
This commit is contained in:
parent
46abdfafe0
commit
4e5ca2ee15
|
@ -50,6 +50,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.transaction.support.TransactionTemplate;
|
import org.springframework.transaction.support.TransactionTemplate;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -145,10 +146,10 @@ public class TermDeferredStorageSvcImpl implements ITermDeferredStorageSvc {
|
||||||
ourLog.info("Saving {} deferred concepts...", count);
|
ourLog.info("Saving {} deferred concepts...", count);
|
||||||
while (codeCount < count && myDeferredConcepts.size() > 0) {
|
while (codeCount < count && myDeferredConcepts.size() > 0) {
|
||||||
TermConcept next = myDeferredConcepts.remove(0);
|
TermConcept next = myDeferredConcepts.remove(0);
|
||||||
if(myCodeSystemVersionDao.findById(next.getCodeSystemVersion().getPid()).isPresent()) {
|
try {
|
||||||
codeCount += myCodeSystemStorageSvc.saveConcept(next);
|
codeCount += myCodeSystemStorageSvc.saveConcept(next);
|
||||||
} else {
|
} catch (Exception theE) {
|
||||||
ourLog.warn("Unable to save deferred TermConcept {} because Code System {} version PID {} is no longer valid. Code system may have since been replaced.",
|
ourLog.warn("Unable to save deferred TermConcept {}, possibly because Code System {} version PID {} may have since been replaced.",
|
||||||
next.getCode(), next.getCodeSystemVersion().getCodeSystemDisplayName(), next.getCodeSystemVersion().getPid());
|
next.getCode(), next.getCodeSystemVersion().getCodeSystemDisplayName(), next.getCodeSystemVersion().getPid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,28 @@ public class TermCodeSystemStorageSvcTest extends BaseJpaR4Test {
|
||||||
|
|
||||||
public static final String URL_MY_CODE_SYSTEM = "http://example.com/my_code_system";
|
public static final String URL_MY_CODE_SYSTEM = "http://example.com/my_code_system";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStoreNewCodeSystemVersionForExistingCodeSystem() {
|
||||||
|
CodeSystem upload = createCodeSystemWithMoreThan100Concepts();
|
||||||
|
|
||||||
|
// Create CodeSystem resource
|
||||||
|
ResourceTable codeSystemResourceEntity = (ResourceTable)myCodeSystemDao.create(upload, mySrd).getEntity();
|
||||||
|
|
||||||
|
// Update the CodeSystem resource
|
||||||
|
runInTransaction(() -> myTermCodeSystemStorageSvc.storeNewCodeSystemVersionIfNeeded(upload, codeSystemResourceEntity));
|
||||||
|
|
||||||
|
/*
|
||||||
|
Because there are more than 100 concepts in the code system, the first 100 will be persisted immediately and
|
||||||
|
the remaining 25 concepts will be queued up for "deferred save".
|
||||||
|
|
||||||
|
As the CodeSystem was persisted twice, the extra 25 term concepts will be queued twice, each with a different
|
||||||
|
CodeSystem version PID. Only one set of the term concepts should be persisted (i.e. 125 term concepts in total).
|
||||||
|
*/
|
||||||
|
myTerminologyDeferredStorageSvc.setProcessDeferred(true);
|
||||||
|
myTerminologyDeferredStorageSvc.saveDeferred();
|
||||||
|
assertEquals(125, myTermConceptDao.count());
|
||||||
|
}
|
||||||
|
|
||||||
private CodeSystem createCodeSystemWithMoreThan100Concepts() {
|
private CodeSystem createCodeSystemWithMoreThan100Concepts() {
|
||||||
CodeSystem codeSystem = new CodeSystem();
|
CodeSystem codeSystem = new CodeSystem();
|
||||||
codeSystem.setUrl(URL_MY_CODE_SYSTEM);
|
codeSystem.setUrl(URL_MY_CODE_SYSTEM);
|
||||||
|
@ -25,20 +47,5 @@ public class TermCodeSystemStorageSvcTest extends BaseJpaR4Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testStoreNewCodeSystemVersionForExistingCodeSystem() {
|
|
||||||
CodeSystem upload = createCodeSystemWithMoreThan100Concepts();
|
|
||||||
|
|
||||||
ResourceTable codeSystemResourceEntity = (ResourceTable)myCodeSystemDao.create(upload, mySrd).getEntity();
|
|
||||||
|
|
||||||
runInTransaction(() -> myTermCodeSystemStorageSvc.storeNewCodeSystemVersionIfNeeded(upload, codeSystemResourceEntity));
|
|
||||||
|
|
||||||
myTerminologyDeferredStorageSvc.setProcessDeferred(true);
|
|
||||||
myTerminologyDeferredStorageSvc.saveDeferred();
|
|
||||||
myTerminologyDeferredStorageSvc.saveDeferred();
|
|
||||||
|
|
||||||
assertEquals(125, myTermConceptDao.count());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,15 +13,12 @@ import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.same;
|
import static org.mockito.ArgumentMatchers.same;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class TermDeferredStorageSvcImplTest {
|
public class TermDeferredStorageSvcImplTest {
|
||||||
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private PlatformTransactionManager myTxManager;
|
private PlatformTransactionManager myTxManager;
|
||||||
@Mock
|
@Mock
|
||||||
|
@ -53,7 +50,6 @@ public class TermDeferredStorageSvcImplTest {
|
||||||
svc.setCodeSystemStorageSvcForUnitTest(myTermConceptStorageSvc);
|
svc.setCodeSystemStorageSvcForUnitTest(myTermConceptStorageSvc);
|
||||||
svc.setDaoConfigForUnitTest(new DaoConfig());
|
svc.setDaoConfigForUnitTest(new DaoConfig());
|
||||||
|
|
||||||
when(myTermCodeSystemVersionDao.findById(anyLong())).thenReturn(Optional.of(myTermCodeSystemVersion));
|
|
||||||
svc.setCodeSystemVersionDaoForUnitTest(myTermCodeSystemVersionDao);
|
svc.setCodeSystemVersionDaoForUnitTest(myTermCodeSystemVersionDao);
|
||||||
svc.setProcessDeferred(true);
|
svc.setProcessDeferred(true);
|
||||||
svc.addConceptToStorageQueue(concept);
|
svc.addConceptToStorageQueue(concept);
|
||||||
|
@ -76,11 +72,13 @@ public class TermDeferredStorageSvcImplTest {
|
||||||
svc.setCodeSystemStorageSvcForUnitTest(myTermConceptStorageSvc);
|
svc.setCodeSystemStorageSvcForUnitTest(myTermConceptStorageSvc);
|
||||||
svc.setDaoConfigForUnitTest(new DaoConfig());
|
svc.setDaoConfigForUnitTest(new DaoConfig());
|
||||||
|
|
||||||
|
when(myTermConceptStorageSvc.saveConcept(concept)).thenThrow(new RuntimeException("Foreign Constraint Violation"));
|
||||||
svc.setCodeSystemVersionDaoForUnitTest(myTermCodeSystemVersionDao);
|
svc.setCodeSystemVersionDaoForUnitTest(myTermCodeSystemVersionDao);
|
||||||
svc.setProcessDeferred(true);
|
svc.setProcessDeferred(true);
|
||||||
svc.addConceptToStorageQueue(concept);
|
svc.addConceptToStorageQueue(concept);
|
||||||
svc.saveDeferred();
|
svc.saveDeferred();
|
||||||
verify(myTermConceptStorageSvc, times(0)).saveConcept(same(concept));
|
|
||||||
|
verify(myTermConceptStorageSvc, times(1)).saveConcept(same(concept));
|
||||||
verifyNoMoreInteractions(myTermConceptStorageSvc);
|
verifyNoMoreInteractions(myTermConceptStorageSvc);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue