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());
}
Aggregations