diff --git a/src/Microsoft.Health.Fhir.Core/Features/Operations/Reindex/ReindexJobTask.cs b/src/Microsoft.Health.Fhir.Core/Features/Operations/Reindex/ReindexJobTask.cs index ccc1b2dedc..37e7078855 100644 --- a/src/Microsoft.Health.Fhir.Core/Features/Operations/Reindex/ReindexJobTask.cs +++ b/src/Microsoft.Health.Fhir.Core/Features/Operations/Reindex/ReindexJobTask.cs @@ -191,7 +191,7 @@ private async Task TryPopulateNewJobFields(CancellationToken cancellationT // Find search parameters not in a final state such as supported, pendingDelete, pendingDisable. List validStatus = new List() { SearchParameterStatus.Supported, SearchParameterStatus.PendingDelete, SearchParameterStatus.PendingDisable }; var searchParamStatusCollection = await _searchParameterStatusManager.GetAllSearchParameterStatus(cancellationToken); - var possibleNotYetIndexedParams = _searchParameterDefinitionManager.AllSearchParameters.Where(sp => validStatus.Contains(searchParamStatusCollection.First(p => p.Uri == sp.Url).Status) || sp.IsSearchable == false || sp.SortStatus == SortParameterStatus.Supported); + var possibleNotYetIndexedParams = _searchParameterDefinitionManager.AllSearchParameters.Where(sp => validStatus.Contains(searchParamStatusCollection.First(p => p.Uri == sp.Url).Status)); var notYetIndexedParams = new List(); var resourceList = new HashSet(); diff --git a/src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Operations/Reindex/ReindexJobTaskTests.cs b/src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Operations/Reindex/ReindexJobTaskTests.cs index d478cd040c..f8afb104e3 100644 --- a/src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Operations/Reindex/ReindexJobTaskTests.cs +++ b/src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Operations/Reindex/ReindexJobTaskTests.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Threading; using MediatR; @@ -100,7 +101,7 @@ public async Task GivenSupportedParams_WhenExecuted_ThenCorrectSearchIsPerformed { // Get one search parameter and configure it such that it needs to be reindexed var param = _searchDefinitionManager.AllSearchParameters.FirstOrDefault(p => p.Url == new Uri("http://hl7.org/fhir/SearchParameter/Account-status")); - param.IsSearchable = false; + await SetSearchParameterStatus(new ReadOnlyCollection(new List() { param.Url.OriginalString }), SearchParameterStatus.Supported); var expectedResourceType = param.BaseResourceTypes.FirstOrDefault(); ReindexJobRecord job = CreateReindexJobRecord(); @@ -154,7 +155,7 @@ public async Task GivenContinuationToken_WhenExecuted_ThenAdditionalQueryAdded() { // Get one search parameter and configure it such that it needs to be reindexed var param = _searchDefinitionManager.AllSearchParameters.FirstOrDefault(p => p.Code == "identifier"); - param.IsSearchable = false; + await SetSearchParameterStatus(new ReadOnlyCollection(new List() { param.Url.OriginalString }), SearchParameterStatus.Supported); var expectedResourceType = param.BaseResourceTypes.FirstOrDefault(); ReindexJobRecord job = CreateReindexJobRecord(); @@ -216,12 +217,12 @@ public async Task GivenRunningJob_WhenExecuted_ThenQueuedQueryCompleted() Assert.NotNull(paramWithAppointmentResponseBaseType); Assert.NotNull(paramWithAppointmentBaseType); - paramWithAppointmentResponseBaseType.IsSearchable = false; - paramWithAppointmentBaseType.IsSearchable = false; - - var resourceTypeSearchParamHashMap = new Dictionary(); - resourceTypeSearchParamHashMap.Add("Appointment", "appointmentHash"); - resourceTypeSearchParamHashMap.Add("AppointmentResponse", "appointmentResponseHash"); + await SetSearchParameterStatus(new ReadOnlyCollection(new List() { paramWithAppointmentResponseBaseType.Url.OriginalString, paramWithAppointmentBaseType.Url.OriginalString }), SearchParameterStatus.Supported); + var resourceTypeSearchParamHashMap = new Dictionary + { + { "Appointment", "appointmentHash" }, + { "AppointmentResponse", "appointmentResponseHash" }, + }; ReindexJobRecord job = CreateReindexJobRecord(paramHashMap: resourceTypeSearchParamHashMap); _fhirOperationDataStore.GetReindexJobByIdAsync(job.Id, _cancellationToken).ReturnsForAnyArgs(new ReindexJobWrapper(job, _weakETag)); @@ -411,12 +412,12 @@ public async Task GivenJobWithNoWork_WhenExecuted_ThenJobCompletedAndSPStatusUpd Assert.NotNull(paramWithAppointmentResponseBaseType); Assert.NotNull(paramWithAppointmentBaseType); - paramWithAppointmentResponseBaseType.IsSearchable = false; - paramWithAppointmentBaseType.IsSearchable = false; - - var resourceTypeSearchParamHashMap = new Dictionary(); - resourceTypeSearchParamHashMap.Add("Appointment", "appointmentHash"); - resourceTypeSearchParamHashMap.Add("AppointmentResponse", "appointmentResponseHash"); + await SetSearchParameterStatus(new ReadOnlyCollection(new List() { paramWithAppointmentResponseBaseType.Url.OriginalString, paramWithAppointmentBaseType.Url.OriginalString }), SearchParameterStatus.Supported); + var resourceTypeSearchParamHashMap = new Dictionary + { + { "Appointment", "appointmentHash" }, + { "AppointmentResponse", "appointmentResponseHash" }, + }; ReindexJobRecord job = CreateReindexJobRecord(paramHashMap: resourceTypeSearchParamHashMap); @@ -543,5 +544,10 @@ private ReindexJobRecord CreateReindexJobRecord(uint maxResourcePerQuery = 100, return new ReindexJobRecord(paramHashMap, new List(), searchParameterTypes, searchParameterResourceTypes: resourceTypes, maxiumumConcurrency: 1, maxResourcePerQuery); } + + private async Task SetSearchParameterStatus(IReadOnlyCollection searchParameter, SearchParameterStatus status) + { + await _searchParameterStatusmanager.UpdateSearchParameterStatusAsync(searchParameter, status, default); + } } } diff --git a/test/Microsoft.Health.Fhir.Shared.Tests.Integration/Features/Operations/Reindex/ReindexJobTests.cs b/test/Microsoft.Health.Fhir.Shared.Tests.Integration/Features/Operations/Reindex/ReindexJobTests.cs index 661714e598..a727d1d454 100644 --- a/test/Microsoft.Health.Fhir.Shared.Tests.Integration/Features/Operations/Reindex/ReindexJobTests.cs +++ b/test/Microsoft.Health.Fhir.Shared.Tests.Integration/Features/Operations/Reindex/ReindexJobTests.cs @@ -357,7 +357,7 @@ public async Task GivenNoSupportedSearchParameters_WhenRunningReindexJob_ThenJob public async Task GivenNoMatchingResources_WhenRunningReindexJob_ThenJobIsCompleted() { var searchParam = _supportedSearchParameterDefinitionManager.GetSearchParameter("http://hl7.org/fhir/SearchParameter/Measure-name"); - searchParam.IsSearchable = false; + await _searchParameterStatusManager.UpdateSearchParameterStatusAsync(new List() { searchParam.Url.ToString() }, SearchParameterStatus.Supported, default); var request = new CreateReindexRequest(new List(), new List()); CreateReindexResponse response = await SetUpForReindexing(request); @@ -368,12 +368,12 @@ public async Task GivenNoMatchingResources_WhenRunningReindexJob_ThenJobIsComple { await PerformReindexingOperation(response, OperationStatus.Completed, cancellationTokenSource); - Assert.True(searchParam.IsSearchable); + var updateSearchParamList = await _searchParameterStatusManager.GetAllSearchParameterStatus(default); + Assert.Equal(SearchParameterStatus.Enabled, updateSearchParamList.Where(sp => sp.Uri.OriginalString == searchParam.Url.OriginalString).First().Status); } finally { cancellationTokenSource.Cancel(); - searchParam.IsSearchable = true; } }