Search in sources :

Example 1 with TorrentsDownloadStatistic

use of jetbrains.buildServer.torrent.util.TorrentsDownloadStatistic in project teamcity-torrent-plugin by JetBrains.

the class AgentTorrentsManagerTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    super.setUp();
    EventDispatcher<AgentLifeCycleListener> dispatcher = EventDispatcher.create(AgentLifeCycleListener.class);
    BuildAgentConfiguration agentConfiguration = myAgentConfigurationFixture.setUp();
    final TorrentConfiguration trackerConfiguration = new FakeTorrentConfiguration();
    Mockery m = new Mockery();
    final LeechSettings leechSettings = m.mock(LeechSettings.class);
    final SeedSettings seedingSettings = m.mock(SeedSettings.class);
    final ArtifactCacheProvider cacheProvider = m.mock(ArtifactCacheProvider.class);
    m.checking(new Expectations() {

        {
            allowing(cacheProvider).addListener(with(any(TorrentArtifactCacheListener.class)));
            allowing(leechSettings).isDownloadEnabled();
            will(returnValue(true));
            allowing(seedingSettings).isSeedingEnabled();
            will(returnValue(true));
        }
    });
    final ArtifactsWatcher artifactsWatcher = m.mock(ArtifactsWatcher.class);
    AgentTorrentsSeeder seeder = new AgentTorrentsSeeder(agentConfiguration, trackerConfiguration);
    TorrentFilesFactoryImpl tff = new TorrentFilesFactoryImpl(agentConfiguration, trackerConfiguration, new FakeAgentIdleTasks(), seeder);
    myTorrentsDownloadStatistic = new TorrentsDownloadStatistic();
    myTorrentsManager = new AgentTorrentsManager(dispatcher, cacheProvider, new CurrentBuildTrackerImpl(dispatcher), trackerConfiguration, seeder, tff, artifactsWatcher, myTorrentsDownloadStatistic, leechSettings, agentConfiguration, seedingSettings);
}
Also used : Expectations(org.jmock.Expectations) AgentLifeCycleListener(jetbrains.buildServer.agent.AgentLifeCycleListener) ArtifactsWatcher(jetbrains.buildServer.agent.artifacts.ArtifactsWatcher) Mockery(org.jmock.Mockery) CurrentBuildTrackerImpl(jetbrains.buildServer.agent.impl.CurrentBuildTrackerImpl) SeedSettings(jetbrains.buildServer.torrent.settings.SeedSettings) LeechSettings(jetbrains.buildServer.torrent.settings.LeechSettings) TorrentsDownloadStatistic(jetbrains.buildServer.torrent.util.TorrentsDownloadStatistic) BuildAgentConfiguration(jetbrains.buildServer.agent.BuildAgentConfiguration) ArtifactCacheProvider(jetbrains.buildServer.artifacts.ArtifactCacheProvider) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with TorrentsDownloadStatistic

use of jetbrains.buildServer.torrent.util.TorrentsDownloadStatistic in project teamcity-torrent-plugin by JetBrains.

the class TorrentArtifactCacheListenerSecondTest method setUp.

