mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Fixed Windows build
- Purity ratchet compares source paths with forward slashes - Hydrology plan reads and saves share a striped file lock - Offline region generator skips directory sync on Windows - Noise seed pin hashes samples rounded to 9 decimal places - Language guide test ignores line endings - Language hotload test uses the VolmLib size limit - Region snapshot tests skip without file keys - Region snapshot test covers reads without file keys - Open region replacement test skips on Windows - Attach signal test links sigaction after the Windows check - Offline publication test expects only file syncs on Windows
This commit is contained in:
1 parent
7efd51de3e
commit
0aad88c301
11 files changed
+88
-16
No files matched your search
+5
-1
@@ -219,7 +219,11 @@ public final class OfflineRegionGenerator {
|
||||
}
|
||||
|
||||
private static void force(Path path) throws IOException {
|
||||
try (FileChannel channel = FileChannel.open(path, Files.isDirectory(path)
|
||||
boolean directory = Files.isDirectory(path);
|
||||
if (directory && File.separatorChar == '\\') {
|
||||
return;
|
||||
}
|
||||
try (FileChannel channel = FileChannel.open(path, directory
|
||||
? StandardOpenOption.READ : StandardOpenOption.WRITE)) {
|
||||
channel.force(true);
|
||||
}
|
||||
|
||||
+2
-1
@@ -6,6 +6,7 @@ import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.file.Files;
|
||||
@@ -78,7 +79,7 @@ public final class OfflineRegionPublicationTest {
|
||||
assertFalse(Files.exists(target));
|
||||
} else {
|
||||
OfflineRegionGenerator.publish(staged, target);
|
||||
assertEquals(List.of(data, nested, staged, output), forced);
|
||||
assertEquals(File.separatorChar == '\\' ? List.of(data) : List.of(data, nested, staged, output), forced);
|
||||
assertEquals("checkpoint", Files.readString(target.resolve("world/data")));
|
||||
}
|
||||
}
|
||||
|
||||
+14
-8
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.platform.agent;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.foreign.Arena;
|
||||
@@ -20,21 +21,26 @@ public class AttachSignalTest {
|
||||
private static final int SIGQUIT = 3;
|
||||
private static final int SIGTERM = 15;
|
||||
private static final long ACTION_BYTES = 256;
|
||||
private static final MethodHandle SIGACTION = Linker.nativeLinker().downcallHandle(
|
||||
Linker.nativeLinker().defaultLookup().find("sigaction").orElseThrow(),
|
||||
FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.ADDRESS));
|
||||
private static MethodHandle sigaction;
|
||||
|
||||
@BeforeClass
|
||||
public static void linkSigaction() {
|
||||
assumeFalse(System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("win"));
|
||||
sigaction = Linker.nativeLinker().downcallHandle(
|
||||
Linker.nativeLinker().defaultLookup().find("sigaction").orElseThrow(),
|
||||
FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.ADDRESS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aConsoleThatResetsQuitGetsTheJvmHandlerBack() throws Throwable {
|
||||
assumeFalse(System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("win"));
|
||||
long jvmHandler = handler(SIGTERM);
|
||||
assertNotEquals(0L, jvmHandler);
|
||||
try (Arena arena = Arena.ofConfined()) {
|
||||
MemorySegment original = arena.allocate(ACTION_BYTES);
|
||||
assertEquals(0, (int) SIGACTION.invokeExact(SIGQUIT, MemorySegment.NULL, original));
|
||||
assertEquals(0, (int) sigaction.invokeExact(SIGQUIT, MemorySegment.NULL, original));
|
||||
try {
|
||||
MemorySegment reset = arena.allocate(ACTION_BYTES);
|
||||
assertEquals(0, (int) SIGACTION.invokeExact(SIGQUIT, reset, MemorySegment.NULL));
|
||||
assertEquals(0, (int) sigaction.invokeExact(SIGQUIT, reset, MemorySegment.NULL));
|
||||
assertEquals(0L, handler(SIGQUIT));
|
||||
|
||||
assertTrue(AttachSignal.restoreJvmHandler());
|
||||
@@ -42,7 +48,7 @@ public class AttachSignalTest {
|
||||
assertEquals(jvmHandler, handler(SIGQUIT));
|
||||
assertFalse(AttachSignal.restoreJvmHandler());
|
||||
} finally {
|
||||
assertEquals(0, (int) SIGACTION.invokeExact(SIGQUIT, original, MemorySegment.NULL));
|
||||
assertEquals(0, (int) sigaction.invokeExact(SIGQUIT, original, MemorySegment.NULL));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,7 +56,7 @@ public class AttachSignalTest {
|
||||
private static long handler(int signal) throws Throwable {
|
||||
try (Arena arena = Arena.ofConfined()) {
|
||||
MemorySegment action = arena.allocate(ACTION_BYTES);
|
||||
assertEquals(0, (int) SIGACTION.invokeExact(signal, MemorySegment.NULL, action));
|
||||
assertEquals(0, (int) sigaction.invokeExact(signal, MemorySegment.NULL, action));
|
||||
return action.get(ValueLayout.JAVA_LONG, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -995,4 +995,14 @@ tasks.withType(PackedJar).configureEach {
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register('buildSwiftSwamp', Copy) {
|
||||
group = 'development'
|
||||
description = 'Builds, verifies, and stages Iris in the workspace BUILDS directory.'
|
||||
dependsOn('buildBukkit')
|
||||
outputs.upToDateWhen { false }
|
||||
from(tasks.named('packedJar', PackedJar).flatMap { PackedJar archive -> archive.outputJar })
|
||||
into(providers.gradleProperty('buildsDirectory').orElse('../BUILDS'))
|
||||
rename { String ignored -> 'Iris.jar' }
|
||||
}
|
||||
|
||||
apply from: file('gradle/multiplexor.gradle')
|
||||
+1
-1
@@ -569,7 +569,7 @@ Closure<Void> registerPurityRatchet = { String taskName, String label, String fo
|
||||
return
|
||||
}
|
||||
if (f.text.contains(forbiddenPackage)) {
|
||||
String rel = sourceRoot.toPath().relativize(f.toPath()).toString()
|
||||
String rel = sourceRoot.toPath().relativize(f.toPath()).toString().replace(File.separatorChar, (char) '/')
|
||||
coupled.add(rel)
|
||||
if (!allowed.contains(rel)) {
|
||||
offenders.add(rel)
|
||||
|
||||
@@ -20,6 +20,9 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
@@ -32,6 +35,7 @@ public final class HydrologyPlanStore {
|
||||
private static final int MAX_PLAN_BYTES = 256 << 20;
|
||||
private static final int BUFFER = 1 << 16;
|
||||
private static final String RUN = UUID.randomUUID().toString().replace("-", "");
|
||||
private static final ReadWriteLock[] FILE_LOCKS = fileLocks(64);
|
||||
|
||||
private final HydrologySettings settings;
|
||||
private final Path directory;
|
||||
@@ -82,6 +86,8 @@ public final class HydrologyPlanStore {
|
||||
}
|
||||
|
||||
private static Optional<byte[]> read(Path file) {
|
||||
Lock lock = fileLock(file).readLock();
|
||||
lock.lock();
|
||||
try {
|
||||
if (!Files.isRegularFile(file, LinkOption.NOFOLLOW_LINKS) || Files.size(file) > MAX_FILE_BYTES) {
|
||||
return Optional.empty();
|
||||
@@ -92,6 +98,8 @@ public final class HydrologyPlanStore {
|
||||
}
|
||||
} catch (IOException failure) {
|
||||
return Optional.empty();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,13 +121,29 @@ public final class HydrologyPlanStore {
|
||||
}
|
||||
|
||||
private static void move(Path staged, Path target) throws IOException {
|
||||
Lock lock = fileLock(target).writeLock();
|
||||
lock.lock();
|
||||
try {
|
||||
Files.move(staged, target, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
|
||||
} catch (AtomicMoveNotSupportedException unsupported) {
|
||||
Files.move(staged, target, StandardCopyOption.REPLACE_EXISTING);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private static ReadWriteLock fileLock(Path file) {
|
||||
return FILE_LOCKS[Math.floorMod(file.hashCode(), FILE_LOCKS.length)];
|
||||
}
|
||||
|
||||
private static ReadWriteLock[] fileLocks(int stripes) {
|
||||
ReadWriteLock[] locks = new ReadWriteLock[stripes];
|
||||
for (int index = 0; index < stripes; index++) {
|
||||
locks[index] = new ReentrantReadWriteLock();
|
||||
}
|
||||
return locks;
|
||||
}
|
||||
|
||||
private static void sweepStaged(Path directory) {
|
||||
try (DirectoryStream<Path> entries = Files.newDirectoryStream(directory)) {
|
||||
for (Path entry : entries) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import static org.junit.Assert.assertEquals;
|
||||
public class NoiseSeedCohesionTest {
|
||||
private static final long[] SEEDS = {813753L, -935731L, Long.MIN_VALUE};
|
||||
private static final double[] COORDINATES = {-29_999_983.25D, -513D, -64D, -1D, 0D, 0.125D, 17D, 64D, 8192D, 29_999_983.25D};
|
||||
private static final double PINNED_SAMPLE_SCALE = 1.0E9D;
|
||||
|
||||
@Test
|
||||
public void allStylesRetainPinnedSamples() {
|
||||
@@ -24,11 +25,11 @@ public class NoiseSeedCohesionTest {
|
||||
for (NoiseStyle style : NoiseStyle.values()) {
|
||||
for (long seed : SEEDS) {
|
||||
for (double sample : samples(style.create(new RNG(seed)), false)) {
|
||||
hash = (hash ^ Double.doubleToLongBits(sample)) * 0x100000001b3L;
|
||||
hash = (hash ^ Math.round(sample * PINNED_SAMPLE_SCALE)) * 0x100000001b3L;
|
||||
}
|
||||
}
|
||||
}
|
||||
assertEquals("All noise style samples", 5059606393854142913L, hash);
|
||||
assertEquals("All noise style samples", 2597318414939754011L, hash);
|
||||
}
|
||||
|
||||
@Test(timeout = 30000)
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.localization;
|
||||
|
||||
import art.arcane.volmlib.util.localization.LanguageDirectory;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
@@ -56,9 +57,9 @@ public class IrisLanguageHotloadSnapshotTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void snapshotsRejectFilesLargerThanTwoMebibytes() throws Exception {
|
||||
public void snapshotsRejectFilesOverTheLanguageSizeLimit() throws Exception {
|
||||
File language = temporaryFolder.newFile("en_US.toml");
|
||||
Files.write(language.toPath(), new byte[2 * 1024 * 1024 + 1]);
|
||||
Files.write(language.toPath(), new byte[(int) LanguageDirectory.MAXIMUM_BYTES + 1]);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> IrisLanguage.captureHotloadSnapshot(language, "en_US"));
|
||||
}
|
||||
|
||||
@@ -286,7 +286,8 @@ public class IrisLanguageTest {
|
||||
public void everyTranslatedGuideDescribesItsVariablesAndMatchesThePackagedGuide() throws Exception {
|
||||
Pattern definition = Pattern.compile("(?m)^# \\{([A-Za-z][A-Za-z0-9_]*)} (\\S[^\\r\\n]*)$");
|
||||
for (String locale : VolmitLocales.nonEnglish()) {
|
||||
String source = Files.readString(ProjectPaths.moduleFile("src/main/resources/languages/" + locale + ".toml"));
|
||||
String source = Files.readString(ProjectPaths.moduleFile("src/main/resources/languages/" + locale + ".toml"))
|
||||
.replace("\r\n", "\n");
|
||||
int bodyStart = source.indexOf("\n[") + 1;
|
||||
assertTrue(locale, bodyStart > 0);
|
||||
String header = source.substring(0, bodyStart);
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -19,6 +20,8 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeFalse;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
public final class SavedTerrainRegionSnapshotTest {
|
||||
private static final int SECTOR_BYTES = 4_096;
|
||||
@@ -29,6 +32,7 @@ public final class SavedTerrainRegionSnapshotTest {
|
||||
|
||||
@Test
|
||||
public void extractsInternalAndExternalPayloadDescriptors() throws Exception {
|
||||
assumeTrue(hasFileIdentity());
|
||||
byte[] bytes = new byte[4 * SECTOR_BYTES];
|
||||
ByteBuffer buffer = ByteBuffer.wrap(bytes);
|
||||
buffer.putInt(0, 2 << 8 | 1);
|
||||
@@ -67,6 +71,7 @@ public final class SavedTerrainRegionSnapshotTest {
|
||||
|
||||
@Test
|
||||
public void acceptsAnExactUnpaddedPayload() throws Exception {
|
||||
assumeTrue(hasFileIdentity());
|
||||
byte[] bytes = region(2 << 8 | 1, 3, 3, HEADER_BYTES + 7);
|
||||
bytes[HEADER_BYTES + 5] = 10;
|
||||
bytes[HEADER_BYTES + 6] = 0;
|
||||
@@ -78,6 +83,7 @@ public final class SavedTerrainRegionSnapshotTest {
|
||||
|
||||
@Test
|
||||
public void reusesLargerBuffersWithoutAcceptingStalePayloadBytes() throws Exception {
|
||||
assumeTrue(hasFileIdentity());
|
||||
byte[] larger = region(2 << 8 | 1, 5, 2, 4 * SECTOR_BYTES);
|
||||
ByteBuffer.wrap(larger).putInt(3 * SECTOR_BYTES, 1);
|
||||
larger[3 * SECTOR_BYTES + Integer.BYTES] = 2;
|
||||
@@ -110,6 +116,7 @@ public final class SavedTerrainRegionSnapshotTest {
|
||||
|
||||
@Test
|
||||
public void rejectsAtomicReplacementWithMatchingSizeAndTimestamp() throws Exception {
|
||||
assumeTrue(hasFileIdentity());
|
||||
byte[] bytes = region(2 << 8 | 1, 1, 2, 3 * SECTOR_BYTES);
|
||||
Path file = writeRegion(bytes);
|
||||
SavedTerrainRegionSnapshot snapshot = SavedTerrainRegionSnapshot.read(file, bytes.length, new byte[0]).orElseThrow();
|
||||
@@ -122,6 +129,7 @@ public final class SavedTerrainRegionSnapshotTest {
|
||||
|
||||
@Test
|
||||
public void rejectsSameFilePayloadModificationAndTruncation() throws Exception {
|
||||
assumeTrue(hasFileIdentity());
|
||||
byte[] bytes = region(2 << 8 | 1, 2, 2, 3 * SECTOR_BYTES);
|
||||
Path file = writeRegion(bytes);
|
||||
SavedTerrainRegionSnapshot snapshot = SavedTerrainRegionSnapshot.read(file, bytes.length, new byte[0]).orElseThrow();
|
||||
@@ -142,6 +150,7 @@ public final class SavedTerrainRegionSnapshotTest {
|
||||
|
||||
@Test
|
||||
public void validatesBothHeaderSectorsEvenWhenTimestampIsRestored() throws Exception {
|
||||
assumeTrue(hasFileIdentity());
|
||||
for (int offset : new int[]{0, SECTOR_BYTES}) {
|
||||
byte[] bytes = region(2 << 8 | 1, 1, 2, 3 * SECTOR_BYTES);
|
||||
Path file = writeRegion(bytes);
|
||||
@@ -158,6 +167,7 @@ public final class SavedTerrainRegionSnapshotTest {
|
||||
|
||||
@Test
|
||||
public void rejectsInvalidAllocationsAndPayloadLengths() throws Exception {
|
||||
assumeTrue(hasFileIdentity());
|
||||
int[][] cases = {
|
||||
{0, 1, 2, 3 * SECTOR_BYTES},
|
||||
{1 << 8 | 1, 1, 2, 3 * SECTOR_BYTES},
|
||||
@@ -193,6 +203,17 @@ public final class SavedTerrainRegionSnapshotTest {
|
||||
assertThrows(IOException.class, () -> SavedTerrainRegionSnapshot.read(link, HEADER_BYTES, new byte[0]));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readsNoSnapshotWithoutFileIdentity() throws Exception {
|
||||
assumeFalse(hasFileIdentity());
|
||||
byte[] bytes = region(2 << 8 | 1, 1, 2, 3 * SECTOR_BYTES);
|
||||
assertTrue(SavedTerrainRegionSnapshot.read(writeRegion(bytes), bytes.length, new byte[0]).isEmpty());
|
||||
}
|
||||
|
||||
private boolean hasFileIdentity() throws IOException {
|
||||
return Files.readAttributes(temporaryFolder.getRoot().toPath(), BasicFileAttributes.class).fileKey() != null;
|
||||
}
|
||||
|
||||
private Path writeRegion(byte[] bytes) throws IOException {
|
||||
Path file = temporaryFolder.newFile().toPath();
|
||||
Files.write(file, bytes);
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
import java.util.zip.DeflaterOutputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
@@ -23,6 +24,7 @@ import java.util.zip.GZIPOutputStream;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeFalse;
|
||||
|
||||
public final class SavedTerrainStatusReaderTest {
|
||||
@Rule
|
||||
@@ -47,6 +49,7 @@ public final class SavedTerrainStatusReaderTest {
|
||||
|
||||
@Test
|
||||
public void observesAtomicReplacementOfAnOpenRegion() throws Exception {
|
||||
assumeFalse(System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("win"));
|
||||
Path world = temporaryFolder.newFolder().toPath();
|
||||
Path replacement = temporaryFolder.newFolder().toPath();
|
||||
writeChunk(world, -1, -2, orderedRoot(), 2, false);
|
||||
|
||||
Reference in new issue
Block a user