Skip to content

Commit

Permalink
refactos code style
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgeniiMunin committed Aug 22, 2024
1 parent 197f44f commit b4bf1bd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 429 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,6 @@ private List<ThrottlingMessage> extractThrottlingMessages(
final ObjectNode impExt = imp.getExt();
final JsonNode bidderNode = extImpPrebid(impExt.get("prebid")).getBidder();

final List<ThrottlingMessage> throttlingImpMessages = new ArrayList<>();

final String ipv4 = Optional.ofNullable(bidRequest.getDevice())
.map(Device::getIp)
.orElse(null);
Expand All @@ -417,6 +415,7 @@ private List<ThrottlingMessage> extractThrottlingMessages(
throw new PreBidException("Failed to get country for IP", e);
}

final List<ThrottlingMessage> throttlingImpMessages = new ArrayList<>();
if (bidderNode.isObject()) {
final ObjectNode bidders = (ObjectNode) bidderNode;
final Iterator<String> fieldNames = bidders.fieldNames();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -73,7 +72,7 @@ public class GreenbidsRealTimeDataProcessedAuctionRequestHookTest {

private static final String THRESHOLDS_CACHE_KEY_PREFIX = "throttlingThresholds_";

private GreenbidsRealTimeDataProcessedAuctionRequestHook hook;
private GreenbidsRealTimeDataProcessedAuctionRequestHook target;

private JacksonMapper jacksonMapper;

Expand All @@ -95,7 +94,7 @@ public void setUp() {
thresholdsCacheWithExpiration = Caffeine.newBuilder()
.expireAfterWrite(CACHE_EXPIRATION_MINUTES, TimeUnit.MINUTES)
.build();
hook = new GreenbidsRealTimeDataProcessedAuctionRequestHook(
target = new GreenbidsRealTimeDataProcessedAuctionRequestHook(
mapper,
modelCacheWithExpiration,
thresholdsCacheWithExpiration,
Expand All @@ -120,7 +119,7 @@ public void setUp() {
}

@Test
public void shouldExitEarlyIfPartnerNotActivatedInBidRequest() throws IOException, OrtException {
public void shouldExitEarlyWhenPartnerNotActivatedInBidRequest() throws IOException, OrtException {
// given
final Banner banner = givenBanner();

Expand All @@ -142,7 +141,7 @@ public void shouldExitEarlyIfPartnerNotActivatedInBidRequest() throws IOExceptio
thresholdCache.getCache().put("throttlingThresholds_test-pbuid", givenThrottlingThresholds());

// when
final Future<InvocationResult<AuctionRequestPayload>> future = hook
final Future<InvocationResult<AuctionRequestPayload>> future = target
.call(null, invocationContext);
final InvocationResult<AuctionRequestPayload> result = future.result();
final BidRequest resultBidRequest = result
Expand All @@ -165,7 +164,7 @@ public void shouldExitEarlyIfPartnerNotActivatedInBidRequest() throws IOExceptio
}

@Test
public void shouldExitEarlyIfThresholdIsNotAvailable() throws OrtException, IOException {
public void shouldExitEarlyWhenThresholdIsNotAvailable() throws OrtException, IOException {
// given
final Banner banner = givenBanner();

Expand All @@ -188,7 +187,7 @@ public void shouldExitEarlyIfThresholdIsNotAvailable() throws OrtException, IOEx
modelCache.getCache().put("onnxModelRunner_test-pbuid", givenOnnxModelRunner());

// when
final Future<InvocationResult<AuctionRequestPayload>> future = hook
final Future<InvocationResult<AuctionRequestPayload>> future = target
.call(null, invocationContext);
final InvocationResult<AuctionRequestPayload> result = future.result();
final BidRequest resultBidRequest = result
Expand All @@ -211,7 +210,7 @@ public void shouldExitEarlyIfThresholdIsNotAvailable() throws OrtException, IOEx
}

@Test
public void shouldExitEarlyIfModelIsNotAvailable() throws IOException {
public void shouldExitEarlyWhenModelIsNotAvailable() throws IOException {
// given
final Banner banner = givenBanner();

Expand All @@ -234,7 +233,7 @@ public void shouldExitEarlyIfModelIsNotAvailable() throws IOException {
thresholdCache.getCache().put("throttlingThresholds_test-pbuid", givenThrottlingThresholds());

// when
final Future<InvocationResult<AuctionRequestPayload>> future = hook
final Future<InvocationResult<AuctionRequestPayload>> future = target
.call(null, invocationContext);
final InvocationResult<AuctionRequestPayload> result = future.result();
final BidRequest resultBidRequest = result
Expand Down Expand Up @@ -283,7 +282,7 @@ public void shouldNotFilterBiddersAndReturnAnalyticsTagWhenExploration() throws
final AnalyticsResult expectedAnalyticsResult = expectedAnalyticsResult(true, true);

// when
final Future<InvocationResult<AuctionRequestPayload>> future = hook
final Future<InvocationResult<AuctionRequestPayload>> future = target
.call(null, invocationContext);
final InvocationResult<AuctionRequestPayload> result = future.result();
final BidRequest resultBidRequest = result
Expand Down Expand Up @@ -314,7 +313,7 @@ public void shouldNotFilterBiddersAndReturnAnalyticsTagWhenExploration() throws
}

@Test
public void shouldFilterBiddersBasedOnModelIfAnyFeatureNotAvailable() throws OrtException, IOException {
public void shouldFilterBiddersBasedOnModelWhenAnyFeatureNotAvailable() throws OrtException, IOException {
// given
final Banner banner = givenBanner();

Expand All @@ -341,7 +340,7 @@ public void shouldFilterBiddersBasedOnModelIfAnyFeatureNotAvailable() throws Ort
final AnalyticsResult expectedAnalyticsResult = expectedAnalyticsResult(false, false);

// when
final Future<InvocationResult<AuctionRequestPayload>> future = hook
final Future<InvocationResult<AuctionRequestPayload>> future = target
.call(null, invocationContext);
final InvocationResult<AuctionRequestPayload> result = future.result();
final BidRequest resultBidRequest = result
Expand Down Expand Up @@ -401,7 +400,7 @@ public void shouldFilterBiddersBasedOnModelResults() throws OrtException, IOExce
final AnalyticsResult expectedAnalyticsResult = expectedAnalyticsResult(false, false);

// when
final Future<InvocationResult<AuctionRequestPayload>> future = hook
final Future<InvocationResult<AuctionRequestPayload>> future = target
.call(null, invocationContext);
final InvocationResult<AuctionRequestPayload> result = future.result();
final BidRequest resultBidRequest = result
Expand Down Expand Up @@ -606,10 +605,10 @@ private static Ortb2ImpExtResult expectedOrtb2ImpExtResult(Boolean isExploration
}

private static ExplorationResult expectedExplorationResult(Boolean isExploration, Boolean isKeptInAuction) {
final Map<String, Boolean> keptInAuction = new HashMap<>();
keptInAuction.put("appnexus", isKeptInAuction);
keptInAuction.put("pubmatic", isKeptInAuction);
keptInAuction.put("rubicon", isKeptInAuction);
final Map<String, Boolean> keptInAuction = Map.of(
"appnexus", isKeptInAuction,
"pubmatic", isKeptInAuction,
"rubicon", isKeptInAuction);
return ExplorationResult.of(null, keptInAuction, isExploration);
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -162,26 +162,6 @@ public void requestShouldFailIfHttpRequestTimedOut(Vertx vertx, VertxTestContext
}));
}

@Test
public void requestShouldFailIfHttpResponseTimedOut(Vertx vertx, VertxTestContext context) {
// given
final BasicHttpClient httpClient = new BasicHttpClient(vertx, vertx.createHttpClient());
final int serverPort = 8888;

startServer(serverPort, 0L, 2000L);

// when
final Future<?> future = httpClient.get("http://localhost:" + serverPort, 1000L);

// then
future.onComplete(context.failing(e -> {
assertThat(e)
.isInstanceOf(TimeoutException.class)
.hasMessage("Timeout period of 1000ms has been exceeded");
context.completeNow();
}));
}

/**
* The server returns entire response or body with delay.
*/
Expand Down

0 comments on commit b4bf1bd

Please sign in to comment.