Add ServerLoadPatch, ServerStoppingPatch, and ServerTickPatch to enhance server lifecycle handling in GameServer. Include tests, update B42PatchSet, and integrate lifecycle management utilities.
This commit is contained in:
1 parent
600373dc61
commit
837367047c
11 files changed
+787
-3
No files matched your search
@@ -0,0 +1,54 @@
|
||||
package dev.overlord.zomboidforge.core;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class LifecycleTest
|
||||
{
|
||||
@Test
|
||||
void advancesInOrder()
|
||||
{
|
||||
Lifecycle lifecycle = new Lifecycle();
|
||||
assertEquals(Lifecycle.Phase.BOOTING, lifecycle.phase());
|
||||
|
||||
lifecycle.loaded();
|
||||
assertEquals(Lifecycle.Phase.LOADED, lifecycle.phase());
|
||||
|
||||
lifecycle.started();
|
||||
assertEquals(Lifecycle.Phase.RUNNING, lifecycle.phase());
|
||||
|
||||
assertTrue(lifecycle.stopping());
|
||||
assertEquals(Lifecycle.Phase.STOPPING, lifecycle.phase());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsSkippedOrRepeatedPhases()
|
||||
{
|
||||
Lifecycle lifecycle = new Lifecycle();
|
||||
|
||||
IllegalStateException e = assertThrows(IllegalStateException.class, lifecycle::started);
|
||||
assertEquals("Cannot enter phase 'RUNNING' from 'BOOTING', only from 'LOADED'.", e.getMessage());
|
||||
assertEquals(Lifecycle.Phase.BOOTING, lifecycle.phase());
|
||||
|
||||
lifecycle.loaded();
|
||||
assertThrows(IllegalStateException.class, lifecycle::loaded);
|
||||
assertEquals(Lifecycle.Phase.LOADED, lifecycle.phase());
|
||||
}
|
||||
|
||||
@Test
|
||||
void stopsFromAnyPhaseOnce()
|
||||
{
|
||||
Lifecycle booting = new Lifecycle();
|
||||
assertTrue(booting.stopping());
|
||||
assertFalse(booting.stopping());
|
||||
|
||||
Lifecycle loaded = new Lifecycle();
|
||||
loaded.loaded();
|
||||
assertTrue(loaded.stopping());
|
||||
assertThrows(IllegalStateException.class, loaded::started);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user