@BeforeMethod
@Override
protected void setUp() throws Exception {
    super.setUp();
    myAgentDirectory = createTempDir();
    myM = new Mockery();
    final AgentRunningBuild build = myM.mock(AgentRunningBuild.class);
    final BuildProgressLogger logger = new FakeBuildProgressLogger();
    myBuildTracker = myM.mock(CurrentBuildTracker.class);
    myCacheProvider = myM.mock(ArtifactCacheProvider.class);
    myAgentConfiguration = myM.mock(BuildAgentConfiguration.class);
    final LeechSettings leechSettings = myM.mock(LeechSettings.class);
    final SeedSettings seedingSettings = myM.mock(SeedSettings.class);
    myM.checking(new Expectations() {

        {
            allowing(myBuildTracker).getCurrentBuild();
            will(returnValue(build));
            allowing(build).getBuildLogger();
            will(returnValue(logger));
            allowing(build).getAgentConfiguration();
            will(returnValue(myAgentConfiguration));
            allowing(build).getBuildTempDirectory();
            will(returnValue(new File(myAgentDirectory, "temp")));
            allowing(myAgentConfiguration).getSystemDirectory();
            will(returnValue(new File(myAgentDirectory, "system")));
            allowing(myAgentConfiguration).getCacheDirectory(with(Constants.TORRENTS_DIRNAME));
            will(returnValue(new File(myAgentDirectory, "torrents")));
            allowing(myAgentConfiguration).getServerUrl();
            will(returnValue("http://localhost:6969/bs"));
            allowing(build).getBuildTypeExternalId();
            will(returnValue(BUILD_EXTERNAL_ID));
            allowing(build).getBuildId();
            will(returnValue(BUILD_ID));
            allowing(myCacheProvider).addListener(with(any(ArtifactsCacheListener.class)));
            allowing(leechSettings).isDownloadEnabled();
            will(returnValue(true));
            allowing(seedingSettings).isSeedingEnabled();
            will(returnValue(true));
        }
    });
    final TorrentConfiguration configuration = new FakeTorrentConfiguration();
    myArtifactsWatcher = myM.mock(ArtifactsWatcher.class);
    AgentTorrentsSeeder seeder = new AgentTorrentsSeeder(myAgentConfiguration, configuration);
    TorrentFilesFactoryImpl torrentsFactory = new TorrentFilesFactoryImpl(myAgentConfiguration, configuration, new FakeAgentIdleTasks(), seeder);
    final EventDispatcher<AgentLifeCycleListener> eventDispatcher = EventDispatcher.create(AgentLifeCycleListener.class);
    AgentTorrentsManager manager = new AgentTorrentsManager(eventDispatcher, myCacheProvider, myBuildTracker, configuration, seeder, torrentsFactory, myArtifactsWatcher, new TorrentsDownloadStatistic(), leechSettings, myAgentConfiguration, seedingSettings);
    myCacheListener = new TorrentArtifactCacheListener(seeder.getTorrentsSeeder(), myBuildTracker, configuration, manager, torrentsFactory, myArtifactsWatcher, myAgentConfiguration);
    myCacheListener.onCacheInitialized(new DirectoryCacheProviderImpl(new File(myAgentDirectory, "cache"), new SimpleDigestCalculator()));
    manager.checkReady();
}
Also used : Mockery(org.jmock.Mockery) LeechSettings(jetbrains.buildServer.torrent.settings.LeechSettings) TorrentsDownloadStatistic(jetbrains.buildServer.torrent.util.TorrentsDownloadStatistic) ArtifactCacheProvider(jetbrains.buildServer.artifacts.ArtifactCacheProvider) Expectations(org.jmock.Expectations) ArtifactsCacheListener(jetbrains.buildServer.artifacts.ArtifactsCacheListener) ArtifactsWatcher(jetbrains.buildServer.agent.artifacts.ArtifactsWatcher) SeedSettings(jetbrains.buildServer.torrent.settings.SeedSettings) SimpleDigestCalculator(jetbrains.buildServer.artifacts.impl.SimpleDigestCalculator) DirectoryCacheProviderImpl(jetbrains.buildServer.artifacts.impl.DirectoryCacheProviderImpl) File(java.io.File) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with TorrentsDownloadStatistic

use of jetbrains.buildServer.torrent.util.TorrentsDownloadStatistic in project teamcity-torrent-plugin by JetBrains.

the class TorrentArtifactCacheListenerTest method setUp.

