Fix FileTransferSession tests.

This commit is contained in:
jmacxx 2022-12-06 20:33:48 -06:00
parent bddbe6b7ae
commit 09a7a09ec3
No known key found for this signature in database
GPG Key ID: 155297BABFE94A1B
3 changed files with 13 additions and 6 deletions

View File

@ -182,7 +182,7 @@ public final class Dispute implements NetworkPayload, PersistablePayload {
public FileTransferSender createFileTransferSender(NetworkNode networkNode,
NodeAddress peerNodeAddress,
FileTransferSession.FtpCallback callback) {
return new FileTransferSender(networkNode, peerNodeAddress, this.tradeId, this.traderId, this.getRoleStringForLogFile(), callback);
return new FileTransferSender(networkNode, peerNodeAddress, this.tradeId, this.traderId, this.getRoleStringForLogFile(), false, callback);
}

View File

@ -55,15 +55,18 @@ import static bisq.common.file.FileUtil.doesFileContainKeyword;
@Slf4j
public class FileTransferSender extends FileTransferSession {
protected final String zipFilePath;
private final boolean isTest;
public FileTransferSender(NetworkNode networkNode,
NodeAddress peerNodeAddress,
String tradeId,
int traderId,
String traderRole,
boolean isTest,
@Nullable FileTransferSession.FtpCallback callback) {
super(networkNode, peerNodeAddress, tradeId, traderId, traderRole, callback);
zipFilePath = Utilities.getUserDataDir() + FileSystems.getDefault().getSeparator() + zipId + ".zip";
this.isTest = isTest;
updateProgress();
}
@ -172,6 +175,9 @@ public class FileTransferSender extends FileTransferSession {
dataAwaitingAck = Optional.empty();
checkpointLastActivity();
updateProgress();
if (isTest) {
return true;
}
UserThread.runAfter(() -> { // to trigger continuing the file transfer
try {
sendNextBlock();

View File

@ -55,20 +55,21 @@ public class FileTransferSessionTest implements FileTransferSession.FtpCallback
@Test
public void testSendCreate() {
new FileTransferSender(networkNode, counterpartyNodeAddress, testTradeId, testTraderId, testClientId, this);
new FileTransferSender(networkNode, counterpartyNodeAddress, testTradeId, testTraderId, testClientId, true, this);
Assert.assertEquals(0.0, notedProgressPct, 0.0);
Assert.assertEquals(1, progressInvocations);
}
@Test
public void testCreateZip() {
FileTransferSender sender = new FileTransferSender(networkNode, counterpartyNodeAddress, testTradeId, testTraderId, testClientId, this);
FileTransferSender sender = new FileTransferSender(networkNode, counterpartyNodeAddress, testTradeId, testTraderId, testClientId, true, this);
Assert.assertEquals(0.0, notedProgressPct, 0.0);
Assert.assertEquals(1, progressInvocations);
sender.createZipFileToSend();
File file = new File(sender.zipFilePath);
Assert.assertTrue(file.exists());
Assert.assertTrue(file.length() > 0);
Assert.assertTrue(file.getAbsoluteFile().exists());
Assert.assertTrue(file.getAbsoluteFile().length() > 0);
file.deleteOnExit();
}
@Test
@ -192,7 +193,7 @@ public class FileTransferSessionTest implements FileTransferSession.FtpCallback
private FileTransferSender initializeSession(int testSize) {
try {
FileTransferSender session = new FileTransferSender(networkNode, counterpartyNodeAddress, testTradeId, testTraderId, testClientId, this);
FileTransferSender session = new FileTransferSender(networkNode, counterpartyNodeAddress, testTradeId, testTraderId, testClientId, true, this);
// simulate a file for sending
FileWriter fileWriter = new FileWriter(session.zipFilePath);
char[] buf = new char[testSize];