Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mfvanek committed Nov 12, 2024
1 parent a18edeb commit a398204
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<TableBloatAware> predicate = FilterTablesByBloatPredicate.of(0L, 10)
.and(FilterTablesByNamePredicate.of(ctx.enrichWithSchema("clients")));
assertThat(check)
.executing(ctx, predicate)
.executing(ctx, SkipBloatUnderThresholdPredicate.of(0L, 0.1))
.isEmpty();
});
}
Expand Down

0 comments on commit a398204

Please sign in to comment.