mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Fix FileTransferSession tests.
This commit is contained in:
parent
bddbe6b7ae
commit
09a7a09ec3
@ -182,7 +182,7 @@ public final class Dispute implements NetworkPayload, PersistablePayload {
|
|||||||
public FileTransferSender createFileTransferSender(NetworkNode networkNode,
|
public FileTransferSender createFileTransferSender(NetworkNode networkNode,
|
||||||
NodeAddress peerNodeAddress,
|
NodeAddress peerNodeAddress,
|
||||||
FileTransferSession.FtpCallback callback) {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,15 +55,18 @@ import static bisq.common.file.FileUtil.doesFileContainKeyword;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class FileTransferSender extends FileTransferSession {
|
public class FileTransferSender extends FileTransferSession {
|
||||||
protected final String zipFilePath;
|
protected final String zipFilePath;
|
||||||
|
private final boolean isTest;
|
||||||
|
|
||||||
public FileTransferSender(NetworkNode networkNode,
|
public FileTransferSender(NetworkNode networkNode,
|
||||||
NodeAddress peerNodeAddress,
|
NodeAddress peerNodeAddress,
|
||||||
String tradeId,
|
String tradeId,
|
||||||
int traderId,
|
int traderId,
|
||||||
String traderRole,
|
String traderRole,
|
||||||
|
boolean isTest,
|
||||||
@Nullable FileTransferSession.FtpCallback callback) {
|
@Nullable FileTransferSession.FtpCallback callback) {
|
||||||
super(networkNode, peerNodeAddress, tradeId, traderId, traderRole, callback);
|
super(networkNode, peerNodeAddress, tradeId, traderId, traderRole, callback);
|
||||||
zipFilePath = Utilities.getUserDataDir() + FileSystems.getDefault().getSeparator() + zipId + ".zip";
|
zipFilePath = Utilities.getUserDataDir() + FileSystems.getDefault().getSeparator() + zipId + ".zip";
|
||||||
|
this.isTest = isTest;
|
||||||
updateProgress();
|
updateProgress();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,6 +175,9 @@ public class FileTransferSender extends FileTransferSession {
|
|||||||
dataAwaitingAck = Optional.empty();
|
dataAwaitingAck = Optional.empty();
|
||||||
checkpointLastActivity();
|
checkpointLastActivity();
|
||||||
updateProgress();
|
updateProgress();
|
||||||
|
if (isTest) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
UserThread.runAfter(() -> { // to trigger continuing the file transfer
|
UserThread.runAfter(() -> { // to trigger continuing the file transfer
|
||||||
try {
|
try {
|
||||||
sendNextBlock();
|
sendNextBlock();
|
||||||
|
@ -55,20 +55,21 @@ public class FileTransferSessionTest implements FileTransferSession.FtpCallback
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendCreate() {
|
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(0.0, notedProgressPct, 0.0);
|
||||||
Assert.assertEquals(1, progressInvocations);
|
Assert.assertEquals(1, progressInvocations);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateZip() {
|
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(0.0, notedProgressPct, 0.0);
|
||||||
Assert.assertEquals(1, progressInvocations);
|
Assert.assertEquals(1, progressInvocations);
|
||||||
sender.createZipFileToSend();
|
sender.createZipFileToSend();
|
||||||
File file = new File(sender.zipFilePath);
|
File file = new File(sender.zipFilePath);
|
||||||
Assert.assertTrue(file.exists());
|
Assert.assertTrue(file.getAbsoluteFile().exists());
|
||||||
Assert.assertTrue(file.length() > 0);
|
Assert.assertTrue(file.getAbsoluteFile().length() > 0);
|
||||||
|
file.deleteOnExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -192,7 +193,7 @@ public class FileTransferSessionTest implements FileTransferSession.FtpCallback
|
|||||||
|
|
||||||
private FileTransferSender initializeSession(int testSize) {
|
private FileTransferSender initializeSession(int testSize) {
|
||||||
try {
|
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
|
// simulate a file for sending
|
||||||
FileWriter fileWriter = new FileWriter(session.zipFilePath);
|
FileWriter fileWriter = new FileWriter(session.zipFilePath);
|
||||||
char[] buf = new char[testSize];
|
char[] buf = new char[testSize];
|
||||||
|
Loading…
Reference in New Issue
Block a user