mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-13 21:13:53 +00:00
Re-apply 374ad99
Accidentally fixed the EntryMaker issue before I pulled 374ad99
. Should reflect upstream now.
This commit is contained in:
committed by
IronApollo
parent
8b97a11fa4
commit
415e91b519
@ -19,6 +19,8 @@
|
||||
|
||||
package com.sk89q.worldedit.world.snapshot.experimental.fs;
|
||||
|
||||
import com.sk89q.worldedit.util.io.Closer;
|
||||
import com.sk89q.worldedit.util.io.file.ArchiveDir;
|
||||
import com.sk89q.worldedit.util.io.file.ArchiveNioSupport;
|
||||
import com.sk89q.worldedit.world.snapshot.experimental.Snapshot;
|
||||
|
||||
@ -28,6 +30,7 @@ import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
@ -67,19 +70,34 @@ class FSSDContext {
|
||||
String worldName = Paths.get(name).getFileName().toString();
|
||||
// Without an extension
|
||||
worldName = worldName.split("\\.")[0];
|
||||
List<Snapshot> snapshots = db.getSnapshots(worldName).collect(toList());
|
||||
assertTrue(1 >= snapshots.size(),
|
||||
"Too many snapshots matched for " + worldName);
|
||||
return requireSnapshot(name, snapshots.stream().findAny().orElse(null));
|
||||
List<Snapshot> snapshots;
|
||||
try (Stream<Snapshot> snapshotStream = db.getSnapshots(worldName)) {
|
||||
snapshots = snapshotStream.collect(toList());
|
||||
}
|
||||
try {
|
||||
assertTrue(snapshots.size() <= 1,
|
||||
"Too many snapshots matched for " + worldName);
|
||||
return requireSnapshot(name, snapshots.stream().findAny().orElse(null));
|
||||
} catch (Throwable t) {
|
||||
Closer closer = Closer.create();
|
||||
snapshots.forEach(closer::register);
|
||||
throw closer.rethrowAndClose(t);
|
||||
}
|
||||
}
|
||||
|
||||
Snapshot requireSnapshot(String name, @Nullable Snapshot snapshot) {
|
||||
Snapshot requireSnapshot(String name, @Nullable Snapshot snapshot) throws IOException {
|
||||
assertNotNull(snapshot, "No snapshot for " + name);
|
||||
assertEquals(name, snapshot.getInfo().getDisplayName());
|
||||
try {
|
||||
assertEquals(name, snapshot.getInfo().getDisplayName());
|
||||
} catch (Throwable t) {
|
||||
Closer closer = Closer.create();
|
||||
closer.register(snapshot);
|
||||
throw closer.rethrowAndClose(t);
|
||||
}
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
Path getRootOfArchive(Path archive) throws IOException {
|
||||
ArchiveDir getRootOfArchive(Path archive) throws IOException {
|
||||
return archiveNioSupport.tryOpenAsDir(archive)
|
||||
.orElseThrow(() -> new AssertionError("No archive opener for " + archive));
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.world.snapshot.experimental.fs;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.util.io.file.ArchiveDir;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
import com.sk89q.worldedit.world.snapshot.experimental.Snapshot;
|
||||
import org.junit.jupiter.api.DynamicNode;
|
||||
@ -29,7 +30,6 @@ import org.junit.jupiter.api.DynamicTest;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
@ -38,8 +38,9 @@ import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static com.sk89q.worldedit.world.snapshot.experimental.fs.FileSystemSnapshotDatabaseTest.CHUNK_TAG;
|
||||
|
||||
import static com.sk89q.worldedit.world.snapshot.experimental.fs.FileSystemSnapshotDatabaseTest.CHUNK_POS;
|
||||
import static com.sk89q.worldedit.world.snapshot.experimental.fs.FileSystemSnapshotDatabaseTest.CHUNK_TAG;
|
||||
import static com.sk89q.worldedit.world.snapshot.experimental.fs.FileSystemSnapshotDatabaseTest.TIME_ONE;
|
||||
import static com.sk89q.worldedit.world.snapshot.experimental.fs.FileSystemSnapshotDatabaseTest.TIME_TWO;
|
||||
import static com.sk89q.worldedit.world.snapshot.experimental.fs.FileSystemSnapshotDatabaseTest.WORLD_ALPHA;
|
||||
@ -102,16 +103,11 @@ enum FSSDTestType {
|
||||
List<DynamicTest> getTests(FSSDContext context) throws IOException {
|
||||
Path worldArchive = EntryMaker.WORLD_ARCHIVE
|
||||
.createEntry(context.db.getRoot(), WORLD_ALPHA);
|
||||
Path rootOfArchive = context.getRootOfArchive(worldArchive);
|
||||
try {
|
||||
try (ArchiveDir rootOfArchive = context.getRootOfArchive(worldArchive)) {
|
||||
Files.setLastModifiedTime(
|
||||
rootOfArchive,
|
||||
rootOfArchive.getPath(),
|
||||
FileTime.from(TIME_ONE.toInstant())
|
||||
);
|
||||
} finally {
|
||||
if (rootOfArchive.getFileSystem() != FileSystems.getDefault()) {
|
||||
rootOfArchive.getFileSystem().close();
|
||||
}
|
||||
}
|
||||
return singleSnapTest(context, WORLD_ALPHA + ".zip", TIME_ONE);
|
||||
}
|
||||
@ -144,14 +140,9 @@ enum FSSDTestType {
|
||||
Path root = context.db.getRoot();
|
||||
Path timestampedArchive = EntryMaker.TIMESTAMPED_ARCHIVE
|
||||
.createEntry(root, TIME_ONE);
|
||||
Path timestampedDir = context.getRootOfArchive(timestampedArchive);
|
||||
try {
|
||||
EntryMaker.WORLD_DIR.createEntry(timestampedDir, WORLD_ALPHA);
|
||||
EntryMaker.WORLD_ARCHIVE.createEntry(timestampedDir, WORLD_BETA);
|
||||
} finally {
|
||||
if (timestampedDir.getFileSystem() != FileSystems.getDefault()) {
|
||||
timestampedDir.getFileSystem().close();
|
||||
}
|
||||
try (ArchiveDir timestampedDir = context.getRootOfArchive(timestampedArchive)) {
|
||||
EntryMaker.WORLD_DIR.createEntry(timestampedDir.getPath(), WORLD_ALPHA);
|
||||
EntryMaker.WORLD_ARCHIVE.createEntry(timestampedDir.getPath(), WORLD_BETA);
|
||||
}
|
||||
return ImmutableList.of(
|
||||
dynamicContainer("world dir",
|
||||
@ -261,16 +252,18 @@ enum FSSDTestType {
|
||||
}
|
||||
};
|
||||
|
||||
private static List<DynamicTest> singleSnapTest(FSSDContext context, String name,
|
||||
List<DynamicTest> singleSnapTest(FSSDContext context, String name,
|
||||
ZonedDateTime time) {
|
||||
return ImmutableList.of(
|
||||
dynamicTest("return a valid snapshot for " + name, () -> {
|
||||
Snapshot snapshot = context.requireSnapshot(name);
|
||||
assertValidSnapshot(time, snapshot);
|
||||
try (Snapshot snapshot = context.requireSnapshot(name)) {
|
||||
assertValidSnapshot(time, snapshot);
|
||||
}
|
||||
}),
|
||||
dynamicTest("list a valid snapshot for " + name, () -> {
|
||||
Snapshot snapshot = context.requireListsSnapshot(name);
|
||||
assertValidSnapshot(time, snapshot);
|
||||
try (Snapshot snapshot = context.requireListsSnapshot(name)) {
|
||||
assertValidSnapshot(time, snapshot);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ import com.sk89q.worldedit.util.io.file.ZipArchiveNioSupport;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
import com.sk89q.worldedit.world.storage.ChunkStoreHelper;
|
||||
import com.sk89q.worldedit.world.storage.McRegionReader;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.DynamicNode;
|
||||
@ -76,6 +77,8 @@ class FileSystemSnapshotDatabaseTest {
|
||||
.atZone(ZoneId.systemDefault());
|
||||
static final ZonedDateTime TIME_TWO = TIME_ONE.minusDays(1);
|
||||
|
||||
private static Path TEMP_DIR;
|
||||
|
||||
@BeforeAll
|
||||
static void setUpStatic() throws IOException, DataException {
|
||||
try (InputStream in = Resources.getResource("world_region.mca.gzip").openStream();
|
||||
@ -104,10 +107,17 @@ class FileSystemSnapshotDatabaseTest {
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
|
||||
TEMP_DIR = Files.createTempDirectory("worldedit-fs-snap-dbs");
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void afterAll() throws IOException {
|
||||
deleteTree(TEMP_DIR);
|
||||
}
|
||||
|
||||
private static Path newTempDb() throws IOException {
|
||||
return Files.createTempDirectory("worldedit-fs-snap-db");
|
||||
return Files.createTempDirectory(TEMP_DIR, "db");
|
||||
}
|
||||
|
||||
private static void deleteTree(Path root) throws IOException {
|
||||
@ -175,7 +185,6 @@ class FileSystemSnapshotDatabaseTest {
|
||||
try {
|
||||
Path dbRoot = root.resolve("snapshots");
|
||||
Files.createDirectories(dbRoot);
|
||||
// we leak `root` here, but I can't see a good way to clean it up.
|
||||
return type.getNamedTests(new FSSDContext(nioSupport, dbRoot));
|
||||
} catch (Throwable t) {
|
||||
deleteTree(root);
|
||||
|
Reference in New Issue
Block a user