Search in sources :

Example 1 with SwiftLargeObjectUploadFeature

use of ch.cyberduck.core.openstack.SwiftLargeObjectUploadFeature in project cyberduck by iterate-ch.

the class SwiftSingleTransferWorkerTest method testTransferredSizeRepeat.

@Test
public void testTransferredSizeRepeat() throws Exception {
    final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
    final byte[] content = new byte[2 * 1024 * 1024];
    new Random().nextBytes(content);
    final OutputStream out = local.getOutputStream(false);
    IOUtils.write(content, out);
    out.close();
    final Host host = new Host(new SwiftProtocol(), "identity.api.rackspacecloud.com", new Credentials(System.getProperties().getProperty("rackspace.key"), System.getProperties().getProperty("rackspace.secret")));
    final AtomicBoolean failed = new AtomicBoolean();
    final SwiftSession session = new SwiftSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager()) {

        @Override
        @SuppressWarnings("unchecked")
        public <T> T _getFeature(final Class<T> type) {
            if (type == Upload.class) {
                final SwiftRegionService regionService = new SwiftRegionService(this);
                return (T) new SwiftLargeObjectUploadFeature(this, regionService, new SwiftWriteFeature(this, regionService), 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 container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume));
    container.attributes().setRegion("IAD");
    final Path test = new Path(container, 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 SwiftAttributesFinderFeature(session).find(test).getSize());
    assertEquals(content.length, counter.getRecv(), 0L);
    assertEquals(content.length, counter.getSent(), 0L);
    assertTrue(failed.get());
    new SwiftDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Delete(ch.cyberduck.core.features.Delete) DisabledX509TrustManager(ch.cyberduck.core.ssl.DisabledX509TrustManager) TransferAction(ch.cyberduck.core.transfer.TransferAction) OutputStream(java.io.OutputStream) SwiftWriteFeature(ch.cyberduck.core.openstack.SwiftWriteFeature) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) Random(java.util.Random) SwiftDeleteFeature(ch.cyberduck.core.openstack.SwiftDeleteFeature) MessageDigest(java.security.MessageDigest) DisabledTransferErrorCallback(ch.cyberduck.core.transfer.DisabledTransferErrorCallback) Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) CountingInputStream(org.apache.commons.io.input.CountingInputStream) InputStream(java.io.InputStream) CountingInputStream(org.apache.commons.io.input.CountingInputStream) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) IOException(java.io.IOException) SwiftAttributesFinderFeature(ch.cyberduck.core.openstack.SwiftAttributesFinderFeature) SwiftProtocol(ch.cyberduck.core.openstack.SwiftProtocol) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DisabledTransferPrompt(ch.cyberduck.core.transfer.DisabledTransferPrompt) SwiftRegionService(ch.cyberduck.core.openstack.SwiftRegionService) SocketTimeoutException(java.net.SocketTimeoutException) DisabledCancelCallback(ch.cyberduck.core.DisabledCancelCallback) DisabledHostKeyCallback(ch.cyberduck.core.DisabledHostKeyCallback) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) TransferSpeedometer(ch.cyberduck.core.transfer.TransferSpeedometer) SwiftLargeObjectUploadFeature(ch.cyberduck.core.openstack.SwiftLargeObjectUploadFeature) DefaultX509KeyManager(ch.cyberduck.core.ssl.DefaultX509KeyManager) TransferItem(ch.cyberduck.core.transfer.TransferItem) Credentials(ch.cyberduck.core.Credentials) SwiftSession(ch.cyberduck.core.openstack.SwiftSession) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 2 with SwiftLargeObjectUploadFeature

use of ch.cyberduck.core.openstack.SwiftLargeObjectUploadFeature in project cyberduck by iterate-ch.

the class SwiftLargeObjectUploadFeatureTest method testLargeObjectUpload.

@Test
public void testLargeObjectUpload() throws Exception {
    // 5L * 1024L * 1024L
    final Path home = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.volume, Path.Type.directory));
    home.attributes().setRegion("IAD");
    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 SwiftRegionService regionService = new SwiftRegionService(session);
    final CryptoUploadFeature m = new CryptoUploadFeature<>(session, new SwiftLargeObjectUploadFeature(session, regionService, new SwiftWriteFeature(session, regionService), 5242880L, 5), new SwiftWriteFeature(session, regionService), cryptomator);
    final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    final int length = 5242885;
    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 SwiftFindFeature(session), cryptomator).find(test));
    assertEquals(content.length, new CryptoListService(session, new SwiftListService(session, regionService), cryptomator).list(test.getParent(), new DisabledListProgressListener()).get(test).attributes().getSize());
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
    final TransferStatus readStatus = new TransferStatus().withLength(content.length);
    final InputStream in = new CryptoReadFeature(session, new SwiftReadFeature(session, regionService), cryptomator).read(test, readStatus, new DisabledConnectionCallback());
    new StreamCopier(readStatus, readStatus).transfer(in, buffer);
    assertArrayEquals(content, buffer.toByteArray());
    cryptomator.getFeature(session, Delete.class, new SwiftDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
    local.delete();
    session.close();
}
Also used : Delete(ch.cyberduck.core.features.Delete) CryptoListService(ch.cyberduck.core.cryptomator.features.CryptoListService) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) SwiftWriteFeature(ch.cyberduck.core.openstack.SwiftWriteFeature) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) SwiftDeleteFeature(ch.cyberduck.core.openstack.SwiftDeleteFeature) 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) SwiftFindFeature(ch.cyberduck.core.openstack.SwiftFindFeature) Path(ch.cyberduck.core.Path) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) SwiftReadFeature(ch.cyberduck.core.openstack.SwiftReadFeature) 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) SwiftRegionService(ch.cyberduck.core.openstack.SwiftRegionService) BandwidthThrottle(ch.cyberduck.core.io.BandwidthThrottle) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) SwiftLargeObjectUploadFeature(ch.cyberduck.core.openstack.SwiftLargeObjectUploadFeature) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) SwiftListService(ch.cyberduck.core.openstack.SwiftListService) AbstractSwiftTest(ch.cyberduck.core.openstack.AbstractSwiftTest) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Aggregations

AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)2 BytecountStreamListener (ch.cyberduck.core.BytecountStreamListener)2 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)2 Local (ch.cyberduck.core.Local)2 Path (ch.cyberduck.core.Path)2 Delete (ch.cyberduck.core.features.Delete)2 SwiftDeleteFeature (ch.cyberduck.core.openstack.SwiftDeleteFeature)2 SwiftLargeObjectUploadFeature (ch.cyberduck.core.openstack.SwiftLargeObjectUploadFeature)2 SwiftRegionService (ch.cyberduck.core.openstack.SwiftRegionService)2 SwiftWriteFeature (ch.cyberduck.core.openstack.SwiftWriteFeature)2 IntegrationTest (ch.cyberduck.test.IntegrationTest)2 InputStream (java.io.InputStream)2 Test (org.junit.Test)2 Credentials (ch.cyberduck.core.Credentials)1 DisabledCancelCallback (ch.cyberduck.core.DisabledCancelCallback)1 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)1 DisabledHostKeyCallback (ch.cyberduck.core.DisabledHostKeyCallback)1 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)1 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)1 DisabledPasswordStore (ch.cyberduck.core.DisabledPasswordStore)1