diff --git a/src/main/java/com/powsybl/caseserver/CaseService.java b/src/main/java/com/powsybl/caseserver/CaseService.java index aa7f9c6..1aa4474 100644 --- a/src/main/java/com/powsybl/caseserver/CaseService.java +++ b/src/main/java/com/powsybl/caseserver/CaseService.java @@ -262,6 +262,9 @@ public Set getCaseToReindex() { .map(CaseMetadataEntity::getId) .collect(Collectors.toSet()); } + public List getAllCases() { + return getCases(getStorageRootDir()); + } CaseInfos createInfos(String fileBaseName, UUID caseUuid, String format) { FileNameParser parser = FileNameParsers.findParser(fileBaseName); diff --git a/src/main/java/com/powsybl/caseserver/services/SupervisionService.java b/src/main/java/com/powsybl/caseserver/services/SupervisionService.java index 1a334af..94dbf17 100644 --- a/src/main/java/com/powsybl/caseserver/services/SupervisionService.java +++ b/src/main/java/com/powsybl/caseserver/services/SupervisionService.java @@ -38,7 +38,7 @@ public SupervisionService(CaseInfosService caseInfosService, CaseService caseSer } public void reindexAllCases() { - List allCases = caseService.getCases(caseService.getStorageRootDir()); + List allCases = caseService.getAllCases(); Set casesToIndex = caseService.getCaseToReindex(); List data = allCases.stream().filter(c -> casesToIndex.contains(c.getUuid())).toList(); caseInfosService.recreateAllCaseInfos(data); @@ -48,13 +48,13 @@ public long deleteIndexedDirectoryElements() { AtomicReference startTime = new AtomicReference<>(); startTime.set(System.nanoTime()); - long nbIndexesToDelete = getIndexedDirectoryElementsCount(); + long nbIndexesToDelete = getIndexedCaseElementsCount(); caseInfosRepository.deleteAll(); LOGGER.trace("Indexed directory elements deletion : {} seconds", TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startTime.get())); return nbIndexesToDelete; } - private long getIndexedDirectoryElementsCount() { + public long getIndexedCaseElementsCount() { return caseInfosRepository.count(); } } diff --git a/src/test/java/com/powsybl/caseserver/SupervisionTest.java b/src/test/java/com/powsybl/caseserver/SupervisionTest.java new file mode 100644 index 0000000..f73d3dd --- /dev/null +++ b/src/test/java/com/powsybl/caseserver/SupervisionTest.java @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package com.powsybl.caseserver; + +import com.powsybl.caseserver.elasticsearch.CaseInfosRepository; +import com.powsybl.caseserver.repository.CaseMetadataRepository; +import com.powsybl.caseserver.services.SupervisionService; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +/** + * @author Jamal KHEYYAD + */ +@RunWith(SpringRunner.class) +@AutoConfigureMockMvc +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK, properties = {"case-store-directory=/cases"}) +@ContextConfigurationWithTestChannel +public class SupervisionTest { + @Autowired + SupervisionService supervisionService; + @Autowired + CaseInfosRepository caseInfosRepository; + @Autowired + CaseMetadataRepository caseMetadataRepository; + @Autowired + CaseService caseService; + + @Autowired + private MockMvc mvc; + + @Test + public void testGetElementInfosCount() { + supervisionService.getIndexedCaseElementsCount(); + verify(caseInfosRepository, times(1)).count(); + } + + @Test + public void testDeleteElementInfos() { + supervisionService.deleteIndexedDirectoryElements(); + + verify(caseInfosRepository, times(1)).count(); + verify(caseInfosRepository, times(1)).deleteAll(); + } + + +}