@Override
    public void await() throws BackgroundException {
        while(size.get() > 0) {
            // Repeat until no new entries in queue found
            try {
                if(log.isInfoEnabled()) {
                    log.info(String.format("Await completion for %d submitted tasks in queue", size.get()));
                }
                final TransferStatus status = completion.take().get();
                if(log.isInfoEnabled()) {
                    log.info(String.format("Finished task with return value %s", status));
                }
            }
            catch(InterruptedException e) {
                // Errors are handled in transfer worker error callback already
                log.warn(String.format("Unhandled failure %s", e));
                throw new ConnectionCanceledException(e);
            }
            catch(ExecutionException e) {
                for(Throwable cause : ExceptionUtils.getThrowableList(e)) {
                    Throwables.throwIfInstanceOf(cause, BackgroundException.class);
                }
                throw new DefaultExceptionMappingService().map(Throwables.getRootCause(e));
            }
            finally {
                size.decrementAndGet();
            }
        }
    }
@Test
    public void testAwait() throws Exception {
        final Host host = new Host(new TestProtocol(), "localhost", new Credentials("u", "p"));
        final Transfer transfer = new UploadTransfer(host,
                new Path("/t", EnumSet.of(Path.Type.directory)),
                new NullLocal("l"));
        final LoginConnectionService connection = new TestLoginConnectionService();
        final ConcurrentTransferWorker worker = new ConcurrentTransferWorker(
                new DefaultSessionPool(connection, new DisabledX509TrustManager(), new DefaultX509KeyManager(),
                        new DefaultVaultRegistry(new DisabledPasswordCallback()),
                        new DisabledTranscriptListener(), host), SessionPool.DISCONNECTED, transfer, new TransferOptions(), new TransferSpeedometer(transfer), new DisabledTransferPrompt(), new DisabledTransferErrorCallback(),
                new DisabledLoginCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledNotificationService()
        );
        int workers = 1000;
        final CountDownLatch entry = new CountDownLatch(workers);
        for(int i = 0; i < workers; i++) {
            worker.submit(new TransferWorker.TransferCallable() {
                @Override
                public TransferStatus call() {
                    entry.countDown();
                    return new TransferStatus().complete();
                }
            });
        }
        worker.await();
        assertEquals(0, entry.getCount());
        worker.cleanup(true);
    }