mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 09:44:24 +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
@@ -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