Search in sources :

Example 1 with FeedOnTimeArrivalMetric

use of com.thinkbiganalytics.metadata.sla.api.core.FeedOnTimeArrivalMetric in project kylo by Teradata.

the class FeedOnTimeArrivalMetricAssessorTest method testFailure.

@Test
public void testFailure() throws ParseException {
    PowerMockito.mockStatic(DateTime.class);
    PowerMockito.mockStatic(CronExpressionUtil.class);
    DateTime now = new DateTime().minusHours(2);
    // Some Cron Expression .. Mockito will overwrite
    CronExpression cron = new CronExpression("0 0 0/2 1/1 * ? *");
    // set the current time to a known time
    BDDMockito.given(DateTime.now()).willReturn(now);
    // set the previous fire date to a known time in the past
    DateTime previousFireTime = new DateTime(now).minusHours(4);
    BDDMockito.given(CronExpressionUtil.getPreviousFireTime(cron)).willReturn(previousFireTime.toDate());
    // window is = (now - 4)  - (now -4) + lateTimeGracePeriod)
    // Some Feed End Time to a time outside the window
    DateTime lastFeedTime = new DateTime(previousFireTime).minusHours(lateTimeGracePeriod + 1);
    when(this.feedProvider.getLastActiveTimeStamp("feed")).thenReturn(lastFeedTime);
    this.metric = new FeedOnTimeArrivalMetric("feed", cron, Period.hours(lateTimeGracePeriod));
    this.assessor.assess(metric, this.builder);
    // assert values
    verify(this.builder.result(AssessmentResult.FAILURE));
}
Also used : CronExpression(org.quartz.CronExpression) FeedOnTimeArrivalMetric(com.thinkbiganalytics.metadata.sla.api.core.FeedOnTimeArrivalMetric) DateTime(org.joda.time.DateTime) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with FeedOnTimeArrivalMetric

use of com.thinkbiganalytics.metadata.sla.api.core.FeedOnTimeArrivalMetric in project kylo by Teradata.

the class FeedOnTimeArrivalMetricAssessorTest method testSuccess.

@Test
public void testSuccess() throws ParseException {
    PowerMockito.mockStatic(DateTime.class);
    PowerMockito.mockStatic(CronExpressionUtil.class);
    DateTime now = new DateTime().minusHours(2);
    // set the current time to a known time
    BDDMockito.given(DateTime.now()).willReturn(now);
    // set the previous fire date to a known time in the past,but within the window
    DateTime previousFireTime = new DateTime(now).minusHours(3);
    // Some Cron Expression .. Mockito will overwrite
    CronExpression cron = new CronExpression("0 0 0/2 1/1 * ? *");
    BDDMockito.given(CronExpressionUtil.getPreviousFireTime(cron)).willReturn(previousFireTime.toDate());
    // window is = (now - 3)  - (now -3) + lateTime)
    // Some Feed End Time to a time within this window
    DateTime lastFeedTime = new DateTime(previousFireTime).plus(lateTimeGracePeriod - 1);
    when(this.feedProvider.getLastActiveTimeStamp("feed")).thenReturn(lastFeedTime);
    this.metric = new FeedOnTimeArrivalMetric("feed", cron, Period.hours(lateTimeGracePeriod));
    this.assessor.assess(metric, this.builder);
    // assert values
    DateTime lateTime = previousFireTime.plusHours(lateTimeGracePeriod);
    Assert.assertTrue((lastFeedTime.isAfter(previousFireTime) && lastFeedTime.isBefore(lateTime)));
    verify(this.builder.result(AssessmentResult.SUCCESS));
}
Also used : CronExpression(org.quartz.CronExpression) FeedOnTimeArrivalMetric(com.thinkbiganalytics.metadata.sla.api.core.FeedOnTimeArrivalMetric) DateTime(org.joda.time.DateTime) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with FeedOnTimeArrivalMetric

use of com.thinkbiganalytics.metadata.sla.api.core.FeedOnTimeArrivalMetric in project kylo by Teradata.

the class TestServiceLevelAgreementMetricPolicyTransform method testFeedExecutedSinceFeed.

@Test
public void testFeedExecutedSinceFeed() throws IOException, ParseException {
    String feedName = "category.feed";
    String cronString = "0 0 12 1/1 * ? *";
    Integer lateTime = 5;
    String lateUnits = "days";
    Integer asOfTime = 3;
    String asOfUnits = "hours";
    FeedOnTimeArrivalMetric metric = new FeedOnTimeArrivalMetric(feedName, cronString, lateTime, lateUnits);
    ServiceLevelAgreementRule uiModel = ServiceLevelAgreementMetricTransformer.instance().toUIModel(metric);
    FeedOnTimeArrivalMetric convertedPolicy = fromUI(uiModel, FeedOnTimeArrivalMetric.class);
    Assert.assertEquals(cronString, convertedPolicy.getExpectedExpression().getCronExpression());
    Assert.assertEquals(Period.days(5).toString(), convertedPolicy.getLatePeriod().toString());
}
Also used : FeedOnTimeArrivalMetric(com.thinkbiganalytics.metadata.sla.api.core.FeedOnTimeArrivalMetric) Test(org.junit.Test)

