From a39820492053a81f106317c46292f6421dd775b1 Mon Sep 17 00:00:00 2001 From: Ivan Vakhrushev Date: Tue, 12 Nov 2024 23:15:17 +0400 Subject: [PATCH] Refactor tests --- .../host/IndexesWithBloatCheckOnHostTest.java | 5 +++++ .../host/TablesWithBloatCheckOnHostTest.java | 5 +++++ .../IndexesWithBloatCheckOnClusterTest.java | 4 ++-- .../TablesWithBloatCheckOnClusterTest.java | 17 ++++------------- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/checks/host/IndexesWithBloatCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/checks/host/IndexesWithBloatCheckOnHostTest.java index 00290551..d653cf89 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/checks/host/IndexesWithBloatCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/checks/host/IndexesWithBloatCheckOnHostTest.java @@ -14,6 +14,7 @@ import io.github.mfvanek.pg.common.maintenance.Diagnostic; import io.github.mfvanek.pg.model.PgContext; import io.github.mfvanek.pg.model.index.IndexWithBloat; +import io.github.mfvanek.pg.model.predicates.SkipBloatUnderThresholdPredicate; import io.github.mfvanek.pg.model.predicates.SkipIndexesByNamePredicate; import io.github.mfvanek.pg.model.predicates.SkipTablesByNamePredicate; import io.github.mfvanek.pg.support.StatisticsAwareTestBase; @@ -67,6 +68,10 @@ void onDatabaseWithThem(final String schemaName) { assertThat(check) .executing(ctx, SkipIndexesByNamePredicate.of(ctx, List.of("accounts_account_number_key", "accounts_pkey", "clients_pkey", "i_clients_email_phone"))) .isEmpty(); + + assertThat(check) + .executing(ctx, SkipBloatUnderThresholdPredicate.of(10_000L, 25.0)) + .isEmpty(); }); } } diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/checks/host/TablesWithBloatCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/checks/host/TablesWithBloatCheckOnHostTest.java index 48f4b078..43d27837 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/checks/host/TablesWithBloatCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/checks/host/TablesWithBloatCheckOnHostTest.java @@ -13,6 +13,7 @@ import io.github.mfvanek.pg.common.maintenance.DatabaseCheckOnHost; import io.github.mfvanek.pg.common.maintenance.Diagnostic; import io.github.mfvanek.pg.model.PgContext; +import io.github.mfvanek.pg.model.predicates.SkipBloatUnderThresholdPredicate; import io.github.mfvanek.pg.model.predicates.SkipTablesByNamePredicate; import io.github.mfvanek.pg.model.table.TableWithBloat; import io.github.mfvanek.pg.support.StatisticsAwareTestBase; @@ -58,6 +59,10 @@ void onDatabaseWithThem(final String schemaName) { assertThat(check) .executing(ctx, SkipTablesByNamePredicate.of(ctx, List.of("accounts", "clients"))) .isEmpty(); + + assertThat(check) + .executing(ctx, SkipBloatUnderThresholdPredicate.of(0L, 0.1)) + .isEmpty(); }); } } diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/checks/cluster/IndexesWithBloatCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/checks/cluster/IndexesWithBloatCheckOnClusterTest.java index bcddb1b4..a448d5a5 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/checks/cluster/IndexesWithBloatCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/checks/cluster/IndexesWithBloatCheckOnClusterTest.java @@ -10,11 +10,11 @@ package io.github.mfvanek.pg.checks.cluster; -import io.github.mfvanek.pg.checks.predicates.FilterIndexesByBloatPredicate; import io.github.mfvanek.pg.common.maintenance.DatabaseCheckOnCluster; import io.github.mfvanek.pg.common.maintenance.Diagnostic; import io.github.mfvanek.pg.model.PgContext; import io.github.mfvanek.pg.model.index.IndexWithBloat; +import io.github.mfvanek.pg.model.predicates.SkipBloatUnderThresholdPredicate; import io.github.mfvanek.pg.model.predicates.SkipIndexesByNamePredicate; import io.github.mfvanek.pg.model.predicates.SkipTablesByNamePredicate; import io.github.mfvanek.pg.support.DatabasePopulator; @@ -82,7 +82,7 @@ void onDatabaseWithThem(final String schemaName) { .isEmpty(); assertThat(check) - .executing(ctx, FilterIndexesByBloatPredicate.of(1_000_000L, 50)) + .executing(ctx, SkipBloatUnderThresholdPredicate.of(10_000L, 25.0)) .isEmpty(); }); } diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/checks/cluster/TablesWithBloatCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/checks/cluster/TablesWithBloatCheckOnClusterTest.java index e33d0d2f..8cace23a 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/checks/cluster/TablesWithBloatCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/checks/cluster/TablesWithBloatCheckOnClusterTest.java @@ -10,13 +10,11 @@ package io.github.mfvanek.pg.checks.cluster; -import io.github.mfvanek.pg.checks.predicates.FilterTablesByBloatPredicate; -import io.github.mfvanek.pg.checks.predicates.FilterTablesByNamePredicate; import io.github.mfvanek.pg.common.maintenance.DatabaseCheckOnCluster; import io.github.mfvanek.pg.common.maintenance.Diagnostic; import io.github.mfvanek.pg.model.PgContext; +import io.github.mfvanek.pg.model.predicates.SkipBloatUnderThresholdPredicate; import io.github.mfvanek.pg.model.predicates.SkipTablesByNamePredicate; -import io.github.mfvanek.pg.model.table.TableBloatAware; import io.github.mfvanek.pg.model.table.TableWithBloat; import io.github.mfvanek.pg.support.StatisticsAwareTestBase; import org.assertj.core.api.Assertions; @@ -25,7 +23,6 @@ import org.junit.jupiter.params.provider.ValueSource; import java.util.List; -import java.util.function.Predicate; import static io.github.mfvanek.pg.support.AbstractCheckOnClusterAssert.assertThat; @@ -59,17 +56,11 @@ void onDatabaseWithThem(final String schemaName) { .allMatch(t -> t.getBloatPercentage() == 0 && t.getBloatSizeInBytes() == 0L); assertThat(check) - .executing(ctx, SkipTablesByNamePredicate.of(ctx, List.of("clients"))) - .hasSize(1) - .containsExactly( - TableWithBloat.of(ctx.enrichWithSchema("accounts"), 0L, 0L, 0)) - .allMatch(t -> t.getTableSizeInBytes() > 0L) // real size doesn't matter - .allMatch(t -> t.getBloatPercentage() == 0 && t.getBloatSizeInBytes() == 0L); + .executing(ctx, SkipTablesByNamePredicate.of(ctx, List.of("accounts", "clients"))) + .isEmpty(); - final Predicate predicate = FilterTablesByBloatPredicate.of(0L, 10) - .and(FilterTablesByNamePredicate.of(ctx.enrichWithSchema("clients"))); assertThat(check) - .executing(ctx, predicate) + .executing(ctx, SkipBloatUnderThresholdPredicate.of(0L, 0.1)) .isEmpty(); }); }