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

ResumeTest fix #272

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
27 changes: 18 additions & 9 deletions src/test/java/org/libtorrent4j/demo/ResumeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static void main(String[] args) throws Throwable {
final SessionManager s = new SessionManager();
final CountDownLatch signal = new CountDownLatch(10);
final CountDownLatch signalResumeData = new CountDownLatch(1);
s.swig().post_torrent_updates();
s.addListener(new AlertListener() {
@Override
public int[] types() {
Expand All @@ -41,28 +42,36 @@ public void alert(Alert<?> alert) {
case ADD_TORRENT:
System.out.println("Torrent added");
((AddTorrentAlert) alert).handle().resume();
s.swig().post_torrent_updates();
break;
case TORRENT_FINISHED:
System.out.println("Torrent finished");
//((TorrentFinishedAlert) alert).handle().saveResumeData(TorrentHandle.SAVE_INFO_DICT);
break;
case TORRENT_PAUSED:
System.out.println("Torrent paused");
s.swig().post_torrent_updates();
break;
case SAVE_RESUME_DATA:
System.out.println("Torrent saveResumeData");
serializeResumeData((SaveResumeDataAlert) alert);
signalResumeData.countDown();
s.swig().post_torrent_updates();
break;
case STATE_UPDATE:
StateUpdateAlert sua = (StateUpdateAlert) alert;
sua.status().forEach(ts -> {
System.out.println(String.format("state update: name:%s seeding time=%d\nactive time=%d\n",
ts.name(),
ts.seedingDuration(),
ts.activeDuration()));

TorrentHandle th = new TorrentHandle(ts.swig().getHandle());
if (th.status().isFinished()) {
signal.countDown();
}
});
break;
// case STATS:
// TorrentHandle th = ((StatsAlert) alert).handle();
// if (th.status().isFinished()) {
// TorrentStatus ts = th.status();
// System.out.println(String.format("seeding time=%d\nactive time=%d\n",
// ts.seedingDuration(), ts.activeDuration()));
// signal.countDown();
// }
// break;
}
}
});
Expand Down
Loading