use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.
the class AgentUpgradeServiceTest method setUp.
@Before
public void setUp() throws Exception {
systemEnvironment = mock(SystemEnvironment.class);
urlService = mock(URLService.class);
GoAgentServerHttpClient httpClient = mock(GoAgentServerHttpClient.class);
jvmExitter = mock(AgentUpgradeService.JvmExitter.class);
agentUpgradeService = spy(new AgentUpgradeService(urlService, httpClient, systemEnvironment, jvmExitter));
httpMethod = mock(HttpGet.class);
doReturn(httpMethod).when(agentUpgradeService).getAgentLatestStatusGetMethod();
closeableHttpResponse = mock(CloseableHttpResponse.class);
when(closeableHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
when(httpClient.execute(httpMethod)).thenReturn(closeableHttpResponse);
}
use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.
the class ConsoleStreamer method stream.
/**
* Applies a lambda (or equivalent {@link Consumer}) to each line and increments the totalLinesConsumed() until
* EOF. Multiple invocations to this method will continue from where it left off if new content was appended after
* the last read.
*
* @param action the lambda to apply to each line
* @return the number of lines streamed by this invocation
* @throws IOException if the file does not exist or is otherwise not readable
*/
public long stream(Consumer<String> action) throws IOException {
long linesStreamed = 0L;
if (null == stream)
stream = Files.lines(path, new SystemEnvironment().consoleLogCharsetAsCharset()).skip(start);
if (null == iterator)
iterator = stream.iterator();
while (iterator.hasNext()) {
action.accept((String) iterator.next());
++linesStreamed;
++count;
}
return linesStreamed;
}
use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.
the class AgentBootstrapper method cleanupTempFiles.
private void cleanupTempFiles() {
FileUtils.deleteQuietly(new File(FileUtil.TMP_PARENT_DIR));
// launchers extracted from old versions
FileUtils.deleteQuietly(new File("exploded_agent_launcher_dependencies"));
FileUtils.listFiles(new File("."), AGENT_LAUNCHER_TMP_FILE_FILTER, FalseFileFilter.INSTANCE).forEach(FileUtils::deleteQuietly);
FileUtils.deleteQuietly(new File(new SystemEnvironment().getConfigDir(), "trust.jks"));
}
use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.
the class BuildWorkArtifactUploadingTest method teardown.
@After
public void teardown() throws Exception {
TestRepo.internalTearDown();
FileUtils.deleteQuietly(buildWorkingDirectory);
new SystemEnvironment().clearProperty("serviceUrl");
}
use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.
the class BuildWorkEnvironmentVariablesTest method shouldOutputEnvironmentVariablesIntoConsoleOut.
@Test
public void shouldOutputEnvironmentVariablesIntoConsoleOut() throws IOException {
BuildAssignment buildAssigment = createAssignment(null);
BuildWork work = new BuildWork(buildAssigment, systemEnvironment.consoleLogCharset());
GoArtifactsManipulatorStub manipulator = new GoArtifactsManipulatorStub();
new SystemEnvironment().setProperty("serviceUrl", "some_random_place");
AgentIdentifier agentIdentifier = new AgentIdentifier("somename", "127.0.0.1", AGENT_UUID);
work.doWork(environmentVariableContext, new AgentWorkContext(agentIdentifier, new FakeBuildRepositoryRemote(), manipulator, new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false), packageRepositoryExtension, scmExtension, taskExtension, null, null));
assertThat(manipulator.consoleOut(), printedEnvVariable("GO_SERVER_URL", "some_random_place"));
assertThat(manipulator.consoleOut(), printedEnvVariable("GO_PIPELINE_NAME", PIPELINE_NAME));
assertThat(manipulator.consoleOut(), printedEnvVariable("GO_PIPELINE_COUNTER", 1));
assertThat(manipulator.consoleOut(), printedEnvVariable("GO_PIPELINE_LABEL", 1));
assertThat(manipulator.consoleOut(), printedEnvVariable("GO_STAGE_NAME", STAGE_NAME));
assertThat(manipulator.consoleOut(), printedEnvVariable("GO_STAGE_COUNTER", 1));
assertThat(manipulator.consoleOut(), printedEnvVariable("GO_JOB_NAME", JOB_NAME));
assertThat(manipulator.consoleOut(), printedEnvVariable("GO_REVISION", 3));
assertThat(manipulator.consoleOut(), printedEnvVariable("GO_TRIGGER_USER", TRIGGERED_BY_USER));
}
Aggregations