mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-08-17 20:56:02 +00:00
added test for file/folder move operations
This commit is contained in:
+5
-7
@@ -1,21 +1,19 @@
|
||||
package org.cryptomator.shortening;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.cryptomator.filesystem.FileSystem;
|
||||
import org.cryptomator.filesystem.Folder;
|
||||
|
||||
/**
|
||||
* Filesystem implementation, that shortens filenames when they reach a certain threshold (inclusive).
|
||||
* Shortening is done by SHA1-hashing those files, so a threshold below the length of the hashed files makes no sense.
|
||||
* Hashes are then mapped back to the original filenames by storing metadata files inside the given metadataRoot.
|
||||
*/
|
||||
public class ShorteningFileSystem extends ShorteningFolder implements FileSystem {
|
||||
|
||||
public ShorteningFileSystem(Folder root, Folder metadataRoot, int threshold) {
|
||||
super(null, root, "", metadataRoot, new FilenameShortener(metadataRoot, threshold));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ShorteningFolder> parent() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return true;
|
||||
|
||||
+43
-1
@@ -2,6 +2,7 @@ package org.cryptomator.shortening;
|
||||
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.time.Instant;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
@@ -47,6 +48,41 @@ public class ShorteningFileSystemTest {
|
||||
Assert.assertTrue(correspondingMetadataFile.exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMoveLongFolders() {
|
||||
final FileSystem underlyingFs = new InMemoryFileSystem();
|
||||
final Folder metadataRoot = underlyingFs.folder("m");
|
||||
final FileSystem fs = new ShorteningFileSystem(underlyingFs, metadataRoot, 10);
|
||||
|
||||
final Folder shortNamedFolder = fs.folder("test");
|
||||
shortNamedFolder.create(FolderCreateMode.FAIL_IF_PARENT_IS_MISSING);
|
||||
Assert.assertFalse(metadataRoot.children().findAny().isPresent());
|
||||
|
||||
final Folder longNamedFolder = fs.folder("morethantenchars");
|
||||
shortNamedFolder.moveTo(longNamedFolder);
|
||||
Assert.assertTrue(metadataRoot.children().findAny().isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMoveLongFiles() throws UncheckedIOException, TimeoutException {
|
||||
final FileSystem underlyingFs = new InMemoryFileSystem();
|
||||
final Folder metadataRoot = underlyingFs.folder("m");
|
||||
final FileSystem fs = new ShorteningFileSystem(underlyingFs, metadataRoot, 10);
|
||||
|
||||
final File shortNamedFolder = fs.file("test");
|
||||
try (WritableFile file = shortNamedFolder.openWritable(1, TimeUnit.MILLISECONDS)) {
|
||||
file.write(ByteBuffer.wrap("hello world".getBytes()));
|
||||
}
|
||||
Assert.assertFalse(metadataRoot.children().findAny().isPresent());
|
||||
|
||||
final File longNamedFolder = fs.file("morethantenchars");
|
||||
try (WritableFile src = shortNamedFolder.openWritable(1, TimeUnit.MILLISECONDS); //
|
||||
WritableFile dst = longNamedFolder.openWritable(1, TimeUnit.MILLISECONDS)) {
|
||||
src.moveTo(dst);
|
||||
}
|
||||
Assert.assertTrue(metadataRoot.children().findAny().isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeflateAndInflateFolder() {
|
||||
final FileSystem underlyingFs = new InMemoryFileSystem();
|
||||
@@ -82,11 +118,15 @@ public class ShorteningFileSystemTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPassthroughShortNamedFiles() throws UncheckedIOException, TimeoutException {
|
||||
public void testPassthroughShortNamedFiles() throws UncheckedIOException, TimeoutException, InterruptedException {
|
||||
final FileSystem underlyingFs = new InMemoryFileSystem();
|
||||
final Folder metadataRoot = underlyingFs.folder("m");
|
||||
final FileSystem fs = new ShorteningFileSystem(underlyingFs, metadataRoot, 10);
|
||||
|
||||
final Instant testStart = Instant.now();
|
||||
|
||||
Thread.sleep(1);
|
||||
|
||||
// of folders:
|
||||
underlyingFs.folder("foo").folder("bar").create(FolderCreateMode.INCLUDING_PARENTS);
|
||||
Assert.assertTrue(fs.folder("foo").folder("bar").exists());
|
||||
@@ -100,6 +140,7 @@ public class ShorteningFileSystemTest {
|
||||
file.read(buf);
|
||||
Assert.assertEquals("hello world", new String(buf.array()));
|
||||
}
|
||||
Assert.assertTrue(fs.folder("foo").file("test1.txt").lastModified().isAfter(testStart));
|
||||
|
||||
// to underlying:
|
||||
try (WritableFile file = fs.folder("foo").file("test2.txt").openWritable(1, TimeUnit.MILLISECONDS)) {
|
||||
@@ -110,6 +151,7 @@ public class ShorteningFileSystemTest {
|
||||
file.read(buf);
|
||||
Assert.assertEquals("hello world", new String(buf.array()));
|
||||
}
|
||||
Assert.assertTrue(fs.folder("foo").file("test2.txt").lastModified().isAfter(testStart));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user