Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
EXP-660: Make priority comparison a class method
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharygoodwin committed Jun 13, 2024
1 parent a9ea605 commit 0ae13b3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import java.util.stream.IntStream;

import static com.indeed.proctor.common.ProctorUtils.UNITLESS_ALLOCATION_IDENTIFIER;
import static com.indeed.proctor.common.model.PayloadExperimentConfig.isHigherPriority;

/**
* The sole entry point for client applications determining the test buckets for a particular
Expand Down Expand Up @@ -562,7 +561,8 @@ private void attemptStoringProperty(
testChoosers.get(testName).getTestDefinition().getPayloadExperimentConfig();
// store property if it has higher priority than the currently stored property
try {
if (isHigherPriority(currPayloadConfig, newPayloadConfig)) {
if (currPayloadConfig == null
|| currPayloadConfig.isHigherPriorityThan(newPayloadConfig)) {
testProperties.put(
field.getKey(),
PayloadProperty.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ public String toString() {
+ '}';
}

public static boolean isHigherPriority(
final PayloadExperimentConfig payloadConfig,
final PayloadExperimentConfig otherPayloadConfig) {
return payloadConfig != null
&& payloadConfig.getPriority() != null
&& otherPayloadConfig != null
&& otherPayloadConfig.getPriority() != null
&& Long.parseLong(payloadConfig.getPriority())
< Long.parseLong(otherPayloadConfig.getPriority());
public boolean isHigherPriorityThan(final PayloadExperimentConfig otherPayloadConfig) {
final long currPriority =
this.getPriority() == null ? Long.MIN_VALUE : Long.parseLong(this.getPriority());
final long otherPriority =
otherPayloadConfig == null || otherPayloadConfig.getPriority() == null
? Long.MIN_VALUE
: Long.parseLong(otherPayloadConfig.getPriority());
return currPriority < otherPriority;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

import java.util.List;

import static java.util.Collections.*;
import static java.util.Collections.EMPTY_LIST;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static java.util.Collections.emptySet;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;

Expand Down

0 comments on commit 0ae13b3

Please sign in to comment.