mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 08:14:45 +00:00
Add the warmUp lifecycle hook and LifecycleRunner.warmUp
This commit is contained in:
1 parent
f6c078aade
commit
3c05cfea0a
6 files changed
+97
-5
No files matched your search
@@ -28,6 +28,7 @@ class LifecycleRunnerTest {
|
||||
registry.registerLifecycle(new ModuleLifecycle() {
|
||||
public void packLoaded(PackResources resources, PackSettings settings) { record("loaded"); }
|
||||
public void worldStarted(PackWorld world) { record("started"); }
|
||||
public void warmUp(PackWorld world) { record("warmed"); }
|
||||
public void worldStopped(PackWorld world) { record("stopped"); }
|
||||
|
||||
private void record(String hook) {
|
||||
@@ -86,6 +87,45 @@ class LifecycleRunnerTest {
|
||||
assertEquals(List.of("stopped test:gamma", "stopped test:beta", "stopped test:alpha"), calls);
|
||||
}
|
||||
|
||||
@Test
|
||||
void warmsUpInModuleIdOrderAfterTheModulesStarted() {
|
||||
var calls = new ArrayList<String>();
|
||||
var runner = runner(module("test:zeta", calls, null), module("test:alpha", calls, null));
|
||||
try (var world = new TestWorld()) {
|
||||
runner.worldStarted(world);
|
||||
runner.warmUp(world);
|
||||
}
|
||||
|
||||
assertEquals(List.of("started test:alpha", "started test:zeta", "warmed test:alpha", "warmed test:zeta"), calls);
|
||||
}
|
||||
|
||||
@Test
|
||||
void everyModuleWarmsUpEvenWhenOneFailsAndEveryFailureIsReported() {
|
||||
var calls = new ArrayList<String>();
|
||||
var runner = runner(module("test:alpha", calls, "warmed"), module("test:beta", calls, null), module("test:gamma", calls, "warmed"));
|
||||
try (var world = new TestWorld()) {
|
||||
var failure = assertThrows(IllegalStateException.class, () -> runner.warmUp(world));
|
||||
assertTrue(failure.getMessage().startsWith("Module test:alpha from host classpath failed while warming up a world"),
|
||||
failure.getMessage());
|
||||
assertEquals(1, failure.getSuppressed().length);
|
||||
assertTrue(failure.getSuppressed()[0].getMessage().startsWith("Module test:gamma"));
|
||||
}
|
||||
|
||||
assertEquals(List.of("warmed test:alpha", "warmed test:beta", "warmed test:gamma"), calls);
|
||||
}
|
||||
|
||||
@Test
|
||||
void modulesWithoutAWarmUpHookWarmUpNothing() {
|
||||
var module = new IrisModule() {
|
||||
public ModuleInfo info() { return ModuleInfo.of("test:plain", "Plain", "1"); }
|
||||
public void install(StageGraph graph) {}
|
||||
public void register(FeatureRegistry registry) { registry.registerLifecycle(new ModuleLifecycle() {}); }
|
||||
};
|
||||
try (var world = new TestWorld()) {
|
||||
runner(module).warmUp(world);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void aFailedPackLoadNamesTheModuleAndSkipsTheRest() {
|
||||
var calls = new ArrayList<String>();
|
||||
|
||||
Reference in new issue
Block a user