@BeforeMethod
@Override
protected void setUp() throws Exception {
    super.setUp();
    myTracker = new Tracker(6969);
    myTracker.start(false);
    myAgentConfiguration = myAgentConfigurationFixture.setUp();
    Mockery m = new Mockery();
    final AgentRunningBuild build = m.mock(AgentRunningBuild.class);
    final BuildProgressLogger logger = new FakeBuildProgressLogger();
    final CurrentBuildTracker buildTracker = m.mock(CurrentBuildTracker.class);
    final ArtifactCacheProvider cacheProvider = m.mock(ArtifactCacheProvider.class);
    final LeechSettings leechSettings = m.mock(LeechSettings.class);
    final SeedSettings seedingSettings = m.mock(SeedSettings.class);
    m.checking(new Expectations() {

        {
            allowing(buildTracker).getCurrentBuild();
            will(returnValue(build));
            allowing(build).getBuildLogger();
            will(returnValue(logger));
            allowing(build).getAgentConfiguration();
            will(returnValue(myAgentConfiguration));
            allowing(cacheProvider).addListener(with(any(ArtifactsCacheListener.class)));
            allowing(build).getBuildTypeExternalId();
            will(returnValue("1"));
            allowing(build).getBuildId();
            will(returnValue(1L));
            allowing(leechSettings).isDownloadEnabled();
            will(returnValue(true));
            allowing(seedingSettings).isSeedingEnabled();
            will(returnValue(true));
        }
    });
    final TorrentConfiguration configuration = new FakeTorrentConfiguration();
    final ArtifactsWatcher artifactsWatcher = m.mock(ArtifactsWatcher.class);
    mySeeder = new AgentTorrentsSeeder(myAgentConfiguration, configuration);
    TorrentFilesFactoryImpl torrentsFactory = new TorrentFilesFactoryImpl(myAgentConfiguration, configuration, new FakeAgentIdleTasks(), mySeeder);
    final EventDispatcher<AgentLifeCycleListener> eventDispatcher = EventDispatcher.create(AgentLifeCycleListener.class);
    AgentTorrentsManager manager = new AgentTorrentsManager(eventDispatcher, cacheProvider, buildTracker, configuration, mySeeder, torrentsFactory, artifactsWatcher, new TorrentsDownloadStatistic(), leechSettings, myAgentConfiguration, seedingSettings);
    myCacheListener = new TorrentArtifactCacheListener(mySeeder.getTorrentsSeeder(), buildTracker, configuration, manager, torrentsFactory, artifactsWatcher, myAgentConfiguration);
    myCacheListener.onCacheInitialized(new DirectoryCacheProviderImpl(getTorrentsDirectory(), new SimpleDigestCalculator()));
    manager.checkReady();
}
Also used : Expectations(org.jmock.Expectations) ArtifactsCacheListener(jetbrains.buildServer.artifacts.ArtifactsCacheListener) Tracker(com.turn.ttorrent.tracker.Tracker) ArtifactsWatcher(jetbrains.buildServer.agent.artifacts.ArtifactsWatcher) Mockery(org.jmock.Mockery) SeedSettings(jetbrains.buildServer.torrent.settings.SeedSettings) SimpleDigestCalculator(jetbrains.buildServer.artifacts.impl.SimpleDigestCalculator) LeechSettings(jetbrains.buildServer.torrent.settings.LeechSettings) DirectoryCacheProviderImpl(jetbrains.buildServer.artifacts.impl.DirectoryCacheProviderImpl) TorrentsDownloadStatistic(jetbrains.buildServer.torrent.util.TorrentsDownloadStatistic) ArtifactCacheProvider(jetbrains.buildServer.artifacts.ArtifactCacheProvider) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with TorrentsDownloadStatistic

use of jetbrains.buildServer.torrent.util.TorrentsDownloadStatistic in project teamcity-torrent-plugin by JetBrains.

