Avoid blocking on shutdown (#2206)

This commit is contained in:
James Agnew 2020-12-02 08:44:06 -05:00 committed by GitHub
parent 6e72ee8f6b
commit 30b6244988
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 4 deletions

View File

@ -103,17 +103,22 @@ public class ResourceChangeListenerCacheRefresherImpl implements IResourceChange
return retval;
}
@Override
public ResourceChangeResult refreshCacheAndNotifyListener(IResourceChangeListenerCache theCache) {
ResourceChangeResult retval = new ResourceChangeResult();
ResourceChangeResult retVal = new ResourceChangeResult();
if (mySchedulerService.isStopping()) {
ourLog.info("Scheduler service is stopping, aborting cache refresh");
return retVal;
}
if (!myResourceChangeListenerRegistry.contains(theCache)) {
ourLog.warn("Requesting cache refresh for unregistered listener {}. Aborting.", theCache);
return new ResourceChangeResult();
return retVal;
}
SearchParameterMap searchParamMap = theCache.getSearchParameterMap();
ResourceVersionMap newResourceVersionMap = myResourceVersionSvc.getVersionMap(theCache.getResourceName(), searchParamMap);
retval = retval.plus(notifyListener(theCache, newResourceVersionMap));
retVal = retVal.plus(notifyListener(theCache, newResourceVersionMap));
return retval;
return retVal;
}
/**

View File

@ -22,6 +22,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
@ExtendWith(SpringExtension.class)
@ -70,4 +71,16 @@ class ResourceChangeListenerCacheRefresherImplTest {
assertTrue(cache.isInitialized());
verifyNoInteractions(listener);
}
@Test
public void testNoActionOnStoppingScheduler() {
when(mySchedulerService.isStopping()).thenReturn(true);
IResourceChangeListener listener = mock(IResourceChangeListener.class);
ResourceChangeListenerCache cache = new ResourceChangeListenerCache(PATIENT_RESOURCE_NAME, listener, ourMap, TEST_REFRESH_INTERVAL_MS);
myResourceChangeListenerCacheRefresher.refreshCacheAndNotifyListener(cache);
verify(myResourceVersionSvc, times(0)).getVersionMap(any(), any());
}
}