From cfb8062894769470608f514871e6fd64630a20a5 Mon Sep 17 00:00:00 2001 From: Alex Maltsev Date: Fri, 26 Apr 2024 16:53:51 +0300 Subject: [PATCH] Renamed everything with `jdbc` prefix to use more generic `database` prefix, since we don't use jdbc anymore. Removed unused provider class field from DatabaseType enum. --- docs/config-app.md | 12 ++--- .../server/settings/ApplicationSettings.java | 2 +- ....java => DatabaseApplicationSettings.java} | 41 ++++++++-------- ...va => DatabaseStoredDataResultMapper.java} | 9 ++-- ...> DatabaseStoredResponseResultMapper.java} | 4 +- ...va => DatabasePeriodicRefreshService.java} | 44 ++++++++--------- .../spring/config/SettingsConfiguration.java | 48 +++++++++---------- .../database/DatabaseConfiguration.java | 30 ++++++------ .../config/database/model/DatabaseType.java | 5 +- .../BasicDatabaseClient.java} | 12 ++--- .../CircuitBreakerSecuredDatabaseClient.java} | 31 ++++++------ .../DatabaseClient.java} | 6 +-- ...a => DatabaseApplicationSettingsTest.java} | 30 ++++++------ ...> DatabaseStoredDataResultMapperTest.java} | 32 ++++++------- ...tabaseStoredResponseResultMapperTest.java} | 12 ++--- ...> DatabasePeriodicRefreshServiceTest.java} | 24 +++++----- .../BasicDatabaseClientTest.java} | 14 +++--- ...cuitBreakerSecuredDatabaseClientTest.java} | 22 ++++----- 18 files changed, 190 insertions(+), 188 deletions(-) rename src/main/java/org/prebid/server/settings/{JdbcApplicationSettings.java => DatabaseApplicationSettings.java} (85%) rename src/main/java/org/prebid/server/settings/helper/{JdbcStoredDataResultMapper.java => DatabaseStoredDataResultMapper.java} (96%) rename src/main/java/org/prebid/server/settings/helper/{JdbcStoredResponseResultMapper.java => DatabaseStoredResponseResultMapper.java} (95%) rename src/main/java/org/prebid/server/settings/service/{JdbcPeriodicRefreshService.java => DatabasePeriodicRefreshService.java} (83%) rename src/main/java/org/prebid/server/vertx/{jdbc/BasicJdbcClient.java => database/BasicDatabaseClient.java} (89%) rename src/main/java/org/prebid/server/vertx/{jdbc/CircuitBreakerSecuredJdbcClient.java => database/CircuitBreakerSecuredDatabaseClient.java} (65%) rename src/main/java/org/prebid/server/vertx/{jdbc/JdbcClient.java => database/DatabaseClient.java} (77%) rename src/test/java/org/prebid/server/settings/{JdbcApplicationSettingsTest.java => DatabaseApplicationSettingsTest.java} (90%) rename src/test/java/org/prebid/server/settings/helper/{JdbcStoredDataResultMapperTest.java => DatabaseStoredDataResultMapperTest.java} (89%) rename src/test/java/org/prebid/server/settings/helper/{JdbcStoredResponseResultMapperTest.java => DatabaseStoredResponseResultMapperTest.java} (86%) rename src/test/java/org/prebid/server/settings/service/{JdbcPeriodicRefreshServiceTest.java => DatabasePeriodicRefreshServiceTest.java} (85%) rename src/test/java/org/prebid/server/vertx/{jdbc/BasicJdbcClientTest.java => database/BasicDatabaseClientTest.java} (96%) rename src/test/java/org/prebid/server/vertx/{jdbc/CircuitBreakerSecuredJdbcClientTest.java => database/CircuitBreakerSecuredDatabaseClientTest.java} (92%) diff --git a/docs/config-app.md b/docs/config-app.md index de902f6240e..ee6bf32dbe3 100644 --- a/docs/config-app.md +++ b/docs/config-app.md @@ -346,14 +346,14 @@ available: `/cache/invalidate?account={accountId}` which remove account from the - `settings.in-memory-cache.http-update.amp-endpoint` - the url to fetch AMP stored request updates. - `settings.in-memory-cache.http-update.refresh-rate` - refresh period in ms for stored request updates. - `settings.in-memory-cache.http-update.timeout` - timeout for obtaining stored request updates. -- `settings.in-memory-cache.jdbc-update.init-query` - initial query for fetching all stored requests at the startup. -- `settings.in-memory-cache.jdbc-update.update-query` - a query for periodical update of stored requests, that should +- `settings.in-memory-cache.database-update.init-query` - initial query for fetching all stored requests at the startup. +- `settings.in-memory-cache.database-update.update-query` - a query for periodical update of stored requests, that should contain 'WHERE last_updated > ?' to fetch only the records that were updated since previous check. -- `settings.in-memory-cache.jdbc-update.amp-init-query` - initial query for fetching all AMP stored requests at the startup. -- `settings.in-memory-cache.jdbc-update.amp-update-query` - a query for periodical update of AMP stored requests, that should +- `settings.in-memory-cache.database-update.amp-init-query` - initial query for fetching all AMP stored requests at the startup. +- `settings.in-memory-cache.database-update.amp-update-query` - a query for periodical update of AMP stored requests, that should contain 'WHERE last_updated > ?' to fetch only the records that were updated since previous check. -- `settings.in-memory-cache.jdbc-update.refresh-rate` - refresh period in ms for stored request updates. -- `settings.in-memory-cache.jdbc-update.timeout` - timeout for obtaining stored request updates. +- `settings.in-memory-cache.database-update.refresh-rate` - refresh period in ms for stored request updates. +- `settings.in-memory-cache.database-update.timeout` - timeout for obtaining stored request updates. For targeting available next options: - `settings.targeting.truncate-attr-chars` - set the max length for names of targeting keywords (0 means no truncation). diff --git a/src/main/java/org/prebid/server/settings/ApplicationSettings.java b/src/main/java/org/prebid/server/settings/ApplicationSettings.java index 8a010991b2f..da414bef279 100644 --- a/src/main/java/org/prebid/server/settings/ApplicationSettings.java +++ b/src/main/java/org/prebid/server/settings/ApplicationSettings.java @@ -14,7 +14,7 @@ * stored requests and imps) from the source. * * @see FileApplicationSettings - * @see JdbcApplicationSettings + * @see DatabaseApplicationSettings * @see HttpApplicationSettings * @see CachingApplicationSettings * @see CompositeApplicationSettings diff --git a/src/main/java/org/prebid/server/settings/JdbcApplicationSettings.java b/src/main/java/org/prebid/server/settings/DatabaseApplicationSettings.java similarity index 85% rename from src/main/java/org/prebid/server/settings/JdbcApplicationSettings.java rename to src/main/java/org/prebid/server/settings/DatabaseApplicationSettings.java index 6dd9f507ffa..9dad7f6a28b 100644 --- a/src/main/java/org/prebid/server/settings/JdbcApplicationSettings.java +++ b/src/main/java/org/prebid/server/settings/DatabaseApplicationSettings.java @@ -10,14 +10,15 @@ import org.prebid.server.execution.Timeout; import org.prebid.server.json.DecodeException; import org.prebid.server.json.JacksonMapper; -import org.prebid.server.settings.helper.JdbcStoredDataResultMapper; -import org.prebid.server.settings.helper.JdbcStoredResponseResultMapper; +import org.prebid.server.settings.helper.DatabaseStoredDataResultMapper; +import org.prebid.server.settings.helper.DatabaseStoredResponseResultMapper; import org.prebid.server.settings.helper.ParametrizedQueryHelper; import org.prebid.server.settings.model.Account; import org.prebid.server.settings.model.StoredDataResult; import org.prebid.server.settings.model.StoredResponseDataResult; import org.prebid.server.util.ObjectUtil; -import org.prebid.server.vertx.jdbc.JdbcClient; +import org.prebid.server.vertx.database.CircuitBreakerSecuredDatabaseClient; +import org.prebid.server.vertx.database.DatabaseClient; import java.util.ArrayList; import java.util.Collections; @@ -33,12 +34,12 @@ *

