Verify adaptive API restoration and override ownership
This commit is contained in:
@@ -58,6 +58,7 @@ final class DistantTerrainBudget {
|
||||
void suspend() {
|
||||
if (setting != null && owned != null && java.util.Objects.equals(setting.getApiValue(), owned)) {
|
||||
setting.clearValue();
|
||||
HorizonLab.LOGGER.info("Adaptive terrain override released; effective runtime ratio: {}", setting.getValue());
|
||||
}
|
||||
owned = null;
|
||||
policy = setting == null ? null : new TerrainBudget(setting.getTrueValue());
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package dev.horizonlab.client;
|
||||
|
||||
import com.seibel.distanthorizons.api.DhApi;
|
||||
import com.seibel.distanthorizons.api.interfaces.config.IDhApiConfig;
|
||||
import com.seibel.distanthorizons.api.interfaces.config.IDhApiConfigValue;
|
||||
import com.seibel.distanthorizons.api.interfaces.config.client.IDhApiMultiThreadingConfig;
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
/** Exercise the actual adapter against the upstream API contracts, without a game process. */
|
||||
public final class DistantTerrainBudgetTest {
|
||||
private static Double override;
|
||||
private static double userValue = 0.5;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> T proxy(Class<T> type, java.lang.reflect.InvocationHandler handler) {
|
||||
return (T) Proxy.newProxyInstance(type.getClassLoader(), new Class<?>[]{type}, handler);
|
||||
}
|
||||
|
||||
private static void check(boolean value, String reason) { if (!value) throw new AssertionError(reason); }
|
||||
|
||||
public static void main(String[] args) {
|
||||
IDhApiConfigValue<?> value = proxy(IDhApiConfigValue.class, (p, method, values) -> switch (method.getName()) {
|
||||
case "getTrueValue" -> userValue;
|
||||
case "getValue" -> override == null ? userValue : override;
|
||||
case "getApiValue" -> override;
|
||||
case "getCanBeOverrodeByApi" -> true;
|
||||
case "setValue" -> { override = (Double) values[0]; yield true; }
|
||||
case "clearValue" -> { override = null; yield true; }
|
||||
default -> throw new AssertionError("Unexpected API call: " + method);
|
||||
});
|
||||
var threading = proxy(IDhApiMultiThreadingConfig.class, (p, method, values) -> value);
|
||||
DhApi.Delayed.configs = proxy(IDhApiConfig.class, (p, method, values) -> threading);
|
||||
|
||||
DistantTerrainBudget budget = new DistantTerrainBudget();
|
||||
budget.observe(1, 0, 16.667);
|
||||
budget.observe(3_000_000_001L, 40_000_000, 16.667);
|
||||
check(Math.abs(override - 0.325) < 1e-9, "Actual adapter applies the policy through the API");
|
||||
budget.suspend();
|
||||
check(override == null && userValue == 0.5, "Suspending releases only our temporary override");
|
||||
budget.observe(4_000_000_001L, 0, 16.667);
|
||||
budget.observe(7_000_000_001L, 40_000_000, 16.667);
|
||||
check(Math.abs(override - 0.325) < 1e-9, "Resuming resets stale frame observations and policy state");
|
||||
userValue = 0.1;
|
||||
budget.observe(8_000_000_001L, 40_000_000, 16.667);
|
||||
budget.observe(11_000_000_001L, 40_000_000, 16.667);
|
||||
check(override <= 0.1, "A changed user ceiling is honored");
|
||||
override = 0.7;
|
||||
budget.observe(12_000_000_001L, 40_000_000, 16.667);
|
||||
budget.suspend();
|
||||
check(override == 0.7 && budget.status().startsWith("yielded"), "Never clear another mod's changed override");
|
||||
budget = new DistantTerrainBudget();
|
||||
budget.observe(13_000_000_001L, 40_000_000, 16.667);
|
||||
check(override == 0.7 && budget.status().startsWith("yielded"), "Never acquire an existing override");
|
||||
System.out.println("Distant terrain API adapter tests passed");
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,14 @@ def build():
|
||||
argfile = BUILD / "javac.args"
|
||||
argfile.write_text("\n".join(json.dumps(arg) for arg in command) + "\n")
|
||||
subprocess.run(["javac", "@" + str(argfile)], cwd=ROOT, check=True)
|
||||
adapter_tests = BUILD / "adapter-tests"
|
||||
adapter_tests.mkdir(parents=True, exist_ok=True)
|
||||
test_classpath = os.pathsep.join(map(str, [classes, *jars]))
|
||||
subprocess.run(["javac", "--release", "25", "-proc:none", "-classpath", test_classpath,
|
||||
"-d", str(adapter_tests),
|
||||
str(SOURCE / "test/java/dev/horizonlab/client/DistantTerrainBudgetTest.java")], check=True)
|
||||
subprocess.run(["java", "-cp", os.pathsep.join([str(adapter_tests), test_classpath]),
|
||||
"dev.horizonlab.client.DistantTerrainBudgetTest"], check=True)
|
||||
output = ROOT / "dist" / f"horizon-lab-{lock['pack_version']}.jar"
|
||||
output.parent.mkdir(exist_ok=True)
|
||||
entries = {path.relative_to(classes).as_posix(): path.read_bytes() for path in classes.rglob("*.class")}
|
||||
|
||||
Reference in New Issue
Block a user