Skip to content

Commit

Permalink
Fix initialization of collection cache for extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinebhs committed Dec 5, 2024
1 parent 169f4dd commit c6143e7
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -120,6 +120,7 @@ public List<Resource<T>> getCachedResources() {
*/
public void init() {
fullyLoaded = true;
fullyLoadedExtensions = true;
}

public boolean isFullyLoaded() {
Original file line number Diff line number Diff line change
@@ -334,6 +334,24 @@ public void removeResourceThenGetContainerTest() {
assertEquals(1, collectionCache.getContainerResources(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, "vl1").size());
}

@Test
public void initExtensionsTest() {
assertEquals(Arrays.asList(l1, l2, l3), collectionCache.getResources(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM));
assertFalse(mockNetworkStoreClient.isExtensionAttributeLoaderCalled());
assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByResourceTypeAndNameCalled());
assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByIdCalled());
assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByResourceTypeCalled());
collectionCache.init(); // it means we trust cache content and no more server loading
collectionCache.getExtensionAttributes(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, ResourceType.LOAD, "l1", "activePowerControl");
collectionCache.getAllExtensionsAttributesByResourceTypeAndExtensionName(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, ResourceType.LOAD, "activePowerControl");
collectionCache.getAllExtensionsAttributesByIdentifiableId(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, ResourceType.LOAD, "l1");
collectionCache.getAllExtensionsAttributesByResourceType(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, ResourceType.LOAD);
assertFalse(mockNetworkStoreClient.isExtensionAttributeLoaderCalled());
assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByResourceTypeAndNameCalled());
assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByIdCalled());
assertFalse(mockNetworkStoreClient.isExtensionAttributesLoaderByResourceTypeCalled());
}

@Test
public void getExtensionAttributesWithResourceNotCachedMustThrow() {
PowsyblException exception = assertThrows(PowsyblException.class, () -> collectionCache.getExtensionAttributes(NETWORK_UUID, Resource.INITIAL_VARIANT_NUM, ResourceType.LOAD, "l1", "activePowerControl"));

0 comments on commit c6143e7

Please sign in to comment.