mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
Merge upstream port lane d
NativeStructureWorldgenAccess keeps both sides: writes are still recorded for the stale deferred-record check, and they go through the POI reconciler when one is bound.
This commit is contained in:
commit
4b1d85177f
69 files changed
+2413
-255
No files matched your search
+88
@@ -0,0 +1,88 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.iris.core.IrisSettings;
|
||||
import art.arcane.iris.modded.command.IrisModdedCommands;
|
||||
import art.arcane.iris.util.common.parallel.MultiBurst;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.server.Bootstrap;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
|
||||
public class ModdedEngineBootstrapShutdownTest {
|
||||
private static final long WORKER_TIMEOUT_SECONDS = 10L;
|
||||
private static final Callable<Thread> RUNNING_THREAD = Thread::currentThread;
|
||||
|
||||
private IrisSettings previousSettings;
|
||||
|
||||
@BeforeClass
|
||||
public static void bootstrapMinecraftRegistries() {
|
||||
SharedConstants.tryDetectVersion();
|
||||
Bootstrap.bootStrap();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void openRuntime() {
|
||||
previousSettings = IrisSettings.settings;
|
||||
IrisSettings.settings = new IrisSettings();
|
||||
reopenBurstPools();
|
||||
}
|
||||
|
||||
@After
|
||||
public void restoreRuntime() {
|
||||
reopenBurstPools();
|
||||
IrisModdedCommands.openDownloadAdmission();
|
||||
IrisSettings.settings = previousSettings;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serverStoppingKeepsTheGenerationPoolsOpenUntilServerStopped() throws Exception {
|
||||
ModdedEngineBootstrap.stop();
|
||||
|
||||
assertNotSame(Thread.currentThread(), MultiBurst.burst.submit(RUNNING_THREAD).get(WORKER_TIMEOUT_SECONDS, TimeUnit.SECONDS));
|
||||
|
||||
ModdedEngineBootstrap.stopped();
|
||||
|
||||
assertSame(Thread.currentThread(), MultiBurst.burst.submit(RUNNING_THREAD).get(WORKER_TIMEOUT_SECONDS, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nextServerStartClosesWhatAServerThatNeverReachedStoppedLeftOpen() throws Exception {
|
||||
ModdedEngineBootstrap.stop();
|
||||
|
||||
try (MockedStatic<ModdedStartup> startup = mockStatic(ModdedStartup.class)) {
|
||||
ModdedEngineBootstrap.serverAboutToStart(mock(MinecraftServer.class));
|
||||
}
|
||||
|
||||
assertSame(Thread.currentThread(), MultiBurst.burst.submit(RUNNING_THREAD).get(WORKER_TIMEOUT_SECONDS, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serverStartLeavesTheGenerationPoolsAloneWhenTheServerStoppedNormally() throws Exception {
|
||||
ModdedEngineBootstrap.stop();
|
||||
ModdedEngineBootstrap.stopped();
|
||||
MultiBurst.burst.reopen();
|
||||
|
||||
try (MockedStatic<ModdedStartup> startup = mockStatic(ModdedStartup.class)) {
|
||||
ModdedEngineBootstrap.serverAboutToStart(mock(MinecraftServer.class));
|
||||
}
|
||||
|
||||
assertNotSame(Thread.currentThread(), MultiBurst.burst.submit(RUNNING_THREAD).get(WORKER_TIMEOUT_SECONDS, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
private static void reopenBurstPools() {
|
||||
MultiBurst.burst.reopen();
|
||||
MultiBurst.ioBurst.reopen();
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -120,10 +120,10 @@ public class ModdedGenerationLeaseContractTest {
|
||||
|
||||
String bootstrap = source("art/arcane/iris/modded/ModdedEngineBootstrap.java");
|
||||
String stop = method(bootstrap, "public static void stop()");
|
||||
int downloads = stop.indexOf("IrisModdedCommands::shutdownDownloads");
|
||||
int scheduler = stop.indexOf("scheduler::shutdown");
|
||||
assertTrue(downloads >= 0);
|
||||
assertTrue(scheduler > downloads);
|
||||
assertTrue(stop.contains("IrisModdedCommands::shutdownDownloads"));
|
||||
assertFalse(stop.contains("scheduler::shutdown"));
|
||||
String stopped = method(bootstrap, "private static void closeStoppedServer()");
|
||||
assertTrue(stopped.contains("scheduler::shutdown"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+14
-8
@@ -141,21 +141,27 @@ public class ModdedLifecycleFailureContractTest {
|
||||
@Test
|
||||
public void engineBootstrapResetsStartupExactlyOnceDuringStop() throws IOException {
|
||||
String source = source("ModdedEngineBootstrap.java");
|
||||
String stop = method(source, "public static void stop(");
|
||||
String stopped = method(source, "private static void closeStoppedServer(");
|
||||
|
||||
assertEquals(1, occurrences(stop, "ModdedStartup::reset"));
|
||||
assertEquals(1, occurrences(source, "ModdedStartup::reset"));
|
||||
assertEquals(1, occurrences(stopped, "ModdedStartup::reset"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void engineBootstrapAttemptsEveryShutdownStageAndAggregatesFailures() throws IOException {
|
||||
String source = source("ModdedEngineBootstrap.java");
|
||||
String stop = method(source, "public static void stop(");
|
||||
String stopped = method(source, "private static void closeStoppedServer(");
|
||||
|
||||
assertBefore(stop, "\"services\"", "\"world engines\"");
|
||||
assertBefore(stop, "\"world engines\"", "\"dimension manager\"");
|
||||
assertBefore(stop, "\"server state\"", "if (failure != null)");
|
||||
assertTrue(stop.contains("\"services\""));
|
||||
assertFalse(stop.contains("\"world engines\""));
|
||||
assertBefore(stopped, "\"world engines\"", "\"dimension manager\"");
|
||||
assertBefore(stopped, "\"server state\"", "reportStopFailure(\"stopped\", failure);");
|
||||
assertBefore(stop, "\"services\"", "reportStopFailure(\"stopping\", failure);");
|
||||
assertFalse(stop.contains("throw"));
|
||||
assertTrue(stop.contains("ModdedIrisLog.error(\"Iris modded shutdown completed with failures\", failure);"));
|
||||
assertFalse(stopped.contains("throw"));
|
||||
String report = method(source, "private static void reportStopFailure(");
|
||||
assertTrue(report.contains("ModdedIrisLog.error(\"Iris modded shutdown ({}) completed with failures\", phase, failure);"));
|
||||
|
||||
String runStage = method(source, "private static Throwable runStopStage(");
|
||||
assertTrue(runStage.contains("catch (Throwable stageFailure)"));
|
||||
@@ -206,12 +212,12 @@ public class ModdedLifecycleFailureContractTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loaderUnloadSurfacesCloseFailureAndDynamicRemovalUsesStrictEviction() throws IOException {
|
||||
public void loaderUnloadLogsCloseFailureAndDynamicRemovalUsesStrictEviction() throws IOException {
|
||||
String bootstrapSource = source("ModdedEngineBootstrap.java");
|
||||
String unload = method(bootstrapSource, "public static void levelUnloaded(ServerLevel level)");
|
||||
String failure = catchBlock(unload);
|
||||
assertTrue(failure.contains("ModdedIrisLog.error("));
|
||||
assertTrue(failure.contains("throw "));
|
||||
assertFalse(failure.contains("throw "));
|
||||
|
||||
String managerSource = source("ModdedDimensionManager.java");
|
||||
String remove = method(managerSource, "public static boolean remove(MinecraftServer server, String dimensionId, boolean wipeStorage)");
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ModdedTeleportDeadlineTest {
|
||||
@Test
|
||||
public void deadlineOutlastsAColdFirstChunkAndStaysBounded() {
|
||||
long before = System.nanoTime();
|
||||
long deadline = ModdedTeleportDeadline.fromNow();
|
||||
long after = System.nanoTime();
|
||||
|
||||
assertTrue("deadline must outlast a cold first chunk", deadline - before >= TimeUnit.SECONDS.toNanos(60L));
|
||||
assertTrue("deadline must be bounded", deadline - after <= TimeUnit.SECONDS.toNanos(120L));
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package art.arcane.iris.modded.command;
|
||||
|
||||
import art.arcane.iris.core.localization.IrisLanguage;
|
||||
import art.arcane.iris.core.localization.ModdedCommandMessages;
|
||||
import art.arcane.volmlib.util.localization.MessageArgument;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class IrisModdedCommandsTeleportTest {
|
||||
private static final String DIMENSION = "irisworldgen:1";
|
||||
|
||||
@Test
|
||||
public void failureReportsItsRootCauseInsteadOfAnUnloadedDimension() {
|
||||
String message = IrisModdedCommands.teleportFailure(DIMENSION, "Tester",
|
||||
new CompletionException(new IllegalStateException("Exception generating new chunk")), true, true);
|
||||
|
||||
assertEquals(IrisLanguage.plain(ModdedCommandMessages.IRIS_MODDED_COMMANDS_TELEPORT_FAILED_REASON,
|
||||
MessageArgument.untrusted("dimensionId", DIMENSION),
|
||||
MessageArgument.untrusted("reason", "Exception generating new chunk")), message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failureWithoutMessageNamesTheFailureType() {
|
||||
String message = IrisModdedCommands.teleportFailure(DIMENSION, "Tester", new TimeoutException(), true, true);
|
||||
|
||||
assertEquals(IrisLanguage.plain(ModdedCommandMessages.IRIS_MODDED_COMMANDS_TELEPORT_FAILED_REASON,
|
||||
MessageArgument.untrusted("dimensionId", DIMENSION),
|
||||
MessageArgument.untrusted("reason", "TimeoutException")), message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unloadedDimensionIsReportedOnlyWhenItIsGone() {
|
||||
assertEquals(IrisLanguage.plain(ModdedCommandMessages.IRIS_MODDED_COMMANDS_TELEPORT_FAILED_DIMENSION_IS_NOT_LOADED,
|
||||
MessageArgument.untrusted("dimensionId", DIMENSION)),
|
||||
IrisModdedCommands.teleportFailure(DIMENSION, "Tester", null, false, true));
|
||||
assertEquals(IrisLanguage.plain(ModdedCommandMessages.IRIS_MODDED_COMMANDS_TELEPORT_CANCELLED_PLAYER_OFFLINE,
|
||||
MessageArgument.untrusted("dimensionId", DIMENSION),
|
||||
MessageArgument.untrusted("value", "Tester")),
|
||||
IrisModdedCommands.teleportFailure(DIMENSION, "Tester", null, true, false));
|
||||
assertEquals(IrisLanguage.plain(ModdedCommandMessages.IRIS_MODDED_COMMANDS_TELEPORT_REFUSED,
|
||||
MessageArgument.untrusted("dimensionId", DIMENSION)),
|
||||
IrisModdedCommands.teleportFailure(DIMENSION, "Tester", null, true, true));
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package art.arcane.iris.modded.command;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class IrisModdedWorldListingTest {
|
||||
private static final String ALPHA = "iris:alpha";
|
||||
private static final String BETA = "iris:beta";
|
||||
private static final long ALPHA_SEED = 424242L;
|
||||
private static final long BETA_SEED = -77L;
|
||||
private static final int ALPHA_CHUNKS = 1089;
|
||||
|
||||
@Test
|
||||
public void rowShowsTheIrisWorldSeedAndPersistedChunkCount() {
|
||||
String alpha = row(ALPHA, ALPHA_SEED, ALPHA_CHUNKS).format(true, null);
|
||||
String beta = row(BETA, BETA_SEED, 0).format(true, null);
|
||||
|
||||
assertTrue(alpha, alpha.startsWith(ALPHA + ": pack=overworld "));
|
||||
assertTrue(alpha, alpha.contains(" seed=424242 "));
|
||||
assertTrue(alpha, alpha.contains(" generated=1089 "));
|
||||
assertTrue(beta, beta.startsWith(BETA + ": pack=overworld "));
|
||||
assertTrue(beta, beta.contains(" seed=-77 "));
|
||||
assertTrue(beta, beta.contains(" generated=0 "));
|
||||
assertFalse(alpha, alpha.contains(" world="));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rowOmitsTheSeedWhenItIsNotShown() {
|
||||
String row = row(ALPHA, ALPHA_SEED, ALPHA_CHUNKS).format(false, null);
|
||||
|
||||
assertFalse(row, row.contains("seed="));
|
||||
assertTrue(row, row.contains(" generated=1089 "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rowAppendsImportedFeatureStatus() {
|
||||
String row = row(ALPHA, ALPHA_SEED, ALPHA_CHUNKS).format(true, "ready");
|
||||
|
||||
assertTrue(row, row.contains(" importedFeatures=ready "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rowForAnUnstartedEngineIsLabeledByItsDimension() {
|
||||
assertEquals("iris:gamma: pack=overworld:overworld (engine not started yet)",
|
||||
IrisModdedCommands.worldRow("iris:gamma", "overworld:overworld", null, true, null));
|
||||
}
|
||||
|
||||
private static IrisModdedCommands.WorldRow row(String dimensionId, long seed, int generated) {
|
||||
return new IrisModdedCommands.WorldRow(dimensionId, "overworld", seed, -64, 320, generated, "overworld");
|
||||
}
|
||||
}
|
||||
+101
@@ -1,20 +1,34 @@
|
||||
package art.arcane.iris.modded.service;
|
||||
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.util.project.matter.TileWrapper;
|
||||
import art.arcane.volmlib.util.function.Consumer4;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleDataAdapter;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleHooks;
|
||||
import art.arcane.volmlib.util.matter.IrisMatter;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterSlice;
|
||||
import art.arcane.volmlib.util.matter.MatterUpdate;
|
||||
import art.arcane.volmlib.util.matter.slices.UpdateMatter;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
|
||||
public class ModdedChunkUpdateServiceTest {
|
||||
@Test
|
||||
@@ -63,6 +77,93 @@ public class ModdedChunkUpdateServiceTest {
|
||||
assertEquals(List.of("materialize"), chunk.operations());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failedUpdateForgetsOnlyTheUpdatesAlreadyApplied() {
|
||||
ChestUpdateMantleChunk chunk = new ChestUpdateMantleChunk();
|
||||
|
||||
assertThrows(IllegalStateException.class, () ->
|
||||
ModdedChunkUpdateService.applyQueuedUpdates(chunk, (Integer x, Integer yf, Integer z) -> {
|
||||
if (x == 2) {
|
||||
throw new IllegalStateException("update failure");
|
||||
}
|
||||
}));
|
||||
|
||||
assertFalse(chunk.deleted());
|
||||
assertNull(chunk.slice.get(1, 5, 1));
|
||||
assertNotNull(chunk.slice.get(2, 5, 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failedChunkIsReportedAndTheNextChunkStillRuns() {
|
||||
AtomicInteger updatedChunks = new AtomicInteger();
|
||||
|
||||
try (MockedStatic<IrisLogging> logging = mockStatic(IrisLogging.class)) {
|
||||
logging.when(() -> IrisLogging.errorOnce(anyString(), anyString(), any(Object[].class))).thenReturn(true);
|
||||
|
||||
ModdedChunkUpdateService.isolateChunkFailure(
|
||||
() -> {
|
||||
throw new IllegalStateException("chunk failure");
|
||||
},
|
||||
() -> false, "example:updates", 0, 0);
|
||||
ModdedChunkUpdateService.isolateChunkFailure(
|
||||
updatedChunks::incrementAndGet, () -> false, "example:updates", 4, 0);
|
||||
|
||||
assertEquals(1, updatedChunks.get());
|
||||
logging.verify(() -> IrisLogging.errorOnce(anyString(), anyString(), any(Object[].class)));
|
||||
logging.verify(() -> IrisLogging.reportError(any(Throwable.class)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endedPassRethrowsTheChunkFailure() {
|
||||
IllegalStateException failure = new IllegalStateException("chunk failure");
|
||||
|
||||
IllegalStateException thrown = assertThrows(IllegalStateException.class, () ->
|
||||
ModdedChunkUpdateService.isolateChunkFailure(
|
||||
() -> {
|
||||
throw failure;
|
||||
},
|
||||
() -> true, "example:updates", 0, 0));
|
||||
|
||||
assertSame(failure, thrown);
|
||||
}
|
||||
|
||||
private static final class ChestUpdateMantleChunk extends MantleChunk<Matter> {
|
||||
private final Matter section = new IrisMatter(16, 16, 16);
|
||||
private final MatterSlice<MatterUpdate> slice = section.slice(MatterUpdate.class);
|
||||
private boolean deleted;
|
||||
|
||||
private ChestUpdateMantleChunk() {
|
||||
super(1, 0, 0, emptyAdapter(), MantleHooks.NONE);
|
||||
slice.set(1, 5, 1, UpdateMatter.ON);
|
||||
slice.set(2, 5, 2, UpdateMatter.ON);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Matter get(int index) {
|
||||
return section;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void iterate(Class<T> type, Consumer4<Integer, Integer, Integer, T> iterator) {
|
||||
if (type == MatterUpdate.class) {
|
||||
iterator.accept(1, 5, 1, type.cast(UpdateMatter.ON));
|
||||
iterator.accept(2, 5, 2, type.cast(UpdateMatter.ON));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteSlices(Class<?> type) {
|
||||
if (type == MatterUpdate.class) {
|
||||
deleted = true;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean deleted() {
|
||||
return deleted;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RecordingMantleChunk extends MantleChunk<Matter> {
|
||||
private final ArrayList<String> operations = new ArrayList<>();
|
||||
|
||||
|
||||
Reference in new issue
Block a user