Source:
public void cleanupFailedUpload() throws Exception { String username = generateUsername(); String password = "test01"; UserContext context = PeergosNetworkUtils.ensureSignedUp(username, password, network, crypto); FileWrapper userRoot = context.getUserRoot().get(); String filename = "small.txt"; byte[] data = new byte[2*5*1024*1024]; ThrowingStream throwingReader = new ThrowingStream(data, 5 * 1024 * 1024); Path filePath = Paths.get(username, filename); FileUploadTransaction transaction = Transaction.buildFileUploadTransaction(filePath.toString(), data.length, AsyncReader.build(data), userRoot.signingPair(), userRoot.generateChildLocationsFromSize(data.length, context.crypto.random)).join(); int prior = context.getTotalSpaceUsed(context.signer.publicKeyHash, context.signer.publicKeyHash).get().intValue(); TransactionService transactions = context.getTransactionService(); network.synchronizer.applyComplexUpdate(userRoot.owner(), transactions.getSigner().join(), (s, committer) -> transactions.open(s, committer, transaction)).join(); try { userRoot.uploadOrOverwriteFile(filename, throwingReader, data.length, context.network, context.crypto, l -> {}, transaction.getLocations()).get(); } catch (Exception e) int during = context.getTotalSpaceUsed(context.signer.publicKeyHash, context.signer.publicKeyHash).get().intValue(); Assert.assertTrue("One chunk uploaded", during > 5 * 1024*1024); network.synchronizer.applyComplexUpdate(userRoot.owner(), transactions.getSigner().join(), (s, committer) -> { Set<Transaction> pending = transactions.getOpenTransactions(s).join(); return Futures.reduceAll(pending, s, (v, t) -> transactions.clearAndClose(v, committer, t), (a, b) -> b); }).join(); int post = context.getTotalSpaceUsed(context.signer.publicKeyHash, context.signer.publicKeyHash).get().intValue(); Assert.assertTrue("Space from failed upload reclaimed", post < prior + 5000); }

Target:
public void cleanupFailedUpload() throws Exception { String username = generateUsername(); String password = "test01"; UserContext context = PeergosNetworkUtils.ensureSignedUp(username, password, network, crypto); FileWrapper userRoot = context.getUserRoot().get(); String filename = "small.txt"; byte[] data = new byte[2*5*1024*1024]; ThrowingStream throwingReader = new ThrowingStream(data, 5 * 1024 * 1024); Path filePath = Paths.get(username, filename); FileUploadTransaction transaction = Transaction.buildFileUploadTransaction(filePath.toString(), data.length, AsyncReader.build(data), userRoot.signingPair(), userRoot.generateChildLocationsFromSize(data.length, context.crypto.random)).join(); int prior = context.getTotalSpaceUsed(context.signer.publicKeyHash, context.signer.publicKeyHash).get().intValue(); TransactionService transactions = context.getTransactionService(); network.synchronizer.applyComplexUpdate(userRoot.owner(), transactions.getSigner(), (s, committer) -> transactions.open(s, committer, transaction)).join(); try { userRoot.uploadOrOverwriteFile(filename, throwingReader, data.length, context.network, context.crypto, l -> {}, transaction.getLocations()).get(); } catch (Exception e) int during = context.getTotalSpaceUsed(context.signer.publicKeyHash, context.signer.publicKeyHash).get().intValue(); Assert.assertTrue("One chunk uploaded", during > 5 * 1024*1024); network.synchronizer.applyComplexUpdate(userRoot.owner(), transactions.getSigner(), (current, committer) -> { Set<Transaction> pending = transactions.getOpenTransactions(current).join(); return Futures.reduceAll(pending, current, (version, t) -> transactions.clearAndClose(version, committer, t), (a, b) -> b); }).join(); int post = context.getTotalSpaceUsed(context.signer.publicKeyHash, context.signer.publicKeyHash).get().intValue(); Assert.assertTrue("Space from failed upload reclaimed", post < prior + 5000); }