use of ch.cyberduck.core.notification.DisabledNotificationService in project cyberduck by iterate-ch.
the class ConcurrentTransferWorkerTest method testBorrow.
@Test
public void testBorrow() throws Exception {
final Host host = new Host(new TestProtocol(), "test.cyberduck.ch");
final Transfer t = new UploadTransfer(host, new Path("/t", EnumSet.of(Path.Type.directory)), new NullLocal("l"));
final LoginConnectionService connection = new TestLoginConnectionService();
final DefaultSessionPool pool = new DefaultSessionPool(connection, new DisabledX509TrustManager(), new DefaultX509KeyManager(), new DefaultVaultRegistry(new DisabledPasswordCallback()), new DisabledTranscriptListener(), host);
final ConcurrentTransferWorker worker = new ConcurrentTransferWorker(pool, SessionPool.DISCONNECTED, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt(), new DisabledTransferErrorCallback(), new DisabledLoginCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledNotificationService());
assertNotSame(worker.borrow(ConcurrentTransferWorker.Connection.source), worker.borrow(ConcurrentTransferWorker.Connection.source));
worker.cleanup(true);
}
use of ch.cyberduck.core.notification.DisabledNotificationService in project cyberduck by iterate-ch.
the class ConcurrentTransferWorkerTest method testSessionReuse.
@Test
public void testSessionReuse() throws Exception {
final Host host = new Host(new TestProtocol(), "test.cyberduck.ch");
final Transfer t = new UploadTransfer(host, new Path("/t", EnumSet.of(Path.Type.directory)), new NullLocal("l"));
final LoginConnectionService connection = new TestLoginConnectionService();
final DefaultSessionPool pool = new DefaultSessionPool(connection, new DisabledX509TrustManager(), new DefaultX509KeyManager(), new DefaultVaultRegistry(new DisabledPasswordCallback()), new DisabledTranscriptListener(), host);
final ConcurrentTransferWorker worker = new ConcurrentTransferWorker(pool.withMaxTotal(1), SessionPool.DISCONNECTED, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt(), new DisabledTransferErrorCallback(), new DisabledLoginCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledNotificationService());
// Override default transfer queue size
pool.withMaxTotal(1);
final Session<?> session = worker.borrow(ConcurrentTransferWorker.Connection.source);
worker.release(session, ConcurrentTransferWorker.Connection.source, null);
assertEquals(Session.State.closed, session.getState());
final Session<?> reuse = worker.borrow(ConcurrentTransferWorker.Connection.source);
assertSame(session, reuse);
final CyclicBarrier lock = new CyclicBarrier(2);
new Thread(new Runnable() {
@Override
public void run() {
try {
assertSame(session, worker.borrow(ConcurrentTransferWorker.Connection.source));
try {
lock.await(1, TimeUnit.MINUTES);
} catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
fail();
}
} catch (BackgroundException e) {
fail();
}
}
}).start();
worker.release(reuse, ConcurrentTransferWorker.Connection.source, null);
lock.await(1, TimeUnit.MINUTES);
worker.cleanup(true);
}
use of ch.cyberduck.core.notification.DisabledNotificationService in project cyberduck by iterate-ch.
the class FTPConcurrentTransferWorkerTest method testConcurrentSessions.
@Test
public void testConcurrentSessions() throws Exception {
final int files = 20;
final int connections = 2;
final List<TransferItem> list = new ArrayList<>();
final Local file = new Local(File.createTempFile(new AlphanumericRandomStringService().random(), "t").getAbsolutePath());
for (int i = 1; i <= files; i++) {
list.add(new TransferItem(new Path(String.format("/t%d", i), EnumSet.of(Path.Type.file)), file));
}
final Transfer transfer = new UploadTransfer(session.getHost(), list);
final DefaultSessionPool pool = new DefaultSessionPool(new LoginConnectionService(new DisabledLoginCallback() {
@Override
public Credentials prompt(final Host bookmark, final String username, final String title, final String reason, final LoginOptions options) {
return new Credentials(username, "test");
}
@Override
public void warn(final Host bookmark, final String title, final String message, final String continueButton, final String disconnectButton, final String preference) {
//
}
}, new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener()), new DisabledX509TrustManager(), new DefaultX509KeyManager(), new DefaultVaultRegistry(new DisabledPasswordCallback()), new DisabledTranscriptListener(), session.getHost());
final ConcurrentTransferWorker worker = new ConcurrentTransferWorker(pool.withMaxTotal(connections), SessionPool.DISCONNECTED, transfer, new TransferOptions(), new TransferSpeedometer(transfer), new DisabledTransferPrompt() {
@Override
public TransferAction prompt(final TransferItem file) {
return TransferAction.overwrite;
}
}, new DisabledTransferErrorCallback(), new DisabledLoginCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledNotificationService());
pool.withMaxTotal(connections);
final Session<?> session = worker.borrow(ConcurrentTransferWorker.Connection.source);
assertTrue(worker.run(session));
worker.release(session, ConcurrentTransferWorker.Connection.source, null);
assertEquals(0L, transfer.getTransferred(), 0L);
worker.cleanup(true);
}
use of ch.cyberduck.core.notification.DisabledNotificationService in project cyberduck by iterate-ch.
the class CryptoAzureSingleTransferWorkerTest method testUpload.
@Test
public void testUpload() throws Exception {
final Path home = new Path("cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory));
final CryptoVault cryptomator = new CryptoVault(new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)));
final Path vault = cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
final Path dir1 = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.placeholder));
final Local localDirectory1 = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
new DefaultLocalDirectoryFeature().mkdir(localDirectory1);
final byte[] content = RandomUtils.nextBytes(62768);
final Path file1 = new Path(dir1, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final Local localFile1 = new Local(localDirectory1, file1.getName());
final OutputStream out1 = localFile1.getOutputStream(false);
IOUtils.write(content, out1);
out1.close();
final Path file2 = new Path(dir1, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final Local localFile2 = new Local(localDirectory1, file2.getName());
final OutputStream out2 = localFile2.getOutputStream(false);
IOUtils.write(content, out2);
out2.close();
final Transfer t = new UploadTransfer(new Host(new TestProtocol()), Collections.singletonList(new TransferItem(dir1, localDirectory1)), new NullFilter<>());
assertTrue(new SingleTransferWorker(session, session, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt() {
@Override
public TransferAction prompt(final TransferItem file) {
return TransferAction.overwrite;
}
}, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService()) {
}.run(session));
assertTrue(new CryptoFindFeature(session, new AzureFindFeature(session, null), cryptomator).find(dir1));
assertEquals(content.length, new CryptoAttributesFeature(session, new AzureAttributesFinderFeature(session, null), cryptomator).find(file1).getSize());
{
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
final InputStream in = new CryptoReadFeature(session, new AzureReadFeature(session, null), cryptomator).read(file1, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(in, buffer);
assertArrayEquals(content, buffer.toByteArray());
}
assertEquals(content.length, new CryptoAttributesFeature(session, new AzureAttributesFinderFeature(session, null), cryptomator).find(file2).getSize());
{
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
final InputStream in = new CryptoReadFeature(session, new AzureReadFeature(session, null), cryptomator).read(file1, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(in, buffer);
assertArrayEquals(content, buffer.toByteArray());
}
cryptomator.getFeature(session, Delete.class, new AzureDeleteFeature(session, null)).delete(Arrays.asList(file1, file2, dir1, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
localFile1.delete();
localFile2.delete();
localDirectory1.delete();
}
use of ch.cyberduck.core.notification.DisabledNotificationService in project cyberduck by iterate-ch.
the class B2SingleTransferWorkerTest method testTransferredSizeRepeat.
@Test
public void testTransferredSizeRepeat() throws Exception {
final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
final byte[] content = new byte[100 * 1024 * 1024 + 1];
new Random().nextBytes(content);
final OutputStream out = local.getOutputStream(false);
IOUtils.write(content, out);
out.close();
final AtomicBoolean failed = new AtomicBoolean();
final B2Session custom = new B2Session(session.getHost().withCredentials(new Credentials(System.getProperties().getProperty("b2.user"), System.getProperties().getProperty("b2.key"))), new DefaultX509TrustManager(), new DefaultX509KeyManager()) {
final B2LargeUploadService upload = new B2LargeUploadService(this, new B2VersionIdProvider(this), new B2WriteFeature(this, new B2VersionIdProvider(this)), PreferencesFactory.get().getLong("b2.upload.largeobject.size"), PreferencesFactory.get().getInteger("b2.upload.largeobject.concurrency")) {
@Override
protected InputStream decorate(final InputStream in, final MessageDigest digest) {
if (failed.get()) {
// Second attempt successful
return in;
}
return new CountingInputStream(in) {
@Override
protected void beforeRead(final int n) throws IOException {
super.beforeRead(n);
if (this.getByteCount() >= 100L * 1024L * 1024L) {
failed.set(true);
throw new SocketTimeoutException();
}
}
};
}
};
@Override
@SuppressWarnings("unchecked")
public <T> T _getFeature(final Class<T> type) {
if (type == Upload.class) {
return (T) upload;
}
return super._getFeature(type);
}
};
custom.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback());
custom.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback());
final Path bucket = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
final Path test = new Path(bucket, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
final Transfer t = new UploadTransfer(session.getHost(), test, local);
final BytecountStreamListener counter = new BytecountStreamListener();
assertTrue(new SingleTransferWorker(custom, custom, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt() {
@Override
public TransferAction prompt(final TransferItem file) {
return TransferAction.overwrite;
}
}, new DisabledTransferErrorCallback(), new DisabledProgressListener(), counter, new DisabledLoginCallback(), new DisabledNotificationService()) {
}.run(custom));
local.delete();
assertTrue(t.isComplete());
final B2VersionIdProvider fileid = new B2VersionIdProvider(custom);
assertEquals(content.length, new B2AttributesFinderFeature(custom, fileid).find(test).getSize());
assertEquals(content.length, counter.getRecv(), 0L);
assertEquals(content.length, counter.getSent(), 0L);
assertTrue(failed.get());
new B2DeleteFeature(custom, fileid).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Aggregations