use of ch.cyberduck.core.PathCache in project cyberduck by iterate-ch.
the class SearchWorkerTest method testRun.
@Test
public void testRun() throws Exception {
final PathCache cache = new PathCache(Integer.MAX_VALUE);
final AttributedList<Path> root = new AttributedList<>();
root.add(new Path("/t1.png", EnumSet.of(Path.Type.file)));
root.add(new Path("/t1.gif", EnumSet.of(Path.Type.file)));
final Path folder = new Path("/folder", EnumSet.of(Path.Type.directory));
root.add(folder);
root.add(new Path("/folder2", EnumSet.of(Path.Type.directory)));
cache.put(new Path("/", EnumSet.of(Path.Type.directory)), root);
final AttributedList<Path> folderContents = new AttributedList<>();
folderContents.add(new Path(folder, "/t2.png", EnumSet.of(Path.Type.file)));
folderContents.add(new Path(folder, "/t2.gif", EnumSet.of(Path.Type.file)));
final Path subfolder = new Path(folder, "/subfolder", EnumSet.of(Path.Type.directory));
folderContents.add(subfolder);
cache.put(folder, folderContents);
final AttributedList<Path> subfolderContents = new AttributedList<>();
subfolderContents.add(new Path(subfolder, "t2.png", EnumSet.of(Path.Type.file)));
subfolderContents.add(new Path(subfolder, "t2.gif", EnumSet.of(Path.Type.file)));
cache.put(subfolder, subfolderContents);
final SearchWorker search = new SearchWorker(new Path("/", EnumSet.of(Path.Type.directory)), new SearchFilter(".png"), cache, new DisabledListProgressListener());
final AttributedList<Path> found = search.run(new NullSession(new Host(new TestProtocol())));
assertTrue(found.contains(new Path("/t1.png", EnumSet.of(Path.Type.file))));
assertFalse(found.contains(new Path("/t1.gif", EnumSet.of(Path.Type.file))));
assertFalse(found.contains(new Path("/t2.png", EnumSet.of(Path.Type.file))));
assertFalse(found.contains(new Path("/t2.gif", EnumSet.of(Path.Type.file))));
assertTrue(found.contains(folder));
assertTrue(found.contains(new Path(folder, "/t2.png", EnumSet.of(Path.Type.file))));
assertTrue(found.contains(subfolder));
assertTrue(found.contains(new Path(subfolder, "/t2.png", EnumSet.of(Path.Type.file))));
assertFalse(found.contains(new Path(new Path("/folder2", EnumSet.of(Path.Type.directory)), "/t2.gif", EnumSet.of(Path.Type.file))));
assertFalse(found.contains(new Path("/folder2", EnumSet.of(Path.Type.directory))));
}
use of ch.cyberduck.core.PathCache in project cyberduck by iterate-ch.
the class CachingFindFeatureTest method testFindDefault.
@Test
public void testFindDefault() throws Exception {
final PathCache cache = new PathCache(1);
final Path bucket = new Path("versioning-test-us-east-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
final String name = new AlphanumericRandomStringService().random();
final CachingFindFeature f = new CachingFindFeature(cache, new DefaultFindFeature(session));
assertFalse(f.find(new Path(bucket, name, EnumSet.of(Path.Type.file))));
final Path test = new S3TouchFeature(session).touch(new Path(bucket, name, EnumSet.of(Path.Type.file)), new TransferStatus());
assertFalse(f.find(test));
cache.clear();
assertTrue(f.find(test));
// Find without version id set in attributes
assertTrue(f.find(new Path(test).withAttributes(PathAttributes.EMPTY)));
new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.PathCache in project cyberduck by iterate-ch.
the class CachingAttributesFinderFeatureTest method testAttributes.
@Test
public void testAttributes() throws Exception {
final PathCache cache = new PathCache(1);
final AttributesFinder f = new CachingAttributesFinderFeature(cache, new DefaultAttributesFinderFeature(session));
final String name = new AlphanumericRandomStringService().random();
final Path file = new DAVTouchFeature(session).touch(new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
final Attributes lookup = f.find(file);
assertEquals(0L, lookup.getSize());
// Test cache
assertSame(lookup, new CachingAttributesFinderFeature(cache, new AttributesFinder() {
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) {
fail("Expected cache hit");
return PathAttributes.EMPTY;
}
}).find(file));
assertEquals(0L, f.find(file).getSize());
assertTrue(cache.containsKey(file.getParent()));
// Test wrong type
try {
f.find(new Path(new DefaultHomeFinderService(session).find(), name, EnumSet.of(Path.Type.directory)));
fail();
} catch (NotfoundException e) {
// Expected
}
new DAVDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.PathCache in project cyberduck by iterate-ch.
the class SyncTransferTest method testFilterMirror.
@Test
public void testFilterMirror() throws Exception {
final Path p = new Path("t", EnumSet.of(Path.Type.directory));
final Path a = new Path(p, "a", EnumSet.of(Path.Type.file));
final Path b = new Path(p, "b", EnumSet.of(Path.Type.file));
final PathCache cache = new PathCache(1);
cache.put(p, new AttributedList<>(Arrays.asList(a, b)));
SyncTransfer t = new SyncTransfer(new Host(new TestProtocol()), new TransferItem(p, new NullLocal(System.getProperty("java.io.tmpdir"), "t")));
t.withCache(cache);
final NullSession session = new NullTransferSession(new Host(new TestProtocol()));
final TransferPathFilter filter = t.filter(session, null, TransferAction.mirror, new DisabledProgressListener());
assertTrue(filter.accept(a, new NullLocal(System.getProperty("java.io.tmpdir"), "a") {
@Override
public boolean exists() {
return true;
}
@Override
public LocalAttributes attributes() {
return new LocalAttributes(this.getAbsolute()) {
@Override
public long getSize() {
return 1L;
}
};
}
}, new TransferStatus().exists(true)));
assertTrue(filter.accept(b, new NullLocal(System.getProperty("java.io.tmpdir"), "b") {
@Override
public boolean exists() {
return true;
}
@Override
public LocalAttributes attributes() {
return new LocalAttributes(this.getAbsolute()) {
@Override
public long getSize() {
return 0L;
}
};
}
}, new TransferStatus().exists(true)));
assertEquals(Comparison.local, t.compare(new TransferItem(a, new NullLocal(System.getProperty("java.io.tmpdir"), "a"))));
assertEquals(Comparison.remote, t.compare(new TransferItem(b, new NullLocal(System.getProperty("java.io.tmpdir"), "b"))));
}
use of ch.cyberduck.core.PathCache in project cyberduck by iterate-ch.
the class DriveWriteFeatureTest method testWriteWithCache.
@Test
public void testWriteWithCache() throws Exception {
final TransferStatus status = new TransferStatus();
final int length = 1048576;
final byte[] content = RandomUtils.nextBytes(length);
status.setLength(content.length);
final Path home = DriveHomeFinderService.MYDRIVE_FOLDER;
final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final CryptoVault cryptomator = new CryptoVault(vault);
cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
final DriveFileIdProvider fileid = new DriveFileIdProvider(session);
final CryptoWriteFeature<File> writer = new CryptoWriteFeature<>(session, new DriveWriteFeature(session, fileid), cryptomator);
final FileHeader header = cryptomator.getFileHeaderCryptor().create();
status.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
status.setNonces(new RandomNonceGenerator());
status.setChecksum(writer.checksum(test, status).compute(new ByteArrayInputStream(content), status));
final OutputStream out = writer.write(test, status, new DisabledConnectionCallback());
assertNotNull(out);
new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
out.close();
assertTrue(new CryptoFindFeature(session, new DriveFindFeature(session, fileid), cryptomator).find(test));
final Path found = new CryptoListService(session, new DriveListService(session, fileid), cryptomator).list(test.getParent(), new DisabledListProgressListener()).find(new SimplePathPredicate(test));
final String fileId = found.attributes().getFileId();
assertNotNull(fileId);
final Cache<Path> cache = new PathCache(1);
final AttributedList<Path> list = new AttributedList<>();
list.add(found);
cache.put(vault, list);
assertEquals(content.length, cache.get(vault).get(0).attributes().getSize());
assertEquals(content.length, found.attributes().getSize());
assertEquals(content.length, writer.append(test, status.withRemote(found.attributes())).size, 0L);
{
final PathAttributes attributes = new CryptoAttributesFeature(session, new DriveAttributesFinderFeature(session, fileid), cryptomator).find(test);
assertEquals(content.length, attributes.getSize());
assertEquals(fileId, found.attributes().getFileId());
}
{
final PathAttributes attributes = new CryptoAttributesFeature(session, new DefaultAttributesFinderFeature(session), cryptomator).find(test);
assertEquals(content.length, attributes.getSize());
assertEquals(fileId, found.attributes().getFileId());
}
{
final PathAttributes attributes = new CryptoAttributesFeature(session, new DefaultAttributesFinderFeature(session), cryptomator).find(test);
assertEquals(content.length, attributes.getSize());
assertEquals(fileId, found.attributes().getFileId());
}
assertEquals(content.length, cache.get(vault).get(0).attributes().getSize());
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
final InputStream in = new CryptoReadFeature(session, new DriveReadFeature(session, fileid), cryptomator).read(test, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
new StreamCopier(status, status).transfer(in, buffer);
assertArrayEquals(content, buffer.toByteArray());
cryptomator.getFeature(session, Delete.class, new DriveDeleteFeature(session, fileid)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
session.close();
}
Aggregations