Cyberduck Mountain Duck CLI

Changeset 20556


Ignore:
Timestamp:
May 20, 2016 7:08:21 AM (2 years ago)
Author:
dkocher
Message:

Add test.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/backblaze/src/test/java/ch/cyberduck/core/b2/B2LargeUploadServiceTest.java

    r20552 r20556  
    9696        buffer.close();
    9797        assertArrayEquals(content, buffer.toByteArray());
    98         new B2DeleteFeature(session).delete(Collections.<Path>singletonList(test), new DisabledLoginCallback(), new Delete.Callback() {
     98        new B2DeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.Callback() {
    9999            @Override
    100100            public void delete(final Path file) {
     
    117117        final Path test = new Path(bucket, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    118118        final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    119         final int length = 100 * 1024 * 1024 + 20 * 1024 * 1024;
     119        final int length = 102 * 1024 * 1024;
    120120        final byte[] random = new byte[length];
    121121        new Random().nextBytes(random);
     
    159159        in.close();
    160160        assertArrayEquals(random, buffer);
    161         new B2DeleteFeature(session).delete(Collections.<Path>singletonList(test), new DisabledLoginCallback(), new Delete.Callback() {
     161        new B2DeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.Callback() {
     162            @Override
     163            public void delete(final Path file) {
     164                //
     165            }
     166        });
     167        local.delete();
     168        session.close();
     169    }
     170
     171    @Test
     172    public void testAppendSecondPart() throws Exception {
     173        final B2Session session = new B2Session(
     174                new Host(new B2Protocol(), new B2Protocol().getDefaultHostname(),
     175                        new Credentials(
     176                                System.getProperties().getProperty("b2.user"), System.getProperties().getProperty("b2.key")
     177                        )));
     178        session.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
     179        session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
     180        final Path bucket = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
     181        final Path test = new Path(bucket, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
     182        final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
     183        final int length = 102 * 1024 * 1024;
     184        final byte[] random = new byte[length];
     185        new Random().nextBytes(random);
     186        IOUtils.write(random, local.getOutputStream(false));
     187        final TransferStatus status = new TransferStatus();
     188        status.setLength(random.length);
     189        final AtomicBoolean interrupt = new AtomicBoolean();
     190        try {
     191            new B2LargeUploadService(session, 100L * 1024L * 1024L, 1).upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener() {
     192                long count;
     193
     194                @Override
     195                public void sent(final long bytes) {
     196                    count += bytes;
     197                    if(count >= 101L * 1024L * 1024L) {
     198                        throw new RuntimeException();
     199                    }
     200                }
     201            }, status, new DisabledLoginCallback());
     202        }
     203        catch(BackgroundException e) {
     204            // Expected
     205            interrupt.set(true);
     206        }
     207        assertTrue(interrupt.get());
     208        assertEquals(101 * 1024 * 1024L, status.getOffset(), 0L);
     209//        assertFalse(status.isComplete());
     210
     211        final TransferStatus append = new TransferStatus().append(true).length(random.length);
     212        new B2LargeUploadService(session, 100 * 1024L * 1024L, 1).upload(test, local,
     213                new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), append,
     214                new DisabledLoginCallback());
     215        assertEquals(2L * 1024L * 1024L, append.getOffset(), 0L);
     216        assertTrue(append.isComplete());
     217        assertTrue(new B2FindFeature(session).find(test));
     218        assertEquals(102L * 1024L * 1024L, new B2AttributesFeature(session).find(test).getSize(), 0L);
     219        final byte[] buffer = new byte[random.length];
     220        final InputStream in = new B2ReadFeature(session).read(test, new TransferStatus());
     221        IOUtils.readFully(in, buffer);
     222        in.close();
     223        assertArrayEquals(random, buffer);
     224        new B2DeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.Callback() {
    162225            @Override
    163226            public void delete(final Path file) {
Note: See TracChangeset for help on using the changeset viewer.
swiss made software