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);
}
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;
}
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"));
}
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);
}
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();
}
Aggregations