Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<property name="format" value="System\.(out|err)\.print"/>
</module>
<module name="SuppressWarningsFilter" />
<module name="LineLength">
<property name="max" value="120"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|@see|//"/>
</module>
<module name="TreeWalker">
<module name="Indentation">
<property name="lineWrappingIndentation" value="8" />
Expand All @@ -31,10 +35,6 @@
<property name="allowMultipleEmptyLines" value="false" />
<property name="allowMultipleEmptyLinesInsideClassMembers" value="false" />
</module>
<module name="LineLength">
<property name="max" value="120"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|@see|//"/>
</module>
<module name="NoLineWrap"/>
<module name="ConstantName">
<property name="format" value="^([A-Z][A-Z0-9]*(_[A-Z0-9]+)*|logger)$" />
Expand Down
62 changes: 37 additions & 25 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<version>2.6.7</version>
<relativePath/>
</parent>

Expand All @@ -45,32 +45,33 @@
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven-source-plugin.version>3.0.1</maven-source-plugin.version>
<maven-clean-plugin.version>3.0.0</maven-clean-plugin.version>
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
<maven-clean-plugin.version>3.2.0</maven-clean-plugin.version>
<maven-surefire-plugin.version>3.0.0-M6</maven-surefire-plugin.version>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
<spring-boot-maven-plugin.version>2.1.2.RELEASE</spring-boot-maven-plugin.version>
<lettuce-core.version>6.0.1.RELEASE</lettuce-core.version>
<gson.version>2.8.5</gson.version>
<guava.version>23.0</guava.version>
<caffeine.version>2.8.8</caffeine.version>
<disruptor.version>3.4.2</disruptor.version>
<lombok.version>1.18.4</lombok.version>
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
<maven-release-plugin.version>3.0.0-M5</maven-release-plugin.version>
<rest-maven-plugin.version>0.1.4</rest-maven-plugin.version>
<spring-boot-maven-plugin.version>2.6.7</spring-boot-maven-plugin.version>
<lettuce-core.version>6.1.8.RELEASE</lettuce-core.version>
<gson.version>2.9.0</gson.version>
<guava.version>31.1-jre</guava.version>
<caffeine.version>3.0.6</caffeine.version>
<disruptor.version>3.4.4</disruptor.version>
<lombok.version>1.18.24</lombok.version>
<metrics-graphite.version>4.0.2</metrics-graphite.version>
<javax.el-api.version>3.0.0</javax.el-api.version>
<rest-maven-plugin.version>0.1.4</rest-maven-plugin.version>
<reflections.version>0.9.11</reflections.version>
<equals-verifier.version>3.1.3</equals-verifier.version>
<aerospike-client.version>4.3.0</aerospike-client.version>
<reactor-extra.version>3.2.2.RELEASE</reactor-extra.version>
<wiremock.version>2.11.0</wiremock.version>
<checkstyle-plugin.version>3.1.0</checkstyle-plugin.version>
<checkstyle.version>8.22</checkstyle.version>
<jacoco-plugin.version>0.8.2</jacoco-plugin.version>
<awaitility.version>3.0.0</awaitility.version>
<resilience4j.version>0.13.2</resilience4j.version>
<log4j2.version>2.17.1</log4j2.version> <!-- Workaround for CVE-2021-44832-->
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
<reflections.version>0.10.2</reflections.version>
<equals-verifier.version>3.10</equals-verifier.version>
<aerospike-client.version>5.1.11</aerospike-client.version>
<reactor-extra.version>3.4.8</reactor-extra.version>
<wiremock.version>2.27.2</wiremock.version>
<checkstyle-plugin.version>3.1.2</checkstyle-plugin.version>
<checkstyle.version>10.2</checkstyle.version>
<jacoco-plugin.version>0.8.8</jacoco-plugin.version>
<awaitility.version>4.2.0</awaitility.version>
<resilience4j.version>1.7.1</resilience4j.version>
<log4j2.version>2.17.2</log4j2.version>
<javax.validation-api>2.0.1.Final</javax.validation-api>

