-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug/met 6244 add vacuum procedure to repositories (#170)
* MET-6244 add vacuum cleaner * MET-6244 fixing removal order for records tables * MET-6244 fix table names
- Loading branch information
1 parent
bc50bb4
commit 3c538f1
Showing
4 changed files
with
120 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/eu/europeana/metis/sandbox/service/util/VacuumService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package eu.europeana.metis.sandbox.service.util; | ||
|
||
import java.util.List; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* The type Vacuum service. | ||
*/ | ||
@Service | ||
public class VacuumService { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(VacuumService.class); | ||
|
||
private final JdbcTemplate jdbcTemplate; | ||
|
||
/** | ||
* Instantiates a new Vacuum service. | ||
* | ||
* @param jdbcTemplate the jdbc template | ||
*/ | ||
public VacuumService(JdbcTemplate jdbcTemplate) { | ||
this.jdbcTemplate = jdbcTemplate; | ||
} | ||
|
||
/** | ||
* Vacuum the listed tables. | ||
*/ | ||
public void vacuum() { | ||
List<String> tables = List.of( | ||
"problem_patterns.record_problem_pattern", | ||
"problem_patterns.record_problem_pattern_occurrence", | ||
"problem_patterns.record_title", | ||
"problem_patterns.dataset_problem_pattern", | ||
"problem_patterns.execution_point", | ||
"public.record_log", | ||
"public.record_error_log", | ||
"public.record", | ||
"public.harvesting_parameter", | ||
"public.record_debias_detail", | ||
"public.record_debias_main", | ||
"public.dataset_debias_detect", | ||
"public.dataset_log", | ||
"public.dataset", | ||
"integration.int_lock", | ||
"rate_limit.buckets" | ||
); | ||
tables.forEach(table -> { | ||
LOGGER.info("Performing vacuum of table {}", table); | ||
jdbcTemplate.execute(String.format("VACUUM %s", table)); | ||
LOGGER.info("Vacuum of table {} completed", table); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/test/java/eu/europeana/metis/sandbox/service/util/VacuumServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package eu.europeana.metis.sandbox.service.util; | ||
|
||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.doNothing; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class VacuumServiceTest { | ||
|
||
@Mock | ||
JdbcTemplate jdbcTemplate; | ||
|
||
@InjectMocks | ||
VacuumService vacuumService; | ||
|
||
@Test | ||
void vacuum() { | ||
doNothing().when(jdbcTemplate).execute(anyString()); | ||
|
||
vacuumService.vacuum(); | ||
|
||
verify(jdbcTemplate,times(16)).execute(anyString()); | ||
} | ||
} |