Search in sources :

Example 1 with S3MultipartUploadService

use of ch.cyberduck.core.s3.S3MultipartUploadService in project cyberduck by iterate-ch.

the class S3MultipartUploadServiceTest method testUploadSinglePart.

@Test
public void testUploadSinglePart() throws Exception {
    // 5L * 1024L * 1024L
    final Path home = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory));
    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 CryptoUploadFeature m = new CryptoUploadFeature<>(session, new S3MultipartUploadService(session, new S3WriteFeature(session), 5L * 1024L * 1024L, 5), new S3WriteFeature(session), cryptomator);
    final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    final int length = 5242880;
    final byte[] content = RandomUtils.nextBytes(length);
    IOUtils.write(content, local.getOutputStream(false));
    final TransferStatus writeStatus = new TransferStatus();
    final FileHeader header = cryptomator.getFileHeaderCryptor().create();
    writeStatus.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
    writeStatus.setLength(content.length);
    final BytecountStreamListener count = new BytecountStreamListener();
    m.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), count, writeStatus, null);
    assertEquals(content.length, count.getSent());
    assertTrue(writeStatus.isComplete());
    assertTrue(new CryptoFindFeature(session, new S3FindFeature(session), cryptomator).find(test));
    assertEquals(content.length, new CryptoAttributesFeature(session, new S3AttributesFinderFeature(session), cryptomator).find(test).getSize());
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
    final TransferStatus readStatus = new TransferStatus().withLength(content.length);
    final InputStream in = new CryptoReadFeature(session, new S3ReadFeature(session), cryptomator).read(test, readStatus, new DisabledConnectionCallback());
    new StreamCopier(readStatus, readStatus).transfer(in, buffer);
    assertArrayEquals(content, buffer.toByteArray());
    cryptomator.getFeature(session, Delete.class, new S3DefaultDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
    local.delete();
}
Also used : Delete(ch.cyberduck.core.features.Delete) S3AttributesFinderFeature(ch.cyberduck.core.s3.S3AttributesFinderFeature) S3MultipartUploadService(ch.cyberduck.core.s3.S3MultipartUploadService) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) CryptoReadFeature(ch.cyberduck.core.cryptomator.features.CryptoReadFeature) FileHeader(org.cryptomator.cryptolib.api.FileHeader) CryptoUploadFeature(ch.cyberduck.core.cryptomator.features.CryptoUploadFeature) Path(ch.cyberduck.core.Path) S3FindFeature(ch.cyberduck.core.s3.S3FindFeature) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) S3DefaultDeleteFeature(ch.cyberduck.core.s3.S3DefaultDeleteFeature) InputStream(java.io.InputStream) Local(ch.cyberduck.core.Local) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener) CryptoFindFeature(ch.cyberduck.core.cryptomator.features.CryptoFindFeature) CryptoAttributesFeature(ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature) BandwidthThrottle(ch.cyberduck.core.io.BandwidthThrottle) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) S3ReadFeature(ch.cyberduck.core.s3.S3ReadFeature) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) S3WriteFeature(ch.cyberduck.core.s3.S3WriteFeature) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) AbstractS3Test(ch.cyberduck.core.s3.AbstractS3Test) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 2 with S3MultipartUploadService

use of ch.cyberduck.core.s3.S3MultipartUploadService in project cyberduck by iterate-ch.

the class S3SingleTransferWorkerTest method testTransferredSizeRepeat.

