Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2452,7 +2452,9 @@ public void scheduleJobs(ISchedulerService theSchedulerService) {
ScheduledJobDefinition vsJobDefinition = new ScheduledJobDefinition();
vsJobDefinition.setId(getClass().getName());
vsJobDefinition.setJobClass(Job.class);
theSchedulerService.scheduleClusteredJob(10 * DateUtils.MILLIS_PER_MINUTE, vsJobDefinition);
theSchedulerService.scheduleClusteredJob(
myStorageSettings.getPreExpandValueSetsScheduleInMinutes() * DateUtils.MILLIS_PER_MINUTE,
vsJobDefinition);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package ca.uhn.fhir.jpa.term;

import ca.uhn.fhir.jpa.api.config.JpaStorageSettings;
import ca.uhn.fhir.jpa.model.sched.ISchedulerService;
import ca.uhn.fhir.jpa.model.sched.ScheduledJobDefinition;
import org.apache.commons.lang3.time.DateUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;

@ExtendWith(MockitoExtension.class)
class TermReadSvcImplTest {

@InjectMocks
private TermReadSvcImpl termReadService;

@Spy
private JpaStorageSettings storageSettings = new JpaStorageSettings();

@Mock
private ISchedulerService schedulerService;

@Test
void testScheduleJobs_whenDefaultInterval_shouldScheduleCorrectly() {
// Setup - using real JpaStorageSettings with default value
int defaultMinutes = storageSettings.getPreExpandValueSetsScheduleInMinutes();

ArgumentCaptor<Long> millisCaptor = ArgumentCaptor.forClass(Long.class);
ArgumentCaptor<ScheduledJobDefinition> jobCaptor = ArgumentCaptor.forClass(ScheduledJobDefinition.class);

// Execute
termReadService.scheduleJobs(schedulerService);

// Verify
verify(schedulerService).scheduleClusteredJob(millisCaptor.capture(), jobCaptor.capture());

long expectedMillis = defaultMinutes * DateUtils.MILLIS_PER_MINUTE;
assertEquals(expectedMillis, millisCaptor.getValue(),
"Interval should match default configuration (" + defaultMinutes + " minutes)");

ScheduledJobDefinition job = jobCaptor.getValue();
assertEquals(TermReadSvcImpl.class.getName(), job.getId());
assertEquals(TermReadSvcImpl.Job.class, job.getJobClass());
}

@Test
void testScheduleJobs_whenCustomInterval_shouldUseOverriddenValue() {
// Setup - override the default with custom value
int customMinutes = 30;
storageSettings.setPreExpandValueSetsScheduleInMinutes(customMinutes);

ArgumentCaptor<Long> millisCaptor = ArgumentCaptor.forClass(Long.class);

// Execute
termReadService.scheduleJobs(schedulerService);

// Verify
verify(schedulerService).scheduleClusteredJob(millisCaptor.capture(), any(ScheduledJobDefinition.class));
assertEquals(customMinutes * DateUtils.MILLIS_PER_MINUTE, millisCaptor.getValue(),
"Interval should match overridden value");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public class JpaStorageSettings extends StorageSettings {

public static final List<Integer> DEFAULT_SEARCH_PRE_FETCH_THRESHOLDS = Arrays.asList(13, 503, 2003, 1000003, -1);

private static final int DEFAULT_PRE_EXPAND_VALUE_SETS_SCHEDULE_IN_MINUTES = 10;
/**
* Do not change default of {@code 0}!
*
Expand Down Expand Up @@ -426,6 +427,13 @@ public class JpaStorageSettings extends StorageSettings {
*/
private boolean myWriteToSearchParamIdentityTable = true;

/**
* Controls the schedule time in minutes for pre expand value set job.
* Defaults to {@code 10}.
* @since 8.8.0
*/
private int myPreExpandValueSetsScheduleInMinutes = DEFAULT_PRE_EXPAND_VALUE_SETS_SCHEDULE_IN_MINUTES;

/**
* Constructor
*/
Expand Down Expand Up @@ -2738,6 +2746,24 @@ public void setWriteToSearchParamIdentityTable(boolean theWriteToSearchParamIden
myWriteToSearchParamIdentityTable = theWriteToSearchParamIdentityTable;
}

/**
* Controls the schedule time in minutes for pre expand value set job.
* Defaults to {@code 10}.
* @since 8.8.0
*/
public int getPreExpandValueSetsScheduleInMinutes() {
return myPreExpandValueSetsScheduleInMinutes;
}

/**
* Controls the schedule time in minutes for pre expand value set job.
* Defaults to {@code 10}.
* @since 8.8.0
*/
public void setPreExpandValueSetsScheduleInMinutes(int thePreExpandValueSetsScheduleInMinutes) {
myPreExpandValueSetsScheduleInMinutes = thePreExpandValueSetsScheduleInMinutes;
}

public enum StoreMetaSourceInformationEnum {
NONE(false, false),
SOURCE_URI(true, false),
Expand Down
Loading