From d9143e0b449c7d955845970584b9cced0315dd7a Mon Sep 17 00:00:00 2001 From: Ivan Vakhrushev Date: Sun, 8 Dec 2024 23:40:38 +0400 Subject: [PATCH] Add overloaded methods to create tables/indexes without specifying zero (#531) * Creation of Table with zero size * Creation of Indexes with zero size * Add javadoc * Add additional constructors to the Table * Add additional constructors to the TableWithBloat and TableWithMissingIndex * Add additional constructors to the SequenceState * Add additional constructors to the StoredFunction * Add additional constructors to the Index and IndexWithBloat * Add additional constructors to the IndexWithColumns and Column * Add additional constructors to the IndexWithNulls * Add additional constructors to the IndexWithSize * Add additional constructors to the UnusedIndex * Add additional constructors to the IndexWithBloat and TableWithBloat * Add additional constructors to the Constraint --- ...eIndexesOnArrayColumnsCheckOnHostTest.java | 4 +- ...ColumnsWithSerialTypesCheckOnHostTest.java | 10 ++-- ...umnsWithoutDescriptionCheckOnHostTest.java | 4 +- .../DuplicatedIndexesCheckOnHostTest.java | 4 +- ...ionsWithoutDescriptionCheckOnHostTest.java | 4 +- .../host/IndexesWithBloatCheckOnHostTest.java | 8 +-- .../IndexesWithBooleanCheckOnHostTest.java | 4 +- .../IndexesWithNullValuesCheckOnHostTest.java | 3 +- .../IntersectedIndexesCheckOnHostTest.java | 13 ++--- .../host/InvalidIndexesCheckOnHostTest.java | 3 +- .../NotValidConstraintsCheckOnHostTest.java | 4 +- ...aryKeysWithSerialTypesCheckOnHostTest.java | 2 +- .../host/SequenceOverflowCheckOnHostTest.java | 6 +-- ...ablesNotLinkedToOthersCheckOnHostTest.java | 2 +- .../host/TablesWithBloatCheckOnHostTest.java | 4 +- ...blesWithMissingIndexesCheckOnHostTest.java | 2 +- ...blesWithoutDescriptionCheckOnHostTest.java | 10 ++-- ...ablesWithoutPrimaryKeyCheckOnHostTest.java | 2 +- .../host/UnusedIndexesCheckOnHostTest.java | 12 ++--- .../health/logger/AbstractHealthLogger.java | 8 +-- .../mfvanek/pg/model/column/Column.java | 39 +++++++++++++- .../pg/model/constraint/Constraint.java | 19 +++++++ .../mfvanek/pg/model/context/PgContext.java | 15 ++++++ .../pg/model/function/StoredFunction.java | 36 ++++++++++++- .../github/mfvanek/pg/model/index/Index.java | 21 +++++++- .../pg/model/index/IndexWithBloat.java | 40 ++++++++++++++ .../pg/model/index/IndexWithColumns.java | 41 +++++++++++++++ .../pg/model/index/IndexWithNulls.java | 22 ++++++++ .../mfvanek/pg/model/index/IndexWithSize.java | 49 +++++++++++++++++ .../mfvanek/pg/model/index/UnusedIndex.java | 52 +++++++++++++++++++ .../pg/model/sequence/SequenceState.java | 19 +++++++ .../pg/model/settings/ParamNameAware.java | 8 +++ .../pg/model/settings/PgParamImpl.java | 3 ++ .../github/mfvanek/pg/model/table/Table.java | 47 ++++++++++++++++- .../pg/model/table/TableWithBloat.java | 38 ++++++++++++++ .../pg/model/table/TableWithMissingIndex.java | 24 +++++++++ .../mfvanek/pg/model/column/ColumnTest.java | 8 ++- .../pg/model/constraint/ConstraintTest.java | 12 +++-- .../pg/model/context/PgContextTest.java | 7 +++ .../pg/model/function/StoredFunctionTest.java | 12 +++++ .../mfvanek/pg/model/index/IndexTest.java | 6 +++ .../pg/model/index/IndexWithBloatTest.java | 10 +++- .../pg/model/index/IndexWithColumnsTest.java | 12 +++-- .../pg/model/index/IndexWithNullsTest.java | 8 ++- .../pg/model/index/IndexWithSizeTest.java | 10 +++- .../pg/model/index/UnusedIndexTest.java | 9 ++++ .../AbstractSkipTablesPredicateTest.java | 2 +- .../SkipBloatUnderThresholdPredicateTest.java | 2 +- .../SkipBySequenceNamePredicateTest.java | 12 ++--- .../SkipFlywayTablesPredicateTest.java | 16 +++--- .../SkipIndexesByNamePredicateTest.java | 12 ++--- .../SkipLiquibaseTablesPredicateTest.java | 20 +++---- .../SkipSmallIndexesPredicateTest.java | 2 +- .../SkipTablesByNamePredicateTest.java | 12 ++--- .../mfvanek/pg/model/table/TableTest.java | 15 +++++- .../pg/model/table/TableWithBloatTest.java | 9 ++++ .../table/TableWithMissingIndexTest.java | 6 +++ ...dexesOnArrayColumnsCheckOnClusterTest.java | 4 +- ...umnsWithSerialTypesCheckOnClusterTest.java | 10 ++-- ...sWithoutDescriptionCheckOnClusterTest.java | 4 +- .../DuplicatedIndexesCheckOnClusterTest.java | 4 +- ...sWithoutDescriptionCheckOnClusterTest.java | 4 +- .../IndexesWithBloatCheckOnClusterTest.java | 8 +-- .../IndexesWithBooleanCheckOnClusterTest.java | 4 +- ...dexesWithNullValuesCheckOnClusterTest.java | 3 +- .../IntersectedIndexesCheckOnClusterTest.java | 12 ++--- .../InvalidIndexesCheckOnClusterTest.java | 3 +- ...NotValidConstraintsCheckOnClusterTest.java | 4 +- ...KeysWithSerialTypesCheckOnClusterTest.java | 2 +- .../SequenceOverflowCheckOnClusterTest.java | 6 +-- ...esNotLinkedToOthersCheckOnClusterTest.java | 2 +- .../TablesWithBloatCheckOnClusterTest.java | 4 +- ...sWithMissingIndexesCheckOnClusterTest.java | 2 +- ...sWithoutDescriptionCheckOnClusterTest.java | 12 ++--- ...esWithoutPrimaryKeyCheckOnClusterTest.java | 2 +- .../UnusedIndexesCheckOnClusterTest.java | 12 ++--- .../common/DatabaseCheckOnClusterTest.java | 4 +- ...esCustomDataSourceDemoApplicationKtTest.kt | 2 +- 78 files changed, 724 insertions(+), 168 deletions(-) diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/BtreeIndexesOnArrayColumnsCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/BtreeIndexesOnArrayColumnsCheckOnHostTest.java index 7cdfe693..7946e778 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/BtreeIndexesOnArrayColumnsCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/BtreeIndexesOnArrayColumnsCheckOnHostTest.java @@ -45,9 +45,9 @@ void onDatabaseWithThem(final String schemaName) { .executing(ctx) .hasSize(2) .containsExactlyInAnyOrder( - IndexWithColumns.ofSingle(accountsTableName, ctx.enrichWithSchema("accounts_roles_btree_idx"), 0L, + IndexWithColumns.ofSingle(ctx, accountsTableName, "accounts_roles_btree_idx", 0L, Column.ofNotNull(accountsTableName, "roles")), - IndexWithColumns.ofSingle(accountsTableName, ctx.enrichWithSchema("accounts_account_number_roles_btree_idx"), 0L, + IndexWithColumns.ofSingle(ctx, accountsTableName, "accounts_account_number_roles_btree_idx", 0L, Column.ofNotNull(accountsTableName, "roles")) ); diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/ColumnsWithSerialTypesCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/ColumnsWithSerialTypesCheckOnHostTest.java index 173252dc..139f8468 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/ColumnsWithSerialTypesCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/ColumnsWithSerialTypesCheckOnHostTest.java @@ -74,7 +74,7 @@ void shouldIgnoreDroppedColumns(final String schemaName) { .hasSize(1) .containsExactly( ColumnWithSerialType.ofBigSerial( - Column.ofNotNull(ctx.enrichWithSchema("bad_accounts"), "real_client_id"), ctx.enrichWithSchema("bad_accounts_real_client_id_seq")) + Column.ofNotNull(ctx, "bad_accounts", "real_client_id"), ctx.enrichWithSchema("bad_accounts_real_client_id_seq")) ); assertThat(check) @@ -105,7 +105,7 @@ void shouldDetectSerialColumnsWithUniqueConstraints(final String schemaName) { .hasSize(1) .containsExactly( ColumnWithSerialType.ofBigSerial( - Column.ofNotNull(ctx.enrichWithSchema("one_more_table"), "id"), ctx.enrichWithSchema("one_more_table_id_seq")) + Column.ofNotNull(ctx, "one_more_table", "id"), ctx.enrichWithSchema("one_more_table_id_seq")) )); } @@ -118,11 +118,11 @@ void shouldDetectPrimaryKeysThatAreForeignKeysAsWell(final String schemaName) { .hasSize(3) .containsExactly( ColumnWithSerialType.ofBigSerial( - Column.ofNotNull(ctx.enrichWithSchema("one_more_table"), "id"), ctx.enrichWithSchema("one_more_table_id_seq")), + Column.ofNotNull(ctx, "one_more_table", "id"), ctx.enrichWithSchema("one_more_table_id_seq")), ColumnWithSerialType.ofBigSerial( - Column.ofNotNull(ctx.enrichWithSchema("test_table"), "id"), ctx.enrichWithSchema("test_table_id_seq")), + Column.ofNotNull(ctx, "test_table", "id"), ctx.enrichWithSchema("test_table_id_seq")), ColumnWithSerialType.ofBigSerial( - Column.ofNotNull(ctx.enrichWithSchema("test_table"), "num"), ctx.enrichWithSchema("test_table_num_seq")) + Column.ofNotNull(ctx, "test_table", "num"), ctx.enrichWithSchema("test_table_num_seq")) )); } } diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/ColumnsWithoutDescriptionCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/ColumnsWithoutDescriptionCheckOnHostTest.java index 171cfb17..e3a65dd9 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/ColumnsWithoutDescriptionCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/ColumnsWithoutDescriptionCheckOnHostTest.java @@ -79,8 +79,8 @@ void shouldNotTakingIntoAccountBlankComments(final String schemaName) { .filteredOn(c -> "id".equalsIgnoreCase(c.getColumnName())) .hasSize(2) .containsExactly( - Column.ofNotNull(ctx.enrichWithSchema("accounts"), "id"), - Column.ofNotNull(ctx.enrichWithSchema("clients"), "id"))); + Column.ofNotNull(ctx, "accounts", "id"), + Column.ofNotNull(ctx, "clients", "id"))); } @ParameterizedTest diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/DuplicatedIndexesCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/DuplicatedIndexesCheckOnHostTest.java index 17723560..6e21b103 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/DuplicatedIndexesCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/DuplicatedIndexesCheckOnHostTest.java @@ -46,8 +46,8 @@ void onDatabaseWithThem(final String schemaName) { .hasSize(1) .containsExactly( DuplicatedIndexes.of( - IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("accounts_account_number_key"), 0L), - IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number"), 0L))) + IndexWithSize.of(ctx, "accounts", "accounts_account_number_key"), + IndexWithSize.of(ctx, "accounts", "i_accounts_account_number"))) .allMatch(d -> d.getTotalSize() >= 16_384L); assertThat(check) diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/FunctionsWithoutDescriptionCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/FunctionsWithoutDescriptionCheckOnHostTest.java index 3c8ceac8..4c433971 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/FunctionsWithoutDescriptionCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/FunctionsWithoutDescriptionCheckOnHostTest.java @@ -86,8 +86,8 @@ void shouldNotTakingIntoAccountBlankComments(final String schemaName) { .executing(ctx) .hasSize(2) .containsExactly( - StoredFunction.of(ctx.enrichWithSchema("add"), "a integer, b integer"), - StoredFunction.of(ctx.enrichWithSchema("add"), "a integer, b integer, c integer") + StoredFunction.of(ctx, "add", "a integer, b integer"), + StoredFunction.of(ctx, "add", "a integer, b integer, c integer") )); } diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/IndexesWithBloatCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/IndexesWithBloatCheckOnHostTest.java index dbb714db..43d2726d 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/IndexesWithBloatCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/IndexesWithBloatCheckOnHostTest.java @@ -55,10 +55,10 @@ void onDatabaseWithThem(final String schemaName) { .executing(ctx) .hasSize(4) .containsExactlyInAnyOrder( - IndexWithBloat.of(accountsTableName, ctx.enrichWithSchema("accounts_account_number_key"), 0L, 0L, 0), - IndexWithBloat.of(accountsTableName, ctx.enrichWithSchema("accounts_pkey"), 0L, 0L, 0), - IndexWithBloat.of(clientsTableName, ctx.enrichWithSchema("clients_pkey"), 0L, 0L, 0), - IndexWithBloat.of(clientsTableName, ctx.enrichWithSchema("i_clients_email_phone"), 0L, 0L, 0)) + IndexWithBloat.of(ctx, accountsTableName, "accounts_account_number_key"), + IndexWithBloat.of(ctx, accountsTableName, "accounts_pkey"), + IndexWithBloat.of(ctx, clientsTableName, "clients_pkey"), + IndexWithBloat.of(ctx, clientsTableName, "i_clients_email_phone")) .allMatch(i -> i.getIndexSizeInBytes() > 1L) .allMatch(i -> i.getBloatSizeInBytes() > 1L && i.getBloatPercentage() >= 14); diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/IndexesWithBooleanCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/IndexesWithBooleanCheckOnHostTest.java index 3007c333..ebffe024 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/IndexesWithBooleanCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/IndexesWithBooleanCheckOnHostTest.java @@ -45,8 +45,8 @@ void onDatabaseWithThem(final String schemaName) { .executing(ctx) .hasSize(1) .containsExactly( - IndexWithColumns.ofSingle(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_deleted"), 0L, - Column.ofNotNull(ctx.enrichWithSchema("accounts"), "deleted")) + IndexWithColumns.ofSingle(ctx, "accounts", "i_accounts_deleted", 0L, + Column.ofNotNull(ctx, "accounts", "deleted")) ); assertThat(check) diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/IndexesWithNullValuesCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/IndexesWithNullValuesCheckOnHostTest.java index 6e408a10..76353270 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/IndexesWithNullValuesCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/IndexesWithNullValuesCheckOnHostTest.java @@ -43,8 +43,7 @@ void onDatabaseWithThem(final String schemaName) { assertThat(check) .executing(ctx) .hasSize(1) - .containsExactly( - IndexWithNulls.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_middle_name"), 0L, "middle_name")) + .containsExactly(IndexWithNulls.of(ctx, "clients", "i_clients_middle_name", 0L, "middle_name")) .allMatch(i -> i.getNullableColumn().isNullable()); assertThat(check) diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/IntersectedIndexesCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/IntersectedIndexesCheckOnHostTest.java index 67d56100..af2c1db0 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/IntersectedIndexesCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/IntersectedIndexesCheckOnHostTest.java @@ -48,12 +48,13 @@ void onDatabaseWithThem(final String schemaName) { .hasSize(2) .containsExactly( DuplicatedIndexes.of( - IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number_not_deleted"), 0L), - IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_number_balance_not_deleted"), 0L) + IndexWithSize.of(ctx, "accounts", "i_accounts_account_number_not_deleted"), + IndexWithSize.of(ctx, "accounts", "i_accounts_number_balance_not_deleted") ), DuplicatedIndexes.of( - IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first"), 0L), - IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name"), 0L))) + IndexWithSize.of(ctx, "clients", "i_clients_last_first"), + IndexWithSize.of(ctx, "clients", "i_clients_last_name") + )) .allMatch(d -> d.getTotalSize() >= 106_496L); assertThat(check) @@ -75,8 +76,8 @@ void shouldFindHashIndex(final String schemaName) { .hasSize(1) .containsExactly( DuplicatedIndexes.of( - IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first"), 0L), - IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name"), 0L))) + IndexWithSize.of(ctx, "clients", "i_clients_last_first"), + IndexWithSize.of(ctx, "clients", "i_clients_last_name"))) .allMatch(d -> d.getTotalSize() >= 106_496L); assertThat(check) diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/InvalidIndexesCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/InvalidIndexesCheckOnHostTest.java index 2bde20d8..0d874335 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/InvalidIndexesCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/InvalidIndexesCheckOnHostTest.java @@ -43,8 +43,7 @@ void onDatabaseWithThem(final String schemaName) { assertThat(check) .executing(ctx) .hasSize(1) - .containsExactly( - Index.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name_first_name"))); + .containsExactly(Index.of(ctx, "clients", "i_clients_last_name_first_name")); assertThat(check) .executing(ctx, SkipTablesByNamePredicate.ofName(ctx, "clients")) diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/NotValidConstraintsCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/NotValidConstraintsCheckOnHostTest.java index 436a3023..ca3ff678 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/NotValidConstraintsCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/NotValidConstraintsCheckOnHostTest.java @@ -48,8 +48,8 @@ void onDatabaseWithThem(final String schemaName) { Assertions.assertThat(notValidConstraints) .hasSize(2) .containsExactly( - Constraint.ofType(ctx.enrichWithSchema("accounts"), "c_accounts_chk_client_id_not_validated_yet", ConstraintType.CHECK), - Constraint.ofType(ctx.enrichWithSchema("accounts"), "c_accounts_fk_client_id_not_validated_yet", ConstraintType.FOREIGN_KEY)); + Constraint.ofType(ctx, "accounts", "c_accounts_chk_client_id_not_validated_yet", ConstraintType.CHECK), + Constraint.ofType(ctx, "accounts", "c_accounts_fk_client_id_not_validated_yet", ConstraintType.FOREIGN_KEY)); assertThat(check) .executing(ctx, SkipTablesByNamePredicate.ofName(ctx, "accounts")) diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/PrimaryKeysWithSerialTypesCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/PrimaryKeysWithSerialTypesCheckOnHostTest.java index f5abc73c..53255006 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/PrimaryKeysWithSerialTypesCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/PrimaryKeysWithSerialTypesCheckOnHostTest.java @@ -47,7 +47,7 @@ void onDatabaseWithThem(final String schemaName) { .hasSize(1) .containsExactlyInAnyOrder( ColumnWithSerialType.of( - Column.ofNotNull(ctx.enrichWithSchema("bad_accounts"), "id"), SerialType.BIG_SERIAL, ctx.enrichWithSchema("bad_accounts_id_seq") + Column.ofNotNull(ctx, "bad_accounts", "id"), SerialType.BIG_SERIAL, ctx.enrichWithSchema("bad_accounts_id_seq") )); assertThat(check) diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/SequenceOverflowCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/SequenceOverflowCheckOnHostTest.java index e43b6671..b7dfb4eb 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/SequenceOverflowCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/SequenceOverflowCheckOnHostTest.java @@ -46,9 +46,9 @@ void onDatabaseWithSequences(final String schemaName) { .executing(ctx) .hasSize(3) .containsExactlyInAnyOrder( - SequenceState.of(ctx.enrichWithSchema("seq_1"), "smallint", 8.08), - SequenceState.of(ctx.enrichWithSchema("seq_3"), "integer", 8.08), - SequenceState.of(ctx.enrichWithSchema("seq_5"), "bigint", 8.08)); + SequenceState.of(ctx, "seq_1", "smallint", 8.08), + SequenceState.of(ctx, "seq_3", "integer", 8.08), + SequenceState.of(ctx, "seq_5", "bigint", 8.08)); assertThat(check) .executing(ctx, SkipBySequenceNamePredicate.of(ctx, List.of("seq_1", "seq_3", "seq_5"))) diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesNotLinkedToOthersCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesNotLinkedToOthersCheckOnHostTest.java index f0f7b2cd..e8c1f803 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesNotLinkedToOthersCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesNotLinkedToOthersCheckOnHostTest.java @@ -42,7 +42,7 @@ void onDatabaseWithThem(final String schemaName) { assertThat(check) .executing(ctx) .hasSize(1) - .containsExactly(Table.of(ctx.enrichWithSchema("bad_clients"), 0L)); + .containsExactly(Table.of(ctx, "bad_clients")); assertThat(check) .executing(ctx, SkipTablesByNamePredicate.ofName(ctx, "bad_clients")) diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesWithBloatCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesWithBloatCheckOnHostTest.java index 6f416d26..4e435c3b 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesWithBloatCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesWithBloatCheckOnHostTest.java @@ -51,8 +51,8 @@ void onDatabaseWithThem(final String schemaName) { .executing(ctx) .hasSize(2) .containsExactlyInAnyOrder( - TableWithBloat.of(ctx.enrichWithSchema("accounts"), 0L, 0L, 0), - TableWithBloat.of(ctx.enrichWithSchema("clients"), 0L, 0L, 0)) + TableWithBloat.of(ctx, "accounts"), + TableWithBloat.of(ctx, "clients")) .allMatch(t -> t.getTableSizeInBytes() > 0L) // real size doesn't matter .allMatch(t -> t.getBloatPercentage() == 0 && t.getBloatSizeInBytes() == 0L); diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesWithMissingIndexesCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesWithMissingIndexesCheckOnHostTest.java index e0457eda..4eb92463 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesWithMissingIndexesCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesWithMissingIndexesCheckOnHostTest.java @@ -45,7 +45,7 @@ void onDatabaseWithThem(final String schemaName) { .executing(ctx) .hasSize(1) .containsExactly( - TableWithMissingIndex.of(ctx.enrichWithSchema("accounts"), 0L, 0L, 0L)) + TableWithMissingIndex.of(ctx, "accounts", 0L, 0L, 0L)) .allMatch(t -> t.getSeqScans() >= AMOUNT_OF_TRIES) .allMatch(t -> t.getIndexScans() == 0) .allMatch(t -> t.getTableSizeInBytes() > 1L); diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesWithoutDescriptionCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesWithoutDescriptionCheckOnHostTest.java index 02ff8d55..1140f7e9 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesWithoutDescriptionCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesWithoutDescriptionCheckOnHostTest.java @@ -47,8 +47,8 @@ void onDatabaseWithThem(final String schemaName) { .executing(ctx) .hasSize(2) .containsExactly( - Table.of(ctx.enrichWithSchema("accounts"), 0L), - Table.of(ctx.enrichWithSchema("clients"), 0L)); + Table.of(ctx, "accounts"), + Table.of(ctx, "clients")); assertThat(check) .executing(ctx, SkipTablesByNamePredicate.of(ctx, List.of("accounts", "clients"))) @@ -64,13 +64,13 @@ void shouldNotTakingIntoAccountBlankComments(final String schemaName) { .executing(ctx) .hasSize(2) .containsExactly( - Table.of(ctx.enrichWithSchema("accounts"), 0L), - Table.of(ctx.enrichWithSchema("clients"), 0L)); + Table.of(ctx, "accounts"), + Table.of(ctx, "clients")); assertThat(check) .executing(ctx, SkipSmallTablesPredicate.of(1_234L)) .hasSize(1) - .containsExactly(Table.of(ctx.enrichWithSchema("clients"), 0L)) + .containsExactly(Table.of(ctx, "clients")) .allMatch(t -> t.getTableSizeInBytes() > 1_234L); }); } diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesWithoutPrimaryKeyCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesWithoutPrimaryKeyCheckOnHostTest.java index bf2b6e12..38b8d645 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesWithoutPrimaryKeyCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesWithoutPrimaryKeyCheckOnHostTest.java @@ -42,7 +42,7 @@ void onDatabaseWithThem(final String schemaName) { assertThat(check) .executing(ctx) .hasSize(1) - .containsExactly(Table.of(ctx.enrichWithSchema("bad_clients"), 0L)); + .containsExactly(Table.of(ctx, "bad_clients")); assertThat(check) .executing(ctx, SkipTablesByNamePredicate.ofName(ctx, "bad_clients")) diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/UnusedIndexesCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/UnusedIndexesCheckOnHostTest.java index 777ce674..a0db5b98 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/UnusedIndexesCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/UnusedIndexesCheckOnHostTest.java @@ -47,12 +47,12 @@ void onDatabaseWithThem(final String schemaName) { .executing(ctx) .hasSize(6) .containsExactlyInAnyOrder( - UnusedIndex.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first"), 0L, 0), - UnusedIndex.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name"), 0L, 0), - UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number"), 0L, 0), - UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_number_balance_not_deleted"), 0L, 0), - UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number_not_deleted"), 0L, 0), - UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_id_account_number_not_deleted"), 0L, 0)) + UnusedIndex.of(ctx, "clients", "i_clients_last_first"), + UnusedIndex.of(ctx, "clients", "i_clients_last_name"), + UnusedIndex.of(ctx, "accounts", "i_accounts_account_number"), + UnusedIndex.of(ctx, "accounts", "i_accounts_number_balance_not_deleted"), + UnusedIndex.of(ctx, "accounts", "i_accounts_account_number_not_deleted"), + UnusedIndex.of(ctx, "accounts", "i_accounts_id_account_number_not_deleted")) .allMatch(i -> i.getIndexSizeInBytes() > 0L) .allMatch(i -> i.getIndexScans() == 0); diff --git a/pg-index-health-logger/src/main/java/io/github/mfvanek/pg/health/logger/AbstractHealthLogger.java b/pg-index-health-logger/src/main/java/io/github/mfvanek/pg/health/logger/AbstractHealthLogger.java index 44ca7dbc..27de58da 100644 --- a/pg-index-health-logger/src/main/java/io/github/mfvanek/pg/health/logger/AbstractHealthLogger.java +++ b/pg-index-health-logger/src/main/java/io/github/mfvanek/pg/health/logger/AbstractHealthLogger.java @@ -77,10 +77,10 @@ public final List logAll(@Nonnull final Exclusions exclusions, return logResult; } - private Predicate prepareFilters(@Nonnull final Exclusions exclusions, @Nonnull final PgContext ctx) { - return SkipTablesByNamePredicate.of(ctx, exclusions.getTableNameExclusions()) - .and(SkipIndexesByNamePredicate.of(ctx, exclusions.getIndexNameExclusions())) - .and(SkipBySequenceNamePredicate.of(ctx, exclusions.getSequenceNameExclusions())) + private Predicate prepareFilters(@Nonnull final Exclusions exclusions, @Nonnull final PgContext pgContext) { + return SkipTablesByNamePredicate.of(pgContext, exclusions.getTableNameExclusions()) + .and(SkipIndexesByNamePredicate.of(pgContext, exclusions.getIndexNameExclusions())) + .and(SkipBySequenceNamePredicate.of(pgContext, exclusions.getSequenceNameExclusions())) .and(SkipBloatUnderThresholdPredicate.of(exclusions.getBloatSizeThresholdInBytes(), exclusions.getBloatPercentageThreshold())) .and(SkipSmallTablesPredicate.of(exclusions.getTableSizeThresholdInBytes())) .and(SkipSmallIndexesPredicate.of(exclusions.getIndexSizeThresholdInBytes())); diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/column/Column.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/column/Column.java index 5c07e8c6..da65f5b4 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/column/Column.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/column/Column.java @@ -10,6 +10,7 @@ package io.github.mfvanek.pg.model.column; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.dbobject.DbObject; import io.github.mfvanek.pg.model.dbobject.PgObjectType; import io.github.mfvanek.pg.model.validation.Validators; @@ -151,10 +152,27 @@ public int compareTo(@Nonnull final Column other) { * @return {@code Column} */ @Nonnull - public static Column ofNotNull(@Nonnull final String tableName, @Nonnull final String columnName) { + public static Column ofNotNull(@Nonnull final String tableName, + @Nonnull final String columnName) { return new Column(tableName, columnName, true); } + /** + * Constructs a not null {@code Column} object with given context. + * + * @param pgContext the schema context to enrich table name; must be non-null. + * @param tableName table name; should be non-blank. + * @param columnName column name; should be non-blank. + * @return {@code Column} + * @since 0.14.3 + */ + @Nonnull + public static Column ofNotNull(@Nonnull final PgContext pgContext, + @Nonnull final String tableName, + @Nonnull final String columnName) { + return ofNotNull(PgContext.enrichWith(tableName, pgContext), columnName); + } + /** * Constructs a nullable {@code Column} object. * @@ -163,7 +181,24 @@ public static Column ofNotNull(@Nonnull final String tableName, @Nonnull final S * @return {@code Column} */ @Nonnull - public static Column ofNullable(@Nonnull final String tableName, @Nonnull final String columnName) { + public static Column ofNullable(@Nonnull final String tableName, + @Nonnull final String columnName) { return new Column(tableName, columnName, false); } + + /** + * Constructs a nullable {@code Column} object with given context. + * + * @param pgContext the schema context to enrich table name; must be non-null. + * @param tableName table name; should be non-blank. + * @param columnName column name; should be non-blank. + * @return {@code Column} + * @since 0.14.3 + */ + @Nonnull + public static Column ofNullable(@Nonnull final PgContext pgContext, + @Nonnull final String tableName, + @Nonnull final String columnName) { + return ofNullable(PgContext.enrichWith(tableName, pgContext), columnName); + } } diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/Constraint.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/Constraint.java index da551771..081845f3 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/Constraint.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/Constraint.java @@ -10,6 +10,7 @@ package io.github.mfvanek.pg.model.constraint; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.dbobject.DbObject; import io.github.mfvanek.pg.model.dbobject.PgObjectType; import io.github.mfvanek.pg.model.table.TableNameAware; @@ -170,4 +171,22 @@ public static Constraint ofType(@Nonnull final String tableName, @Nonnull final ConstraintType constraintType) { return new Constraint(tableName, constraintName, constraintType); } + + /** + * Constructs a {@code Constraint} object with given {@code ConstraintType} and context. + * + * @param pgContext the schema context to enrich table name; must be non-null. + * @param tableName table name; should be non-blank. + * @param constraintName constraint name; should be non-blank. + * @param constraintType constraint type; should be non-null. + * @return {@code Constraint} + * @since 0.14.3 + */ + @Nonnull + public static Constraint ofType(@Nonnull final PgContext pgContext, + @Nonnull final String tableName, + @Nonnull final String constraintName, + @Nonnull final ConstraintType constraintType) { + return ofType(PgContext.enrichWith(tableName, pgContext), constraintName, constraintType); + } } diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/context/PgContext.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/context/PgContext.java index a5bb5c17..78bce144 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/context/PgContext.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/context/PgContext.java @@ -13,6 +13,7 @@ import io.github.mfvanek.pg.model.validation.Validators; import java.util.Locale; +import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.ThreadSafe; @@ -178,4 +179,18 @@ public static PgContext of(@Nonnull final String schemaName) { public static PgContext ofPublic() { return of(DEFAULT_SCHEMA_NAME); } + + /** + * Complement the given object name with the specified schema name if it is necessary. + * + * @param objectName the name of the object to be enriched with schema information; must not be {@code null} + * @param pgContext the schema context to enrich object name; must be non-null. + * @return the fully qualified object name with schema information + * @since 0.14.3 + */ + @Nonnull + public static String enrichWith(@Nonnull final String objectName, @Nonnull final PgContext pgContext) { + Objects.requireNonNull(pgContext, "pgContext cannot be null"); + return pgContext.enrichWithSchema(objectName); + } } diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/function/StoredFunction.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/function/StoredFunction.java index 37947849..efd025aa 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/function/StoredFunction.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/function/StoredFunction.java @@ -10,6 +10,7 @@ package io.github.mfvanek.pg.model.function; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.dbobject.DbObject; import io.github.mfvanek.pg.model.dbobject.PgObjectType; import io.github.mfvanek.pg.model.validation.Validators; @@ -128,10 +129,25 @@ public int compareTo(@Nonnull final StoredFunction other) { * @param functionName procedure/function name. * @return {@code StoredFunction} */ + @Nonnull public static StoredFunction ofNoArgs(@Nonnull final String functionName) { return new StoredFunction(functionName, ""); } + /** + * Constructs a {@code StoredFunction} object without arguments/signature with given context. + * + * @param pgContext the schema context to enrich procedure/function name; must be non-null. + * @param functionName procedure/function name. + * @return {@code StoredFunction} + * @since 0.14.3 + */ + @Nonnull + public static StoredFunction ofNoArgs(@Nonnull final PgContext pgContext, + @Nonnull final String functionName) { + return ofNoArgs(PgContext.enrichWith(functionName, pgContext)); + } + /** * Constructs a {@code StoredFunction} object. * @@ -139,7 +155,25 @@ public static StoredFunction ofNoArgs(@Nonnull final String functionName) { * @param functionSignature procedure/function signature (arguments). * @return {@code StoredFunction} */ - public static StoredFunction of(@Nonnull final String functionName, @Nonnull final String functionSignature) { + @Nonnull + public static StoredFunction of(@Nonnull final String functionName, + @Nonnull final String functionSignature) { return new StoredFunction(functionName, functionSignature); } + + /** + * Constructs a {@code StoredFunction} object with given context. + * + * @param pgContext the schema context to enrich procedure/function name; must be non-null. + * @param functionName procedure/function name. + * @param functionSignature procedure/function signature (arguments). + * @return {@code StoredFunction} + * @since 0.14.3 + */ + @Nonnull + public static StoredFunction of(@Nonnull final PgContext pgContext, + @Nonnull final String functionName, + @Nonnull final String functionSignature) { + return of(PgContext.enrichWith(functionName, pgContext), functionSignature); + } } diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/Index.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/Index.java index 7bc6d032..d63e332d 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/Index.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/Index.java @@ -10,6 +10,7 @@ package io.github.mfvanek.pg.model.index; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.dbobject.DbObject; import io.github.mfvanek.pg.model.dbobject.PgObjectType; import io.github.mfvanek.pg.model.table.TableNameAware; @@ -146,7 +147,25 @@ public int compareTo(@Nonnull final Index other) { * @param indexName index name; should be non-blank. * @return {@code Index} */ - public static Index of(@Nonnull final String tableName, @Nonnull final String indexName) { + @Nonnull + public static Index of(@Nonnull final String tableName, + @Nonnull final String indexName) { return new Index(tableName, indexName); } + + /** + * Constructs an {@code Index} object with given context. + * + * @param pgContext the schema context to enrich table and index name; must be non-null. + * @param tableName table name; should be non-blank. + * @param indexName index name; should be non-blank. + * @return {@code Index} + * @since 0.14.3 + */ + @Nonnull + public static Index of(@Nonnull final PgContext pgContext, + @Nonnull final String tableName, + @Nonnull final String indexName) { + return of(PgContext.enrichWith(tableName, pgContext), PgContext.enrichWith(indexName, pgContext)); + } } diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithBloat.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithBloat.java index a3760f6d..5de4c93a 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithBloat.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithBloat.java @@ -11,6 +11,7 @@ package io.github.mfvanek.pg.model.index; import io.github.mfvanek.pg.model.bloat.BloatAware; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.validation.Validators; import javax.annotation.Nonnull; @@ -90,4 +91,43 @@ public static IndexWithBloat of(@Nonnull final String tableName, final double bloatPercentage) { return new IndexWithBloat(tableName, indexName, indexSizeInBytes, bloatSizeInBytes, bloatPercentage); } + + /** + * Constructs a {@code IndexWithBloat} object with given context. + * + * @param pgContext the schema context to enrich table and index name; must be non-null. + * @param tableName table name; should be non-blank. + * @param indexName index name; should be non-blank. + * @param indexSizeInBytes index size in bytes; should be positive or zero. + * @param bloatSizeInBytes bloat amount in bytes; should be positive or zero. + * @param bloatPercentage bloat percentage in the range from 0 to 100 inclusive. + * @return {@code IndexWithBloat} + * @since 0.14.3 + */ + @Nonnull + public static IndexWithBloat of(@Nonnull final PgContext pgContext, + @Nonnull final String tableName, + @Nonnull final String indexName, + final long indexSizeInBytes, + final long bloatSizeInBytes, + final double bloatPercentage) { + return of(PgContext.enrichWith(tableName, pgContext), PgContext.enrichWith(indexName, pgContext), + indexSizeInBytes, bloatSizeInBytes, bloatPercentage); + } + + /** + * Constructs a {@code IndexWithBloat} object with given context and zero bloat. + * + * @param pgContext the schema context to enrich table and index name; must be non-null. + * @param tableName table name; should be non-blank. + * @param indexName index name; should be non-blank. + * @return {@code IndexWithBloat} + * @since 0.14.3 + */ + @Nonnull + public static IndexWithBloat of(@Nonnull final PgContext pgContext, + @Nonnull final String tableName, + @Nonnull final String indexName) { + return of(pgContext, tableName, indexName, 0L, 0L, 0.0); + } } diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithColumns.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithColumns.java index 5b3c6b45..9cfebd3f 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithColumns.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithColumns.java @@ -11,6 +11,7 @@ package io.github.mfvanek.pg.model.index; import io.github.mfvanek.pg.model.column.Column; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.validation.Validators; import java.util.List; @@ -94,6 +95,26 @@ public static IndexWithColumns ofSingle(@Nonnull final String tableName, return new IndexWithColumns(tableName, indexName, indexSizeInBytes, columns); } + /** + * Constructs an {@code IndexWithColumns} object with one column and given context. + * + * @param pgContext the schema context to enrich table and index name; must be non-null. + * @param tableName table name; should be non-blank. + * @param indexName index name; should be non-blank. + * @param indexSizeInBytes index size in bytes; should be positive or zero. + * @param column column in index. + * @return {@code IndexWithColumns} + * @since 0.14.3 + */ + @Nonnull + public static IndexWithColumns ofSingle(@Nonnull final PgContext pgContext, + @Nonnull final String tableName, + @Nonnull final String indexName, + final long indexSizeInBytes, + @Nonnull final Column column) { + return ofSingle(PgContext.enrichWith(tableName, pgContext), PgContext.enrichWith(indexName, pgContext), indexSizeInBytes, column); + } + /** * Constructs an {@code IndexWithColumns} object with given columns. * @@ -110,4 +131,24 @@ public static IndexWithColumns ofColumns(@Nonnull final String tableName, @Nonnull final List columns) { return new IndexWithColumns(tableName, indexName, indexSizeInBytes, columns); } + + /** + * Constructs an {@code IndexWithColumns} object with given columns and context. + * + * @param pgContext the schema context to enrich table and index name; must be non-null. + * @param tableName table name; should be non-blank. + * @param indexName index name; should be non-blank. + * @param indexSizeInBytes index size in bytes; should be positive or zero. + * @param columns columns in index. + * @return {@code IndexWithColumns} + * @since 0.14.3 + */ + @Nonnull + public static IndexWithColumns ofColumns(@Nonnull final PgContext pgContext, + @Nonnull final String tableName, + @Nonnull final String indexName, + final long indexSizeInBytes, + @Nonnull final List columns) { + return ofColumns(PgContext.enrichWith(tableName, pgContext), PgContext.enrichWith(indexName, pgContext), indexSizeInBytes, columns); + } } diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithNulls.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithNulls.java index 382d5c7e..e948e961 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithNulls.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithNulls.java @@ -11,6 +11,7 @@ package io.github.mfvanek.pg.model.index; import io.github.mfvanek.pg.model.column.Column; +import io.github.mfvanek.pg.model.context.PgContext; import java.util.List; import java.util.Objects; @@ -68,4 +69,25 @@ public static IndexWithNulls of(@Nonnull final String tableName, @Nonnull final String nullableColumnName) { return new IndexWithNulls(tableName, indexName, indexSizeInBytes, Column.ofNullable(tableName, nullableColumnName)); } + + /** + * Constructs an {@code IndexWithNulls} object with given context. + * + * @param pgContext the schema context to enrich table and index name; must be non-null. + * @param tableName table name; should be non-blank. + * @param indexName index name; should be non-blank. + * @param indexSizeInBytes index size in bytes; should be positive or zero. + * @param nullableColumnName nullable column in this index. + * @return {@code IndexWithNulls} + * @since 0.14.3 + */ + @Nonnull + public static IndexWithNulls of(@Nonnull final PgContext pgContext, + @Nonnull final String tableName, + @Nonnull final String indexName, + final long indexSizeInBytes, + @Nonnull final String nullableColumnName) { + return new IndexWithNulls(PgContext.enrichWith(tableName, pgContext), PgContext.enrichWith(indexName, pgContext), + indexSizeInBytes, Column.ofNullable(pgContext, tableName, nullableColumnName)); + } } diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithSize.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithSize.java index b13ec8b9..663a54ef 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithSize.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithSize.java @@ -10,6 +10,7 @@ package io.github.mfvanek.pg.model.index; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.validation.Validators; import javax.annotation.Nonnull; @@ -81,4 +82,52 @@ public static IndexWithSize of(@Nonnull final String tableName, final long indexSizeInBytes) { return new IndexWithSize(tableName, indexName, indexSizeInBytes); } + + /** + * Constructs an {@code IndexWithSize} object with given context. + * + * @param pgContext the schema context to enrich table and index name; must be non-null. + * @param tableName table name; should be non-blank. + * @param indexName index name; should be non-blank. + * @param indexSizeInBytes index size in bytes; should be positive or zero. + * @return {@code IndexWithSize} + * @since 0.14.3 + */ + @Nonnull + public static IndexWithSize of(@Nonnull final PgContext pgContext, + @Nonnull final String tableName, + @Nonnull final String indexName, + final long indexSizeInBytes) { + return of(PgContext.enrichWith(tableName, pgContext), PgContext.enrichWith(indexName, pgContext), indexSizeInBytes); + } + + /** + * Constructs an {@code IndexWithSize} object with zero size. + * + * @param tableName table name; should be non-blank. + * @param indexName index name; should be non-blank. + * @return {@code IndexWithSize} + * @since 0.14.3 + */ + @Nonnull + public static IndexWithSize of(@Nonnull final String tableName, + @Nonnull final String indexName) { + return of(tableName, indexName, 0L); + } + + /** + * Constructs an {@code IndexWithSize} object with zero size and given context. + * + * @param pgContext the schema context to enrich table and index name; must be non-null. + * @param tableName table name; should be non-blank. + * @param indexName index name; should be non-blank. + * @return {@code IndexWithSize} + * @since 0.14.3 + */ + @Nonnull + public static IndexWithSize of(@Nonnull final PgContext pgContext, + @Nonnull final String tableName, + @Nonnull final String indexName) { + return of(pgContext, tableName, indexName, 0L); + } } diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/UnusedIndex.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/UnusedIndex.java index 0cad5ec4..dcf98379 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/UnusedIndex.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/UnusedIndex.java @@ -10,6 +10,7 @@ package io.github.mfvanek.pg.model.index; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.validation.Validators; import javax.annotation.Nonnull; @@ -71,10 +72,61 @@ public String toString() { * @throws NullPointerException if {@code tableName} or {@code indexName} is null * @throws IllegalArgumentException if {@code indexScans} is negative */ + @Nonnull public static UnusedIndex of(@Nonnull final String tableName, @Nonnull final String indexName, final long indexSizeInBytes, final long indexScans) { return new UnusedIndex(tableName, indexName, indexSizeInBytes, indexScans); } + + /** + * Creates a new {@code UnusedIndex} instance with the specified parameters and given context. + * + * @param pgContext the schema context to enrich table and index name; must be non-null. + * @param tableName the name of the table associated with the index, must be non-null + * @param indexName the name of the index, must be non-null + * @param indexSizeInBytes the size of the index in bytes + * @param indexScans the number of times the index has been scanned, must be non-negative + * @return a new {@code UnusedIndex} instance + * @since 0.14.3 + */ + @Nonnull + public static UnusedIndex of(@Nonnull final PgContext pgContext, + @Nonnull final String tableName, + @Nonnull final String indexName, + final long indexSizeInBytes, + final long indexScans) { + return of(PgContext.enrichWith(tableName, pgContext), PgContext.enrichWith(indexName, pgContext), indexSizeInBytes, indexScans); + } + + /** + * Creates a new {@code UnusedIndex} instance with zero size. + * + * @param tableName the name of the table associated with the index, must be non-null + * @param indexName the name of the index, must be non-null + * @return a new {@code UnusedIndex} instance + * @since 0.14.3 + */ + @Nonnull + public static UnusedIndex of(@Nonnull final String tableName, + @Nonnull final String indexName) { + return of(tableName, indexName, 0L, 0L); + } + + /** + * Creates a new {@code UnusedIndex} instance with zero size and given context. + * + * @param pgContext the schema context to enrich table and index name; must be non-null. + * @param tableName the name of the table associated with the index, must be non-null + * @param indexName the name of the index, must be non-null + * @return a new {@code UnusedIndex} instance + * @since 0.14.3 + */ + @Nonnull + public static UnusedIndex of(@Nonnull final PgContext pgContext, + @Nonnull final String tableName, + @Nonnull final String indexName) { + return of(pgContext, tableName, indexName, 0L, 0L); + } } diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/sequence/SequenceState.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/sequence/SequenceState.java index 07757a7d..06755779 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/sequence/SequenceState.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/sequence/SequenceState.java @@ -10,6 +10,7 @@ package io.github.mfvanek.pg.model.sequence; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.dbobject.DbObject; import io.github.mfvanek.pg.model.dbobject.PgObjectType; import io.github.mfvanek.pg.model.validation.Validators; @@ -148,4 +149,22 @@ public static SequenceState of(@Nonnull final String sequenceName, final double remainingPercentage) { return new SequenceState(sequenceName, dataType, remainingPercentage); } + + /** + * Constructs a {@code SequenceState} object with given context. + * + * @param pgContext the schema context to enrich sequence name; must be non-null. + * @param sequenceName sequence name; should be non-blank. + * @param dataType data type; should be non-blank. + * @param remainingPercentage remaining percentage; in the range from 0 to 100 inclusive. + * @return {@code SequenceState} + * @since 0.14.3 + */ + @Nonnull + public static SequenceState of(@Nonnull final PgContext pgContext, + @Nonnull final String sequenceName, + @Nonnull final String dataType, + final double remainingPercentage) { + return of(PgContext.enrichWith(sequenceName, pgContext), dataType, remainingPercentage); + } } diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/settings/ParamNameAware.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/settings/ParamNameAware.java index e06feeb0..33156386 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/settings/ParamNameAware.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/settings/ParamNameAware.java @@ -12,9 +12,17 @@ import javax.annotation.Nonnull; +/** + * Represents an entity that is aware of its parameter name. + */ @SuppressWarnings("WeakerAccess") public interface ParamNameAware { + /** + * Retrieves the name of the parameter. + * + * @return the name of the parameter, never {@code null} + */ @Nonnull String getName(); } diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/settings/PgParamImpl.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/settings/PgParamImpl.java index 8b0a2e25..ef4e2399 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/settings/PgParamImpl.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/settings/PgParamImpl.java @@ -26,6 +26,9 @@ private PgParamImpl(@Nonnull final String name, @Nonnull final String value) { this.value = ParamValidators.paramValueNotNull(value, "value for '" + name + "' cannot be null"); } + /** + * {@inheritDoc} + */ @Override @Nonnull public String getName() { diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/Table.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/Table.java index ca6a14a5..97687769 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/Table.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/Table.java @@ -10,6 +10,7 @@ package io.github.mfvanek.pg.model.table; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.dbobject.DbObject; import io.github.mfvanek.pg.model.dbobject.PgObjectType; import io.github.mfvanek.pg.model.validation.Validators; @@ -131,7 +132,51 @@ public int compareTo(@Nonnull final Table other) { * @return {@code Table} */ @Nonnull - public static Table of(@Nonnull final String tableName, final long tableSizeInBytes) { + public static Table of(@Nonnull final String tableName, + final long tableSizeInBytes) { return new Table(tableName, tableSizeInBytes); } + + /** + * Constructs a {@code Table} object with given context. + * + * @param pgContext the schema context to enrich table name; must be non-null. + * @param tableName table name; should be non-blank. + * @param tableSizeInBytes table size in bytes; should be positive or zero. + * @return {@code Table} + * @since 0.14.3 + */ + @Nonnull + public static Table of(@Nonnull final PgContext pgContext, + @Nonnull final String tableName, + final long tableSizeInBytes) { + return of(PgContext.enrichWith(tableName, pgContext), tableSizeInBytes); + } + + /** + * Constructs a {@code Table} object with zero size. + * + * @param tableName table name; should be non-blank. + * @return {@code Table} + * @since 0.14.3 + */ + @Nonnull + public static Table of(@Nonnull final String tableName) { + return of(tableName, 0L); + } + + /** + * Constructs a {@code Table} object with zero size and given context. + * + * @param pgContext the schema context to enrich table name; must be non-null. + * @param tableName table name; should be non-blank. + * @return {@code Table} + * @since 0.14.3 + */ + @Nonnull + public static Table of(@Nonnull final PgContext pgContext, + @Nonnull final String tableName) { + Objects.requireNonNull(pgContext, "pgContext cannot be null"); + return of(PgContext.enrichWith(tableName, pgContext)); + } } diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/TableWithBloat.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/TableWithBloat.java index 9b89177b..3ee5708e 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/TableWithBloat.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/TableWithBloat.java @@ -11,6 +11,7 @@ package io.github.mfvanek.pg.model.table; import io.github.mfvanek.pg.model.bloat.BloatAware; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.validation.Validators; import java.util.Objects; @@ -107,6 +108,7 @@ public int compareTo(@Nonnull final TableWithBloat other) { * @param bloatPercentage bloat percentage in the range from 0 to 100 inclusive. * @return {@code TableWithBloat} */ + @Nonnull public static TableWithBloat of(@Nonnull final String tableName, final long tableSizeInBytes, final long bloatSizeInBytes, @@ -115,6 +117,41 @@ public static TableWithBloat of(@Nonnull final String tableName, return of(table, bloatSizeInBytes, bloatPercentage); } + /** + * Constructs a {@code TableWithBloat} object with given context. + * + * @param pgContext the schema context to enrich table name; must be non-null. + * @param tableName table name; should be non-blank. + * @param tableSizeInBytes table size in bytes; should be positive or zero. + * @param bloatSizeInBytes bloat amount in bytes; should be positive or zero. + * @param bloatPercentage bloat percentage in the range from 0 to 100 inclusive. + * @return {@code TableWithBloat} + * @since 0.14.3 + */ + @Nonnull + public static TableWithBloat of(@Nonnull final PgContext pgContext, + @Nonnull final String tableName, + final long tableSizeInBytes, + final long bloatSizeInBytes, + final double bloatPercentage) { + final Table table = Table.of(pgContext, tableName, tableSizeInBytes); + return of(table, bloatSizeInBytes, bloatPercentage); + } + + /** + * Constructs a {@code TableWithBloat} object with given context and zero bloat. + * + * @param pgContext the schema context to enrich table name; must be non-null. + * @param tableName table name; should be non-blank. + * @return {@code TableWithBloat} + * @since 0.14.3 + */ + @Nonnull + public static TableWithBloat of(@Nonnull final PgContext pgContext, + @Nonnull final String tableName) { + return of(pgContext, tableName, 0L, 0L, 0.0); + } + /** * Constructs a {@code TableWithBloat} object. * @@ -124,6 +161,7 @@ public static TableWithBloat of(@Nonnull final String tableName, * @return {@code TableWithBloat} * @since 0.7.0 */ + @Nonnull public static TableWithBloat of(@Nonnull final Table table, final long bloatSizeInBytes, final double bloatPercentage) { diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/TableWithMissingIndex.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/TableWithMissingIndex.java index 7ca2dad1..cd01720f 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/TableWithMissingIndex.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/TableWithMissingIndex.java @@ -10,6 +10,7 @@ package io.github.mfvanek.pg.model.table; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.validation.Validators; import java.util.Objects; @@ -118,6 +119,7 @@ public int compareTo(@Nonnull final TableWithMissingIndex other) { * @param indexScans number of index scans initiated on this table; should be non-negative. * @return {@code TableWithMissingIndex} */ + @Nonnull public static TableWithMissingIndex of(@Nonnull final String tableName, final long tableSizeInBytes, final long seqScans, @@ -126,6 +128,27 @@ public static TableWithMissingIndex of(@Nonnull final String tableName, return of(table, seqScans, indexScans); } + /** + * Constructs a {@code TableWithMissingIndex} object with given context. + * + * @param pgContext the schema context to enrich table name; must be non-null. + * @param tableName table name; should be non-blank. + * @param tableSizeInBytes table size in bytes; should be positive or zero. + * @param seqScans number of sequential scans initiated on this table; should be non-negative. + * @param indexScans number of index scans initiated on this table; should be non-negative. + * @return {@code TableWithMissingIndex} + * @since 0.14.3 + */ + @Nonnull + public static TableWithMissingIndex of(@Nonnull final PgContext pgContext, + @Nonnull final String tableName, + final long tableSizeInBytes, + final long seqScans, + final long indexScans) { + final Table table = Table.of(pgContext, tableName, tableSizeInBytes); + return of(table, seqScans, indexScans); + } + /** * Constructs a {@code TableWithMissingIndex} object. * @@ -135,6 +158,7 @@ public static TableWithMissingIndex of(@Nonnull final String tableName, * @return {@code TableWithMissingIndex} * @since 0.7.0 */ + @Nonnull public static TableWithMissingIndex of(@Nonnull final Table table, final long seqScans, final long indexScans) { diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/column/ColumnTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/column/ColumnTest.java index e597cc80..20082d1d 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/column/ColumnTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/column/ColumnTest.java @@ -10,6 +10,7 @@ package io.github.mfvanek.pg.model.column; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.dbobject.PgObjectType; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.jupiter.api.Test; @@ -79,9 +80,14 @@ void withInvalidValuesShouldThrowException() { void testToString() { assertThat(Column.ofNotNull("t1", "c1")) .hasToString("Column{tableName='t1', columnName='c1', notNull=true}"); - assertThat(Column.ofNullable("t2", "c2")) .hasToString("Column{tableName='t2', columnName='c2', notNull=false}"); + + final PgContext ctx = PgContext.of("tst"); + assertThat(Column.ofNotNull(ctx, "t1", "c1")) + .hasToString("Column{tableName='tst.t1', columnName='c1', notNull=true}"); + assertThat(Column.ofNullable(ctx, "t2", "c2")) + .hasToString("Column{tableName='tst.t2', columnName='c2', notNull=false}"); } @SuppressWarnings("ConstantConditions") diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/constraint/ConstraintTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/constraint/ConstraintTest.java index 42b9b6e8..bdcc2353 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/constraint/ConstraintTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/constraint/ConstraintTest.java @@ -10,6 +10,7 @@ package io.github.mfvanek.pg.model.constraint; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.dbobject.PgObjectType; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.jupiter.api.Test; @@ -21,13 +22,16 @@ class ConstraintTest { @Test void testToString() { - final Constraint constraintWithCheck = Constraint.ofType("t", "not_valid_id", ConstraintType.CHECK); - assertThat(constraintWithCheck) + final PgContext ctx = PgContext.of("tst"); + assertThat(Constraint.ofType("t", "not_valid_id", ConstraintType.CHECK)) .hasToString("Constraint{tableName='t', constraintName='not_valid_id', constraintType=CHECK}"); + assertThat(Constraint.ofType(ctx, "t", "not_valid_id", ConstraintType.CHECK)) + .hasToString("Constraint{tableName='tst.t', constraintName='not_valid_id', constraintType=CHECK}"); - final Constraint constraintWithForeignKey = Constraint.ofType("t", "not_valid_id", ConstraintType.FOREIGN_KEY); - assertThat(constraintWithForeignKey) + assertThat(Constraint.ofType("t", "not_valid_id", ConstraintType.FOREIGN_KEY)) .hasToString("Constraint{tableName='t', constraintName='not_valid_id', constraintType=FOREIGN_KEY}"); + assertThat(Constraint.ofType(ctx, "t1", "not_valid_id", ConstraintType.FOREIGN_KEY)) + .hasToString("Constraint{tableName='tst.t1', constraintName='not_valid_id', constraintType=FOREIGN_KEY}"); } @Test diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/context/PgContextTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/context/PgContextTest.java index 33e6bfdf..ebc0a131 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/context/PgContextTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/context/PgContextTest.java @@ -93,6 +93,8 @@ void complementWithCustomSchema() { .isEqualTo("test.table2"); assertThat(pgContext.enrichWithSchema("TEST.table2")) .isEqualTo("TEST.table2"); + assertThat(PgContext.enrichWith("table1", pgContext)) + .isEqualTo("test.table1"); } @Test @@ -106,6 +108,8 @@ void complementWithPublicSchema() { .isEqualTo("public.table2"); assertThat(pgContext.enrichWithSchema("PUBLIC.table2")) .isEqualTo("PUBLIC.table2"); + assertThat(PgContext.enrichWith("table1", pgContext)) + .isEqualTo("table1"); } @SuppressWarnings("ConstantConditions") @@ -121,5 +125,8 @@ void complementWithSchemaWithInvalidArguments() { assertThatThrownBy(() -> pgContext.enrichWithSchema(" ")) .isInstanceOf(IllegalArgumentException.class) .hasMessage("objectName cannot be blank"); + assertThatThrownBy(() -> PgContext.enrichWith(null, null)) + .isInstanceOf(NullPointerException.class) + .hasMessage("pgContext cannot be null"); } } diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/function/StoredFunctionTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/function/StoredFunctionTest.java index b4eb9129..866c8f46 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/function/StoredFunctionTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/function/StoredFunctionTest.java @@ -10,6 +10,7 @@ package io.github.mfvanek.pg.model.function; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.dbobject.PgObjectType; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.jupiter.api.Test; @@ -68,6 +69,9 @@ void withInvalidValuesShouldThrowException() { assertThatThrownBy(() -> StoredFunction.ofNoArgs(" ")) .isInstanceOf(IllegalArgumentException.class) .hasMessage("functionName cannot be blank"); + assertThatThrownBy(() -> StoredFunction.ofNoArgs(null, null)) + .isInstanceOf(NullPointerException.class) + .hasMessage("pgContext cannot be null"); assertThatThrownBy(() -> StoredFunction.of(null, null)) .isInstanceOf(NullPointerException.class) @@ -81,15 +85,23 @@ void withInvalidValuesShouldThrowException() { assertThatThrownBy(() -> StoredFunction.of("f1", null)) .isInstanceOf(NullPointerException.class) .hasMessage("functionSignature cannot be null"); + assertThatThrownBy(() -> StoredFunction.of(null, null, null)) + .isInstanceOf(NullPointerException.class) + .hasMessage("pgContext cannot be null"); } @Test void testToString() { + final PgContext ctx = PgContext.of("tst"); assertThat(StoredFunction.ofNoArgs("f1")) .hasToString("StoredFunction{functionName='f1', functionSignature=''}"); + assertThat(StoredFunction.ofNoArgs(ctx, "f1")) + .hasToString("StoredFunction{functionName='tst.f1', functionSignature=''}"); assertThat(StoredFunction.of("f2", "IN a integer, IN b integer, IN c integer")) .hasToString("StoredFunction{functionName='f2', functionSignature='IN a integer, IN b integer, IN c integer'}"); + assertThat(StoredFunction.of(ctx, "f2", "IN a integer, IN b integer, IN c integer")) + .hasToString("StoredFunction{functionName='tst.f2', functionSignature='IN a integer, IN b integer, IN c integer'}"); } @SuppressWarnings("ConstantConditions") diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/IndexTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/IndexTest.java index 02c95979..4a64e2a2 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/IndexTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/IndexTest.java @@ -10,6 +10,7 @@ package io.github.mfvanek.pg.model.index; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.dbobject.PgObjectType; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.jupiter.api.Test; @@ -40,6 +41,9 @@ void validation() { assertThatThrownBy(() -> Index.of("t", " ")) .isInstanceOf(IllegalArgumentException.class) .hasMessage("indexName cannot be blank"); + assertThatThrownBy(() -> Index.of(null, null, null)) + .isInstanceOf(NullPointerException.class) + .hasMessage("pgContext cannot be null"); } @Test @@ -60,6 +64,8 @@ void getTableAndIndexName() { void testToString() { assertThat(Index.of("t", "i")) .hasToString("Index{tableName='t', indexName='i'}"); + assertThat(Index.of(PgContext.of("tst"), "t", "i")) + .hasToString("Index{tableName='tst.t', indexName='tst.i'}"); } @SuppressWarnings("ConstantConditions") diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/IndexWithBloatTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/IndexWithBloatTest.java index e8332fca..685231bd 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/IndexWithBloatTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/IndexWithBloatTest.java @@ -10,6 +10,7 @@ package io.github.mfvanek.pg.model.index; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.dbobject.PgObjectType; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.jupiter.api.Test; @@ -41,6 +42,11 @@ void getBloatPercentage() { void testToString() { assertThat(IndexWithBloat.of("t", "i", 2L, 1L, 50)) .hasToString("IndexWithBloat{tableName='t', indexName='i', indexSizeInBytes=2, bloatSizeInBytes=1, bloatPercentage=50.0}"); + final PgContext ctx = PgContext.of("tst"); + assertThat(IndexWithBloat.of(ctx, "t", "i", 2L, 1L, 50)) + .hasToString("IndexWithBloat{tableName='tst.t', indexName='tst.i', indexSizeInBytes=2, bloatSizeInBytes=1, bloatPercentage=50.0}"); + assertThat(IndexWithBloat.of(ctx, "t", "i")) + .hasToString("IndexWithBloat{tableName='tst.t', indexName='tst.i', indexSizeInBytes=0, bloatSizeInBytes=0, bloatPercentage=0.0}"); } @Test @@ -54,8 +60,8 @@ void withInvalidArguments() { assertThatThrownBy(() -> IndexWithBloat.of("t", "i", -1L, 0L, 0)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("indexSizeInBytes cannot be less than zero"); - final IndexWithBloat bloat = IndexWithBloat.of("t", "i", 0L, 0L, 0); - assertThat(bloat).isNotNull(); + assertThat(IndexWithBloat.of("t", "i", 0L, 0L, 0)) + .isNotNull(); } @SuppressWarnings("ConstantConditions") diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/IndexWithColumnsTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/IndexWithColumnsTest.java index f8a6d068..f3943a76 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/IndexWithColumnsTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/IndexWithColumnsTest.java @@ -11,6 +11,7 @@ package io.github.mfvanek.pg.model.index; import io.github.mfvanek.pg.model.column.Column; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.dbobject.PgObjectType; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.jupiter.api.Test; @@ -75,9 +76,14 @@ void tableShouldBeTheSame() { @Test void testToString() { - final Column column = Column.ofNullable("t", "f"); - assertThat(IndexWithColumns.ofSingle("t", "i", 22L, column)) - .hasToString("IndexWithColumns{tableName='t', indexName='i', " + "indexSizeInBytes=22, columns=[Column{tableName='t', columnName='f', notNull=false}]}"); + assertThat(IndexWithColumns.ofSingle("t", "i", 22L, Column.ofNullable("t", "f"))) + .hasToString("IndexWithColumns{tableName='t', indexName='i', indexSizeInBytes=22, columns=[Column{tableName='t', columnName='f', notNull=false}]}"); + final PgContext ctx = PgContext.of("tst"); + final Column column = Column.ofNullable(ctx, "t", "f"); + assertThat(IndexWithColumns.ofSingle(ctx, "t", "i", 22L, column)) + .hasToString("IndexWithColumns{tableName='tst.t', indexName='tst.i', indexSizeInBytes=22, columns=[Column{tableName='tst.t', columnName='f', notNull=false}]}"); + assertThat(IndexWithColumns.ofColumns(ctx, "t", "i", 22L, List.of(column))) + .hasToString("IndexWithColumns{tableName='tst.t', indexName='tst.i', indexSizeInBytes=22, columns=[Column{tableName='tst.t', columnName='f', notNull=false}]}"); } @SuppressWarnings("ConstantConditions") diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/IndexWithNullsTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/IndexWithNullsTest.java index dacee0d2..70b8bef7 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/IndexWithNullsTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/IndexWithNullsTest.java @@ -11,6 +11,7 @@ package io.github.mfvanek.pg.model.index; import io.github.mfvanek.pg.model.column.Column; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.dbobject.PgObjectType; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.jupiter.api.Test; @@ -62,12 +63,17 @@ void withInvalidArguments() { assertThatThrownBy(() -> IndexWithNulls.of("t", "i", 0, " ")) .isInstanceOf(IllegalArgumentException.class) .hasMessage("columnName cannot be blank"); + assertThatThrownBy(() -> IndexWithNulls.of(null, null, null, 0, "f")) + .isInstanceOf(NullPointerException.class) + .hasMessage("pgContext cannot be null"); } @Test void testToString() { assertThat(IndexWithNulls.of("t", "i", 22L, "f")) - .hasToString("IndexWithNulls{tableName='t', indexName='i', " + "indexSizeInBytes=22, columns=[Column{tableName='t', columnName='f', notNull=false}]}"); + .hasToString("IndexWithNulls{tableName='t', indexName='i', indexSizeInBytes=22, columns=[Column{tableName='t', columnName='f', notNull=false}]}"); + assertThat(IndexWithNulls.of(PgContext.of("tst"), "t", "i", 22L, "f")) + .hasToString("IndexWithNulls{tableName='tst.t', indexName='tst.i', indexSizeInBytes=22, columns=[Column{tableName='tst.t', columnName='f', notNull=false}]}"); } @SuppressWarnings("ConstantConditions") diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/IndexWithSizeTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/IndexWithSizeTest.java index 349be939..6943c7d9 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/IndexWithSizeTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/IndexWithSizeTest.java @@ -10,6 +10,7 @@ package io.github.mfvanek.pg.model.index; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.dbobject.PgObjectType; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.jupiter.api.Test; @@ -21,7 +22,7 @@ class IndexWithSizeTest { @Test void indexWithZeroSize() { - final IndexWithSize index = IndexWithSize.of("t", "i", 0L); + final IndexWithSize index = IndexWithSize.of("t", "i"); assertThat(index.getIndexName()) .isEqualTo("i") .isEqualTo(index.getName()); @@ -45,8 +46,15 @@ void indexWithNegativeSize() { @Test void testToString() { + final PgContext ctx = PgContext.of("tst"); assertThat(IndexWithSize.of("t", "i", 33L)) .hasToString("IndexWithSize{tableName='t', indexName='i', indexSizeInBytes=33}"); + assertThat(IndexWithSize.of(ctx, "t", "i", 33L)) + .hasToString("IndexWithSize{tableName='tst.t', indexName='tst.i', indexSizeInBytes=33}"); + assertThat(IndexWithSize.of("t", "i")) + .hasToString("IndexWithSize{tableName='t', indexName='i', indexSizeInBytes=0}"); + assertThat(IndexWithSize.of(ctx, "t", "i")) + .hasToString("IndexWithSize{tableName='tst.t', indexName='tst.i', indexSizeInBytes=0}"); } @SuppressWarnings("ConstantConditions") diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/UnusedIndexTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/UnusedIndexTest.java index 075e1071..f6b878a1 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/UnusedIndexTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/UnusedIndexTest.java @@ -10,6 +10,7 @@ package io.github.mfvanek.pg.model.index; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.dbobject.PgObjectType; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.jupiter.api.Test; @@ -34,8 +35,16 @@ void getIndexScans() { @Test void testToString() { + final PgContext ctx = PgContext.of("tst"); assertThat(UnusedIndex.of("t", "i", 1L, 2L)) .hasToString("UnusedIndex{tableName='t', indexName='i', " + "indexSizeInBytes=1, indexScans=2}"); + assertThat(UnusedIndex.of(ctx, "t", "i", 1L, 2L)) + .hasToString("UnusedIndex{tableName='tst.t', indexName='tst.i', " + "indexSizeInBytes=1, indexScans=2}"); + + assertThat(UnusedIndex.of("t", "i")) + .hasToString("UnusedIndex{tableName='t', indexName='i', " + "indexSizeInBytes=0, indexScans=0}"); + assertThat(UnusedIndex.of(ctx, "t", "i")) + .hasToString("UnusedIndex{tableName='tst.t', indexName='tst.i', " + "indexSizeInBytes=0, indexScans=0}"); } @Test diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/AbstractSkipTablesPredicateTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/AbstractSkipTablesPredicateTest.java index 9128ffe2..7b9691cc 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/AbstractSkipTablesPredicateTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/AbstractSkipTablesPredicateTest.java @@ -43,7 +43,7 @@ void shouldThrowExceptionWhenInvalidDataPassed() { void canCombinePredicatesIntoChain() { final Predicate composite = SkipLiquibaseTablesPredicate.ofPublic().and(SkipFlywayTablesPredicate.ofPublic()); assertThat(composite) - .accepts(Table.of("t", 0L)) + .accepts(Table.of("t")) .rejects(Table.of("databasechangelog", 1L)) .rejects(Table.of("flyway_schema_history", 1L)); } diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipBloatUnderThresholdPredicateTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipBloatUnderThresholdPredicateTest.java index 248d2174..1d031039 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipBloatUnderThresholdPredicateTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipBloatUnderThresholdPredicateTest.java @@ -49,7 +49,7 @@ void shouldNotCastObjectsWhenThresholdIsZero() { @Test void shouldWork() { assertThat(SkipBloatUnderThresholdPredicate.of(100L, 10.0)) - .accepts(Table.of("t", 0L)) + .accepts(Table.of("t")) .accepts(SequenceState.of("s1", "int", 80.0)) .rejects(TableWithBloat.of(Table.of("t2", 1L), 1L, 10.0)) .rejects(TableWithBloat.of(Table.of("t2", 1L), 1L, 11.0)) diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipBySequenceNamePredicateTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipBySequenceNamePredicateTest.java index 8f47a683..811165b4 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipBySequenceNamePredicateTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipBySequenceNamePredicateTest.java @@ -80,14 +80,14 @@ void shouldNotCastObjectsWhenExclusionsIsEmpty() { @Test void shouldWorkForSingleSequence() { assertThat(SkipBySequenceNamePredicate.ofName("s2")) - .accepts(Table.of("t", 0L)) + .accepts(Table.of("t")) .accepts(SequenceState.of("s1", "int", 80.0)) .rejects(SequenceState.of("s2", "int", 80.0)) .rejects(SequenceState.of("S2", "int", 80.0)); final PgContext ctx = PgContext.of("CUSTOM"); assertThat(SkipBySequenceNamePredicate.ofName(ctx, "S2")) - .accepts(Table.of("custom.t", 0L)) + .accepts(Table.of("custom.t")) .accepts(SequenceState.of("custom.s1", "int", 80.0)) .rejects(SequenceState.of("custom.s2", "int", 80.0)) .rejects(SequenceState.of("custom.S2", "int", 80.0)); @@ -96,7 +96,7 @@ void shouldWorkForSingleSequence() { @Test void shouldWorkForMultipleSequences() { assertThat(SkipBySequenceNamePredicate.ofPublic(Set.of("s1", "S2"))) - .accepts(Table.of("t", 0L)) + .accepts(Table.of("t")) .accepts(SequenceState.of("s11", "int", 80.0)) .rejects(SequenceState.of("s1", "int", 80.0)) .rejects(SequenceState.of("s2", "int", 80.0)) @@ -109,9 +109,9 @@ void shouldWorkForMultipleSequences() { void shouldWorkWithCustomSchema(final String schemaName) { final PgContext ctx = PgContext.of(schemaName); assertThat(SkipBySequenceNamePredicate.of(ctx, Set.of("s1", "s2"))) - .accepts(Table.of(ctx.enrichWithSchema("t"), 0L)) - .accepts(SequenceState.of(ctx.enrichWithSchema("s11"), "int", 80.0)) - .rejects(SequenceState.of(ctx.enrichWithSchema("s1"), "int", 80.0)) + .accepts(Table.of(ctx, "t")) + .accepts(SequenceState.of(ctx, "s11", "int", 80.0)) + .rejects(SequenceState.of(ctx, "s1", "int", 80.0)) .rejects(ColumnWithSerialType.ofSerial(Column.ofNullable(ctx.enrichWithSchema("t"), "c"), ctx.enrichWithSchema("s1"))); } } diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipFlywayTablesPredicateTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipFlywayTablesPredicateTest.java index f4eda1b0..7402d135 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipFlywayTablesPredicateTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipFlywayTablesPredicateTest.java @@ -38,13 +38,13 @@ void shouldThrowExceptionWhenPgContextIsNull() { @Test void shouldWorkWithDbObjectsList() { final List objects = List.of( - Table.of("t", 0L), - Table.of("flyway_schema_history", 0L) + Table.of("t"), + Table.of("flyway_schema_history") ); assertThat(objects.stream().filter(SkipFlywayTablesPredicate.ofPublic())) .hasSize(1) .asInstanceOf(list(Table.class)) - .containsExactly(Table.of("t", 0L)); + .containsExactly(Table.of("t")); } @ParameterizedTest @@ -52,10 +52,10 @@ void shouldWorkWithDbObjectsList() { void shouldWorkWithCustomSchema(final String schemaName) { final PgContext ctx = PgContext.of(schemaName); assertThat(SkipFlywayTablesPredicate.of(ctx)) - .accepts(Table.of(ctx.enrichWithSchema("t"), 0L)) - .accepts(Index.of(ctx.enrichWithSchema("t"), ctx.enrichWithSchema("i"))) - .accepts(SequenceState.of(ctx.enrichWithSchema("s"), "int", 100.0)) - .rejects(Table.of(ctx.enrichWithSchema("flyway_schema_history"), 0L)) - .rejects(Table.of(ctx.enrichWithSchema("FLYWAY_SCHEMA_HISTORY"), 0L)); + .accepts(Table.of(ctx, "t")) + .accepts(Index.of(ctx, "t", "i")) + .accepts(SequenceState.of(ctx, "s", "int", 100.0)) + .rejects(Table.of(ctx, "flyway_schema_history")) + .rejects(Table.of(ctx, "FLYWAY_SCHEMA_HISTORY")); } } diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipIndexesByNamePredicateTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipIndexesByNamePredicateTest.java index edaf5a35..b3fa31a7 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipIndexesByNamePredicateTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipIndexesByNamePredicateTest.java @@ -83,7 +83,7 @@ void shouldNotCastObjectsWhenExclusionsIsEmpty() { @Test void shouldWorkForSingleIndex() { assertThat(SkipIndexesByNamePredicate.ofName("i2")) - .accepts(Table.of("t", 0L)) + .accepts(Table.of("t")) .accepts(Index.of("t1", "i1")) .accepts(DuplicatedIndexes.of( IndexWithSize.of("t1", "i1", 1L), @@ -96,7 +96,7 @@ void shouldWorkForSingleIndex() { final PgContext ctx = PgContext.of("CUSTOM"); assertThat(SkipIndexesByNamePredicate.ofName(ctx, "I2")) - .accepts(Table.of("custom.t", 0L)) + .accepts(Table.of("custom.t")) .accepts(Index.of("custom.t1", "custom.i1")) .accepts(DuplicatedIndexes.of( IndexWithSize.of("custom.t1", "custom.i1", 1L), @@ -111,7 +111,7 @@ void shouldWorkForSingleIndex() { @Test void shouldWorkForMultipleIndexes() { assertThat(SkipIndexesByNamePredicate.ofPublic(Set.of("i1", "I2"))) - .accepts(Table.of("t", 0L)) + .accepts(Table.of("t")) .accepts(SequenceState.of("s11", "int", 80.0)) .accepts(ColumnWithSerialType.ofSerial(Column.ofNullable("t", "c"), "s1")) .accepts(DuplicatedIndexes.of( @@ -130,8 +130,8 @@ void shouldWorkForMultipleIndexes() { void shouldWorkWithCustomSchema(final String schemaName) { final PgContext ctx = PgContext.of(schemaName); assertThat(SkipIndexesByNamePredicate.of(ctx, Set.of("i1", "i2"))) - .accepts(Table.of(ctx.enrichWithSchema("t"), 0L)) - .accepts(Index.of(ctx.enrichWithSchema("t1"), ctx.enrichWithSchema("i11"))) - .rejects(Index.of(ctx.enrichWithSchema("t2"), ctx.enrichWithSchema("i2"))); + .accepts(Table.of(ctx, "t")) + .accepts(Index.of(ctx, "t1", "i11")) + .rejects(Index.of(ctx, "t2", "i2")); } } diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipLiquibaseTablesPredicateTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipLiquibaseTablesPredicateTest.java index 41acbe47..909dc2dd 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipLiquibaseTablesPredicateTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipLiquibaseTablesPredicateTest.java @@ -38,13 +38,13 @@ void shouldThrowExceptionWhenPgContextIsNull() { @Test void shouldWorkWithDbObjectsList() { final List objects = List.of( - Table.of("t", 0L), - Table.of("databasechangelog", 0L) + Table.of("t"), + Table.of("databasechangelog") ); assertThat(objects.stream().filter(SkipLiquibaseTablesPredicate.ofPublic())) .hasSize(1) .asInstanceOf(list(Table.class)) - .containsExactly(Table.of("t", 0L)); + .containsExactly(Table.of("t")); } @ParameterizedTest @@ -52,12 +52,12 @@ void shouldWorkWithDbObjectsList() { void shouldWorkWithCustomSchema(final String schemaName) { final PgContext ctx = PgContext.of(schemaName); assertThat(SkipLiquibaseTablesPredicate.of(ctx)) - .accepts(Table.of(ctx.enrichWithSchema("t"), 0L)) - .accepts(Index.of(ctx.enrichWithSchema("t"), ctx.enrichWithSchema("i"))) - .accepts(SequenceState.of(ctx.enrichWithSchema("s"), "int", 100.0)) - .rejects(Table.of(ctx.enrichWithSchema("databasechangelog"), 0L)) - .rejects(Table.of(ctx.enrichWithSchema("DATABASECHANGELOG"), 0L)) - .rejects(Table.of(ctx.enrichWithSchema("databasechangeloglock"), 0L)) - .rejects(Table.of(ctx.enrichWithSchema("DATABASECHANGELOGLOCK"), 0L)); + .accepts(Table.of(ctx, "t")) + .accepts(Index.of(ctx, "t", "i")) + .accepts(SequenceState.of(ctx, "s", "int", 100.0)) + .rejects(Table.of(ctx, "databasechangelog")) + .rejects(Table.of(ctx, "DATABASECHANGELOG")) + .rejects(Table.of(ctx, "databasechangeloglock")) + .rejects(Table.of(ctx, "DATABASECHANGELOGLOCK")); } } diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipSmallIndexesPredicateTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipSmallIndexesPredicateTest.java index d95cb5d3..bb94cd0d 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipSmallIndexesPredicateTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipSmallIndexesPredicateTest.java @@ -39,7 +39,7 @@ void shouldNotCastObjectsWhenThresholdIsZero() { @Test void shouldWork() { assertThat(SkipSmallIndexesPredicate.of(10L)) - .accepts(Table.of("t", 0L)) + .accepts(Table.of("t")) .accepts(IndexWithSize.of("t", "i", 10L)) .accepts(IndexWithSize.of("t", "i", 11L)) .accepts(SequenceState.of("s1", "int", 80.0)) diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipTablesByNamePredicateTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipTablesByNamePredicateTest.java index bb251a73..7457133e 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipTablesByNamePredicateTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipTablesByNamePredicateTest.java @@ -94,11 +94,11 @@ void shouldWorkForMultipleTables() { void shouldWorkWithCustomSchema(final String schemaName) { final PgContext ctx = PgContext.of(schemaName); assertThat(SkipTablesByNamePredicate.of(ctx, Set.of("t2", "T1"))) - .accepts(Table.of(ctx.enrichWithSchema("t"), 0L)) - .accepts(Index.of(ctx.enrichWithSchema("T"), ctx.enrichWithSchema("I"))) - .accepts(SequenceState.of(ctx.enrichWithSchema("s"), "int", 100.0)) - .rejects(Index.of(ctx.enrichWithSchema("t1"), ctx.enrichWithSchema("i1"))) - .rejects(Index.of(ctx.enrichWithSchema("T2"), ctx.enrichWithSchema("i2"))) - .accepts(Table.of(ctx.enrichWithSchema("t11"), 0L)); + .accepts(Table.of(ctx, "t")) + .accepts(Index.of(ctx, "T", "I")) + .accepts(SequenceState.of(ctx, "s", "int", 100.0)) + .rejects(Index.of(ctx, "t1", "i1")) + .rejects(Index.of(ctx, "T2", "i2")) + .accepts(Table.of(ctx, "t11")); } } diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/table/TableTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/table/TableTest.java index 5595eb12..2b045fc3 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/table/TableTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/table/TableTest.java @@ -10,6 +10,7 @@ package io.github.mfvanek.pg.model.table; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.dbobject.PgObjectType; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.jupiter.api.Test; @@ -46,19 +47,29 @@ void withInvalidValues() { assertThatThrownBy(() -> Table.of("t", -1L)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("tableSizeInBytes cannot be less than zero"); + assertThatThrownBy(() -> Table.of(null, "t")) + .isInstanceOf(NullPointerException.class) + .hasMessage("pgContext cannot be null"); + assertThatThrownBy(() -> Table.of(null, "t", -1L)) + .isInstanceOf(NullPointerException.class) + .hasMessage("pgContext cannot be null"); } @Test void testToString() { assertThat(Table.of("t", 2L)) .hasToString("Table{tableName='t', tableSizeInBytes=2}"); + assertThat(Table.of(PgContext.ofPublic(), "t", 2L)) + .hasToString("Table{tableName='t', tableSizeInBytes=2}"); + assertThat(Table.of(PgContext.of("tst"), "t")) + .hasToString("Table{tableName='tst.t', tableSizeInBytes=0}"); } @SuppressWarnings("ConstantConditions") @Test void testEqualsAndHashCode() { final Table first = Table.of("t1", 22L); - final Table theSame = Table.of("t1", 0L); // different size! + final Table theSame = Table.of("t1"); // different size! final Table second = Table.of("t2", 30L); final Table third = Table.of("t3", 22L); @@ -106,7 +117,7 @@ void equalsHashCodeShouldAdhereContracts() { @Test void compareToTest() { final Table first = Table.of("t1", 22L); - final Table theSame = Table.of("t1", 0L); // different size! + final Table theSame = Table.of("t1"); // different size! final Table second = Table.of("t2", 30L); final Table third = Table.of("t3", 22L); diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/table/TableWithBloatTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/table/TableWithBloatTest.java index cb1c3c9b..88ca181b 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/table/TableWithBloatTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/table/TableWithBloatTest.java @@ -10,6 +10,7 @@ package io.github.mfvanek.pg.model.table; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.dbobject.PgObjectType; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.jupiter.api.Test; @@ -39,6 +40,11 @@ void gettersShouldWork() { void testToString() { assertThat(TableWithBloat.of("t", 2L, 1L, 50)) .hasToString("TableWithBloat{tableName='t', tableSizeInBytes=2, bloatSizeInBytes=1, bloatPercentage=50.0}"); + final PgContext ctx = PgContext.of("tst"); + assertThat(TableWithBloat.of(ctx, "t", 2L, 1L, 50)) + .hasToString("TableWithBloat{tableName='tst.t', tableSizeInBytes=2, bloatSizeInBytes=1, bloatPercentage=50.0}"); + assertThat(TableWithBloat.of(ctx, "t")) + .hasToString("TableWithBloat{tableName='tst.t', tableSizeInBytes=0, bloatSizeInBytes=0, bloatPercentage=0.0}"); } @SuppressWarnings("ConstantConditions") @@ -59,6 +65,9 @@ void withInvalidArguments() { assertThatThrownBy(() -> TableWithBloat.of("t", -1L, 0L, 0)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("tableSizeInBytes cannot be less than zero"); + assertThatThrownBy(() -> TableWithBloat.of(null, "t", 0L, 0L, 0)) + .isInstanceOf(NullPointerException.class) + .hasMessage("pgContext cannot be null"); assertThat(TableWithBloat.of("t", 0L, 0L, 0)) .isNotNull(); diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/table/TableWithMissingIndexTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/table/TableWithMissingIndexTest.java index 659e0c65..feb96fcd 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/table/TableWithMissingIndexTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/table/TableWithMissingIndexTest.java @@ -10,6 +10,7 @@ package io.github.mfvanek.pg.model.table; +import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.dbobject.PgObjectType; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.jupiter.api.Test; @@ -59,12 +60,17 @@ void invalidArguments() { assertThatThrownBy(() -> TableWithMissingIndex.of(null, 0L, 0L)) .isInstanceOf(NullPointerException.class) .hasMessage("table cannot be null"); + assertThatThrownBy(() -> TableWithMissingIndex.of(null, "t", 0L, 0L, 0L)) + .isInstanceOf(NullPointerException.class) + .hasMessage("pgContext cannot be null"); } @Test void testToString() { assertThat(TableWithMissingIndex.of("t", 11L, 33L, 22L)) .hasToString("TableWithMissingIndex{tableName='t', tableSizeInBytes=11, seqScans=33, indexScans=22}"); + assertThat(TableWithMissingIndex.of(PgContext.of("tst"), "t", 11L, 33L, 22L)) + .hasToString("TableWithMissingIndex{tableName='tst.t', tableSizeInBytes=11, seqScans=33, indexScans=22}"); } @SuppressWarnings("ConstantConditions") diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/BtreeIndexesOnArrayColumnsCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/BtreeIndexesOnArrayColumnsCheckOnClusterTest.java index 8ebb4ad1..7f41ca0d 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/BtreeIndexesOnArrayColumnsCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/BtreeIndexesOnArrayColumnsCheckOnClusterTest.java @@ -53,9 +53,9 @@ void onDatabaseWithThem(final String schemaName) { .executing(ctx) .hasSize(2) .containsExactlyInAnyOrder( - IndexWithColumns.ofSingle(accountsTableName, ctx.enrichWithSchema("accounts_roles_btree_idx"), 0L, + IndexWithColumns.ofSingle(ctx, accountsTableName, "accounts_roles_btree_idx", 0L, Column.ofNotNull(accountsTableName, "roles")), - IndexWithColumns.ofSingle(accountsTableName, ctx.enrichWithSchema("accounts_account_number_roles_btree_idx"), 0L, + IndexWithColumns.ofSingle(ctx, accountsTableName, "accounts_account_number_roles_btree_idx", 0L, Column.ofNotNull(accountsTableName, "roles")) ); diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/ColumnsWithSerialTypesCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/ColumnsWithSerialTypesCheckOnClusterTest.java index bc8b0100..10bf66cb 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/ColumnsWithSerialTypesCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/ColumnsWithSerialTypesCheckOnClusterTest.java @@ -72,7 +72,7 @@ void shouldIgnoreDroppedColumns(final String schemaName) { .hasSize(1) .containsExactly( ColumnWithSerialType.ofBigSerial( - Column.ofNotNull(ctx.enrichWithSchema("bad_accounts"), "real_client_id"), ctx.enrichWithSchema("bad_accounts_real_client_id_seq")) + Column.ofNotNull(ctx, "bad_accounts", "real_client_id"), ctx.enrichWithSchema("bad_accounts_real_client_id_seq")) ); assertThat(check) @@ -103,7 +103,7 @@ void shouldDetectSerialColumnsWithUniqueConstraints(final String schemaName) { .hasSize(1) .containsExactly( ColumnWithSerialType.ofBigSerial( - Column.ofNotNull(ctx.enrichWithSchema("one_more_table"), "id"), ctx.enrichWithSchema("one_more_table_id_seq")) + Column.ofNotNull(ctx, "one_more_table", "id"), ctx.enrichWithSchema("one_more_table_id_seq")) )); } @@ -116,11 +116,11 @@ void shouldDetectPrimaryKeysThatAreForeignKeysAsWell(final String schemaName) { .hasSize(3) .containsExactly( ColumnWithSerialType.ofBigSerial( - Column.ofNotNull(ctx.enrichWithSchema("one_more_table"), "id"), ctx.enrichWithSchema("one_more_table_id_seq")), + Column.ofNotNull(ctx, "one_more_table", "id"), ctx.enrichWithSchema("one_more_table_id_seq")), ColumnWithSerialType.ofBigSerial( - Column.ofNotNull(ctx.enrichWithSchema("test_table"), "id"), ctx.enrichWithSchema("test_table_id_seq")), + Column.ofNotNull(ctx, "test_table", "id"), ctx.enrichWithSchema("test_table_id_seq")), ColumnWithSerialType.ofBigSerial( - Column.ofNotNull(ctx.enrichWithSchema("test_table"), "num"), ctx.enrichWithSchema("test_table_num_seq")) + Column.ofNotNull(ctx, "test_table", "num"), ctx.enrichWithSchema("test_table_num_seq")) )); } } diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/ColumnsWithoutDescriptionCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/ColumnsWithoutDescriptionCheckOnClusterTest.java index c4d491ee..b2bb6f00 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/ColumnsWithoutDescriptionCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/ColumnsWithoutDescriptionCheckOnClusterTest.java @@ -78,8 +78,8 @@ void shouldNotTakingIntoAccountBlankComments(final String schemaName) { .filteredOn(c -> "id".equalsIgnoreCase(c.getColumnName())) .hasSize(2) .containsExactly( - Column.ofNotNull(ctx.enrichWithSchema("accounts"), "id"), - Column.ofNotNull(ctx.enrichWithSchema("clients"), "id"))); + Column.ofNotNull(ctx, "accounts", "id"), + Column.ofNotNull(ctx, "clients", "id"))); } @ParameterizedTest diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/DuplicatedIndexesCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/DuplicatedIndexesCheckOnClusterTest.java index ad6e4980..73052670 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/DuplicatedIndexesCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/DuplicatedIndexesCheckOnClusterTest.java @@ -45,8 +45,8 @@ void onDatabaseWithThem(final String schemaName) { .hasSize(1) .containsExactly( DuplicatedIndexes.of( - IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("accounts_account_number_key"), 0L), - IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number"), 0L))) + IndexWithSize.of(ctx, "accounts", "accounts_account_number_key"), + IndexWithSize.of(ctx, "accounts", "i_accounts_account_number"))) .allMatch(d -> d.getTotalSize() >= 16_384L); assertThat(check) diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/FunctionsWithoutDescriptionCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/FunctionsWithoutDescriptionCheckOnClusterTest.java index 68fe3c9f..0d704a5b 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/FunctionsWithoutDescriptionCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/FunctionsWithoutDescriptionCheckOnClusterTest.java @@ -83,8 +83,8 @@ void shouldNotTakingIntoAccountBlankComments(final String schemaName) { .executing(ctx) .hasSize(2) .containsExactly( - StoredFunction.of(ctx.enrichWithSchema("add"), "a integer, b integer"), - StoredFunction.of(ctx.enrichWithSchema("add"), "a integer, b integer, c integer") + StoredFunction.of(ctx, "add", "a integer, b integer"), + StoredFunction.of(ctx, "add", "a integer, b integer, c integer") )); } diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/IndexesWithBloatCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/IndexesWithBloatCheckOnClusterTest.java index 1b3d9545..acea649e 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/IndexesWithBloatCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/IndexesWithBloatCheckOnClusterTest.java @@ -67,10 +67,10 @@ void onDatabaseWithThem(final String schemaName) { .executing(ctx) .hasSize(4) .containsExactlyInAnyOrder( - IndexWithBloat.of(accountsTableName, ctx.enrichWithSchema("accounts_account_number_key"), 0L, 0L, 0), - IndexWithBloat.of(accountsTableName, ctx.enrichWithSchema("accounts_pkey"), 0L, 0L, 0), - IndexWithBloat.of(clientsTableName, ctx.enrichWithSchema("clients_pkey"), 0L, 0L, 0), - IndexWithBloat.of(clientsTableName, ctx.enrichWithSchema("i_clients_email_phone"), 0L, 0L, 0)) + IndexWithBloat.of(ctx, accountsTableName, "accounts_account_number_key"), + IndexWithBloat.of(ctx, accountsTableName, "accounts_pkey"), + IndexWithBloat.of(ctx, clientsTableName, "clients_pkey"), + IndexWithBloat.of(ctx, clientsTableName, "i_clients_email_phone")) .allMatch(i -> i.getIndexSizeInBytes() > 1L) .allMatch(i -> i.getBloatSizeInBytes() > 1L && i.getBloatPercentage() >= 14); diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/IndexesWithBooleanCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/IndexesWithBooleanCheckOnClusterTest.java index 0375629d..7770164f 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/IndexesWithBooleanCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/IndexesWithBooleanCheckOnClusterTest.java @@ -44,8 +44,8 @@ void onDatabaseWithThem(final String schemaName) { .executing(ctx) .hasSize(1) .containsExactly( - IndexWithColumns.ofSingle(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_deleted"), 0L, - Column.ofNotNull(ctx.enrichWithSchema("accounts"), "deleted"))); + IndexWithColumns.ofSingle(ctx, "accounts", "i_accounts_deleted", 0L, + Column.ofNotNull(ctx, "accounts", "deleted"))); assertThat(check) .executing(ctx, SkipTablesByNamePredicate.ofName(ctx, "accounts")) diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/IndexesWithNullValuesCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/IndexesWithNullValuesCheckOnClusterTest.java index 105f3030..634bf11f 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/IndexesWithNullValuesCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/IndexesWithNullValuesCheckOnClusterTest.java @@ -51,8 +51,7 @@ void onDatabaseWithThem(final String schemaName) { assertThat(check) .executing(ctx) .hasSize(1) - .containsExactly( - IndexWithNulls.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_middle_name"), 0L, "middle_name")) + .containsExactly(IndexWithNulls.of(ctx, "clients", "i_clients_middle_name", 0L, "middle_name")) .allMatch(i -> i.getNullableColumn().isNullable()); assertThat(check) diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/IntersectedIndexesCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/IntersectedIndexesCheckOnClusterTest.java index 6919eeef..597249b2 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/IntersectedIndexesCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/IntersectedIndexesCheckOnClusterTest.java @@ -47,12 +47,12 @@ void onDatabaseWithThem(final String schemaName) { .hasSize(2) .containsExactly( DuplicatedIndexes.of( - IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number_not_deleted"), 0L), - IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_number_balance_not_deleted"), 0L) + IndexWithSize.of(ctx, "accounts", "i_accounts_account_number_not_deleted"), + IndexWithSize.of(ctx, "accounts", "i_accounts_number_balance_not_deleted") ), DuplicatedIndexes.of( - IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first"), 0L), - IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name"), 0L))) + IndexWithSize.of(ctx, "clients", "i_clients_last_first"), + IndexWithSize.of(ctx, "clients", "i_clients_last_name"))) .allMatch(d -> d.getTotalSize() >= 106_496L); assertThat(check) @@ -74,8 +74,8 @@ void shouldFindHashIndex(final String schemaName) { .hasSize(1) .containsExactly( DuplicatedIndexes.of( - IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first"), 0L), - IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name"), 0L))) + IndexWithSize.of(ctx, "clients", "i_clients_last_first"), + IndexWithSize.of(ctx, "clients", "i_clients_last_name"))) .allMatch(d -> d.getTotalSize() >= 106_496L); assertThat(check) diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/InvalidIndexesCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/InvalidIndexesCheckOnClusterTest.java index 94063240..e75cc640 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/InvalidIndexesCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/InvalidIndexesCheckOnClusterTest.java @@ -42,8 +42,7 @@ void onDatabaseWithThem(final String schemaName) { assertThat(check) .executing(ctx) .hasSize(1) - .containsExactly( - Index.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name_first_name"))); + .containsExactly(Index.of(ctx, "clients", "i_clients_last_name_first_name")); assertThat(check) .executing(ctx, SkipTablesByNamePredicate.ofName(ctx, "clients")) diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/NotValidConstraintsCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/NotValidConstraintsCheckOnClusterTest.java index becbbb00..a7dae01c 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/NotValidConstraintsCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/NotValidConstraintsCheckOnClusterTest.java @@ -47,8 +47,8 @@ void onDatabaseWithThem(final String schemaName) { Assertions.assertThat(notValidConstraints) .hasSize(2) .containsExactly( - Constraint.ofType(ctx.enrichWithSchema("accounts"), "c_accounts_chk_client_id_not_validated_yet", ConstraintType.CHECK), - Constraint.ofType(ctx.enrichWithSchema("accounts"), "c_accounts_fk_client_id_not_validated_yet", ConstraintType.FOREIGN_KEY)); + Constraint.ofType(ctx, "accounts", "c_accounts_chk_client_id_not_validated_yet", ConstraintType.CHECK), + Constraint.ofType(ctx, "accounts", "c_accounts_fk_client_id_not_validated_yet", ConstraintType.FOREIGN_KEY)); assertThat(check) .executing(ctx, SkipTablesByNamePredicate.ofName(ctx, "accounts")) diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/PrimaryKeysWithSerialTypesCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/PrimaryKeysWithSerialTypesCheckOnClusterTest.java index 4bf04ff9..cadc7240 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/PrimaryKeysWithSerialTypesCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/PrimaryKeysWithSerialTypesCheckOnClusterTest.java @@ -46,7 +46,7 @@ void onDatabaseWithThem(final String schemaName) { .hasSize(1) .containsExactlyInAnyOrder( ColumnWithSerialType.of( - Column.ofNotNull(ctx.enrichWithSchema("bad_accounts"), "id"), SerialType.BIG_SERIAL, ctx.enrichWithSchema("bad_accounts_id_seq") + Column.ofNotNull(ctx, "bad_accounts", "id"), SerialType.BIG_SERIAL, ctx.enrichWithSchema("bad_accounts_id_seq") )); assertThat(check) diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/SequenceOverflowCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/SequenceOverflowCheckOnClusterTest.java index 7f1b49e2..ceca1842 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/SequenceOverflowCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/SequenceOverflowCheckOnClusterTest.java @@ -45,9 +45,9 @@ void onDatabaseWithSequences(final String schemaName) { .executing(ctx) .hasSize(3) .containsExactlyInAnyOrder( - SequenceState.of(ctx.enrichWithSchema("seq_1"), "smallint", 8.08), - SequenceState.of(ctx.enrichWithSchema("seq_3"), "integer", 8.08), - SequenceState.of(ctx.enrichWithSchema("seq_5"), "bigint", 8.08)); + SequenceState.of(ctx, "seq_1", "smallint", 8.08), + SequenceState.of(ctx, "seq_3", "integer", 8.08), + SequenceState.of(ctx, "seq_5", "bigint", 8.08)); assertThat(check) .executing(ctx, SkipBySequenceNamePredicate.of(ctx, List.of("seq_1", "seq_3", "seq_5"))) diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesNotLinkedToOthersCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesNotLinkedToOthersCheckOnClusterTest.java index 7636c2fc..9fbe0251 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesNotLinkedToOthersCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesNotLinkedToOthersCheckOnClusterTest.java @@ -41,7 +41,7 @@ void onDatabaseWithThem(final String schemaName) { assertThat(check) .executing(ctx) .hasSize(1) - .containsExactly(Table.of(ctx.enrichWithSchema("bad_clients"), 0L)); + .containsExactly(Table.of(ctx, "bad_clients")); assertThat(check) .executing(ctx, SkipTablesByNamePredicate.ofName(ctx, "bad_clients")) diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithBloatCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithBloatCheckOnClusterTest.java index 965e9916..43ac20e5 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithBloatCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithBloatCheckOnClusterTest.java @@ -50,8 +50,8 @@ void onDatabaseWithThem(final String schemaName) { .executing(ctx) .hasSize(2) .containsExactlyInAnyOrder( - TableWithBloat.of(ctx.enrichWithSchema("accounts"), 0L, 0L, 0), - TableWithBloat.of(ctx.enrichWithSchema("clients"), 0L, 0L, 0)) + TableWithBloat.of(ctx, "accounts"), + TableWithBloat.of(ctx, "clients")) .allMatch(t -> t.getTableSizeInBytes() > 0L) // real size doesn't matter .allMatch(t -> t.getBloatPercentage() == 0 && t.getBloatSizeInBytes() == 0L); diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithMissingIndexesCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithMissingIndexesCheckOnClusterTest.java index 6a3f551a..85af10d3 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithMissingIndexesCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithMissingIndexesCheckOnClusterTest.java @@ -47,7 +47,7 @@ void onDatabaseWithThem(final String schemaName) { .executing(ctx) .hasSize(1) .containsExactly( - TableWithMissingIndex.of(ctx.enrichWithSchema("accounts"), 0L, 0L, 0L)) + TableWithMissingIndex.of(ctx, "accounts", 0L, 0L, 0L)) .allMatch(t -> t.getSeqScans() >= AMOUNT_OF_TRIES) .allMatch(t -> t.getIndexScans() == 0) .allMatch(t -> t.getTableSizeInBytes() > 1L); diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithoutDescriptionCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithoutDescriptionCheckOnClusterTest.java index 3e6dd9fe..38e4394d 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithoutDescriptionCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithoutDescriptionCheckOnClusterTest.java @@ -46,13 +46,13 @@ void onDatabaseWithThem(final String schemaName) { .executing(ctx) .hasSize(2) .containsExactly( - Table.of(ctx.enrichWithSchema("accounts"), 0L), - Table.of(ctx.enrichWithSchema("clients"), 0L)); + Table.of(ctx, "accounts"), + Table.of(ctx, "clients")); assertThat(check) .executing(ctx, SkipTablesByNamePredicate.of(ctx, List.of("accounts"))) .hasSize(1) - .containsExactly(Table.of(ctx.enrichWithSchema("clients"), 0L)) + .containsExactly(Table.of(ctx, "clients")) .allMatch(t -> t.getTableSizeInBytes() > 0L); }); } @@ -65,13 +65,13 @@ void shouldNotTakingIntoAccountBlankComments(final String schemaName) { .executing(ctx) .hasSize(2) .containsExactly( - Table.of(ctx.enrichWithSchema("accounts"), 0L), - Table.of(ctx.enrichWithSchema("clients"), 0L)); + Table.of(ctx, "accounts"), + Table.of(ctx, "clients")); assertThat(check) .executing(ctx, SkipSmallTablesPredicate.of(1_234L)) .hasSize(1) - .containsExactly(Table.of(ctx.enrichWithSchema("clients"), 0L)) + .containsExactly(Table.of(ctx, "clients")) .allMatch(t -> t.getTableSizeInBytes() > 1_234L); }); } diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithoutPrimaryKeyCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithoutPrimaryKeyCheckOnClusterTest.java index 563632e7..157fcb6a 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithoutPrimaryKeyCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithoutPrimaryKeyCheckOnClusterTest.java @@ -41,7 +41,7 @@ void onDatabaseWithThem(final String schemaName) { assertThat(check) .executing(ctx) .hasSize(1) - .containsExactly(Table.of(ctx.enrichWithSchema("bad_clients"), 0L)); + .containsExactly(Table.of(ctx, "bad_clients")); assertThat(check) .executing(ctx, SkipTablesByNamePredicate.ofName(ctx, "bad_clients")) diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/UnusedIndexesCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/UnusedIndexesCheckOnClusterTest.java index 651fc8bc..ae717706 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/UnusedIndexesCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/UnusedIndexesCheckOnClusterTest.java @@ -68,12 +68,12 @@ void onDatabaseWithThem(final String schemaName) { .executing(ctx) .hasSize(6) .containsExactlyInAnyOrder( - UnusedIndex.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first"), 0L, 0), - UnusedIndex.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name"), 0L, 0), - UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number"), 0L, 0), - UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_number_balance_not_deleted"), 0L, 0), - UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number_not_deleted"), 0L, 0), - UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_id_account_number_not_deleted"), 0L, 0)) + UnusedIndex.of(ctx, "clients", "i_clients_last_first"), + UnusedIndex.of(ctx, "clients", "i_clients_last_name"), + UnusedIndex.of(ctx, "accounts", "i_accounts_account_number"), + UnusedIndex.of(ctx, "accounts", "i_accounts_number_balance_not_deleted"), + UnusedIndex.of(ctx, "accounts", "i_accounts_account_number_not_deleted"), + UnusedIndex.of(ctx, "accounts", "i_accounts_id_account_number_not_deleted")) .allMatch(i -> i.getIndexSizeInBytes() > 0L) .allMatch(i -> i.getIndexScans() == 0); diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/common/DatabaseCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/common/DatabaseCheckOnClusterTest.java index f969254a..46933e1f 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/common/DatabaseCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/common/DatabaseCheckOnClusterTest.java @@ -36,8 +36,8 @@ void check() { .thenAnswer(invocation -> { final PgContext ctx = invocation.getArgument(0); return List.of( - Table.of(ctx.enrichWithSchema("t1"), 1L), - Table.of(ctx.enrichWithSchema("t2"), 1L)); + Table.of(ctx, "t1", 1L), + Table.of(ctx, "t2", 1L)); }); final List tables = check.check(CONTEXTS, item -> true); assertThat(tables) diff --git a/spring-boot-integration/kotlin-custom-ds-demo-app/src/test/kotlin/io/github/mfvanek/pg/spring/postgres/kt/custom/ds/PostgresCustomDataSourceDemoApplicationKtTest.kt b/spring-boot-integration/kotlin-custom-ds-demo-app/src/test/kotlin/io/github/mfvanek/pg/spring/postgres/kt/custom/ds/PostgresCustomDataSourceDemoApplicationKtTest.kt index 87f327bc..f2a554ea 100644 --- a/spring-boot-integration/kotlin-custom-ds-demo-app/src/test/kotlin/io/github/mfvanek/pg/spring/postgres/kt/custom/ds/PostgresCustomDataSourceDemoApplicationKtTest.kt +++ b/spring-boot-integration/kotlin-custom-ds-demo-app/src/test/kotlin/io/github/mfvanek/pg/spring/postgres/kt/custom/ds/PostgresCustomDataSourceDemoApplicationKtTest.kt @@ -51,7 +51,7 @@ internal class PostgresCustomDataSourceDemoApplicationKtTest { Diagnostic.TABLES_NOT_LINKED_TO_OTHERS -> listAssert .hasSize(1) - .containsExactly(Table.of("warehouse", 0L)) + .containsExactly(Table.of("warehouse")) else -> listAssert.isEmpty() }