@Test
public void testTransferredSizeRepeat() throws Exception {
    final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
    // Minimum multipart upload size
    final byte[] content = new byte[6 * 1024 * 1024];
    new Random().nextBytes(content);
    final OutputStream out = local.getOutputStream(false);
    IOUtils.write(content, out);
    out.close();
    final ProtocolFactory factory = new ProtocolFactory(new HashSet<>(Collections.singleton(new S3Protocol())));
    final Profile profile = new ProfilePlistReader(factory).read(this.getClass().getResourceAsStream("/S3 (HTTPS).cyberduckprofile"));
    final Host host = new Host(profile, profile.getDefaultHostname(), new Credentials(System.getProperties().getProperty("s3.key"), System.getProperties().getProperty("s3.secret")));
    final AtomicBoolean failed = new AtomicBoolean();
    final S3Session session = new S3Session(host, new DefaultX509TrustManager(), new DefaultX509KeyManager()) {

        @Override
        @SuppressWarnings("unchecked")
        public <T> T _getFeature(final Class<T> type) {
            if (type == Upload.class) {
                return (T) new S3MultipartUploadService(this, new S3WriteFeature(this), 5 * 1024L * 1024L, 5) {

                    @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() >= 1024L * 1024L) {
                                    failed.set(true);
                                    throw new SocketTimeoutException();
                                }
                            }
                        };
                    }
                };
            }
            return super._getFeature(type);
        }
    };
    session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback());
    session.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path home = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory));
    final Path test = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Transfer t = new UploadTransfer(session.getHost(), test, local);
    final BytecountStreamListener counter = new BytecountStreamListener();
    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(), counter, new DisabledLoginCallback(), new DisabledNotificationService()) {
    }.run(session));
    local.delete();
    assertTrue(t.isComplete());
    assertEquals(content.length, new S3AttributesFinderFeature(session).find(test).getSize());
    assertEquals(content.length, counter.getRecv(), 0L);
    assertEquals(content.length, counter.getSent(), 0L);
    assertTrue(failed.get());
    new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Delete(ch.cyberduck.core.features.Delete) S3AttributesFinderFeature(ch.cyberduck.core.s3.S3AttributesFinderFeature) S3MultipartUploadService(ch.cyberduck.core.s3.S3MultipartUploadService) TransferAction(ch.cyberduck.core.transfer.TransferAction) OutputStream(java.io.OutputStream) StatusOutputStream(ch.cyberduck.core.io.StatusOutputStream) ProfilePlistReader(ch.cyberduck.core.serializer.impl.dd.ProfilePlistReader) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) Random(java.util.Random) MessageDigest(java.security.MessageDigest) DisabledTransferErrorCallback(ch.cyberduck.core.transfer.DisabledTransferErrorCallback) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) S3Session(ch.cyberduck.core.s3.S3Session) S3DefaultDeleteFeature(ch.cyberduck.core.s3.S3DefaultDeleteFeature) ByteArrayInputStream(java.io.ByteArrayInputStream) CountingInputStream(org.apache.commons.io.input.CountingInputStream) InputStream(java.io.InputStream) CountingInputStream(org.apache.commons.io.input.CountingInputStream) IOException(java.io.IOException) S3Protocol(ch.cyberduck.core.s3.S3Protocol) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DisabledTransferPrompt(ch.cyberduck.core.transfer.DisabledTransferPrompt) SocketTimeoutException(java.net.SocketTimeoutException) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) TransferSpeedometer(ch.cyberduck.core.transfer.TransferSpeedometer) S3WriteFeature(ch.cyberduck.core.s3.S3WriteFeature) DefaultX509KeyManager(ch.cyberduck.core.ssl.DefaultX509KeyManager) TransferItem(ch.cyberduck.core.transfer.TransferItem) DefaultX509TrustManager(ch.cyberduck.core.ssl.DefaultX509TrustManager) AbstractS3Test(ch.cyberduck.core.s3.AbstractS3Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) Test(org.junit.Test)

Example 3 with S3MultipartUploadService

use of ch.cyberduck.core.s3.S3MultipartUploadService in project cyberduck by iterate-ch.

the class S3MultipartUploadServiceTest method testUpload.

@Test
public void testUpload() throws Exception {
    // 5L * 1024L * 1024L
    final Path home = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory));
    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 CryptoUploadFeature m = new CryptoUploadFeature<>(session, new S3MultipartUploadService(session, new S3WriteFeature(session), 5L * 1024L * 1024L, 5), new S3WriteFeature(session), cryptomator);
    final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    final byte[] content = RandomUtils.nextBytes(6 * 1024 * 1024);
    IOUtils.write(content, local.getOutputStream(false));
    final TransferStatus writeStatus = new TransferStatus();
    final FileHeader header = cryptomator.getFileHeaderCryptor().create();
    writeStatus.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
    writeStatus.setLength(content.length);
    m.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), writeStatus, null);
    assertTrue(writeStatus.isComplete());
    assertTrue(new CryptoFindFeature(session, new S3FindFeature(session), cryptomator).find(test));
    assertEquals(content.length, new CryptoAttributesFeature(session, new S3AttributesFinderFeature(session), cryptomator).find(test).getSize());
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
    final TransferStatus readStatus = new TransferStatus().withLength(content.length);
    final InputStream in = new CryptoReadFeature(session, new S3ReadFeature(session), cryptomator).read(test, readStatus, new DisabledConnectionCallback());
    new StreamCopier(readStatus, readStatus).transfer(in, buffer);
    assertArrayEquals(content, buffer.toByteArray());
    cryptomator.getFeature(session, Delete.class, new S3DefaultDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
    local.delete();
}
Also used : Delete(ch.cyberduck.core.features.Delete) S3AttributesFinderFeature(ch.cyberduck.core.s3.S3AttributesFinderFeature) S3MultipartUploadService(ch.cyberduck.core.s3.S3MultipartUploadService) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) CryptoReadFeature(ch.cyberduck.core.cryptomator.features.CryptoReadFeature) FileHeader(org.cryptomator.cryptolib.api.FileHeader) CryptoUploadFeature(ch.cyberduck.core.cryptomator.features.CryptoUploadFeature) Path(ch.cyberduck.core.Path) S3FindFeature(ch.cyberduck.core.s3.S3FindFeature) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) S3DefaultDeleteFeature(ch.cyberduck.core.s3.S3DefaultDeleteFeature) InputStream(java.io.InputStream) Local(ch.cyberduck.core.Local) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CryptoFindFeature(ch.cyberduck.core.cryptomator.features.CryptoFindFeature) CryptoAttributesFeature(ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature) BandwidthThrottle(ch.cyberduck.core.io.BandwidthThrottle) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) S3ReadFeature(ch.cyberduck.core.s3.S3ReadFeature) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) S3WriteFeature(ch.cyberduck.core.s3.S3WriteFeature) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) AbstractS3Test(ch.cyberduck.core.s3.AbstractS3Test) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 4 with S3MultipartUploadService

