Search in sources :

Example 1 with PipelineRunManager

use of com.epam.pipeline.manager.pipeline.PipelineRunManager in project cloud-pipeline by epam.

the class ResourceMonitoringManagerTest method testPauseOnDemand.

@Test
public void testPauseOnDemand() throws InterruptedException {
    when(preferenceManager.getPreference(SystemPreferences.SYSTEM_IDLE_ACTION)).thenReturn(IdleRunAction.PAUSE.name());
    LocalDateTime lastNotificationDate = mockAlreadyNotifiedRuns();
    Thread.sleep(10);
    resourceMonitoringManager.monitorResourceUsage();
    verify(pipelineRunManager).updatePipelineRunsLastNotification(runsToUpdateCaptor.capture());
    verify(notificationManager).notifyIdleRuns(runsToNotifyCaptor.capture(), eq(NotificationType.IDLE_RUN));
    verify(notificationManager).notifyIdleRuns(any(), eq(NotificationType.IDLE_RUN_PAUSED));
    List<PipelineRun> updatedRuns = runsToUpdateCaptor.getValue();
    Assert.assertEquals(2, updatedRuns.size());
    Assert.assertFalse(updatedRuns.stream().anyMatch(r -> lastNotificationDate.equals(r.getLastIdleNotificationTime())));
    Assert.assertNull(updatedRuns.stream().filter(r -> r.getPodId().equals(idleOnDemandRun.getPodId())).findFirst().get().getLastIdleNotificationTime());
    verify(pipelineRunManager).pauseRun(TEST_IDLE_ON_DEMAND_RUN_ID, true);
    verify(pipelineRunManager, never()).pauseRun(TEST_OK_RUN_ID, true);
    List<Pair<PipelineRun, Double>> runsToNotify = runsToNotifyCaptor.getValue();
    Assert.assertEquals(1, runsToNotify.size());
}
Also used : LocalDateTime(java.time.LocalDateTime) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) Arrays(java.util.Arrays) InstanceType(com.epam.pipeline.entity.cluster.InstanceType) Mock(org.mockito.Mock) Date(java.util.Date) PipelineRunManager(com.epam.pipeline.manager.pipeline.PipelineRunManager) BehaviorSubject(io.reactivex.subjects.BehaviorSubject) LocalDateTime(java.time.LocalDateTime) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) HashMap(java.util.HashMap) IdleRunAction(com.epam.pipeline.entity.monitoring.IdleRunAction) Captor(org.mockito.Captor) MockitoAnnotations(org.mockito.MockitoAnnotations) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) ArgumentCaptor(org.mockito.ArgumentCaptor) MessageHelper(com.epam.pipeline.common.MessageHelper) Pair(org.apache.commons.lang3.tuple.Pair) Matchers.eq(org.mockito.Matchers.eq) Map(java.util.Map) NotificationType(com.epam.pipeline.entity.notification.NotificationSettings.NotificationType) Observable(io.reactivex.Observable) Before(org.junit.Before) DateUtils(com.epam.pipeline.entity.utils.DateUtils) InstanceOfferManager(com.epam.pipeline.manager.cluster.InstanceOfferManager) PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) TaskScheduler(org.springframework.scheduling.TaskScheduler) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Instant(java.time.Instant) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) List(java.util.List) Mockito.never(org.mockito.Mockito.never) ChronoUnit(java.time.temporal.ChronoUnit) Whitebox(org.mockito.internal.util.reflection.Whitebox) NotificationManager(com.epam.pipeline.manager.notification.NotificationManager) MonitoringESDao(com.epam.pipeline.dao.monitoring.MonitoringESDao) Assert(org.junit.Assert) Collections(java.util.Collections) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.Test)

Example 2 with PipelineRunManager

use of com.epam.pipeline.manager.pipeline.PipelineRunManager in project cloud-pipeline by epam.

the class ResourceMonitoringManagerTest method testNotifyTwice.

