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
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
url = https://github.com/prefab-cloud/prefab-cloud.git
[submodule "integration-test-data"]
path = sdk/src/test/resources/shared-integration-test-data
url = https://github.com/prefab-cloud/prefab-cloud-integration-test-data.git
url = git@github.com:ReforgeHQ/integration-test-data.git
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
public class ConfigRuleEvaluator {

public static final String CURRENT_TIME_KEY = "prefab.current-time";
public static final String REFORGE_CURRENT_TIME_KEY = "reforge.current-time";
private static final Logger LOG = LoggerFactory.getLogger(ConfigRuleEvaluator.class);

private final ConfigStore configStore;
Expand Down Expand Up @@ -241,7 +242,7 @@ private Optional<Prefab.ConfigValue> prop(
}
}
//TODO: move this current time injection into a ContextResolver class?
if (CURRENT_TIME_KEY.equals(key)) {
if (CURRENT_TIME_KEY.equals(key) || REFORGE_CURRENT_TIME_KEY.equals(key)) {
return Optional.of(
Prefab.ConfigValue.newBuilder().setInt(System.currentTimeMillis()).build()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private Sdk buildClient(IntegrationTestClientOverrides clientOverrides) {
.getInitTimeoutSeconds()
.ifPresent(options::setInitializationTimeoutSec);
clientOverrides
.getPrefabApiUrl()
.getReforgeApiUrl()
.ifPresent(host -> options.setApiHosts(List.of(host)));
clientOverrides.getOnInitFailure().ifPresent(options::setOnInitializationFailure);
clientOverrides.getContextUploadMode().ifPresent(options::setContextUploadMode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class IntegrationTestClientOverrides {
private final Optional<String> namespace;
private final Optional<Integer> onNoDefault;
private final Optional<Integer> initTimeoutSeconds;
private final Optional<String> prefabApiUrl;
private final Optional<String> reforgeApiUrl;
private final Optional<Options.OnInitializationFailure> onInitFailure;
private final Optional<String> aggregator;
private final Optional<Options.CollectContextMode> contextUploadMode;
Expand All @@ -20,15 +20,15 @@ public IntegrationTestClientOverrides(
@JsonProperty("namespace") Optional<String> namespace,
@JsonProperty("on_no_default") Optional<Integer> onNoDefault,
@JsonProperty("initialization_timeout_sec") Optional<Integer> initTimeoutSeconds,
@JsonProperty("prefab_api_url") Optional<String> prefabApiUrl,
@JsonProperty("reforge_api_url") Optional<String> reforgeApiUrl,
@JsonProperty("on_init_failure") Optional<String> onInitFailure,
@JsonProperty("aggregator") Optional<String> aggregator,
@JsonProperty("context_upload_mode") Optional<String> contextUploadMode
) {
this.namespace = namespace;
this.onNoDefault = onNoDefault;
this.initTimeoutSeconds = initTimeoutSeconds;
this.prefabApiUrl = prefabApiUrl;
this.reforgeApiUrl = reforgeApiUrl;
this.onInitFailure =
onInitFailure.map(text -> {
if (":return".equals(text)) {
Expand Down Expand Up @@ -83,8 +83,8 @@ public Optional<Integer> getInitTimeoutSeconds() {
return initTimeoutSeconds;
}

public Optional<String> getPrefabApiUrl() {
return prefabApiUrl;
public Optional<String> getReforgeApiUrl() {
return reforgeApiUrl;
}

public Optional<Options.OnInitializationFailure> getOnInitFailure() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,44 @@ public void testTimeAfterRange() {
assertThat(eval.isMatch()).isFalse();
}

@Test
public void testReforgeCurrentTimeKey() {
// Test that reforge.current-time works the same as prefab.current-time
final Prefab.Criterion reforgeTimeCriterion = Prefab.Criterion
.newBuilder()
.setPropertyName(ConfigRuleEvaluator.REFORGE_CURRENT_TIME_KEY)
.setValueToMatch(
Prefab.ConfigValue.newBuilder().setIntRange(Prefab.IntRange.newBuilder().build())
)
.setOperator(Prefab.Criterion.CriterionOperator.IN_INT_RANGE)
.build();
final EvaluatedCriterion reforgeEval = evaluator
.evaluateCriterionMatch(reforgeTimeCriterion, LookupContext.EMPTY)
.stream()
.findFirst()
.get();
assertThat(reforgeEval.isMatch()).isTrue();

// Also test that we can use it with a specific time range that should not match current time
long pastTime = System.currentTimeMillis() - 60000; // 1 minute ago
final Prefab.Criterion pastRangeCriterion = Prefab.Criterion
.newBuilder()
.setPropertyName(ConfigRuleEvaluator.REFORGE_CURRENT_TIME_KEY)
.setValueToMatch(
Prefab.ConfigValue
.newBuilder()
.setIntRange(Prefab.IntRange.newBuilder().setStart(0).setEnd(pastTime).build())
)
.setOperator(Prefab.Criterion.CriterionOperator.IN_INT_RANGE)
.build();
final EvaluatedCriterion pastEval = evaluator
.evaluateCriterionMatch(pastRangeCriterion, LookupContext.EMPTY)
.stream()
.findFirst()
.get();
assertThat(pastEval.isMatch()).isFalse();
}

public static Stream<Arguments> comparisonArguments() {
return Stream.of(
Arguments.of(
Expand Down
Loading