From 7c5c0e909abc68a1214caa8ff1e30aabdfb61347 Mon Sep 17 00:00:00 2001 From: BOUHOURS Antoine Date: Mon, 7 Oct 2024 17:03:11 +0200 Subject: [PATCH 1/4] Fix looking on all resources when retrieving extensions for preloading collection Signed-off-by: BOUHOURS Antoine --- .../store/iidm/impl/CollectionCache.java | 43 +++++++++++++++---- .../store/iidm/impl/CollectionCacheTest.java | 6 +++ 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CollectionCache.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CollectionCache.java index b45734572..fb063908b 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CollectionCache.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CollectionCache.java @@ -48,6 +48,20 @@ public class CollectionCache { */ private final Set removedResources = new HashSet<>(); + /** + * Cache of extension attributes indexed by identifiable ID.
+ * Each key represents an identifiable ID, mapping to another map where the keys are extension names + * and the values are {@code ExtensionAttributes} for that extension. + */ + private final Map> extensionAttributesByIdentifiableId = new HashMap<>(); + + /** + * Cache of extension attributes indexed by extension name.
+ * Each key represents an extension name, mapping to another map where the keys are identifiable IDs + * and the values are {@code ExtensionAttributes} for that identifiable resource. + */ + private final Map> extensionAttributesByExtensionName = new HashMap<>(); + /** * Indicates if the extension has been fully loaded and synchronized with the server. */ @@ -326,6 +340,12 @@ public CollectionCache clone(ObjectMapper objectMapper, int newVariantNum, Co for (Map.Entry> entry : removedExtensionAttributes.entrySet()) { clonedCache.removedExtensionAttributes.put(entry.getKey(), new HashSet<>(entry.getValue())); } + for (Map.Entry> entry : extensionAttributesByIdentifiableId.entrySet()) { + clonedCache.extensionAttributesByIdentifiableId.put(entry.getKey(), new HashMap<>(entry.getValue())); + } + for (Map.Entry> entry : extensionAttributesByExtensionName.entrySet()) { + clonedCache.extensionAttributesByExtensionName.put(entry.getKey(), new HashMap<>(entry.getValue())); + } clonedCache.fullyLoadedExtensionsByExtensionName.addAll(fullyLoadedExtensionsByExtensionName); clonedCache.fullyLoadedExtensionsByIdentifiableIds.addAll(fullyLoadedExtensionsByIdentifiableIds); @@ -405,11 +425,9 @@ public Map getAllExtensionsAttributesByResourceType // we update the full cache and set it as fully loaded extensionAttributesMap.forEach((identifiableId, extensionAttributes) -> addExtensionAttributesToCache(identifiableId, extensionName, extensionAttributes)); fullyLoadedExtensionsByExtensionName.add(extensionName); + extensionAttributesByExtensionName.put(extensionName, extensionAttributesMap); } - return resources.entrySet() - .stream() - .filter(resourceEntry -> resourceEntry.getValue().getAttributes().getExtensionAttributes().containsKey(extensionName)) - .collect(Collectors.toMap(Map.Entry::getKey, resourceEntry -> resourceEntry.getValue().getAttributes().getExtensionAttributes().get(extensionName))); + return extensionAttributesByExtensionName.get(extensionName); } /** @@ -461,11 +479,20 @@ public Map> getAllExtensionsAttributesB // we update the full cache and set it as fully loaded extensionAttributesMap.forEach(this::addAllExtensionAttributesToCache); fullyLoadedExtensions = true; + extensionAttributesByIdentifiableId.putAll(extensionAttributesMap); + updateExtensionAttributesByExtensionNameMap(extensionAttributesMap); } - return resources.entrySet() - .stream() - .filter(resourceEntry -> !resourceEntry.getValue().getAttributes().getExtensionAttributes().isEmpty()) - .collect(Collectors.toMap(Map.Entry::getKey, resourceEntry -> resourceEntry.getValue().getAttributes().getExtensionAttributes())); + return extensionAttributesByIdentifiableId; + } + + private void updateExtensionAttributesByExtensionNameMap(Map> extensionAttributesMap) { + extensionAttributesMap.forEach((identifiableId, nestedExtensionAttributesByExtensionName) -> { + nestedExtensionAttributesByExtensionName.forEach((extensionName, extensionAttribute) -> { + extensionAttributesByExtensionName + .computeIfAbsent(extensionName, k -> new HashMap<>()) + .put(identifiableId, extensionAttribute); + }); + }); } public void removeExtensionAttributesByExtensionName(String identifiableId, String extensionName) { diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/CollectionCacheTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/CollectionCacheTest.java index 301dcf693..0ff83267c 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/CollectionCacheTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/CollectionCacheTest.java @@ -553,5 +553,11 @@ public void getExtensionAttributesLoaderByResourceType() { assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByResourceTypeAndNameCalled()); assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByIdCalled()); assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByResourceTypeCalled()); + // Verify that the map extensionAttributesByExtensionName is correctly updated when calling getAllExtensionsAttributesByResourceType() + assertEquals(Map.of("l1", apc1, "l2", apc2), collectionCache.getAllExtensionsAttributesByResourceTypeAndExtensionName(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, ResourceType.LOAD, "activePowerControl")); + assertFalse(mockNetworkStoreClient.isExtensionAttributeLoaderCalled()); + assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByResourceTypeAndNameCalled()); + assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByIdCalled()); + assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByResourceTypeCalled()); } } From 811cef6efcae9093e842562a3e5c54ef75261c81 Mon Sep 17 00:00:00 2001 From: BOUHOURS Antoine Date: Mon, 7 Oct 2024 17:36:10 +0200 Subject: [PATCH 2/4] Fix tests and add new tests for clone Signed-off-by: BOUHOURS Antoine --- .../client/CachedNetworkStoreClientTest.java | 5 +- .../PreloadingNetworkStoreClientTest.java | 56 +++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/network-store-client/src/test/java/com/powsybl/network/store/client/CachedNetworkStoreClientTest.java b/network-store-client/src/test/java/com/powsybl/network/store/client/CachedNetworkStoreClientTest.java index 0de899341..b2351b3b1 100644 --- a/network-store-client/src/test/java/com/powsybl/network/store/client/CachedNetworkStoreClientTest.java +++ b/network-store-client/src/test/java/com/powsybl/network/store/client/CachedNetworkStoreClientTest.java @@ -645,10 +645,11 @@ public void testGetExtensionCacheWithClonedNetwork() throws IOException { server.expect(ExpectedCount.once(), requestTo("/networks/" + networkUuid + "/" + Resource.INITIAL_VARIANT_NUM + "/to/" + targetVariantNum + "?targetVariantId=" + targetVariantId)) .andExpect(method(PUT)) .andRespond(withSuccess()); + // Clone network and verify that there is the expected extension in the cloned cache cachedClient.cloneNetwork(networkUuid, Resource.INITIAL_VARIANT_NUM, targetVariantNum, targetVariantId); - Optional apc1Attributes = cachedClient.getExtensionAttributes(networkUuid, Resource.INITIAL_VARIANT_NUM, ResourceType.GENERATOR, identifiableId, ActivePowerControl.NAME); + Optional apc1Attributes = cachedClient.getExtensionAttributes(networkUuid, targetVariantNum, ResourceType.GENERATOR, identifiableId, ActivePowerControl.NAME); assertTrue(apc1Attributes.isPresent()); - Optional os1Attributes = cachedClient.getExtensionAttributes(networkUuid, Resource.INITIAL_VARIANT_NUM, ResourceType.GENERATOR, identifiableId, OperatingStatus.NAME); + Optional os1Attributes = cachedClient.getExtensionAttributes(networkUuid, targetVariantNum, ResourceType.GENERATOR, identifiableId, OperatingStatus.NAME); assertFalse(os1Attributes.isPresent()); server.verify(); server.reset(); diff --git a/network-store-client/src/test/java/com/powsybl/network/store/client/PreloadingNetworkStoreClientTest.java b/network-store-client/src/test/java/com/powsybl/network/store/client/PreloadingNetworkStoreClientTest.java index c80c5a01d..472c28814 100644 --- a/network-store-client/src/test/java/com/powsybl/network/store/client/PreloadingNetworkStoreClientTest.java +++ b/network-store-client/src/test/java/com/powsybl/network/store/client/PreloadingNetworkStoreClientTest.java @@ -34,6 +34,7 @@ import static org.junit.Assert.*; import static org.springframework.http.HttpMethod.GET; +import static org.springframework.http.HttpMethod.PUT; import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; @@ -960,4 +961,59 @@ private void loadTwoIdentifiablesToCache(String identifiableId1, String identifi server.verify(); server.reset(); } + + @Test + public void testGetExtensionsCacheWithClonedNetwork() throws IOException { + int targetVariantNum = 1; + String targetVariantId = "new_variant"; + String identifiableId1 = "GEN"; + String identifiableId2 = "GEN1"; + + // Load the identifiables in the cache + loadTwoIdentifiablesToCache(identifiableId1, identifiableId2); + + // Two successive ExtensionAttributes retrieval, only the first should send a REST request, the second uses the cache + ActivePowerControlAttributes apc1 = ActivePowerControlAttributes.builder() + .droop(5.2) + .participate(true) + .participationFactor(0.5) + .build(); + GeneratorStartupAttributes gs1 = GeneratorStartupAttributes.builder() + .marginalCost(6.8) + .forcedOutageRate(35) + .plannedOutageRate(30) + .startupCost(28) + .plannedActivePowerSetpoint(5) + .build(); + ActivePowerControlAttributes apc2 = ActivePowerControlAttributes.builder() + .droop(5.2) + .participate(true) + .participationFactor(1) + .build(); + + // Load extensions to cache + String multipleExtensionAttributes = objectMapper.writerFor(new TypeReference>>() { + }).writeValueAsString(Map.of(identifiableId1, Map.of(ActivePowerControl.NAME, apc1, GeneratorStartup.NAME, gs1), identifiableId2, Map.of(ActivePowerControl.NAME, apc2))); + server.expect(ExpectedCount.once(), requestTo("/networks/" + networkUuid + "/" + Resource.INITIAL_VARIANT_NUM + "/identifiables/types/" + ResourceType.GENERATOR + "/extensions")) + .andExpect(method(GET)) + .andRespond(withSuccess(multipleExtensionAttributes, MediaType.APPLICATION_JSON)); + Map> extensionAttributesByIdentifiableIdMap = cachedClient.getAllExtensionsAttributesByResourceType(networkUuid, Resource.INITIAL_VARIANT_NUM, ResourceType.GENERATOR); + assertEquals(2, extensionAttributesByIdentifiableIdMap.size()); + server.verify(); + server.reset(); + + // Clone network + server.expect(ExpectedCount.once(), requestTo("/networks/" + networkUuid + "/" + Resource.INITIAL_VARIANT_NUM + "/to/" + targetVariantNum + "?targetVariantId=" + targetVariantId)) + .andExpect(method(PUT)) + .andRespond(withSuccess()); + cachedClient.cloneNetwork(networkUuid, Resource.INITIAL_VARIANT_NUM, targetVariantNum, targetVariantId); + + // Verify that the cache is copied and there is no new fetch + extensionAttributesByIdentifiableIdMap = cachedClient.getAllExtensionsAttributesByResourceType(networkUuid, targetVariantNum, ResourceType.GENERATOR); + assertEquals(2, extensionAttributesByIdentifiableIdMap.size()); + Map extensionAttributesByExtensionNameMap = cachedClient.getAllExtensionsAttributesByIdentifiableId(networkUuid, targetVariantNum, ResourceType.GENERATOR, identifiableId1); + assertEquals(2, extensionAttributesByExtensionNameMap.size()); + server.verify(); + server.reset(); + } } From 28d2a93af88a431809facc0c39d80ad89847ab0a Mon Sep 17 00:00:00 2001 From: BOUHOURS Antoine Date: Mon, 7 Oct 2024 17:49:40 +0200 Subject: [PATCH 3/4] Fix sonar warning Signed-off-by: BOUHOURS Antoine --- .../network/store/iidm/impl/CollectionCache.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CollectionCache.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CollectionCache.java index fb063908b..19e6e4572 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CollectionCache.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CollectionCache.java @@ -486,13 +486,13 @@ public Map> getAllExtensionsAttributesB } private void updateExtensionAttributesByExtensionNameMap(Map> extensionAttributesMap) { - extensionAttributesMap.forEach((identifiableId, nestedExtensionAttributesByExtensionName) -> { - nestedExtensionAttributesByExtensionName.forEach((extensionName, extensionAttribute) -> { - extensionAttributesByExtensionName - .computeIfAbsent(extensionName, k -> new HashMap<>()) - .put(identifiableId, extensionAttribute); - }); - }); + extensionAttributesMap.forEach((identifiableId, nestedExtensionAttributesByExtensionName) -> + nestedExtensionAttributesByExtensionName.forEach((extensionName, extensionAttribute) -> + extensionAttributesByExtensionName + .computeIfAbsent(extensionName, k -> new HashMap<>()) + .put(identifiableId, extensionAttribute) + ) + ); } public void removeExtensionAttributesByExtensionName(String identifiableId, String extensionName) { From 90d39f8f0d4aaa620c5cd8fbc2d33ea586e6f760 Mon Sep 17 00:00:00 2001 From: BOUHOURS Antoine Date: Wed, 9 Oct 2024 09:24:48 +0200 Subject: [PATCH 4/4] Return null instead of a map that is not synchronized with the resources map Signed-off-by: BOUHOURS Antoine --- .../PreloadingNetworkStoreClientTest.java | 8 ++- .../store/iidm/impl/CollectionCache.java | 49 ++++++------------- .../store/iidm/impl/CollectionCacheTest.java | 14 ++---- 3 files changed, 21 insertions(+), 50 deletions(-) diff --git a/network-store-client/src/test/java/com/powsybl/network/store/client/PreloadingNetworkStoreClientTest.java b/network-store-client/src/test/java/com/powsybl/network/store/client/PreloadingNetworkStoreClientTest.java index 472c28814..dbe87a1d2 100644 --- a/network-store-client/src/test/java/com/powsybl/network/store/client/PreloadingNetworkStoreClientTest.java +++ b/network-store-client/src/test/java/com/powsybl/network/store/client/PreloadingNetworkStoreClientTest.java @@ -991,14 +991,13 @@ public void testGetExtensionsCacheWithClonedNetwork() throws IOException { .participationFactor(1) .build(); - // Load extensions to cache + // Load extensions to cache on initial variant String multipleExtensionAttributes = objectMapper.writerFor(new TypeReference>>() { }).writeValueAsString(Map.of(identifiableId1, Map.of(ActivePowerControl.NAME, apc1, GeneratorStartup.NAME, gs1), identifiableId2, Map.of(ActivePowerControl.NAME, apc2))); server.expect(ExpectedCount.once(), requestTo("/networks/" + networkUuid + "/" + Resource.INITIAL_VARIANT_NUM + "/identifiables/types/" + ResourceType.GENERATOR + "/extensions")) .andExpect(method(GET)) .andRespond(withSuccess(multipleExtensionAttributes, MediaType.APPLICATION_JSON)); - Map> extensionAttributesByIdentifiableIdMap = cachedClient.getAllExtensionsAttributesByResourceType(networkUuid, Resource.INITIAL_VARIANT_NUM, ResourceType.GENERATOR); - assertEquals(2, extensionAttributesByIdentifiableIdMap.size()); + cachedClient.getAllExtensionsAttributesByResourceType(networkUuid, Resource.INITIAL_VARIANT_NUM, ResourceType.GENERATOR); server.verify(); server.reset(); @@ -1009,8 +1008,7 @@ public void testGetExtensionsCacheWithClonedNetwork() throws IOException { cachedClient.cloneNetwork(networkUuid, Resource.INITIAL_VARIANT_NUM, targetVariantNum, targetVariantId); // Verify that the cache is copied and there is no new fetch - extensionAttributesByIdentifiableIdMap = cachedClient.getAllExtensionsAttributesByResourceType(networkUuid, targetVariantNum, ResourceType.GENERATOR); - assertEquals(2, extensionAttributesByIdentifiableIdMap.size()); + cachedClient.getAllExtensionsAttributesByResourceType(networkUuid, targetVariantNum, ResourceType.GENERATOR); Map extensionAttributesByExtensionNameMap = cachedClient.getAllExtensionsAttributesByIdentifiableId(networkUuid, targetVariantNum, ResourceType.GENERATOR, identifiableId1); assertEquals(2, extensionAttributesByExtensionNameMap.size()); server.verify(); diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CollectionCache.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CollectionCache.java index 19e6e4572..91e585ffb 100644 --- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CollectionCache.java +++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CollectionCache.java @@ -48,20 +48,6 @@ public class CollectionCache { */ private final Set removedResources = new HashSet<>(); - /** - * Cache of extension attributes indexed by identifiable ID.
- * Each key represents an identifiable ID, mapping to another map where the keys are extension names - * and the values are {@code ExtensionAttributes} for that extension. - */ - private final Map> extensionAttributesByIdentifiableId = new HashMap<>(); - - /** - * Cache of extension attributes indexed by extension name.
- * Each key represents an extension name, mapping to another map where the keys are identifiable IDs - * and the values are {@code ExtensionAttributes} for that identifiable resource. - */ - private final Map> extensionAttributesByExtensionName = new HashMap<>(); - /** * Indicates if the extension has been fully loaded and synchronized with the server. */ @@ -340,12 +326,6 @@ public CollectionCache clone(ObjectMapper objectMapper, int newVariantNum, Co for (Map.Entry> entry : removedExtensionAttributes.entrySet()) { clonedCache.removedExtensionAttributes.put(entry.getKey(), new HashSet<>(entry.getValue())); } - for (Map.Entry> entry : extensionAttributesByIdentifiableId.entrySet()) { - clonedCache.extensionAttributesByIdentifiableId.put(entry.getKey(), new HashMap<>(entry.getValue())); - } - for (Map.Entry> entry : extensionAttributesByExtensionName.entrySet()) { - clonedCache.extensionAttributesByExtensionName.put(entry.getKey(), new HashMap<>(entry.getValue())); - } clonedCache.fullyLoadedExtensionsByExtensionName.addAll(fullyLoadedExtensionsByExtensionName); clonedCache.fullyLoadedExtensionsByIdentifiableIds.addAll(fullyLoadedExtensionsByIdentifiableIds); @@ -425,9 +405,14 @@ public Map getAllExtensionsAttributesByResourceType // we update the full cache and set it as fully loaded extensionAttributesMap.forEach((identifiableId, extensionAttributes) -> addExtensionAttributesToCache(identifiableId, extensionName, extensionAttributes)); fullyLoadedExtensionsByExtensionName.add(extensionName); - extensionAttributesByExtensionName.put(extensionName, extensionAttributesMap); } - return extensionAttributesByExtensionName.get(extensionName); + //TODO This method is only used to load extension attributes in the collection cache when using preloading collection. + // The return is never used by the client as the call to getAllExtensionsAttributesByResourceTypeAndExtensionName() is always followed + // by a call to getExtensionAttributes(). The latter returns something meaningful for the client + // and it's used in the identifiable.getExtension() method. The map extensionAttributesMap can't be stored in the cache to be returned + // as we can't ensure synchronization with the resources map (if extensions or identifiables are updated/removed). + // We should refactor this method to return void. + return null; } /** @@ -479,20 +464,14 @@ public Map> getAllExtensionsAttributesB // we update the full cache and set it as fully loaded extensionAttributesMap.forEach(this::addAllExtensionAttributesToCache); fullyLoadedExtensions = true; - extensionAttributesByIdentifiableId.putAll(extensionAttributesMap); - updateExtensionAttributesByExtensionNameMap(extensionAttributesMap); } - return extensionAttributesByIdentifiableId; - } - - private void updateExtensionAttributesByExtensionNameMap(Map> extensionAttributesMap) { - extensionAttributesMap.forEach((identifiableId, nestedExtensionAttributesByExtensionName) -> - nestedExtensionAttributesByExtensionName.forEach((extensionName, extensionAttribute) -> - extensionAttributesByExtensionName - .computeIfAbsent(extensionName, k -> new HashMap<>()) - .put(identifiableId, extensionAttribute) - ) - ); + //TODO This method is only used to load extension attributes in the collection cache when using preloading collection. + // The return is never used by the client as the call to getAllExtensionsAttributesByResourceType() is always followed + // by a call to getAllExtensionsAttributesByIdentifiableId(). The latter returns something meaningful for the client + // and it's used in the identifiable.getExtensions() method. The map extensionAttributesMap can't be stored in the cache to be returned + // as we can't ensure synchronization with the resources map (if extensions or identifiables are updated/removed). + // We should refactor this method to return void. + return null; } public void removeExtensionAttributesByExtensionName(String identifiableId, String extensionName) { diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/CollectionCacheTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/CollectionCacheTest.java index 0ff83267c..d614fcfac 100644 --- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/CollectionCacheTest.java +++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/CollectionCacheTest.java @@ -495,13 +495,13 @@ public void getExtensionAttributesLoaderByResourceTypeAndName() { assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByResourceTypeAndNameCalled()); assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByIdCalled()); assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByResourceTypeCalled()); - assertEquals(Map.of("l1", apc1, "l2", apc2), collectionCache.getAllExtensionsAttributesByResourceTypeAndExtensionName(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, ResourceType.LOAD, "activePowerControl")); + assertNull(collectionCache.getAllExtensionsAttributesByResourceTypeAndExtensionName(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, ResourceType.LOAD, "activePowerControl")); assertFalse(mockNetworkStoreClient.isExtensionAttributeLoaderCalled()); assertTrue(mockNetworkStoreClient.isExtensionAttributesLoaderByResourceTypeAndNameCalled()); assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByIdCalled()); assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByResourceTypeCalled()); mockNetworkStoreClient.setExtensionAttributesLoaderByResourceTypeAndNameCalled(false); - assertEquals(Map.of("l1", apc1, "l2", apc2), collectionCache.getAllExtensionsAttributesByResourceTypeAndExtensionName(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, ResourceType.LOAD, "activePowerControl")); + assertNull(collectionCache.getAllExtensionsAttributesByResourceTypeAndExtensionName(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, ResourceType.LOAD, "activePowerControl")); assertEquals(apc1, collectionCache.getExtensionAttributes(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, ResourceType.LOAD, "l1", "activePowerControl").orElse(null)); assertEquals(apc2, collectionCache.getExtensionAttributes(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, ResourceType.LOAD, "l2", "activePowerControl").orElse(null)); assertFalse(mockNetworkStoreClient.isExtensionAttributeLoaderCalled()); @@ -539,13 +539,13 @@ public void getExtensionAttributesLoaderByResourceType() { assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByResourceTypeAndNameCalled()); assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByIdCalled()); assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByResourceTypeCalled()); - assertEquals(Map.of("l1", Map.of("activePowerControl", apc1, "operatingStatus", os1), "l2", Map.of("activePowerControl", apc2)), collectionCache.getAllExtensionsAttributesByResourceType(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, ResourceType.LOAD)); + assertNull(collectionCache.getAllExtensionsAttributesByResourceType(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, ResourceType.LOAD)); assertFalse(mockNetworkStoreClient.isExtensionAttributeLoaderCalled()); assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByResourceTypeAndNameCalled()); assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByIdCalled()); assertTrue(mockNetworkStoreClient.isExtensionAttributesLoaderByResourceTypeCalled()); mockNetworkStoreClient.setExtensionAttributesLoaderByResourceTypeCalled(false); - assertEquals(Map.of("l1", Map.of("activePowerControl", apc1, "operatingStatus", os1), "l2", Map.of("activePowerControl", apc2)), collectionCache.getAllExtensionsAttributesByResourceType(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, ResourceType.LOAD)); + assertNull(collectionCache.getAllExtensionsAttributesByResourceType(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, ResourceType.LOAD)); assertEquals(apc1, collectionCache.getExtensionAttributes(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, ResourceType.LOAD, "l1", "activePowerControl").orElse(null)); assertEquals(os1, collectionCache.getExtensionAttributes(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, ResourceType.LOAD, "l1", "operatingStatus").orElse(null)); assertEquals(apc2, collectionCache.getExtensionAttributes(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, ResourceType.LOAD, "l2", "activePowerControl").orElse(null)); @@ -553,11 +553,5 @@ public void getExtensionAttributesLoaderByResourceType() { assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByResourceTypeAndNameCalled()); assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByIdCalled()); assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByResourceTypeCalled()); - // Verify that the map extensionAttributesByExtensionName is correctly updated when calling getAllExtensionsAttributesByResourceType() - assertEquals(Map.of("l1", apc1, "l2", apc2), collectionCache.getAllExtensionsAttributesByResourceTypeAndExtensionName(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, ResourceType.LOAD, "activePowerControl")); - assertFalse(mockNetworkStoreClient.isExtensionAttributeLoaderCalled()); - assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByResourceTypeAndNameCalled()); - assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByIdCalled()); - assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByResourceTypeCalled()); } }