Search in sources :

Example 1 with TrackedPeer

use of com.turn.ttorrent.tracker.TrackedPeer in project teamcity-torrent-plugin by JetBrains.

the class TorrentTrackerManagerTest method testThatOnePeerWithManyTorrentsCalculatedAsOnePeer.

@Test
public void testThatOnePeerWithManyTorrentsCalculatedAsOnePeer() {
    TrackedTorrent firstTorrent = new TrackedTorrent(new byte[] { 1 });
    TrackedTorrent secondTorrent = new TrackedTorrent(new byte[] { 2 });
    myTorrentTrackerManager.startTracker();
    final String ip = "127.0.0.1";
    final int port = 6881;
    firstTorrent.getPeers().put(new PeerUID(new InetSocketAddress(ip, port), "1"), new TrackedPeer(firstTorrent, ip, port, ByteBuffer.allocate(10)));
    firstTorrent.getPeers().put(new PeerUID(new InetSocketAddress(ip, port), "2"), new TrackedPeer(secondTorrent, ip, port, ByteBuffer.allocate(10)));
    myTorrentTrackerManager.getTorrentsRepository().putIfAbsent("1", firstTorrent);
    myTorrentTrackerManager.getTorrentsRepository().putIfAbsent("2", secondTorrent);
    assertEquals(2, myTorrentTrackerManager.getTorrents().size());
    assertEquals(1, myTorrentTrackerManager.getConnectedClientsNum());
    firstTorrent.getPeers().put(new PeerUID(new InetSocketAddress(ip, port + 1), "1"), new TrackedPeer(firstTorrent, ip, port + 1, ByteBuffer.allocate(10)));
    assertEquals(2, myTorrentTrackerManager.getTorrents().size());
    assertEquals(2, myTorrentTrackerManager.getConnectedClientsNum());
}
Also used : TrackedPeer(com.turn.ttorrent.tracker.TrackedPeer) InetSocketAddress(java.net.InetSocketAddress) TrackedTorrent(com.turn.ttorrent.tracker.TrackedTorrent) PeerUID(com.turn.ttorrent.common.PeerUID) Test(org.testng.annotations.Test)

Aggregations

PeerUID (com.turn.ttorrent.common.PeerUID)1 TrackedPeer (com.turn.ttorrent.tracker.TrackedPeer)1 TrackedTorrent (com.turn.ttorrent.tracker.TrackedTorrent)1 InetSocketAddress (java.net.InetSocketAddress)1 Test (org.testng.annotations.Test)1