From f58a18201398fa21dd1530070cd9a9ec4e328c07 Mon Sep 17 00:00:00 2001 From: ZMai <zmai@slb.com> Date: Wed, 7 Jun 2023 20:14:24 -0500 Subject: [PATCH] Avoid using wildcard search to find the associated children records --- .../cache/ChildrenKindsCacheVmImpl.java | 35 ++++++ .../indexer/cache/IChildrenKindsCache.java | 7 ++ .../indexer/cache/IRelatedObjectCache.java | 3 +- .../PartitionSafeChildrenKindsCache.java | 35 ++++++ .../cache/RelatedObjectCacheVmImpl.java | 7 +- .../model/indexproperty/ChildrenKinds.java | 10 ++ .../PropertyConfigurationsServiceImpl.java | 109 ++++++++++++------ ...PropertyConfigurationsServiceImplTest.java | 56 ++++----- 8 files changed, 194 insertions(+), 68 deletions(-) create mode 100644 indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/ChildrenKindsCacheVmImpl.java create mode 100644 indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IChildrenKindsCache.java create mode 100644 indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeChildrenKindsCache.java create mode 100644 indexer-core/src/main/java/org/opengroup/osdu/indexer/model/indexproperty/ChildrenKinds.java diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/ChildrenKindsCacheVmImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/ChildrenKindsCacheVmImpl.java new file mode 100644 index 000000000..133c6f15f --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/ChildrenKindsCacheVmImpl.java @@ -0,0 +1,35 @@ +package org.opengroup.osdu.indexer.cache; + +import org.opengroup.osdu.core.common.cache.VmCache; +import org.opengroup.osdu.indexer.model.Constants; +import org.opengroup.osdu.indexer.model.indexproperty.ChildrenKinds; +import org.springframework.stereotype.Component; + +@Component +public class ChildrenKindsCacheVmImpl implements IChildrenKindsCache{ + private VmCache<String, ChildrenKinds> cache; + + public ChildrenKindsCacheVmImpl() { + cache = new VmCache<>(Constants.SPEC_CACHE_EXPIRATION, Constants.SPEC_MAX_CACHE_SIZE); + } + + @Override + public void put(String s, ChildrenKinds o) { + this.cache.put(s, o); + } + + @Override + public ChildrenKinds get(String s) { + return this.cache.get(s); + } + + @Override + public void delete(String s) { + this.cache.delete(s); + } + + @Override + public void clearAll() { + this.cache.clearAll(); + } +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IChildrenKindsCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IChildrenKindsCache.java new file mode 100644 index 000000000..858c83e24 --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IChildrenKindsCache.java @@ -0,0 +1,7 @@ +package org.opengroup.osdu.indexer.cache; + +import org.opengroup.osdu.core.common.cache.ICache; +import org.opengroup.osdu.indexer.model.indexproperty.ChildrenKinds; + +public interface IChildrenKindsCache extends ICache<String, ChildrenKinds> { +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IRelatedObjectCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IRelatedObjectCache.java index ca87122e9..e33200e56 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IRelatedObjectCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/IRelatedObjectCache.java @@ -16,8 +16,9 @@ package org.opengroup.osdu.indexer.cache; import org.opengroup.osdu.core.common.cache.ICache; +import org.opengroup.osdu.core.common.model.storage.RecordData; import java.util.Map; -public interface IRelatedObjectCache extends ICache<String, Map<String, Object>> { +public interface IRelatedObjectCache extends ICache<String, RecordData> { } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeChildrenKindsCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeChildrenKindsCache.java new file mode 100644 index 000000000..3bf010675 --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PartitionSafeChildrenKindsCache.java @@ -0,0 +1,35 @@ +package org.opengroup.osdu.indexer.cache; + +import org.opengroup.osdu.indexer.model.indexproperty.ChildrenKinds; +import org.springframework.stereotype.Component; +import org.springframework.web.context.annotation.RequestScope; + +import javax.inject.Inject; + + +@Component +@RequestScope +public class PartitionSafeChildrenKindsCache extends AbstractPartitionSafeCache<String, ChildrenKinds>{ + @Inject + private IChildrenKindsCache cache; + + @Override + public void put(String s, ChildrenKinds o) { + this.cache.put(cacheKey(s), o); + } + + @Override + public ChildrenKinds get(String s) { + return this.cache.get(cacheKey(s)); + } + + @Override + public void delete(String s) { + this.cache.delete(cacheKey(s)); + } + + @Override + public void clearAll() { + this.cache.clearAll(); + } +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/RelatedObjectCacheVmImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/RelatedObjectCacheVmImpl.java index c1a6f6988..f3d2e166a 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/RelatedObjectCacheVmImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/RelatedObjectCacheVmImpl.java @@ -16,6 +16,7 @@ package org.opengroup.osdu.indexer.cache; import org.opengroup.osdu.core.common.cache.VmCache; +import org.opengroup.osdu.core.common.model.storage.RecordData; import org.opengroup.osdu.indexer.model.Constants; import org.springframework.stereotype.Component; @@ -23,19 +24,19 @@ import java.util.Map; @Component public class RelatedObjectCacheVmImpl implements IRelatedObjectCache { - private VmCache<String, Map<String, Object>> cache; + private VmCache<String, RecordData> cache; public RelatedObjectCacheVmImpl() { cache = new VmCache<>(Constants.DATA_CACHE_EXPIRATION, Constants.DATA_MAX_CACHE_SIZE); } @Override - public void put(String s, Map<String, Object> o) { + public void put(String s, RecordData o) { this.cache.put(s, o); } @Override - public Map<String, Object> get(String s) { + public RecordData get(String s) { return this.cache.get(s); } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/indexproperty/ChildrenKinds.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/indexproperty/ChildrenKinds.java new file mode 100644 index 000000000..6ee7cc3e6 --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/indexproperty/ChildrenKinds.java @@ -0,0 +1,10 @@ +package org.opengroup.osdu.indexer.model.indexproperty; + +import lombok.Data; + +import java.util.List; + +@Data +public class ChildrenKinds { + private List<String> kinds; +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImpl.java index 5bb37704e..4b49a8c04 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImpl.java @@ -24,6 +24,7 @@ import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.indexer.OperationType; import org.opengroup.osdu.core.common.model.indexer.RecordInfo; import org.opengroup.osdu.core.common.model.search.RecordChangedMessages; +import org.opengroup.osdu.core.common.model.storage.RecordData; import org.opengroup.osdu.core.common.model.storage.Schema; import org.opengroup.osdu.core.common.model.storage.SchemaItem; import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; @@ -46,11 +47,12 @@ import java.util.stream.Collectors; public class PropertyConfigurationsServiceImpl implements PropertyConfigurationsService { private static final String ASSOCIATED_IDENTITIES_PROPERTY = "AssociatedIdentities"; private static final String ASSOCIATED_IDENTITIES_PROPERTY_STORAGE_FORMAT_TYPE = "[]string"; - private static final String WILD_CARD_KIND = "*:*:*:*"; private static final String INDEX_PROPERTY_PATH_CONFIGURATION_KIND = "osdu:wks:reference-data--IndexPropertyPathConfiguration:*"; private static final String ANCESTRY_KINDS_DELIMITER = ","; private static final String PARENT_CHILDREN_CONFIGURATION_QUERY_FORMAT = "nested(data.Configurations, nested(data.Configurations.Paths, (RelatedObjectsSpec.RelationshipDirection: ParentToChildren AND RelatedObjectsSpec.RelatedObjectKind:\"%s\")))"; + private static final String CHILDREN_PARENT_CONFIGURATION_QUERY_FORMAT = + "nested(data.Configurations, nested(data.Configurations.Paths, (RelatedObjectsSpec.RelationshipDirection: ChildToParent AND RelatedObjectsSpec.RelatedObjectKind:\"%s\")))"; private static final String HAS_CONFIGURATIONS_QUERY_FORMAT = "data.Code: \"%s\" OR nested(data.Configurations, nested(data.Configurations.Paths, (RelatedObjectsSpec.RelatedObjectKind:\"%s\")))"; private static final int MAX_SEARCH_LIMIT = 1000; @@ -72,6 +74,8 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations @Inject private PartitionSafeParentChildRelationshipSpecsCache parentChildRelationshipSpecsCache; @Inject + private PartitionSafeChildrenKindsCache childrenKindsCache; + @Inject private PartitionSafeKindCache kindCache; @Inject private IRelatedObjectCache relatedObjectCache; @@ -175,11 +179,8 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations for (SearchRecord record : childrenRecords) { // If the child record is in the cache, that means the record was updated very recently. // In this case, use the cache's record instead of the record from search result - Map<String, Object> childDataMap = this.relatedObjectCache.get(record.getId()); - if(childDataMap == null) { - childDataMap = record.getData(); - } - + RecordData cachedRecordData = this.relatedObjectCache.get(record.getId()); + Map<String, Object> childDataMap = (cachedRecordData != null)? cachedRecordData.getData() : record.getData(); Map<String, Object> propertyValues = getExtendedPropertyValues(extendedPropertyName, childDataMap, path.getValueExtraction(), configuration.isExtractFirstMatch()); if (allPropertyValues.isEmpty() && configuration.isExtractFirstMatch()) { allPropertyValues = propertyValues; @@ -300,7 +301,9 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations changedInfo.setUpdatedProperties(updatedProperties); } recordChangeInfoCache.put(recordId, changedInfo); - relatedObjectCache.put(recordId, dataMap); + RecordData recordData = new RecordData(); + recordData.setData(dataMap); + relatedObjectCache.put(recordId, recordData); } @Override @@ -321,7 +324,7 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations String updatedAncestors = Strings.isNullOrEmpty(ancestors) ? kind : ancestors + ANCESTRY_KINDS_DELIMITER + kind; updateAssociatedParentRecords(updatedAncestors, kind, recordChangeInfoList); - updateAssociatedChildrenRecords(updatedAncestors, recordChangeInfoList); + updateAssociatedChildrenRecords(updatedAncestors, kind, recordChangeInfoList); } } @@ -365,12 +368,16 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations private Map<String, Object> getRelatedObjectData(String relatedObjectKind, String relatedObjectId) { String key = PropertyUtil.removeIdPostfix(relatedObjectId); - Map<String, Object> relatedObject = relatedObjectCache.get(key); + RecordData recordData = relatedObjectCache.get(key); + Map<String, Object> relatedObject = (recordData != null)? recordData.getData() : null; if (relatedObject == null) { SearchRecord searchRecord = searchRelatedRecord(relatedObjectKind, relatedObjectId); if (searchRecord != null) { relatedObject = searchRecord.getData(); - relatedObjectCache.put(key, relatedObject); + + recordData = new RecordData(); + recordData.setData(relatedObject); + relatedObjectCache.put(key, recordData); } } @@ -589,6 +596,22 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations return propertyValueList; } + private List<String> getChildrenKinds(String parentKind) { + final String parentKindWithMajor = PropertyUtil.getKindWithMajor(parentKind); + ChildrenKinds childrenKinds = childrenKindsCache.get(parentKindWithMajor); + if(childrenKinds == null) { + childrenKinds = new ChildrenKinds(); + Set<String> kinds = new HashSet<>(); + for (PropertyConfigurations propertyConfigurations: searchChildrenKindConfigurations(parentKindWithMajor)) { + kinds.add(propertyConfigurations.getCode()); + } + childrenKinds.setKinds(new ArrayList<>(kinds)); + childrenKindsCache.put(parentKindWithMajor, childrenKinds); + } + + return childrenKinds.getKinds(); + } + private ParentChildRelationshipSpecs getParentChildRelatedObjectsSpecs(String childKind) { final String childKindWithMajor = PropertyUtil.getKindWithMajor(childKind); @@ -739,20 +762,30 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations return false; } - private void updateAssociatedChildrenRecords(String ancestors, List<RecordChangeInfo> recordChangeInfos) { + private void updateAssociatedChildrenRecords(String ancestors, String parentKind, List<RecordChangeInfo> recordChangeInfos) { List<String> processedIds = recordChangeInfos.stream().map(recordChangeInfo -> recordChangeInfo.getRecordInfo().getId()).collect(Collectors.toList()); String query = String.format("data.%s:(%s)", ASSOCIATED_IDENTITIES_PROPERTY, createIdsFilter(processedIds)); - String kind = WILD_CARD_KIND; + + List<String> childrenKinds = getChildrenKinds(parentKind); for (String ancestryKind : ancestors.split(ANCESTRY_KINDS_DELIMITER)) { - if (!ancestryKind.trim().isEmpty()) { - // Exclude the kinds in the ancestryKinds to prevent circular chasing - kind += ",-" + ancestryKind.trim(); + // Exclude the kinds in the ancestryKinds to prevent circular chasing + childrenKinds.removeIf(k -> ancestryKind.contains(k)); + } + if(childrenKinds.isEmpty()) { + return; + } + + StringBuilder kindBuilder = new StringBuilder(); + for(String kind: childrenKinds) { + if(kindBuilder.length() > 0) { + kindBuilder.append(","); } + kindBuilder.append(kind + "*"); } final int limit = configurationProperties.getStorageRecordsByKindBatchSize(); SearchRequest searchRequest = new SearchRequest(); - searchRequest.setKind(kind); + searchRequest.setKind(kindBuilder.toString()); searchRequest.setQuery(query); searchRequest.setReturnedFields(Arrays.asList("kind", "id", "data." + ASSOCIATED_IDENTITIES_PROPERTY)); List<RecordInfo> recordInfos = new ArrayList<>(); @@ -810,31 +843,37 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations } /****************************** search methods that use search service to get the data **************************************/ + private SearchRequest createSearchRequest(String kind, String query) { + SearchRequest searchRequest = new SearchRequest(); + searchRequest.setKind(kind); + searchRequest.setQuery(query); + return searchRequest; + } private PropertyConfigurations searchConfigurations(String kind) { - SearchRequest searchRequest = new SearchRequest(); - searchRequest.setKind(INDEX_PROPERTY_PATH_CONFIGURATION_KIND); String query = String.format("data.Code: \"%s\"", kind); - searchRequest.setQuery(query); - for (SearchRecord searchRecord : searchAllRecords(searchRequest)) { - try { - String data = objectMapper.writeValueAsString(searchRecord.getData()); - PropertyConfigurations configurations = objectMapper.readValue(data, PropertyConfigurations.class); - if (kind.equals(configurations.getCode())) { - return configurations; - } - } catch (JsonProcessingException e) { - jaxRsDpsLog.error("failed to deserialize PropertyConfigurations object", e); + SearchRequest searchRequest = createSearchRequest(INDEX_PROPERTY_PATH_CONFIGURATION_KIND, query); + for(PropertyConfigurations configurations : searchConfigurations(searchRequest)) { + if (kind.equals(configurations.getCode())) { + return configurations; } } return null; } private List<PropertyConfigurations> searchParentKindConfigurations(String childKind) { - SearchRequest searchRequest = new SearchRequest(); - searchRequest.setKind(INDEX_PROPERTY_PATH_CONFIGURATION_KIND); String query = String.format(PARENT_CHILDREN_CONFIGURATION_QUERY_FORMAT, childKind); - searchRequest.setQuery(query); + SearchRequest searchRequest = createSearchRequest(INDEX_PROPERTY_PATH_CONFIGURATION_KIND, query); + return searchConfigurations(searchRequest); + } + + private List<PropertyConfigurations> searchChildrenKindConfigurations(String parentKind) { + String query = String.format(CHILDREN_PARENT_CONFIGURATION_QUERY_FORMAT, parentKind); + SearchRequest searchRequest = createSearchRequest(INDEX_PROPERTY_PATH_CONFIGURATION_KIND, query); + return searchConfigurations(searchRequest); + } + + private List<PropertyConfigurations> searchConfigurations(SearchRequest searchRequest) { List<PropertyConfigurations> configurationsList = new ArrayList<>(); for (SearchRecord searchRecord : searchAllRecords(searchRequest)) { try { @@ -913,18 +952,16 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations searchRequest.setLimit(MAX_SEARCH_LIMIT); List<SearchRecord> allRecords = new ArrayList<>(); boolean done = false; - int offset = 0; try { while (!done) { - searchRequest.setOffset(offset); - SearchResponse searchResponse = searchService.query(searchRequest); + SearchResponse searchResponse = searchService.queryWithCursor(searchRequest); List<SearchRecord> results = searchResponse.getResults(); if (results != null && results.size() > 0) { allRecords.addAll(results); } - if (results != null && results.size() == MAX_SEARCH_LIMIT) { - offset += MAX_SEARCH_LIMIT; + if (!Strings.isNullOrEmpty(searchResponse.getCursor())) { + searchRequest.setCursor(searchResponse.getCursor()); } else { done = true; } diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImplTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImplTest.java index caeacd2cf..b5783bf56 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImplTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImplTest.java @@ -33,6 +33,7 @@ import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.indexer.OperationType; import org.opengroup.osdu.core.common.model.indexer.RecordInfo; import org.opengroup.osdu.core.common.model.search.RecordChangedMessages; +import org.opengroup.osdu.core.common.model.storage.RecordData; import org.opengroup.osdu.core.common.model.storage.Schema; import org.opengroup.osdu.core.common.model.storage.SchemaItem; import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; @@ -76,6 +77,8 @@ public class PropertyConfigurationsServiceImplTest { @Mock private PartitionSafeParentChildRelationshipSpecsCache parentChildRelationshipSpecsCache; @Mock + private PartitionSafeChildrenKindsCache childrenKindsCache; + @Mock private PartitionSafeKindCache kindCache; @Mock private IRelatedObjectCache relatedObjectCache; @@ -182,7 +185,7 @@ public class PropertyConfigurationsServiceImplTest { SearchResponse searchResponse = new SearchResponse(); searchResponse.setResults(results); searchResponse.setTotalCount(results.size()); - when(this.searchService.query(any())).thenReturn(searchResponse); + when(this.searchService.queryWithCursor(any())).thenReturn(searchResponse); String kind = "osdu:wks:master-data--Well:1.0.0"; String code = "osdu:wks:master-data--Well:1."; @@ -197,7 +200,7 @@ public class PropertyConfigurationsServiceImplTest { @Test public void getPropertyConfigurations_without_result_from_search() throws URISyntaxException { - when(this.searchService.query(any())).thenReturn(new SearchResponse()); + when(this.searchService.queryWithCursor(any())).thenReturn(new SearchResponse()); String kind = "osdu:wks:master-data--Well:1.0.0"; PropertyConfigurations configuration = sut.getPropertyConfigurations(kind); @@ -217,7 +220,7 @@ public class PropertyConfigurationsServiceImplTest { List<SearchRecord> childrenRecords = gson.fromJson(jsonText, type); SearchResponse response = new SearchResponse(); response.setResults(childrenRecords); - when(this.searchService.query(any())).thenReturn(response); + when(this.searchService.queryWithCursor(any())).thenReturn(response); Map<String, Object> extendedProperties = this.sut.getExtendedProperties("anyId", originalDataMap, propertyConfigurations); Map<String, Object> expectedExtendedProperties = getDataMap("wellbore_extended_data.json"); @@ -237,7 +240,7 @@ public class PropertyConfigurationsServiceImplTest { relatedObjectData = getDataMap("organisation_data2.json"); relatedObjects.put("opendes:master-data--Organisation:BigOil-Department-SeismicProcessing", relatedObjectData); - // Setup search response for searchService.query(...) + // Setup search response for searchService.queryWithCursor(...) when(this.searchService.query(any())).thenAnswer(invocation -> { SearchRequest searchRequest = invocation.getArgument(0); String query = searchRequest.getQuery(); @@ -397,7 +400,7 @@ public class PropertyConfigurationsServiceImplTest { @Test public void cacheDataRecord_create_record() throws URISyntaxException { ArgumentCaptor<RecordChangeInfo> recordInfoArgumentCaptor = ArgumentCaptor.forClass(RecordChangeInfo.class); - ArgumentCaptor<Map<String, Object>> dataMapArgumentCaptor = ArgumentCaptor.forClass(Map.class); + ArgumentCaptor<RecordData> dataMapArgumentCaptor = ArgumentCaptor.forClass(RecordData.class); String recordId = "anyId"; String kind = "anyKind"; Map<String, Object> dataMap = new HashMap<>(); @@ -411,13 +414,13 @@ public class PropertyConfigurationsServiceImplTest { verify(this.relatedObjectCache, times(1)).put(any(), dataMapArgumentCaptor.capture()); Assert.assertEquals(OperationType.create.getValue(), recordInfoArgumentCaptor.getValue().getRecordInfo().getOp()); - Assert.assertEquals(1, dataMapArgumentCaptor.getValue().size()); + Assert.assertEquals(1, dataMapArgumentCaptor.getValue().getData().size()); } @Test public void cacheDataRecord_update_record() throws URISyntaxException { ArgumentCaptor<RecordChangeInfo> recordInfoArgumentCaptor = ArgumentCaptor.forClass(RecordChangeInfo.class); - ArgumentCaptor<Map<String, Object>> dataMapArgumentCaptor = ArgumentCaptor.forClass(Map.class); + ArgumentCaptor<RecordData> dataMapArgumentCaptor = ArgumentCaptor.forClass(RecordData.class); String recordId = "anyId"; String kind = "anyKind"; Map<String, Object> dataMap = new HashMap<>(); @@ -445,14 +448,14 @@ public class PropertyConfigurationsServiceImplTest { Assert.assertEquals(2, changedInfo.getUpdatedProperties().size()); Assert.assertTrue(changedInfo.getUpdatedProperties().contains("p1")); Assert.assertTrue(changedInfo.getUpdatedProperties().contains("p2")); - Assert.assertEquals(1, dataMapArgumentCaptor.getValue().size()); - Assert.assertEquals("v1", dataMapArgumentCaptor.getValue().get("p1")); + Assert.assertEquals(1, dataMapArgumentCaptor.getValue().getData().size()); + Assert.assertEquals("v1", dataMapArgumentCaptor.getValue().getData().get("p1")); } @Test public void cacheDataRecord_update_record_merge_previous_UpdateChangedInfo() throws URISyntaxException { ArgumentCaptor<RecordChangeInfo> recordInfoArgumentCaptor = ArgumentCaptor.forClass(RecordChangeInfo.class); - ArgumentCaptor<Map<String, Object>> dataMapArgumentCaptor = ArgumentCaptor.forClass(Map.class); + ArgumentCaptor<RecordData> dataMapArgumentCaptor = ArgumentCaptor.forClass(RecordData.class); String recordId = "anyId"; String kind = "anyKind"; Map<String, Object> dataMap = new HashMap<>(); @@ -490,14 +493,14 @@ public class PropertyConfigurationsServiceImplTest { Assert.assertEquals(2, changedInfo.getUpdatedProperties().size()); Assert.assertTrue(changedInfo.getUpdatedProperties().contains("p1")); Assert.assertTrue(changedInfo.getUpdatedProperties().contains("p2")); - Assert.assertEquals(1, dataMapArgumentCaptor.getValue().size()); - Assert.assertEquals("v1", dataMapArgumentCaptor.getValue().get("p1")); + Assert.assertEquals(1, dataMapArgumentCaptor.getValue().getData().size()); + Assert.assertEquals("v1", dataMapArgumentCaptor.getValue().getData().get("p1")); } @Test public void cacheDataRecord_update_record_merge_previous_CreateChangedInfo() throws URISyntaxException { ArgumentCaptor<RecordChangeInfo> recordInfoArgumentCaptor = ArgumentCaptor.forClass(RecordChangeInfo.class); - ArgumentCaptor<Map<String, Object>> dataMapArgumentCaptor = ArgumentCaptor.forClass(Map.class); + ArgumentCaptor<RecordData> dataMapArgumentCaptor = ArgumentCaptor.forClass(RecordData.class); String recordId = "anyId"; String kind = "anyKind"; Map<String, Object> dataMap = new HashMap<>(); @@ -532,8 +535,8 @@ public class PropertyConfigurationsServiceImplTest { RecordChangeInfo changedInfo = recordInfoArgumentCaptor.getValue(); Assert.assertEquals(OperationType.create.getValue(), changedInfo.getRecordInfo().getOp()); Assert.assertNull(changedInfo.getUpdatedProperties()); - Assert.assertEquals(1, dataMapArgumentCaptor.getValue().size()); - Assert.assertEquals("v1", dataMapArgumentCaptor.getValue().get("p1")); + Assert.assertEquals(1, dataMapArgumentCaptor.getValue().getData().size()); + Assert.assertEquals("v1", dataMapArgumentCaptor.getValue().getData().get("p1")); } @Test @@ -656,12 +659,12 @@ public class PropertyConfigurationsServiceImplTest { parentKind = "osdu:wks:master-data--Wellbore:1.0.0"; parentId = "anyParentId"; - // Setup search response for searchService.query(...) - when(this.searchService.query(any())).thenAnswer(invocation -> { + // Setup search response for searchService.queryWithCursor(...) + when(this.searchService.queryWithCursor(any())).thenAnswer(invocation -> { SearchRequest searchRequest = invocation.getArgument(0); SearchResponse searchResponse = new SearchResponse(); if (searchRequest.getKind().toString().equals(propertyConfigurationKind)) { - if (searchRequest.getQuery().contains("nested")) { + if (searchRequest.getQuery().contains("ParentToChildren")) { // Return of getParentChildRelatedObjectsSpecs(...) Map<String, Object> dataMap = getDataMap("wellbore_configuration_record.json"); SearchRecord searchRecord = new SearchRecord(); @@ -820,13 +823,14 @@ public class PropertyConfigurationsServiceImplTest { parentKind = "osdu:wks:master-data--GeoPoliticalEntity:1.0.0"; parentId = "anyParentId"; - // Setup search response for searchService.query(...) - when(this.searchService.query(any())).thenAnswer(invocation -> { + // Setup search response for searchService.queryWithCursor(...) + when(this.searchService.queryWithCursor(any())).thenAnswer(invocation -> { SearchRequest searchRequest = invocation.getArgument(0); SearchResponse searchResponse = new SearchResponse(); if (searchRequest.getKind().toString().equals(propertyConfigurationKind)) { - if (!searchRequest.getQuery().contains("nested")) { - // Return of getParentChildRelatedObjectsSpecs(...) + if (searchRequest.getQuery().contains("ChildToParent") || searchRequest.getQuery().contains("data.Code:")) { + // Return of getParentChildRelatedObjectsSpecs(...) or + // getPropertyConfigurations(...) Map<String, Object> dataMap = getDataMap("well_configuration_record.json"); SearchRecord searchRecord = new SearchRecord(); searchRecord.setData(dataMap); @@ -836,8 +840,7 @@ public class PropertyConfigurationsServiceImplTest { // No result } } else { - String kind = "*:*:*:*,-"+parentKind; - if(searchRequest.getKind().toString().equals(kind)) { + if(searchRequest.getKind().toString().equals("osdu:wks:master-data--Well:1.*")) { // Return of searchUniqueParentIds(...) SearchRecord searchRecord = new SearchRecord(); Map<String, Object> childDataMap = new HashMap<>(); @@ -850,10 +853,7 @@ public class PropertyConfigurationsServiceImplTest { else { // This branch is a setup for test case: // updateAssociatedRecords_updateAssociatedChildrenRecords_circularIndexing - kind = "*:*:*:*,-"+ childKind + ",-" + parentKind; - if(!searchRequest.getKind().toString().equals(kind)) { - throw new Exception("Unexpected search"); - } + throw new Exception("Unexpected search"); } } return searchResponse; -- GitLab