Example 4 with FeedOnTimeArrivalMetric

use of com.thinkbiganalytics.metadata.sla.api.core.FeedOnTimeArrivalMetric in project kylo by Teradata.

the class TestServiceLevelAgreementMetricPolicyTransform method testUiCreation.

@Test
public void testUiCreation() {
    List<ServiceLevelAgreementRule> rules = serviceLevelAgreementMetrics.discoverSlaMetrics();
    ServiceLevelAgreementRule rule = Iterables.tryFind(rules, new Predicate<ServiceLevelAgreementRule>() {

        @Override
        public boolean apply(ServiceLevelAgreementRule rule) {
            return rule.getName().equalsIgnoreCase("Feed Processing deadline");
        }
    }).orNull();
    rule.getProperty("FeedName").setValue("currentCategory.currentFeed");
    rule.getProperty("ExpectedDeliveryTime").setValue("0 0 12 1/1 * ? *");
    rule.getProperty("NoLaterThanTime").setValue("5");
    rule.getProperty("NoLaterThanUnits").setValue("days");
    FeedOnTimeArrivalMetric convertedPolicy = fromUI(rule, FeedOnTimeArrivalMetric.class);
    Assert.assertEquals("currentCategory.currentFeed", convertedPolicy.getFeedName());
    Assert.assertEquals("0 0 12 1/1 * ? *", convertedPolicy.getExpectedExpression().getCronExpression());
}
Also used : FeedOnTimeArrivalMetric(com.thinkbiganalytics.metadata.sla.api.core.FeedOnTimeArrivalMetric) Predicate(com.google.common.base.Predicate) Test(org.junit.Test)

Example 5 with FeedOnTimeArrivalMetric

use of com.thinkbiganalytics.metadata.sla.api.core.FeedOnTimeArrivalMetric in project kylo by Teradata.

the class FeedOnTimeArrivalMetricAssessorTest method testNoDataButStillBeforeLateTime.

@Test
public /**
 * test use case where the date window is still valid, but still no data has been found for the Feed.
 * This will return no Assessment result as it still could process data
 */
void testNoDataButStillBeforeLateTime() throws ParseException {
    PowerMockito.mockStatic(DateTime.class);
    PowerMockito.mockStatic(CronExpressionUtil.class);
    DateTime now = new DateTime().minusHours(2);
    // Some Cron Expression .. Mockito will overwrite
    CronExpression cron = new CronExpression("0 0 0/2 1/1 * ? *");
    // set the current time to a known time
    BDDMockito.given(DateTime.now()).willReturn(now);
    // set the previous fire date to a known time in the past,but within the window
    DateTime previousFireTime = new DateTime(now).minusHours(3);
    BDDMockito.given(CronExpressionUtil.getPreviousFireTime(cron)).willReturn(previousFireTime.toDate());
    // window is = (now - 3)  - (now -3) + lateTime)
    // Some Feed End Time to a time not within this window
    DateTime lastFeedTime = new DateTime().minusWeeks(2);
    when(this.feedProvider.getLastActiveTimeStamp("feed")).thenReturn(lastFeedTime);
    this.metric = new FeedOnTimeArrivalMetric("feed", cron, Period.hours(lateTimeGracePeriod));
    this.assessor.assess(metric, this.builder);
    // assert values
    DateTime lateTime = previousFireTime.plusHours(lateTimeGracePeriod);
    Assert.assertTrue(now.isBefore(lateTime) && !(lastFeedTime.isAfter(previousFireTime) && lastFeedTime.isBefore(lateTime)));
    verify(this.builder);
}
Also used : CronExpression(org.quartz.CronExpression) FeedOnTimeArrivalMetric(com.thinkbiganalytics.metadata.sla.api.core.FeedOnTimeArrivalMetric) DateTime(org.joda.time.DateTime) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

FeedOnTimeArrivalMetric (com.thinkbiganalytics.metadata.sla.api.core.FeedOnTimeArrivalMetric)6 Test (org.junit.Test)5 DateTime (org.joda.time.DateTime)4 CronExpression (org.quartz.CronExpression)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Predicate (com.google.common.base.Predicate)1 AssessmentResult (com.thinkbiganalytics.metadata.sla.api.AssessmentResult)1 Metric (com.thinkbiganalytics.metadata.sla.api.Metric)1 Before (org.junit.Before)1