Skip to content

Commit

Permalink
Add basic tests on PreloadingNetworkStoreClient
Browse files Browse the repository at this point in the history
Signed-off-by: BOUHOURS Antoine <[email protected]>
  • Loading branch information
antoinebhs committed Oct 18, 2024
1 parent 10ed186 commit e50a021
Show file tree
Hide file tree
Showing 2 changed files with 463 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
*/
package com.powsybl.network.store.client;

import com.powsybl.iidm.network.VariantManagerConstants;
import com.powsybl.network.store.iidm.impl.CachedNetworkStoreClient;
import com.powsybl.network.store.iidm.impl.OfflineNetworkStoreClient;
import com.powsybl.network.store.model.NetworkAttributes;
import com.powsybl.network.store.model.Resource;
import com.powsybl.network.store.model.ResourceType;
import org.junit.Test;

import java.time.ZonedDateTime;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ForkJoinPool;

Expand All @@ -30,4 +35,32 @@ public void testWithAllCollections() {
client.getSubstations(networkUuid, 0);
assertFalse(client.shouldLoadAllCollectionsNeededForBusView(ResourceType.SUBSTATION));
}

@Test
public void testWithAllCollectionsDeleteNetwork() {
var client = new PreloadingNetworkStoreClient(new CachedNetworkStoreClient(new OfflineNetworkStoreClient()), true, ForkJoinPool.commonPool());
UUID networkUuid = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4");
Resource<NetworkAttributes> n1 = Resource.networkBuilder()
.id("n1")
.attributes(NetworkAttributes.builder()
.uuid(networkUuid)
.variantId(VariantManagerConstants.INITIAL_VARIANT_ID)
.caseDate(ZonedDateTime.parse("2015-01-01T00:00:00.000Z"))
.build())
.build();
client.createNetworks(List.of(n1));
assertTrue(client.shouldLoadAllCollectionsNeededForBusView(ResourceType.SUBSTATION));
client.getSubstations(networkUuid, 0);
assertFalse(client.shouldLoadAllCollectionsNeededForBusView(ResourceType.SUBSTATION));
// When we delete the network, we should load again all collection needed for bus view on next get
client.deleteNetwork(networkUuid);
assertTrue(client.shouldLoadAllCollectionsNeededForBusView(ResourceType.SUBSTATION));
client.createNetworks(List.of(n1));
assertTrue(client.shouldLoadAllCollectionsNeededForBusView(ResourceType.SUBSTATION));
client.getSubstations(networkUuid, 0);
assertFalse(client.shouldLoadAllCollectionsNeededForBusView(ResourceType.SUBSTATION));
// When we delete the network variant, we should load again all collection needed for bus view on next get
client.deleteNetwork(networkUuid, 0);
assertTrue(client.shouldLoadAllCollectionsNeededForBusView(ResourceType.SUBSTATION));
}
}
Loading

0 comments on commit e50a021

Please sign in to comment.