the class TorrentTransportTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    super.setUp();
    myServer = new Server(12345);
    WebAppContext handler = new WebAppContext();
    handler.setResourceBase("/");
    handler.setContextPath(CONTEXT_PATH);
    myDownloadMap = new HashMap<String, File>();
    myDownloadAttempts = new ArrayList<String>();
    myDownloadHonestly = true;
    myConfiguration = new FakeTorrentConfiguration();
    myDownloadHacks = new HashMap<String, byte[]>();
    myDownloadHackAttempts = new ArrayList<String>();
    handler.addServlet(new ServletHolder(new HttpServlet() {

        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            myDownloadAttempts.add(req.getPathInfo());
            final ServletOutputStream os = resp.getOutputStream();
            final File file = myDownloadMap.get(req.getPathInfo());
            if (file == null) {
                resp.getOutputStream().close();
            } else {
                final byte[] bytes = FileUtils.readFileToByteArray(file);
                os.write(bytes);
                os.close();
            }
        }
    }), "/*");
    myServer.setHandler(handler);
    myServer.start();
    myAgentParametersMap = new HashMap<String, String>();
    Mockery m = new Mockery();
    myBuild = m.mock(AgentRunningBuild.class);
    myLeechSettings = m.mock(LeechSettings.class);
    final BuildProgressLogger myLogger = new FakeBuildProgressLogger();
    final TorrentFilesFactory torrentFilesFactory = m.mock(TorrentFilesFactory.class);
    m.checking(new Expectations() {

        {
            allowing(myBuild).getSharedConfigParameters();
            will(returnValue(myAgentParametersMap));
            allowing(myBuild).getBuildTypeId();
            will(returnValue("TC_Gaya80x_BuildDist"));
            allowing(myBuild).getBuildLogger();
            will(returnValue(myLogger));
            allowing(myLeechSettings).isDownloadEnabled();
            will(returnValue(true));
            allowing(myLeechSettings).getMaxPieceDownloadTime();
            will(returnValue(15));
            allowing(myLeechSettings).getMinSeedersForDownload();
            will(returnValue(1));
            allowing(torrentFilesFactory).getTorrentFile();
            will(returnValue(createTempFile()));
        }
    });
    BuildAgentConfiguration agentConfiguration = myAgentConfigurationFixture.setUp();
    mySeeder = new AgentTorrentsSeeder(agentConfiguration, myConfiguration);
    myTorrentTransport = new TorrentTransportFactory.TorrentTransport(mySeeder.getTorrentsSeeder(), new HttpClient(), myBuild.getBuildLogger(), "http://localhost:12345", new TorrentsDownloadStatistic(), myLeechSettings, torrentFilesFactory) {

        @Override
        protected byte[] download(@NotNull String urlString) throws IOException {
            if (myDownloadHonestly) {
                return super.download(urlString);
            } else {
                myDownloadHackAttempts.add(urlString);
                return myDownloadHacks.get(urlString);
            }
        }
    };
    myTempDir = createTempDir();
}
Also used : Server(org.eclipse.jetty.server.Server) ServletOutputStream(javax.servlet.ServletOutputStream) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) Mockery(org.jmock.Mockery) HttpServletRequest(javax.servlet.http.HttpServletRequest) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) LeechSettings(jetbrains.buildServer.torrent.settings.LeechSettings) TorrentsDownloadStatistic(jetbrains.buildServer.torrent.util.TorrentsDownloadStatistic) BuildAgentConfiguration(jetbrains.buildServer.agent.BuildAgentConfiguration) Expectations(org.jmock.Expectations) AgentRunningBuild(jetbrains.buildServer.agent.AgentRunningBuild) HttpServlet(javax.servlet.http.HttpServlet) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) BuildProgressLogger(jetbrains.buildServer.agent.BuildProgressLogger) HttpClient(org.apache.commons.httpclient.HttpClient) File(java.io.File) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

LeechSettings (jetbrains.buildServer.torrent.settings.LeechSettings)4 TorrentsDownloadStatistic (jetbrains.buildServer.torrent.util.TorrentsDownloadStatistic)4 Expectations (org.jmock.Expectations)4 Mockery (org.jmock.Mockery)4 BeforeMethod (org.testng.annotations.BeforeMethod)4 ArtifactsWatcher (jetbrains.buildServer.agent.artifacts.ArtifactsWatcher)3 ArtifactCacheProvider (jetbrains.buildServer.artifacts.ArtifactCacheProvider)3 SeedSettings (jetbrains.buildServer.torrent.settings.SeedSettings)3 File (java.io.File)2 BuildAgentConfiguration (jetbrains.buildServer.agent.BuildAgentConfiguration)2 ArtifactsCacheListener (jetbrains.buildServer.artifacts.ArtifactsCacheListener)2 DirectoryCacheProviderImpl (jetbrains.buildServer.artifacts.impl.DirectoryCacheProviderImpl)2 SimpleDigestCalculator (jetbrains.buildServer.artifacts.impl.SimpleDigestCalculator)2 Tracker (com.turn.ttorrent.tracker.Tracker)1 IOException (java.io.IOException)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 HttpServlet (javax.servlet.http.HttpServlet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 AgentLifeCycleListener (jetbrains.buildServer.agent.AgentLifeCycleListener)1