Search in sources :

Example 1 with InternalCeQueue

use of org.sonar.ce.queue.InternalCeQueue 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 InternalCeQueue

use of org.sonar.ce.queue.InternalCeQueue in project sonarqube by SonarSource.

the class CeCleaningSchedulerImplTest method startScheduling_calls_cleaning_methods_of_internalCeQueue_at_fixed_rate_with_value_from_CeConfiguration.

@Test
public void startScheduling_calls_cleaning_methods_of_internalCeQueue_at_fixed_rate_with_value_from_CeConfiguration() {
    InternalCeQueue mockedInternalCeQueue = mock(InternalCeQueue.class);
    long wornOutInitialDelay = 10L;
    long wornOutDelay = 20L;
    long unknownWorkerInitialDelay = 11L;
    long unknownWorkerDelay = 21L;
    CeConfiguration mockedCeConfiguration = mockCeConfiguration(wornOutInitialDelay, wornOutDelay);
    CeCleaningAdapter executorService = new CeCleaningAdapter() {

        @Override
        public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initDelay, long period, TimeUnit unit) {
            schedulerCounter++;
            switch(schedulerCounter) {
                case 1:
                    assertThat(initDelay).isEqualTo(wornOutInitialDelay);
                    assertThat(period).isEqualTo(wornOutDelay);
                    assertThat(unit).isEqualTo(TimeUnit.MINUTES);
                    break;
                case 2:
                    assertThat(initDelay).isEqualTo(unknownWorkerInitialDelay);
                    assertThat(period).isEqualTo(unknownWorkerDelay);
                    assertThat(unit).isEqualTo(TimeUnit.MINUTES);
                    break;
                default:
                    fail("Unknwon call of scheduleWithFixedDelay");
            }
            // synchronously execute command
            command.run();
            return null;
        }
    };
    CeCleaningSchedulerImpl underTest = new CeCleaningSchedulerImpl(executorService, mockedCeConfiguration, mockedInternalCeQueue, mockCeDistributedInformation(jobLock));
    underTest.startScheduling();
    assertThat(executorService.schedulerCounter).isOne();
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) CeConfiguration(org.sonar.ce.configuration.CeConfiguration) InternalCeQueue(org.sonar.ce.queue.InternalCeQueue) Test(org.junit.Test)

Example 3 with InternalCeQueue

use of org.sonar.ce.queue.InternalCeQueue 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 4 with InternalCeQueue

use of org.sonar.ce.queue.InternalCeQueue 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 5 with InternalCeQueue

use of org.sonar.ce.queue.InternalCeQueue 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)

Aggregations

Test (org.junit.Test)5 InternalCeQueue (org.sonar.ce.queue.InternalCeQueue)5 CeDistributedInformation (org.sonar.ce.CeDistributedInformation)4 TimeUnit (java.util.concurrent.TimeUnit)1 CeConfiguration (org.sonar.ce.configuration.CeConfiguration)1