* Reads an application settings from the database source. *

- * In order to enable caching and reduce latency for read operations {@link JdbcApplicationSettings} + * In order to enable caching and reduce latency for read operations {@link DatabaseApplicationSettings} * can be decorated by {@link CachingApplicationSettings}. */ -public class JdbcApplicationSettings implements ApplicationSettings { +public class DatabaseApplicationSettings implements ApplicationSettings { - private final JdbcClient jdbcClient; + private final DatabaseClient databaseClient; private final JacksonMapper mapper; private final ParametrizedQueryHelper parametrizedQueryHelper; @@ -81,15 +82,15 @@ public class JdbcApplicationSettings implements ApplicationSettings { */ private final String selectStoredResponsesQuery; - public JdbcApplicationSettings(JdbcClient jdbcClient, - JacksonMapper mapper, - ParametrizedQueryHelper parametrizedQueryHelper, - String selectAccountQuery, - String selectStoredRequestsQuery, - String selectAmpStoredRequestsQuery, - String selectStoredResponsesQuery) { + public DatabaseApplicationSettings(DatabaseClient databaseClient, + JacksonMapper mapper, + ParametrizedQueryHelper parametrizedQueryHelper, + String selectAccountQuery, + String selectStoredRequestsQuery, + String selectAmpStoredRequestsQuery, + String selectStoredResponsesQuery) { - this.jdbcClient = Objects.requireNonNull(jdbcClient); + this.databaseClient = Objects.requireNonNull(databaseClient); this.mapper = Objects.requireNonNull(mapper); this.parametrizedQueryHelper = Objects.requireNonNull(parametrizedQueryHelper); this.selectAccountQuery = parametrizedQueryHelper.replaceAccountIdPlaceholder( @@ -105,7 +106,7 @@ public JdbcApplicationSettings(JdbcClient jdbcClient, */ @Override public Future getAccountById(String accountId, Timeout timeout) { - return jdbcClient.executeQuery( + return databaseClient.executeQuery( selectAccountQuery, Collections.singletonList(accountId), result -> mapToModelOrError(result, this::toAccount), @@ -122,7 +123,7 @@ public Future> getCategories(String primaryAdServer, String * Transforms the first row of {@link RowSet} to required object or returns null. *

* Note: mapper should never throws exception in case of using - * {@link org.prebid.server.vertx.jdbc.CircuitBreakerSecuredJdbcClient}. + * {@link CircuitBreakerSecuredDatabaseClient}. */ private T mapToModelOrError(RowSet rowSet, Function mapper) { final RowIterator rowIterator = rowSet != null ? rowSet.iterator() : null; @@ -197,8 +198,8 @@ public Future getStoredResponses(Set responseI IntStream.rangeClosed(1, responseIdPlaceholderCount) .forEach(i -> idsQueryParameters.addAll(responseIds)); - return jdbcClient.executeQuery(queryResolvedWithParameters, idsQueryParameters, - result -> JdbcStoredResponseResultMapper.map(result, responseIds), timeout); + return databaseClient.executeQuery(queryResolvedWithParameters, idsQueryParameters, + result -> DatabaseStoredResponseResultMapper.map(result, responseIds), timeout); } /** @@ -223,8 +224,8 @@ private Future fetchStoredData(String query, String accountId, requestIds.size(), impIds.size()); - future = jdbcClient.executeQuery(parametrizedQuery, idsQueryParameters, - result -> JdbcStoredDataResultMapper.map(result, accountId, requestIds, impIds), + future = databaseClient.executeQuery(parametrizedQuery, idsQueryParameters, + result -> DatabaseStoredDataResultMapper.map(result, accountId, requestIds, impIds), timeout); } diff --git a/src/main/java/org/prebid/server/settings/helper/JdbcStoredDataResultMapper.java b/src/main/java/org/prebid/server/settings/helper/DatabaseStoredDataResultMapper.java similarity index 96% rename from src/main/java/org/prebid/server/settings/helper/JdbcStoredDataResultMapper.java rename to src/main/java/org/prebid/server/settings/helper/DatabaseStoredDataResultMapper.java index b50cf8895dc..00853194e65 100644 --- a/src/main/java/org/prebid/server/settings/helper/JdbcStoredDataResultMapper.java +++ b/src/main/java/org/prebid/server/settings/helper/DatabaseStoredDataResultMapper.java @@ -10,6 +10,7 @@ import org.prebid.server.settings.model.StoredDataType; import org.prebid.server.settings.model.StoredItem; import org.prebid.server.util.ObjectUtil; +import org.prebid.server.vertx.database.CircuitBreakerSecuredDatabaseClient; import java.util.ArrayList; import java.util.Collections; @@ -22,11 +23,11 @@ /** * Utility class for mapping {@link RowSet} to {@link StoredDataResult}. */ -public class JdbcStoredDataResultMapper { +public class DatabaseStoredDataResultMapper { - private static final Logger logger = LoggerFactory.getLogger(JdbcStoredDataResultMapper.class); + private static final Logger logger = LoggerFactory.getLogger(DatabaseStoredDataResultMapper.class); - private JdbcStoredDataResultMapper() { + private DatabaseStoredDataResultMapper() { } /** @@ -39,7 +40,7 @@ private JdbcStoredDataResultMapper() { * @return - a {@link StoredDataResult} object *

* Note: mapper should never throws exception in case of using - * {@link org.prebid.server.vertx.jdbc.CircuitBreakerSecuredJdbcClient}. + * {@link CircuitBreakerSecuredDatabaseClient}. */ public static StoredDataResult map(RowSet rowSet, String accountId, diff --git a/src/main/java/org/prebid/server/settings/helper/JdbcStoredResponseResultMapper.java b/src/main/java/org/prebid/server/settings/helper/DatabaseStoredResponseResultMapper.java similarity index 95% rename from src/main/java/org/prebid/server/settings/helper/JdbcStoredResponseResultMapper.java rename to src/main/java/org/prebid/server/settings/helper/DatabaseStoredResponseResultMapper.java index a86514cfc01..99896d72911 100644 --- a/src/main/java/org/prebid/server/settings/helper/JdbcStoredResponseResultMapper.java +++ b/src/main/java/org/prebid/server/settings/helper/DatabaseStoredResponseResultMapper.java @@ -13,9 +13,9 @@ import java.util.Map; import java.util.Set; -public class JdbcStoredResponseResultMapper { +public class DatabaseStoredResponseResultMapper { - private JdbcStoredResponseResultMapper() { + private DatabaseStoredResponseResultMapper() { } public static StoredResponseDataResult map(RowSet rowSet, Set responseIds) { diff --git a/src/main/java/org/prebid/server/settings/service/JdbcPeriodicRefreshService.java b/src/main/java/org/prebid/server/settings/service/DatabasePeriodicRefreshService.java similarity index 83% rename from src/main/java/org/prebid/server/settings/service/JdbcPeriodicRefreshService.java rename to src/main/java/org/prebid/server/settings/service/DatabasePeriodicRefreshService.java index 13e76bc9c89..cc4b80ad870 100644 --- a/src/main/java/org/prebid/server/settings/service/JdbcPeriodicRefreshService.java +++ b/src/main/java/org/prebid/server/settings/service/DatabasePeriodicRefreshService.java @@ -11,10 +11,10 @@ import org.prebid.server.metric.MetricName; import org.prebid.server.metric.Metrics; import org.prebid.server.settings.CacheNotificationListener; -import org.prebid.server.settings.helper.JdbcStoredDataResultMapper; +import org.prebid.server.settings.helper.DatabaseStoredDataResultMapper; import org.prebid.server.settings.model.StoredDataResult; import org.prebid.server.vertx.Initializable; -import org.prebid.server.vertx.jdbc.JdbcClient; +import org.prebid.server.vertx.database.DatabaseClient; import java.time.Clock; import java.time.Instant; @@ -42,9 +42,9 @@ * If data is not empty, depending on TYPE, it should be put to corresponding map with ID as a key and DATA as value. *

*/ -public class JdbcPeriodicRefreshService implements Initializable { +public class DatabasePeriodicRefreshService implements Initializable { - private static final Logger logger = LoggerFactory.getLogger(JdbcPeriodicRefreshService.class); + private static final Logger logger = LoggerFactory.getLogger(DatabasePeriodicRefreshService.class); /** * Example of initialize query: @@ -71,24 +71,24 @@ public class JdbcPeriodicRefreshService implements Initializable { private final MetricName cacheType; private final CacheNotificationListener cacheNotificationListener; private final Vertx vertx; - private final JdbcClient jdbcClient; + private final DatabaseClient databaseClient; private final TimeoutFactory timeoutFactory; private final Metrics metrics; private final Clock clock; private Instant lastUpdate; - public JdbcPeriodicRefreshService(String initQuery, - String updateQuery, - long refreshPeriod, - long timeout, - MetricName cacheType, - CacheNotificationListener cacheNotificationListener, - Vertx vertx, - JdbcClient jdbcClient, - TimeoutFactory timeoutFactory, - Metrics metrics, - Clock clock) { + public DatabasePeriodicRefreshService(String initQuery, + String updateQuery, + long refreshPeriod, + long timeout, + MetricName cacheType, + CacheNotificationListener cacheNotificationListener, + Vertx vertx, + DatabaseClient databaseClient, + TimeoutFactory timeoutFactory, + Metrics metrics, + Clock clock) { this.initQuery = Objects.requireNonNull(StringUtils.stripToNull(initQuery)); this.updateQuery = Objects.requireNonNull(StringUtils.stripToNull(updateQuery)); @@ -97,7 +97,7 @@ public JdbcPeriodicRefreshService(String initQuery, this.cacheType = Objects.requireNonNull(cacheType); this.cacheNotificationListener = Objects.requireNonNull(cacheNotificationListener); this.vertx = Objects.requireNonNull(vertx); - this.jdbcClient = Objects.requireNonNull(jdbcClient); + this.databaseClient = Objects.requireNonNull(databaseClient); this.timeoutFactory = Objects.requireNonNull(timeoutFactory); this.metrics = Objects.requireNonNull(metrics); this.clock = Objects.requireNonNull(clock); @@ -115,10 +115,10 @@ public void initialize(Promise initializePromise) { private void getAll() { final long startTime = clock.millis(); - jdbcClient.executeQuery( + databaseClient.executeQuery( initQuery, Collections.emptyList(), - JdbcStoredDataResultMapper::map, + DatabaseStoredDataResultMapper::map, createTimeout()) .map(storedDataResult -> handleResult(storedDataResult, Instant.now(clock), startTime, MetricName.initialize)) @@ -139,7 +139,7 @@ private Void handleResult(StoredDataResult storedDataResult, } private Future handleFailure(Throwable exception, long startTime, MetricName refreshType) { - logger.warn("Error occurred while request to jdbc refresh service", exception); + logger.warn("Error occurred while request to database refresh service", exception); metrics.updateSettingsCacheRefreshTime(cacheType, refreshType, clock.millis() - startTime); metrics.updateSettingsCacheRefreshErrorMetric(cacheType, refreshType); @@ -151,10 +151,10 @@ private void refresh() { final Instant updateTime = Instant.now(clock); final long startTime = clock.millis(); - jdbcClient.executeQuery( + databaseClient.executeQuery( updateQuery, Collections.singletonList(Date.from(lastUpdate)), - JdbcStoredDataResultMapper::map, + DatabaseStoredDataResultMapper::map, createTimeout()) .map(storedDataResult -> handleResult(invalidate(storedDataResult), updateTime, startTime, MetricName.update)) diff --git a/src/main/java/org/prebid/server/spring/config/SettingsConfiguration.java b/src/main/java/org/prebid/server/spring/config/SettingsConfiguration.java index 4929a67fca4..77a5db343a3 100644 --- a/src/main/java/org/prebid/server/spring/config/SettingsConfiguration.java +++ b/src/main/java/org/prebid/server/spring/config/SettingsConfiguration.java @@ -19,14 +19,14 @@ import org.prebid.server.settings.EnrichingApplicationSettings; import org.prebid.server.settings.FileApplicationSettings; import org.prebid.server.settings.HttpApplicationSettings; -import org.prebid.server.settings.JdbcApplicationSettings; +import org.prebid.server.settings.DatabaseApplicationSettings; import org.prebid.server.settings.SettingsCache; import org.prebid.server.settings.helper.ParametrizedQueryHelper; import org.prebid.server.settings.service.HttpPeriodicRefreshService; -import org.prebid.server.settings.service.JdbcPeriodicRefreshService; +import org.prebid.server.settings.service.DatabasePeriodicRefreshService; import org.prebid.server.spring.config.database.DatabaseConfiguration; import org.prebid.server.vertx.httpclient.HttpClient; -import org.prebid.server.vertx.jdbc.JdbcClient; +import org.prebid.server.vertx.database.DatabaseClient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; @@ -73,17 +73,17 @@ FileApplicationSettings fileApplicationSettings( static class DatabaseSettingsConfiguration { @Bean - JdbcApplicationSettings jdbcApplicationSettings( + DatabaseApplicationSettings databaseApplicationSettings( @Value("${settings.database.account-query}") String accountQuery, @Value("${settings.database.stored-requests-query}") String storedRequestsQuery, @Value("${settings.database.amp-stored-requests-query}") String ampStoredRequestsQuery, @Value("${settings.database.stored-responses-query}") String storedResponsesQuery, ParametrizedQueryHelper parametrizedQueryHelper, - JdbcClient jdbcClient, + DatabaseClient databaseClient, JacksonMapper jacksonMapper) { - return new JdbcApplicationSettings( - jdbcClient, + return new DatabaseApplicationSettings( + databaseClient, jacksonMapper, parametrizedQueryHelper, accountQuery, @@ -151,21 +151,21 @@ public HttpPeriodicRefreshService ampHttpPeriodicRefreshService( @Configuration @ConditionalOnProperty( - prefix = "settings.in-memory-cache.jdbc-update", + prefix = "settings.in-memory-cache.database-update", name = {"refresh-rate", "timeout", "init-query", "update-query", "amp-init-query", "amp-update-query"}) - static class JdbcPeriodicRefreshServiceConfiguration { + static class DatabasePeriodicRefreshServiceConfiguration { - @Value("${settings.in-memory-cache.jdbc-update.refresh-rate}") + @Value("${settings.in-memory-cache.database-update.refresh-rate}") long refreshPeriod; - @Value("${settings.in-memory-cache.jdbc-update.timeout}") + @Value("${settings.in-memory-cache.database-update.timeout}") long timeout; @Autowired Vertx vertx; @Autowired - JdbcClient jdbcClient; + DatabaseClient databaseClient; @Autowired TimeoutFactory timeoutFactory; @@ -177,12 +177,12 @@ static class JdbcPeriodicRefreshServiceConfiguration { Clock clock; @Bean - public JdbcPeriodicRefreshService jdbcPeriodicRefreshService( + public DatabasePeriodicRefreshService databasePeriodicRefreshService( @Qualifier("settingsCache") SettingsCache settingsCache, - @Value("${settings.in-memory-cache.jdbc-update.init-query}") String initQuery, - @Value("${settings.in-memory-cache.jdbc-update.update-query}") String updateQuery) { + @Value("${settings.in-memory-cache.database-update.init-query}") String initQuery, + @Value("${settings.in-memory-cache.database-update.update-query}") String updateQuery) { - return new JdbcPeriodicRefreshService( + return new DatabasePeriodicRefreshService( initQuery, updateQuery, refreshPeriod, @@ -190,19 +190,19 @@ public JdbcPeriodicRefreshService jdbcPeriodicRefreshService( MetricName.stored_request, settingsCache, vertx, - jdbcClient, + databaseClient, timeoutFactory, metrics, clock); } @Bean - public JdbcPeriodicRefreshService ampJdbcPeriodicRefreshService( + public DatabasePeriodicRefreshService ampDatabasePeriodicRefreshService( @Qualifier("ampSettingsCache") SettingsCache ampSettingsCache, - @Value("${settings.in-memory-cache.jdbc-update.amp-init-query}") String ampInitQuery, - @Value("${settings.in-memory-cache.jdbc-update.amp-update-query}") String ampUpdateQuery) { + @Value("${settings.in-memory-cache.database-update.amp-init-query}") String ampInitQuery, + @Value("${settings.in-memory-cache.database-update.amp-update-query}") String ampUpdateQuery) { - return new JdbcPeriodicRefreshService( + return new DatabasePeriodicRefreshService( ampInitQuery, ampUpdateQuery, refreshPeriod, @@ -210,7 +210,7 @@ public JdbcPeriodicRefreshService ampJdbcPeriodicRefreshService( MetricName.amp_stored_request, ampSettingsCache, vertx, - jdbcClient, + databaseClient, timeoutFactory, metrics, clock); @@ -226,12 +226,12 @@ static class CompositeSettingsConfiguration { @Bean CompositeApplicationSettings compositeApplicationSettings( @Autowired(required = false) FileApplicationSettings fileApplicationSettings, - @Autowired(required = false) JdbcApplicationSettings jdbcApplicationSettings, + @Autowired(required = false) DatabaseApplicationSettings databaseApplicationSettings, @Autowired(required = false) HttpApplicationSettings httpApplicationSettings) { final List applicationSettingsList = Stream.of(fileApplicationSettings, - jdbcApplicationSettings, + databaseApplicationSettings, httpApplicationSettings) .filter(Objects::nonNull) .toList(); diff --git a/src/main/java/org/prebid/server/spring/config/database/DatabaseConfiguration.java b/src/main/java/org/prebid/server/spring/config/database/DatabaseConfiguration.java index ebbbd260af7..ba322b34707 100644 --- a/src/main/java/org/prebid/server/spring/config/database/DatabaseConfiguration.java +++ b/src/main/java/org/prebid/server/spring/config/database/DatabaseConfiguration.java @@ -16,8 +16,8 @@ import org.prebid.server.spring.config.database.properties.DatabaseConfigurationProperties; import org.prebid.server.spring.config.model.CircuitBreakerProperties; import org.prebid.server.vertx.ContextRunner; -import org.prebid.server.vertx.jdbc.BasicJdbcClient; -import org.prebid.server.vertx.jdbc.CircuitBreakerSecuredJdbcClient; +import org.prebid.server.vertx.database.BasicDatabaseClient; +import org.prebid.server.vertx.database.CircuitBreakerSecuredDatabaseClient; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -138,14 +138,14 @@ CircuitBreakerProperties databaseCircuitBreakerProperties() { @Bean @ConditionalOnProperty(prefix = "settings.database.circuit-breaker", name = "enabled", havingValue = "false", matchIfMissing = true) - BasicJdbcClient basicJdbcClient(Pool pool, Metrics metrics, Clock clock, ContextRunner contextRunner) { + BasicDatabaseClient basicDatabaseClient(Pool pool, Metrics metrics, Clock clock, ContextRunner contextRunner) { - return createBasicJdbcClient(pool, metrics, clock, contextRunner); + return createBasicDatabaseClient(pool, metrics, clock, contextRunner); } @Bean @ConditionalOnProperty(prefix = "settings.database.circuit-breaker", name = "enabled", havingValue = "true") - CircuitBreakerSecuredJdbcClient circuitBreakerSecuredAsyncDatabaseClient( + CircuitBreakerSecuredDatabaseClient circuitBreakerSecuredAsyncDatabaseClient( Vertx vertx, Pool pool, Metrics metrics, @@ -153,10 +153,10 @@ CircuitBreakerSecuredJdbcClient circuitBreakerSecuredAsyncDatabaseClient( ContextRunner contextRunner, @Qualifier("databaseCircuitBreakerProperties") CircuitBreakerProperties circuitBreakerProperties) { - final BasicJdbcClient jdbcClient = createBasicJdbcClient(pool, metrics, clock, contextRunner); - return new CircuitBreakerSecuredJdbcClient( + final BasicDatabaseClient databaseClient = createBasicDatabaseClient(pool, metrics, clock, contextRunner); + return new CircuitBreakerSecuredDatabaseClient( vertx, - jdbcClient, + databaseClient, metrics, circuitBreakerProperties.getOpeningThreshold(), circuitBreakerProperties.getOpeningIntervalMs(), @@ -164,15 +164,15 @@ CircuitBreakerSecuredJdbcClient circuitBreakerSecuredAsyncDatabaseClient( clock); } - private static BasicJdbcClient createBasicJdbcClient(Pool pool, - Metrics metrics, - Clock clock, - ContextRunner contextRunner) { + private static BasicDatabaseClient createBasicDatabaseClient(Pool pool, + Metrics metrics, + Clock clock, + ContextRunner contextRunner) { - final BasicJdbcClient basicJdbcClient = new BasicJdbcClient(pool, metrics, clock); + final BasicDatabaseClient basicDatabaseClient = new BasicDatabaseClient(pool, metrics, clock); - contextRunner.runBlocking(promise -> basicJdbcClient.initialize().onComplete(promise)); + contextRunner.runBlocking(promise -> basicDatabaseClient.initialize().onComplete(promise)); - return basicJdbcClient; + return basicDatabaseClient; } } diff --git a/src/main/java/org/prebid/server/spring/config/database/model/DatabaseType.java b/src/main/java/org/prebid/server/spring/config/database/model/DatabaseType.java index 8c94c1c0ced..d0121d71b0d 100644 --- a/src/main/java/org/prebid/server/spring/config/database/model/DatabaseType.java +++ b/src/main/java/org/prebid/server/spring/config/database/model/DatabaseType.java @@ -5,8 +5,7 @@ @AllArgsConstructor public enum DatabaseType { - postgres("org.postgresql.Driver"), - mysql("com.mysql.cj.jdbc.Driver"); + postgres, + mysql; - public final String jdbcDriver; } diff --git a/src/main/java/org/prebid/server/vertx/jdbc/BasicJdbcClient.java b/src/main/java/org/prebid/server/vertx/database/BasicDatabaseClient.java similarity index 89% rename from src/main/java/org/prebid/server/vertx/jdbc/BasicJdbcClient.java rename to src/main/java/org/prebid/server/vertx/database/BasicDatabaseClient.java index 6b6effa79a3..e5aa90aabb2 100644 --- a/src/main/java/org/prebid/server/vertx/jdbc/BasicJdbcClient.java +++ b/src/main/java/org/prebid/server/vertx/database/BasicDatabaseClient.java @@ -1,4 +1,4 @@ -package org.prebid.server.vertx.jdbc; +package org.prebid.server.vertx.database; import io.vertx.core.Future; import io.vertx.sqlclient.Pool; @@ -21,15 +21,15 @@ /** * Wrapper over {@link Pool} that supports setting query timeout in milliseconds. */ -public class BasicJdbcClient implements JdbcClient { +public class BasicDatabaseClient implements DatabaseClient { - private static final Logger logger = LoggerFactory.getLogger(BasicJdbcClient.class); + private static final Logger logger = LoggerFactory.getLogger(BasicDatabaseClient.class); private final Pool pool; private final Metrics metrics; private final Clock clock; - public BasicJdbcClient(Pool pool, Metrics metrics, Clock clock) { + public BasicDatabaseClient(Pool pool, Metrics metrics, Clock clock) { this.pool = Objects.requireNonNull(pool); this.metrics = Objects.requireNonNull(metrics); this.clock = Objects.requireNonNull(clock); @@ -43,7 +43,7 @@ public BasicJdbcClient(Pool pool, Metrics metrics, Clock clock) { */ public Future initialize() { return pool.getConnection() - .recover(BasicJdbcClient::logConnectionError) + .recover(BasicDatabaseClient::logConnectionError) .mapEmpty(); } @@ -60,7 +60,7 @@ public Future executeQuery(String query, final long startTime = clock.millis(); return pool.getConnection() - .recover(BasicJdbcClient::logConnectionError) + .recover(BasicDatabaseClient::logConnectionError) .compose(connection -> makeQuery(connection, query, params)) .timeout(remainingTimeout, TimeUnit.MILLISECONDS) .recover(this::handleFailure) diff --git a/src/main/java/org/prebid/server/vertx/jdbc/CircuitBreakerSecuredJdbcClient.java b/src/main/java/org/prebid/server/vertx/database/CircuitBreakerSecuredDatabaseClient.java similarity index 65% rename from src/main/java/org/prebid/server/vertx/jdbc/CircuitBreakerSecuredJdbcClient.java rename to src/main/java/org/prebid/server/vertx/database/CircuitBreakerSecuredDatabaseClient.java index f85fa351941..bb4fa7d09c1 100644 --- a/src/main/java/org/prebid/server/vertx/jdbc/CircuitBreakerSecuredJdbcClient.java +++ b/src/main/java/org/prebid/server/vertx/database/CircuitBreakerSecuredDatabaseClient.java @@ -1,4 +1,4 @@ -package org.prebid.server.vertx.jdbc; +package org.prebid.server.vertx.database; import io.vertx.core.Future; import io.vertx.core.Vertx; @@ -18,26 +18,26 @@ import java.util.function.Function; /** - * JDBC Client wrapped by {@link CircuitBreaker} to achieve robust operating. + * Database Client wrapped by {@link CircuitBreaker} to achieve robust operating. */ -public class CircuitBreakerSecuredJdbcClient implements JdbcClient { +public class CircuitBreakerSecuredDatabaseClient implements DatabaseClient { - private static final Logger logger = LoggerFactory.getLogger(CircuitBreakerSecuredJdbcClient.class); + private static final Logger logger = LoggerFactory.getLogger(CircuitBreakerSecuredDatabaseClient.class); private static final ConditionalLogger conditionalLogger = new ConditionalLogger(logger); private static final int LOG_PERIOD_SECONDS = 5; - private final JdbcClient jdbcClient; + private final DatabaseClient databaseClient; private final CircuitBreaker breaker; - public CircuitBreakerSecuredJdbcClient(Vertx vertx, - JdbcClient jdbcClient, - Metrics metrics, - int openingThreshold, - long openingIntervalMs, - long closingIntervalMs, - Clock clock) { + public CircuitBreakerSecuredDatabaseClient(Vertx vertx, + DatabaseClient databaseClient, + Metrics metrics, + int openingThreshold, + long openingIntervalMs, + long closingIntervalMs, + Clock clock) { - this.jdbcClient = Objects.requireNonNull(jdbcClient); + this.databaseClient = Objects.requireNonNull(databaseClient); breaker = new CircuitBreaker( "db_cb", @@ -52,7 +52,7 @@ public CircuitBreakerSecuredJdbcClient(Vertx vertx, metrics.createDatabaseCircuitBreakerGauge(breaker::isOpen); - logger.info("Initialized JDBC client with Circuit Breaker"); + logger.info("Initialized database client with Circuit Breaker"); } @Override @@ -61,7 +61,8 @@ public Future executeQuery(String query, Function, T> mapper, Timeout timeout) { - return breaker.execute(promise -> jdbcClient.executeQuery(query, params, mapper, timeout).onComplete(promise)); + return breaker.execute( + promise -> databaseClient.executeQuery(query, params, mapper, timeout).onComplete(promise)); } private void circuitOpened() { diff --git a/src/main/java/org/prebid/server/vertx/jdbc/JdbcClient.java b/src/main/java/org/prebid/server/vertx/database/DatabaseClient.java similarity index 77% rename from src/main/java/org/prebid/server/vertx/jdbc/JdbcClient.java rename to src/main/java/org/prebid/server/vertx/database/DatabaseClient.java index 3fc7754b038..87c9ada84c6 100644 --- a/src/main/java/org/prebid/server/vertx/jdbc/JdbcClient.java +++ b/src/main/java/org/prebid/server/vertx/database/DatabaseClient.java @@ -1,4 +1,4 @@ -package org.prebid.server.vertx.jdbc; +package org.prebid.server.vertx.database; import io.vertx.core.Future; import io.vertx.sqlclient.Row; @@ -9,10 +9,10 @@ import java.util.function.Function; /** - * Interface for asynchronous interaction with database over JDBC API. + * Interface for asynchronous interaction with database over database API. */ @FunctionalInterface -public interface JdbcClient { +public interface DatabaseClient { /** * Executes query with parameters and returns {@link Future} eventually holding result mapped to a model diff --git a/src/test/java/org/prebid/server/settings/JdbcApplicationSettingsTest.java b/src/test/java/org/prebid/server/settings/DatabaseApplicationSettingsTest.java similarity index 90% rename from src/test/java/org/prebid/server/settings/JdbcApplicationSettingsTest.java rename to src/test/java/org/prebid/server/settings/DatabaseApplicationSettingsTest.java index 1871046b5d6..15ef34417a6 100644 --- a/src/test/java/org/prebid/server/settings/JdbcApplicationSettingsTest.java +++ b/src/test/java/org/prebid/server/settings/DatabaseApplicationSettingsTest.java @@ -17,7 +17,7 @@ import org.prebid.server.settings.model.Account; import org.prebid.server.settings.model.StoredDataResult; import org.prebid.server.settings.model.StoredResponseDataResult; -import org.prebid.server.vertx.jdbc.JdbcClient; +import org.prebid.server.vertx.database.DatabaseClient; import java.time.Clock; import java.time.Instant; @@ -35,7 +35,7 @@ import static org.mockito.BDDMockito.given; @RunWith(VertxUnitRunner.class) -public class JdbcApplicationSettingsTest extends VertxTest { +public class DatabaseApplicationSettingsTest extends VertxTest { @Rule public final MockitoRule mockitoRule = MockitoJUnit.rule(); @@ -57,9 +57,9 @@ public class JdbcApplicationSettingsTest extends VertxTest { private ParametrizedQueryHelper parametrizedQueryHelper; @Mock - private JdbcClient jdbcClient; + private DatabaseClient databaseClient; - private JdbcApplicationSettings target; + private DatabaseApplicationSettings target; private Timeout timeout; @@ -67,8 +67,8 @@ public class JdbcApplicationSettingsTest extends VertxTest { public void setUp() { timeout = new TimeoutFactory(Clock.fixed(Instant.now(), ZoneId.systemDefault())).create(5000L); given(parametrizedQueryHelper.replaceAccountIdPlaceholder(SELECT_ACCOUNT_QUERY)).willReturn("query"); - target = new JdbcApplicationSettings( - jdbcClient, + target = new DatabaseApplicationSettings( + databaseClient, jacksonMapper, parametrizedQueryHelper, SELECT_ACCOUNT_QUERY, @@ -81,7 +81,7 @@ public void setUp() { public void getAccountByIdShouldReturnAccountWithAllFieldsPopulated() { // given final Account givenAccount = Account.builder().build(); - given(jdbcClient.executeQuery( + given(databaseClient.executeQuery( eq("query"), eq(List.of("1001")), any(), @@ -99,7 +99,7 @@ public void getAccountByIdShouldReturnAccountWithAllFieldsPopulated() { @Test public void getAccountByIdShouldFailIfAccountNotFound() { // given - given(jdbcClient.executeQuery( + given(databaseClient.executeQuery( eq("query"), eq(List.of("non-existing")), any(), @@ -124,7 +124,7 @@ public void getStoredDataShouldReturnExpectedResult() { Map.of("1", "value1", "2", "value2"), Map.of("4", "value4", "5", "value5"), emptyList()); - given(jdbcClient.executeQuery(eq("query"), eq(List.of("1", "2", "4", "5")), any(), eq(timeout))) + given(databaseClient.executeQuery(eq("query"), eq(List.of("1", "2", "4", "5")), any(), eq(timeout))) .willReturn(Future.succeededFuture(givenStoredDataResult)); // when @@ -146,7 +146,7 @@ public void getAmpStoredDataShouldReturnExpectedResult() { Map.of("1", "value1", "2", "value2"), Map.of(), emptyList()); - given(jdbcClient.executeQuery(eq("query"), eq(List.of("1", "2")), any(), eq(timeout))) + given(databaseClient.executeQuery(eq("query"), eq(List.of("1", "2")), any(), eq(timeout))) .willReturn(Future.succeededFuture(givenStoredDataResult)); // when @@ -168,7 +168,7 @@ public void getVideoStoredDataShouldReturnExpectedResult() { Map.of("1", "value1", "2", "value2"), Map.of("4", "value4", "5", "value5"), emptyList()); - given(jdbcClient.executeQuery(eq("query"), eq(List.of("1", "2", "4", "5")), any(), eq(timeout))) + given(databaseClient.executeQuery(eq("query"), eq(List.of("1", "2", "4", "5")), any(), eq(timeout))) .willReturn(Future.succeededFuture(givenStoredDataResult)); // when @@ -190,7 +190,7 @@ public void getStoredDataShouldReturnResultWithError() { Map.of("1", "value1"), Map.of(), List.of("No stored request found for id: 3")); - given(jdbcClient.executeQuery(eq("query"), eq(List.of("1", "3")), any(), eq(timeout))) + given(databaseClient.executeQuery(eq("query"), eq(List.of("1", "3")), any(), eq(timeout))) .willReturn(Future.succeededFuture(givenStoredDataResult)); // when @@ -212,7 +212,7 @@ public void getAmpStoredDataShouldReturnResultWithError() { Map.of("1", "value1"), Map.of(), List.of("No stored request found for id: 3")); - given(jdbcClient.executeQuery(eq("query"), eq(List.of("1", "3")), any(), eq(timeout))) + given(databaseClient.executeQuery(eq("query"), eq(List.of("1", "3")), any(), eq(timeout))) .willReturn(Future.succeededFuture(givenStoredDataResult)); // when @@ -234,7 +234,7 @@ public void getVideoStoredDataShouldReturnResultWithError() { Map.of("1", "value1"), Map.of(), List.of("No stored request found for id: 3")); - given(jdbcClient.executeQuery(eq("query"), eq(List.of("1", "3")), any(), eq(timeout))) + given(databaseClient.executeQuery(eq("query"), eq(List.of("1", "3")), any(), eq(timeout))) .willReturn(Future.succeededFuture(givenStoredDataResult)); // when @@ -255,7 +255,7 @@ public void getStoredResponseShouldReturnExpectedResult() { final StoredResponseDataResult givenStoredResponseResult = StoredResponseDataResult.of( Map.of("1", "response1"), List.of("No stored response found for id: 2")); - given(jdbcClient.executeQuery(eq("query"), eq(List.of("1", "2")), any(), eq(timeout))) + given(databaseClient.executeQuery(eq("query"), eq(List.of("1", "2")), any(), eq(timeout))) .willReturn(Future.succeededFuture(givenStoredResponseResult)); // when diff --git a/src/test/java/org/prebid/server/settings/helper/JdbcStoredDataResultMapperTest.java b/src/test/java/org/prebid/server/settings/helper/DatabaseStoredDataResultMapperTest.java similarity index 89% rename from src/test/java/org/prebid/server/settings/helper/JdbcStoredDataResultMapperTest.java rename to src/test/java/org/prebid/server/settings/helper/DatabaseStoredDataResultMapperTest.java index 1fc17aba849..88dab8b8267 100644 --- a/src/test/java/org/prebid/server/settings/helper/JdbcStoredDataResultMapperTest.java +++ b/src/test/java/org/prebid/server/settings/helper/DatabaseStoredDataResultMapperTest.java @@ -24,7 +24,7 @@ import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; -public class JdbcStoredDataResultMapperTest { +public class DatabaseStoredDataResultMapperTest { @Rule public final MockitoRule mockitoRule = MockitoJUnit.rule(); @@ -38,7 +38,7 @@ public void mapShouldReturnEmptyStoredResultWithErrorWhenResultSetHasEmptyResult givenRowSet(); // when - final StoredDataResult result = JdbcStoredDataResultMapper.map(rowSet, null, emptySet(), emptySet()); + final StoredDataResult result = DatabaseStoredDataResultMapper.map(rowSet, null, emptySet(), emptySet()); // then assertThat(result.getStoredIdToRequest()).isEmpty(); @@ -53,7 +53,7 @@ public void mapShouldReturnEmptyStoredResultWithErrorWhenResultSetHasEmptyResult givenRowSet(); // when - final StoredDataResult result = JdbcStoredDataResultMapper.map( + final StoredDataResult result = DatabaseStoredDataResultMapper.map( rowSet, null, singleton("reqId"), @@ -72,7 +72,7 @@ public void mapShouldReturnEmptyStoredResultWithErrorWhenResultSetHasLessColumns givenRowSet(givenRow("accountId", "id1", "data")); // when - final StoredDataResult result = JdbcStoredDataResultMapper.map( + final StoredDataResult result = DatabaseStoredDataResultMapper.map( rowSet, "accountId", singleton("reqId"), @@ -91,7 +91,7 @@ public void mapShouldReturnEmptyStoredResultWithErrorWhenResultSetHasUnexpectedC givenRowSet(givenRow("accountId", "id1", "data", 123)); // when - final StoredDataResult result = JdbcStoredDataResultMapper.map( + final StoredDataResult result = DatabaseStoredDataResultMapper.map( rowSet, "accountId", singleton("reqId"), @@ -112,7 +112,7 @@ public void mapShouldSkipStoredResultWithInvalidType() { givenRow("accountId", "id1", "data2", "invalid")); // when - final StoredDataResult result = JdbcStoredDataResultMapper.map( + final StoredDataResult result = DatabaseStoredDataResultMapper.map( rowSet, "accountId", singleton("id1"), @@ -131,7 +131,7 @@ public void mapShouldReturnStoredResultWithErrorForMissingId() { givenRowSet(givenRow("accountId", "id1", "data1", "request")); // when - final StoredDataResult result = JdbcStoredDataResultMapper.map( + final StoredDataResult result = DatabaseStoredDataResultMapper.map( rowSet, "accountId", singleton("id1"), @@ -153,7 +153,7 @@ public void mapShouldReturnEmptyStoredResultWithErrorsForMissingIdsIfAccountDiff givenRow("accountId", "id2", "data2", "imp")); // when - final StoredDataResult result = JdbcStoredDataResultMapper.map( + final StoredDataResult result = DatabaseStoredDataResultMapper.map( rowSet, "otherAccountId", singleton("id1"), @@ -176,7 +176,7 @@ public void mapShouldReturnEmptyStoredResultWithErrorIfMultipleStoredItemsFoundB givenRow("accountId2", "id1", "data2", "request")); // when - final StoredDataResult result = JdbcStoredDataResultMapper.map( + final StoredDataResult result = DatabaseStoredDataResultMapper.map( rowSet, null, singleton("id1"), @@ -199,7 +199,7 @@ public void mapShouldReturnEmptyStoredResultWithErrorIfMultipleStoredItemsFoundB givenRow("accountId2", "id2", "data-otherAccountId", "imp")); // when - final StoredDataResult result = JdbcStoredDataResultMapper.map( + final StoredDataResult result = DatabaseStoredDataResultMapper.map( rowSet, "otherAccountId", singleton("id1"), @@ -224,7 +224,7 @@ public void mapShouldReturnExpectedStoredResultForGivenAccount() { givenRow("otherAccountId", "id2", "data-otherAccountId", "imp")); // when - final StoredDataResult result = JdbcStoredDataResultMapper.map( + final StoredDataResult result = DatabaseStoredDataResultMapper.map( rowSet, "accountId", singleton("id1"), @@ -244,7 +244,7 @@ public void mapWithoutParamsShouldReturnEmptyStoredResultWithErrorWhenResultSetH givenRowSet(); // when - final StoredDataResult result = JdbcStoredDataResultMapper.map(rowSet); + final StoredDataResult result = DatabaseStoredDataResultMapper.map(rowSet); // then assertThat(result.getStoredIdToRequest()).isEmpty(); @@ -261,7 +261,7 @@ public void mapWithoutParamsShouldSkipStoredResultWithInvalidType() { givenRow("accountId", "id2", "data2", "invalid")); // when - final StoredDataResult result = JdbcStoredDataResultMapper.map(rowSet); + final StoredDataResult result = DatabaseStoredDataResultMapper.map(rowSet); // then assertThat(result.getStoredIdToRequest()).hasSize(1) @@ -276,7 +276,7 @@ public void mapWithoutParamsShouldReturnEmptyStoredResultWithErrorWhenResultSetH givenRowSet(givenRow("accountId", "id1", "data")); // when - final StoredDataResult result = JdbcStoredDataResultMapper.map(rowSet); + final StoredDataResult result = DatabaseStoredDataResultMapper.map(rowSet); // then assertThat(result.getStoredIdToRequest()).isEmpty(); @@ -291,7 +291,7 @@ public void mapWithoutParamsShouldReturnEmptyStoredResultWhenResultSetHasInvalid givenRowSet(givenRow("accountId", "id1", "data", 123)); // when - final StoredDataResult result = JdbcStoredDataResultMapper.map(rowSet); + final StoredDataResult result = DatabaseStoredDataResultMapper.map(rowSet); // then assertThat(result.getStoredIdToRequest()).isEmpty(); @@ -307,7 +307,7 @@ public void mapWithoutParamsShouldReturnExpectedStoredResult() { givenRow("accountId", "id2", "data2", "imp")); // when - final StoredDataResult result = JdbcStoredDataResultMapper.map(rowSet); + final StoredDataResult result = DatabaseStoredDataResultMapper.map(rowSet); // then assertThat(result.getStoredIdToRequest()).hasSize(1) diff --git a/src/test/java/org/prebid/server/settings/helper/JdbcStoredResponseResultMapperTest.java b/src/test/java/org/prebid/server/settings/helper/DatabaseStoredResponseResultMapperTest.java similarity index 86% rename from src/test/java/org/prebid/server/settings/helper/JdbcStoredResponseResultMapperTest.java rename to src/test/java/org/prebid/server/settings/helper/DatabaseStoredResponseResultMapperTest.java index b7632d09b8a..693462b8c50 100644 --- a/src/test/java/org/prebid/server/settings/helper/JdbcStoredResponseResultMapperTest.java +++ b/src/test/java/org/prebid/server/settings/helper/DatabaseStoredResponseResultMapperTest.java @@ -25,7 +25,7 @@ import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; -public class JdbcStoredResponseResultMapperTest { +public class DatabaseStoredResponseResultMapperTest { @Rule public final MockitoRule mockitoRule = MockitoJUnit.rule(); @@ -39,7 +39,7 @@ public void mapShouldReturnEmptyStoredResponseResultWithErrorWhenRowSetIsEmpty() givenRowSet(); // when - final StoredResponseDataResult result = JdbcStoredResponseResultMapper.map(rowSet, emptySet()); + final StoredResponseDataResult result = DatabaseStoredResponseResultMapper.map(rowSet, emptySet()); // then assertThat(result.getIdToStoredResponses()).isEmpty(); @@ -53,7 +53,7 @@ public void mapShouldReturnEmptyStoredResponseResultWithErrorWhenRowSetHasLessCo givenRowSet(givenRow("id1")); // when - final StoredResponseDataResult result = JdbcStoredResponseResultMapper.map(rowSet, emptySet()); + final StoredResponseDataResult result = DatabaseStoredResponseResultMapper.map(rowSet, emptySet()); // then assertThat(result.getIdToStoredResponses()).isEmpty(); @@ -67,7 +67,7 @@ public void mapShouldReturnStoredResponseResultWithErrorForMissingID() { givenRowSet(givenRow("id1", "data")); // when - final StoredResponseDataResult result = JdbcStoredResponseResultMapper.map(rowSet, Set.of("id1", "id2")); + final StoredResponseDataResult result = DatabaseStoredResponseResultMapper.map(rowSet, Set.of("id1", "id2")); // then assertThat(result.getIdToStoredResponses()).hasSize(1) @@ -82,7 +82,7 @@ public void mapShouldReturnEmptyStoredResponseResultWithErrorWhenRowSetHasEmptyR givenRowSet(); // when - final StoredResponseDataResult result = JdbcStoredResponseResultMapper.map(rowSet, singleton("id")); + final StoredResponseDataResult result = DatabaseStoredResponseResultMapper.map(rowSet, singleton("id")); // then assertThat(result.getIdToStoredResponses()).isEmpty(); @@ -96,7 +96,7 @@ public void mapShouldReturnFilledStoredResponseResultWithoutErrors() { givenRowSet(givenRow("id1", "data1"), givenRow("id2", "data2")); // when - final StoredResponseDataResult result = JdbcStoredResponseResultMapper.map(rowSet, Set.of("id1", "id2")); + final StoredResponseDataResult result = DatabaseStoredResponseResultMapper.map(rowSet, Set.of("id1", "id2")); // then assertThat(result.getIdToStoredResponses()).hasSize(2) diff --git a/src/test/java/org/prebid/server/settings/service/JdbcPeriodicRefreshServiceTest.java b/src/test/java/org/prebid/server/settings/service/DatabasePeriodicRefreshServiceTest.java similarity index 85% rename from src/test/java/org/prebid/server/settings/service/JdbcPeriodicRefreshServiceTest.java rename to src/test/java/org/prebid/server/settings/service/DatabasePeriodicRefreshServiceTest.java index 9857d048ad9..2913f1e807b 100644 --- a/src/test/java/org/prebid/server/settings/service/JdbcPeriodicRefreshServiceTest.java +++ b/src/test/java/org/prebid/server/settings/service/DatabasePeriodicRefreshServiceTest.java @@ -16,7 +16,7 @@ import org.prebid.server.metric.Metrics; import org.prebid.server.settings.CacheNotificationListener; import org.prebid.server.settings.model.StoredDataResult; -import org.prebid.server.vertx.jdbc.JdbcClient; +import org.prebid.server.vertx.database.DatabaseClient; import java.time.Clock; import java.time.Instant; @@ -37,7 +37,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -public class JdbcPeriodicRefreshServiceTest { +public class DatabasePeriodicRefreshServiceTest { @Rule public final MockitoRule mockitoRule = MockitoJUnit.rule(); @@ -47,7 +47,7 @@ public class JdbcPeriodicRefreshServiceTest { @Mock private Vertx vertx; @Mock - private JdbcClient jdbcClient; + private DatabaseClient databaseClient; private final Clock clock = Clock.fixed(Instant.now(), ZoneId.systemDefault()); private final TimeoutFactory timeoutFactory = new TimeoutFactory(clock); @Mock @@ -63,9 +63,9 @@ public void setUp() { final StoredDataResult updateResult = StoredDataResult.of(singletonMap("id1", "null"), singletonMap("id2", "changed_value"), emptyList()); - given(jdbcClient.executeQuery(eq("init_query"), anyList(), any(), any())) + given(databaseClient.executeQuery(eq("init_query"), anyList(), any(), any())) .willReturn(Future.succeededFuture(initialResult)); - given(jdbcClient.executeQuery(eq("update_query"), anyList(), any(), any())) + given(databaseClient.executeQuery(eq("update_query"), anyList(), any(), any())) .willReturn(Future.succeededFuture(updateResult)); } @@ -103,8 +103,8 @@ public void initializeShouldMakeOneInitialRequestAndTwoScheduledRequestsWithPara createAndInitService(1000); // then - verify(jdbcClient).executeQuery(eq("init_query"), eq(emptyList()), any(), any()); - verify(jdbcClient, times(2)).executeQuery(eq("update_query"), anyList(), any(), any()); + verify(databaseClient).executeQuery(eq("init_query"), eq(emptyList()), any(), any()); + verify(databaseClient, times(2)).executeQuery(eq("update_query"), anyList(), any(), any()); } @Test @@ -114,7 +114,7 @@ public void initializeShouldMakeOnlyOneInitialRequestIfRefreshPeriodIsNegative() // then verify(vertx, never()).setPeriodic(anyLong(), any()); - verify(jdbcClient).executeQuery(anyString(), anyList(), any(), any()); + verify(databaseClient).executeQuery(anyString(), anyList(), any(), any()); } @Test @@ -130,7 +130,7 @@ public void shouldUpdateTimerMetric() { @Test public void shouldUpdateTimerAndErrorMetric() { // given - given(jdbcClient.executeQuery(eq("init_query"), anyList(), any(), any())) + given(databaseClient.executeQuery(eq("init_query"), anyList(), any(), any())) .willReturn(Future.failedFuture("Query error")); // when @@ -145,7 +145,7 @@ public void shouldUpdateTimerAndErrorMetric() { private void createAndInitService(long refresh) { - final JdbcPeriodicRefreshService jdbcPeriodicRefreshService = new JdbcPeriodicRefreshService( + final DatabasePeriodicRefreshService databasePeriodicRefreshService = new DatabasePeriodicRefreshService( "init_query", "update_query", refresh, @@ -153,12 +153,12 @@ private void createAndInitService(long refresh) { MetricName.stored_request, cacheNotificationListener, vertx, - jdbcClient, + databaseClient, timeoutFactory, metrics, clock); - jdbcPeriodicRefreshService.initialize(Promise.promise()); + databasePeriodicRefreshService.initialize(Promise.promise()); } @SuppressWarnings("unchecked") diff --git a/src/test/java/org/prebid/server/vertx/jdbc/BasicJdbcClientTest.java b/src/test/java/org/prebid/server/vertx/database/BasicDatabaseClientTest.java similarity index 96% rename from src/test/java/org/prebid/server/vertx/jdbc/BasicJdbcClientTest.java rename to src/test/java/org/prebid/server/vertx/database/BasicDatabaseClientTest.java index 79514bf1fec..941ac685520 100644 --- a/src/test/java/org/prebid/server/vertx/jdbc/BasicJdbcClientTest.java +++ b/src/test/java/org/prebid/server/vertx/database/BasicDatabaseClientTest.java @@ -1,4 +1,4 @@ -package org.prebid.server.vertx.jdbc; +package org.prebid.server.vertx.database; import io.vertx.core.Future; import io.vertx.sqlclient.Pool; @@ -39,7 +39,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; -public class BasicJdbcClientTest { +public class BasicDatabaseClientTest { @Rule public final MockitoRule mockitoRule = MockitoJUnit.rule(); @@ -50,7 +50,7 @@ public class BasicJdbcClientTest { private Metrics metrics; private Clock clock; - private BasicJdbcClient target; + private BasicDatabaseClient target; private Timeout timeout; @@ -59,14 +59,14 @@ public void setUp() { clock = Clock.fixed(Instant.now(), ZoneId.systemDefault()); timeout = new TimeoutFactory(clock).create(500L); - target = new BasicJdbcClient(pool, metrics, clock); + target = new BasicDatabaseClient(pool, metrics, clock); } @Test public void creationShouldFailOnNullArguments() { - assertThatNullPointerException().isThrownBy(() -> new BasicJdbcClient(null, null, null)); - assertThatNullPointerException().isThrownBy(() -> new BasicJdbcClient(pool, null, null)); - assertThatNullPointerException().isThrownBy(() -> new BasicJdbcClient(pool, metrics, null)); + assertThatNullPointerException().isThrownBy(() -> new BasicDatabaseClient(null, null, null)); + assertThatNullPointerException().isThrownBy(() -> new BasicDatabaseClient(pool, null, null)); + assertThatNullPointerException().isThrownBy(() -> new BasicDatabaseClient(pool, metrics, null)); } @Test diff --git a/src/test/java/org/prebid/server/vertx/jdbc/CircuitBreakerSecuredJdbcClientTest.java b/src/test/java/org/prebid/server/vertx/database/CircuitBreakerSecuredDatabaseClientTest.java similarity index 92% rename from src/test/java/org/prebid/server/vertx/jdbc/CircuitBreakerSecuredJdbcClientTest.java rename to src/test/java/org/prebid/server/vertx/database/CircuitBreakerSecuredDatabaseClientTest.java index a1e86429401..ed415108260 100644 --- a/src/test/java/org/prebid/server/vertx/jdbc/CircuitBreakerSecuredJdbcClientTest.java +++ b/src/test/java/org/prebid/server/vertx/database/CircuitBreakerSecuredDatabaseClientTest.java @@ -1,4 +1,4 @@ -package org.prebid.server.vertx.jdbc; +package org.prebid.server.vertx.database; import io.vertx.core.Future; import io.vertx.core.Vertx; @@ -36,7 +36,7 @@ import static org.mockito.Mockito.verify; @RunWith(VertxUnitRunner.class) -public class CircuitBreakerSecuredJdbcClientTest { +public class CircuitBreakerSecuredDatabaseClientTest { @Rule public final MockitoRule mockitoRule = MockitoJUnit.rule(); @@ -45,11 +45,11 @@ public class CircuitBreakerSecuredJdbcClientTest { private Clock clock; @Mock - private JdbcClient wrappedJdbcClient; + private DatabaseClient wrappedDatabaseClient; @Mock private Metrics metrics; - private CircuitBreakerSecuredJdbcClient target; + private CircuitBreakerSecuredDatabaseClient target; private Timeout timeout; @@ -59,7 +59,7 @@ public void setUp() { clock = Clock.fixed(Instant.now(), ZoneId.systemDefault()); timeout = new TimeoutFactory(clock).create(500L); - target = new CircuitBreakerSecuredJdbcClient(vertx, wrappedJdbcClient, metrics, 1, 100L, 200L, clock); + target = new CircuitBreakerSecuredDatabaseClient(vertx, wrappedDatabaseClient, metrics, 1, 100L, 200L, clock); } @After @@ -112,7 +112,7 @@ public void executeQueryShouldNotExecuteQueryIfCircuitIsOpened(TestContext conte future.onComplete(context.asyncAssertFailure(throwable -> { assertThat(throwable).isInstanceOf(RuntimeException.class).hasMessage("open circuit"); - verify(wrappedJdbcClient) + verify(wrappedDatabaseClient) .executeQuery(any(), any(), any(), any()); // invoked only on 1 call })); } @@ -136,7 +136,7 @@ public void executeQueryShouldReturnExceptionIfCircuitIsHalfOpenedAndQueryFails( future.onComplete(context.asyncAssertFailure(exception -> { assertThat(exception).isInstanceOf(RuntimeException.class).hasMessage("exception1"); - verify(wrappedJdbcClient, times(2)) + verify(wrappedDatabaseClient, times(2)) .executeQuery(any(), any(), any(), any()); // invoked only on 1 & 3 calls })); } @@ -165,7 +165,7 @@ public void executeQueryShouldReturnResultIfCircuitIsHalfOpenedAndQuerySucceeded future.onComplete(context.asyncAssertSuccess(result -> { assertThat(result).isEqualTo("value"); - verify(wrappedJdbcClient, times(2)) + verify(wrappedDatabaseClient, times(2)) .executeQuery(any(), any(), any(), any()); // invoked only on 1 & 3 calls })); } @@ -173,7 +173,7 @@ public void executeQueryShouldReturnResultIfCircuitIsHalfOpenedAndQuerySucceeded @Test public void executeQueryShouldFailsWithOriginalExceptionIfOpeningIntervalExceeds(TestContext context) { // given - target = new CircuitBreakerSecuredJdbcClient(vertx, wrappedJdbcClient, metrics, 2, 100L, 200L, clock); + target = new CircuitBreakerSecuredDatabaseClient(vertx, wrappedDatabaseClient, metrics, 2, 100L, 200L, clock); givenExecuteQueryReturning(asList( Future.failedFuture(new RuntimeException("exception1")), @@ -194,7 +194,7 @@ public void executeQueryShouldFailsWithOriginalExceptionIfOpeningIntervalExceeds future2.onComplete(context.asyncAssertFailure(exception -> assertThat(exception).isInstanceOf(RuntimeException.class).hasMessage("exception2"))); - verify(wrappedJdbcClient, times(2)) + verify(wrappedDatabaseClient, times(2)) .executeQuery(any(), any(), any(), any()); } @@ -248,7 +248,7 @@ public void circuitBreakerGaugeShouldReportClosedWhenCircuitClosed(TestContext c @SuppressWarnings("unchecked") private void givenExecuteQueryReturning(List> results) { BDDMockito.BDDMyOngoingStubbing> given = - given(wrappedJdbcClient.executeQuery(any(), any(), any(), any())); + given(wrappedDatabaseClient.executeQuery(any(), any(), any(), any())); for (Future result : results) { given = given.willReturn((Future) result); }