<!-- Functional Tests -->
<kotest.version>5.3.0</kotest.version>
Expand Down Expand Up @@ -134,6 +135,11 @@
<artifactId>caffeine</artifactId>
<version>${caffeine.version}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>${javax.validation-api}</version>
</dependency>
<!-- Needed for Async Logging with Log4j 2 -->
<dependency>
<groupId>com.lmax</groupId>
Expand Down Expand Up @@ -235,6 +241,12 @@
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core-jvm</artifactId>
<version>1.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.kotest</groupId>
<artifactId>kotest-runner-junit5-jvm</artifactId>
Expand Down Expand Up @@ -564,7 +576,7 @@
</pluginRepository>
<pluginRepository>
<id>mvnrepository</id>
<url>http://repo1.maven.org/maven2</url>
<url>https://repo1.maven.org/maven2</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.github.resilience4j.circuitbreaker.CircuitBreaker;
import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig;
import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry;
import io.github.resilience4j.circuitbreaker.monitoring.health.CircuitBreakerHealthIndicator;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand All @@ -29,11 +28,12 @@ public class CircuitBreakerPropertyConfiguration {

@Bean
CircuitBreakerConfig config() {
int slidingWindowSize = getClosedStateCallsNumber();
return CircuitBreakerConfig.custom()
.failureRateThreshold(getFailureRateThreshold())
.waitDurationInOpenState(Duration.ofMillis(getOpenStateDuration()))
.ringBufferSizeInHalfOpenState(getHalfOpenStateCallsNumber())
.ringBufferSizeInClosedState(getClosedStateCallsNumber())
.permittedNumberOfCallsInHalfOpenState(getHalfOpenStateCallsNumber())
.slidingWindow(slidingWindowSize, slidingWindowSize, CircuitBreakerConfig.SlidingWindowType.COUNT_BASED)
.build();
}

Expand All @@ -46,9 +46,4 @@ CircuitBreakerRegistry registry() {
CircuitBreaker circuitBreaker() {
return registry().circuitBreaker(CIRCUIT_BREAKER_NAME, config());
}

@Bean
CircuitBreakerHealthIndicator healthIndicator() {
return new CircuitBreakerHealthIndicator(circuitBreaker());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Mono;
import reactor.retry.Retry;
import reactor.util.retry.Retry;

import javax.validation.constraints.NotNull;
import java.time.Duration;
Expand Down Expand Up @@ -65,18 +65,18 @@ public Mono<PayloadWrapper> save(final PayloadWrapper wrapper) {
}

return Mono.<String>create(sink -> client.put(eventLoops.next(),
new AerospikeWriteListener(sink, normalizedId), policy,
new Key(configuration.getNamespace(), "", normalizedId),
new Bin(BIN_NAME, Json.toJson(wrapper)))).map(payload -> wrapper)
new AerospikeWriteListener(sink, normalizedId), policy,
new Key(configuration.getNamespace(), "", normalizedId),
new Bin(BIN_NAME, Json.toJson(wrapper)))).map(payload -> wrapper)
.retryWhen(getRetryPolicy())
.onErrorResume(this::handleAerospikeError);
}

@Override
public Mono<PayloadWrapper> findById(String id) {
return Mono.<String>create(sink -> client.get(eventLoops.next(),
new AerospikeReadListener(sink, id),
policy, new Key(configuration.getNamespace(), "", id)))
new AerospikeReadListener(sink, id),
policy, new Key(configuration.getNamespace(), "", id)))
.map(json -> Json.createPayloadFromJson(json, PayloadWrapper.class))
.retryWhen(getRetryPolicy())
.onErrorResume(this::handleAerospikeError);
Expand All @@ -96,15 +96,16 @@ private List<Integer> getRetryCodes() {
return Arrays.asList(ResultCode.GENERATION_ERROR, ResultCode.KEY_NOT_FOUND_ERROR);
}

private Retry<Object> getRetryPolicy() {
Duration firstBackoff = Duration.ofMillis(configuration.getFirstBackoff());
private Retry getRetryPolicy() {
Duration minBackoff = Duration.ofMillis(configuration.getFirstBackoff());
Duration maxBackoff = Duration.ofMillis(configuration.getMaxBackoff());
long maxAttempts = configuration.getMaxRetry();

return Retry.onlyIf(context -> context.exception() instanceof AerospikeException
&& getRetryCodes().contains(((AerospikeException) context.exception()).getResultCode())
).doOnRetry(context -> log.warn("Retrying context {}", context))
.retryMax(configuration.getMaxRetry())
.exponentialBackoffWithJitter(firstBackoff, maxBackoff);
return Retry.backoff(maxAttempts, minBackoff)
.maxBackoff(maxBackoff)
.filter(e -> e instanceof AerospikeException
&& getRetryCodes().contains(((AerospikeException) e).getResultCode()))
.doAfterRetry(signal -> log.warn("Retrying context {}", signal.retryContextView()));
}

private <T> Mono<T> handleAerospikeError(Throwable throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class GeneralCacheSpec : ShouldSpec({
// and: Request object
val requestObject = RequestObject.getDefaultJsonRequestObject()

// and: POST cache endpoint is called
// when: POST cache endpoint is called
val exception = shouldThrowExactly<ApiException> { prebidCacheApi.postCache(requestObject) }

// then: Internal Server Exception is thrown
Expand All @@ -127,8 +127,11 @@ class GeneralCacheSpec : ShouldSpec({
BaseSpec.prebidCacheConfig.getCacheTimeoutConfig(requestTimeoutMs)
)

// and: GET cache endpoint is called
val exception = shouldThrowExactly<ApiException> { prebidCacheApi.getCache(getRandomUuid()) }
// and: POST cache endpoint is called
val postResponse = BaseSpec.getPrebidCacheApi().postCache(RequestObject.getDefaultJsonRequestObject())

// when: GET cache endpoint is called
val exception = shouldThrowExactly<ApiException> { prebidCacheApi.getCache(postResponse.responses[0].uuid) }

// then: Internal Server Exception is thrown
assertSoftly {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ProxyCacheHostSpec : ShouldSpec({
// then: Internal Server Error exception is thrown
assertSoftly {
exception.statusCode shouldBe INTERNAL_SERVER_ERROR.value()
exception.responseBody shouldContain "\"message\":\"$cacheHost: Temporary failure in name resolution\""
exception.responseBody shouldContain "\"message\":\"Failed to resolve '$cacheHost'"
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cors.allowCredentials=true
# cache
cache.prefix=prebid_
cache.expiry_sec=700
cache.timeout_ms=700
cache.timeout_ms=3000
cache.allow_external_UUID=true
cache.min_expiry=60
cache.max_expiry=28800
Expand Down