diff --git a/extra/modules/ortb2-blocking/src/test/java/org/prebid/server/hooks/modules/ortb2/blocking/v1/model/BidderInvocationContextImpl.java b/extra/modules/ortb2-blocking/src/test/java/org/prebid/server/hooks/modules/ortb2/blocking/v1/model/BidderInvocationContextImpl.java index 8b68c9279df..d39d0a4ca5f 100644 --- a/extra/modules/ortb2-blocking/src/test/java/org/prebid/server/hooks/modules/ortb2/blocking/v1/model/BidderInvocationContextImpl.java +++ b/extra/modules/ortb2-blocking/src/test/java/org/prebid/server/hooks/modules/ortb2/blocking/v1/model/BidderInvocationContextImpl.java @@ -7,7 +7,7 @@ import lombok.experimental.Accessors; import org.prebid.server.auction.model.AuctionContext; import org.prebid.server.auction.model.BidRejectionTracker; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.hooks.v1.bidder.BidderInvocationContext; import org.prebid.server.model.Endpoint; import org.prebid.server.proto.openrtb.ext.request.ExtRequest; diff --git a/src/main/java/org/prebid/server/auction/BidResponseCreator.java b/src/main/java/org/prebid/server/auction/BidResponseCreator.java index 1c0b837bb4e..31ed4ee1403 100644 --- a/src/main/java/org/prebid/server/auction/BidResponseCreator.java +++ b/src/main/java/org/prebid/server/auction/BidResponseCreator.java @@ -52,7 +52,7 @@ import org.prebid.server.events.EventsService; import org.prebid.server.exception.InvalidRequestException; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.hooks.execution.HookStageExecutor; import org.prebid.server.hooks.execution.model.HookStageExecutionResult; import org.prebid.server.hooks.v1.bidder.AllProcessedBidResponsesPayload; diff --git a/src/main/java/org/prebid/server/auction/ExchangeService.java b/src/main/java/org/prebid/server/auction/ExchangeService.java index 66b34a8df46..bea65a97762 100644 --- a/src/main/java/org/prebid/server/auction/ExchangeService.java +++ b/src/main/java/org/prebid/server/auction/ExchangeService.java @@ -57,8 +57,8 @@ import org.prebid.server.cookie.UidsCookie; import org.prebid.server.exception.InvalidRequestException; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.floors.PriceFloorAdjuster; import org.prebid.server.floors.PriceFloorProcessor; import org.prebid.server.hooks.execution.HookStageExecutor; diff --git a/src/main/java/org/prebid/server/auction/GeoLocationServiceWrapper.java b/src/main/java/org/prebid/server/auction/GeoLocationServiceWrapper.java index 4c1a3b0b8cf..609e7481b81 100644 --- a/src/main/java/org/prebid/server/auction/GeoLocationServiceWrapper.java +++ b/src/main/java/org/prebid/server/auction/GeoLocationServiceWrapper.java @@ -8,7 +8,7 @@ import org.prebid.server.auction.model.AuctionContext; import org.prebid.server.auction.model.IpAddress; import org.prebid.server.auction.requestfactory.Ortb2ImplicitParametersResolver; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.geolocation.GeoLocationService; import org.prebid.server.geolocation.model.GeoInfo; import org.prebid.server.log.Logger; diff --git a/src/main/java/org/prebid/server/auction/SkippedAuctionService.java b/src/main/java/org/prebid/server/auction/SkippedAuctionService.java index dd8c95c0f50..e833b317cc2 100644 --- a/src/main/java/org/prebid/server/auction/SkippedAuctionService.java +++ b/src/main/java/org/prebid/server/auction/SkippedAuctionService.java @@ -8,7 +8,7 @@ import org.prebid.server.auction.model.AuctionContext; import org.prebid.server.auction.model.StoredResponseResult; import org.prebid.server.exception.InvalidRequestException; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.proto.openrtb.ext.request.ExtRequest; import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebid; import org.prebid.server.proto.openrtb.ext.request.ExtStoredAuctionResponse; diff --git a/src/main/java/org/prebid/server/auction/StoredRequestProcessor.java b/src/main/java/org/prebid/server/auction/StoredRequestProcessor.java index f982870c049..3729c5da661 100644 --- a/src/main/java/org/prebid/server/auction/StoredRequestProcessor.java +++ b/src/main/java/org/prebid/server/auction/StoredRequestProcessor.java @@ -12,8 +12,8 @@ import org.prebid.server.exception.InvalidRequestException; import org.prebid.server.exception.InvalidStoredImpException; import org.prebid.server.exception.InvalidStoredRequestException; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.identity.IdGenerator; import org.prebid.server.json.JacksonMapper; import org.prebid.server.json.JsonMerger; diff --git a/src/main/java/org/prebid/server/auction/StoredResponseProcessor.java b/src/main/java/org/prebid/server/auction/StoredResponseProcessor.java index b769d2974b1..1f5b0d83258 100644 --- a/src/main/java/org/prebid/server/auction/StoredResponseProcessor.java +++ b/src/main/java/org/prebid/server/auction/StoredResponseProcessor.java @@ -21,7 +21,7 @@ import org.prebid.server.bidder.model.BidderSeatBid; import org.prebid.server.exception.InvalidRequestException; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.json.JacksonMapper; import org.prebid.server.proto.openrtb.ext.request.ExtImp; import org.prebid.server.proto.openrtb.ext.request.ExtImpPrebid; diff --git a/src/main/java/org/prebid/server/auction/VideoStoredRequestProcessor.java b/src/main/java/org/prebid/server/auction/VideoStoredRequestProcessor.java index 84ebacc7416..f6bcb5599af 100644 --- a/src/main/java/org/prebid/server/auction/VideoStoredRequestProcessor.java +++ b/src/main/java/org/prebid/server/auction/VideoStoredRequestProcessor.java @@ -24,7 +24,7 @@ import org.prebid.server.auction.model.Tuple2; import org.prebid.server.auction.model.WithPodErrors; import org.prebid.server.exception.InvalidRequestException; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.json.JacksonMapper; import org.prebid.server.json.JsonMerger; import org.prebid.server.log.Logger; diff --git a/src/main/java/org/prebid/server/auction/categorymapping/BasicCategoryMappingService.java b/src/main/java/org/prebid/server/auction/categorymapping/BasicCategoryMappingService.java index b13cf522b49..e9a7b7818a1 100644 --- a/src/main/java/org/prebid/server/auction/categorymapping/BasicCategoryMappingService.java +++ b/src/main/java/org/prebid/server/auction/categorymapping/BasicCategoryMappingService.java @@ -28,7 +28,7 @@ import org.prebid.server.bidder.model.BidderSeatBid; import org.prebid.server.exception.InvalidRequestException; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.json.JacksonMapper; import org.prebid.server.proto.openrtb.ext.ExtIncludeBrandCategory; import org.prebid.server.proto.openrtb.ext.request.ExtDealTier; diff --git a/src/main/java/org/prebid/server/auction/categorymapping/CategoryMappingService.java b/src/main/java/org/prebid/server/auction/categorymapping/CategoryMappingService.java index 088a9604b9d..2c3b3f369b0 100644 --- a/src/main/java/org/prebid/server/auction/categorymapping/CategoryMappingService.java +++ b/src/main/java/org/prebid/server/auction/categorymapping/CategoryMappingService.java @@ -4,7 +4,7 @@ import io.vertx.core.Future; import org.prebid.server.auction.model.BidderResponse; import org.prebid.server.auction.model.CategoryMappingResult; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import java.util.List; diff --git a/src/main/java/org/prebid/server/auction/categorymapping/NoOpCategoryMappingService.java b/src/main/java/org/prebid/server/auction/categorymapping/NoOpCategoryMappingService.java index f6161fa6f90..88ac988c521 100644 --- a/src/main/java/org/prebid/server/auction/categorymapping/NoOpCategoryMappingService.java +++ b/src/main/java/org/prebid/server/auction/categorymapping/NoOpCategoryMappingService.java @@ -4,7 +4,7 @@ import io.vertx.core.Future; import org.prebid.server.auction.model.BidderResponse; import org.prebid.server.auction.model.CategoryMappingResult; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import java.util.List; diff --git a/src/main/java/org/prebid/server/auction/model/SetuidContext.java b/src/main/java/org/prebid/server/auction/model/SetuidContext.java index d045b0ceadc..05c451bf863 100644 --- a/src/main/java/org/prebid/server/auction/model/SetuidContext.java +++ b/src/main/java/org/prebid/server/auction/model/SetuidContext.java @@ -8,7 +8,7 @@ import org.prebid.server.auction.gpp.model.GppContext; import org.prebid.server.bidder.UsersyncMethodType; import org.prebid.server.cookie.UidsCookie; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.privacy.model.PrivacyContext; import org.prebid.server.settings.model.Account; diff --git a/src/main/java/org/prebid/server/auction/model/TimeoutContext.java b/src/main/java/org/prebid/server/auction/model/TimeoutContext.java index b8379056afa..87c390e6b2e 100644 --- a/src/main/java/org/prebid/server/auction/model/TimeoutContext.java +++ b/src/main/java/org/prebid/server/auction/model/TimeoutContext.java @@ -1,7 +1,7 @@ package org.prebid.server.auction.model; import lombok.Value; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; @Value(staticConstructor = "of") public class TimeoutContext { diff --git a/src/main/java/org/prebid/server/auction/privacy/contextfactory/CookieSyncPrivacyContextFactory.java b/src/main/java/org/prebid/server/auction/privacy/contextfactory/CookieSyncPrivacyContextFactory.java index 55e32fd1372..0e1e6cbab13 100644 --- a/src/main/java/org/prebid/server/auction/privacy/contextfactory/CookieSyncPrivacyContextFactory.java +++ b/src/main/java/org/prebid/server/auction/privacy/contextfactory/CookieSyncPrivacyContextFactory.java @@ -6,7 +6,7 @@ import org.prebid.server.auction.ImplicitParametersExtractor; import org.prebid.server.auction.IpAddressHelper; import org.prebid.server.auction.model.IpAddress; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.metric.MetricName; import org.prebid.server.privacy.PrivacyExtractor; import org.prebid.server.privacy.gdpr.TcfDefinerService; diff --git a/src/main/java/org/prebid/server/auction/privacy/contextfactory/SetuidPrivacyContextFactory.java b/src/main/java/org/prebid/server/auction/privacy/contextfactory/SetuidPrivacyContextFactory.java index 3e81b3fcf4f..b637e656290 100644 --- a/src/main/java/org/prebid/server/auction/privacy/contextfactory/SetuidPrivacyContextFactory.java +++ b/src/main/java/org/prebid/server/auction/privacy/contextfactory/SetuidPrivacyContextFactory.java @@ -6,7 +6,7 @@ import org.prebid.server.auction.ImplicitParametersExtractor; import org.prebid.server.auction.IpAddressHelper; import org.prebid.server.auction.model.IpAddress; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.metric.MetricName; import org.prebid.server.privacy.PrivacyExtractor; import org.prebid.server.privacy.gdpr.TcfDefinerService; diff --git a/src/main/java/org/prebid/server/auction/requestfactory/Ortb2RequestFactory.java b/src/main/java/org/prebid/server/auction/requestfactory/Ortb2RequestFactory.java index 336f2b5f8f1..90b20dd4f29 100644 --- a/src/main/java/org/prebid/server/auction/requestfactory/Ortb2RequestFactory.java +++ b/src/main/java/org/prebid/server/auction/requestfactory/Ortb2RequestFactory.java @@ -33,8 +33,8 @@ import org.prebid.server.exception.InvalidRequestException; import org.prebid.server.exception.PreBidException; import org.prebid.server.exception.UnauthorizedAccountException; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.geolocation.CountryCodeMapper; import org.prebid.server.geolocation.model.GeoInfo; import org.prebid.server.hooks.execution.HookStageExecutor; diff --git a/src/main/java/org/prebid/server/bidder/HttpBidderRequester.java b/src/main/java/org/prebid/server/bidder/HttpBidderRequester.java index 2a2fde46430..ebfdb8bb8ee 100644 --- a/src/main/java/org/prebid/server/bidder/HttpBidderRequester.java +++ b/src/main/java/org/prebid/server/bidder/HttpBidderRequester.java @@ -24,7 +24,7 @@ import org.prebid.server.bidder.model.HttpResponse; import org.prebid.server.bidder.model.Result; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.json.JacksonMapper; import org.prebid.server.log.Logger; import org.prebid.server.log.LoggerFactory; diff --git a/src/main/java/org/prebid/server/cache/CoreCacheService.java b/src/main/java/org/prebid/server/cache/CoreCacheService.java index 5d5034e23ce..e60ed70f949 100644 --- a/src/main/java/org/prebid/server/cache/CoreCacheService.java +++ b/src/main/java/org/prebid/server/cache/CoreCacheService.java @@ -27,7 +27,7 @@ import org.prebid.server.events.EventsContext; import org.prebid.server.events.EventsService; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.identity.UUIDIdGenerator; import org.prebid.server.json.DecodeException; import org.prebid.server.json.JacksonMapper; diff --git a/src/main/java/org/prebid/server/cookie/model/CookieSyncContext.java b/src/main/java/org/prebid/server/cookie/model/CookieSyncContext.java index 886c245122c..281313d25f5 100644 --- a/src/main/java/org/prebid/server/cookie/model/CookieSyncContext.java +++ b/src/main/java/org/prebid/server/cookie/model/CookieSyncContext.java @@ -8,7 +8,7 @@ import org.prebid.server.auction.gpp.model.GppContext; import org.prebid.server.bidder.UsersyncMethodChooser; import org.prebid.server.cookie.UidsCookie; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.privacy.model.PrivacyContext; import org.prebid.server.proto.request.CookieSyncRequest; import org.prebid.server.settings.model.Account; diff --git a/src/main/java/org/prebid/server/execution/RemoteFileProcessor.java b/src/main/java/org/prebid/server/execution/RemoteFileProcessor.java deleted file mode 100644 index 8621e00dbce..00000000000 --- a/src/main/java/org/prebid/server/execution/RemoteFileProcessor.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.prebid.server.execution; - -import io.vertx.core.Future; - -/** - * Contract fro services which use external files. - */ -public interface RemoteFileProcessor { - - Future setDataPath(String dataFilePath); -} - diff --git a/src/main/java/org/prebid/server/execution/file/FileProcessor.java b/src/main/java/org/prebid/server/execution/file/FileProcessor.java new file mode 100644 index 00000000000..f17ab4758ee --- /dev/null +++ b/src/main/java/org/prebid/server/execution/file/FileProcessor.java @@ -0,0 +1,8 @@ +package org.prebid.server.execution.file; + +import io.vertx.core.Future; + +public interface FileProcessor { + + Future setDataPath(String dataFilePath); +} diff --git a/src/main/java/org/prebid/server/execution/file/FileUtil.java b/src/main/java/org/prebid/server/execution/file/FileUtil.java new file mode 100644 index 00000000000..3de28c1992f --- /dev/null +++ b/src/main/java/org/prebid/server/execution/file/FileUtil.java @@ -0,0 +1,106 @@ +package org.prebid.server.execution.file; + +import io.vertx.core.Vertx; +import io.vertx.core.file.FileProps; +import io.vertx.core.file.FileSystem; +import io.vertx.core.file.FileSystemException; +import io.vertx.core.http.HttpClientOptions; +import org.apache.commons.lang3.ObjectUtils; +import org.prebid.server.exception.PreBidException; +import org.prebid.server.execution.file.syncer.FileSyncer; +import org.prebid.server.execution.file.syncer.LocalFileSyncer; +import org.prebid.server.execution.file.syncer.RemoteFileSyncerV2; +import org.prebid.server.execution.retry.ExponentialBackoffRetryPolicy; +import org.prebid.server.execution.retry.FixedIntervalRetryPolicy; +import org.prebid.server.execution.retry.RetryPolicy; +import org.prebid.server.spring.config.model.ExponentialBackoffProperties; +import org.prebid.server.spring.config.model.FileSyncerProperties; +import org.prebid.server.spring.config.model.HttpClientProperties; + +import java.nio.file.Files; +import java.nio.file.InvalidPathException; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class FileUtil { + + private FileUtil() { + } + + public static void createAndCheckWritePermissionsFor(FileSystem fileSystem, String filePath) { + try { + final Path dirPath = Paths.get(filePath).getParent(); + final String dirPathString = dirPath.toString(); + final FileProps props = fileSystem.existsBlocking(dirPathString) + ? fileSystem.propsBlocking(dirPathString) + : null; + + if (props == null || !props.isDirectory()) { + fileSystem.mkdirsBlocking(dirPathString); + } else if (!Files.isWritable(dirPath)) { + throw new PreBidException("No write permissions for directory: " + dirPath); + } + } catch (FileSystemException | InvalidPathException e) { + throw new PreBidException("Cannot create directory for file: " + filePath, e); + } + } + + public static FileSyncer fileSyncerFor(FileProcessor fileProcessor, + FileSyncerProperties properties, + Vertx vertx) { + + return switch (properties.getType()) { + case LOCAL -> new LocalFileSyncer( + fileProcessor, + properties.getSaveFilepath(), + properties.getUpdateIntervalMs(), + toRetryPolicy(properties), + vertx); + case REMOTE -> remoteFileSyncer(fileProcessor, properties, vertx); + }; + } + + private static RemoteFileSyncerV2 remoteFileSyncer(FileProcessor fileProcessor, + FileSyncerProperties properties, + Vertx vertx) { + + final HttpClientProperties httpClientProperties = properties.getHttpClient(); + final HttpClientOptions httpClientOptions = new HttpClientOptions() + .setConnectTimeout(httpClientProperties.getConnectTimeoutMs()) + .setMaxRedirects(httpClientProperties.getMaxRedirects()); + + return new RemoteFileSyncerV2( + fileProcessor, + properties.getDownloadUrl(), + properties.getSaveFilepath(), + properties.getTmpFilepath(), + vertx.createHttpClient(httpClientOptions), + properties.getTimeoutMs(), + properties.isCheckSize(), + properties.getUpdateIntervalMs(), + toRetryPolicy(properties), + vertx); + } + + // TODO: remove after transition period + private static RetryPolicy toRetryPolicy(FileSyncerProperties properties) { + final Long retryIntervalMs = properties.getRetryIntervalMs(); + final Integer retryCount = properties.getRetryCount(); + final boolean fixedRetryPolicyDefined = ObjectUtils.anyNotNull(retryIntervalMs, retryCount); + final boolean fixedRetryPolicyValid = ObjectUtils.allNotNull(retryIntervalMs, retryCount) + || !fixedRetryPolicyDefined; + + if (!fixedRetryPolicyValid) { + throw new IllegalArgumentException("fixed interval retry policy is invalid"); + } + + final ExponentialBackoffProperties exponentialBackoffProperties = properties.getRetry(); + return fixedRetryPolicyDefined + ? FixedIntervalRetryPolicy.limited(retryIntervalMs, retryCount) + : ExponentialBackoffRetryPolicy.of( + exponentialBackoffProperties.getDelayMillis(), + exponentialBackoffProperties.getMaxDelayMillis(), + exponentialBackoffProperties.getFactor(), + exponentialBackoffProperties.getJitter()); + } +} diff --git a/src/main/java/org/prebid/server/execution/file/supplier/LocalFileSupplier.java b/src/main/java/org/prebid/server/execution/file/supplier/LocalFileSupplier.java new file mode 100644 index 00000000000..55517caa9a7 --- /dev/null +++ b/src/main/java/org/prebid/server/execution/file/supplier/LocalFileSupplier.java @@ -0,0 +1,47 @@ +package org.prebid.server.execution.file.supplier; + +import io.vertx.core.Future; +import io.vertx.core.file.FileProps; +import io.vertx.core.file.FileSystem; + +import java.util.Objects; +import java.util.concurrent.atomic.AtomicLong; +import java.util.function.Supplier; + +public class LocalFileSupplier implements Supplier> { + + private final String filePath; + private final FileSystem fileSystem; + private final AtomicLong lastSupplyTime; + + public LocalFileSupplier(String filePath, FileSystem fileSystem) { + this.filePath = Objects.requireNonNull(filePath); + this.fileSystem = Objects.requireNonNull(fileSystem); + lastSupplyTime = new AtomicLong(Long.MIN_VALUE); + } + + @Override + public Future get() { + return fileSystem.exists(filePath) + .compose(exists -> exists + ? fileSystem.props(filePath) + : Future.failedFuture("File %s not found.".formatted(filePath))) + .map(this::getFileIfModified); + } + + private String getFileIfModified(FileProps fileProps) { + final long lastModifiedTime = lasModifiedTime(fileProps); + final long lastSupplyTime = this.lastSupplyTime.get(); + + if (lastSupplyTime < lastModifiedTime) { + this.lastSupplyTime.compareAndSet(lastSupplyTime, lastModifiedTime); + return filePath; + } + + return null; + } + + private static long lasModifiedTime(FileProps fileProps) { + return Math.max(fileProps.creationTime(), fileProps.lastModifiedTime()); + } +} diff --git a/src/main/java/org/prebid/server/execution/file/supplier/RemoteFileSupplier.java b/src/main/java/org/prebid/server/execution/file/supplier/RemoteFileSupplier.java new file mode 100644 index 00000000000..e8b8f313c54 --- /dev/null +++ b/src/main/java/org/prebid/server/execution/file/supplier/RemoteFileSupplier.java @@ -0,0 +1,160 @@ +package org.prebid.server.execution.file.supplier; + +import io.netty.handler.codec.http.HttpResponseStatus; +import io.vertx.core.Future; +import io.vertx.core.file.CopyOptions; +import io.vertx.core.file.FileProps; +import io.vertx.core.file.FileSystem; +import io.vertx.core.file.OpenOptions; +import io.vertx.core.http.HttpClient; +import io.vertx.core.http.HttpClientRequest; +import io.vertx.core.http.HttpClientResponse; +import io.vertx.core.http.HttpHeaders; +import io.vertx.core.http.HttpMethod; +import io.vertx.core.http.RequestOptions; +import org.prebid.server.exception.PreBidException; +import org.prebid.server.execution.file.FileUtil; +import org.prebid.server.log.Logger; +import org.prebid.server.log.LoggerFactory; +import org.prebid.server.util.HttpUtil; + +import java.util.Objects; +import java.util.function.Supplier; + +public class RemoteFileSupplier implements Supplier> { + + private static final Logger logger = LoggerFactory.getLogger(RemoteFileSupplier.class); + + private final String savePath; + private final String backupPath; + private final String tmpPath; + private final HttpClient httpClient; + private final FileSystem fileSystem; + + private final RequestOptions getRequestOptions; + private final RequestOptions headRequestOptions; + + public RemoteFileSupplier(String downloadUrl, + String savePath, + String tmpPath, + HttpClient httpClient, + long timeout, + boolean checkRemoteFileSize, + FileSystem fileSystem) { + + this.savePath = Objects.requireNonNull(savePath); + this.backupPath = savePath + ".old"; + this.tmpPath = Objects.requireNonNull(tmpPath); + this.httpClient = Objects.requireNonNull(httpClient); + this.fileSystem = Objects.requireNonNull(fileSystem); + + HttpUtil.validateUrl(downloadUrl); + FileUtil.createAndCheckWritePermissionsFor(fileSystem, savePath); + FileUtil.createAndCheckWritePermissionsFor(fileSystem, backupPath); + FileUtil.createAndCheckWritePermissionsFor(fileSystem, tmpPath); + + getRequestOptions = new RequestOptions() + .setMethod(HttpMethod.GET) + .setTimeout(timeout) + .setAbsoluteURI(downloadUrl) + .setFollowRedirects(true); + headRequestOptions = checkRemoteFileSize + ? new RequestOptions() + .setMethod(HttpMethod.HEAD) + .setTimeout(timeout) + .setAbsoluteURI(downloadUrl) + .setFollowRedirects(true) + : null; + } + + @Override + public Future get() { + return isDownloadRequired().compose(isDownloadRequired -> isDownloadRequired + ? Future.all(downloadFile(), createBackup()) + .compose(ignored -> tmpToSave()) + .map(savePath) + : Future.succeededFuture()); + } + + private Future isDownloadRequired() { + return headRequestOptions != null + ? fileSystem.exists(savePath) + .compose(exists -> exists ? isSizeChanged() : Future.succeededFuture(true)) + : Future.succeededFuture(true); + } + + private Future isSizeChanged() { + final Future localFileSize = fileSystem.props(savePath).map(FileProps::size); + final Future remoteFileSize = sendHttpRequest(headRequestOptions) + .map(response -> response.getHeader(HttpHeaders.CONTENT_LENGTH)) + .map(Long::parseLong); + + return Future.all(localFileSize, remoteFileSize) + .map(compositeResult -> !Objects.equals(compositeResult.resultAt(0), compositeResult.resultAt(1))); + } + + private Future downloadFile() { + return fileSystem.open(tmpPath, new OpenOptions()) + .compose(tmpFile -> sendHttpRequest(getRequestOptions) + .compose(response -> response.pipeTo(tmpFile)) + .onComplete(result -> tmpFile.close())); + } + + private Future sendHttpRequest(RequestOptions requestOptions) { + return httpClient.request(requestOptions) + .compose(HttpClientRequest::send) + .map(this::validateResponse); + } + + private HttpClientResponse validateResponse(HttpClientResponse response) { + final int statusCode = response.statusCode(); + if (statusCode != HttpResponseStatus.OK.code()) { + throw new PreBidException("Got unexpected response from server with status code %s and message %s" + .formatted(statusCode, response.statusMessage())); + } + + return response; + } + + private Future tmpToSave() { + return copyFile(tmpPath, savePath); + } + + public void clearTmp() { + fileSystem.exists(tmpPath).onSuccess(exists -> { + if (exists) { + deleteFile(tmpPath); + } + }); + } + + private Future createBackup() { + return fileSystem.exists(savePath) + .compose(exists -> exists ? copyFile(savePath, backupPath) : Future.succeededFuture()); + } + + public void deleteBackup() { + fileSystem.exists(backupPath).onSuccess(exists -> { + if (exists) { + deleteFile(backupPath); + } + }); + } + + public Future restoreFromBackup() { + return fileSystem.exists(backupPath) + .compose(exists -> exists + ? copyFile(backupPath, savePath) + .onSuccess(ignored -> deleteFile(backupPath)) + : Future.succeededFuture()); + } + + private Future copyFile(String from, String to) { + return fileSystem.move(from, to, new CopyOptions().setReplaceExisting(true)); + } + + private void deleteFile(String filePath) { + fileSystem.delete(filePath) + .onFailure(error -> logger.error("Can't delete file: " + filePath)); + } +} diff --git a/src/main/java/org/prebid/server/execution/file/syncer/FileSyncer.java b/src/main/java/org/prebid/server/execution/file/syncer/FileSyncer.java new file mode 100644 index 00000000000..fd850e126c4 --- /dev/null +++ b/src/main/java/org/prebid/server/execution/file/syncer/FileSyncer.java @@ -0,0 +1,84 @@ +package org.prebid.server.execution.file.syncer; + +import io.vertx.core.Future; +import io.vertx.core.Vertx; +import org.prebid.server.execution.file.FileProcessor; +import org.prebid.server.execution.retry.RetryPolicy; +import org.prebid.server.execution.retry.Retryable; +import org.prebid.server.log.Logger; +import org.prebid.server.log.LoggerFactory; + +import java.util.Objects; +import java.util.function.Function; + +public abstract class FileSyncer { + + private static final Logger logger = LoggerFactory.getLogger(FileSyncer.class); + + private final FileProcessor fileProcessor; + private final long updatePeriod; + private final RetryPolicy retryPolicy; + private final Vertx vertx; + + protected FileSyncer(FileProcessor fileProcessor, + long updatePeriod, + RetryPolicy retryPolicy, + Vertx vertx) { + + this.fileProcessor = Objects.requireNonNull(fileProcessor); + this.updatePeriod = updatePeriod; + this.retryPolicy = Objects.requireNonNull(retryPolicy); + this.vertx = Objects.requireNonNull(vertx); + } + + public void sync() { + sync(retryPolicy); + } + + private void sync(RetryPolicy currentRetryPolicy) { + getFile() + .compose(this::processFile) + .onSuccess(ignored -> onSuccess()) + .onFailure(failure -> onFailure(currentRetryPolicy, failure)); + } + + protected abstract Future getFile(); + + private Future processFile(String filePath) { + return filePath != null + ? vertx.executeBlocking(() -> fileProcessor.setDataPath(filePath)) + .compose(Function.identity()) + .onFailure(error -> logger.error("Can't process saved file: " + filePath)) + : Future.succeededFuture(); + } + + private void onSuccess() { + doOnSuccess().onComplete(ignored -> setUpDeferredUpdate()); + } + + protected abstract Future doOnSuccess(); + + private void setUpDeferredUpdate() { + if (updatePeriod > 0) { + vertx.setTimer(updatePeriod, ignored -> sync()); + } + } + + private void onFailure(RetryPolicy currentRetryPolicy, Throwable failure) { + doOnFailure(failure).onComplete(ignored -> retrySync(currentRetryPolicy)); + } + + protected abstract Future doOnFailure(Throwable throwable); + + private void retrySync(RetryPolicy currentRetryPolicy) { + if (currentRetryPolicy instanceof Retryable policy) { + logger.info( + "Retrying file sync for {} with policy: {}", + fileProcessor.getClass().getSimpleName(), + policy); + vertx.setTimer(policy.delay(), timerId -> sync(policy.next())); + } else { + setUpDeferredUpdate(); + } + } +} diff --git a/src/main/java/org/prebid/server/execution/file/syncer/LocalFileSyncer.java b/src/main/java/org/prebid/server/execution/file/syncer/LocalFileSyncer.java new file mode 100644 index 00000000000..6ea109185b5 --- /dev/null +++ b/src/main/java/org/prebid/server/execution/file/syncer/LocalFileSyncer.java @@ -0,0 +1,38 @@ +package org.prebid.server.execution.file.syncer; + +import io.vertx.core.Future; +import io.vertx.core.Vertx; +import org.prebid.server.execution.file.FileProcessor; +import org.prebid.server.execution.file.supplier.LocalFileSupplier; +import org.prebid.server.execution.retry.RetryPolicy; + +public class LocalFileSyncer extends FileSyncer { + + private final LocalFileSupplier localFileSupplier; + + public LocalFileSyncer(FileProcessor fileProcessor, + String localFile, + long updatePeriod, + RetryPolicy retryPolicy, + Vertx vertx) { + + super(fileProcessor, updatePeriod, retryPolicy, vertx); + + localFileSupplier = new LocalFileSupplier(localFile, vertx.fileSystem()); + } + + @Override + protected Future getFile() { + return localFileSupplier.get(); + } + + @Override + protected Future doOnSuccess() { + return Future.succeededFuture(); + } + + @Override + protected Future doOnFailure(Throwable throwable) { + return Future.succeededFuture(); + } +} diff --git a/src/main/java/org/prebid/server/execution/RemoteFileSyncer.java b/src/main/java/org/prebid/server/execution/file/syncer/RemoteFileSyncer.java similarity index 84% rename from src/main/java/org/prebid/server/execution/RemoteFileSyncer.java rename to src/main/java/org/prebid/server/execution/file/syncer/RemoteFileSyncer.java index b841bf8a136..8deb838646f 100644 --- a/src/main/java/org/prebid/server/execution/RemoteFileSyncer.java +++ b/src/main/java/org/prebid/server/execution/file/syncer/RemoteFileSyncer.java @@ -1,13 +1,11 @@ -package org.prebid.server.execution; +package org.prebid.server.execution.file.syncer; import io.netty.handler.codec.http.HttpResponseStatus; import io.vertx.core.Future; import io.vertx.core.Promise; import io.vertx.core.Vertx; import io.vertx.core.file.CopyOptions; -import io.vertx.core.file.FileProps; import io.vertx.core.file.FileSystem; -import io.vertx.core.file.FileSystemException; import io.vertx.core.file.OpenOptions; import io.vertx.core.http.HttpClient; import io.vertx.core.http.HttpClientRequest; @@ -17,22 +15,23 @@ import io.vertx.core.http.RequestOptions; import org.apache.commons.lang3.StringUtils; import org.prebid.server.exception.PreBidException; +import org.prebid.server.execution.file.FileProcessor; +import org.prebid.server.execution.file.FileUtil; import org.prebid.server.execution.retry.RetryPolicy; import org.prebid.server.execution.retry.Retryable; import org.prebid.server.log.Logger; import org.prebid.server.log.LoggerFactory; import org.prebid.server.util.HttpUtil; -import java.nio.file.Files; -import java.nio.file.InvalidPathException; -import java.nio.file.Paths; import java.util.Objects; +import java.util.function.Function; +@Deprecated public class RemoteFileSyncer { private static final Logger logger = LoggerFactory.getLogger(RemoteFileSyncer.class); - private final RemoteFileProcessor processor; + private final FileProcessor processor; private final String downloadUrl; private final String saveFilePath; private final String tmpFilePath; @@ -44,7 +43,7 @@ public class RemoteFileSyncer { private final RequestOptions getFileRequestOptions; private final RequestOptions isUpdateRequiredRequestOptions; - public RemoteFileSyncer(RemoteFileProcessor processor, + public RemoteFileSyncer(FileProcessor processor, String downloadUrl, String saveFilePath, String tmpFilePath, @@ -64,8 +63,8 @@ public RemoteFileSyncer(RemoteFileProcessor processor, this.vertx = Objects.requireNonNull(vertx); this.fileSystem = vertx.fileSystem(); - createAndCheckWritePermissionsFor(fileSystem, saveFilePath); - createAndCheckWritePermissionsFor(fileSystem, tmpFilePath); + FileUtil.createAndCheckWritePermissionsFor(fileSystem, saveFilePath); + FileUtil.createAndCheckWritePermissionsFor(fileSystem, tmpFilePath); getFileRequestOptions = new RequestOptions() .setMethod(HttpMethod.GET) @@ -80,20 +79,6 @@ public RemoteFileSyncer(RemoteFileProcessor processor, .setFollowRedirects(true); } - private static void createAndCheckWritePermissionsFor(FileSystem fileSystem, String filePath) { - try { - final String dirPath = Paths.get(filePath).getParent().toString(); - final FileProps props = fileSystem.existsBlocking(dirPath) ? fileSystem.propsBlocking(dirPath) : null; - if (props == null || !props.isDirectory()) { - fileSystem.mkdirsBlocking(dirPath); - } else if (!Files.isWritable(Paths.get(dirPath))) { - throw new PreBidException("No write permissions for directory: " + dirPath); - } - } catch (FileSystemException | InvalidPathException e) { - throw new PreBidException("Cannot create directory for file: " + filePath, e); - } - } - public void sync() { fileSystem.exists(saveFilePath) .compose(exists -> exists ? processSavedFile() : syncRemoteFile(retryPolicy)) @@ -101,7 +86,8 @@ public void sync() { } private Future processSavedFile() { - return processor.setDataPath(saveFilePath) + return vertx.executeBlocking(() -> processor.setDataPath(saveFilePath)) + .compose(Function.identity()) .onFailure(error -> logger.error("Can't process saved file: " + saveFilePath)) .recover(ignored -> deleteFile(saveFilePath).mapEmpty()) .mapEmpty(); diff --git a/src/main/java/org/prebid/server/execution/file/syncer/RemoteFileSyncerV2.java b/src/main/java/org/prebid/server/execution/file/syncer/RemoteFileSyncerV2.java new file mode 100644 index 00000000000..54755dccc19 --- /dev/null +++ b/src/main/java/org/prebid/server/execution/file/syncer/RemoteFileSyncerV2.java @@ -0,0 +1,69 @@ +package org.prebid.server.execution.file.syncer; + +import io.vertx.core.Future; +import io.vertx.core.Vertx; +import io.vertx.core.file.FileSystem; +import io.vertx.core.http.HttpClient; +import org.prebid.server.execution.file.FileProcessor; +import org.prebid.server.execution.file.supplier.LocalFileSupplier; +import org.prebid.server.execution.file.supplier.RemoteFileSupplier; +import org.prebid.server.execution.retry.RetryPolicy; + +public class RemoteFileSyncerV2 extends FileSyncer { + + private final LocalFileSupplier localFileSupplier; + private final RemoteFileSupplier remoteFileSupplier; + + public RemoteFileSyncerV2(FileProcessor fileProcessor, + String downloadUrl, + String saveFilePath, + String tmpFilePath, + HttpClient httpClient, + long timeout, + boolean checkSize, + long updatePeriod, + RetryPolicy retryPolicy, + Vertx vertx) { + + super(fileProcessor, updatePeriod, retryPolicy, vertx); + + final FileSystem fileSystem = vertx.fileSystem(); + localFileSupplier = new LocalFileSupplier(saveFilePath, fileSystem); + remoteFileSupplier = new RemoteFileSupplier( + downloadUrl, + saveFilePath, + tmpFilePath, + httpClient, + timeout, + checkSize, + fileSystem); + } + + @Override + protected Future getFile() { + return localFileSupplier.get() + .otherwiseEmpty() + .compose(localFile -> localFile != null + ? Future.succeededFuture(localFile) + : remoteFileSupplier.get()); + } + + @Override + protected Future doOnSuccess() { + remoteFileSupplier.clearTmp(); + remoteFileSupplier.deleteBackup(); + forceLastSupplyTimeUpdate(); + return Future.succeededFuture(); + } + + @Override + protected Future doOnFailure(Throwable throwable) { + remoteFileSupplier.clearTmp(); + return remoteFileSupplier.restoreFromBackup() + .onSuccess(ignore -> forceLastSupplyTimeUpdate()); + } + + private void forceLastSupplyTimeUpdate() { + localFileSupplier.get(); + } +} diff --git a/src/main/java/org/prebid/server/execution/Timeout.java b/src/main/java/org/prebid/server/execution/timeout/Timeout.java similarity index 95% rename from src/main/java/org/prebid/server/execution/Timeout.java rename to src/main/java/org/prebid/server/execution/timeout/Timeout.java index f5abf239c87..b0f37e439fc 100644 --- a/src/main/java/org/prebid/server/execution/Timeout.java +++ b/src/main/java/org/prebid/server/execution/timeout/Timeout.java @@ -1,4 +1,4 @@ -package org.prebid.server.execution; +package org.prebid.server.execution.timeout; import lombok.Getter; diff --git a/src/main/java/org/prebid/server/execution/TimeoutFactory.java b/src/main/java/org/prebid/server/execution/timeout/TimeoutFactory.java similarity index 95% rename from src/main/java/org/prebid/server/execution/TimeoutFactory.java rename to src/main/java/org/prebid/server/execution/timeout/TimeoutFactory.java index cbe2768af1a..ae2624c8585 100644 --- a/src/main/java/org/prebid/server/execution/TimeoutFactory.java +++ b/src/main/java/org/prebid/server/execution/timeout/TimeoutFactory.java @@ -1,4 +1,4 @@ -package org.prebid.server.execution; +package org.prebid.server.execution.timeout; import java.time.Clock; diff --git a/src/main/java/org/prebid/server/floors/PriceFloorFetcher.java b/src/main/java/org/prebid/server/floors/PriceFloorFetcher.java index 0692dce090a..0195c344474 100644 --- a/src/main/java/org/prebid/server/floors/PriceFloorFetcher.java +++ b/src/main/java/org/prebid/server/floors/PriceFloorFetcher.java @@ -13,7 +13,7 @@ import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.http.HttpStatus; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.floors.model.PriceFloorData; import org.prebid.server.floors.model.PriceFloorDebugProperties; import org.prebid.server.floors.proto.FetchResult; diff --git a/src/main/java/org/prebid/server/geolocation/CircuitBreakerSecuredGeoLocationService.java b/src/main/java/org/prebid/server/geolocation/CircuitBreakerSecuredGeoLocationService.java index 791a1da06c1..268de61b246 100755 --- a/src/main/java/org/prebid/server/geolocation/CircuitBreakerSecuredGeoLocationService.java +++ b/src/main/java/org/prebid/server/geolocation/CircuitBreakerSecuredGeoLocationService.java @@ -2,7 +2,7 @@ import io.vertx.core.Future; import io.vertx.core.Vertx; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.geolocation.model.GeoInfo; import org.prebid.server.log.ConditionalLogger; import org.prebid.server.log.Logger; diff --git a/src/main/java/org/prebid/server/geolocation/ConfigurationGeoLocationService.java b/src/main/java/org/prebid/server/geolocation/ConfigurationGeoLocationService.java index 72ec6feb2b2..30d78ea27c0 100644 --- a/src/main/java/org/prebid/server/geolocation/ConfigurationGeoLocationService.java +++ b/src/main/java/org/prebid/server/geolocation/ConfigurationGeoLocationService.java @@ -1,7 +1,7 @@ package org.prebid.server.geolocation; import io.vertx.core.Future; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.geolocation.model.GeoInfo; import org.prebid.server.geolocation.model.GeoInfoConfiguration; diff --git a/src/main/java/org/prebid/server/geolocation/GeoLocationService.java b/src/main/java/org/prebid/server/geolocation/GeoLocationService.java index 7604a25c71a..3d4c582db38 100644 --- a/src/main/java/org/prebid/server/geolocation/GeoLocationService.java +++ b/src/main/java/org/prebid/server/geolocation/GeoLocationService.java @@ -1,7 +1,7 @@ package org.prebid.server.geolocation; import io.vertx.core.Future; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.geolocation.model.GeoInfo; /** diff --git a/src/main/java/org/prebid/server/geolocation/MaxMindGeoLocationService.java b/src/main/java/org/prebid/server/geolocation/MaxMindGeoLocationService.java index 2cea7119714..5afa9311cba 100644 --- a/src/main/java/org/prebid/server/geolocation/MaxMindGeoLocationService.java +++ b/src/main/java/org/prebid/server/geolocation/MaxMindGeoLocationService.java @@ -14,8 +14,8 @@ import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.lang3.StringUtils; -import org.prebid.server.execution.RemoteFileProcessor; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.file.FileProcessor; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.geolocation.model.GeoInfo; import java.io.FileInputStream; @@ -28,7 +28,7 @@ * Implementation of the {@link GeoLocationService} * backed by MaxMind free database */ -public class MaxMindGeoLocationService implements GeoLocationService, RemoteFileProcessor { +public class MaxMindGeoLocationService implements GeoLocationService, FileProcessor { private static final String VENDOR = "maxmind"; diff --git a/src/main/java/org/prebid/server/handler/CookieSyncHandler.java b/src/main/java/org/prebid/server/handler/CookieSyncHandler.java index 746dffb5fc7..3ac0f44069c 100644 --- a/src/main/java/org/prebid/server/handler/CookieSyncHandler.java +++ b/src/main/java/org/prebid/server/handler/CookieSyncHandler.java @@ -24,8 +24,8 @@ import org.prebid.server.cookie.model.CookieSyncContext; import org.prebid.server.cookie.model.PartitionedCookie; import org.prebid.server.exception.InvalidAccountConfigException; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.json.DecodeException; import org.prebid.server.json.JacksonMapper; import org.prebid.server.log.ConditionalLogger; diff --git a/src/main/java/org/prebid/server/handler/NotificationEventHandler.java b/src/main/java/org/prebid/server/handler/NotificationEventHandler.java index 971cb82204f..60e11195c26 100644 --- a/src/main/java/org/prebid/server/handler/NotificationEventHandler.java +++ b/src/main/java/org/prebid/server/handler/NotificationEventHandler.java @@ -18,7 +18,7 @@ import org.prebid.server.events.EventRequest; import org.prebid.server.events.EventUtil; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.log.Logger; import org.prebid.server.log.LoggerFactory; import org.prebid.server.model.Endpoint; diff --git a/src/main/java/org/prebid/server/handler/SetuidHandler.java b/src/main/java/org/prebid/server/handler/SetuidHandler.java index c036bb310cd..4425e698458 100644 --- a/src/main/java/org/prebid/server/handler/SetuidHandler.java +++ b/src/main/java/org/prebid/server/handler/SetuidHandler.java @@ -37,8 +37,8 @@ import org.prebid.server.cookie.model.UidsCookieUpdateResult; import org.prebid.server.exception.InvalidAccountConfigException; import org.prebid.server.exception.InvalidRequestException; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.log.Logger; import org.prebid.server.log.LoggerFactory; import org.prebid.server.metric.Metrics; diff --git a/src/main/java/org/prebid/server/handler/VtrackHandler.java b/src/main/java/org/prebid/server/handler/VtrackHandler.java index 6539881eaa4..3d1243264d9 100644 --- a/src/main/java/org/prebid/server/handler/VtrackHandler.java +++ b/src/main/java/org/prebid/server/handler/VtrackHandler.java @@ -17,8 +17,8 @@ import org.prebid.server.cache.proto.response.bid.BidCacheResponse; import org.prebid.server.events.EventUtil; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.json.DecodeException; import org.prebid.server.json.EncodeException; import org.prebid.server.json.JacksonMapper; diff --git a/src/main/java/org/prebid/server/health/GeoLocationHealthChecker.java b/src/main/java/org/prebid/server/health/GeoLocationHealthChecker.java index 6243f9ed8c7..97bd43c4abf 100644 --- a/src/main/java/org/prebid/server/health/GeoLocationHealthChecker.java +++ b/src/main/java/org/prebid/server/health/GeoLocationHealthChecker.java @@ -1,7 +1,7 @@ package org.prebid.server.health; import io.vertx.core.Vertx; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.geolocation.GeoLocationService; import org.prebid.server.health.model.Status; import org.prebid.server.health.model.StatusResponse; diff --git a/src/main/java/org/prebid/server/hooks/execution/HookStageExecutor.java b/src/main/java/org/prebid/server/hooks/execution/HookStageExecutor.java index 81f44e3a528..95ff763bea1 100644 --- a/src/main/java/org/prebid/server/hooks/execution/HookStageExecutor.java +++ b/src/main/java/org/prebid/server/hooks/execution/HookStageExecutor.java @@ -11,8 +11,8 @@ import org.prebid.server.auction.model.BidderRequest; import org.prebid.server.auction.model.BidderResponse; import org.prebid.server.bidder.model.BidderBid; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.hooks.execution.model.EndpointExecutionPlan; import org.prebid.server.hooks.execution.model.ExecutionGroup; import org.prebid.server.hooks.execution.model.ExecutionPlan; diff --git a/src/main/java/org/prebid/server/hooks/execution/v1/InvocationContextImpl.java b/src/main/java/org/prebid/server/hooks/execution/v1/InvocationContextImpl.java index 6ed23ef8980..99399d5ba6b 100644 --- a/src/main/java/org/prebid/server/hooks/execution/v1/InvocationContextImpl.java +++ b/src/main/java/org/prebid/server/hooks/execution/v1/InvocationContextImpl.java @@ -2,7 +2,7 @@ import lombok.Value; import lombok.experimental.Accessors; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.hooks.v1.InvocationContext; import org.prebid.server.model.Endpoint; diff --git a/src/main/java/org/prebid/server/hooks/v1/InvocationContext.java b/src/main/java/org/prebid/server/hooks/v1/InvocationContext.java index 7c3b6c922d3..22493ea8a07 100644 --- a/src/main/java/org/prebid/server/hooks/v1/InvocationContext.java +++ b/src/main/java/org/prebid/server/hooks/v1/InvocationContext.java @@ -1,6 +1,6 @@ package org.prebid.server.hooks.v1; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.model.Endpoint; public interface InvocationContext { diff --git a/src/main/java/org/prebid/server/privacy/gdpr/TcfDefinerService.java b/src/main/java/org/prebid/server/privacy/gdpr/TcfDefinerService.java index b02698bbce3..5c994ec590f 100644 --- a/src/main/java/org/prebid/server/privacy/gdpr/TcfDefinerService.java +++ b/src/main/java/org/prebid/server/privacy/gdpr/TcfDefinerService.java @@ -10,7 +10,7 @@ import org.prebid.server.auction.IpAddressHelper; import org.prebid.server.auction.model.IpAddress; import org.prebid.server.bidder.BidderCatalog; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.geolocation.model.GeoInfo; import org.prebid.server.log.ConditionalLogger; import org.prebid.server.log.Logger; diff --git a/src/main/java/org/prebid/server/settings/ApplicationSettings.java b/src/main/java/org/prebid/server/settings/ApplicationSettings.java index da414bef279..7a6582ccd42 100644 --- a/src/main/java/org/prebid/server/settings/ApplicationSettings.java +++ b/src/main/java/org/prebid/server/settings/ApplicationSettings.java @@ -1,7 +1,7 @@ package org.prebid.server.settings; import io.vertx.core.Future; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.settings.model.Account; import org.prebid.server.settings.model.StoredDataResult; import org.prebid.server.settings.model.StoredResponseDataResult; diff --git a/src/main/java/org/prebid/server/settings/CachingApplicationSettings.java b/src/main/java/org/prebid/server/settings/CachingApplicationSettings.java index 97348e7bbd8..9f8fcea9ff2 100644 --- a/src/main/java/org/prebid/server/settings/CachingApplicationSettings.java +++ b/src/main/java/org/prebid/server/settings/CachingApplicationSettings.java @@ -3,7 +3,7 @@ import io.vertx.core.Future; import org.apache.commons.lang3.StringUtils; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.log.Logger; import org.prebid.server.log.LoggerFactory; import org.prebid.server.metric.MetricName; diff --git a/src/main/java/org/prebid/server/settings/CompositeApplicationSettings.java b/src/main/java/org/prebid/server/settings/CompositeApplicationSettings.java index 2edd16b7345..32d47d6abad 100644 --- a/src/main/java/org/prebid/server/settings/CompositeApplicationSettings.java +++ b/src/main/java/org/prebid/server/settings/CompositeApplicationSettings.java @@ -1,7 +1,7 @@ package org.prebid.server.settings; import io.vertx.core.Future; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.settings.helper.StoredDataFetcher; import org.prebid.server.settings.model.Account; import org.prebid.server.settings.model.StoredDataResult; diff --git a/src/main/java/org/prebid/server/settings/DatabaseApplicationSettings.java b/src/main/java/org/prebid/server/settings/DatabaseApplicationSettings.java index 9dad7f6a28b..c346e4824f4 100644 --- a/src/main/java/org/prebid/server/settings/DatabaseApplicationSettings.java +++ b/src/main/java/org/prebid/server/settings/DatabaseApplicationSettings.java @@ -7,7 +7,7 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.json.DecodeException; import org.prebid.server.json.JacksonMapper; import org.prebid.server.settings.helper.DatabaseStoredDataResultMapper; diff --git a/src/main/java/org/prebid/server/settings/EnrichingApplicationSettings.java b/src/main/java/org/prebid/server/settings/EnrichingApplicationSettings.java index 11a0d2cb3af..bfde0fc2e81 100644 --- a/src/main/java/org/prebid/server/settings/EnrichingApplicationSettings.java +++ b/src/main/java/org/prebid/server/settings/EnrichingApplicationSettings.java @@ -4,7 +4,7 @@ import org.apache.commons.lang3.StringUtils; import org.prebid.server.activity.ActivitiesConfigResolver; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.floors.PriceFloorsConfigResolver; import org.prebid.server.json.DecodeException; import org.prebid.server.json.JacksonMapper; diff --git a/src/main/java/org/prebid/server/settings/FileApplicationSettings.java b/src/main/java/org/prebid/server/settings/FileApplicationSettings.java index 33a1ea36390..1a2f42e86c4 100644 --- a/src/main/java/org/prebid/server/settings/FileApplicationSettings.java +++ b/src/main/java/org/prebid/server/settings/FileApplicationSettings.java @@ -8,7 +8,7 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.json.DecodeException; import org.prebid.server.json.JacksonMapper; import org.prebid.server.settings.model.Account; diff --git a/src/main/java/org/prebid/server/settings/HttpApplicationSettings.java b/src/main/java/org/prebid/server/settings/HttpApplicationSettings.java index 1c78e4693c5..98517003baf 100644 --- a/src/main/java/org/prebid/server/settings/HttpApplicationSettings.java +++ b/src/main/java/org/prebid/server/settings/HttpApplicationSettings.java @@ -9,7 +9,7 @@ import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.json.DecodeException; import org.prebid.server.json.JacksonMapper; import org.prebid.server.log.Logger; diff --git a/src/main/java/org/prebid/server/settings/S3ApplicationSettings.java b/src/main/java/org/prebid/server/settings/S3ApplicationSettings.java index f6198a5ad94..f1c8b107c5f 100644 --- a/src/main/java/org/prebid/server/settings/S3ApplicationSettings.java +++ b/src/main/java/org/prebid/server/settings/S3ApplicationSettings.java @@ -8,7 +8,7 @@ import org.apache.commons.lang3.StringUtils; import org.prebid.server.auction.model.Tuple2; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.json.DecodeException; import org.prebid.server.json.JacksonMapper; import org.prebid.server.settings.model.Account; diff --git a/src/main/java/org/prebid/server/settings/service/DatabasePeriodicRefreshService.java b/src/main/java/org/prebid/server/settings/service/DatabasePeriodicRefreshService.java index cc4b80ad870..bdd9e8258e0 100644 --- a/src/main/java/org/prebid/server/settings/service/DatabasePeriodicRefreshService.java +++ b/src/main/java/org/prebid/server/settings/service/DatabasePeriodicRefreshService.java @@ -4,8 +4,8 @@ import io.vertx.core.Promise; import io.vertx.core.Vertx; import org.apache.commons.lang3.StringUtils; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.log.Logger; import org.prebid.server.log.LoggerFactory; import org.prebid.server.metric.MetricName; diff --git a/src/main/java/org/prebid/server/spring/config/GeoLocationConfiguration.java b/src/main/java/org/prebid/server/spring/config/GeoLocationConfiguration.java index 7edc69d6176..bfb56b8c0c1 100644 --- a/src/main/java/org/prebid/server/spring/config/GeoLocationConfiguration.java +++ b/src/main/java/org/prebid/server/spring/config/GeoLocationConfiguration.java @@ -1,16 +1,12 @@ package org.prebid.server.spring.config; import io.vertx.core.Vertx; -import io.vertx.core.http.HttpClientOptions; import lombok.Data; -import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.prebid.server.auction.GeoLocationServiceWrapper; import org.prebid.server.auction.requestfactory.Ortb2ImplicitParametersResolver; -import org.prebid.server.execution.RemoteFileSyncer; -import org.prebid.server.execution.retry.ExponentialBackoffRetryPolicy; -import org.prebid.server.execution.retry.FixedIntervalRetryPolicy; -import org.prebid.server.execution.retry.RetryPolicy; +import org.prebid.server.execution.file.FileUtil; +import org.prebid.server.execution.file.syncer.FileSyncer; import org.prebid.server.geolocation.CircuitBreakerSecuredGeoLocationService; import org.prebid.server.geolocation.ConfigurationGeoLocationService; import org.prebid.server.geolocation.CountryCodeMapper; @@ -18,9 +14,7 @@ import org.prebid.server.geolocation.MaxMindGeoLocationService; import org.prebid.server.metric.Metrics; import org.prebid.server.spring.config.model.CircuitBreakerProperties; -import org.prebid.server.spring.config.model.ExponentialBackoffProperties; -import org.prebid.server.spring.config.model.HttpClientProperties; -import org.prebid.server.spring.config.model.RemoteFileSyncerProperties; +import org.prebid.server.spring.config.model.FileSyncerProperties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; @@ -57,14 +51,14 @@ CircuitBreakerProperties maxMindCircuitBreakerProperties() { @Bean @ConfigurationProperties(prefix = "geolocation.maxmind.remote-file-syncer") - RemoteFileSyncerProperties maxMindRemoteFileSyncerProperties() { - return new RemoteFileSyncerProperties(); + FileSyncerProperties maxMindRemoteFileSyncerProperties() { + return new FileSyncerProperties(); } @Bean @ConditionalOnProperty(prefix = "geolocation.circuit-breaker", name = "enabled", havingValue = "false", matchIfMissing = true) - GeoLocationService basicGeoLocationService(RemoteFileSyncerProperties fileSyncerProperties, + GeoLocationService basicGeoLocationService(FileSyncerProperties fileSyncerProperties, Vertx vertx) { return createGeoLocationService(fileSyncerProperties, vertx); @@ -75,7 +69,7 @@ GeoLocationService basicGeoLocationService(RemoteFileSyncerProperties fileSyncer CircuitBreakerSecuredGeoLocationService circuitBreakerSecuredGeoLocationService( Vertx vertx, Metrics metrics, - RemoteFileSyncerProperties fileSyncerProperties, + FileSyncerProperties fileSyncerProperties, @Qualifier("maxMindCircuitBreakerProperties") CircuitBreakerProperties circuitBreakerProperties, Clock clock) { @@ -85,49 +79,12 @@ CircuitBreakerSecuredGeoLocationService circuitBreakerSecuredGeoLocationService( circuitBreakerProperties.getClosingIntervalMs(), clock); } - private GeoLocationService createGeoLocationService(RemoteFileSyncerProperties properties, Vertx vertx) { + private GeoLocationService createGeoLocationService(FileSyncerProperties properties, Vertx vertx) { final MaxMindGeoLocationService maxMindGeoLocationService = new MaxMindGeoLocationService(); - final HttpClientProperties httpClientProperties = properties.getHttpClient(); - final HttpClientOptions httpClientOptions = new HttpClientOptions() - .setConnectTimeout(httpClientProperties.getConnectTimeoutMs()) - .setMaxRedirects(httpClientProperties.getMaxRedirects()); - - final RemoteFileSyncer remoteFileSyncer = new RemoteFileSyncer( - maxMindGeoLocationService, - properties.getDownloadUrl(), - properties.getSaveFilepath(), - properties.getTmpFilepath(), - toRetryPolicy(properties), - properties.getTimeoutMs(), - properties.getUpdateIntervalMs(), - vertx.createHttpClient(httpClientOptions), - vertx); - - remoteFileSyncer.sync(); + final FileSyncer fileSyncer = FileUtil.fileSyncerFor(maxMindGeoLocationService, properties, vertx); + fileSyncer.sync(); return maxMindGeoLocationService; } - - // TODO: remove after transition period - private static RetryPolicy toRetryPolicy(RemoteFileSyncerProperties properties) { - final Long retryIntervalMs = properties.getRetryIntervalMs(); - final Integer retryCount = properties.getRetryCount(); - final boolean fixedRetryPolicyDefined = ObjectUtils.anyNotNull(retryIntervalMs, retryCount); - final boolean fixedRetryPolicyValid = ObjectUtils.allNotNull(retryIntervalMs, retryCount) - || !fixedRetryPolicyDefined; - - if (!fixedRetryPolicyValid) { - throw new IllegalArgumentException("fixed interval retry policy is invalid"); - } - - final ExponentialBackoffProperties exponentialBackoffProperties = properties.getRetry(); - return fixedRetryPolicyDefined - ? FixedIntervalRetryPolicy.limited(retryIntervalMs, retryCount) - : ExponentialBackoffRetryPolicy.of( - exponentialBackoffProperties.getDelayMillis(), - exponentialBackoffProperties.getMaxDelayMillis(), - exponentialBackoffProperties.getFactor(), - exponentialBackoffProperties.getJitter()); - } } @Configuration diff --git a/src/main/java/org/prebid/server/spring/config/HealthCheckerConfiguration.java b/src/main/java/org/prebid/server/spring/config/HealthCheckerConfiguration.java index 93eaeb48030..836b45ca285 100644 --- a/src/main/java/org/prebid/server/spring/config/HealthCheckerConfiguration.java +++ b/src/main/java/org/prebid/server/spring/config/HealthCheckerConfiguration.java @@ -2,7 +2,7 @@ import io.vertx.core.Vertx; import io.vertx.sqlclient.Pool; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.geolocation.GeoLocationService; import org.prebid.server.health.ApplicationChecker; import org.prebid.server.health.DatabaseHealthChecker; diff --git a/src/main/java/org/prebid/server/spring/config/HooksConfiguration.java b/src/main/java/org/prebid/server/spring/config/HooksConfiguration.java index bffc5ee32f0..5a0239b4af2 100644 --- a/src/main/java/org/prebid/server/spring/config/HooksConfiguration.java +++ b/src/main/java/org/prebid/server/spring/config/HooksConfiguration.java @@ -3,7 +3,7 @@ import io.vertx.core.Vertx; import lombok.Data; import lombok.NoArgsConstructor; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.hooks.execution.HookCatalog; import org.prebid.server.hooks.execution.HookStageExecutor; import org.prebid.server.hooks.v1.Module; diff --git a/src/main/java/org/prebid/server/spring/config/PriceFloorsConfiguration.java b/src/main/java/org/prebid/server/spring/config/PriceFloorsConfiguration.java index 79a62ffbe87..8a483e92a4d 100644 --- a/src/main/java/org/prebid/server/spring/config/PriceFloorsConfiguration.java +++ b/src/main/java/org/prebid/server/spring/config/PriceFloorsConfiguration.java @@ -3,7 +3,7 @@ import io.vertx.core.Vertx; import org.prebid.server.auction.adjustment.FloorAdjustmentFactorResolver; import org.prebid.server.currency.CurrencyConversionService; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.floors.BasicPriceFloorAdjuster; import org.prebid.server.floors.BasicPriceFloorEnforcer; import org.prebid.server.floors.BasicPriceFloorProcessor; diff --git a/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java b/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java index 71e014fcc23..fdd1e4422a2 100644 --- a/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java +++ b/src/main/java/org/prebid/server/spring/config/ServiceConfiguration.java @@ -84,7 +84,7 @@ import org.prebid.server.cookie.UidsCookieService; import org.prebid.server.currency.CurrencyConversionService; import org.prebid.server.events.EventsService; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.floors.PriceFloorAdjuster; import org.prebid.server.floors.PriceFloorEnforcer; import org.prebid.server.floors.PriceFloorProcessor; 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 f7aaa9bb4ba..f101495eb66 100644 --- a/src/main/java/org/prebid/server/spring/config/SettingsConfiguration.java +++ b/src/main/java/org/prebid/server/spring/config/SettingsConfiguration.java @@ -7,7 +7,7 @@ import lombok.experimental.UtilityClass; import org.apache.commons.lang3.ObjectUtils; import org.prebid.server.activity.ActivitiesConfigResolver; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.floors.PriceFloorsConfigResolver; import org.prebid.server.json.JacksonMapper; import org.prebid.server.json.JsonMerger; diff --git a/src/main/java/org/prebid/server/spring/config/model/RemoteFileSyncerProperties.java b/src/main/java/org/prebid/server/spring/config/model/FileSyncerProperties.java similarity index 83% rename from src/main/java/org/prebid/server/spring/config/model/RemoteFileSyncerProperties.java rename to src/main/java/org/prebid/server/spring/config/model/FileSyncerProperties.java index 09e56ac59c6..54dbd81a5a9 100644 --- a/src/main/java/org/prebid/server/spring/config/model/RemoteFileSyncerProperties.java +++ b/src/main/java/org/prebid/server/spring/config/model/FileSyncerProperties.java @@ -11,7 +11,9 @@ @Validated @Data @NoArgsConstructor -public class RemoteFileSyncerProperties { +public class FileSyncerProperties { + + private Type type = Type.REMOTE; @NotBlank private String downloadUrl; @@ -37,6 +39,13 @@ public class RemoteFileSyncerProperties { @NotNull private Long updateIntervalMs; + private boolean checkSize; + @NotNull private HttpClientProperties httpClient; + + public enum Type { + + LOCAL, REMOTE + } } diff --git a/src/main/java/org/prebid/server/spring/config/server/application/ApplicationServerConfiguration.java b/src/main/java/org/prebid/server/spring/config/server/application/ApplicationServerConfiguration.java index 82794d58ffb..8c93941c679 100644 --- a/src/main/java/org/prebid/server/spring/config/server/application/ApplicationServerConfiguration.java +++ b/src/main/java/org/prebid/server/spring/config/server/application/ApplicationServerConfiguration.java @@ -29,7 +29,7 @@ import org.prebid.server.cookie.CookieDeprecationService; import org.prebid.server.cookie.CookieSyncService; import org.prebid.server.cookie.UidsCookieService; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.handler.BidderParamHandler; import org.prebid.server.handler.CookieSyncHandler; import org.prebid.server.handler.ExceptionHandler; diff --git a/src/main/java/org/prebid/server/vertx/database/BasicDatabaseClient.java b/src/main/java/org/prebid/server/vertx/database/BasicDatabaseClient.java index e5aa90aabb2..7158bd4ba07 100644 --- a/src/main/java/org/prebid/server/vertx/database/BasicDatabaseClient.java +++ b/src/main/java/org/prebid/server/vertx/database/BasicDatabaseClient.java @@ -6,7 +6,7 @@ import io.vertx.sqlclient.RowSet; import io.vertx.sqlclient.SqlConnection; import io.vertx.sqlclient.Tuple; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.log.Logger; import org.prebid.server.log.LoggerFactory; import org.prebid.server.metric.Metrics; diff --git a/src/main/java/org/prebid/server/vertx/database/CircuitBreakerSecuredDatabaseClient.java b/src/main/java/org/prebid/server/vertx/database/CircuitBreakerSecuredDatabaseClient.java index bb4fa7d09c1..ea59c9f9670 100644 --- a/src/main/java/org/prebid/server/vertx/database/CircuitBreakerSecuredDatabaseClient.java +++ b/src/main/java/org/prebid/server/vertx/database/CircuitBreakerSecuredDatabaseClient.java @@ -4,7 +4,7 @@ import io.vertx.core.Vertx; import io.vertx.sqlclient.Row; import io.vertx.sqlclient.RowSet; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.log.ConditionalLogger; import org.prebid.server.log.Logger; import org.prebid.server.log.LoggerFactory; diff --git a/src/main/java/org/prebid/server/vertx/database/DatabaseClient.java b/src/main/java/org/prebid/server/vertx/database/DatabaseClient.java index 87c9ada84c6..78a6a34ac7e 100644 --- a/src/main/java/org/prebid/server/vertx/database/DatabaseClient.java +++ b/src/main/java/org/prebid/server/vertx/database/DatabaseClient.java @@ -3,7 +3,7 @@ import io.vertx.core.Future; import io.vertx.sqlclient.Row; import io.vertx.sqlclient.RowSet; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import java.util.List; import java.util.function.Function; diff --git a/src/test/java/org/prebid/server/analytics/reporter/pubstack/PubstackEventHandlerTest.java b/src/test/java/org/prebid/server/analytics/reporter/pubstack/PubstackEventHandlerTest.java index 4fc744e4b43..b7418e7b777 100644 --- a/src/test/java/org/prebid/server/analytics/reporter/pubstack/PubstackEventHandlerTest.java +++ b/src/test/java/org/prebid/server/analytics/reporter/pubstack/PubstackEventHandlerTest.java @@ -16,7 +16,7 @@ import org.prebid.server.auction.model.AuctionContext; import org.prebid.server.auction.model.TimeoutContext; import org.prebid.server.cookie.UidsCookie; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.vertx.httpclient.HttpClient; import org.prebid.server.vertx.httpclient.model.HttpClientResponse; import org.springframework.test.util.ReflectionTestUtils; diff --git a/src/test/java/org/prebid/server/auction/BasicCategoryMappingServiceTest.java b/src/test/java/org/prebid/server/auction/BasicCategoryMappingServiceTest.java index d1de6726c42..3c05d00af37 100644 --- a/src/test/java/org/prebid/server/auction/BasicCategoryMappingServiceTest.java +++ b/src/test/java/org/prebid/server/auction/BasicCategoryMappingServiceTest.java @@ -18,8 +18,8 @@ import org.prebid.server.bidder.model.BidderBid; import org.prebid.server.bidder.model.BidderSeatBid; import org.prebid.server.exception.InvalidRequestException; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.proto.openrtb.ext.ExtIncludeBrandCategory; import org.prebid.server.proto.openrtb.ext.request.ExtImp; import org.prebid.server.proto.openrtb.ext.request.ExtImpPrebid; diff --git a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java index 17de10e38b5..0e3d0220ba1 100644 --- a/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java +++ b/src/test/java/org/prebid/server/auction/BidResponseCreatorTest.java @@ -62,8 +62,8 @@ import org.prebid.server.events.EventsContext; import org.prebid.server.events.EventsService; import org.prebid.server.exception.InvalidRequestException; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.hooks.execution.HookStageExecutor; import org.prebid.server.hooks.execution.model.HookStageExecutionResult; import org.prebid.server.hooks.execution.v1.bidder.AllProcessedBidResponsesPayloadImpl; diff --git a/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java b/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java index 7eb1a351531..cf450fb6e7a 100644 --- a/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java +++ b/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java @@ -70,8 +70,8 @@ import org.prebid.server.cookie.UidsCookie; import org.prebid.server.exception.InvalidRequestException; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.floors.PriceFloorAdjuster; import org.prebid.server.floors.PriceFloorProcessor; import org.prebid.server.hooks.execution.HookStageExecutor; diff --git a/src/test/java/org/prebid/server/auction/GeoLocationServiceWrapperTest.java b/src/test/java/org/prebid/server/auction/GeoLocationServiceWrapperTest.java index 12fed4e7f19..be7348abb74 100644 --- a/src/test/java/org/prebid/server/auction/GeoLocationServiceWrapperTest.java +++ b/src/test/java/org/prebid/server/auction/GeoLocationServiceWrapperTest.java @@ -15,8 +15,8 @@ import org.prebid.server.auction.model.IpAddress.IP; import org.prebid.server.auction.model.TimeoutContext; import org.prebid.server.auction.requestfactory.Ortb2ImplicitParametersResolver; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.geolocation.GeoLocationService; import org.prebid.server.geolocation.model.GeoInfo; import org.prebid.server.metric.Metrics; diff --git a/src/test/java/org/prebid/server/auction/SkippedAuctionServiceTest.java b/src/test/java/org/prebid/server/auction/SkippedAuctionServiceTest.java index adcd1e9a296..3976a4bbd8f 100644 --- a/src/test/java/org/prebid/server/auction/SkippedAuctionServiceTest.java +++ b/src/test/java/org/prebid/server/auction/SkippedAuctionServiceTest.java @@ -13,7 +13,7 @@ import org.prebid.server.auction.model.AuctionContext; import org.prebid.server.auction.model.StoredResponseResult; import org.prebid.server.auction.model.TimeoutContext; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.proto.openrtb.ext.request.ExtRequest; import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebid; import org.prebid.server.proto.openrtb.ext.request.ExtStoredAuctionResponse; diff --git a/src/test/java/org/prebid/server/auction/StoredRequestProcessorTest.java b/src/test/java/org/prebid/server/auction/StoredRequestProcessorTest.java index 8cbd5bc8b70..9b9aa5aba48 100644 --- a/src/test/java/org/prebid/server/auction/StoredRequestProcessorTest.java +++ b/src/test/java/org/prebid/server/auction/StoredRequestProcessorTest.java @@ -19,7 +19,7 @@ import org.prebid.server.VertxTest; import org.prebid.server.auction.model.AuctionStoredResult; import org.prebid.server.exception.InvalidRequestException; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.identity.IdGenerator; import org.prebid.server.json.JsonMerger; import org.prebid.server.metric.Metrics; diff --git a/src/test/java/org/prebid/server/auction/StoredResponseProcessorTest.java b/src/test/java/org/prebid/server/auction/StoredResponseProcessorTest.java index 3b625ddf379..a137578ef14 100644 --- a/src/test/java/org/prebid/server/auction/StoredResponseProcessorTest.java +++ b/src/test/java/org/prebid/server/auction/StoredResponseProcessorTest.java @@ -23,8 +23,8 @@ import org.prebid.server.bidder.model.BidderSeatBid; import org.prebid.server.exception.InvalidRequestException; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.proto.openrtb.ext.request.ExtImp; import org.prebid.server.proto.openrtb.ext.request.ExtImpPrebid; import org.prebid.server.proto.openrtb.ext.request.ExtStoredAuctionResponse; diff --git a/src/test/java/org/prebid/server/auction/VideoStoredRequestProcessorTest.java b/src/test/java/org/prebid/server/auction/VideoStoredRequestProcessorTest.java index 3946162ff92..66442d47c93 100644 --- a/src/test/java/org/prebid/server/auction/VideoStoredRequestProcessorTest.java +++ b/src/test/java/org/prebid/server/auction/VideoStoredRequestProcessorTest.java @@ -24,7 +24,7 @@ import org.prebid.server.VertxTest; import org.prebid.server.auction.model.WithPodErrors; import org.prebid.server.exception.InvalidRequestException; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.json.JsonMerger; import org.prebid.server.metric.Metrics; import org.prebid.server.proto.openrtb.ext.ExtIncludeBrandCategory; diff --git a/src/test/java/org/prebid/server/auction/privacy/contextfactory/CookieSyncPrivacyContextFactoryTest.java b/src/test/java/org/prebid/server/auction/privacy/contextfactory/CookieSyncPrivacyContextFactoryTest.java index fd005459913..477e67ffd0b 100644 --- a/src/test/java/org/prebid/server/auction/privacy/contextfactory/CookieSyncPrivacyContextFactoryTest.java +++ b/src/test/java/org/prebid/server/auction/privacy/contextfactory/CookieSyncPrivacyContextFactoryTest.java @@ -14,7 +14,7 @@ import org.prebid.server.auction.ImplicitParametersExtractor; import org.prebid.server.auction.IpAddressHelper; import org.prebid.server.auction.model.IpAddress; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.privacy.PrivacyExtractor; import org.prebid.server.privacy.gdpr.TcfDefinerService; import org.prebid.server.privacy.gdpr.model.TcfContext; diff --git a/src/test/java/org/prebid/server/auction/privacy/contextfactory/SetuidPrivacyContextFactoryTest.java b/src/test/java/org/prebid/server/auction/privacy/contextfactory/SetuidPrivacyContextFactoryTest.java index 453210aabd1..1cf5961ff4e 100644 --- a/src/test/java/org/prebid/server/auction/privacy/contextfactory/SetuidPrivacyContextFactoryTest.java +++ b/src/test/java/org/prebid/server/auction/privacy/contextfactory/SetuidPrivacyContextFactoryTest.java @@ -14,7 +14,7 @@ import org.prebid.server.auction.ImplicitParametersExtractor; import org.prebid.server.auction.IpAddressHelper; import org.prebid.server.auction.model.IpAddress; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.privacy.PrivacyExtractor; import org.prebid.server.privacy.gdpr.TcfDefinerService; import org.prebid.server.privacy.gdpr.model.TcfContext; diff --git a/src/test/java/org/prebid/server/auction/requestfactory/Ortb2RequestFactoryTest.java b/src/test/java/org/prebid/server/auction/requestfactory/Ortb2RequestFactoryTest.java index b38c305cd2b..5b4c0bd72e5 100644 --- a/src/test/java/org/prebid/server/auction/requestfactory/Ortb2RequestFactoryTest.java +++ b/src/test/java/org/prebid/server/auction/requestfactory/Ortb2RequestFactoryTest.java @@ -39,8 +39,8 @@ import org.prebid.server.exception.InvalidRequestException; import org.prebid.server.exception.PreBidException; import org.prebid.server.exception.UnauthorizedAccountException; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.geolocation.CountryCodeMapper; import org.prebid.server.geolocation.model.GeoInfo; import org.prebid.server.hooks.execution.HookStageExecutor; diff --git a/src/test/java/org/prebid/server/bidder/HttpBidderRequesterTest.java b/src/test/java/org/prebid/server/bidder/HttpBidderRequesterTest.java index 83079b4d825..e54bc826030 100644 --- a/src/test/java/org/prebid/server/bidder/HttpBidderRequesterTest.java +++ b/src/test/java/org/prebid/server/bidder/HttpBidderRequesterTest.java @@ -33,8 +33,8 @@ import org.prebid.server.bidder.model.HttpRequest; import org.prebid.server.bidder.model.HttpResponse; import org.prebid.server.bidder.model.Result; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.model.CaseInsensitiveMultiMap; import org.prebid.server.proto.openrtb.ext.response.ExtHttpCall; import org.prebid.server.proto.openrtb.ext.response.FledgeAuctionConfig; diff --git a/src/test/java/org/prebid/server/cache/CoreCacheServiceTest.java b/src/test/java/org/prebid/server/cache/CoreCacheServiceTest.java index a8ce602aeb5..058f958fa48 100644 --- a/src/test/java/org/prebid/server/cache/CoreCacheServiceTest.java +++ b/src/test/java/org/prebid/server/cache/CoreCacheServiceTest.java @@ -32,8 +32,8 @@ import org.prebid.server.events.EventsContext; import org.prebid.server.events.EventsService; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.identity.UUIDIdGenerator; import org.prebid.server.metric.MetricName; import org.prebid.server.metric.Metrics; diff --git a/src/test/java/org/prebid/server/execution/file/supplier/LocalFileSupplierTest.java b/src/test/java/org/prebid/server/execution/file/supplier/LocalFileSupplierTest.java new file mode 100644 index 00000000000..407e01c6bf5 --- /dev/null +++ b/src/test/java/org/prebid/server/execution/file/supplier/LocalFileSupplierTest.java @@ -0,0 +1,68 @@ +package org.prebid.server.execution.file.supplier; + +import io.vertx.core.Future; +import io.vertx.core.file.FileProps; +import io.vertx.core.file.FileSystem; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.prebid.server.assertion.FutureAssertion; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; + +@ExtendWith(MockitoExtension.class) +public class LocalFileSupplierTest { + + @Mock + private FileSystem fileSystem; + + private LocalFileSupplier target; + + @BeforeEach + public void setUp() { + given(fileSystem.exists(anyString())).willReturn(Future.succeededFuture(true)); + + target = new LocalFileSupplier("/path/to/file", fileSystem); + } + + @Test + public void getShouldReturnFailedFutureIfFileNotFound() { + // given + given(fileSystem.exists(anyString())).willReturn(Future.succeededFuture(false)); + + // when and then + FutureAssertion.assertThat(target.get()).isFailed().hasMessage("File /path/to/file not found."); + } + + @Test + public void getShouldReturnFilePath() { + // given + final FileProps fileProps = mock(FileProps.class); + given(fileSystem.props(anyString())).willReturn(Future.succeededFuture(fileProps)); + given(fileProps.creationTime()).willReturn(1000L); + + // when and then + assertThat(target.get().result()).isEqualTo("/path/to/file"); + } + + @Test + public void getShouldReturnNullIfFileNotModifiedSinceLastTry() { + // given + final FileProps fileProps = mock(FileProps.class); + given(fileSystem.props(anyString())).willReturn(Future.succeededFuture(fileProps)); + given(fileProps.creationTime()).willReturn(1000L); + + // when + target.get(); + final Future result = target.get(); + + // then + assertThat(result.succeeded()).isTrue(); + assertThat(result.result()).isNull(); + } +} diff --git a/src/test/java/org/prebid/server/execution/file/supplier/RemoteFileSupplierTest.java b/src/test/java/org/prebid/server/execution/file/supplier/RemoteFileSupplierTest.java new file mode 100644 index 00000000000..d60ff696ba7 --- /dev/null +++ b/src/test/java/org/prebid/server/execution/file/supplier/RemoteFileSupplierTest.java @@ -0,0 +1,244 @@ +package org.prebid.server.execution.file.supplier; + +import io.vertx.core.Future; +import io.vertx.core.Promise; +import io.vertx.core.file.AsyncFile; +import io.vertx.core.file.CopyOptions; +import io.vertx.core.file.FileProps; +import io.vertx.core.file.FileSystem; +import io.vertx.core.http.HttpClient; +import io.vertx.core.http.HttpClientRequest; +import io.vertx.core.http.HttpClientResponse; +import io.vertx.core.http.HttpHeaders; +import io.vertx.core.http.HttpMethod; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; +import org.prebid.server.assertion.FutureAssertion; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.LENIENT) +public class RemoteFileSupplierTest { + + private static final String SAVE_PATH = "/path/to/file"; + private static final String BACKUP_PATH = SAVE_PATH + ".old"; + private static final String TMP_PATH = "/path/to/tmp"; + + @Mock + private HttpClient httpClient; + + @Mock + private FileSystem fileSystem; + + private RemoteFileSupplier target; + + @Mock + private HttpClientResponse getResponse; + + @Mock + private HttpClientResponse headResponse; + + @BeforeEach + public void setUp() { + final HttpClientRequest getRequest = mock(HttpClientRequest.class); + given(httpClient.request(argThat(requestOptions -> + requestOptions != null && requestOptions.getMethod().equals(HttpMethod.GET)))) + .willReturn(Future.succeededFuture(getRequest)); + given(getRequest.send()).willReturn(Future.succeededFuture(getResponse)); + + final HttpClientRequest headRequest = mock(HttpClientRequest.class); + given(httpClient.request(argThat(requestOptions -> + requestOptions != null && requestOptions.getMethod().equals(HttpMethod.HEAD)))) + .willReturn(Future.succeededFuture(headRequest)); + given(headRequest.send()).willReturn(Future.succeededFuture(headResponse)); + given(headResponse.statusCode()).willReturn(200); + + target = target(false); + } + + private RemoteFileSupplier target(boolean checkRemoteFileSize) { + return new RemoteFileSupplier( + "https://download.url/", + SAVE_PATH, + TMP_PATH, + httpClient, + 1000L, + checkRemoteFileSize, + fileSystem); + } + + @Test + public void shouldCheckWritePermissionsForFiles() { + // given + reset(fileSystem); + final FileProps fileProps = mock(FileProps.class); + given(fileSystem.existsBlocking(anyString())).willReturn(true); + given(fileSystem.propsBlocking(anyString())).willReturn(fileProps); + given(fileProps.isDirectory()).willReturn(false); + + // when + target(false); + + // then + verify(fileSystem, times(3)).mkdirsBlocking(anyString()); + } + + @Test + public void getShouldReturnFailureWhenCanNotOpenTmpFile() { + // given + given(fileSystem.open(eq(TMP_PATH), any())).willReturn(Future.failedFuture("Failure.")); + given(fileSystem.exists(eq(SAVE_PATH))).willReturn(Promise.promise().future()); + + // when + final Future result = target.get(); + + // then + FutureAssertion.assertThat(result).isFailed().hasMessage("Failure."); + } + + @Test + public void getShouldReturnFailureOnNotOkStatusCode() { + // given + final AsyncFile tmpFile = mock(AsyncFile.class); + given(fileSystem.open(eq(TMP_PATH), any())).willReturn(Future.succeededFuture(tmpFile)); + given(fileSystem.exists(eq(SAVE_PATH))).willReturn(Promise.promise().future()); + + given(getResponse.statusCode()).willReturn(204); + + // when + final Future result = target.get(); + + // then + FutureAssertion.assertThat(result).isFailed() + .hasMessage("Got unexpected response from server with status code 204 and message null"); + } + + @Test + public void getShouldReturnExpectedResult() { + // given + final AsyncFile tmpFile = mock(AsyncFile.class); + given(fileSystem.open(eq(TMP_PATH), any())).willReturn(Future.succeededFuture(tmpFile)); + given(fileSystem.exists(eq(SAVE_PATH))).willReturn(Future.succeededFuture(true)); + given(fileSystem.move(eq(SAVE_PATH), eq(BACKUP_PATH), Mockito.any())) + .willReturn(Future.succeededFuture()); + given(fileSystem.move(eq(TMP_PATH), eq(SAVE_PATH), Mockito.any())) + .willReturn(Future.succeededFuture()); + + given(getResponse.statusCode()).willReturn(200); + given(getResponse.pipeTo(any())).willReturn(Future.succeededFuture()); + + // when + final Future result = target.get(); + + // then + verify(tmpFile).close(); + assertThat(result.result()).isEqualTo(SAVE_PATH); + } + + @Test + public void getShouldReturnExpectedResultWhenCheckRemoteFileSizeIsTrue() { + // given + target = target(true); + + final FileProps fileProps = mock(FileProps.class); + given(fileSystem.exists(eq(SAVE_PATH))).willReturn(Future.succeededFuture(true)); + given(fileSystem.props(eq(SAVE_PATH))).willReturn(Future.succeededFuture(fileProps)); + given(fileProps.size()).willReturn(1000L); + + given(headResponse.statusCode()).willReturn(200); + given(headResponse.getHeader(eq(HttpHeaders.CONTENT_LENGTH))).willReturn("1001"); + + final AsyncFile tmpFile = mock(AsyncFile.class); + given(fileSystem.open(eq(TMP_PATH), any())).willReturn(Future.succeededFuture(tmpFile)); + given(fileSystem.move(eq(SAVE_PATH), eq(BACKUP_PATH), Mockito.any())) + .willReturn(Future.succeededFuture()); + given(fileSystem.move(eq(TMP_PATH), eq(SAVE_PATH), Mockito.any())) + .willReturn(Future.succeededFuture()); + + given(getResponse.statusCode()).willReturn(200); + given(getResponse.pipeTo(any())).willReturn(Future.succeededFuture()); + + // when + final Future result = target.get(); + + // then + verify(tmpFile).close(); + assertThat(result.result()).isEqualTo(SAVE_PATH); + } + + @Test + public void getShouldReturnNullWhenCheckRemoteFileSizeIsTrueAndSizeNotChanged() { + // given + target = target(true); + + final FileProps fileProps = mock(FileProps.class); + given(fileSystem.exists(eq(SAVE_PATH))).willReturn(Future.succeededFuture(true)); + given(fileSystem.props(eq(SAVE_PATH))).willReturn(Future.succeededFuture(fileProps)); + given(fileProps.size()).willReturn(1000L); + + given(headResponse.statusCode()).willReturn(200); + given(headResponse.getHeader(eq(HttpHeaders.CONTENT_LENGTH))).willReturn("1000"); + + // when + final Future result = target.get(); + + // then + assertThat(result.result()).isNull(); + } + + @Test + public void clearTmpShouldCallExpectedMethods() { + // given + given(fileSystem.exists(eq(TMP_PATH))).willReturn(Future.succeededFuture(true)); + given(fileSystem.delete(eq(TMP_PATH))).willReturn(Future.succeededFuture()); + + // when + target.clearTmp(); + + // then + verify(fileSystem).delete(TMP_PATH); + } + + @Test + public void deleteBackupShouldCallExpectedMethods() { + // given + given(fileSystem.exists(eq(BACKUP_PATH))).willReturn(Future.succeededFuture(true)); + given(fileSystem.delete(eq(BACKUP_PATH))).willReturn(Future.succeededFuture()); + + // when + target.deleteBackup(); + + // then + verify(fileSystem).delete(BACKUP_PATH); + } + + @Test + public void restoreFromBackupShouldCallExpectedMethods() { + // given + given(fileSystem.exists(eq(BACKUP_PATH))).willReturn(Future.succeededFuture(true)); + given(fileSystem.move(eq(BACKUP_PATH), eq(SAVE_PATH))).willReturn(Future.succeededFuture()); + given(fileSystem.delete(eq(BACKUP_PATH))).willReturn(Future.succeededFuture()); + + // when + target.deleteBackup(); + + // then + verify(fileSystem).delete(BACKUP_PATH); + } +} diff --git a/src/test/java/org/prebid/server/execution/file/syncer/FileSyncerTest.java b/src/test/java/org/prebid/server/execution/file/syncer/FileSyncerTest.java new file mode 100644 index 00000000000..39a8e8ae966 --- /dev/null +++ b/src/test/java/org/prebid/server/execution/file/syncer/FileSyncerTest.java @@ -0,0 +1,160 @@ +package org.prebid.server.execution.file.syncer; + +import io.vertx.core.Future; +import io.vertx.core.Handler; +import io.vertx.core.Promise; +import io.vertx.core.Vertx; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; +import org.prebid.server.execution.file.FileProcessor; +import org.prebid.server.execution.retry.FixedIntervalRetryPolicy; +import org.prebid.server.execution.retry.NonRetryable; +import org.prebid.server.execution.retry.RetryPolicy; +import org.testcontainers.shaded.org.apache.commons.lang3.NotImplementedException; + +import java.util.concurrent.Callable; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; + +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.LENIENT) +public class FileSyncerTest { + + private static final String SAVE_PATH = "/path/to/file"; + + @Mock + private FileProcessor fileProcessor; + + @Mock + private Vertx vertx; + + @BeforeEach + public void setUp() { + given(vertx.executeBlocking(Mockito.>any())).willAnswer(invocation -> { + try { + return Future.succeededFuture(((Callable) invocation.getArgument(0)).call()); + } catch (Throwable e) { + return Future.failedFuture(e); + } + }); + } + + @Test + public void syncShouldCallExpectedMethodsOnSuccessWhenNoReturnedFile() { + // given + final FileSyncer fileSyncer = fileSyncer(NonRetryable.instance()); + given(fileSyncer.getFile()).willReturn(Future.succeededFuture()); + + // when + fileSyncer.sync(); + + // then + verifyNoInteractions(fileProcessor); + verify(fileSyncer).doOnSuccess(); + verify(vertx).setTimer(eq(1000L), any()); + } + + @Test + public void syncShouldCallExpectedMethodsOnSuccess() { + // given + final FileSyncer fileSyncer = fileSyncer(NonRetryable.instance()); + given(fileSyncer.getFile()).willReturn(Future.succeededFuture(SAVE_PATH)); + given(fileProcessor.setDataPath(eq(SAVE_PATH))).willReturn(Future.succeededFuture()); + + // when + fileSyncer.sync(); + + // then + verify(fileProcessor).setDataPath(eq(SAVE_PATH)); + verify(fileSyncer).doOnSuccess(); + verify(vertx).setTimer(eq(1000L), any()); + } + + @Test + public void syncShouldCallExpectedMethodsOnFailure() { + // given + final FileSyncer fileSyncer = fileSyncer(NonRetryable.instance()); + given(fileSyncer.getFile()).willReturn(Future.succeededFuture(SAVE_PATH)); + given(fileProcessor.setDataPath(eq(SAVE_PATH))).willReturn(Future.failedFuture("Failure")); + + // when + fileSyncer.sync(); + + // then + verify(fileProcessor).setDataPath(eq(SAVE_PATH)); + verify(fileSyncer).doOnFailure(any()); + verify(vertx).setTimer(eq(1000L), any()); + } + + @Test + public void syncShouldCallExpectedMethodsOnFailureWithRetryable() { + // given + final FileSyncer fileSyncer = fileSyncer(FixedIntervalRetryPolicy.limited(10L, 1)); + given(fileSyncer.getFile()).willReturn(Future.succeededFuture(SAVE_PATH)); + given(fileProcessor.setDataPath(eq(SAVE_PATH))).willReturn(Future.failedFuture("Failure")); + + final Promise promise = Promise.promise(); + given(vertx.setTimer(eq(10L), any())).willAnswer(invocation -> { + promise.future().onComplete(ignore -> ((Handler) invocation.getArgument(1)).handle(1L)); + return 1L; + }); + + // when + fileSyncer.sync(); + + // then + verify(fileProcessor).setDataPath(eq(SAVE_PATH)); + verify(fileSyncer).doOnFailure(any()); + verify(vertx).setTimer(eq(10L), any()); + + // when + promise.complete(); + + // then + verify(fileProcessor, times(2)).setDataPath(eq(SAVE_PATH)); + verify(fileSyncer, times(2)).doOnFailure(any()); + verify(vertx).setTimer(eq(1000L), any()); + } + + private FileSyncer fileSyncer(RetryPolicy retryPolicy) { + return spy(new TestFileSyncer(fileProcessor, 1000L, retryPolicy, vertx)); + } + + private static class TestFileSyncer extends FileSyncer { + + protected TestFileSyncer(FileProcessor fileProcessor, + long updatePeriod, + RetryPolicy retryPolicy, + Vertx vertx) { + + super(fileProcessor, updatePeriod, retryPolicy, vertx); + } + + @Override + public Future getFile() { + return Future.failedFuture(new NotImplementedException()); + } + + @Override + protected Future doOnSuccess() { + return Future.succeededFuture(); + } + + @Override + protected Future doOnFailure(Throwable throwable) { + return Future.succeededFuture(); + } + } +} diff --git a/src/test/java/org/prebid/server/execution/RemoteFileSyncerTest.java b/src/test/java/org/prebid/server/execution/file/syncer/RemoteFileSyncerTest.java similarity index 87% rename from src/test/java/org/prebid/server/execution/RemoteFileSyncerTest.java rename to src/test/java/org/prebid/server/execution/file/syncer/RemoteFileSyncerTest.java index 9acd719d30f..2da614c4e50 100644 --- a/src/test/java/org/prebid/server/execution/RemoteFileSyncerTest.java +++ b/src/test/java/org/prebid/server/execution/file/syncer/RemoteFileSyncerTest.java @@ -1,4 +1,4 @@ -package org.prebid.server.execution; +package org.prebid.server.execution.file.syncer; import io.netty.handler.codec.http.HttpResponseStatus; import io.vertx.core.Future; @@ -17,14 +17,17 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.stubbing.Answer; import org.prebid.server.VertxTest; import org.prebid.server.exception.PreBidException; +import org.prebid.server.execution.file.FileProcessor; import org.prebid.server.execution.retry.FixedIntervalRetryPolicy; import org.prebid.server.execution.retry.RetryPolicy; import java.io.File; +import java.util.concurrent.Callable; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatNullPointerException; @@ -57,7 +60,8 @@ public class RemoteFileSyncerTest extends VertxTest { private static final String TMP_FILE_PATH = String.join(File.separator, "tmp", "fake", "path", "to", "file.pdf"); private static final String DIR_PATH = String.join(File.separator, "fake", "path", "to"); private static final Long FILE_SIZE = 2131242L; - @Mock + + @Mock(strictness = LENIENT) private Vertx vertx; @Mock(strictness = LENIENT) @@ -67,7 +71,7 @@ public class RemoteFileSyncerTest extends VertxTest { private HttpClient httpClient; @Mock(strictness = LENIENT) - private RemoteFileProcessor remoteFileProcessor; + private FileProcessor fileProcessor; @Mock private AsyncFile asyncFile; @@ -85,30 +89,38 @@ public class RemoteFileSyncerTest extends VertxTest { @BeforeEach public void setUp() { when(vertx.fileSystem()).thenReturn(fileSystem); - remoteFileSyncer = new RemoteFileSyncer(remoteFileProcessor, SOURCE_URL, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, + given(vertx.executeBlocking(Mockito.>any())).willAnswer(invocation -> { + try { + return Future.succeededFuture(((Callable) invocation.getArgument(0)).call()); + } catch (Throwable e) { + return Future.failedFuture(e); + } + }); + + remoteFileSyncer = new RemoteFileSyncer(fileProcessor, SOURCE_URL, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, TIMEOUT, 0, httpClient, vertx); } @Test public void shouldThrowNullPointerExceptionWhenIllegalArgumentsWhenNullArguments() { assertThatNullPointerException().isThrownBy( - () -> new RemoteFileSyncer(remoteFileProcessor, SOURCE_URL, null, TMP_FILE_PATH, RETRY_POLICY, TIMEOUT, + () -> new RemoteFileSyncer(fileProcessor, SOURCE_URL, null, TMP_FILE_PATH, RETRY_POLICY, TIMEOUT, UPDATE_INTERVAL, httpClient, vertx)); assertThatNullPointerException().isThrownBy( - () -> new RemoteFileSyncer(remoteFileProcessor, SOURCE_URL, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, + () -> new RemoteFileSyncer(fileProcessor, SOURCE_URL, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, TIMEOUT, UPDATE_INTERVAL, null, vertx)); assertThatNullPointerException().isThrownBy( - () -> new RemoteFileSyncer(remoteFileProcessor, SOURCE_URL, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, + () -> new RemoteFileSyncer(fileProcessor, SOURCE_URL, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, TIMEOUT, UPDATE_INTERVAL, httpClient, null)); } @Test public void shouldThrowIllegalArgumentExceptionWhenIllegalArguments() { assertThatIllegalArgumentException().isThrownBy( - () -> new RemoteFileSyncer(remoteFileProcessor, null, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, + () -> new RemoteFileSyncer(fileProcessor, null, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, TIMEOUT, UPDATE_INTERVAL, httpClient, vertx)); assertThatIllegalArgumentException().isThrownBy( - () -> new RemoteFileSyncer(remoteFileProcessor, "bad url", FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, + () -> new RemoteFileSyncer(fileProcessor, "bad url", FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, TIMEOUT, UPDATE_INTERVAL, httpClient, vertx)); } @@ -119,7 +131,7 @@ public void creteShouldCreateDirWithWritePermissionIfDirNotExist() { when(fileSystem.existsBlocking(eq(DIR_PATH))).thenReturn(false); // when - new RemoteFileSyncer(remoteFileProcessor, SOURCE_URL, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, TIMEOUT, + new RemoteFileSyncer(fileProcessor, SOURCE_URL, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, TIMEOUT, UPDATE_INTERVAL, httpClient, vertx); // then @@ -136,7 +148,7 @@ public void createShouldCreateDirWithWritePermissionIfItsNotDir() { when(fileProps.isDirectory()).thenReturn(false); // when - new RemoteFileSyncer(remoteFileProcessor, SOURCE_URL, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, TIMEOUT, + new RemoteFileSyncer(fileProcessor, SOURCE_URL, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, TIMEOUT, UPDATE_INTERVAL, httpClient, vertx); // then @@ -151,7 +163,7 @@ public void createShouldThrowPreBidExceptionWhenPropsThrowException() { when(fileSystem.propsBlocking(eq(DIR_PATH))).thenThrow(FileSystemException.class); // when and then - assertThatThrownBy(() -> new RemoteFileSyncer(remoteFileProcessor, SOURCE_URL, FILE_PATH, TMP_FILE_PATH, + assertThatThrownBy(() -> new RemoteFileSyncer(fileProcessor, SOURCE_URL, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, TIMEOUT, UPDATE_INTERVAL, httpClient, vertx)) .isInstanceOf(PreBidException.class); } @@ -167,14 +179,14 @@ public void syncForFilepathShouldNotTriggerServiceWhenCantCheckIfUsableFileExist // then verify(fileSystem).exists(eq(FILE_PATH)); - verifyNoInteractions(remoteFileProcessor); + verifyNoInteractions(fileProcessor); verifyNoInteractions(httpClient); } @Test public void syncForFilepathShouldNotUpdateWhenHeadRequestReturnInvalidHead() { // given - remoteFileSyncer = new RemoteFileSyncer(remoteFileProcessor, SOURCE_URL, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, + remoteFileSyncer = new RemoteFileSyncer(fileProcessor, SOURCE_URL, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, TIMEOUT, UPDATE_INTERVAL, httpClient, vertx); givenTriggerUpdate(); @@ -194,7 +206,7 @@ public void syncForFilepathShouldNotUpdateWhenHeadRequestReturnInvalidHead() { // then verify(fileSystem, times(2)).exists(eq(FILE_PATH)); verify(httpClient).request(any()); - verify(remoteFileProcessor).setDataPath(any()); + verify(fileProcessor).setDataPath(any()); verify(fileSystem, never()).move(eq(TMP_FILE_PATH), eq(FILE_PATH), any(), any()); verify(vertx).setPeriodic(eq(UPDATE_INTERVAL), any()); verifyNoMoreInteractions(httpClient); @@ -203,7 +215,7 @@ public void syncForFilepathShouldNotUpdateWhenHeadRequestReturnInvalidHead() { @Test public void syncForFilepathShouldNotUpdateWhenPropsIsFailed() { // given - remoteFileSyncer = new RemoteFileSyncer(remoteFileProcessor, SOURCE_URL, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, + remoteFileSyncer = new RemoteFileSyncer(fileProcessor, SOURCE_URL, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, TIMEOUT, UPDATE_INTERVAL, httpClient, vertx); givenTriggerUpdate(); @@ -228,7 +240,7 @@ public void syncForFilepathShouldNotUpdateWhenPropsIsFailed() { verify(httpClient).request(any()); verify(httpClientResponse).getHeader(eq(HttpHeaders.CONTENT_LENGTH)); verify(fileSystem).props(eq(FILE_PATH)); - verify(remoteFileProcessor).setDataPath(any()); + verify(fileProcessor).setDataPath(any()); verify(fileSystem, never()).move(eq(TMP_FILE_PATH), eq(FILE_PATH), any(CopyOptions.class)); verify(vertx).setPeriodic(eq(UPDATE_INTERVAL), any()); verifyNoMoreInteractions(httpClient); @@ -237,7 +249,7 @@ public void syncForFilepathShouldNotUpdateWhenPropsIsFailed() { @Test public void syncForFilepathShouldNotUpdateServiceWhenSizeEqualsContentLength() { // given - remoteFileSyncer = new RemoteFileSyncer(remoteFileProcessor, SOURCE_URL, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, + remoteFileSyncer = new RemoteFileSyncer(fileProcessor, SOURCE_URL, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, TIMEOUT, UPDATE_INTERVAL, httpClient, vertx); givenTriggerUpdate(); @@ -264,7 +276,7 @@ public void syncForFilepathShouldNotUpdateServiceWhenSizeEqualsContentLength() { verify(httpClient).request(any()); verify(httpClientResponse).getHeader(eq(HttpHeaders.CONTENT_LENGTH)); verify(fileSystem).props(eq(FILE_PATH)); - verify(remoteFileProcessor).setDataPath(any()); + verify(fileProcessor).setDataPath(any()); verify(fileSystem, never()).move(eq(TMP_FILE_PATH), eq(FILE_PATH), any(CopyOptions.class)); verify(vertx).setPeriodic(eq(UPDATE_INTERVAL), any()); verifyNoMoreInteractions(httpClient); @@ -274,7 +286,7 @@ public void syncForFilepathShouldNotUpdateServiceWhenSizeEqualsContentLength() { public void syncForFilepathShouldUpdateServiceWhenSizeNotEqualsContentLength() { // given remoteFileSyncer = new RemoteFileSyncer( - remoteFileProcessor, SOURCE_URL, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, + fileProcessor, SOURCE_URL, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, TIMEOUT, UPDATE_INTERVAL, httpClient, vertx); givenTriggerUpdate(); @@ -304,7 +316,7 @@ public void syncForFilepathShouldUpdateServiceWhenSizeNotEqualsContentLength() { given(fileSystem.move(anyString(), any(), any(CopyOptions.class))) .willReturn(Future.succeededFuture()); - given(remoteFileProcessor.setDataPath(anyString())) + given(fileProcessor.setDataPath(anyString())) .willReturn(Future.succeededFuture()); // when @@ -319,7 +331,7 @@ public void syncForFilepathShouldUpdateServiceWhenSizeNotEqualsContentLength() { verify(fileSystem).open(eq(TMP_FILE_PATH), any()); verify(asyncFile).close(); - verify(remoteFileProcessor, times(2)).setDataPath(any()); + verify(fileProcessor, times(2)).setDataPath(any()); verify(vertx).setPeriodic(eq(UPDATE_INTERVAL), any()); verify(fileSystem).move(eq(TMP_FILE_PATH), eq(FILE_PATH), any(CopyOptions.class)); verifyNoMoreInteractions(httpClient); @@ -347,7 +359,7 @@ public void syncForFilepathShouldRetryAfterFailedDownload() { verify(fileSystem, times(RETRY_COUNT + 1)).open(eq(TMP_FILE_PATH), any()); verifyNoInteractions(httpClient); - verifyNoInteractions(remoteFileProcessor); + verifyNoInteractions(fileProcessor); } @Test @@ -368,7 +380,7 @@ public void syncForFilepathShouldRetryWhenFileOpeningFailed() { .willAnswer(withSelfAndPassObjectToHandler(Future.succeededFuture())) .willAnswer(withSelfAndPassObjectToHandler(Future.failedFuture(new RuntimeException()))); - given(remoteFileProcessor.setDataPath(anyString())) + given(fileProcessor.setDataPath(anyString())) .willReturn(Future.succeededFuture()); // when @@ -379,13 +391,13 @@ public void syncForFilepathShouldRetryWhenFileOpeningFailed() { verify(fileSystem, times(RETRY_COUNT + 1)).delete(eq(TMP_FILE_PATH)); verifyNoInteractions(httpClient); - verifyNoInteractions(remoteFileProcessor); + verifyNoInteractions(fileProcessor); } @Test public void syncForFilepathShouldDownloadFilesAndNotUpdateWhenUpdatePeriodIsNotSet() { // given - given(remoteFileProcessor.setDataPath(anyString())) + given(fileProcessor.setDataPath(anyString())) .willReturn(Future.succeededFuture()); given(fileSystem.exists(anyString())) @@ -414,7 +426,7 @@ public void syncForFilepathShouldDownloadFilesAndNotUpdateWhenUpdatePeriodIsNotS verify(httpClient).request(any()); verify(asyncFile).close(); verify(httpClientResponse).statusCode(); - verify(remoteFileProcessor).setDataPath(any()); + verify(fileProcessor).setDataPath(any()); verify(fileSystem).move(eq(TMP_FILE_PATH), eq(FILE_PATH), any(CopyOptions.class)); verify(vertx, never()).setTimer(eq(UPDATE_INTERVAL), any()); verifyNoMoreInteractions(httpClient); @@ -452,7 +464,7 @@ public void syncForFilepathShouldRetryWhenTimeoutIsReached() { verify(httpClient, times(RETRY_COUNT + 1)).request(any()); verify(asyncFile, times(RETRY_COUNT + 1)).close(); - verifyNoInteractions(remoteFileProcessor); + verifyNoInteractions(fileProcessor); } @Test @@ -484,7 +496,7 @@ public void syncShouldNotSaveFileWhenServerRespondsWithNonOkStatusCode() { verify(httpClient).request(any()); verify(httpClientResponse).statusCode(); verify(httpClientResponse, never()).pipeTo(any()); - verify(remoteFileProcessor, never()).setDataPath(any()); + verify(fileProcessor, never()).setDataPath(any()); verify(vertx, never()).setTimer(eq(UPDATE_INTERVAL), any()); } @@ -492,7 +504,7 @@ public void syncShouldNotSaveFileWhenServerRespondsWithNonOkStatusCode() { public void syncShouldNotUpdateFileWhenServerRespondsWithNonOkStatusCode() { // given remoteFileSyncer = new RemoteFileSyncer( - remoteFileProcessor, SOURCE_URL, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, + fileProcessor, SOURCE_URL, FILE_PATH, TMP_FILE_PATH, RETRY_POLICY, TIMEOUT, UPDATE_INTERVAL, httpClient, vertx); givenTriggerUpdate(); @@ -528,7 +540,7 @@ private void givenTriggerUpdate() { given(fileSystem.exists(anyString())) .willReturn(Future.succeededFuture(true)); - given(remoteFileProcessor.setDataPath(anyString())) + given(fileProcessor.setDataPath(anyString())) .willReturn(Future.succeededFuture()); given(vertx.setPeriodic(eq(UPDATE_INTERVAL), any())) diff --git a/src/test/java/org/prebid/server/execution/TimeoutFactoryTest.java b/src/test/java/org/prebid/server/execution/timeout/TimeoutFactoryTest.java similarity index 97% rename from src/test/java/org/prebid/server/execution/TimeoutFactoryTest.java rename to src/test/java/org/prebid/server/execution/timeout/TimeoutFactoryTest.java index e38e4c7304d..9e4a140cb7b 100644 --- a/src/test/java/org/prebid/server/execution/TimeoutFactoryTest.java +++ b/src/test/java/org/prebid/server/execution/timeout/TimeoutFactoryTest.java @@ -1,4 +1,4 @@ -package org.prebid.server.execution; +package org.prebid.server.execution.timeout; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/src/test/java/org/prebid/server/execution/TimeoutTest.java b/src/test/java/org/prebid/server/execution/timeout/TimeoutTest.java similarity index 95% rename from src/test/java/org/prebid/server/execution/TimeoutTest.java rename to src/test/java/org/prebid/server/execution/timeout/TimeoutTest.java index c45589bc86a..c1c7dfd7ca3 100644 --- a/src/test/java/org/prebid/server/execution/TimeoutTest.java +++ b/src/test/java/org/prebid/server/execution/timeout/TimeoutTest.java @@ -1,4 +1,4 @@ -package org.prebid.server.execution; +package org.prebid.server.execution.timeout; import org.junit.jupiter.api.Test; diff --git a/src/test/java/org/prebid/server/floors/PriceFloorFetcherTest.java b/src/test/java/org/prebid/server/floors/PriceFloorFetcherTest.java index 59253e200a7..64a66c507c0 100644 --- a/src/test/java/org/prebid/server/floors/PriceFloorFetcherTest.java +++ b/src/test/java/org/prebid/server/floors/PriceFloorFetcherTest.java @@ -12,7 +12,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.prebid.server.VertxTest; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.floors.model.PriceFloorData; import org.prebid.server.floors.model.PriceFloorDebugProperties; import org.prebid.server.floors.model.PriceFloorField; diff --git a/src/test/java/org/prebid/server/geolocation/ConfigurationGeoLocationServiceTest.java b/src/test/java/org/prebid/server/geolocation/ConfigurationGeoLocationServiceTest.java index 945d292970f..05643ce0e57 100644 --- a/src/test/java/org/prebid/server/geolocation/ConfigurationGeoLocationServiceTest.java +++ b/src/test/java/org/prebid/server/geolocation/ConfigurationGeoLocationServiceTest.java @@ -6,7 +6,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.geolocation.model.GeoInfo; import org.prebid.server.geolocation.model.GeoInfoConfiguration; diff --git a/src/test/java/org/prebid/server/handler/CookieSyncHandlerTest.java b/src/test/java/org/prebid/server/handler/CookieSyncHandlerTest.java index e5c71464d05..0b6027fcc92 100644 --- a/src/test/java/org/prebid/server/handler/CookieSyncHandlerTest.java +++ b/src/test/java/org/prebid/server/handler/CookieSyncHandlerTest.java @@ -32,7 +32,7 @@ import org.prebid.server.cookie.model.PartitionedCookie; import org.prebid.server.cookie.proto.Uids; import org.prebid.server.exception.InvalidAccountConfigException; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.metric.Metrics; import org.prebid.server.privacy.ccpa.Ccpa; import org.prebid.server.privacy.gdpr.model.TcfContext; diff --git a/src/test/java/org/prebid/server/handler/NotificationEventHandlerTest.java b/src/test/java/org/prebid/server/handler/NotificationEventHandlerTest.java index 9f27a7dde1f..c386ca753ef 100644 --- a/src/test/java/org/prebid/server/handler/NotificationEventHandlerTest.java +++ b/src/test/java/org/prebid/server/handler/NotificationEventHandlerTest.java @@ -19,7 +19,7 @@ import org.prebid.server.analytics.reporter.AnalyticsReporterDelegator; import org.prebid.server.auction.model.Tuple2; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.model.CaseInsensitiveMultiMap; import org.prebid.server.model.HttpRequestContext; import org.prebid.server.settings.ApplicationSettings; diff --git a/src/test/java/org/prebid/server/handler/SetuidHandlerTest.java b/src/test/java/org/prebid/server/handler/SetuidHandlerTest.java index 5df909ebd78..95e5ad24ced 100644 --- a/src/test/java/org/prebid/server/handler/SetuidHandlerTest.java +++ b/src/test/java/org/prebid/server/handler/SetuidHandlerTest.java @@ -33,7 +33,7 @@ import org.prebid.server.cookie.proto.Uids; import org.prebid.server.exception.InvalidAccountConfigException; import org.prebid.server.exception.InvalidRequestException; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.metric.Metrics; import org.prebid.server.privacy.HostVendorTcfDefinerService; import org.prebid.server.privacy.gdpr.model.HostVendorTcfResponse; diff --git a/src/test/java/org/prebid/server/handler/VtrackHandlerTest.java b/src/test/java/org/prebid/server/handler/VtrackHandlerTest.java index e0f2e5a966c..0674ab1d1ce 100644 --- a/src/test/java/org/prebid/server/handler/VtrackHandlerTest.java +++ b/src/test/java/org/prebid/server/handler/VtrackHandlerTest.java @@ -21,7 +21,7 @@ import org.prebid.server.cache.proto.response.bid.BidCacheResponse; import org.prebid.server.cache.proto.response.bid.CacheObject; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.settings.ApplicationSettings; import org.prebid.server.settings.model.Account; import org.prebid.server.settings.model.AccountAuctionConfig; diff --git a/src/test/java/org/prebid/server/handler/openrtb2/AmpHandlerTest.java b/src/test/java/org/prebid/server/handler/openrtb2/AmpHandlerTest.java index 9f40ed1bc81..e22a9178e84 100644 --- a/src/test/java/org/prebid/server/handler/openrtb2/AmpHandlerTest.java +++ b/src/test/java/org/prebid/server/handler/openrtb2/AmpHandlerTest.java @@ -39,8 +39,8 @@ import org.prebid.server.exception.InvalidAccountConfigException; import org.prebid.server.exception.InvalidRequestException; import org.prebid.server.exception.UnauthorizedAccountException; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.log.HttpInteractionLogger; import org.prebid.server.metric.MetricName; import org.prebid.server.metric.Metrics; diff --git a/src/test/java/org/prebid/server/handler/openrtb2/AuctionHandlerTest.java b/src/test/java/org/prebid/server/handler/openrtb2/AuctionHandlerTest.java index c2a84bcc922..7ff40d09899 100644 --- a/src/test/java/org/prebid/server/handler/openrtb2/AuctionHandlerTest.java +++ b/src/test/java/org/prebid/server/handler/openrtb2/AuctionHandlerTest.java @@ -31,8 +31,8 @@ import org.prebid.server.exception.InvalidAccountConfigException; import org.prebid.server.exception.InvalidRequestException; import org.prebid.server.exception.UnauthorizedAccountException; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.log.HttpInteractionLogger; import org.prebid.server.metric.MetricName; import org.prebid.server.metric.Metrics; diff --git a/src/test/java/org/prebid/server/handler/openrtb2/VideoHandlerTest.java b/src/test/java/org/prebid/server/handler/openrtb2/VideoHandlerTest.java index fe59fb31fcc..5da93cd4c94 100644 --- a/src/test/java/org/prebid/server/handler/openrtb2/VideoHandlerTest.java +++ b/src/test/java/org/prebid/server/handler/openrtb2/VideoHandlerTest.java @@ -29,8 +29,8 @@ import org.prebid.server.cookie.UidsCookie; import org.prebid.server.exception.InvalidRequestException; import org.prebid.server.exception.UnauthorizedAccountException; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.metric.Metrics; import org.prebid.server.proto.response.VideoResponse; import org.prebid.server.settings.model.Account; diff --git a/src/test/java/org/prebid/server/health/GeoLocationHealthCheckerTest.java b/src/test/java/org/prebid/server/health/GeoLocationHealthCheckerTest.java index e7b8bff269e..b46abafac7e 100644 --- a/src/test/java/org/prebid/server/health/GeoLocationHealthCheckerTest.java +++ b/src/test/java/org/prebid/server/health/GeoLocationHealthCheckerTest.java @@ -9,7 +9,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.geolocation.GeoLocationService; import org.prebid.server.geolocation.model.GeoInfo; import org.prebid.server.health.model.StatusResponse; diff --git a/src/test/java/org/prebid/server/hooks/execution/HookStageExecutorTest.java b/src/test/java/org/prebid/server/hooks/execution/HookStageExecutorTest.java index 060855334cc..c2dba2efdfe 100644 --- a/src/test/java/org/prebid/server/hooks/execution/HookStageExecutorTest.java +++ b/src/test/java/org/prebid/server/hooks/execution/HookStageExecutorTest.java @@ -28,7 +28,7 @@ import org.prebid.server.auction.model.debug.DebugContext; import org.prebid.server.bidder.model.BidderBid; import org.prebid.server.bidder.model.BidderSeatBid; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.hooks.execution.model.EndpointExecutionPlan; import org.prebid.server.hooks.execution.model.ExecutionAction; import org.prebid.server.hooks.execution.model.ExecutionGroup; diff --git a/src/test/java/org/prebid/server/settings/CachingApplicationSettingsTest.java b/src/test/java/org/prebid/server/settings/CachingApplicationSettingsTest.java index d09df3327a8..1767491959a 100644 --- a/src/test/java/org/prebid/server/settings/CachingApplicationSettingsTest.java +++ b/src/test/java/org/prebid/server/settings/CachingApplicationSettingsTest.java @@ -8,8 +8,8 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.prebid.server.exception.InvalidRequestException; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.metric.MetricName; import org.prebid.server.metric.Metrics; import org.prebid.server.settings.model.Account; diff --git a/src/test/java/org/prebid/server/settings/DatabaseApplicationSettingsTest.java b/src/test/java/org/prebid/server/settings/DatabaseApplicationSettingsTest.java index bab03ea0bb8..86c72604150 100644 --- a/src/test/java/org/prebid/server/settings/DatabaseApplicationSettingsTest.java +++ b/src/test/java/org/prebid/server/settings/DatabaseApplicationSettingsTest.java @@ -8,8 +8,8 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.prebid.server.VertxTest; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.settings.helper.ParametrizedQueryHelper; import org.prebid.server.settings.model.Account; import org.prebid.server.settings.model.StoredDataResult; diff --git a/src/test/java/org/prebid/server/settings/EnrichingApplicationSettingsTest.java b/src/test/java/org/prebid/server/settings/EnrichingApplicationSettingsTest.java index aaa72b45756..f3180d3651e 100644 --- a/src/test/java/org/prebid/server/settings/EnrichingApplicationSettingsTest.java +++ b/src/test/java/org/prebid/server/settings/EnrichingApplicationSettingsTest.java @@ -8,7 +8,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.prebid.server.VertxTest; import org.prebid.server.activity.ActivitiesConfigResolver; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.floors.PriceFloorsConfigResolver; import org.prebid.server.json.JsonMerger; import org.prebid.server.settings.model.Account; diff --git a/src/test/java/org/prebid/server/settings/HttpApplicationSettingsTest.java b/src/test/java/org/prebid/server/settings/HttpApplicationSettingsTest.java index b2452e06cae..e3076ddbdfd 100644 --- a/src/test/java/org/prebid/server/settings/HttpApplicationSettingsTest.java +++ b/src/test/java/org/prebid/server/settings/HttpApplicationSettingsTest.java @@ -10,8 +10,8 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.prebid.server.VertxTest; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.settings.model.Account; import org.prebid.server.settings.model.AccountAuctionConfig; import org.prebid.server.settings.model.AccountPrivacyConfig; diff --git a/src/test/java/org/prebid/server/settings/S3ApplicationSettingsTest.java b/src/test/java/org/prebid/server/settings/S3ApplicationSettingsTest.java index 2f7c293f9f8..a702d71ab2e 100644 --- a/src/test/java/org/prebid/server/settings/S3ApplicationSettingsTest.java +++ b/src/test/java/org/prebid/server/settings/S3ApplicationSettingsTest.java @@ -13,7 +13,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.prebid.server.VertxTest; import org.prebid.server.exception.PreBidException; -import org.prebid.server.execution.Timeout; +import org.prebid.server.execution.timeout.Timeout; import org.prebid.server.settings.model.Account; import org.prebid.server.settings.model.StoredDataResult; import org.prebid.server.settings.model.StoredResponseDataResult; diff --git a/src/test/java/org/prebid/server/settings/service/DatabasePeriodicRefreshServiceTest.java b/src/test/java/org/prebid/server/settings/service/DatabasePeriodicRefreshServiceTest.java index d0010e7699c..1e1ffd37271 100644 --- a/src/test/java/org/prebid/server/settings/service/DatabasePeriodicRefreshServiceTest.java +++ b/src/test/java/org/prebid/server/settings/service/DatabasePeriodicRefreshServiceTest.java @@ -10,7 +10,7 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.stubbing.Answer; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.metric.MetricName; import org.prebid.server.metric.Metrics; import org.prebid.server.settings.CacheNotificationListener; diff --git a/src/test/java/org/prebid/server/vertx/database/BasicDatabaseClientTest.java b/src/test/java/org/prebid/server/vertx/database/BasicDatabaseClientTest.java index e182255df87..15c76f3b6c7 100644 --- a/src/test/java/org/prebid/server/vertx/database/BasicDatabaseClientTest.java +++ b/src/test/java/org/prebid/server/vertx/database/BasicDatabaseClientTest.java @@ -14,8 +14,8 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.metric.Metrics; import java.time.Clock; diff --git a/src/test/java/org/prebid/server/vertx/database/CircuitBreakerSecuredDatabaseClientTest.java b/src/test/java/org/prebid/server/vertx/database/CircuitBreakerSecuredDatabaseClientTest.java index fe6bc6c337b..abc2d8af479 100644 --- a/src/test/java/org/prebid/server/vertx/database/CircuitBreakerSecuredDatabaseClientTest.java +++ b/src/test/java/org/prebid/server/vertx/database/CircuitBreakerSecuredDatabaseClientTest.java @@ -14,8 +14,8 @@ import org.mockito.BDDMockito; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.prebid.server.execution.Timeout; -import org.prebid.server.execution.TimeoutFactory; +import org.prebid.server.execution.timeout.Timeout; +import org.prebid.server.execution.timeout.TimeoutFactory; import org.prebid.server.metric.Metrics; import java.time.Clock;