Search in sources :

Example 6 with SystemEnvironment

use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.

the class AgentWebSocketClientControllerTest method processAssignWorkActionWithConsoleLogsThroughWebSockets.

@Test
public void processAssignWorkActionWithConsoleLogsThroughWebSockets() throws IOException, InterruptedException {
    SystemEnvironment env = new SystemEnvironment();
    env.set(SystemEnvironment.WEBSOCKET_ENABLED, true);
    env.set(SystemEnvironment.CONSOLE_LOGS_THROUGH_WEBSOCKET_ENABLED, true);
    ArgumentCaptor<Message> argumentCaptor = ArgumentCaptor.forClass(Message.class);
    agentController = createAgentController();
    agentController.init();
    agentController.process(new Message(Action.assignWork, MessageEncoding.encodeWork(new SleepWork("work1", 0))));
    assertThat(agentController.getAgentRuntimeInfo().getRuntimeStatus(), is(AgentRuntimeStatus.Idle));
    verify(webSocketSessionHandler, times(2)).sendAndWaitForAcknowledgement(argumentCaptor.capture());
    verify(artifactsManipulator).setProperty(null, new Property("work1_result", "done"));
    Message message = argumentCaptor.getAllValues().get(1);
    assertThat(message.getAcknowledgementId(), notNullValue());
    assertThat(message.getAction(), is(Action.ping));
    assertThat(message.getData(), is(MessageEncoding.encodeData(agentController.getAgentRuntimeInfo())));
    Message message2 = argumentCaptor.getAllValues().get(0);
    assertThat(message2.getAcknowledgementId(), notNullValue());
    assertThat(message2.getAction(), is(Action.consoleOut));
    ConsoleTransmission ct = MessageEncoding.decodeData(message2.getData(), ConsoleTransmission.class);
    assertThat(ct.getLine(), RegexMatcher.matches("Sleeping for 0 milliseconds"));
    env.set(SystemEnvironment.WEBSOCKET_ENABLED, false);
    env.set(SystemEnvironment.CONSOLE_LOGS_THROUGH_WEBSOCKET_ENABLED, false);
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) SleepWork(com.thoughtworks.go.work.SleepWork) Test(org.junit.Test)

Example 7 with SystemEnvironment

use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.

the class AgentMain method main.

public static void main(String... argv) throws Exception {
    AgentBootstrapperArgs args = new AgentCLI().parse(argv);
    LoggingHelper.configureLoggerIfNoneExists("go-agent.log", "go-agent-log4j.properties");
    new SystemEnvironment().setProperty("go.process.type", "agent");
    new SystemEnvironment().setProperty(SystemEnvironment.SERVICE_URL, args.getServerUrl().toString());
    new SystemEnvironment().setProperty(SystemEnvironment.AGENT_SSL_VERIFICATION_MODE, args.getSslMode().toString());
    if (args.getRootCertFile() != null) {
        new SystemEnvironment().setProperty(SystemEnvironment.AGENT_ROOT_CERT_FILE, args.getRootCertFile().toString());
    }
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
    ctx.registerShutdownHook();
}
Also used : AgentCLI(com.thoughtworks.go.agent.common.AgentCLI) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) AgentBootstrapperArgs(com.thoughtworks.go.agent.common.AgentBootstrapperArgs)

Example 8 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 9 with SystemEnvironment

use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.

the class FileValidatorTest method setUp.

@Before
public void setUp() {
    realConfigDir = new SystemEnvironment().getPropertyImpl("cruise.config.dir");
    new SystemEnvironment().setProperty("cruise.config.dir", new SystemEnvironment().getPropertyImpl("java.io.tmpdir"));
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) Before(org.junit.Before)

Example 10 with SystemEnvironment

use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.

the class BuildCauseProducerServiceTest method shouldHandleNoModificationExceptionThrownByAutoBuild.

@Test
public void shouldHandleNoModificationExceptionThrownByAutoBuild() {
    String pipelineName = "pipeline";
    ServerHealthStateOperationResult result = new ServerHealthStateOperationResult();
    PipelineConfig config = PipelineConfigMother.pipelineConfig(pipelineName);
    Material svnMaterial = MaterialsMother.defaultMaterials().get(0);
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("up"), new CaseInsensitiveString("s1"));
    config.materialConfigs().clear();
    config.addMaterialConfig(svnMaterial.config());
    config.addMaterialConfig(dependencyMaterial.config());
    when(pipelineService.getRevisionsBasedOnDependencies(Matchers.<MaterialRevisions>any(), Matchers.<BasicCruiseConfig>any(), Matchers.<CaseInsensitiveString>any())).thenThrow(new NoModificationsPresentForDependentMaterialException("P/1/S/1"));
    when(pipelineScheduleQueue.mostRecentScheduled(pipelineName)).thenReturn(BuildCause.createNeverRun());
    Modification modification = ModificationsMother.checkinWithComment("r", "c", new Date(), "f1");
    when(materialRepository.findLatestModification(svnMaterial)).thenReturn(ModificationsMother.createSvnMaterialWithMultipleRevisions(1, modification));
    when(materialRepository.findLatestModification(dependencyMaterial)).thenReturn(new MaterialRevisions(ModificationsMother.changedDependencyMaterialRevision("up", 1, "1", "s", 1, new Date())));
    when(specificMaterialRevisionFactory.create(Matchers.<String>any(), Matchers.<Map<String, String>>any())).thenReturn(MaterialRevisions.EMPTY);
    when(goConfigService.upstreamDependencyGraphOf(Matchers.<String>any(), Matchers.<BasicCruiseConfig>any())).thenReturn(new PipelineConfigDependencyGraph(config));
    MaterialConfigs knownMaterialConfigs = new MaterialConfigs(svnMaterial.config(), dependencyMaterial.config());
    Materials materials = new Materials(svnMaterial, dependencyMaterial);
    when(materialConfigConverter.toMaterials(config.materialConfigs())).thenReturn(materials);
    when(materialExpansionService.expandMaterialConfigsForScheduling(config.materialConfigs())).thenReturn(knownMaterialConfigs);
    when(materialConfigConverter.toMaterials(knownMaterialConfigs)).thenReturn(materials);
    AutoBuild autoBuild = new AutoBuild(goConfigService, pipelineService, pipelineName, new SystemEnvironment(), null, mockServerHealthService);
    ServerHealthState serverHealthState = buildCauseProducerService.newProduceBuildCause(config, autoBuild, result, 12345);
    assertThat(serverHealthState.isSuccess(), is(true));
}
Also used : AutoBuild(com.thoughtworks.go.server.service.AutoBuild) Modification(com.thoughtworks.go.domain.materials.Modification) MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) NoModificationsPresentForDependentMaterialException(com.thoughtworks.go.server.service.NoModificationsPresentForDependentMaterialException) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Materials(com.thoughtworks.go.config.materials.Materials) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Date(java.util.Date) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) Test(org.junit.Test)

Aggregations

SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)158 Test (org.junit.Test)82 Before (org.junit.Before)38 File (java.io.File)35 AgentInstance (com.thoughtworks.go.domain.AgentInstance)26 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)15 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)14 ArrayList (java.util.ArrayList)12 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)10 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)9 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)8 PipelineConfigDependencyGraph (com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph)8 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)8 ZipUtil (com.thoughtworks.go.util.ZipUtil)8 Date (java.util.Date)8 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)7 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)7 AgentConfig (com.thoughtworks.go.config.AgentConfig)6 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)6 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)5