@Test
public void testNotifyTwice() throws InterruptedException {
    when(preferenceManager.getPreference(SystemPreferences.SYSTEM_IDLE_ACTION)).thenReturn(IdleRunAction.NOTIFY.name());
    LocalDateTime lastNotificationDate = mockAlreadyNotifiedRuns();
    Thread.sleep(10);
    resourceMonitoringManager.monitorResourceUsage();
    verify(pipelineRunManager).updatePipelineRunsLastNotification(runsToUpdateCaptor.capture());
    verify(notificationManager).notifyIdleRuns(runsToNotifyCaptor.capture(), eq(NotificationType.IDLE_RUN));
    List<PipelineRun> updatedRuns = runsToUpdateCaptor.getValue();
    Assert.assertEquals(2, updatedRuns.size());
    Assert.assertFalse(updatedRuns.stream().anyMatch(r -> r.getLastIdleNotificationTime().equals(lastNotificationDate)));
    List<Pair<PipelineRun, Double>> runsToNotify = runsToNotifyCaptor.getValue();
    Assert.assertEquals(2, runsToNotify.size());
}
Also used : LocalDateTime(java.time.LocalDateTime) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) Arrays(java.util.Arrays) InstanceType(com.epam.pipeline.entity.cluster.InstanceType) Mock(org.mockito.Mock) Date(java.util.Date) PipelineRunManager(com.epam.pipeline.manager.pipeline.PipelineRunManager) BehaviorSubject(io.reactivex.subjects.BehaviorSubject) LocalDateTime(java.time.LocalDateTime) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) HashMap(java.util.HashMap) IdleRunAction(com.epam.pipeline.entity.monitoring.IdleRunAction) Captor(org.mockito.Captor) MockitoAnnotations(org.mockito.MockitoAnnotations) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) ArgumentCaptor(org.mockito.ArgumentCaptor) MessageHelper(com.epam.pipeline.common.MessageHelper) Pair(org.apache.commons.lang3.tuple.Pair) Matchers.eq(org.mockito.Matchers.eq) Map(java.util.Map) NotificationType(com.epam.pipeline.entity.notification.NotificationSettings.NotificationType) Observable(io.reactivex.Observable) Before(org.junit.Before) DateUtils(com.epam.pipeline.entity.utils.DateUtils) InstanceOfferManager(com.epam.pipeline.manager.cluster.InstanceOfferManager) PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) TaskScheduler(org.springframework.scheduling.TaskScheduler) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Instant(java.time.Instant) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) List(java.util.List) Mockito.never(org.mockito.Mockito.never) ChronoUnit(java.time.temporal.ChronoUnit) Whitebox(org.mockito.internal.util.reflection.Whitebox) NotificationManager(com.epam.pipeline.manager.notification.NotificationManager) MonitoringESDao(com.epam.pipeline.dao.monitoring.MonitoringESDao) Assert(org.junit.Assert) Collections(java.util.Collections) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.Test)

Aggregations

MessageHelper (com.epam.pipeline.common.MessageHelper)2 MonitoringESDao (com.epam.pipeline.dao.monitoring.MonitoringESDao)2 InstanceType (com.epam.pipeline.entity.cluster.InstanceType)2 IdleRunAction (com.epam.pipeline.entity.monitoring.IdleRunAction)2 NotificationType (com.epam.pipeline.entity.notification.NotificationSettings.NotificationType)2 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)2 RunInstance (com.epam.pipeline.entity.pipeline.RunInstance)2 DateUtils (com.epam.pipeline.entity.utils.DateUtils)2 InstanceOfferManager (com.epam.pipeline.manager.cluster.InstanceOfferManager)2 NotificationManager (com.epam.pipeline.manager.notification.NotificationManager)2 PipelineRunManager (com.epam.pipeline.manager.pipeline.PipelineRunManager)2 PreferenceManager (com.epam.pipeline.manager.preference.PreferenceManager)2 SystemPreferences (com.epam.pipeline.manager.preference.SystemPreferences)2 Observable (io.reactivex.Observable)2 BehaviorSubject (io.reactivex.subjects.BehaviorSubject)2 Instant (java.time.Instant)2 LocalDateTime (java.time.LocalDateTime)2 ChronoUnit (java.time.temporal.ChronoUnit)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2