Search in sources :

Example 26 with TestMonkeyCalendar

use of com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar in project SimianArmy by Netflix.

the class TestOldUnusedLaunchConfigRule method testOldUnsedLaunchConfig.

@Test
public void testOldUnsedLaunchConfig() {
    Resource resource = new AWSResource().withId("launchConfig1").withResourceType(AWSResourceType.LAUNCH_CONFIG);
    resource.setAdditionalField(LaunchConfigJanitorCrawler.LAUNCH_CONFIG_FIELD_USED_BY_ASG, "false");
    MonkeyCalendar calendar = new TestMonkeyCalendar();
    int ageThreshold = 3;
    DateTime now = new DateTime(calendar.now().getTimeInMillis());
    resource.setLaunchTime(new Date(now.minusDays(ageThreshold + 1).getMillis()));
    int retentionDays = 3;
    OldUnusedLaunchConfigRule rule = new OldUnusedLaunchConfigRule(calendar, ageThreshold, retentionDays);
    Assert.assertFalse(rule.isValid(resource));
    TestUtils.verifyTerminationTimeRough(resource, retentionDays, now);
}
Also used : TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) MonkeyCalendar(com.netflix.simianarmy.MonkeyCalendar) DateTime(org.joda.time.DateTime) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 27 with TestMonkeyCalendar

use of com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar in project SimianArmy by Netflix.

the class TestOldUnusedLaunchConfigRule method testUnsedLaunchConfigNotOld.

@Test
public void testUnsedLaunchConfigNotOld() {
    Resource resource = new AWSResource().withId("launchConfig1").withResourceType(AWSResourceType.LAUNCH_CONFIG);
    resource.setAdditionalField(LaunchConfigJanitorCrawler.LAUNCH_CONFIG_FIELD_USED_BY_ASG, "false");
    MonkeyCalendar calendar = new TestMonkeyCalendar();
    int ageThreshold = 3;
    DateTime now = new DateTime(calendar.now().getTimeInMillis());
    resource.setLaunchTime(new Date(now.minusDays(ageThreshold - 1).getMillis()));
    int retentionDays = 3;
    OldUnusedLaunchConfigRule rule = new OldUnusedLaunchConfigRule(calendar, ageThreshold, retentionDays);
    Assert.assertTrue(rule.isValid(resource));
    Assert.assertNull(resource.getExpectedTerminationTime());
}
Also used : TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) MonkeyCalendar(com.netflix.simianarmy.MonkeyCalendar) DateTime(org.joda.time.DateTime) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 28 with TestMonkeyCalendar

use of com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar in project SimianArmy by Netflix.

the class TestOldUnusedLaunchConfigRule method testUsedLaunchConfigNoLaunchTimeSet.

@Test
public void testUsedLaunchConfigNoLaunchTimeSet() {
    Resource resource = new AWSResource().withId("launchConfig1").withResourceType(AWSResourceType.LAUNCH_CONFIG);
    resource.setAdditionalField(LaunchConfigJanitorCrawler.LAUNCH_CONFIG_FIELD_USED_BY_ASG, "true");
    MonkeyCalendar calendar = new TestMonkeyCalendar();
    int ageThreshold = 3;
    int retentionDays = 3;
    OldUnusedLaunchConfigRule rule = new OldUnusedLaunchConfigRule(calendar, ageThreshold, retentionDays);
    Assert.assertTrue(rule.isValid(resource));
    Assert.assertNull(resource.getExpectedTerminationTime());
}
Also used : TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) MonkeyCalendar(com.netflix.simianarmy.MonkeyCalendar) Test(org.testng.annotations.Test)

Example 29 with TestMonkeyCalendar

use of com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar in project SimianArmy by Netflix.

the class TestOldUnusedLaunchConfigRule method testNullResource.

@Test(expectedExceptions = IllegalArgumentException.class)
public void testNullResource() {
    OldUnusedLaunchConfigRule rule = new OldUnusedLaunchConfigRule(new TestMonkeyCalendar(), 3, 3);
    rule.isValid(null);
}
Also used : TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) Test(org.testng.annotations.Test)

Example 30 with TestMonkeyCalendar

use of com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar in project SimianArmy by Netflix.

the class TestNoGeneratedAMIRule method testResourceWithExpectedTerminationTimeSet.

@Test
public void testResourceWithExpectedTerminationTimeSet() {
    int ageThreshold = 5;
    DateTime now = DateTime.now();
    Resource resource = new AWSResource().withId("snap-12345678901234567").withResourceType(AWSResourceType.EBS_SNAPSHOT).withLaunchTime(new Date(now.minusDays(ageThreshold + 1).getMillis()));
    ((AWSResource) resource).setAWSResourceState("completed");
    Date oldTermDate = new Date(now.plusDays(10).getMillis());
    String oldTermReason = "Foo";
    int retentionDays = 4;
    NoGeneratedAMIRule rule = new NoGeneratedAMIRule(new TestMonkeyCalendar(), ageThreshold, retentionDays);
    resource.setExpectedTerminationTime(oldTermDate);
    resource.setTerminationReason(oldTermReason);
    Assert.assertFalse(rule.isValid(resource));
    Assert.assertEquals(oldTermDate, resource.getExpectedTerminationTime());
    Assert.assertEquals(oldTermReason, resource.getTerminationReason());
}
Also used : TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) DateTime(org.joda.time.DateTime) Date(java.util.Date) Test(org.testng.annotations.Test)

Aggregations

TestMonkeyCalendar (com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar)79 Test (org.testng.annotations.Test)79 AWSResource (com.netflix.simianarmy.aws.AWSResource)73 Resource (com.netflix.simianarmy.Resource)64 DateTime (org.joda.time.DateTime)51 Date (java.util.Date)28 MonkeyCalendar (com.netflix.simianarmy.MonkeyCalendar)21 BasicJanitorRuleEngine (com.netflix.simianarmy.basic.janitor.BasicJanitorRuleEngine)9 HashSet (java.util.HashSet)5 Calendar (java.util.Calendar)1