Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FileTransferSession tests. #6445

Merged
merged 1 commit into from Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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