use of com.turn.ttorrent.tracker.TrackedTorrent in project teamcity-torrent-plugin by JetBrains.
the class TorrentTrackerConfiguratorTest method test_announce_interval.
public void test_announce_interval() throws IOException, TrackerMessage.MessageValidationException {
System.setProperty(TorrentConfiguration.ANNOUNCE_INTERVAL, "10");
myConfigurator.getConfigurationWatcher().checkForModifications();
assertEquals(10, myConfigurator.getAnnounceIntervalSec());
assertEquals(10, myTrackerManager.getTrackerService().getAnnounceInterval());
final String uri = "http://localhost:8111/trackerAnnounce.html" + "?info_hash=12345678901234567890" + "&peer_id=ABCDEFGHIJKLMNOPQRST" + "&ip=127.0.0.0" + "&port=6881" + "&downloaded=1234" + "&left=98765" + "&event=stopped";
final AtomicReference<String> response = new AtomicReference<String>();
myTrackerManager.getTrackerService().process(uri, "http://localhost:8111/", new TrackerRequestProcessor.RequestHandler() {
public void serveResponse(int code, String description, ByteBuffer responseData) {
response.set(new String(responseData.array()));
}
public ConcurrentMap<String, TrackedTorrent> getTorrentsMap() {
return new ConcurrentHashMap<String, TrackedTorrent>();
}
});
final HTTPAnnounceResponseMessage parse = (HTTPAnnounceResponseMessage) HTTPTrackerMessage.parse(new ByteArrayInputStream(response.get().getBytes()));
assertEquals(10, parse.getInterval());
}
use of com.turn.ttorrent.tracker.TrackedTorrent in project teamcity-torrent-plugin by JetBrains.
the class TorrentTrackerConfiguratorTest method test_torrent_expire_timeout.
public void test_torrent_expire_timeout() throws IOException, TrackerMessage.MessageValidationException, InterruptedException {
System.setProperty(TorrentConfiguration.TRACKER_TORRENT_EXPIRE_TIMEOUT, "5");
myConfigurator.getConfigurationWatcher().checkForModifications();
assertEquals(5, myConfigurator.getTrackerTorrentExpireTimeoutSec());
final String uriCompleted = "http://localhost:8111/trackerAnnounce.html" + "?info_hash=12345678901234567890" + "&peer_id=ABCDEFGHIJKLMNOPQRST" + "&ip=172.20.240.249" + "&port=6884" + "&downloaded=1234" + "&left=0" + "&event=" + "completed";
final String uriCompleted2 = "http://localhost:8111/trackerAnnounce.html" + "?info_hash=12345678901234567890" + "&peer_id=BBCDEFGHIJKLMNOPQRST" + "&ip=172.20.240.249" + "&port=6881" + "&downloaded=1234" + "&left=0" + "&event=" + "completed";
// assertEquals(uriCompleted, uriCompleted2);
final AtomicReference<byte[]> response = new AtomicReference<byte[]>();
final TrackerRequestProcessor.RequestHandler requestHandler = new TrackerRequestProcessor.RequestHandler() {
public void serveResponse(int code, String description, ByteBuffer responseData) {
response.set(responseData.array());
}
};
myTrackerManager.getTrackerService().process(uriCompleted, "http://localhost:8111/", requestHandler);
assertEquals(1, myTrackerManager.getTorrents().size());
final AtomicInteger complete = new AtomicInteger(100);
final AtomicInteger peersSize = new AtomicInteger(100);
final String torrentHash = "3132333435363738393031323334353637383930";
new WaitFor(15 * 1000) {
@Override
protected boolean condition() {
try {
myTrackerManager.getTrackerService().process(uriCompleted2, "http://localhost:8111/", requestHandler);
final HTTPAnnounceResponseMessage parse = (HTTPAnnounceResponseMessage) HTTPTrackerMessage.parse(new ByteArrayInputStream(response.get()));
complete.set(parse.getComplete());
peersSize.set(parse.getPeers().size());
final TrackedTorrent trackedTorrent = myTrackerManager.getTorrents().get(torrentHash);
return parse.getComplete() == 1 && trackedTorrent.getPeers().size() == 1;
} catch (IOException e) {
e.printStackTrace();
} catch (TrackerMessage.MessageValidationException e) {
e.printStackTrace();
}
return false;
}
};
final TrackedTorrent trackedTorrent = myTrackerManager.getTorrents().get(torrentHash);
for (PeerUID peerUID : trackedTorrent.getPeers().keySet()) {
if (peerUID.getTorrentHash().equals("4142434445464748494A4B4C4D4E4F5051525354"))
fail();
}
new WaitFor(15 * 1000) {
@Override
protected boolean condition() {
return !myTrackerManager.getTorrents().containsKey(torrentHash);
}
};
assertNotContains(myTrackerManager.getTorrents().keySet(), torrentHash);
}
use of com.turn.ttorrent.tracker.TrackedTorrent 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());
}
Aggregations