From 8d74e953f04b937b07e9895c42af5254d3498905 Mon Sep 17 00:00:00 2001 From: Ivan Vakhrushev Date: Tue, 19 Nov 2024 22:33:20 +0400 Subject: [PATCH] Refactor packages for pg-index-health-jdbc-connection (#502) * Refactor packages for pg-index-health-jdbc-connection * Refactor validators --- config/spotbugs/exclude.xml | 2 +- .../pg/checks/host/AbstractCheckOnHost.java | 2 +- .../maintenance/DatabaseCheckOnHost.java | 2 +- .../ConfigurationMaintenanceOnHost.java | 2 +- .../ConfigurationMaintenanceOnHostImpl.java | 2 +- .../StatisticsMaintenanceOnHost.java | 2 +- .../StatisticsMaintenanceOnHostImpl.java | 2 +- .../mfvanek/pg/utils/QueryExecutors.java | 2 +- .../checks/host/AbstractCheckOnHostTest.java | 2 +- ...onfigurationMaintenanceOnHostImplTest.java | 2 +- .../pg/support/AbstractCheckOnHostAssert.java | 2 +- .../mfvanek/pg/utils/QueryExecutorsTest.java | 4 +- .../pg/support/DatabaseAwareTestBase.java | 6 +- .../mfvanek/pg/support/ExecuteUtils.java | 2 +- .../pg/support/StatisticsAwareTestBase.java | 2 +- .../CreateCustomCollationStatement.java | 2 +- .../InsertDataIntoTablesAction.java | 2 +- .../HighAvailabilityPgConnectionImpl.java | 9 +- .../mfvanek/pg/connection/PgConnection.java | 3 + .../pg/connection/PgConnectionImpl.java | 2 + .../pg/connection/PgConnectionValidators.java | 79 ---------------- .../pg/connection/PrimaryHostDeterminer.java | 3 + .../connection/PrimaryHostDeterminerImpl.java | 1 + .../{ => factory}/ConnectionCredentials.java | 28 +++++- .../HighAvailabilityPgConnectionFactory.java | 4 +- ...ghAvailabilityPgConnectionFactoryImpl.java | 8 +- .../{ => factory}/PgConnectionFactory.java | 4 +- .../PgConnectionFactoryImpl.java | 5 +- .../{ => factory}/PgConnectionHelper.java | 5 +- .../factory/PgConnectionValidators.java | 70 ++++++++++++++ .../PgSqlException.java | 7 +- .../pg/{connection => host}/HostAware.java | 2 +- .../pg/{connection => host}/PgHost.java | 7 +- .../pg/{connection => host}/PgHostImpl.java | 48 +++++----- .../pg/{connection => host}/PgUrlParser.java | 94 +++++++++++++++++-- .../mfvanek/pg/host/PgUrlValidators.java | 82 ++++++++++++++++ .../HighAvailabilityPgConnectionImplTest.java | 1 + .../HighAvailabilityPgConnectionUnitTest.java | 2 + .../pg/connection/PgConnectionImplTest.java | 2 + .../PrimaryHostDeterminerImplTest.java | 3 + .../ConnectionCredentialsTest.java | 14 +-- ...ailabilityPgConnectionFactoryImplTest.java | 5 +- .../PgConnectionFactoryImplTest.java | 3 +- .../{ => factory}/PgConnectionHelperTest.java | 2 +- .../factory/PgConnectionValidatorsTest.java | 37 ++++++++ .../{connection => host}/PgHostImplTest.java | 6 +- .../{connection => host}/PgUrlParserTest.java | 8 +- .../PgUrlValidatorsTest.java} | 36 +++---- .../pg/support/DatabaseAwareTestBase.java | 4 +- .../pg/support/PostgresVersionReader.java | 2 +- .../health/logger/AbstractHealthLogger.java | 4 +- .../logger/KeyValueFileHealthLogger.java | 4 +- .../health/logger/StandardHealthLogger.java | 4 +- .../health/logger/HealthLoggerTestBase.java | 6 +- .../pg/testing/PostgreSqlClusterWrapper.java | 2 +- .../PostgresBitnamiRepmgrContainer.java | 2 +- .../cluster/AbstractCheckOnCluster.java | 2 +- .../cluster/UnusedIndexesCheckOnCluster.java | 2 +- .../management/DatabaseManagementImpl.java | 2 +- .../DatabaseManagementImplUnitTest.java | 2 +- .../pg/e2e/PgConnectionAwareCluster.java | 2 +- ...abaseStructureHealthAutoConfiguration.java | 6 +- ...eStructureHealthAutoConfigurationTest.java | 4 +- 63 files changed, 458 insertions(+), 210 deletions(-) delete mode 100644 pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnectionValidators.java rename pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/{ => factory}/ConnectionCredentials.java (74%) rename pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/{ => factory}/HighAvailabilityPgConnectionFactory.java (92%) rename pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/{ => factory}/HighAvailabilityPgConnectionFactoryImpl.java (89%) rename pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/{ => factory}/PgConnectionFactory.java (85%) rename pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/{ => factory}/PgConnectionFactoryImpl.java (87%) rename pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/{ => factory}/PgConnectionHelper.java (91%) create mode 100644 pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/PgConnectionValidators.java rename pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/{connection => exception}/PgSqlException.java (74%) rename pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/{connection => host}/HostAware.java (93%) rename pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/{connection => host}/PgHost.java (84%) rename pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/{connection => host}/PgHostImpl.java (88%) rename pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/{connection => host}/PgUrlParser.java (61%) create mode 100644 pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/host/PgUrlValidators.java rename pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/{ => factory}/ConnectionCredentialsTest.java (94%) rename pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/{ => factory}/HighAvailabilityPgConnectionFactoryImplTest.java (96%) rename pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/{ => factory}/PgConnectionFactoryImplTest.java (91%) rename pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/{ => factory}/PgConnectionHelperTest.java (97%) create mode 100644 pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/factory/PgConnectionValidatorsTest.java rename pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/{connection => host}/PgHostImplTest.java (97%) rename pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/{connection => host}/PgUrlParserTest.java (98%) rename pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/{connection/PgConnectionValidatorsTest.java => host/PgUrlValidatorsTest.java} (54%) diff --git a/config/spotbugs/exclude.xml b/config/spotbugs/exclude.xml index dcf1226c..d800da83 100644 --- a/config/spotbugs/exclude.xml +++ b/config/spotbugs/exclude.xml @@ -92,7 +92,7 @@ - + diff --git a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/checks/host/AbstractCheckOnHost.java b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/checks/host/AbstractCheckOnHost.java index b011aa45..df9fff90 100644 --- a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/checks/host/AbstractCheckOnHost.java +++ b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/checks/host/AbstractCheckOnHost.java @@ -16,7 +16,7 @@ import io.github.mfvanek.pg.common.maintenance.Diagnostic; import io.github.mfvanek.pg.common.maintenance.ResultSetExtractor; import io.github.mfvanek.pg.connection.PgConnection; -import io.github.mfvanek.pg.connection.PgHost; +import io.github.mfvanek.pg.host.PgHost; import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.dbobject.DbObject; import io.github.mfvanek.pg.utils.SqlQueryReader; diff --git a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/common/maintenance/DatabaseCheckOnHost.java b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/common/maintenance/DatabaseCheckOnHost.java index 5f6ee277..873a3b9e 100644 --- a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/common/maintenance/DatabaseCheckOnHost.java +++ b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/common/maintenance/DatabaseCheckOnHost.java @@ -10,7 +10,7 @@ package io.github.mfvanek.pg.common.maintenance; -import io.github.mfvanek.pg.connection.HostAware; +import io.github.mfvanek.pg.host.HostAware; import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.dbobject.DbObject; diff --git a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/settings/maintenance/ConfigurationMaintenanceOnHost.java b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/settings/maintenance/ConfigurationMaintenanceOnHost.java index 55c68a25..06fa5780 100644 --- a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/settings/maintenance/ConfigurationMaintenanceOnHost.java +++ b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/settings/maintenance/ConfigurationMaintenanceOnHost.java @@ -10,7 +10,7 @@ package io.github.mfvanek.pg.settings.maintenance; -import io.github.mfvanek.pg.connection.HostAware; +import io.github.mfvanek.pg.host.HostAware; import io.github.mfvanek.pg.settings.ConfigurationAware; import io.github.mfvanek.pg.settings.ParamNameAware; import io.github.mfvanek.pg.settings.PgParam; diff --git a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/settings/maintenance/ConfigurationMaintenanceOnHostImpl.java b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/settings/maintenance/ConfigurationMaintenanceOnHostImpl.java index 101cf857..8bd1a4df 100644 --- a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/settings/maintenance/ConfigurationMaintenanceOnHostImpl.java +++ b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/settings/maintenance/ConfigurationMaintenanceOnHostImpl.java @@ -11,7 +11,7 @@ package io.github.mfvanek.pg.settings.maintenance; import io.github.mfvanek.pg.connection.PgConnection; -import io.github.mfvanek.pg.connection.PgHost; +import io.github.mfvanek.pg.host.PgHost; import io.github.mfvanek.pg.settings.ImportantParam; import io.github.mfvanek.pg.settings.ParamNameAware; import io.github.mfvanek.pg.settings.PgParam; diff --git a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/statistics/maintenance/StatisticsMaintenanceOnHost.java b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/statistics/maintenance/StatisticsMaintenanceOnHost.java index 3cf32161..4e3ba3fb 100644 --- a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/statistics/maintenance/StatisticsMaintenanceOnHost.java +++ b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/statistics/maintenance/StatisticsMaintenanceOnHost.java @@ -10,7 +10,7 @@ package io.github.mfvanek.pg.statistics.maintenance; -import io.github.mfvanek.pg.connection.HostAware; +import io.github.mfvanek.pg.host.HostAware; import io.github.mfvanek.pg.statistics.StatisticsAware; import java.time.OffsetDateTime; diff --git a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/statistics/maintenance/StatisticsMaintenanceOnHostImpl.java b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/statistics/maintenance/StatisticsMaintenanceOnHostImpl.java index 05442dc2..5e9d266f 100644 --- a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/statistics/maintenance/StatisticsMaintenanceOnHostImpl.java +++ b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/statistics/maintenance/StatisticsMaintenanceOnHostImpl.java @@ -11,7 +11,7 @@ package io.github.mfvanek.pg.statistics.maintenance; import io.github.mfvanek.pg.connection.PgConnection; -import io.github.mfvanek.pg.connection.PgHost; +import io.github.mfvanek.pg.host.PgHost; import io.github.mfvanek.pg.utils.QueryExecutors; import java.time.OffsetDateTime; diff --git a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/utils/QueryExecutors.java b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/utils/QueryExecutors.java index 7737c4ec..c7862b8f 100644 --- a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/utils/QueryExecutors.java +++ b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/utils/QueryExecutors.java @@ -12,7 +12,7 @@ import io.github.mfvanek.pg.common.maintenance.ResultSetExtractor; import io.github.mfvanek.pg.connection.PgConnection; -import io.github.mfvanek.pg.connection.PgSqlException; +import io.github.mfvanek.pg.exception.PgSqlException; import io.github.mfvanek.pg.model.context.PgContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/checks/host/AbstractCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/checks/host/AbstractCheckOnHostTest.java index 679443b7..7be0eb43 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/checks/host/AbstractCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/checks/host/AbstractCheckOnHostTest.java @@ -10,7 +10,7 @@ package io.github.mfvanek.pg.checks.host; -import io.github.mfvanek.pg.connection.PgSqlException; +import io.github.mfvanek.pg.exception.PgSqlException; import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.index.IndexWithNulls; import io.github.mfvanek.pg.support.DatabaseAwareTestBase; diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/settings/maintenance/ConfigurationMaintenanceOnHostImplTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/settings/maintenance/ConfigurationMaintenanceOnHostImplTest.java index 6fa112d7..bf0d1a4d 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/settings/maintenance/ConfigurationMaintenanceOnHostImplTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/settings/maintenance/ConfigurationMaintenanceOnHostImplTest.java @@ -10,7 +10,7 @@ package io.github.mfvanek.pg.settings.maintenance; -import io.github.mfvanek.pg.connection.PgSqlException; +import io.github.mfvanek.pg.exception.PgSqlException; import io.github.mfvanek.pg.settings.ImportantParam; import io.github.mfvanek.pg.settings.PgParam; import io.github.mfvanek.pg.settings.PgParamImpl; diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/support/AbstractCheckOnHostAssert.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/support/AbstractCheckOnHostAssert.java index b4544d6f..8abf7461 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/support/AbstractCheckOnHostAssert.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/support/AbstractCheckOnHostAssert.java @@ -12,7 +12,7 @@ import io.github.mfvanek.pg.common.maintenance.DatabaseCheckOnHost; import io.github.mfvanek.pg.common.maintenance.Diagnostic; -import io.github.mfvanek.pg.connection.PgHost; +import io.github.mfvanek.pg.host.PgHost; import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.dbobject.DbObject; import org.assertj.core.api.AbstractAssert; diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/utils/QueryExecutorsTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/utils/QueryExecutorsTest.java index 5e424b9e..9c98d5ff 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/utils/QueryExecutorsTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/utils/QueryExecutorsTest.java @@ -12,8 +12,8 @@ import io.github.mfvanek.pg.connection.PgConnection; import io.github.mfvanek.pg.connection.PgConnectionImpl; -import io.github.mfvanek.pg.connection.PgHostImpl; -import io.github.mfvanek.pg.connection.PgSqlException; +import io.github.mfvanek.pg.exception.PgSqlException; +import io.github.mfvanek.pg.host.PgHostImpl; import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.support.DatabaseAwareTestBase; import io.github.mfvanek.pg.support.TestUtils; diff --git a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/support/DatabaseAwareTestBase.java b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/support/DatabaseAwareTestBase.java index 0c05d7a1..df08fd88 100644 --- a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/support/DatabaseAwareTestBase.java +++ b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/support/DatabaseAwareTestBase.java @@ -10,13 +10,13 @@ package io.github.mfvanek.pg.support; -import io.github.mfvanek.pg.connection.ConnectionCredentials; import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; import io.github.mfvanek.pg.connection.HighAvailabilityPgConnectionImpl; import io.github.mfvanek.pg.connection.PgConnection; import io.github.mfvanek.pg.connection.PgConnectionImpl; -import io.github.mfvanek.pg.connection.PgHost; -import io.github.mfvanek.pg.connection.PgHostImpl; +import io.github.mfvanek.pg.connection.factory.ConnectionCredentials; +import io.github.mfvanek.pg.host.PgHost; +import io.github.mfvanek.pg.host.PgHostImpl; import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.testing.PostgreSqlContainerWrapper; diff --git a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/support/ExecuteUtils.java b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/support/ExecuteUtils.java index 92c75320..d46077ee 100644 --- a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/support/ExecuteUtils.java +++ b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/support/ExecuteUtils.java @@ -10,7 +10,7 @@ package io.github.mfvanek.pg.support; -import io.github.mfvanek.pg.connection.PgSqlException; +import io.github.mfvanek.pg.exception.PgSqlException; import io.github.mfvanek.pg.support.statements.DbStatement; import java.sql.Connection; diff --git a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/support/StatisticsAwareTestBase.java b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/support/StatisticsAwareTestBase.java index e15370f5..04c8130c 100644 --- a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/support/StatisticsAwareTestBase.java +++ b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/support/StatisticsAwareTestBase.java @@ -10,7 +10,7 @@ package io.github.mfvanek.pg.support; -import io.github.mfvanek.pg.connection.PgSqlException; +import io.github.mfvanek.pg.exception.PgSqlException; import io.github.mfvanek.pg.model.context.PgContext; import java.sql.Connection; diff --git a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/support/statements/CreateCustomCollationStatement.java b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/support/statements/CreateCustomCollationStatement.java index c99e3bf0..4bc6c0b3 100644 --- a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/support/statements/CreateCustomCollationStatement.java +++ b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/support/statements/CreateCustomCollationStatement.java @@ -10,7 +10,7 @@ package io.github.mfvanek.pg.support.statements; -import io.github.mfvanek.pg.connection.PgSqlException; +import io.github.mfvanek.pg.exception.PgSqlException; import io.github.mfvanek.pg.support.SchemaNameHolder; import java.sql.ResultSet; diff --git a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/support/statements/InsertDataIntoTablesAction.java b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/support/statements/InsertDataIntoTablesAction.java index b22eaf09..709f6e4c 100644 --- a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/support/statements/InsertDataIntoTablesAction.java +++ b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/support/statements/InsertDataIntoTablesAction.java @@ -10,7 +10,7 @@ package io.github.mfvanek.pg.support.statements; -import io.github.mfvanek.pg.connection.PgSqlException; +import io.github.mfvanek.pg.exception.PgSqlException; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.StringUtils; import org.postgresql.util.PGobject; diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnectionImpl.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnectionImpl.java index b389067f..5c51ce41 100644 --- a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnectionImpl.java +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnectionImpl.java @@ -45,7 +45,7 @@ private HighAvailabilityPgConnectionImpl(@Nonnull final PgConnection connectionT this.primaryHostDeterminer = Objects.requireNonNull(primaryHostDeterminer); Objects.requireNonNull(connectionToPrimary, "connectionToPrimary"); final Set defensiveCopy = Set.copyOf(Objects.requireNonNull(connectionsToAllHostsInCluster, "connectionsToAllHostsInCluster")); - PgConnectionValidators.shouldContainsConnectionToPrimary(connectionToPrimary, defensiveCopy); + shouldContainsConnectionToPrimary(connectionToPrimary, defensiveCopy); this.cachedConnectionToPrimary.set(connectionToPrimary); this.connectionsToAllHostsInCluster = defensiveCopy; } @@ -131,4 +131,11 @@ private void updateConnectionToPrimary() { } }); } + + private static void shouldContainsConnectionToPrimary(@Nonnull final PgConnection connectionToPrimary, + @Nonnull final Set connectionsToAllHostsInCluster) { + if (!connectionsToAllHostsInCluster.contains(connectionToPrimary)) { + throw new IllegalArgumentException("connectionsToAllHostsInCluster have to contain a connection to the primary"); + } + } } diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnection.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnection.java index 836342c7..c67be4e4 100644 --- a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnection.java +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnection.java @@ -10,6 +10,9 @@ package io.github.mfvanek.pg.connection; +import io.github.mfvanek.pg.host.HostAware; +import io.github.mfvanek.pg.host.PgHost; + import javax.annotation.Nonnull; import javax.sql.DataSource; diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnectionImpl.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnectionImpl.java index 07705bcd..9ba53b2c 100644 --- a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnectionImpl.java +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnectionImpl.java @@ -10,6 +10,8 @@ package io.github.mfvanek.pg.connection; +import io.github.mfvanek.pg.host.PgHost; + import java.util.Objects; import javax.annotation.Nonnull; import javax.sql.DataSource; diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnectionValidators.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnectionValidators.java deleted file mode 100644 index dbcf6784..00000000 --- a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnectionValidators.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2019-2024. Ivan Vakhrushev and others. - * https://github.com/mfvanek/pg-index-health - * - * This file is a part of "pg-index-health" - a Java library for - * analyzing and maintaining indexes health in PostgreSQL databases. - * - * Licensed under the Apache License 2.0 - */ - -package io.github.mfvanek.pg.connection; - -import java.util.Collection; -import java.util.Objects; -import java.util.Set; -import javax.annotation.Nonnull; - -final class PgConnectionValidators { - - private PgConnectionValidators() { - throw new UnsupportedOperationException(); - } - - @Nonnull - static String pgUrlNotBlankAndValid(@Nonnull final String pgUrl, @Nonnull final String argumentName) { - notBlank(pgUrl, argumentName); - if (!Objects.requireNonNull(pgUrl).startsWith(PgUrlParser.URL_HEADER)) { - throw new IllegalArgumentException(argumentName + " has invalid format"); - } - return pgUrl; - } - - @Nonnull - static String userNameNotBlank(@Nonnull final String userName) { - notBlank(userName, "userName"); - return userName; - } - - @Nonnull - static String passwordNotBlank(@Nonnull final String password) { - notBlank(password, "password"); - return password; - } - - static void connectionUrlsNotEmptyAndValid(@Nonnull final Collection connectionUrls) { - Objects.requireNonNull(connectionUrls, "connectionUrls"); - if (connectionUrls.isEmpty()) { - throw new IllegalArgumentException("connectionUrls have to contain at least one url"); - } - connectionUrls.forEach(url -> pgUrlNotBlankAndValid(url, "connectionUrl")); - } - - static void shouldContainsConnectionToPrimary(@Nonnull final PgConnection connectionToPrimary, - @Nonnull final Set connectionsToAllHostsInCluster) { - if (!connectionsToAllHostsInCluster.contains(connectionToPrimary)) { - throw new IllegalArgumentException("connectionsToAllHostsInCluster have to contain a connection to the primary"); - } - } - - static int portInAcceptableRange(final int port) { - // https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers - if (port < 1024 || port > 65_535) { - throw new IllegalArgumentException("the port number must be in the range from 1024 to 65535"); - } - return port; - } - - @Nonnull - static String hostNameNotBlank(@Nonnull final String hostName) { - notBlank(hostName, "hostName"); - return hostName; - } - - private static void notBlank(@Nonnull final String argumentValue, @Nonnull final String argumentName) { - if (Objects.requireNonNull(argumentValue, argumentName + " cannot be null").isBlank()) { - throw new IllegalArgumentException(argumentName + " cannot be blank or empty"); - } - } -} diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PrimaryHostDeterminer.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PrimaryHostDeterminer.java index db8868a7..8a71d401 100644 --- a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PrimaryHostDeterminer.java +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PrimaryHostDeterminer.java @@ -12,6 +12,9 @@ import javax.annotation.Nonnull; +/** + * Represents a service that determines if a given database connection is established with a primary host. + */ public interface PrimaryHostDeterminer { /** diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PrimaryHostDeterminerImpl.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PrimaryHostDeterminerImpl.java index fe39373d..86e8f9fb 100644 --- a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PrimaryHostDeterminerImpl.java +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PrimaryHostDeterminerImpl.java @@ -10,6 +10,7 @@ package io.github.mfvanek.pg.connection; +import io.github.mfvanek.pg.exception.PgSqlException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/ConnectionCredentials.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/ConnectionCredentials.java similarity index 74% rename from pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/ConnectionCredentials.java rename to pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/ConnectionCredentials.java index 41f9a1f9..5bb43137 100644 --- a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/ConnectionCredentials.java +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/ConnectionCredentials.java @@ -8,7 +8,9 @@ * Licensed under the Apache License 2.0 */ -package io.github.mfvanek.pg.connection; +package io.github.mfvanek.pg.connection.factory; + +import io.github.mfvanek.pg.host.PgUrlValidators; import java.util.ArrayList; import java.util.Collection; @@ -27,7 +29,7 @@ * @author Ivan Vakhrushev */ @Immutable -public class ConnectionCredentials { +public final class ConnectionCredentials { private final SortedSet connectionUrls; private final String userName; @@ -77,7 +79,7 @@ public String getPassword() { * {@inheritDoc} */ @Override - public final boolean equals(final Object other) { + public boolean equals(final Object other) { if (this == other) { return true; } @@ -96,7 +98,7 @@ public final boolean equals(final Object other) { * {@inheritDoc} */ @Override - public final int hashCode() { + public int hashCode() { return Objects.hash(connectionUrls, userName, password); } @@ -113,6 +115,14 @@ public String toString() { '}'; } + /** + * Creates a {@link ConnectionCredentials} object with multiple connection URLs. + * + * @param connectionUrls the collection of connection URLs; must not be null or empty, and all URLs must be valid. + * @param userName the username for authentication; must not be null or blank. + * @param password the password for authentication; must not be null or blank. + * @return a new {@link ConnectionCredentials} instance. + */ @Nonnull public static ConnectionCredentials of(@Nonnull final Collection connectionUrls, @Nonnull final String userName, @@ -120,11 +130,19 @@ public static ConnectionCredentials of(@Nonnull final Collection connect return new ConnectionCredentials(connectionUrls, userName, password); } + /** + * Creates a {@link ConnectionCredentials} object for a single connection URL. + * + * @param writeUrl the write connection URL; must not be null, blank, or have an invalid format. + * @param userName the username for authentication; must not be null or blank. + * @param password the password for authentication; must not be null or blank. + * @return a new {@link ConnectionCredentials} instance containing the validated URL. + */ @Nonnull public static ConnectionCredentials ofUrl(@Nonnull final String writeUrl, @Nonnull final String userName, @Nonnull final String password) { - final Set connectionUrls = Set.of(PgConnectionValidators.pgUrlNotBlankAndValid(writeUrl, "writeUrl")); + final Set connectionUrls = Set.of(PgUrlValidators.pgUrlNotBlankAndValid(writeUrl, "writeUrl")); return new ConnectionCredentials(connectionUrls, userName, password); } } diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnectionFactory.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/HighAvailabilityPgConnectionFactory.java similarity index 92% rename from pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnectionFactory.java rename to pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/HighAvailabilityPgConnectionFactory.java index 5c68184f..3a8189b2 100644 --- a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnectionFactory.java +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/HighAvailabilityPgConnectionFactory.java @@ -8,7 +8,9 @@ * Licensed under the Apache License 2.0 */ -package io.github.mfvanek.pg.connection; +package io.github.mfvanek.pg.connection.factory; + +import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; import java.util.Collection; import javax.annotation.Nonnull; diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnectionFactoryImpl.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/HighAvailabilityPgConnectionFactoryImpl.java similarity index 89% rename from pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnectionFactoryImpl.java rename to pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/HighAvailabilityPgConnectionFactoryImpl.java index cde62a1e..87f5e198 100644 --- a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnectionFactoryImpl.java +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/HighAvailabilityPgConnectionFactoryImpl.java @@ -8,7 +8,13 @@ * Licensed under the Apache License 2.0 */ -package io.github.mfvanek.pg.connection; +package io.github.mfvanek.pg.connection.factory; + +import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; +import io.github.mfvanek.pg.connection.HighAvailabilityPgConnectionImpl; +import io.github.mfvanek.pg.connection.PgConnection; +import io.github.mfvanek.pg.connection.PrimaryHostDeterminer; +import io.github.mfvanek.pg.host.PgUrlParser; import java.util.LinkedHashMap; import java.util.List; diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnectionFactory.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/PgConnectionFactory.java similarity index 85% rename from pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnectionFactory.java rename to pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/PgConnectionFactory.java index 2e97e54b..3f633b0f 100644 --- a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnectionFactory.java +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/PgConnectionFactory.java @@ -8,7 +8,9 @@ * Licensed under the Apache License 2.0 */ -package io.github.mfvanek.pg.connection; +package io.github.mfvanek.pg.connection.factory; + +import io.github.mfvanek.pg.connection.PgConnection; import javax.annotation.Nonnull; import javax.sql.DataSource; diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnectionFactoryImpl.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/PgConnectionFactoryImpl.java similarity index 87% rename from pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnectionFactoryImpl.java rename to pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/PgConnectionFactoryImpl.java index 98d5f2f1..919fbfed 100644 --- a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnectionFactoryImpl.java +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/PgConnectionFactoryImpl.java @@ -8,8 +8,11 @@ * Licensed under the Apache License 2.0 */ -package io.github.mfvanek.pg.connection; +package io.github.mfvanek.pg.connection.factory; +import io.github.mfvanek.pg.connection.PgConnection; +import io.github.mfvanek.pg.connection.PgConnectionImpl; +import io.github.mfvanek.pg.host.PgHostImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnectionHelper.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/PgConnectionHelper.java similarity index 91% rename from pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnectionHelper.java rename to pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/PgConnectionHelper.java index b92ca2a1..3d55b93e 100644 --- a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnectionHelper.java +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/PgConnectionHelper.java @@ -8,8 +8,9 @@ * Licensed under the Apache License 2.0 */ -package io.github.mfvanek.pg.connection; +package io.github.mfvanek.pg.connection.factory; +import io.github.mfvanek.pg.host.PgUrlValidators; import org.apache.commons.dbcp2.BasicDataSource; import javax.annotation.Nonnull; @@ -25,7 +26,7 @@ private PgConnectionHelper() { static DataSource createDataSource(@Nonnull final String pgUrl, @Nonnull final String userName, @Nonnull final String password) { - PgConnectionValidators.pgUrlNotBlankAndValid(pgUrl, "pgUrl"); + PgUrlValidators.pgUrlNotBlankAndValid(pgUrl, "pgUrl"); PgConnectionValidators.userNameNotBlank(userName); PgConnectionValidators.passwordNotBlank(password); final BasicDataSource dataSource = new BasicDataSource(); diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/PgConnectionValidators.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/PgConnectionValidators.java new file mode 100644 index 00000000..c1c9b70a --- /dev/null +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/PgConnectionValidators.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * https://github.com/mfvanek/pg-index-health + * + * This file is a part of "pg-index-health" - a Java library for + * analyzing and maintaining indexes health in PostgreSQL databases. + * + * Licensed under the Apache License 2.0 + */ + +package io.github.mfvanek.pg.connection.factory; + +import io.github.mfvanek.pg.host.PgUrlValidators; +import io.github.mfvanek.pg.model.validation.Validators; + +import java.util.Collection; +import java.util.Objects; +import javax.annotation.Nonnull; + +/** + * Utility class providing validation methods for PostgreSQL connection parameters. + * This class includes methods for validating PostgreSQL URLs, usernames, passwords, + * hostnames, ports, and ensuring connections meet specific requirements. + */ +final class PgConnectionValidators { + + private PgConnectionValidators() { + throw new UnsupportedOperationException(); + } + + /** + * Validates that a username is not blank. + * + * @param userName the username to validate; must not be {@code null} or blank. + * @return the validated username. + * @throws IllegalArgumentException if the username is blank. + */ + @Nonnull + static String userNameNotBlank(@Nonnull final String userName) { + Validators.notBlank(userName, "userName"); + return userName; + } + + /** + * Validates that a password is not blank. + * + * @param password the password to validate; must not be {@code null} or blank. + * @return the validated password. + * @throws IllegalArgumentException if the password is blank. + */ + @Nonnull + static String passwordNotBlank(@Nonnull final String password) { + Validators.notBlank(password, "password"); + return password; + } + + /** + * Validates that a collection of PostgreSQL connection URLs is not empty and that each URL is valid. + * + * @param connectionUrls the collection of connection URLs; must not be {@code null} or empty. + * @throws IllegalArgumentException if the collection is empty or any URL is invalid. + */ + static void connectionUrlsNotEmptyAndValid(@Nonnull final Collection connectionUrls) { + Objects.requireNonNull(connectionUrls, "connectionUrls"); + if (connectionUrls.isEmpty()) { + throw new IllegalArgumentException("connectionUrls have to contain at least one url"); + } + connectionUrls.forEach(url -> PgUrlValidators.pgUrlNotBlankAndValid(url, "connectionUrl")); + } +} diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgSqlException.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/exception/PgSqlException.java similarity index 74% rename from pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgSqlException.java rename to pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/exception/PgSqlException.java index 3616a71f..584c95c1 100644 --- a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgSqlException.java +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/exception/PgSqlException.java @@ -8,7 +8,7 @@ * Licensed under the Apache License 2.0 */ -package io.github.mfvanek.pg.connection; +package io.github.mfvanek.pg.exception; import java.sql.SQLException; import javax.annotation.Nonnull; @@ -23,6 +23,11 @@ public class PgSqlException extends RuntimeException { private static final long serialVersionUID = -6917248037245766939L; + /** + * Constructs a new {@code PgSqlException} with the specified cause. + * + * @param cause the {@link SQLException} that caused this exception; must not be {@code null}. + */ public PgSqlException(@Nonnull final SQLException cause) { super(cause.getMessage(), cause); } diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/HostAware.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/host/HostAware.java similarity index 93% rename from pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/HostAware.java rename to pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/host/HostAware.java index c5f91d20..cf266528 100644 --- a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/HostAware.java +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/host/HostAware.java @@ -8,7 +8,7 @@ * Licensed under the Apache License 2.0 */ -package io.github.mfvanek.pg.connection; +package io.github.mfvanek.pg.host; import javax.annotation.Nonnull; diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgHost.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/host/PgHost.java similarity index 84% rename from pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgHost.java rename to pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/host/PgHost.java index e552a9b9..36e6cf20 100644 --- a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgHost.java +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/host/PgHost.java @@ -8,7 +8,7 @@ * Licensed under the Apache License 2.0 */ -package io.github.mfvanek.pg.connection; +package io.github.mfvanek.pg.host; import javax.annotation.Nonnull; @@ -52,6 +52,11 @@ public interface PgHost { */ boolean canBePrimary(); + /** + * Determines whether this host cannot act as a primary host. + * + * @return {@code true} if this host cannot be a primary host; {@code false} otherwise. + */ default boolean cannotBePrimary() { return !canBePrimary(); } diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgHostImpl.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/host/PgHostImpl.java similarity index 88% rename from pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgHostImpl.java rename to pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/host/PgHostImpl.java index e4fd2397..e1aae6b1 100644 --- a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgHostImpl.java +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/host/PgHostImpl.java @@ -8,7 +8,7 @@ * Licensed under the Apache License 2.0 */ -package io.github.mfvanek.pg.connection; +package io.github.mfvanek.pg.host; import java.util.List; import java.util.Map; @@ -23,7 +23,7 @@ * @see PgHost */ @Immutable -public class PgHostImpl implements PgHost { +public final class PgHostImpl implements PgHost { private final String pgUrl; private final String hostName; @@ -34,9 +34,9 @@ private PgHostImpl(@Nonnull final String pgUrl, @Nonnull final String hostName, final int port, final boolean maybePrimary) { - this.pgUrl = PgConnectionValidators.pgUrlNotBlankAndValid(pgUrl, "pgUrl"); - this.hostName = PgConnectionValidators.hostNameNotBlank(hostName); - this.port = PgConnectionValidators.portInAcceptableRange(port); + this.pgUrl = PgUrlValidators.pgUrlNotBlankAndValid(pgUrl); + this.hostName = PgUrlValidators.hostNameNotBlank(hostName); + this.port = PgUrlValidators.portInAcceptableRange(port); this.maybePrimary = maybePrimary; } @@ -74,28 +74,11 @@ public boolean canBePrimary() { return maybePrimary; } - /** - * Constructs a {@code PgHost} object from given JDBC connection string. - * - * @param pgUrl connection string to a database in JDBC format - * @return {@code PgHost} - */ - @Nonnull - public static PgHost ofUrl(@Nonnull final String pgUrl) { - final List> extractHostNames = PgUrlParser.extractHostNames(pgUrl); - if (extractHostNames.size() > 1) { - throw new IllegalArgumentException("pgUrl couldn't contain multiple hosts"); - } - - final Map.Entry host = extractHostNames.get(0); - return new PgHostImpl(pgUrl, host.getKey(), host.getValue(), !PgUrlParser.isReplicaUrl(pgUrl)); - } - /** * {@inheritDoc} */ @Override - public final boolean equals(final Object other) { + public boolean equals(final Object other) { if (this == other) { return true; } @@ -113,7 +96,7 @@ public final boolean equals(final Object other) { * {@inheritDoc} */ @Override - public final int hashCode() { + public int hashCode() { return Objects.hash(hostName, port); } @@ -130,4 +113,21 @@ public String toString() { ", maybePrimary=" + maybePrimary + '}'; } + + /** + * Constructs a {@code PgHost} object from given JDBC connection string. + * + * @param pgUrl connection string to a database in JDBC format + * @return {@code PgHost} + */ + @Nonnull + public static PgHost ofUrl(@Nonnull final String pgUrl) { + final List> extractHostNames = PgUrlParser.extractHostNames(pgUrl); + if (extractHostNames.size() > 1) { + throw new IllegalArgumentException("pgUrl couldn't contain multiple hosts"); + } + + final Map.Entry host = extractHostNames.get(0); + return new PgHostImpl(pgUrl, host.getKey(), host.getValue(), !PgUrlParser.isReplicaUrl(pgUrl)); + } } diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgUrlParser.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/host/PgUrlParser.java similarity index 61% rename from pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgUrlParser.java rename to pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/host/PgUrlParser.java index a76b1456..5ea61af7 100644 --- a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgUrlParser.java +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/host/PgUrlParser.java @@ -8,7 +8,7 @@ * Licensed under the Apache License 2.0 */ -package io.github.mfvanek.pg.connection; +package io.github.mfvanek.pg.host; import java.util.Arrays; import java.util.List; @@ -19,10 +19,18 @@ import java.util.stream.Collectors; import javax.annotation.Nonnull; +import static io.github.mfvanek.pg.host.PgUrlValidators.pgUrlNotBlankAndValid; + +/** + * Utility class for parsing and manipulating PostgreSQL connection URLs. + */ public final class PgUrlParser { + /** + * Header prefix for PostgreSQL JDBC URLs. + */ public static final String URL_HEADER = "jdbc:postgresql://"; - private static final String PG_URL = "pgUrl"; + private static final Map DEFAULT_URL_PARAMETERS = Map.ofEntries( Map.entry("targetServerType", "primary"), Map.entry("hostRecheckSeconds", "2"), @@ -34,16 +42,28 @@ private PgUrlParser() { throw new UnsupportedOperationException(); } + /** + * Checks if the given PostgreSQL URL points to a replica. + * + * @param pgUrl the PostgreSQL connection URL; must be valid and non-blank. + * @return {@code true} if the URL specifies a replica as the target server type. + */ static boolean isReplicaUrl(@Nonnull final String pgUrl) { - PgConnectionValidators.pgUrlNotBlankAndValid(pgUrl, PG_URL); + pgUrlNotBlankAndValid(pgUrl); return pgUrl.contains("targetServerType=slave") || pgUrl.contains("targetServerType=secondary"); } - // For example, jdbc:postgresql://host-1:6432/db_name?param=value + /** + * Extracts host-port pairs and builds replica-compatible connection URLs for each host. + * + * @param pgUrl the PostgreSQL connection URL; must be valid and non-blank. + * @return a list of host-port pairs and corresponding replica-compatible URLs. + */ @Nonnull - static List> extractNameWithPortAndUrlForEachHost(@Nonnull final String pgUrl) { - PgConnectionValidators.pgUrlNotBlankAndValid(pgUrl, PG_URL); + public static List> extractNameWithPortAndUrlForEachHost(@Nonnull final String pgUrl) { + // For example, jdbc:postgresql://host-1:6432/db_name?param=value + pgUrlNotBlankAndValid(pgUrl); final int lastIndex = pgUrl.lastIndexOf('/'); final String dbNameWithParams = pgUrl.substring(lastIndex); final String dbNameWithParamsForReplica = convertToReplicaConnectionString(dbNameWithParams); @@ -55,6 +75,12 @@ static List> extractNameWithPortAndUrlForEachHost(@Non .collect(Collectors.toUnmodifiableList()); } + /** + * Converts a given part of connection string to a replica-compatible connection string. + * + * @param dbNameWithParams the database name and parameters from the URL. + * @return the replica-compatible connection string. + */ @Nonnull private static String convertToReplicaConnectionString(@Nonnull final String dbNameWithParams) { final List primaryServerTypes = List.of("targetServerType=primary", "targetServerType=master"); @@ -66,10 +92,15 @@ private static String convertToReplicaConnectionString(@Nonnull final String dbN return dbNameWithParams; } + /** + * Extracts host names and ports from a PostgreSQL connection URL. + * + * @param pgUrl the PostgreSQL connection URL; must be valid and non-blank. + * @return a list of host-port pairs. + */ @Nonnull static List> extractHostNames(@Nonnull final String pgUrl) { - PgConnectionValidators.pgUrlNotBlankAndValid(pgUrl, PG_URL); - final String allHostsWithPort = extractAllHostsWithPort(pgUrl); + final String allHostsWithPort = extractAllHostsWithPort(pgUrlNotBlankAndValid(pgUrl)); return Arrays.stream(allHostsWithPort.split(",")) .filter(Predicate.not(String::isBlank)) .map(h -> { @@ -81,6 +112,13 @@ static List> extractHostNames(@Nonnull final String p .collect(Collectors.toUnmodifiableList()); } + /** + * Extracts the database name from a set of PostgreSQL connection URLs. + * + * @param pgUrls a set of PostgreSQL connection URLs; must contain at least one valid URL. + * @return the database name extracted from the URLs. + * @throws IllegalArgumentException if the connection string is invalid. + */ @Nonnull static String extractDatabaseName(@Nonnull final Set pgUrls) { final String pgUrl = pgUrls.iterator().next(); @@ -95,6 +133,12 @@ static String extractDatabaseName(@Nonnull final Set pgUrls) { return dbNameWithParams; } + /** + * Extracts all host and port pairs from a PostgreSQL connection URL. + * + * @param pgUrl the PostgreSQL connection URL; must be valid and non-blank. + * @return a string containing all host and port pairs. + */ @Nonnull private static String extractAllHostsWithPort(@Nonnull final String pgUrl) { final int lastIndex = pgUrl.lastIndexOf('/'); @@ -104,12 +148,27 @@ private static String extractAllHostsWithPort(@Nonnull final String pgUrl) { return pgUrl.substring(URL_HEADER.length()); } + /** + * Constructs a common (joint) PostgreSQL URL for a primary server. + * + * @param firstPgUrl a first PostgreSQL connection URL. + * @param secondPgUrl a second PostgreSQL connection URL. + * @return the constructed primary connection URL. + */ @Nonnull public static String buildCommonUrlToPrimary(@Nonnull final String firstPgUrl, @Nonnull final String secondPgUrl) { return buildCommonUrlToPrimary(Set.of(firstPgUrl, secondPgUrl)); } + /** + * Constructs a common (joint) PostgreSQL URL for a primary server. + * + * @param firstPgUrl a first PostgreSQL connection URL. + * @param secondPgUrl a second PostgreSQL connection URL. + * @param urlParameters optional additional parameters to include in the URL. + * @return the constructed primary connection URL. + */ @Nonnull public static String buildCommonUrlToPrimary(@Nonnull final String firstPgUrl, @Nonnull final String secondPgUrl, @@ -117,11 +176,24 @@ public static String buildCommonUrlToPrimary(@Nonnull final String firstPgUrl, return buildCommonUrlToPrimary(Set.of(firstPgUrl, secondPgUrl), urlParameters); } + /** + * Constructs a common (joint) PostgreSQL URL for a primary server. + * + * @param pgUrls a set of PostgreSQL connection URLs. + * @return the constructed primary connection URL. + */ @Nonnull public static String buildCommonUrlToPrimary(@Nonnull final Set pgUrls) { return buildCommonUrlToPrimary(pgUrls, Map.of()); } + /** + * Constructs a common (joint) PostgreSQL URL for a primary server. + * + * @param pgUrls a set of PostgreSQL connection URLs. + * @param urlParameters optional additional parameters to include in the URL. + * @return the constructed primary connection URL. + */ @Nonnull public static String buildCommonUrlToPrimary(@Nonnull final Set pgUrls, @Nonnull final Map urlParameters) { @@ -133,6 +205,12 @@ public static String buildCommonUrlToPrimary(@Nonnull final Set pgUrls, extractDatabaseName(pgUrls) + additionalUrlParams; } + /** + * Constructs a query string from default and provided URL parameters. + * + * @param urlParameters a map of additional URL parameters. + * @return the constructed query string, prefixed by {@code ?}. + */ @Nonnull static String constructUrlParameters(@Nonnull final Map urlParameters) { final Map jointUrlParameters = new TreeMap<>(urlParameters); diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/host/PgUrlValidators.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/host/PgUrlValidators.java new file mode 100644 index 00000000..8fe68624 --- /dev/null +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/host/PgUrlValidators.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * https://github.com/mfvanek/pg-index-health + * + * This file is a part of "pg-index-health" - a Java library for + * analyzing and maintaining indexes health in PostgreSQL databases. + * + * Licensed under the Apache License 2.0 + */ + +package io.github.mfvanek.pg.host; + +import io.github.mfvanek.pg.model.validation.Validators; + +import java.util.Objects; +import javax.annotation.Nonnull; + +/** + * Utility class providing validation methods for PostgreSQL connection string (URL). + */ +public final class PgUrlValidators { + + private PgUrlValidators() { + throw new UnsupportedOperationException(); + } + + /** + * Validates that a PostgreSQL URL is not blank and has a valid format. + * + * @param pgUrl the PostgreSQL URL to validate; must not be {@code null} or blank. + * @param argumentName the name of the argument being validated, for use in error messages. + * @return the validated PostgreSQL URL. + * @throws IllegalArgumentException if the URL is blank or does not start with the expected header. + */ + @Nonnull + public static String pgUrlNotBlankAndValid(@Nonnull final String pgUrl, @Nonnull final String argumentName) { + Validators.notBlank(pgUrl, argumentName); + if (!Objects.requireNonNull(pgUrl).startsWith(PgUrlParser.URL_HEADER)) { + throw new IllegalArgumentException(argumentName + " has invalid format"); + } + return pgUrl; + } + + /** + * Validates that a PostgreSQL URL is not blank and has a valid format. + * + * @param pgUrl the PostgreSQL URL to validate; must not be {@code null} or blank. + * @return the validated PostgreSQL URL. + */ + @Nonnull + static String pgUrlNotBlankAndValid(@Nonnull final String pgUrl) { + return pgUrlNotBlankAndValid(pgUrl, "pgUrl"); + } + + /** + * Validates that a hostname is not blank. + * + * @param hostName the hostname to validate; must not be {@code null} or blank. + * @return the validated hostname. + * @throws IllegalArgumentException if the hostname is blank. + */ + @Nonnull + static String hostNameNotBlank(@Nonnull final String hostName) { + Validators.notBlank(hostName, "hostName"); + return hostName; + } + + /** + * Validates that a port number is within the acceptable range (1024–65535). + * + * @param port the port number to validate. + * @return the validated port number. + * @throws IllegalArgumentException if the port number is outside the acceptable range. + */ + static int portInAcceptableRange(final int port) { + // https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers + if (port < 1024 || port > 65_535) { + throw new IllegalArgumentException("the port number must be in the range from 1024 to 65535"); + } + return port; + } +} diff --git a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnectionImplTest.java b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnectionImplTest.java index c3208ed8..d57be267 100644 --- a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnectionImplTest.java +++ b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnectionImplTest.java @@ -10,6 +10,7 @@ package io.github.mfvanek.pg.connection; +import io.github.mfvanek.pg.host.PgHostImpl; import io.github.mfvanek.pg.support.DatabaseAwareTestBase; import org.junit.jupiter.api.Test; diff --git a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnectionUnitTest.java b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnectionUnitTest.java index 516d4215..506b294d 100644 --- a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnectionUnitTest.java +++ b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnectionUnitTest.java @@ -11,6 +11,8 @@ package io.github.mfvanek.pg.connection; import ch.qos.logback.classic.Level; +import io.github.mfvanek.pg.host.PgHost; +import io.github.mfvanek.pg.host.PgHostImpl; import io.github.mfvanek.pg.support.LogsCaptor; import org.awaitility.Awaitility; import org.junit.jupiter.api.Tag; diff --git a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PgConnectionImplTest.java b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PgConnectionImplTest.java index 201a36ff..701d9e3d 100644 --- a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PgConnectionImplTest.java +++ b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PgConnectionImplTest.java @@ -10,6 +10,8 @@ package io.github.mfvanek.pg.connection; +import io.github.mfvanek.pg.host.PgHost; +import io.github.mfvanek.pg.host.PgHostImpl; import io.github.mfvanek.pg.support.DatabaseAwareTestBase; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.jupiter.api.Test; diff --git a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PrimaryHostDeterminerImplTest.java b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PrimaryHostDeterminerImplTest.java index ebbfcba7..ffa74903 100644 --- a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PrimaryHostDeterminerImplTest.java +++ b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PrimaryHostDeterminerImplTest.java @@ -10,6 +10,9 @@ package io.github.mfvanek.pg.connection; +import io.github.mfvanek.pg.exception.PgSqlException; +import io.github.mfvanek.pg.host.PgHost; +import io.github.mfvanek.pg.host.PgHostImpl; import io.github.mfvanek.pg.support.DatabaseAwareTestBase; import org.junit.jupiter.api.Test; import org.mockito.Mockito; diff --git a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/ConnectionCredentialsTest.java b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/factory/ConnectionCredentialsTest.java similarity index 94% rename from pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/ConnectionCredentialsTest.java rename to pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/factory/ConnectionCredentialsTest.java index 21f135fe..86fb557c 100644 --- a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/ConnectionCredentialsTest.java +++ b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/factory/ConnectionCredentialsTest.java @@ -8,7 +8,7 @@ * Licensed under the Apache License 2.0 */ -package io.github.mfvanek.pg.connection; +package io.github.mfvanek.pg.connection.factory; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.jupiter.api.Tag; @@ -130,25 +130,25 @@ void withInvalidArguments() { .hasMessage("password cannot be null"); assertThatThrownBy(() -> ConnectionCredentials.ofUrl("", "u", "p")) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("writeUrl cannot be blank or empty"); + .hasMessage("writeUrl cannot be blank"); assertThatThrownBy(() -> ConnectionCredentials.ofUrl(" ", "u", "p")) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("writeUrl cannot be blank or empty"); + .hasMessage("writeUrl cannot be blank"); assertThatThrownBy(() -> ConnectionCredentials.ofUrl("url", "u", "p")) .isInstanceOf(IllegalArgumentException.class) .hasMessage("writeUrl has invalid format"); assertThatThrownBy(() -> ConnectionCredentials.ofUrl(DEFAULT_URL, "", "p")) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("userName cannot be blank or empty"); + .hasMessage("userName cannot be blank"); assertThatThrownBy(() -> ConnectionCredentials.ofUrl(DEFAULT_URL, " ", "p")) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("userName cannot be blank or empty"); + .hasMessage("userName cannot be blank"); assertThatThrownBy(() -> ConnectionCredentials.ofUrl(DEFAULT_URL, "u", "")) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("password cannot be blank or empty"); + .hasMessage("password cannot be blank"); assertThatThrownBy(() -> ConnectionCredentials.ofUrl(DEFAULT_URL, "u", " ")) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("password cannot be blank or empty"); + .hasMessage("password cannot be blank"); assertThatThrownBy(() -> ConnectionCredentials.of(null, null, null)) .isInstanceOf(NullPointerException.class) diff --git a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnectionFactoryImplTest.java b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/factory/HighAvailabilityPgConnectionFactoryImplTest.java similarity index 96% rename from pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnectionFactoryImplTest.java rename to pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/factory/HighAvailabilityPgConnectionFactoryImplTest.java index dfddd6d0..f81cabcf 100644 --- a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnectionFactoryImplTest.java +++ b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/factory/HighAvailabilityPgConnectionFactoryImplTest.java @@ -8,8 +8,11 @@ * Licensed under the Apache License 2.0 */ -package io.github.mfvanek.pg.connection; +package io.github.mfvanek.pg.connection.factory; +import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; +import io.github.mfvanek.pg.connection.PgConnection; +import io.github.mfvanek.pg.connection.PrimaryHostDeterminer; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.mockito.Mockito; diff --git a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PgConnectionFactoryImplTest.java b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/factory/PgConnectionFactoryImplTest.java similarity index 91% rename from pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PgConnectionFactoryImplTest.java rename to pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/factory/PgConnectionFactoryImplTest.java index 6aa761f1..83c98ea8 100644 --- a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PgConnectionFactoryImplTest.java +++ b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/factory/PgConnectionFactoryImplTest.java @@ -8,8 +8,9 @@ * Licensed under the Apache License 2.0 */ -package io.github.mfvanek.pg.connection; +package io.github.mfvanek.pg.connection.factory; +import io.github.mfvanek.pg.connection.PgConnection; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; diff --git a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PgConnectionHelperTest.java b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/factory/PgConnectionHelperTest.java similarity index 97% rename from pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PgConnectionHelperTest.java rename to pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/factory/PgConnectionHelperTest.java index 921647b9..b6928571 100644 --- a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PgConnectionHelperTest.java +++ b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/factory/PgConnectionHelperTest.java @@ -8,7 +8,7 @@ * Licensed under the Apache License 2.0 */ -package io.github.mfvanek.pg.connection; +package io.github.mfvanek.pg.connection.factory; import io.github.mfvanek.pg.support.TestUtils; import org.apache.commons.dbcp2.BasicDataSource; diff --git a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/factory/PgConnectionValidatorsTest.java b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/factory/PgConnectionValidatorsTest.java new file mode 100644 index 00000000..ed04205f --- /dev/null +++ b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/factory/PgConnectionValidatorsTest.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * https://github.com/mfvanek/pg-index-health + * + * This file is a part of "pg-index-health" - a Java library for + * analyzing and maintaining indexes health in PostgreSQL databases. + * + * Licensed under the Apache License 2.0 + */ + +package io.github.mfvanek.pg.connection.factory; + +import io.github.mfvanek.pg.support.TestUtils; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +@Tag("fast") +class PgConnectionValidatorsTest { + + @Test + void privateConstructor() { + assertThatThrownBy(() -> TestUtils.invokePrivateConstructor(PgConnectionValidators.class)) + .isInstanceOf(UnsupportedOperationException.class); + } + + @Test + void connectionUrlsNotEmptyAndValid() { + final List urls = List.of("jdbc:postgresql:/", "jdb:postgresl://"); + assertThatThrownBy(() -> PgConnectionValidators.connectionUrlsNotEmptyAndValid(urls)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("connectionUrl has invalid format"); + } +} diff --git a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PgHostImplTest.java b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/host/PgHostImplTest.java similarity index 97% rename from pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PgHostImplTest.java rename to pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/host/PgHostImplTest.java index 616ab897..1798212f 100644 --- a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PgHostImplTest.java +++ b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/host/PgHostImplTest.java @@ -8,7 +8,7 @@ * Licensed under the Apache License 2.0 */ -package io.github.mfvanek.pg.connection; +package io.github.mfvanek.pg.host; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.jupiter.api.Tag; @@ -54,13 +54,13 @@ void withInvalidValues() { .hasMessage("pgUrl cannot be null"); assertThatThrownBy(() -> PgHostImpl.ofUrl("")) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("pgUrl cannot be blank or empty"); + .hasMessage("pgUrl cannot be blank"); assertThatThrownBy(() -> PgHostImpl.ofUrl("host")) .isInstanceOf(IllegalArgumentException.class) .hasMessage("pgUrl has invalid format"); assertThatThrownBy(() -> PgHostImpl.ofUrl("jdbc:postgresql://:6432")) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("hostName cannot be blank or empty"); + .hasMessage("hostName cannot be blank"); assertThatThrownBy(() -> PgHostImpl.ofUrl("jdbc:postgresql://localhost:1023")) .isInstanceOf(IllegalArgumentException.class) .hasMessage("the port number must be in the range from 1024 to 65535"); diff --git a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PgUrlParserTest.java b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/host/PgUrlParserTest.java similarity index 98% rename from pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PgUrlParserTest.java rename to pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/host/PgUrlParserTest.java index 3e5e2e20..1630682f 100644 --- a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PgUrlParserTest.java +++ b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/host/PgUrlParserTest.java @@ -8,7 +8,7 @@ * Licensed under the Apache License 2.0 */ -package io.github.mfvanek.pg.connection; +package io.github.mfvanek.pg.host; import io.github.mfvanek.pg.support.TestUtils; import org.junit.jupiter.api.Tag; @@ -50,7 +50,7 @@ void extractNamesAndUrlsForEachHostWithInvalidUrl() { .hasMessage("pgUrl cannot be null"); assertThatThrownBy(() -> PgUrlParser.extractNameWithPortAndUrlForEachHost("")) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("pgUrl cannot be blank or empty"); + .hasMessage("pgUrl cannot be blank"); assertThatThrownBy(() -> PgUrlParser.extractNameWithPortAndUrlForEachHost("host-name:5432")) .isInstanceOf(IllegalArgumentException.class) .hasMessage("pgUrl has invalid format"); @@ -128,7 +128,7 @@ void extractHostNamesWithInvalidUrl() { .hasMessage("pgUrl cannot be null"); assertThatThrownBy(() -> PgUrlParser.extractHostNames("")) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("pgUrl cannot be blank or empty"); + .hasMessage("pgUrl cannot be blank"); assertThatThrownBy(() -> PgUrlParser.extractHostNames("host-name:5432")) .isInstanceOf(IllegalArgumentException.class) .hasMessage("pgUrl has invalid format"); @@ -158,7 +158,7 @@ void isReplicaUrlWithInvalidUrl() { .hasMessage("pgUrl cannot be null"); assertThatThrownBy(() -> PgUrlParser.isReplicaUrl("")) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("pgUrl cannot be blank or empty"); + .hasMessage("pgUrl cannot be blank"); assertThatThrownBy(() -> PgUrlParser.isReplicaUrl("host-name:5432")) .isInstanceOf(IllegalArgumentException.class) .hasMessage("pgUrl has invalid format"); diff --git a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PgConnectionValidatorsTest.java b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/host/PgUrlValidatorsTest.java similarity index 54% rename from pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PgConnectionValidatorsTest.java rename to pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/host/PgUrlValidatorsTest.java index c52a89f7..ce9bdd65 100644 --- a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/connection/PgConnectionValidatorsTest.java +++ b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/host/PgUrlValidatorsTest.java @@ -8,61 +8,51 @@ * Licensed under the Apache License 2.0 */ -package io.github.mfvanek.pg.connection; +package io.github.mfvanek.pg.host; import io.github.mfvanek.pg.support.TestUtils; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import java.util.List; - import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @Tag("fast") -class PgConnectionValidatorsTest { +class PgUrlValidatorsTest { @Test void privateConstructor() { - assertThatThrownBy(() -> TestUtils.invokePrivateConstructor(PgConnectionValidators.class)) + assertThatThrownBy(() -> TestUtils.invokePrivateConstructor(PgUrlValidators.class)) .isInstanceOf(UnsupportedOperationException.class); } - @Test - void connectionUrlsNotEmptyAndValid() { - final List urls = List.of("jdbc:postgresql:/", "jdb:postgresl://"); - assertThatThrownBy(() -> PgConnectionValidators.connectionUrlsNotEmptyAndValid(urls)) - .isInstanceOf(IllegalArgumentException.class) - .hasMessage("connectionUrl has invalid format"); - } - @Test void portInAcceptableRange() { - assertThatThrownBy(() -> PgConnectionValidators.portInAcceptableRange(1023)) + assertThatThrownBy(() -> PgUrlValidators.portInAcceptableRange(1023)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("the port number must be in the range from 1024 to 65535"); - assertThatThrownBy(() -> PgConnectionValidators.portInAcceptableRange(65_536)) + assertThatThrownBy(() -> PgUrlValidators.portInAcceptableRange(65_536)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("the port number must be in the range from 1024 to 65535"); - assertThat(PgConnectionValidators.portInAcceptableRange(1024)) + assertThat(PgUrlValidators.portInAcceptableRange(1024)) .isEqualTo(1024); - assertThat(PgConnectionValidators.portInAcceptableRange(65_535)) + assertThat(PgUrlValidators.portInAcceptableRange(65_535)) .isEqualTo(65_535); } @SuppressWarnings("DataFlowIssue") @Test void hostNameNotBlank() { - assertThatThrownBy(() -> PgConnectionValidators.hostNameNotBlank(null)) + assertThatThrownBy(() -> PgUrlValidators.hostNameNotBlank(null)) .isInstanceOf(NullPointerException.class) .hasMessage("hostName cannot be null"); - assertThatThrownBy(() -> PgConnectionValidators.hostNameNotBlank("")) + assertThatThrownBy(() -> PgUrlValidators.hostNameNotBlank("")) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("hostName cannot be blank or empty"); - assertThatThrownBy(() -> PgConnectionValidators.hostNameNotBlank(" ")) + .hasMessage("hostName cannot be blank"); + assertThatThrownBy(() -> PgUrlValidators.hostNameNotBlank(" ")) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("hostName cannot be blank or empty"); - assertThat(PgConnectionValidators.hostNameNotBlank("localhost")) + .hasMessage("hostName cannot be blank"); + assertThat(PgUrlValidators.hostNameNotBlank("localhost")) .isEqualTo("localhost"); } } diff --git a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/support/DatabaseAwareTestBase.java b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/support/DatabaseAwareTestBase.java index 7b64bb98..b0b592f5 100644 --- a/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/support/DatabaseAwareTestBase.java +++ b/pg-index-health-jdbc-connection/src/test/java/io/github/mfvanek/pg/support/DatabaseAwareTestBase.java @@ -12,8 +12,8 @@ import io.github.mfvanek.pg.connection.PgConnection; import io.github.mfvanek.pg.connection.PgConnectionImpl; -import io.github.mfvanek.pg.connection.PgHost; -import io.github.mfvanek.pg.connection.PgHostImpl; +import io.github.mfvanek.pg.host.PgHost; +import io.github.mfvanek.pg.host.PgHostImpl; import io.github.mfvanek.pg.testing.PostgreSqlContainerWrapper; import javax.annotation.Nonnull; diff --git a/pg-index-health-jdbc-connection/src/testFixtures/java/io/github/mfvanek/pg/support/PostgresVersionReader.java b/pg-index-health-jdbc-connection/src/testFixtures/java/io/github/mfvanek/pg/support/PostgresVersionReader.java index da596246..8df0d79c 100644 --- a/pg-index-health-jdbc-connection/src/testFixtures/java/io/github/mfvanek/pg/support/PostgresVersionReader.java +++ b/pg-index-health-jdbc-connection/src/testFixtures/java/io/github/mfvanek/pg/support/PostgresVersionReader.java @@ -10,7 +10,7 @@ package io.github.mfvanek.pg.support; -import io.github.mfvanek.pg.connection.PgSqlException; +import io.github.mfvanek.pg.exception.PgSqlException; import java.sql.Connection; import java.sql.ResultSet; diff --git a/pg-index-health-logger/src/main/java/io/github/mfvanek/pg/common/health/logger/AbstractHealthLogger.java b/pg-index-health-logger/src/main/java/io/github/mfvanek/pg/common/health/logger/AbstractHealthLogger.java index e5c42fe8..9a5fd84d 100644 --- a/pg-index-health-logger/src/main/java/io/github/mfvanek/pg/common/health/logger/AbstractHealthLogger.java +++ b/pg-index-health-logger/src/main/java/io/github/mfvanek/pg/common/health/logger/AbstractHealthLogger.java @@ -13,9 +13,9 @@ import io.github.mfvanek.pg.common.maintenance.DatabaseCheckOnCluster; import io.github.mfvanek.pg.common.maintenance.DatabaseChecks; import io.github.mfvanek.pg.common.maintenance.Diagnostic; -import io.github.mfvanek.pg.connection.ConnectionCredentials; import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; -import io.github.mfvanek.pg.connection.HighAvailabilityPgConnectionFactory; +import io.github.mfvanek.pg.connection.factory.ConnectionCredentials; +import io.github.mfvanek.pg.connection.factory.HighAvailabilityPgConnectionFactory; import io.github.mfvanek.pg.model.column.Column; import io.github.mfvanek.pg.model.column.ColumnWithSerialType; import io.github.mfvanek.pg.model.constraint.Constraint; diff --git a/pg-index-health-logger/src/main/java/io/github/mfvanek/pg/common/health/logger/KeyValueFileHealthLogger.java b/pg-index-health-logger/src/main/java/io/github/mfvanek/pg/common/health/logger/KeyValueFileHealthLogger.java index 7b2b3ee4..1f3dc150 100644 --- a/pg-index-health-logger/src/main/java/io/github/mfvanek/pg/common/health/logger/KeyValueFileHealthLogger.java +++ b/pg-index-health-logger/src/main/java/io/github/mfvanek/pg/common/health/logger/KeyValueFileHealthLogger.java @@ -11,9 +11,9 @@ package io.github.mfvanek.pg.common.health.logger; import io.github.mfvanek.pg.common.maintenance.DatabaseChecks; -import io.github.mfvanek.pg.connection.ConnectionCredentials; import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; -import io.github.mfvanek.pg.connection.HighAvailabilityPgConnectionFactory; +import io.github.mfvanek.pg.connection.factory.ConnectionCredentials; +import io.github.mfvanek.pg.connection.factory.HighAvailabilityPgConnectionFactory; import io.github.mfvanek.pg.utils.ClockHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/pg-index-health-logger/src/main/java/io/github/mfvanek/pg/common/health/logger/StandardHealthLogger.java b/pg-index-health-logger/src/main/java/io/github/mfvanek/pg/common/health/logger/StandardHealthLogger.java index 9c2aff77..59401876 100644 --- a/pg-index-health-logger/src/main/java/io/github/mfvanek/pg/common/health/logger/StandardHealthLogger.java +++ b/pg-index-health-logger/src/main/java/io/github/mfvanek/pg/common/health/logger/StandardHealthLogger.java @@ -11,9 +11,9 @@ package io.github.mfvanek.pg.common.health.logger; import io.github.mfvanek.pg.common.maintenance.DatabaseChecks; -import io.github.mfvanek.pg.connection.ConnectionCredentials; import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; -import io.github.mfvanek.pg.connection.HighAvailabilityPgConnectionFactory; +import io.github.mfvanek.pg.connection.factory.ConnectionCredentials; +import io.github.mfvanek.pg.connection.factory.HighAvailabilityPgConnectionFactory; import java.util.function.Function; import javax.annotation.Nonnull; diff --git a/pg-index-health-logger/src/test/java/io/github/mfvanek/pg/common/health/logger/HealthLoggerTestBase.java b/pg-index-health-logger/src/test/java/io/github/mfvanek/pg/common/health/logger/HealthLoggerTestBase.java index b1db3753..6c8f73bf 100644 --- a/pg-index-health-logger/src/test/java/io/github/mfvanek/pg/common/health/logger/HealthLoggerTestBase.java +++ b/pg-index-health-logger/src/test/java/io/github/mfvanek/pg/common/health/logger/HealthLoggerTestBase.java @@ -11,10 +11,10 @@ package io.github.mfvanek.pg.common.health.logger; import io.github.mfvanek.pg.common.maintenance.Diagnostic; -import io.github.mfvanek.pg.connection.HighAvailabilityPgConnectionFactory; -import io.github.mfvanek.pg.connection.HighAvailabilityPgConnectionFactoryImpl; -import io.github.mfvanek.pg.connection.PgConnectionFactoryImpl; import io.github.mfvanek.pg.connection.PrimaryHostDeterminerImpl; +import io.github.mfvanek.pg.connection.factory.HighAvailabilityPgConnectionFactory; +import io.github.mfvanek.pg.connection.factory.HighAvailabilityPgConnectionFactoryImpl; +import io.github.mfvanek.pg.connection.factory.PgConnectionFactoryImpl; import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.support.DatabaseConfigurer; import io.github.mfvanek.pg.support.StatisticsAwareTestBase; diff --git a/pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/PostgreSqlClusterWrapper.java b/pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/PostgreSqlClusterWrapper.java index 66370f43..ebf10781 100644 --- a/pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/PostgreSqlClusterWrapper.java +++ b/pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/PostgreSqlClusterWrapper.java @@ -10,7 +10,7 @@ package io.github.mfvanek.pg.testing; -import io.github.mfvanek.pg.connection.PgUrlParser; +import io.github.mfvanek.pg.host.PgUrlParser; import io.github.mfvanek.pg.testing.annotations.ExcludeFromJacocoGeneratedReport; import io.github.mfvanek.pg.units.MemoryUnit; import org.apache.commons.dbcp2.BasicDataSource; diff --git a/pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/PostgresBitnamiRepmgrContainer.java b/pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/PostgresBitnamiRepmgrContainer.java index c5755eee..14e52852 100644 --- a/pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/PostgresBitnamiRepmgrContainer.java +++ b/pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/PostgresBitnamiRepmgrContainer.java @@ -10,7 +10,7 @@ package io.github.mfvanek.pg.testing; -import io.github.mfvanek.pg.connection.PgUrlParser; +import io.github.mfvanek.pg.host.PgUrlParser; import org.testcontainers.containers.JdbcDatabaseContainer; import org.testcontainers.utility.DockerImageName; diff --git a/pg-index-health/src/main/java/io/github/mfvanek/pg/checks/cluster/AbstractCheckOnCluster.java b/pg-index-health/src/main/java/io/github/mfvanek/pg/checks/cluster/AbstractCheckOnCluster.java index 9f113ad8..748ed97b 100644 --- a/pg-index-health/src/main/java/io/github/mfvanek/pg/checks/cluster/AbstractCheckOnCluster.java +++ b/pg-index-health/src/main/java/io/github/mfvanek/pg/checks/cluster/AbstractCheckOnCluster.java @@ -15,7 +15,7 @@ import io.github.mfvanek.pg.common.maintenance.Diagnostic; import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; import io.github.mfvanek.pg.connection.PgConnection; -import io.github.mfvanek.pg.connection.PgHost; +import io.github.mfvanek.pg.host.PgHost; import io.github.mfvanek.pg.model.context.PgContext; import io.github.mfvanek.pg.model.dbobject.DbObject; import org.slf4j.Logger; diff --git a/pg-index-health/src/main/java/io/github/mfvanek/pg/checks/cluster/UnusedIndexesCheckOnCluster.java b/pg-index-health/src/main/java/io/github/mfvanek/pg/checks/cluster/UnusedIndexesCheckOnCluster.java index 71d0fef1..a01f5d47 100644 --- a/pg-index-health/src/main/java/io/github/mfvanek/pg/checks/cluster/UnusedIndexesCheckOnCluster.java +++ b/pg-index-health/src/main/java/io/github/mfvanek/pg/checks/cluster/UnusedIndexesCheckOnCluster.java @@ -13,7 +13,7 @@ import io.github.mfvanek.pg.checks.host.UnusedIndexesCheckOnHost; import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; import io.github.mfvanek.pg.connection.PgConnection; -import io.github.mfvanek.pg.connection.PgHost; +import io.github.mfvanek.pg.host.PgHost; import io.github.mfvanek.pg.model.index.UnusedIndex; import io.github.mfvanek.pg.statistics.maintenance.StatisticsMaintenanceOnHost; import io.github.mfvanek.pg.statistics.maintenance.StatisticsMaintenanceOnHostImpl; diff --git a/pg-index-health/src/main/java/io/github/mfvanek/pg/common/management/DatabaseManagementImpl.java b/pg-index-health/src/main/java/io/github/mfvanek/pg/common/management/DatabaseManagementImpl.java index 4ddf0177..2a423474 100644 --- a/pg-index-health/src/main/java/io/github/mfvanek/pg/common/management/DatabaseManagementImpl.java +++ b/pg-index-health/src/main/java/io/github/mfvanek/pg/common/management/DatabaseManagementImpl.java @@ -12,7 +12,7 @@ import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; import io.github.mfvanek.pg.connection.PgConnection; -import io.github.mfvanek.pg.connection.PgHost; +import io.github.mfvanek.pg.host.PgHost; import io.github.mfvanek.pg.settings.PgParam; import io.github.mfvanek.pg.settings.ServerSpecification; import io.github.mfvanek.pg.settings.maintenance.ConfigurationMaintenanceOnHost; diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/common/management/DatabaseManagementImplUnitTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/common/management/DatabaseManagementImplUnitTest.java index 225898f8..50317314 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/common/management/DatabaseManagementImplUnitTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/common/management/DatabaseManagementImplUnitTest.java @@ -13,7 +13,7 @@ import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; import io.github.mfvanek.pg.connection.PgConnection; import io.github.mfvanek.pg.connection.PgConnectionImpl; -import io.github.mfvanek.pg.connection.PgHostImpl; +import io.github.mfvanek.pg.host.PgHostImpl; import io.github.mfvanek.pg.settings.maintenance.ConfigurationMaintenanceOnHostImpl; import io.github.mfvanek.pg.statistics.maintenance.StatisticsMaintenanceOnHost; import org.junit.jupiter.api.Tag; diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/e2e/PgConnectionAwareCluster.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/e2e/PgConnectionAwareCluster.java index b5608977..b65bd86b 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/e2e/PgConnectionAwareCluster.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/e2e/PgConnectionAwareCluster.java @@ -12,7 +12,7 @@ import io.github.mfvanek.pg.connection.PgConnection; import io.github.mfvanek.pg.connection.PgConnectionImpl; -import io.github.mfvanek.pg.connection.PgHostImpl; +import io.github.mfvanek.pg.host.PgHostImpl; import io.github.mfvanek.pg.testing.PostgreSqlClusterWrapper; import java.time.Duration; diff --git a/spring-boot-integration/pg-index-health-test-starter/src/main/java/io/github/mfvanek/pg/spring/DatabaseStructureHealthAutoConfiguration.java b/spring-boot-integration/pg-index-health-test-starter/src/main/java/io/github/mfvanek/pg/spring/DatabaseStructureHealthAutoConfiguration.java index ba92f04d..94661501 100644 --- a/spring-boot-integration/pg-index-health-test-starter/src/main/java/io/github/mfvanek/pg/spring/DatabaseStructureHealthAutoConfiguration.java +++ b/spring-boot-integration/pg-index-health-test-starter/src/main/java/io/github/mfvanek/pg/spring/DatabaseStructureHealthAutoConfiguration.java @@ -12,9 +12,9 @@ import io.github.mfvanek.pg.connection.PgConnection; import io.github.mfvanek.pg.connection.PgConnectionImpl; -import io.github.mfvanek.pg.connection.PgHost; -import io.github.mfvanek.pg.connection.PgHostImpl; -import io.github.mfvanek.pg.connection.PgSqlException; +import io.github.mfvanek.pg.exception.PgSqlException; +import io.github.mfvanek.pg.host.PgHost; +import io.github.mfvanek.pg.host.PgHostImpl; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.AutoConfiguration; diff --git a/spring-boot-integration/pg-index-health-test-starter/src/test/java/io/github/mfvanek/pg/spring/DatabaseStructureHealthAutoConfigurationTest.java b/spring-boot-integration/pg-index-health-test-starter/src/test/java/io/github/mfvanek/pg/spring/DatabaseStructureHealthAutoConfigurationTest.java index 0e4595c7..4e89a810 100644 --- a/spring-boot-integration/pg-index-health-test-starter/src/test/java/io/github/mfvanek/pg/spring/DatabaseStructureHealthAutoConfigurationTest.java +++ b/spring-boot-integration/pg-index-health-test-starter/src/test/java/io/github/mfvanek/pg/spring/DatabaseStructureHealthAutoConfigurationTest.java @@ -11,7 +11,7 @@ package io.github.mfvanek.pg.spring; import io.github.mfvanek.pg.connection.PgConnection; -import io.github.mfvanek.pg.connection.PgHostImpl; +import io.github.mfvanek.pg.host.PgHostImpl; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.boot.test.context.runner.ApplicationContextRunner; @@ -142,7 +142,7 @@ void withDataSourceAndExceptionWhileObtainingUrlFromMetadata() throws SQLExcepti .isInstanceOf(IllegalStateException.class) .hasMessage("Unstarted application context org.springframework.boot.test.context.assertj.AssertableApplicationContext[" + "startupFailure=org.springframework.beans.factory.BeanCreationException] failed to start") - .hasStackTraceContaining("Factory method 'pgConnection' threw exception; nested exception is io.github.mfvanek.pg.connection.PgSqlException"); + .hasStackTraceContaining("Factory method 'pgConnection' threw exception; nested exception is io.github.mfvanek.pg.exception.PgSqlException"); } }