Search in sources :

Example 6 with TestMonkeyCalendar

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

the class TestOldEmptyASGRule method testASGWithoutInstanceAndNonZeroSize.

@Test
public void testASGWithoutInstanceAndNonZeroSize() {
    Resource resource = new AWSResource().withId("asg1").withResourceType(AWSResourceType.ASG);
    resource.setAdditionalField(ASGJanitorCrawler.ASG_FIELD_LC_NAME, "launchConfig");
    resource.setAdditionalField(ASGJanitorCrawler.ASG_FIELD_MAX_SIZE, "2");
    int launchConfiguAgeThreshold = 60;
    MonkeyCalendar calendar = new TestMonkeyCalendar();
    DateTime now = new DateTime(calendar.now().getTimeInMillis());
    resource.setAdditionalField(ASGJanitorCrawler.ASG_FIELD_LC_CREATION_TIME, String.valueOf(now.minusDays(launchConfiguAgeThreshold + 1).getMillis()));
    int retentionDays = 3;
    OldEmptyASGRule rule = new OldEmptyASGRule(calendar, launchConfiguAgeThreshold, retentionDays, new DummyASGInstanceValidator());
    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) Test(org.testng.annotations.Test)

Example 7 with TestMonkeyCalendar

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

the class TestSuspendedASGRule method testASGWithInstances.

@Test
public void testASGWithInstances() {
    Resource resource = new AWSResource().withId("asg1").withResourceType(AWSResourceType.ASG);
    resource.setAdditionalField(ASGJanitorCrawler.ASG_FIELD_MAX_SIZE, "2");
    resource.setAdditionalField(ASGJanitorCrawler.ASG_FIELD_INSTANCES, "123456789012345671,i-123456789012345672");
    int suspensionAgeThreshold = 2;
    MonkeyCalendar calendar = new TestMonkeyCalendar();
    DateTime now = new DateTime(calendar.now().getTimeInMillis());
    DateTime suspensionTime = now.minusDays(suspensionAgeThreshold + 1);
    resource.setAdditionalField(ASGJanitorCrawler.ASG_FIELD_SUSPENSION_TIME, ASGJanitorCrawler.SUSPENSION_TIME_FORMATTER.print(suspensionTime));
    int retentionDays = 3;
    SuspendedASGRule rule = new SuspendedASGRule(calendar, suspensionAgeThreshold, retentionDays, new DummyASGInstanceValidator());
    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) Test(org.testng.annotations.Test)

Example 8 with TestMonkeyCalendar

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

the class TestSuspendedASGRule method testSuspensionTimeIncorrectFormat.

@Test(expectedExceptions = IllegalArgumentException.class)
public void testSuspensionTimeIncorrectFormat() {
    Resource resource = new AWSResource().withId("asg1").withResourceType(AWSResourceType.ASG);
    resource.setAdditionalField(ASGJanitorCrawler.ASG_FIELD_MAX_SIZE, "0");
    MonkeyCalendar calendar = new TestMonkeyCalendar();
    int suspensionAgeThreshold = 2;
    resource.setAdditionalField(ASGJanitorCrawler.ASG_FIELD_SUSPENSION_TIME, "foo");
    int retentionDays = 3;
    SuspendedASGRule rule = new SuspendedASGRule(calendar, suspensionAgeThreshold, retentionDays, new DummyASGInstanceValidator());
    Assert.assertFalse(rule.isValid(resource));
}
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 9 with TestMonkeyCalendar

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

the class TestSuspendedASGRule method testNonASGResource.

@Test
public void testNonASGResource() {
    Resource resource = new AWSResource().withId("i-12345678901234567").withResourceType(AWSResourceType.INSTANCE);
    SuspendedASGRule rule = new SuspendedASGRule(new TestMonkeyCalendar(), 3, 2, new DummyASGInstanceValidator());
    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) Test(org.testng.annotations.Test)

Example 10 with TestMonkeyCalendar

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

the class TestSuspendedASGRule method testEmptyASGSuspendedMoreThanThreshold.

@Test
public void testEmptyASGSuspendedMoreThanThreshold() {
    Resource resource = new AWSResource().withId("asg1").withResourceType(AWSResourceType.ASG);
    resource.setAdditionalField(ASGJanitorCrawler.ASG_FIELD_MAX_SIZE, "0");
    MonkeyCalendar calendar = new TestMonkeyCalendar();
    DateTime now = new DateTime(calendar.now().getTimeInMillis());
    int suspensionAgeThreshold = 2;
    DateTime suspensionTime = now.minusDays(suspensionAgeThreshold + 1);
    resource.setAdditionalField(ASGJanitorCrawler.ASG_FIELD_SUSPENSION_TIME, ASGJanitorCrawler.SUSPENSION_TIME_FORMATTER.print(suspensionTime));
    int retentionDays = 3;
    SuspendedASGRule rule = new SuspendedASGRule(calendar, suspensionAgeThreshold, retentionDays, new DummyASGInstanceValidator());
    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) 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