mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-02-16 18:05:19 +00:00
Test fixes
This commit is contained in:
parent
ce3b7c82ce
commit
055478e1f1
@ -487,10 +487,12 @@ public class TransactionProcessor<BUNDLE extends IBaseBundle, BUNDLEENTRY> {
|
||||
}
|
||||
|
||||
|
||||
private Map<BUNDLEENTRY, ResourceTable> doTransactionWriteOperations(ServletRequestDetails theRequestDetails, String theActionName, Date theUpdateTime, Set<IIdType> theAllIds,
|
||||
private Map<BUNDLEENTRY, ResourceTable> doTransactionWriteOperations(final ServletRequestDetails theRequestDetails, String theActionName, Date theUpdateTime, Set<IIdType> theAllIds,
|
||||
Map<IIdType, IIdType> theIdSubstitutions, Map<IIdType, DaoMethodOutcome> theIdToPersistedOutcome, BUNDLE theResponse, IdentityHashMap<BUNDLEENTRY, Integer> theOriginalRequestOrder, List<BUNDLEENTRY> theEntries, StopWatch theTransactionStopWatch) {
|
||||
|
||||
theRequestDetails.startDeferredOperationCallback();
|
||||
if (theRequestDetails != null) {
|
||||
theRequestDetails.startDeferredOperationCallback();
|
||||
}
|
||||
try {
|
||||
|
||||
Set<String> deletedResources = new HashSet<>();
|
||||
@ -771,7 +773,9 @@ public class TransactionProcessor<BUNDLE extends IBaseBundle, BUNDLEENTRY> {
|
||||
return entriesToProcess;
|
||||
|
||||
} finally {
|
||||
theRequestDetails.stopDeferredRequestOperationCallbackAndRunDeferredItems();
|
||||
if (theRequestDetails != null) {
|
||||
theRequestDetails.stopDeferredRequestOperationCallbackAndRunDeferredItems();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ import org.springframework.data.repository.query.Param;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
@ -55,4 +56,12 @@ public interface IResourceReindexJobDao extends JpaRepository<ResourceReindexJob
|
||||
@Modifying
|
||||
@Query("UPDATE ResourceReindexJobEntity j SET j.myThresholdLow = :low WHERE j.myId = :id")
|
||||
void setThresholdLow(@Param("id") Long theId, @Param("low") Date theLow);
|
||||
|
||||
@Query("SELECT j.myReindexCount FROM ResourceReindexJobEntity j WHERE j.myId = :id")
|
||||
Optional<Integer> getReindexCount(@Param("id") Long theId);
|
||||
|
||||
@Query("UPDATE ResourceReindexJobEntity j SET j.myReindexCount = :newCount WHERE j.myId = :id")
|
||||
@Modifying
|
||||
void setReindexCount(@Param("id") Long theId, @Param("newCount") int theNewCount);
|
||||
|
||||
}
|
||||
|
@ -55,6 +55,16 @@ public class ResourceReindexJobEntity implements Serializable {
|
||||
@Column(name = "SUSPENDED_UNTIL", nullable = true)
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date mySuspendedUntil;
|
||||
@Column(name = "REINDEX_COUNT", nullable = true)
|
||||
private Integer myReindexCount;
|
||||
|
||||
public Integer getReindexCount() {
|
||||
return myReindexCount;
|
||||
}
|
||||
|
||||
public void setReindexCount(Integer theReindexCount) {
|
||||
myReindexCount = theReindexCount;
|
||||
}
|
||||
|
||||
public Date getSuspendedUntil() {
|
||||
return mySuspendedUntil;
|
||||
|
@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.search.reindex;
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@ -20,22 +20,21 @@ package ca.uhn.fhir.jpa.search.reindex;
|
||||
* #L%
|
||||
*/
|
||||
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
public interface IResourceReindexingSvc {
|
||||
|
||||
/**
|
||||
* Marks all indexes as needing fresh indexing
|
||||
*
|
||||
* @return Returns the job ID
|
||||
*/
|
||||
void markAllResourcesForReindexing();
|
||||
Long markAllResourcesForReindexing();
|
||||
|
||||
/**
|
||||
* Marks all indexes of the given type as needing fresh indexing
|
||||
*
|
||||
* @return Returns the job ID
|
||||
*/
|
||||
void markAllResourcesForReindexing(String theType);
|
||||
Long markAllResourcesForReindexing(String theType);
|
||||
|
||||
/**
|
||||
* Called automatically by the job scheduler
|
||||
|
@ -150,13 +150,13 @@ public class ResourceReindexingSvcImpl implements IResourceReindexingSvc {
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void markAllResourcesForReindexing() {
|
||||
markAllResourcesForReindexing(null);
|
||||
public Long markAllResourcesForReindexing() {
|
||||
return markAllResourcesForReindexing(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void markAllResourcesForReindexing(String theType) {
|
||||
public Long markAllResourcesForReindexing(String theType) {
|
||||
String typeDesc;
|
||||
if (isNotBlank(theType)) {
|
||||
myReindexJobDao.markAllOfTypeAsDeleted(theType);
|
||||
@ -172,6 +172,7 @@ public class ResourceReindexingSvcImpl implements IResourceReindexingSvc {
|
||||
job = myReindexJobDao.saveAndFlush(job);
|
||||
|
||||
ourLog.info("Marking all resources of type {} for reindexing - Got job ID[{}]", typeDesc, job.getId());
|
||||
return job.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -338,6 +339,9 @@ public class ResourceReindexingSvcImpl implements IResourceReindexingSvc {
|
||||
|
||||
myTxTemplate.execute(t -> {
|
||||
myReindexJobDao.setThresholdLow(theJob.getId(), newLow);
|
||||
Integer existingCount = myReindexJobDao.getReindexCount(theJob.getId()).orElse(0);
|
||||
int newCount = existingCount + counter.get();
|
||||
myReindexJobDao.setReindexCount(theJob.getId(), newCount);
|
||||
return null;
|
||||
});
|
||||
|
||||
|
@ -528,7 +528,7 @@ public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest {
|
||||
ResourceTable entity = new TransactionTemplate(myTxManager).execute(t -> myEntityManager.find(ResourceTable.class, id.getIdPartAsLong()));
|
||||
assertEquals(Long.valueOf(1), entity.getIndexStatus());
|
||||
|
||||
myResourceReindexingSvc.markAllResourcesForReindexing();
|
||||
Long jobId = myResourceReindexingSvc.markAllResourcesForReindexing();
|
||||
myResourceReindexingSvc.forceReindexingPass();
|
||||
|
||||
entity = new TransactionTemplate(myTxManager).execute(t -> myEntityManager.find(ResourceTable.class, id.getIdPartAsLong()));
|
||||
@ -537,6 +537,17 @@ public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest {
|
||||
// Just make sure this doesn't cause a choke
|
||||
myResourceReindexingSvc.forceReindexingPass();
|
||||
|
||||
/*
|
||||
* We expect a final reindex count of 3 because there are 2 resources to
|
||||
* reindex and the final pass uses the most recent time as the low threshold,
|
||||
* so it indexes the newest resource one more time. It wouldn't be a big deal
|
||||
* if this ever got fixed so that it ends up with 2 instead of 3.
|
||||
*/
|
||||
runInTransaction(()->{
|
||||
Optional<Integer> reindexCount = myResourceReindexJobDao.getReindexCount(jobId);
|
||||
assertEquals(3, reindexCount.orElseThrow(()->new NullPointerException("No job " + jobId)).intValue());
|
||||
});
|
||||
|
||||
// Try making the resource unparseable
|
||||
|
||||
TransactionTemplate template = new TransactionTemplate(myTxManager);
|
||||
|
Loading…
x
Reference in New Issue
Block a user