Search in sources :

Example 1 with SpectraBulkService

use of ch.cyberduck.core.spectra.SpectraBulkService in project cyberduck by iterate-ch.

the class SpectraSingleTransferWorkerTest method testTransferredSizeRepeat.

@Ignore
@Test(expected = ConflictException.class)
public void testTransferredSizeRepeat() throws Exception {
    final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
    final byte[] content = new byte[98305];
    new Random().nextBytes(content);
    final OutputStream out = local.getOutputStream(false);
    IOUtils.write(content, out);
    out.close();
    final Host host = new Host(new SpectraProtocol() {

        @Override
        public Scheme getScheme() {
            return Scheme.http;
        }
    }, System.getProperties().getProperty("spectra.hostname"), Integer.valueOf(System.getProperties().getProperty("spectra.port")), new Credentials(System.getProperties().getProperty("spectra.user"), System.getProperties().getProperty("spectra.key")));
    final BytecountStreamListener counter = new BytecountStreamListener();
    final AtomicBoolean failed = new AtomicBoolean();
    final SpectraSession session = new SpectraSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager()) {

        final SpectraWriteFeature write = new SpectraWriteFeature(this) {

            @Override
            public HttpResponseOutputStream<StorageObject> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
                final HttpResponseOutputStream<StorageObject> proxy = super.write(file, status, callback);
                if (failed.get()) {
                    // Second attempt successful
                    return proxy;
                }
                return new HttpResponseOutputStream<StorageObject>(new CountingOutputStream(proxy) {

                    @Override
                    protected void afterWrite(final int n) throws IOException {
                        super.afterWrite(n);
                        if (this.getByteCount() >= 42768L) {
                            assertTrue(this.getByteCount() < content.length);
                            // Buffer size
                            assertEquals(32768L, counter.getSent());
                            failed.set(true);
                            throw new SocketTimeoutException();
                        }
                    }
                }, new S3AttributesAdapter(), status) {

                    @Override
                    public StorageObject getStatus() throws BackgroundException {
                        return proxy.getStatus();
                    }

                    @Override
                    public void close() throws IOException {
                        super.close();
                        proxy.close();
                    }
                };
            }
        };

        @Override
        @SuppressWarnings("unchecked")
        public <T> T _getFeature(final Class<T> type) {
            if (type == Write.class) {
                return (T) write;
            }
            if (type == Upload.class) {
                return (T) new SpectraUploadFeature(this, write, new SpectraBulkService(this));
            }
            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("cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path test = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Transfer t = new UploadTransfer(session.getHost(), test, local);
    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, counter.getSent(), 0L);
    assertTrue(failed.get());
    assertEquals(content.length, new SpectraAttributesFinderFeature(session).find(test).getSize());
    new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Delete(ch.cyberduck.core.features.Delete) SpectraAttributesFinderFeature(ch.cyberduck.core.spectra.SpectraAttributesFinderFeature) Scheme(ch.cyberduck.core.Scheme) HttpResponseOutputStream(ch.cyberduck.core.http.HttpResponseOutputStream) OutputStream(java.io.OutputStream) CountingOutputStream(org.apache.commons.io.output.CountingOutputStream) SpectraBulkService(ch.cyberduck.core.spectra.SpectraBulkService) CountingOutputStream(org.apache.commons.io.output.CountingOutputStream) Random(java.util.Random) S3AttributesAdapter(ch.cyberduck.core.s3.S3AttributesAdapter) SpectraProtocol(ch.cyberduck.core.spectra.SpectraProtocol) DisabledTransferErrorCallback(ch.cyberduck.core.transfer.DisabledTransferErrorCallback) S3DefaultDeleteFeature(ch.cyberduck.core.s3.S3DefaultDeleteFeature) Local(ch.cyberduck.core.Local) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) TransferSpeedometer(ch.cyberduck.core.transfer.TransferSpeedometer) HttpResponseOutputStream(ch.cyberduck.core.http.HttpResponseOutputStream) DefaultX509KeyManager(ch.cyberduck.core.ssl.DefaultX509KeyManager) TransferItem(ch.cyberduck.core.transfer.TransferItem) BackgroundException(ch.cyberduck.core.exception.BackgroundException) DisabledX509TrustManager(ch.cyberduck.core.ssl.DisabledX509TrustManager) SpectraWriteFeature(ch.cyberduck.core.spectra.SpectraWriteFeature) TransferAction(ch.cyberduck.core.transfer.TransferAction) SpectraUploadFeature(ch.cyberduck.core.spectra.SpectraUploadFeature) SpectraSession(ch.cyberduck.core.spectra.SpectraSession) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) StorageObject(org.jets3t.service.model.StorageObject) Host(ch.cyberduck.core.Host) IOException(java.io.IOException) DisabledTransferPrompt(ch.cyberduck.core.transfer.DisabledTransferPrompt) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) Credentials(ch.cyberduck.core.Credentials) Ignore(org.junit.Ignore) IntegrationTest(ch.cyberduck.test.IntegrationTest) Test(org.junit.Test)

Aggregations

AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)1 BytecountStreamListener (ch.cyberduck.core.BytecountStreamListener)1 ConnectionCallback (ch.cyberduck.core.ConnectionCallback)1 Credentials (ch.cyberduck.core.Credentials)1 DisabledCancelCallback (ch.cyberduck.core.DisabledCancelCallback)1 DisabledHostKeyCallback (ch.cyberduck.core.DisabledHostKeyCallback)1 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)1 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)1 Host (ch.cyberduck.core.Host)1 Local (ch.cyberduck.core.Local)1 Path (ch.cyberduck.core.Path)1 Scheme (ch.cyberduck.core.Scheme)1 BackgroundException (ch.cyberduck.core.exception.BackgroundException)1 Delete (ch.cyberduck.core.features.Delete)1 HttpResponseOutputStream (ch.cyberduck.core.http.HttpResponseOutputStream)1 DisabledNotificationService (ch.cyberduck.core.notification.DisabledNotificationService)1 S3AttributesAdapter (ch.cyberduck.core.s3.S3AttributesAdapter)1 S3DefaultDeleteFeature (ch.cyberduck.core.s3.S3DefaultDeleteFeature)1 SpectraAttributesFinderFeature (ch.cyberduck.core.spectra.SpectraAttributesFinderFeature)1 SpectraBulkService (ch.cyberduck.core.spectra.SpectraBulkService)1