use of ch.cyberduck.core.s3.S3MultipartUploadService in project cyberduck by iterate-ch.

the class S3MultipartUploadServiceTest method testUploadWithBulk.

@Test
public void testUploadWithBulk() throws Exception {
    // 5L * 1024L * 1024L
    final Path home = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory));
    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 TransferStatus writeStatus = new TransferStatus();
    final byte[] content = RandomUtils.nextBytes(6 * 1024 * 1024);
    writeStatus.setLength(content.length);
    final CryptoBulkFeature<Map<TransferItem, TransferStatus>> bulk = new CryptoBulkFeature<>(session, new DisabledBulkFeature(), new S3DefaultDeleteFeature(session), cryptomator);
    bulk.pre(Transfer.Type.upload, Collections.singletonMap(new TransferItem(test), writeStatus), new DisabledConnectionCallback());
    final CryptoUploadFeature m = new CryptoUploadFeature<>(session, new S3MultipartUploadService(session, new S3WriteFeature(session), 5L * 1024L * 1024L, 5), new S3WriteFeature(session), cryptomator);
    final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    IOUtils.write(content, local.getOutputStream(false));
    m.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), writeStatus, null);
    assertTrue(writeStatus.isComplete());
    assertTrue(new CryptoFindFeature(session, new S3FindFeature(session), cryptomator).find(test));
    assertEquals(content.length, new CryptoAttributesFeature(session, new S3AttributesFinderFeature(session), cryptomator).find(test).getSize());
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
    final TransferStatus readStatus = new TransferStatus().withLength(content.length);
    final InputStream in = new CryptoReadFeature(session, new S3ReadFeature(session), cryptomator).read(test, readStatus, new DisabledConnectionCallback());
    new StreamCopier(readStatus, readStatus).transfer(in, buffer);
    assertArrayEquals(content, buffer.toByteArray());
    cryptomator.getFeature(session, Delete.class, new S3DefaultDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
    local.delete();
}
Also used : Delete(ch.cyberduck.core.features.Delete) S3AttributesFinderFeature(ch.cyberduck.core.s3.S3AttributesFinderFeature) S3MultipartUploadService(ch.cyberduck.core.s3.S3MultipartUploadService) CryptoBulkFeature(ch.cyberduck.core.cryptomator.features.CryptoBulkFeature) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) CryptoReadFeature(ch.cyberduck.core.cryptomator.features.CryptoReadFeature) CryptoUploadFeature(ch.cyberduck.core.cryptomator.features.CryptoUploadFeature) Path(ch.cyberduck.core.Path) S3FindFeature(ch.cyberduck.core.s3.S3FindFeature) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) S3DefaultDeleteFeature(ch.cyberduck.core.s3.S3DefaultDeleteFeature) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) InputStream(java.io.InputStream) DisabledBulkFeature(ch.cyberduck.core.shared.DisabledBulkFeature) Local(ch.cyberduck.core.Local) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CryptoFindFeature(ch.cyberduck.core.cryptomator.features.CryptoFindFeature) CryptoAttributesFeature(ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature) BandwidthThrottle(ch.cyberduck.core.io.BandwidthThrottle) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) S3ReadFeature(ch.cyberduck.core.s3.S3ReadFeature) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) S3WriteFeature(ch.cyberduck.core.s3.S3WriteFeature) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) Map(java.util.Map) TransferItem(ch.cyberduck.core.transfer.TransferItem) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) AbstractS3Test(ch.cyberduck.core.s3.AbstractS3Test) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Aggregations

Delete (ch.cyberduck.core.features.Delete)4 AbstractS3Test (ch.cyberduck.core.s3.AbstractS3Test)4 S3AttributesFinderFeature (ch.cyberduck.core.s3.S3AttributesFinderFeature)4 S3DefaultDeleteFeature (ch.cyberduck.core.s3.S3DefaultDeleteFeature)4 S3MultipartUploadService (ch.cyberduck.core.s3.S3MultipartUploadService)4 S3WriteFeature (ch.cyberduck.core.s3.S3WriteFeature)4 IntegrationTest (ch.cyberduck.test.IntegrationTest)4 InputStream (java.io.InputStream)4 Test (org.junit.Test)4 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)3 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)3 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)3 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)3 DisabledPasswordStore (ch.cyberduck.core.DisabledPasswordStore)3 Local (ch.cyberduck.core.Local)3 Path (ch.cyberduck.core.Path)3 CryptoAttributesFeature (ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature)3 CryptoFindFeature (ch.cyberduck.core.cryptomator.features.CryptoFindFeature)3 CryptoReadFeature (ch.cyberduck.core.cryptomator.features.CryptoReadFeature)3 CryptoUploadFeature (ch.cyberduck.core.cryptomator.features.CryptoUploadFeature)3