use of jetbrains.buildServer.util.WaitFor 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 jetbrains.buildServer.util.WaitFor in project teamcity-torrent-plugin by JetBrains.
the class TorrentTrackerConfiguratorTest method setUp.
@BeforeMethod
@Override
protected void setUp() throws Exception {
super.setUp();
Mockery m = new Mockery();
final AddressChecker addressChecker = m.mock(AddressChecker.class);
m.checking(new Expectations() {
{
allowing(addressChecker).isBadAddress(with(any(String.class)));
will(returnValue(false));
}
});
myTrackerManager = new TorrentTrackerManager(myConfigurator, new ExecutorServices() {
@NotNull
public ScheduledExecutorService getNormalExecutorService() {
return ExecutorsFactory.newFixedScheduledExecutor("aaa", 1);
}
@NotNull
public ExecutorService getLowPriorityExecutorService() {
return null;
}
}, myDispatcher, addressChecker);
myDispatcher.getMulticaster().serverStartup();
new WaitFor(5 * 1000) {
@Override
protected boolean condition() {
return !myTorrentsSeeder.getTorrentsSeeder().isStopped();
}
};
assertFalse(myTorrentsSeeder.getTorrentsSeeder().isStopped());
}
use of jetbrains.buildServer.util.WaitFor 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();
}
}
Aggregations