Search in sources :

Example 51 with SystemEnvironment

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);
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) URLService(com.thoughtworks.go.util.URLService) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) GoAgentServerHttpClient(com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClient) BasicStatusLine(org.apache.http.message.BasicStatusLine) Before(org.junit.Before)

Example 52 with SystemEnvironment

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;
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment)

Example 53 with SystemEnvironment

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"));
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) FileUtils(org.apache.commons.io.FileUtils) File(java.io.File)

Example 54 with SystemEnvironment

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");
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) After(org.junit.After)

Example 55 with SystemEnvironment

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));
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) FakeBuildRepositoryRemote(com.thoughtworks.go.agent.testhelpers.FakeBuildRepositoryRemote) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) Test(org.junit.Test)

Aggregations

SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)174 Test (org.junit.Test)93 Before (org.junit.Before)38 File (java.io.File)37 AgentInstance (com.thoughtworks.go.domain.AgentInstance)27 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)15 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)14 ArrayList (java.util.ArrayList)14 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)11 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)10 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)10 AgentStatusChangeListener (com.thoughtworks.go.listener.AgentStatusChangeListener)10 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)9 AgentConfig (com.thoughtworks.go.config.AgentConfig)8 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)8 PipelineConfigDependencyGraph (com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph)8 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)7 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)7 Date (java.util.Date)7 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)6