Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add overloaded methods to create tables/indexes without specifying zero #531

Merged
merged 14 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add additional constructors to the IndexWithBloat and TableWithBloat
  • Loading branch information
mfvanek committed Dec 8, 2024
commit 1db59959c7f4ff9dfa6cd8653c6c52aae59414a2
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ void onDatabaseWithThem(final String schemaName) {
.executing(ctx)
.hasSize(4)
.containsExactlyInAnyOrder(
IndexWithBloat.of(ctx, accountsTableName, "accounts_account_number_key", 0L, 0L, 0),
IndexWithBloat.of(ctx, accountsTableName, "accounts_pkey", 0L, 0L, 0),
IndexWithBloat.of(ctx, clientsTableName, "clients_pkey", 0L, 0L, 0),
IndexWithBloat.of(ctx, clientsTableName, "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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ void onDatabaseWithThem(final String schemaName) {
.executing(ctx)
.hasSize(2)
.containsExactlyInAnyOrder(
TableWithBloat.of(ctx, "accounts", 0L, 0L, 0),
TableWithBloat.of(ctx, "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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,20 @@ public static IndexWithBloat of(@Nonnull final PgContext pgContext,
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ public static TableWithBloat of(@Nonnull final PgContext pgContext,
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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +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}");
assertThat(IndexWithBloat.of(PgContext.of("tst"), "t", "i", 2L, 1L, 50))
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ void gettersShouldWork() {
void testToString() {
assertThat(TableWithBloat.of("t", 2L, 1L, 50))
.hasToString("TableWithBloat{tableName='t', tableSizeInBytes=2, bloatSizeInBytes=1, bloatPercentage=50.0}");
assertThat(TableWithBloat.of(PgContext.of("tst"), "t", 2L, 1L, 50))
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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ void onDatabaseWithThem(final String schemaName) {
.executing(ctx)
.hasSize(4)
.containsExactlyInAnyOrder(
IndexWithBloat.of(ctx, accountsTableName, "accounts_account_number_key", 0L, 0L, 0),
IndexWithBloat.of(ctx, accountsTableName, "accounts_pkey", 0L, 0L, 0),
IndexWithBloat.of(ctx, clientsTableName, "clients_pkey", 0L, 0L, 0),
IndexWithBloat.of(ctx, clientsTableName, "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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ void onDatabaseWithThem(final String schemaName) {
.executing(ctx)
.hasSize(2)
.containsExactlyInAnyOrder(
TableWithBloat.of(ctx, "accounts", 0L, 0L, 0),
TableWithBloat.of(ctx, "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);

Expand Down
Loading