Search in sources :

Example 1 with AnnounceableFileTorrent

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();
    }
}
Also used : Tracker(com.turn.ttorrent.tracker.Tracker) Torrent(com.turn.ttorrent.common.Torrent) AnnounceableTorrent(com.turn.ttorrent.common.AnnounceableTorrent) AnnounceableFileTorrent(com.turn.ttorrent.common.AnnounceableFileTorrent) AnnounceableFileTorrent(com.turn.ttorrent.common.AnnounceableFileTorrent) WaitFor(jetbrains.buildServer.util.WaitFor) ArrayList(java.util.ArrayList) File(java.io.File) AnnounceableTorrent(com.turn.ttorrent.common.AnnounceableTorrent) Mock(org.jmock.Mock)

Example 2 with AnnounceableFileTorrent

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());
}
Also used : Torrent(com.turn.ttorrent.common.Torrent) AnnounceableTorrent(com.turn.ttorrent.common.AnnounceableTorrent) AnnounceableFileTorrent(com.turn.ttorrent.common.AnnounceableFileTorrent) AnnounceableFileTorrent(com.turn.ttorrent.common.AnnounceableFileTorrent) File(java.io.File) AnnounceableTorrent(com.turn.ttorrent.common.AnnounceableTorrent)

Example 3 with AnnounceableFileTorrent

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));
}
Also used : Torrent(com.turn.ttorrent.common.Torrent) AnnounceableTorrent(com.turn.ttorrent.common.AnnounceableTorrent) AnnounceableFileTorrent(com.turn.ttorrent.common.AnnounceableFileTorrent) AnnounceableFileTorrent(com.turn.ttorrent.common.AnnounceableFileTorrent) File(java.io.File) AnnounceableTorrent(com.turn.ttorrent.common.AnnounceableTorrent)

Aggregations

AnnounceableFileTorrent (com.turn.ttorrent.common.AnnounceableFileTorrent)3 AnnounceableTorrent (com.turn.ttorrent.common.AnnounceableTorrent)3 Torrent (com.turn.ttorrent.common.Torrent)3 File (java.io.File)3 Tracker (com.turn.ttorrent.tracker.Tracker)1 ArrayList (java.util.ArrayList)1 WaitFor (jetbrains.buildServer.util.WaitFor)1 Mock (org.jmock.Mock)1