mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-29 09:15:27 +00:00
Merge master into hydrology
This commit is contained in:
commit
52dae154bb
35 files changed
+3025
-1835
No files matched your search
+2
-2
@@ -1,6 +1,6 @@
|
||||
package art.arcane.iris.fixture;
|
||||
|
||||
import art.arcane.iris.Iris;
|
||||
import art.arcane.iris.IrisRuntime;
|
||||
import art.arcane.volmlib.nativelib.NativeAdapters;
|
||||
import art.arcane.iris.world.runtime.RuntimeInjection;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
@@ -138,7 +138,7 @@ public final class NativeLifecycleFixture extends JavaPlugin implements WorldRun
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
if (WorldCreatorCompat.persistentLevelRoot(TREASURE_KEY).exists()) {
|
||||
return Iris.instance.worldReconciler().loadWorld(ServerProperties.BUKKIT_YML, TREASURE_KEY.toString());
|
||||
return IrisRuntime.require().worldReconciler().loadWorld(ServerProperties.BUKKIT_YML, TREASURE_KEY.toString());
|
||||
}
|
||||
return runAsync(() -> {
|
||||
try {
|
||||
|
||||
@@ -148,16 +148,16 @@ public class FailedEnableLockTest {
|
||||
try (EnableFixture fixture = new EnableFixture(false)) {
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class, plugin::onEnable);
|
||||
assertTrue(failure.getMessage(), failure.getMessage().contains("already bound"));
|
||||
Field failed = Iris.class.getDeclaredField("enableFailed");
|
||||
Field failed = IrisRuntime.class.getDeclaredField("enableFailed");
|
||||
failed.setAccessible(true);
|
||||
assertTrue(failed.getBoolean(plugin));
|
||||
assertTrue(failed.getBoolean(plugin.runtime()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anUnsupportedServerWithIrisWorldsLocksInsteadOfDisablingIris() throws Exception {
|
||||
Iris plugin = plugin();
|
||||
set(plugin, "pendingWorldReplacements", mock(PendingWorldReplacementManager.class));
|
||||
set(IrisRuntime.class, plugin.runtime(), "pendingWorldReplacements", mock(PendingWorldReplacementManager.class));
|
||||
|
||||
try (EnableFixture fixture = new EnableFixture(true);
|
||||
MockedStatic<INMS> nms = mockStatic(INMS.class);
|
||||
@@ -208,18 +208,18 @@ public class FailedEnableLockTest {
|
||||
|
||||
/**
|
||||
* Paper builds plugins through its class loader, so the plugin under test is the real class with its fields
|
||||
* set by hand: the resolver getDefaultWorldGenerator delegates to, and whatever enable touches before failing.
|
||||
* set by hand: the runtime getDefaultWorldGenerator delegates to, and whatever enable touches before failing.
|
||||
*/
|
||||
private static Iris plugin() throws Exception {
|
||||
Iris plugin = mock(Iris.class, CALLS_REAL_METHODS);
|
||||
set(plugin, "generatorResolver", new IrisWorldGeneratorResolver(plugin));
|
||||
set(Iris.class, plugin, "runtime", new IrisRuntime(plugin));
|
||||
return plugin;
|
||||
}
|
||||
|
||||
private static void set(Iris plugin, String name, Object value) throws Exception {
|
||||
Field field = Iris.class.getDeclaredField(name);
|
||||
private static void set(Class<?> owner, Object target, String name, Object value) throws Exception {
|
||||
Field field = owner.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
field.set(plugin, value);
|
||||
field.set(target, value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-2
@@ -11,8 +11,8 @@ import static org.junit.Assert.assertTrue;
|
||||
public class IrisApiServiceDiscoveryTest {
|
||||
@Test
|
||||
public void bothApiServicesSatisfyTheServiceLoaderRule() {
|
||||
assertTrue(Iris.isConcreteImplementation(IrisTerrainSVC.class, IrisService.class));
|
||||
assertTrue(Iris.isConcreteImplementation(IrisApiEventSVC.class, IrisService.class));
|
||||
assertTrue(IrisRuntime.isConcreteImplementation(IrisTerrainSVC.class, IrisService.class));
|
||||
assertTrue(IrisRuntime.isConcreteImplementation(IrisApiEventSVC.class, IrisService.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-2
@@ -31,7 +31,7 @@ public class IrisBootstrapFailureContractTest {
|
||||
when(context.getLogger()).thenReturn(logger);
|
||||
when(context.getLifecycleManager()).thenReturn(manager);
|
||||
|
||||
IrisBootstrap.armStartupFailure(context, cause, eventType);
|
||||
IrisBootstrapSequence.armStartupFailure(context, cause, eventType);
|
||||
|
||||
assertSame(eventType, manager.eventType);
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class, manager::runCapturedHandler);
|
||||
@@ -47,7 +47,7 @@ public class IrisBootstrapFailureContractTest {
|
||||
IllegalStateException failure = new IllegalStateException("Iris world storage is unusable",
|
||||
new IOException("Invalid generation manifest: manifest.json"));
|
||||
|
||||
IrisBootstrap.armStartupFailure(context, failure, lifecycleEventType());
|
||||
IrisBootstrapSequence.armStartupFailure(context, failure, lifecycleEventType());
|
||||
|
||||
ArgumentCaptor<String> lines = ArgumentCaptor.forClass(String.class);
|
||||
verify(logger, atLeastOnce()).error(lines.capture());
|
||||
|
||||
+15
-15
@@ -44,7 +44,7 @@ public class IrisBootstrapWorldStorageContractTest {
|
||||
|
||||
IllegalStateException failure = assertThrows(
|
||||
IllegalStateException.class,
|
||||
() -> IrisBootstrap.requireUsableWorldStorage(startupPaths(serverRoot)));
|
||||
() -> IrisBootstrapSequence.requireUsableWorldStorage(startupPaths(serverRoot)));
|
||||
|
||||
assertTrue(failure.getMessage(), failure.getMessage().contains("world_iris_orphan2"));
|
||||
assertTrue(failure.getMessage(),
|
||||
@@ -64,7 +64,7 @@ public class IrisBootstrapWorldStorageContractTest {
|
||||
writeServerProperties(serverRoot);
|
||||
writeBukkitWorlds(serverRoot, "world_iris_husk");
|
||||
|
||||
IrisBootstrap.requireUsableWorldStorage(startupPaths(serverRoot));
|
||||
IrisBootstrapSequence.requireUsableWorldStorage(startupPaths(serverRoot));
|
||||
|
||||
assertTrue(MissingWorldStorageLog.hasWarned("world_iris_husk"));
|
||||
}
|
||||
@@ -83,8 +83,8 @@ public class IrisBootstrapWorldStorageContractTest {
|
||||
writeBukkitWorlds(serverRoot, "world_iris_husk");
|
||||
List<String> warnings = new ArrayList<>();
|
||||
|
||||
IrisBootstrap.quarantineWorthlessHusks(startupPaths(serverRoot), warnings::add);
|
||||
IrisBootstrap.requireUsableWorldStorage(startupPaths(serverRoot));
|
||||
IrisBootstrapSequence.quarantineWorthlessHusks(startupPaths(serverRoot), warnings::add);
|
||||
IrisBootstrapSequence.requireUsableWorldStorage(startupPaths(serverRoot));
|
||||
|
||||
assertFalse(Files.exists(serverRoot.resolve("world/dimensions/iris/husk")));
|
||||
assertEquals(1, warnings.size());
|
||||
@@ -106,7 +106,7 @@ public class IrisBootstrapWorldStorageContractTest {
|
||||
writeBukkitWorlds(serverRoot);
|
||||
List<String> warnings = new ArrayList<>();
|
||||
|
||||
IrisBootstrap.quarantineWorthlessHusks(startupPaths(serverRoot), warnings::add);
|
||||
IrisBootstrapSequence.quarantineWorthlessHusks(startupPaths(serverRoot), warnings::add);
|
||||
|
||||
assertFalse(Files.exists(serverRoot.resolve("world/dimensions/iris/husk")));
|
||||
assertEquals(1, warnings.size());
|
||||
@@ -121,13 +121,13 @@ public class IrisBootstrapWorldStorageContractTest {
|
||||
writeBukkitWorlds(serverRoot, "world_iris_kept");
|
||||
List<String> warnings = new ArrayList<>();
|
||||
|
||||
IrisBootstrap.quarantineWorthlessHusks(startupPaths(serverRoot), warnings::add);
|
||||
IrisBootstrapSequence.quarantineWorthlessHusks(startupPaths(serverRoot), warnings::add);
|
||||
|
||||
assertTrue(Files.isDirectory(serverRoot.resolve("world/dimensions/iris/kept")));
|
||||
assertTrue(warnings.isEmpty());
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
() -> IrisBootstrap.requireUsableWorldStorage(startupPaths(serverRoot)));
|
||||
() -> IrisBootstrapSequence.requireUsableWorldStorage(startupPaths(serverRoot)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,13 +142,13 @@ public class IrisBootstrapWorldStorageContractTest {
|
||||
writeBukkitWorlds(serverRoot, "world_iris_marked");
|
||||
List<String> warnings = new ArrayList<>();
|
||||
|
||||
IrisBootstrap.quarantineWorthlessHusks(startupPaths(serverRoot), warnings::add);
|
||||
IrisBootstrapSequence.quarantineWorthlessHusks(startupPaths(serverRoot), warnings::add);
|
||||
|
||||
assertTrue(Files.isDirectory(serverRoot.resolve("world/dimensions/iris/marked/iris/engine-data")));
|
||||
assertTrue(warnings.isEmpty());
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
() -> IrisBootstrap.requireUsableWorldStorage(startupPaths(serverRoot)));
|
||||
() -> IrisBootstrapSequence.requireUsableWorldStorage(startupPaths(serverRoot)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -158,7 +158,7 @@ public class IrisBootstrapWorldStorageContractTest {
|
||||
writeServerProperties(serverRoot);
|
||||
writeBukkitWorlds(serverRoot, "world_iris_orphan1");
|
||||
|
||||
IrisBootstrap.requireUsableWorldStorage(startupPaths(serverRoot));
|
||||
IrisBootstrapSequence.requireUsableWorldStorage(startupPaths(serverRoot));
|
||||
|
||||
assertTrue(MissingWorldStorageLog.hasWarned("world_iris_orphan1"));
|
||||
}
|
||||
@@ -170,7 +170,7 @@ public class IrisBootstrapWorldStorageContractTest {
|
||||
writeServerProperties(serverRoot);
|
||||
writeBukkitWorlds(serverRoot, "world_iris_moon");
|
||||
|
||||
IrisBootstrap.requireUsableWorldStorage(startupPaths(serverRoot));
|
||||
IrisBootstrapSequence.requireUsableWorldStorage(startupPaths(serverRoot));
|
||||
|
||||
assertFalse(MissingWorldStorageLog.hasWarned("world_iris_moon"));
|
||||
}
|
||||
@@ -190,7 +190,7 @@ public class IrisBootstrapWorldStorageContractTest {
|
||||
|
||||
IllegalStateException failure = assertThrows(
|
||||
IllegalStateException.class,
|
||||
() -> IrisBootstrap.requireUsableWorldStorage(startupPaths(serverRoot)));
|
||||
() -> IrisBootstrapSequence.requireUsableWorldStorage(startupPaths(serverRoot)));
|
||||
|
||||
assertTrue(failure.getMessage(),
|
||||
failure.getMessage().contains(serverRoot.toRealPath().resolve("world/dimensions/minecraft/overworld")
|
||||
@@ -210,7 +210,7 @@ public class IrisBootstrapWorldStorageContractTest {
|
||||
|
||||
IllegalStateException failure = assertThrows(
|
||||
IllegalStateException.class,
|
||||
() -> IrisBootstrap.requireUsableWorldStorage(startupPaths(serverRoot)));
|
||||
() -> IrisBootstrapSequence.requireUsableWorldStorage(startupPaths(serverRoot)));
|
||||
|
||||
assertTrue(failure.getMessage(), failure.getMessage().contains("Invalid generation manifest"));
|
||||
assertFalse(failure.getMessage(), failure.getMessage().contains("\n"));
|
||||
@@ -229,7 +229,7 @@ public class IrisBootstrapWorldStorageContractTest {
|
||||
|
||||
IllegalStateException failure = assertThrows(
|
||||
IllegalStateException.class,
|
||||
() -> IrisBootstrap.requireUsableWorldStorage(startupPaths(serverRoot)));
|
||||
() -> IrisBootstrapSequence.requireUsableWorldStorage(startupPaths(serverRoot)));
|
||||
|
||||
assertTrue(failure.getMessage(), failure.getMessage().contains("worlds.world.generator"));
|
||||
assertTrue(failure.getMessage(),
|
||||
@@ -247,7 +247,7 @@ public class IrisBootstrapWorldStorageContractTest {
|
||||
writeServerProperties(serverRoot);
|
||||
writeBukkitWorlds(serverRoot);
|
||||
|
||||
IrisBootstrap.requireUsableWorldStorage(startupPaths(serverRoot));
|
||||
IrisBootstrapSequence.requireUsableWorldStorage(startupPaths(serverRoot));
|
||||
}
|
||||
|
||||
private static BukkitStartupPaths startupPaths(Path serverRoot) throws Exception {
|
||||
|
||||
+5
-5
@@ -15,18 +15,18 @@ import static org.junit.Assert.assertNull;
|
||||
public class IrisDiagnosticLogLevelTest {
|
||||
@Test
|
||||
public void coreDiagnosticsKeepTheirSeverity() {
|
||||
assertEquals(Level.WARNING, Iris.diagnosticLevel(LogLevel.WARN));
|
||||
assertEquals(Level.SEVERE, Iris.diagnosticLevel(LogLevel.ERROR));
|
||||
assertEquals(Level.WARNING, IrisRuntime.diagnosticLevel(LogLevel.WARN));
|
||||
assertEquals(Level.SEVERE, IrisRuntime.diagnosticLevel(LogLevel.ERROR));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void informationalAndDebugMessagesStayOnTheInformationalPath() {
|
||||
assertNull(Iris.diagnosticLevel(LogLevel.INFO));
|
||||
assertNull(Iris.diagnosticLevel(LogLevel.DEBUG));
|
||||
assertNull(IrisRuntime.diagnosticLevel(LogLevel.INFO));
|
||||
assertNull(IrisRuntime.diagnosticLevel(LogLevel.DEBUG));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lifecycleNoticesReachThePluginLoggerAtInfo() {
|
||||
assertEquals(Level.INFO, Iris.diagnosticLevel(LogLevel.NOTICE));
|
||||
assertEquals(Level.INFO, IrisRuntime.diagnosticLevel(LogLevel.NOTICE));
|
||||
}
|
||||
}
|
||||
@@ -23,8 +23,8 @@ public class IrisDiagnosticsTest {
|
||||
public void serviceInitializationSkipsPackageHelperClasses() throws Exception {
|
||||
Class<?> registrar = Class.forName("art.arcane.iris.command.PaperCommandRegistrar");
|
||||
|
||||
assertFalse(Iris.isConcreteImplementation(registrar, IrisService.class));
|
||||
assertTrue(Iris.isConcreteImplementation(CommandSVC.class, IrisService.class));
|
||||
assertFalse(IrisRuntime.isConcreteImplementation(registrar, IrisService.class));
|
||||
assertTrue(IrisRuntime.isConcreteImplementation(CommandSVC.class, IrisService.class));
|
||||
// The service package is eagerly Class.forName-scanned by JarScanner at enable; a class
|
||||
// referencing Paper-only types there prints an NCDFE stack trace on plain Spigot.
|
||||
assertFalse(
|
||||
|
||||
@@ -9,10 +9,8 @@ import org.mockito.MockedStatic;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -53,9 +51,6 @@ public class IrisErrorReportingTest {
|
||||
IrisSettings previousSettings = IrisSettings.settings;
|
||||
PrintStream previousError = System.err;
|
||||
Iris plugin = mock(Iris.class);
|
||||
Field deferred = Iris.class.getDeclaredField("serverStopTeardownDeferred");
|
||||
deferred.setAccessible(true);
|
||||
deferred.set(plugin, new AtomicBoolean());
|
||||
File report = new File(temporaryFolder.getRoot(), "failure.txt");
|
||||
when(plugin.getDataFile(any(String[].class))).thenReturn(report);
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
|
||||
+46
-46
@@ -10,7 +10,6 @@ import art.arcane.iris.platform.bukkit.plugin.IrisService;
|
||||
import art.arcane.iris.platform.bukkit.plugin.VolmitPlugin;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.world.lifecycle.IrisRuntimeStatics;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
import art.arcane.iris.generation.runtime.GenerationSessionLease;
|
||||
import art.arcane.iris.generation.runtime.GenerationSessionManager;
|
||||
@@ -38,6 +37,7 @@ import org.mockito.MockedStatic;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
@@ -84,7 +84,7 @@ public class IrisShutdownMaintenanceTest {
|
||||
assertTrue(release.await(5, TimeUnit.SECONDS));
|
||||
return false;
|
||||
});
|
||||
setField(fixture.plugin, "serverShutdownBoundary", boundary);
|
||||
setField(fixture.runtime, "serverShutdownBoundary", boundary);
|
||||
fixture.quiesce();
|
||||
fixture.startFinisher();
|
||||
try {
|
||||
@@ -108,9 +108,9 @@ public class IrisShutdownMaintenanceTest {
|
||||
@Test
|
||||
public void missingShutdownBoundaryDoesNotAuthorizeResourceRelease() throws Exception {
|
||||
try (Fixture fixture = new Fixture()) {
|
||||
Method method = Iris.class.getDeclaredMethod("awaitServerShutdownBoundary");
|
||||
Method method = IrisRuntime.class.getDeclaredMethod("awaitServerShutdownBoundary");
|
||||
method.setAccessible(true);
|
||||
assertEquals(false, method.invoke(fixture.plugin));
|
||||
assertEquals(false, method.invoke(fixture.runtime));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ public class IrisShutdownMaintenanceTest {
|
||||
assertSame(fixture.plugin.getClass().getClassLoader(), invocation.getArgument(0));
|
||||
return null;
|
||||
}).when(fixture.binding).initializeLifecycle(fixture.plugin.getClass().getClassLoader());
|
||||
invoke(fixture.plugin, "initializeShutdownProtection");
|
||||
invoke(fixture.runtime, "initializeShutdownProtection");
|
||||
verify(fixture.binding).initializeLifecycle(fixture.plugin.getClass().getClassLoader());
|
||||
verify(fixture.binding, never()).injectBukkit();
|
||||
}
|
||||
@@ -190,7 +190,7 @@ public class IrisShutdownMaintenanceTest {
|
||||
try (Fixture fixture = new Fixture(); MockedStatic<Agent> agent = mockStatic(Agent.class)) {
|
||||
when(fixture.binding.supportsIrisWorldGeneration()).thenReturn(true);
|
||||
InvocationTargetException failure = assertThrows(InvocationTargetException.class,
|
||||
() -> invoke(fixture.plugin, "initializeShutdownProtection"));
|
||||
() -> invoke(fixture.runtime, "initializeShutdownProtection"));
|
||||
assertTrue(failure.getCause() instanceof IllegalStateException);
|
||||
verify(fixture.binding, never()).initializeLifecycle(fixture.plugin.getClass().getClassLoader());
|
||||
}
|
||||
@@ -208,8 +208,8 @@ public class IrisShutdownMaintenanceTest {
|
||||
IllegalStateException failure = new IllegalStateException("world hook teardown failed");
|
||||
fixture.nms.when(INMS::isBound).thenReturn(true);
|
||||
doThrow(failure).when(fixture.binding).uninjectBukkit();
|
||||
setField(fixture.plugin, "services", new KMap<Class<? extends IrisService>, IrisService>());
|
||||
setField(fixture.plugin, "enabledServices", List.of(service));
|
||||
setField(fixture.runtime, "services", new KMap<Class<? extends IrisService>, IrisService>());
|
||||
setField(fixture.runtime, "enabledServices", List.of(service));
|
||||
doAnswer(invocation -> {
|
||||
platforms.verify(IrisPlatforms::unbind);
|
||||
bukkitPlatform.verify(BukkitPlatform::releaseHost);
|
||||
@@ -257,8 +257,8 @@ public class IrisShutdownMaintenanceTest {
|
||||
IrisService service = mock(IrisService.class);
|
||||
IllegalStateException failure = new IllegalStateException("service teardown failed");
|
||||
doThrow(failure).when(service).onDisable();
|
||||
setField(fixture.plugin, "services", new KMap<Class<? extends IrisService>, IrisService>());
|
||||
setField(fixture.plugin, "enabledServices", List.of(service));
|
||||
setField(fixture.runtime, "services", new KMap<Class<? extends IrisService>, IrisService>());
|
||||
setField(fixture.runtime, "enabledServices", List.of(service));
|
||||
fixture.quiesce();
|
||||
fixture.finish(5L);
|
||||
verify(service).onDisable();
|
||||
@@ -293,7 +293,7 @@ public class IrisShutdownMaintenanceTest {
|
||||
assertTrue(started.await(5, TimeUnit.SECONDS));
|
||||
IllegalStateException failure = new IllegalStateException("post-shutdown callback failed");
|
||||
AtomicBoolean cleanupAttempted = new AtomicBoolean();
|
||||
KList<Runnable> callbacks = new KList<>();
|
||||
List<Runnable> callbacks = new ArrayList<>();
|
||||
callbacks.add(() -> { throw failure; });
|
||||
callbacks.add(() -> {
|
||||
cleanupAttempted.set(true);
|
||||
@@ -302,9 +302,7 @@ public class IrisShutdownMaintenanceTest {
|
||||
Field callbacksField = VolmitPlugin.class.getDeclaredField("postShutdown");
|
||||
callbacksField.setAccessible(true);
|
||||
callbacksField.set(fixture.plugin, callbacks);
|
||||
Method runCallbacks = VolmitPlugin.class.getDeclaredMethod("runPostShutdown");
|
||||
runCallbacks.setAccessible(true);
|
||||
runCallbacks.invoke(doCallRealMethod().when(fixture.plugin));
|
||||
doCallRealMethod().when(fixture.plugin).runPostShutdown();
|
||||
fixture.quiesce();
|
||||
fixture.finish(5L);
|
||||
iris.verify(() -> Iris.reportError("Failed to run Iris post-shutdown cleanup.", failure));
|
||||
@@ -326,8 +324,8 @@ public class IrisShutdownMaintenanceTest {
|
||||
public void incompleteDrainRetainsServicesWorkersAndClassLoader() throws Exception {
|
||||
try (Fixture fixture = new Fixture(); MockedStatic<Iris> iris = mockStatic(Iris.class)) {
|
||||
IrisService service = mock(IrisService.class);
|
||||
setField(fixture.plugin, "services", new KMap<Class<? extends IrisService>, IrisService>());
|
||||
setField(fixture.plugin, "enabledServices", List.of(service));
|
||||
setField(fixture.runtime, "services", new KMap<Class<? extends IrisService>, IrisService>());
|
||||
setField(fixture.runtime, "enabledServices", List.of(service));
|
||||
when(fixture.generator.closeAsync()).thenReturn(new CompletableFuture<>());
|
||||
fixture.quiesce();
|
||||
fixture.finish(0L);
|
||||
@@ -340,7 +338,7 @@ public class IrisShutdownMaintenanceTest {
|
||||
@Test
|
||||
public void serverStopPreUnloadDefersTeardownWhileTheClassLoaderIsHeld() throws Exception {
|
||||
try (Fixture fixture = new Fixture()) {
|
||||
setField(fixture.plugin, "postStopFinisherStarted", new AtomicBoolean(true));
|
||||
setField(fixture.runtime, "postStopFinisherStarted", new AtomicBoolean(true));
|
||||
try {
|
||||
fixture.commitReloadDuringServerStop();
|
||||
verify(fixture.binding).deferPluginClassLoaderClose();
|
||||
@@ -373,7 +371,7 @@ public class IrisShutdownMaintenanceTest {
|
||||
@Test
|
||||
public void serverStopPreUnloadDrainsInlineWithoutInitializedProtection() throws Exception {
|
||||
try (Fixture fixture = new Fixture()) {
|
||||
setField(fixture.plugin, "shutdownProtectionInitialized", false);
|
||||
setField(fixture.runtime, "shutdownProtectionInitialized", false);
|
||||
try {
|
||||
fixture.commitReloadDuringServerStop();
|
||||
verify(fixture.binding, never()).deferPluginClassLoaderClose();
|
||||
@@ -386,20 +384,21 @@ public class IrisShutdownMaintenanceTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static void invoke(Iris plugin, String name) throws ReflectiveOperationException {
|
||||
Method method = Iris.class.getDeclaredMethod(name);
|
||||
private static void invoke(IrisRuntime runtime, String name) throws ReflectiveOperationException {
|
||||
Method method = IrisRuntime.class.getDeclaredMethod(name);
|
||||
method.setAccessible(true);
|
||||
method.invoke(plugin);
|
||||
method.invoke(runtime);
|
||||
}
|
||||
|
||||
private static void setField(Iris plugin, String name, Object value) throws ReflectiveOperationException {
|
||||
Field field = Iris.class.getDeclaredField(name);
|
||||
private static void setField(IrisRuntime runtime, String name, Object value) throws ReflectiveOperationException {
|
||||
Field field = IrisRuntime.class.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
field.set(plugin, value);
|
||||
field.set(runtime, value);
|
||||
}
|
||||
|
||||
private static final class Fixture implements AutoCloseable {
|
||||
private final Iris plugin = mock(Iris.class);
|
||||
private final IrisRuntime runtime = mock(IrisRuntime.class);
|
||||
private final World world = mock(World.class);
|
||||
private final IrisWorld irisWorld = mock(IrisWorld.class);
|
||||
private final Engine engine = mock(Engine.class);
|
||||
@@ -419,15 +418,16 @@ public class IrisShutdownMaintenanceTest {
|
||||
|
||||
private Fixture() throws ReflectiveOperationException {
|
||||
IrisSettings.settings = new IrisSettings();
|
||||
setField(plugin, "shutdownProtectionInitialized", true);
|
||||
setField(plugin, "alreadyDrained", new AtomicBoolean());
|
||||
setField(plugin, "servicesDisabled", new AtomicBoolean());
|
||||
setField(plugin, "runtimeTeardownFailed", new AtomicBoolean());
|
||||
setField(plugin, "sharedRuntimeClosed", new AtomicBoolean());
|
||||
setField(plugin, "terminalCleanupCompleted", new AtomicBoolean());
|
||||
setField(plugin, "serverStopTeardownDeferred", new AtomicBoolean());
|
||||
setField(plugin, "postStopFinisherStarted", new AtomicBoolean());
|
||||
setField(plugin, "deferredShutdownGenerators", new CopyOnWriteArrayList<PlatformChunkGenerator>());
|
||||
setField(runtime, "plugin", plugin);
|
||||
setField(runtime, "shutdownProtectionInitialized", true);
|
||||
setField(runtime, "alreadyDrained", new AtomicBoolean());
|
||||
setField(runtime, "servicesDisabled", new AtomicBoolean());
|
||||
setField(runtime, "runtimeTeardownFailed", new AtomicBoolean());
|
||||
setField(runtime, "sharedRuntimeClosed", new AtomicBoolean());
|
||||
setField(runtime, "terminalCleanupCompleted", new AtomicBoolean());
|
||||
setField(runtime, "serverStopTeardownDeferred", new AtomicBoolean());
|
||||
setField(runtime, "postStopFinisherStarted", new AtomicBoolean());
|
||||
setField(runtime, "deferredShutdownGenerators", new CopyOnWriteArrayList<PlatformChunkGenerator>());
|
||||
when(world.getKey()).thenReturn(NamespacedKey.fromString(identity));
|
||||
when(engine.getWorld()).thenReturn(irisWorld);
|
||||
when(irisWorld.hasPlatformWorld()).thenReturn(true);
|
||||
@@ -441,42 +441,42 @@ public class IrisShutdownMaintenanceTest {
|
||||
}
|
||||
|
||||
private void quiesce() throws ReflectiveOperationException {
|
||||
Method method = Iris.class.getDeclaredMethod("quiesceRuntimeForServerShutdown", String.class);
|
||||
Method method = IrisRuntime.class.getDeclaredMethod("quiesceRuntimeForServerShutdown", String.class);
|
||||
method.setAccessible(true);
|
||||
method.invoke(plugin, "server_stop");
|
||||
method.invoke(runtime, "server_stop");
|
||||
quiesces++;
|
||||
}
|
||||
|
||||
private void drain() throws ReflectiveOperationException {
|
||||
Method method = Iris.class.getDeclaredMethod("drainWorldGenerators", String.class, long.class);
|
||||
Method method = IrisRuntime.class.getDeclaredMethod("drainWorldGenerators", String.class, long.class);
|
||||
method.setAccessible(true);
|
||||
method.invoke(plugin, "manual_disable", 5L);
|
||||
method.invoke(runtime, "manual_disable", 5L);
|
||||
}
|
||||
|
||||
private void commitReloadDuringServerStop() throws ReflectiveOperationException {
|
||||
setField(plugin, "alreadyDrained", new AtomicBoolean());
|
||||
setField(runtime, "alreadyDrained", new AtomicBoolean());
|
||||
toolbelt.when(IrisToolbelt::isServerStopping).thenReturn(true);
|
||||
doCallRealMethod().when(plugin).commitReload(any());
|
||||
plugin.commitReload(ReloadAware.PreUnloadReason.HOT_UNLOAD);
|
||||
doCallRealMethod().when(runtime).commitReload(any());
|
||||
runtime.commitReload(ReloadAware.PreUnloadReason.HOT_UNLOAD);
|
||||
}
|
||||
|
||||
private boolean serverStopTeardownDeferred() throws ReflectiveOperationException {
|
||||
Field field = Iris.class.getDeclaredField("serverStopTeardownDeferred");
|
||||
Field field = IrisRuntime.class.getDeclaredField("serverStopTeardownDeferred");
|
||||
field.setAccessible(true);
|
||||
return ((AtomicBoolean) field.get(plugin)).get();
|
||||
return ((AtomicBoolean) field.get(runtime)).get();
|
||||
}
|
||||
|
||||
|
||||
private void finish(long timeoutSeconds) throws ReflectiveOperationException {
|
||||
Method method = Iris.class.getDeclaredMethod("finishDeferredRuntimeTeardown", String.class, long.class);
|
||||
Method method = IrisRuntime.class.getDeclaredMethod("finishDeferredRuntimeTeardown", String.class, long.class);
|
||||
method.setAccessible(true);
|
||||
method.invoke(plugin, "test_shutdown", timeoutSeconds);
|
||||
method.invoke(runtime, "test_shutdown", timeoutSeconds);
|
||||
}
|
||||
|
||||
private void startFinisher() throws ReflectiveOperationException {
|
||||
Method method = Iris.class.getDeclaredMethod("startPostStopFinisher");
|
||||
Method method = IrisRuntime.class.getDeclaredMethod("startPostStopFinisher");
|
||||
method.setAccessible(true);
|
||||
method.invoke(plugin);
|
||||
method.invoke(runtime);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,16 +11,13 @@ import java.util.List;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Answers.CALLS_REAL_METHODS;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
|
||||
public class IrisVersionNumberTest {
|
||||
@Test
|
||||
public void releaseAndQualifiedBuildsUseTheSameVersionNumber() {
|
||||
for (String version : List.of("4.3.3", "4.3.3-SNAPSHOT", "4.3.3-test")) {
|
||||
assertEquals(version, 433, plugin(version).getIrisVersion());
|
||||
assertEquals(version, 433, IrisRuntime.irisVersion(version));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,10 +26,8 @@ public class IrisVersionNumberTest {
|
||||
try (InputStream stream = getClass().getResourceAsStream("/plugin.yml")) {
|
||||
assertNotNull(stream);
|
||||
PluginDescriptionFile description = new PluginDescriptionFile(stream);
|
||||
Iris plugin = mock(Iris.class, CALLS_REAL_METHODS);
|
||||
doReturn(description).when(plugin).getDescription();
|
||||
|
||||
assertNotEquals(-1, plugin.getIrisVersion());
|
||||
assertNotEquals(-1, IrisRuntime.irisVersion(description.getVersion()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,28 +35,21 @@ public class IrisVersionNumberTest {
|
||||
public void malformedAndOverflowingReleaseNumbersStayInvalid() {
|
||||
for (String version : List.of("development", "4..3", ".4.3.3", "4.3.3.", "4.3a.3-test",
|
||||
"2147483648", "999999999999999999999-SNAPSHOT", "-SNAPSHOT")) {
|
||||
assertEquals(version, -1, plugin(version).getIrisVersion());
|
||||
assertEquals(version, -1, IrisRuntime.irisVersion(version));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportedMinecraftVersionsRetainTheirEngineNumbers() {
|
||||
Iris plugin = mock(Iris.class, CALLS_REAL_METHODS);
|
||||
try (MockedStatic<Bukkit> bukkit = mockStatic(Bukkit.class)) {
|
||||
bukkit.when(Bukkit::getVersion).thenReturn("26.1.2-74-ver/26.1.2@e4e17fc (MC: 26.1.2)");
|
||||
assertEquals(2612, plugin.getMCVersion());
|
||||
assertEquals(2612, IrisRuntime.minecraftVersion());
|
||||
bukkit.when(Bukkit::getVersion).thenReturn("26.1.2-8-ver/26.1.x@62dc0f2 (MC: 26.1.2)");
|
||||
assertEquals(2612, plugin.getMCVersion());
|
||||
assertEquals(2612, IrisRuntime.minecraftVersion());
|
||||
bukkit.when(Bukkit::getVersion).thenReturn("26.2-133 (MC: 26.2)");
|
||||
assertEquals(262, plugin.getMCVersion());
|
||||
assertEquals(262, IrisRuntime.minecraftVersion());
|
||||
bukkit.when(Bukkit::getVersion).thenReturn("26.3-169 (MC: 26.3)");
|
||||
assertEquals(263, plugin.getMCVersion());
|
||||
assertEquals(263, IrisRuntime.minecraftVersion());
|
||||
}
|
||||
}
|
||||
|
||||
private static Iris plugin(String version) {
|
||||
Iris plugin = mock(Iris.class, CALLS_REAL_METHODS);
|
||||
doReturn(new PluginDescriptionFile("Iris", version, Iris.class.getName())).when(plugin).getDescription();
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package art.arcane.iris.command;
|
||||
|
||||
import art.arcane.iris.Iris;
|
||||
import art.arcane.iris.IrisRuntime;
|
||||
import art.arcane.iris.command.CommandSVC;
|
||||
import art.arcane.iris.world.task.J;
|
||||
import art.arcane.volmlib.util.diagnostics.BukkitDebugDump;
|
||||
@@ -30,18 +31,18 @@ import static org.mockito.Mockito.when;
|
||||
public class CommandDebugTest {
|
||||
@Test
|
||||
public void nestedDumpPreservesUploadDefaultAndLocalOnlyOption() {
|
||||
Iris previousPlugin = Iris.instance;
|
||||
Iris plugin = mock(Iris.class);
|
||||
Iris.instance = plugin;
|
||||
IrisRuntime runtime = mock(IrisRuntime.class);
|
||||
BukkitDebugDump dump = mock(BukkitDebugDump.class);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
DirectorSender invocationSender = mock(DirectorSender.class);
|
||||
when(plugin.debugDump()).thenReturn(dump);
|
||||
when(runtime.debugDump()).thenReturn(dump);
|
||||
when(invocationSender.getName()).thenReturn("Console");
|
||||
DirectorContextRegistry contexts = new DirectorContextRegistry();
|
||||
contexts.register(CommandSender.class, (invocation, arguments) -> sender);
|
||||
|
||||
try (MockedStatic<Iris> iris = mockStatic(Iris.class)) {
|
||||
try (MockedStatic<Iris> iris = mockStatic(Iris.class);
|
||||
MockedStatic<IrisRuntime> runtimes = mockStatic(IrisRuntime.class)) {
|
||||
runtimes.when(IrisRuntime::require).thenReturn(runtime);
|
||||
DirectorRuntimeEngine engine = DirectorEngineFactory.create(new CommandIris(),
|
||||
DirectorEngineOptions.builder().contexts(contexts).build());
|
||||
|
||||
@@ -52,8 +53,6 @@ public class CommandDebugTest {
|
||||
assertEquals(List.of("dump", "toggle", "version"),
|
||||
DirectorMiniMenu.resolveHelp(engine, List.of("debug")).orElseThrow().entries().stream()
|
||||
.map(entry -> entry.getDescriptor().getName()).sorted().toList());
|
||||
} finally {
|
||||
Iris.instance = previousPlugin;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+13
-3
@@ -1,6 +1,7 @@
|
||||
package art.arcane.iris.integration;
|
||||
|
||||
import art.arcane.iris.Iris;
|
||||
import art.arcane.iris.IrisRuntime;
|
||||
import art.arcane.volmlib.util.bukkit.papi.PlaceholderRegistration;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.HandlerList;
|
||||
@@ -89,12 +90,21 @@ public class IrisPapiLifecycleTest {
|
||||
when(iris.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||
doCallRealMethod().when(iris).onPlaceholderApiEnable(any());
|
||||
doCallRealMethod().when(iris).onPlaceholderApiDisable(any());
|
||||
Field lifecycle = Iris.class.getDeclaredField("papiLifecycleActive");
|
||||
lifecycle.setAccessible(true);
|
||||
lifecycle.setBoolean(iris, active);
|
||||
IrisRuntime runtime = mock(IrisRuntime.class);
|
||||
doCallRealMethod().when(runtime).onPlaceholderApiEnable(any());
|
||||
doCallRealMethod().when(runtime).onPlaceholderApiDisable(any());
|
||||
set(IrisRuntime.class, runtime, "plugin", iris);
|
||||
set(IrisRuntime.class, runtime, "papiLifecycleActive", active);
|
||||
set(Iris.class, iris, "runtime", runtime);
|
||||
return iris;
|
||||
}
|
||||
|
||||
private static void set(Class<?> owner, Object target, String name, Object value) throws ReflectiveOperationException {
|
||||
Field field = owner.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
field.set(target, value);
|
||||
}
|
||||
|
||||
private static Plugin namedPlugin(String name) {
|
||||
Plugin plugin = mock(Plugin.class);
|
||||
when(plugin.getName()).thenReturn(name);
|
||||
|
||||
+8
-8
@@ -107,10 +107,10 @@ public class BukkitWorldReconcilerRuntimeTest {
|
||||
public void aRefusedReconcilerCreateIsReportedAsARefusal() throws Exception {
|
||||
NamespacedKey key = new NamespacedKey("iris", "probe");
|
||||
IllegalStateException refusal = new IllegalStateException("Iris generation history is unusable at /srv/probe.");
|
||||
Iris plugin = mock(Iris.class);
|
||||
IrisWorldGeneratorResolver resolver = mock(IrisWorldGeneratorResolver.class);
|
||||
WorldRefusalReporter refusals = mock(WorldRefusalReporter.class);
|
||||
when(plugin.worldRefusals()).thenReturn(refusals);
|
||||
when(plugin.requireWorldGenerator("world_iris_probe", "overworld")).thenThrow(refusal);
|
||||
when(resolver.refusals()).thenReturn(refusals);
|
||||
when(resolver.requireWorldGenerator("world_iris_probe", "overworld")).thenThrow(refusal);
|
||||
|
||||
try (MockedStatic<Iris> iris = mockStatic(Iris.class);
|
||||
MockedStatic<IrisWorldStorage> storage = mockStatic(IrisWorldStorage.class)) {
|
||||
@@ -118,7 +118,7 @@ public class BukkitWorldReconcilerRuntimeTest {
|
||||
storage.when(() -> IrisWorldStorage.configuredWorldName(key, "world")).thenReturn("world_iris_probe");
|
||||
storage.when(() -> IrisWorldStorage.logicalName(key)).thenReturn("probe");
|
||||
|
||||
CompletableFuture<World> created = backend(plugin).createWorld(key, "overworld", 1337L);
|
||||
CompletableFuture<World> created = backend(resolver).createWorld(key, "overworld", 1337L);
|
||||
|
||||
ExecutionException failure = assertThrows(ExecutionException.class, created::get);
|
||||
assertSame(refusal, failure.getCause());
|
||||
@@ -165,14 +165,14 @@ public class BukkitWorldReconcilerRuntimeTest {
|
||||
when(dimension.getLoadKey()).thenReturn("overworld");
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(data.getDataFolder()).thenReturn(pack.toFile());
|
||||
return new RuntimeFixture(backend(mock(Iris.class)), world, key, generator, engine, history, root, pack);
|
||||
return new RuntimeFixture(backend(mock(IrisWorldGeneratorResolver.class)), world, key, generator, engine, history, root, pack);
|
||||
}
|
||||
|
||||
private static BukkitWorldReconciler.Backend backend(Iris plugin) throws Exception {
|
||||
private static BukkitWorldReconciler.Backend backend(IrisWorldGeneratorResolver resolver) throws Exception {
|
||||
Class<?> backendClass = Class.forName(BukkitWorldReconciler.class.getName() + "$BukkitBackend");
|
||||
Constructor<?> constructor = backendClass.getDeclaredConstructor(Iris.class);
|
||||
Constructor<?> constructor = backendClass.getDeclaredConstructor(IrisWorldGeneratorResolver.class);
|
||||
constructor.setAccessible(true);
|
||||
return (BukkitWorldReconciler.Backend) constructor.newInstance(plugin);
|
||||
return (BukkitWorldReconciler.Backend) constructor.newInstance(resolver);
|
||||
}
|
||||
|
||||
private record RuntimeFixture(BukkitWorldReconciler.Backend backend, World world, NamespacedKey key,
|
||||
|
||||
Reference in new issue
Block a user