Search in sources :

Example 1 with BuildAgentConfiguration

use of jetbrains.buildServer.agent.BuildAgentConfiguration 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 BuildAgentConfiguration

use of jetbrains.buildServer.agent.BuildAgentConfiguration in project teamcity-torrent-plugin by JetBrains.

the class BuildAgentConfigurationFixture method setUp.

public BuildAgentConfiguration setUp() throws IOException {
    myTmpFiles = new TempFiles();
    final File systemDir = myTmpFiles.createTempDir();
    final File torrentsDir = myTmpFiles.createTempDir();
    Mockery m = new Mockery();
    final BuildAgentConfiguration agentConfiguration = m.mock(BuildAgentConfiguration.class);
    m.checking(new Expectations() {

        {
            allowing(agentConfiguration).getServerUrl();
            will(returnValue("http://localhost:8111/bs"));
            allowing(agentConfiguration).getSystemDirectory();
            will(returnValue(systemDir));
            allowing(agentConfiguration).getCacheDirectory(with(Constants.TORRENTS_DIRNAME));
            will(returnValue(torrentsDir));
        }
    });
    return agentConfiguration;
}
Also used : Expectations(org.jmock.Expectations) File(java.io.File) Mockery(org.jmock.Mockery) BuildAgentConfiguration(jetbrains.buildServer.agent.BuildAgentConfiguration) TempFiles(jetbrains.buildServer.TempFiles)

Example 3 with BuildAgentConfiguration

use of jetbrains.buildServer.agent.BuildAgentConfiguration in project teamcity-powershell by JetBrains.

the class PowerShellInfoTest method testSaveLoad.

@Test(dataProvider = "editionProvider")
public void testSaveLoad(@NotNull final PowerShellEdition edition) throws IOException {
    PowerShellInfo info = new PowerShellInfo(PowerShellBitness.x64, createTempDir(), "1.0", edition, "powershell.exe");
    final Mockery m = new Mockery();
    final BuildAgentConfiguration conf = m.mock(BuildAgentConfiguration.class);
    final Map<String, String> confParams = new HashMap<String, String>();
    m.checking(new Expectations() {

        {
            allowing(conf).getConfigurationParameters();
            will(returnValue(Collections.unmodifiableMap(confParams)));
            allowing(conf).addConfigurationParameter(with(any(String.class)), with(any(String.class)));
            will(new Action() {

                public Object invoke(final Invocation invocation) {
                    final String key = (String) invocation.getParameter(0);
                    final String value = (String) invocation.getParameter(1);
                    Assert.assertNotNull(key);
                    Assert.assertNotNull(value);
                    confParams.put(key, value);
                    return null;
                }

                public void describeTo(final Description description) {
                    description.appendText("add Parameters");
                }
            });
        }
    });
    final String propertyName = "powershell_" + info.getEdition().getValue() + "_" + info.getVersion() + "_" + info.getBitness().getValue();
    assertNull(conf.getConfigurationParameters().get(propertyName));
    assertNull(conf.getConfigurationParameters().get(propertyName + "_Path"));
    info.saveInfo(conf);
    assertEquals(info.getVersion(), conf.getConfigurationParameters().get(propertyName));
    assertEquals(info.getHome().getAbsolutePath(), conf.getConfigurationParameters().get(propertyName + "_Path"));
}
Also used : Expectations(org.jmock.Expectations) Action(org.jmock.api.Action) Description(org.hamcrest.Description) Invocation(org.jmock.api.Invocation) HashMap(java.util.HashMap) Mockery(org.jmock.Mockery) BuildAgentConfiguration(jetbrains.buildServer.agent.BuildAgentConfiguration) Test(org.testng.annotations.Test)

Example 4 with BuildAgentConfiguration

use of jetbrains.buildServer.agent.BuildAgentConfiguration in project teamcity-torrent-plugin by JetBrains.

the class TorrentFilesFactoryTest method setUp.

@BeforeMethod
@Override
protected void setUp() throws Exception {
    super.setUp();
    myTorrentsDir = createTempDir();
    final BuildAgentConfiguration agentConfiguration = myAgentConfigurationFixture.setUp();
    final TorrentConfiguration configuration = new FakeTorrentConfiguration();
    myFakeAgentIdleTasks = new FakeAgentIdleTasks();
    mySeeder = new AgentTorrentsSeeder(agentConfiguration, configuration);
    myTorrentFilesFactory = new TorrentFilesFactoryImpl(agentConfiguration, configuration, myFakeAgentIdleTasks, mySeeder);
}
Also used : BuildAgentConfiguration(jetbrains.buildServer.agent.BuildAgentConfiguration) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with BuildAgentConfiguration

use of jetbrains.buildServer.agent.BuildAgentConfiguration 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

BuildAgentConfiguration (jetbrains.buildServer.agent.BuildAgentConfiguration)5 Expectations (org.jmock.Expectations)4 Mockery (org.jmock.Mockery)4 BeforeMethod (org.testng.annotations.BeforeMethod)3 File (java.io.File)2 LeechSettings (jetbrains.buildServer.torrent.settings.LeechSettings)2 TorrentsDownloadStatistic (jetbrains.buildServer.torrent.util.TorrentsDownloadStatistic)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 HttpServlet (javax.servlet.http.HttpServlet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 TempFiles (jetbrains.buildServer.TempFiles)1 AgentLifeCycleListener (jetbrains.buildServer.agent.AgentLifeCycleListener)1 AgentRunningBuild (jetbrains.buildServer.agent.AgentRunningBuild)1 BuildProgressLogger (jetbrains.buildServer.agent.BuildProgressLogger)1 ArtifactsWatcher (jetbrains.buildServer.agent.artifacts.ArtifactsWatcher)1 CurrentBuildTrackerImpl (jetbrains.buildServer.agent.impl.CurrentBuildTrackerImpl)1 ArtifactCacheProvider (jetbrains.buildServer.artifacts.ArtifactCacheProvider)1