Search in sources :

Example 11 with TimeAlert

use of com.sequenceiq.periscope.domain.TimeAlert in project cloudbreak by hortonworks.

the class DateUtilsTest method testIsTriggerWhenTheCurrentTimeEqualsWithTheNextTriggerThenItShouldTriggerAnEvent.

@Test
public void testIsTriggerWhenTheCurrentTimeEqualsWithTheNextTriggerThenItShouldTriggerAnEvent() {
    String timeZone = "America/New_York";
    ZoneId zoneId = ZoneId.of(timeZone);
    ZonedDateTime currentTime = ZonedDateTime.of(2017, 12, 20, 20, 0, 0, 0, ZoneId.systemDefault());
    ZonedDateTime currentZonedTime = ZonedDateTime.of(2017, 12, 20, 12, 0, 0, 0, zoneId);
    long monitorUpdateRate = 60000;
    when(dateTimeUtils.getDefaultZonedDateTime()).thenReturn(currentTime);
    when(dateTimeUtils.getZonedDateTime(currentTime.toInstant(), timeZone)).thenReturn(currentZonedTime);
    TimeAlert timeAlert = createTimeAlert("0 0 12 * * ?", timeZone);
    assertTrue(underTest.isTrigger(timeAlert, monitorUpdateRate));
}
Also used : ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) TimeAlert(com.sequenceiq.periscope.domain.TimeAlert) Test(org.junit.Test)

Example 12 with TimeAlert

use of com.sequenceiq.periscope.domain.TimeAlert in project cloudbreak by hortonworks.

the class DateUtilsTest method testIsTriggerWhenTheCurrentTimeEqualsWithTheNextTriggerAndZonesAreEquivalentThenItShouldTriggerAnEvent.

@Test
public void testIsTriggerWhenTheCurrentTimeEqualsWithTheNextTriggerAndZonesAreEquivalentThenItShouldTriggerAnEvent() {
    ZoneId zone = ZoneId.systemDefault();
    String timeZone = zone.getId();
    ZonedDateTime currentZonedTime = ZonedDateTime.of(2017, 12, 20, 12, 0, 0, 0, zone.normalized());
    long monitorUpdateRate = 60000;
    when(dateTimeUtils.getDefaultZonedDateTime()).thenReturn(currentZonedTime);
    when(dateTimeUtils.getZonedDateTime(currentZonedTime.toInstant(), timeZone)).thenReturn(currentZonedTime);
    TimeAlert timeAlert = createTimeAlert("0 0 12 * * ?", timeZone);
    assertTrue(underTest.isTrigger(timeAlert, monitorUpdateRate));
}
Also used : ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) TimeAlert(com.sequenceiq.periscope.domain.TimeAlert) Test(org.junit.Test)

Example 13 with TimeAlert

use of com.sequenceiq.periscope.domain.TimeAlert in project cloudbreak by hortonworks.

the class DateUtilsTest method testIsTriggerWhenTheCurrentTimeIsAfterTheNextTriggerWithSizeOfTheMonitorUpdateRateThenItShouldNotTriggerAnEvent.

@Test
public void testIsTriggerWhenTheCurrentTimeIsAfterTheNextTriggerWithSizeOfTheMonitorUpdateRateThenItShouldNotTriggerAnEvent() {
    String timeZone = "America/New_York";
    ZoneId zoneId = ZoneId.of(timeZone);
    ZonedDateTime currentZonedTime = ZonedDateTime.of(2017, 12, 20, 12, 0, 10, 0, zoneId);
    long monitorUpdateRate = 10000;
    when(dateTimeUtils.getDefaultZonedDateTime()).thenReturn(currentZonedTime);
    when(dateTimeUtils.getZonedDateTime(currentZonedTime.toInstant(), timeZone)).thenReturn(currentZonedTime);
    TimeAlert timeAlert = createTimeAlert("0 0 12 * * ?", timeZone);
    assertFalse(underTest.isTrigger(timeAlert, monitorUpdateRate));
}
Also used : ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) TimeAlert(com.sequenceiq.periscope.domain.TimeAlert) Test(org.junit.Test)

Example 14 with TimeAlert

use of com.sequenceiq.periscope.domain.TimeAlert in project cloudbreak by hortonworks.

the class DateUtilsTest method testIsTriggerWhenTheCurrentTimeIsBeforeTheNextTriggerMoreThanTheMonitorUpdateRateThenItShouldNotTriggerAnEvent.

@Test
public void testIsTriggerWhenTheCurrentTimeIsBeforeTheNextTriggerMoreThanTheMonitorUpdateRateThenItShouldNotTriggerAnEvent() {
    String timeZone = "America/Denver";
    ZoneId zoneId = ZoneId.of(timeZone);
    ZonedDateTime currentTime = ZonedDateTime.of(2017, 12, 19, 13, 15, 0, 0, zoneId);
    long monitorUpdateRate = 1000;
    when(dateTimeUtils.getDefaultZonedDateTime()).thenReturn(currentTime);
    when(dateTimeUtils.getZonedDateTime(currentTime.toInstant(), timeZone)).thenReturn(currentTime);
    TimeAlert timeAlert = createTimeAlert("0 0 12 * * ?", timeZone);
    assertFalse(underTest.isTrigger(timeAlert, monitorUpdateRate));
}
Also used : ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) TimeAlert(com.sequenceiq.periscope.domain.TimeAlert) Test(org.junit.Test)

Aggregations

TimeAlert (com.sequenceiq.periscope.domain.TimeAlert)14 ZoneId (java.time.ZoneId)7 ZonedDateTime (java.time.ZonedDateTime)7 Test (org.junit.Test)7 Cluster (com.sequenceiq.periscope.domain.Cluster)2 AutoscaleClusterRequest (com.sequenceiq.periscope.api.model.AutoscaleClusterRequest)1 MetricAlertRequest (com.sequenceiq.periscope.api.model.MetricAlertRequest)1 PrometheusAlertRequest (com.sequenceiq.periscope.api.model.PrometheusAlertRequest)1 ScalingConfigurationRequest (com.sequenceiq.periscope.api.model.ScalingConfigurationRequest)1 TimeAlertRequest (com.sequenceiq.periscope.api.model.TimeAlertRequest)1 MetricAlert (com.sequenceiq.periscope.domain.MetricAlert)1 PrometheusAlert (com.sequenceiq.periscope.domain.PrometheusAlert)1 ScalingEvent (com.sequenceiq.periscope.monitor.event.ScalingEvent)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Component (org.springframework.stereotype.Component)1