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