Search in sources :

Example 1 with CeDistributedInformation

use of org.sonar.ce.CeDistributedInformation in project sonarqube by SonarSource.

the class CeCleaningSchedulerImplTest method startScheduling_does_not_fail_if_cleaning_methods_send_even_an_Exception.

@Test
public void startScheduling_does_not_fail_if_cleaning_methods_send_even_an_Exception() {
    InternalCeQueue mockedInternalCeQueue = mock(InternalCeQueue.class);
    CeDistributedInformation mockedCeDistributedInformation = mockCeDistributedInformation(jobLock);
    CeCleaningSchedulerImpl underTest = mockCeCleaningSchedulerImpl(mockedInternalCeQueue, mockedCeDistributedInformation);
    Exception exception = new IllegalArgumentException("faking unchecked exception thrown by cancelWornOuts");
    doThrow(exception).when(mockedInternalCeQueue).resetTasksWithUnknownWorkerUUIDs(any());
    underTest.startScheduling();
    verify(mockedInternalCeQueue).resetTasksWithUnknownWorkerUUIDs(any());
}
Also used : CeDistributedInformation(org.sonar.ce.CeDistributedInformation) InternalCeQueue(org.sonar.ce.queue.InternalCeQueue) Test(org.junit.Test)

Example 2 with CeDistributedInformation

use of org.sonar.ce.CeDistributedInformation in project sonarqube by SonarSource.

the class CeCleaningSchedulerImplTest method startScheduling_must_call_the_lock_methods.

@Test
public void startScheduling_must_call_the_lock_methods() {
    InternalCeQueue mockedInternalCeQueue = mock(InternalCeQueue.class);
    CeDistributedInformation mockedCeDistributedInformation = mockCeDistributedInformation(jobLock);
    CeCleaningSchedulerImpl underTest = mockCeCleaningSchedulerImpl(mockedInternalCeQueue, mockedCeDistributedInformation);
    underTest.startScheduling();
    verify(mockedCeDistributedInformation, times(1)).acquireCleanJobLock();
    verify(jobLock, times(1)).tryLock();
    verify(jobLock, times(1)).unlock();
}
Also used : CeDistributedInformation(org.sonar.ce.CeDistributedInformation) InternalCeQueue(org.sonar.ce.queue.InternalCeQueue) Test(org.junit.Test)

Example 3 with CeDistributedInformation

use of org.sonar.ce.CeDistributedInformation in project sonarqube by SonarSource.

the class CeCleaningSchedulerImplTest method startScheduling_fails_if_resetTasksWithUnknownWorkerUUIDs_send_an_Error.

@Test
public void startScheduling_fails_if_resetTasksWithUnknownWorkerUUIDs_send_an_Error() {
    InternalCeQueue mockedInternalCeQueue = mock(InternalCeQueue.class);
    CeDistributedInformation mockedCeDistributedInformation = mockCeDistributedInformation(jobLock);
    CeCleaningSchedulerImpl underTest = mockCeCleaningSchedulerImpl(mockedInternalCeQueue, mockedCeDistributedInformation);
    Error expected = new Error("faking Error thrown by cancelWornOuts");
    doThrow(expected).when(mockedInternalCeQueue).resetTasksWithUnknownWorkerUUIDs(any());
    try {
        underTest.startScheduling();
        fail("the error should have been thrown");
    } catch (Error e) {
        assertThat(e).isSameAs(expected);
    }
    verify(mockedInternalCeQueue).resetTasksWithUnknownWorkerUUIDs(any());
}
Also used : CeDistributedInformation(org.sonar.ce.CeDistributedInformation) InternalCeQueue(org.sonar.ce.queue.InternalCeQueue) Test(org.junit.Test)

Example 4 with CeDistributedInformation

use of org.sonar.ce.CeDistributedInformation in project sonarqube by SonarSource.

the class CeCleaningSchedulerImplTest method startScheduling_must_not_execute_method_if_lock_is_already_acquired.

@Test
public void startScheduling_must_not_execute_method_if_lock_is_already_acquired() {
    InternalCeQueue mockedInternalCeQueue = mock(InternalCeQueue.class);
    CeDistributedInformation mockedCeDistributedInformation = mockCeDistributedInformation(jobLock);
    when(jobLock.tryLock()).thenReturn(false);
    CeCleaningSchedulerImpl underTest = mockCeCleaningSchedulerImpl(mockedInternalCeQueue, mockedCeDistributedInformation);
    underTest.startScheduling();
    verify(mockedCeDistributedInformation, times(1)).acquireCleanJobLock();
    verify(jobLock, times(1)).tryLock();
    // since lock cannot be locked, unlock method is not been called
    verify(jobLock, times(0)).unlock();
    // since lock cannot be locked, cleaning job methods must not be called
    verify(mockedInternalCeQueue, times(0)).resetTasksWithUnknownWorkerUUIDs(any());
}
Also used : CeDistributedInformation(org.sonar.ce.CeDistributedInformation) InternalCeQueue(org.sonar.ce.queue.InternalCeQueue) Test(org.junit.Test)

Example 5 with CeDistributedInformation

use of org.sonar.ce.CeDistributedInformation in project sonarqube by SonarSource.

the class CeCleaningSchedulerImplTest method mockCeDistributedInformation.

private CeDistributedInformation mockCeDistributedInformation(Lock result) {
    CeDistributedInformation mocked = mock(CeDistributedInformation.class);
    when(mocked.acquireCleanJobLock()).thenReturn(result);
    when(result.tryLock()).thenReturn(true);
    return mocked;
}
Also used : CeDistributedInformation(org.sonar.ce.CeDistributedInformation)

Aggregations

CeDistributedInformation (org.sonar.ce.CeDistributedInformation)5 Test (org.junit.Test)4 InternalCeQueue (org.sonar.ce.queue.InternalCeQueue)4