Skip to content

Commit

Permalink
Merge pull request #6445 from jmacxx/backup_zip_logfiles
Browse files Browse the repository at this point in the history
Fix FileTransferSession tests.
  • Loading branch information
alejandrogarcia83 authored Dec 7, 2022
2 parents 555742d + 09a7a09 commit 39db3cc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/support/dispute/Dispute.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public FileTransferReceiver createOrGetFileTransferReceiver(NetworkNode networkN
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);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,18 @@
@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();
}

Expand Down Expand Up @@ -172,6 +175,9 @@ public boolean processAckForFilePart(String ackUid) {
dataAwaitingAck = Optional.empty();
checkpointLastActivity();
updateProgress();
if (isTest) {
return true;
}
UserThread.runAfter(() -> { // to trigger continuing the file transfer
try {
sendNextBlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,21 @@ public void setUp() throws Exception {

@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
Expand Down Expand Up @@ -192,7 +193,7 @@ public void testSendTwoFullBlocksPlusOneByte() {

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];
Expand Down

0 comments on commit 39db3cc

Please sign in to comment.