Search in sources :

Example 1 with ProcessManager

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

the class MaterialUpdateServiceTest method shouldUpdateServerHealthMessageWhenHung.

@Test
void shouldUpdateServerHealthMessageWhenHung() {
    // given
    service = spy(service);
    systemEnvironment.set(SystemEnvironment.MATERIAL_UPDATE_INACTIVE_TIMEOUT, 1);
    ProcessManager processManager = mock(ProcessManager.class);
    Material material = mock(Material.class);
    service.updateMaterial(material);
    when(service.getProcessManager()).thenReturn(processManager);
    when(material.getFingerprint()).thenReturn("fingerprint");
    when(material.getUriForDisplay()).thenReturn("uri");
    when(material.getLongDescription()).thenReturn("details to uniquely identify a material");
    when(material.isAutoUpdate()).thenReturn(true);
    when(processManager.getIdleTimeFor(new MaterialFingerprintTag("fingerprint"))).thenReturn(60010L);
    // when
    service.updateMaterial(material);
    // then
    verify(serverHealthService).removeByScope(HealthStateScope.forMaterialUpdate(material));
    ArgumentCaptor<ServerHealthState> argumentCaptor = ArgumentCaptor.forClass(ServerHealthState.class);
    verify(serverHealthService).update(argumentCaptor.capture());
    assertThat(argumentCaptor.getValue().getMessage()).isEqualTo("Material update for uri hung:");
    assertThat(argumentCaptor.getValue().getDescription()).isEqualTo("Material update is currently running but has not shown any activity in the last 1 minute(s). This may be hung. Details - details to uniquely identify a material");
    assertThat(argumentCaptor.getValue().getType()).isEqualTo(HealthStateType.general(HealthStateScope.forMaterialUpdate(material)));
}
Also used : MaterialFingerprintTag(com.thoughtworks.go.util.MaterialFingerprintTag) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) MaterialsMother.gitMaterial(com.thoughtworks.go.helper.MaterialsMother.gitMaterial) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) ProcessManager(com.thoughtworks.go.util.ProcessManager) Test(org.junit.jupiter.api.Test)

Aggregations

PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)1 ScmMaterial (com.thoughtworks.go.config.materials.ScmMaterial)1 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)1 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)1 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)1 Material (com.thoughtworks.go.domain.materials.Material)1 MaterialsMother.gitMaterial (com.thoughtworks.go.helper.MaterialsMother.gitMaterial)1 ServerHealthState (com.thoughtworks.go.serverhealth.ServerHealthState)1 MaterialFingerprintTag (com.thoughtworks.go.util.MaterialFingerprintTag)1 ProcessManager (com.thoughtworks.go.util.ProcessManager)1 Test (org.junit.jupiter.api.Test)1