Search in sources :

Example 1 with LogFixture

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

the class DownloadActionTest method shouldFailAfterFourthTryWhenDownloadFails.

@Test
public void shouldFailAfterFourthTryWhenDownloadFails() throws Exception {
    try (LogFixture logging = logFixtureFor(DownloadAction.class, Level.DEBUG)) {
        FailSometimesHttpService httpService = new FailSometimesHttpService(99);
        try {
            new DownloadAction(httpService, new StubGoPublisher(), clock).perform("foo", fetchHandler);
            fail("Expected to throw exception after four tries");
        } catch (Exception e) {
            assertThat(httpService.timesCalled, is(4));
            shouldHaveLogged(logging, Level.ERROR, "Giving up fetching resource 'foo'. Tried 4 times and failed.");
        }
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) IOException(java.io.IOException) SocketException(java.net.SocketException) Test(org.junit.Test)

Example 2 with LogFixture

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

the class AgentProcessParentImplTest method shouldLogInterruptOnAgentProcess.

@Test
public void shouldLogInterruptOnAgentProcess() throws InterruptedException {
    final List<String> cmd = new ArrayList<>();
    try (LogFixture logFixture = logFixtureFor(AgentProcessParentImpl.class, Level.DEBUG)) {
        Process subProcess = mockProcess();
        when(subProcess.waitFor()).thenThrow(new InterruptedException("bang bang!"));
        AgentProcessParentImpl bootstrapper = createBootstrapper(cmd, subProcess);
        int returnCode = bootstrapper.run("bootstrapper_version", "bar", getURLGenerator(), new HashMap<>(), context());
        assertThat(returnCode, is(0));
        assertThat(logFixture.contains(Level.ERROR, "Agent was interrupted. Terminating agent and respawning. java.lang.InterruptedException: bang bang!"), is(true));
        verify(subProcess).destroy();
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) Test(org.junit.Test)

Example 3 with LogFixture

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

the class ExecCommandExecutorTest method shouldNotLeakSecretsToLog.

@Test
@RunIf(value = EnhancedOSChecker.class, arguments = { DO_NOT_RUN_ON, OSChecker.WINDOWS })
public void shouldNotLeakSecretsToLog() {
    try (LogFixture logFixture = logFixtureFor(ExecCommandExecutor.class, Level.DEBUG)) {
        runBuild(compose(secret("topsecret"), exec("not-not-not-exist", "topsecret")), Failed);
        String logs = ArrayUtil.join(logFixture.getMessages());
        assertThat(logs, containsString("not-not-not-exist ******"));
        assertThat(logs, not(containsString("topsecret")));
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RunIf(com.googlecode.junit.ext.RunIf) Test(org.junit.Test)

Example 4 with LogFixture

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

the class JobRerunScheduleServiceTest method shouldMarkResultIfScheduleFailsForUnexpectedReason.

@Test
public void shouldMarkResultIfScheduleFailsForUnexpectedReason() {
    PipelineConfig mingleConfig = PipelineConfigMother.createPipelineConfig("mingle", "build", "unit", "functional");
    Pipeline pipeline = PipelineMother.passedPipelineInstance("mingle", "build", "unit");
    Stage firstStage = pipeline.getFirstStage();
    stub(mingleConfig, pipeline, firstStage);
    //leads to null pointer exception
    schedulingChecker = mock(SchedulingCheckerService.class);
    doThrow(new NullPointerException("The whole world is a big null.")).when(schedulingChecker).canSchedule(any(OperationResult.class));
    service = new ScheduleService(goConfigService, pipelineService, stageService, schedulingChecker, mock(PipelineScheduledTopic.class), mock(PipelineDao.class), mock(StageDao.class), mock(StageOrderService.class), securityService, pipelineScheduleQueue, jobInstanceService, mock(JobInstanceDao.class), mock(AgentAssignment.class), environmentConfigService, lockService, serverHealthService, txnTemplate, mock(AgentService.class), null, null, null, null, null, schedulingPerformanceLogger, null);
    HttpOperationResult result = new HttpOperationResult();
    try (LogFixture logFixture = logFixtureFor(ScheduleService.class, Level.DEBUG)) {
        Stage stage = service.rerunJobs(firstStage, a("unit"), result);
        assertThat(logFixture.contains(Level.ERROR, "Job rerun request for job(s) [unit] could not be completed because of unexpected failure. Cause: The whole world is a big null."), is(true));
        assertThat(stage, is(nullValue()));
        assertThat(result.httpCode(), is(400));
        assertThat(result.message(), is("Job rerun request for job(s) [unit] could not be completed because of unexpected failure. Cause: The whole world is a big null."));
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) OperationResult(com.thoughtworks.go.server.service.result.OperationResult) Test(org.junit.Test)

Example 5 with LogFixture

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

the class DefaultPluginLoggingServiceIntegrationTest method shouldNotLogPluginMessagesToRootLogger.

@Test
public void shouldNotLogPluginMessagesToRootLogger() throws Exception {
    try (LogFixture fixture = logFixtureForRootLogger(Level.INFO)) {
        DefaultPluginLoggingService service = new DefaultPluginLoggingService(systemEnvironment);
        service.info(pluginID(1), "LoggingClass", "this-message-should-not-go-to-root-logger");
        String failureMessage = "Expected no messages to be logged to root logger. Found: " + Arrays.toString(fixture.getMessages());
        assertThat(failureMessage, fixture.getMessages().length, is(0));
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) Test(org.junit.Test)

Aggregations

LogFixture (com.thoughtworks.go.util.LogFixture)20 Test (org.junit.Test)20 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)4 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)3 ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)3 IOException (java.io.IOException)3 RunIf (com.googlecode.junit.ext.RunIf)1 ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)1 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)1 ConfigUpdateCheckFailedException (com.thoughtworks.go.config.update.ConfigUpdateCheckFailedException)1 AgentInstance (com.thoughtworks.go.domain.AgentInstance)1 JobInstance (com.thoughtworks.go.domain.JobInstance)1 NullUser (com.thoughtworks.go.domain.NullUser)1 Modification (com.thoughtworks.go.domain.materials.Modification)1 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)1 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)1 OperationResult (com.thoughtworks.go.server.service.result.OperationResult)1 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)1 TimeProvider (com.thoughtworks.go.util.TimeProvider)1 ConsoleResult (com.thoughtworks.go.util.command.ConsoleResult)1