Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Hotfix: Remove unused storage payload field #126

Merged
merged 1 commit into from
Feb 26, 2024
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
11 changes: 2 additions & 9 deletions src/main/java/org/prebid/cache/handlers/PostCacheHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;

@Component
@Slf4j
Expand All @@ -52,7 +50,6 @@ public class PostCacheHandler extends CacheHandler {

private final ReactiveRepository<PayloadWrapper, String> repository;
private final CacheConfig config;
private final Supplier<Date> currentDateProvider;
private final Function<PayloadWrapper, Map<String, String>> payloadWrapperToMapTransformer = payload ->
ImmutableMap.of(UUID_KEY, payload.getId());
private final Map<String, WebClient> webClients = new HashMap<>();
Expand All @@ -64,7 +61,6 @@ public PostCacheHandler(final ReactiveRepository<PayloadWrapper, String> reposit
final CacheConfig config,
final MetricsRecorder metricsRecorder,
final PrebidServerResponseBuilder builder,
final Supplier<Date> currentDateProvider,
final CircuitBreaker webClientCircuitBreaker,
@Value("${sampling.rate:0.01}") final Double samplingRate) {

Expand All @@ -77,7 +73,6 @@ public PostCacheHandler(final ReactiveRepository<PayloadWrapper, String> reposit
config.getSecondaryUris().forEach(ip -> webClients.put(ip, WebClient.create(ip)));
}
this.builder = builder;
this.currentDateProvider = currentDateProvider;
this.metricTagPrefix = "write";
this.circuitBreaker = webClientCircuitBreaker;
}
Expand All @@ -96,7 +91,7 @@ public Mono<ServerResponse> save(final ServerRequest request) {
.prefix(config.getPrefix())
.expiry(adjustExpiry(payload.compareAndGetExpiry()))
.build())
.map(payloadWrapperTransformer(currentDateProvider))
.map(payloadWrapperTransformer())
.handle(this::validateUUID)
.handle(this::validateExpiry)
.concatMap(repository::save)
Expand All @@ -122,14 +117,13 @@ public Mono<ServerResponse> save(final ServerRequest request) {
return finalizeResult(responseMono, request, timerContext);
}

private Function<PayloadTransfer, PayloadWrapper> payloadWrapperTransformer(Supplier<Date> currentDateProvider) {
private Function<PayloadTransfer, PayloadWrapper> payloadWrapperTransformer() {
return transfer ->
new PayloadWrapper(
RandomUUID.extractUUID(transfer),
transfer.getPrefix(),
new Payload(transfer.getType(), transfer.getKey(), transfer.valueAsString()),
transfer.getExpiry(),
currentDateProvider.get(),
RandomUUID.isExternalUUID(transfer)
);
}
Expand Down Expand Up @@ -218,4 +212,3 @@ private Mono<RequestObject> getRequestBodyMono(final ServerRequest request) {
return request.bodyToMono(RequestObject.class);
}
}

16 changes: 0 additions & 16 deletions src/main/java/org/prebid/cache/helpers/CurrentDateProvider.java

This file was deleted.

3 changes: 0 additions & 3 deletions src/main/java/org/prebid/cache/model/PayloadWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import lombok.Value;
import org.prebid.cache.exceptions.PayloadWrapperPropertyException;

import java.util.Date;

@Value
@Builder
@RequiredArgsConstructor
Expand All @@ -16,7 +14,6 @@ public class PayloadWrapper {
Payload payload;

Long expiry;
Date lastModified;

transient boolean isExternalId;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package org.prebid.cache.builders;

import org.junit.jupiter.api.BeforeAll;
import org.prebid.cache.model.Payload;
import org.prebid.cache.model.PayloadWrapper;
import lombok.val;
import org.junit.jupiter.api.BeforeAll;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;

import java.util.Date;

import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8;
import static org.springframework.http.MediaType.APPLICATION_XML;

@SpringBootTest
public abstract class PayloadWrapperResponseTests
{
public abstract class PayloadWrapperResponseTests {
static PayloadWrapper jsonPayloadWrapper;
static PayloadWrapper jsonUTF8PayloadWrapper;
static PayloadWrapper xmlPayloadWrapper;
Expand Down Expand Up @@ -72,6 +68,6 @@ private static PayloadWrapper createPayloadWrapper(MediaType mediaType) {
}

final var payload = new Payload("json", "1234567890", payloadValue);
return new PayloadWrapper("","prefix", payload, 200L, new Date(), false);
return new PayloadWrapper("", "prefix", payload, 200L, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import reactor.test.StepVerifier;

import java.util.Collections;
import java.util.Date;
import java.util.function.Consumer;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -184,7 +183,7 @@ private static PayloadWrapper createPayloadWrapper(MediaType mediaType) {
}

final var payload = new Payload("json", "1234567890", payloadValue);
return new PayloadWrapper("", "prefix", payload, 200L, new Date(), false);
return new PayloadWrapper("", "prefix", payload, 200L, false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import reactor.core.publisher.Signal;
import reactor.test.StepVerifier;

import java.util.Date;
import java.util.function.Consumer;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
Expand All @@ -42,7 +41,6 @@
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
Expand Down Expand Up @@ -115,7 +113,7 @@ void testVerifyError() {
@Test
void testVerifyFetch() {
final var payload = new Payload("json", "2be04ba5-8f9b-4a1e-8100-d573c40312f8", "");
final var payloadWrapper = new PayloadWrapper("12", "prebid_", payload, 1800L, new Date(), true);
final var payloadWrapper = new PayloadWrapper("12", "prebid_", payload, 1800L, true);
given(repository.findById("prebid_a8db2208-d085-444c-9721-c1161d7f09ce")).willReturn(Mono.just(payloadWrapper));

final var requestMono = MockServerRequest.builder()
Expand Down
17 changes: 7 additions & 10 deletions src/test/java/org/prebid/cache/handlers/PostCacheHandlerTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.prebid.cache.builders.PrebidServerResponseBuilder;
import org.prebid.cache.config.CircuitBreakerPropertyConfiguration;
import org.prebid.cache.exceptions.DuplicateKeyException;
import org.prebid.cache.helpers.CurrentDateProvider;
import org.prebid.cache.metrics.MetricsRecorder;
import org.prebid.cache.metrics.MetricsRecorderTest;
import org.prebid.cache.model.Payload;
Expand Down Expand Up @@ -59,7 +58,6 @@
MetricsRecorderTest.class,
MetricsRecorder.class,
ApiConfig.class,
CurrentDateProvider.class,
CircuitBreakerPropertyConfiguration.class
})
@EnableConfigurationProperties
Expand Down Expand Up @@ -94,7 +92,6 @@ void testVerifyError() {
cacheConfig,
metricsRecorder,
builder,
currentDateProvider,
webClientCircuitBreaker,
samplingRate);
verifyJacksonError(handler);
Expand All @@ -118,12 +115,12 @@ public void teardown() {
void testVerifySave() {
final var payloadInner = new Payload("json", "2be04ba5-8f9b-4a1e-8100-d573c40312f8", "");
final var payloadWrapper = new PayloadWrapper("2be04ba5-8f9b-4a1e-8100-d573c40312f8", "prebid_", payloadInner
, 1800L, new Date(100), true);
, 1800L, true);
given(currentDateProvider.get()).willReturn(new Date(100));
given(repository.save(payloadWrapper)).willReturn(Mono.just(payloadWrapper));

final var handler = new PostCacheHandler(repository, cacheConfig, metricsRecorder, builder,
currentDateProvider, webClientCircuitBreaker, samplingRate);
webClientCircuitBreaker, samplingRate);

final var payload = new PayloadTransfer("json", "2be04ba5-8f9b-4a1e-8100-d573c40312f8", "", 1800L, null,
"prebid_");
Expand All @@ -148,15 +145,15 @@ void testVerifySave() {
void testSecondaryCacheSuccess() {
final var payloadInner = new Payload("json", "2be04ba5-8f9b-4a1e-8100-d573c40312f8", "");
final var payloadWrapper = new PayloadWrapper("2be04ba5-8f9b-4a1e-8100-d573c40312f8", "prebid_", payloadInner
, 1800L, new Date(100), true);
, 1800L, true);
given(currentDateProvider.get()).willReturn(new Date(100));
given(repository.save(payloadWrapper)).willReturn(Mono.just(payloadWrapper));

serverMock.stubFor(post(urlPathEqualTo("/cache"))
.willReturn(aResponse().withBody("{\"responses\":[{\"uuid\":\"2be04ba5-8f9b-4a1e-8100-d573c40312f8\"}]}")));

final var handler = new PostCacheHandler(repository, cacheConfig, metricsRecorder, builder,
currentDateProvider, webClientCircuitBreaker, samplingRate);
webClientCircuitBreaker, samplingRate);

final var payload = new PayloadTransfer("json", "2be04ba5-8f9b-4a1e-8100-d573c40312f8", "", 1800L, null,
"prebid_");
Expand Down Expand Up @@ -191,7 +188,7 @@ void testExternalUUIDInvalid() {
cacheConfig.getMinExpiry(), cacheConfig.getMaxExpiry(),
false, Collections.emptyList(), cacheConfig.getSecondaryCachePath(), 100, 100, "example.com", "http");
final var handler = new PostCacheHandler(repository, cacheConfigLocal, metricsRecorder, builder,
currentDateProvider, webClientCircuitBreaker, samplingRate);
webClientCircuitBreaker, samplingRate);

final var payload = new PayloadTransfer("json", "2be04ba5-8f9b-4a1e-8100-d573c40312f8", "", 1800L, null,
"prebid_");
Expand All @@ -216,7 +213,7 @@ void testExternalUUIDInvalid() {
void testUUIDDuplication() {
final var payloadInner = new Payload("json", "2be04ba5-8f9b-4a1e-8100-d573c40312f8", "");
final var payloadWrapper = new PayloadWrapper("2be04ba5-8f9b-4a1e-8100-d573c40312f8", "prebid_", payloadInner
, 1800L, new Date(100), true);
, 1800L, true);
given(currentDateProvider.get()).willReturn(new Date(100));
given(repository.save(payloadWrapper)).willReturn(Mono.just(payloadWrapper)).willReturn(Mono.error(new DuplicateKeyException("")));

Expand All @@ -225,7 +222,7 @@ void testUUIDDuplication() {
5, cacheConfig.getMaxExpiry(), cacheConfig.isAllowExternalUUID(),
Collections.emptyList(), cacheConfig.getSecondaryCachePath(), 100, 100, "example.com", "http");
final var handler = new PostCacheHandler(repository, cacheConfigLocal, metricsRecorder, builder,
currentDateProvider, webClientCircuitBreaker, samplingRate);
webClientCircuitBreaker, samplingRate);

final var payload = new PayloadTransfer("json", "2be04ba5-8f9b-4a1e-8100-d573c40312f8", "", 1800L, null,
"prebid_");
Expand Down
Loading