use of com.turn.ttorrent.common.AnnounceableFileTorrent in project teamcity-torrent-plugin by JetBrains.
the class AgentTorrentsManagerTest method testAnnounceAllOnAgentStarted.
public void testAnnounceAllOnAgentStarted() throws IOException, URISyntaxException, InterruptedException, NoSuchAlgorithmException {
Tracker tracker = new Tracker(6969);
try {
final List<String> torrentHashes = new ArrayList<String>();
final List<File> createdFiles = new ArrayList<File>();
final int torrentsCount = 10;
tracker.start(true);
for (int i = 0; i < torrentsCount; i++) {
final File artifactFile = createTempFile(65535);
createdFiles.add(artifactFile);
File torrentDir = createTempDir();
final Torrent torrent = TorrentCreator.create(artifactFile, tracker.getAnnounceURI(), "tc-plugin-test");
final File torrentFile = new File(torrentDir, artifactFile.getName() + ".torrent");
torrentHashes.add(torrent.getHexInfoHash());
TorrentUtil.saveTorrentToFile(torrent, torrentFile);
myTorrentsManager.getTorrentsSeeder().registerSrcAndTorrentFile(artifactFile, torrentFile, false);
}
Mock buildAgentMock = mock(BuildAgent.class);
myTorrentsManager.agentStarted((BuildAgent) buildAgentMock.proxy());
new WaitFor(3 * 1000) {
@Override
protected boolean condition() {
return myTorrentsManager.getTorrentsSeeder().getNumberOfSeededTorrents() == torrentsCount;
}
};
List<String> seededHashes = new ArrayList<String>();
List<File> seededFiles = new ArrayList<File>();
for (AnnounceableTorrent st : myTorrentsManager.getTorrentsSeeder().getClient().getAnnounceableTorrents()) {
seededHashes.add(st.getHexInfoHash());
AnnounceableFileTorrent torrent = myTorrentsManager.getTorrentsSeeder().getClient().getAnnounceableFileTorrent(st.getHexInfoHash());
Torrent metadata = Torrent.load(new File(torrent.getDotTorrentFilePath()));
seededFiles.add(new File(torrent.getDownloadDirPath(), metadata.getName()));
}
assertSameElements(torrentHashes, seededHashes);
assertSameElements(createdFiles, seededFiles);
} finally {
myTorrentsManager.agentShutdown();
tracker.stop();
}
}
use of com.turn.ttorrent.common.AnnounceableFileTorrent in project teamcity-torrent-plugin by JetBrains.
the class TorrentArtifactCacheListenerTest method test_stop_seed_when_delete.
public void test_stop_seed_when_delete() throws IOException, NoSuchAlgorithmException {
File file = createTempFile(1024 * 1025);
myCacheListener.onAfterAddOrUpdate(file);
waitForSeededTorrents(1);
final AnnounceableTorrent announceableTorrent = mySeeder.getTorrentsSeeder().getClient().getAnnounceableTorrents().iterator().next();
final AnnounceableFileTorrent torrent = mySeeder.getTorrentsSeeder().getClient().getAnnounceableFileTorrent(announceableTorrent.getHexInfoHash());
Torrent metadata = Torrent.load(new File(torrent.getDotTorrentFilePath()));
assertEquals(file.getAbsolutePath(), torrent.getDownloadDirPath() + File.separatorChar + metadata.getFilenames().get(0));
myCacheListener.onBeforeDelete(file);
assertEquals(0, mySeeder.getNumberOfSeededTorrents());
}
use of com.turn.ttorrent.common.AnnounceableFileTorrent in project teamcity-torrent-plugin by JetBrains.
the class TorrentArtifactCacheListenerTest method test_seed_when_file_appear.
public void test_seed_when_file_appear() throws IOException, NoSuchAlgorithmException {
File file = createTempFile(1024 * 1025);
myCacheListener.onAfterAddOrUpdate(file);
waitForSeededTorrents(1);
assertEquals(1, mySeeder.getNumberOfSeededTorrents());
final AnnounceableTorrent announceableTorrent = mySeeder.getTorrentsSeeder().getClient().getAnnounceableTorrents().iterator().next();
final AnnounceableFileTorrent torrent = mySeeder.getTorrentsSeeder().getClient().getAnnounceableFileTorrent(announceableTorrent.getHexInfoHash());
Torrent metadata = Torrent.load(new File(torrent.getDotTorrentFilePath()));
assertEquals(file.getAbsolutePath(), torrent.getDownloadDirPath() + File.separatorChar + metadata.getFilenames().get(0));
}
Aggregations