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..bb9ad969 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.enrichWithSchema("accounts"), ctx.enrichWithSchema("accounts_account_number_key")), + IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("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/IntersectedIndexesCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/IntersectedIndexesCheckOnHostTest.java index 67d56100..1dc48473 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,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.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number_not_deleted")), + IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("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.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first")), + IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name")))) .allMatch(d -> d.getTotalSize() >= 106_496L); assertThat(check) @@ -75,8 +75,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.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first")), + IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("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/UnusedIndexesCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/UnusedIndexesCheckOnHostTest.java index 777ce674..5bf6d704 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.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first")), + UnusedIndex.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name")), + UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number")), + UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_number_balance_not_deleted")), + UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number_not_deleted")), + UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_id_account_number_not_deleted"))) .allMatch(i -> i.getIndexSizeInBytes() > 0L) .allMatch(i -> i.getIndexScans() == 0); 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..0e571fb7 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 @@ -81,4 +81,18 @@ public static IndexWithSize of(@Nonnull final String tableName, final long indexSizeInBytes) { return new IndexWithSize(tableName, indexName, 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 new IndexWithSize(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..959646cd 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 @@ -71,10 +71,24 @@ 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 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 + */ + @Nonnull + public static UnusedIndex of(@Nonnull final String tableName, + @Nonnull final String indexName) { + return new UnusedIndex(tableName, indexName, 0L, 0L); + } } 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 b99b40b8..93675e9d 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 @@ -137,8 +137,10 @@ public static Table of(@Nonnull final String tableName, final long tableSizeInBy /** * 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) { 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..e7407737 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 @@ -21,7 +21,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()); 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..323a6c80 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 @@ -36,6 +36,9 @@ void getIndexScans() { void testToString() { assertThat(UnusedIndex.of("t", "i", 1L, 2L)) .hasToString("UnusedIndex{tableName='t', indexName='i', " + "indexSizeInBytes=1, indexScans=2}"); + + assertThat(UnusedIndex.of("t", "i")) + .hasToString("UnusedIndex{tableName='t', indexName='i', " + "indexSizeInBytes=0, indexScans=0}"); } @Test 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..93173b57 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.enrichWithSchema("accounts"), ctx.enrichWithSchema("accounts_account_number_key")), + IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("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/IntersectedIndexesCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/IntersectedIndexesCheckOnClusterTest.java index 6919eeef..e6528a6c 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.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number_not_deleted")), + IndexWithSize.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("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.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first")), + IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("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.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first")), + IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("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/UnusedIndexesCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/UnusedIndexesCheckOnClusterTest.java index 651fc8bc..88cdddcf 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.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first")), + UnusedIndex.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name")), + UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number")), + UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_number_balance_not_deleted")), + UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_account_number_not_deleted")), + UnusedIndex.of(ctx.enrichWithSchema("accounts"), ctx.enrichWithSchema("i_accounts_id_account_number_not_deleted"))) .allMatch(i -> i.getIndexSizeInBytes() > 0L) .allMatch(i -> i.getIndexScans() == 0);