Search in sources :

Example 76 with TestMonkeyCalendar

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

the class TestOrphanedELBRule method testMissingReferencedASGCountCheck.

@Test
public void testMissingReferencedASGCountCheck() {
    DateTime now = DateTime.now();
    Resource resource = new AWSResource().withId("test-elb").withResourceType(AWSResourceType.ELB).withOwnerEmail("owner@foo.com");
    resource.setAdditionalField("instanceCount", "0");
    OrphanedELBRule rule = new OrphanedELBRule(new TestMonkeyCalendar(), 7);
    Assert.assertTrue(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) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 77 with TestMonkeyCalendar

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

the class TestJanitorContext method testJanitorWithCleanupFailure.

@Test
public static void testJanitorWithCleanupFailure() {
    Collection<Resource> crawledResources = new ArrayList<Resource>();
    int n = 20;
    for (Resource r : generateTestingResources(n)) {
        crawledResources.add(r);
    }
    TestJanitorCrawler crawler = new TestJanitorCrawler(crawledResources);
    TestAbstractJanitor janitor = new TestAbstractJanitor(new TestJanitorContext(TEST_REGION, new BasicJanitorRuleEngine().addRule(new IsEvenRule()), crawler, new TestJanitorResourceTracker(new HashMap<String, Resource>()), new TestMonkeyCalendar()), TestResourceType.TEST_RESOURCE_TYPE);
    janitor.setLeashed(false);
    Assert.assertEquals(crawler.resources(TestResourceType.TEST_RESOURCE_TYPE).size(), n);
    janitor.markResources();
    Assert.assertEquals(janitor.getMarkedResources().size(), n / 2);
    janitor.cleanupResources();
    Assert.assertEquals(janitor.getCleanedResources().size(), n / 2 - 1);
    Assert.assertEquals(janitor.getFailedToCleanResources().size(), 1);
    Assert.assertEquals(janitor.getResourcesCleanedCount(), janitor.cleanedResourceIds.size());
    Assert.assertEquals(janitor.getMarkedResourcesCount(), janitor.markedResourceIds.size());
    Assert.assertEquals(janitor.getFailedToCleanResourcesCount(), 1);
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) BasicJanitorRuleEngine(com.netflix.simianarmy.basic.janitor.BasicJanitorRuleEngine) Test(org.testng.annotations.Test)

Example 78 with TestMonkeyCalendar

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

the class TestJanitorContext method testJanitor.

@Test
public static void testJanitor() {
    Collection<Resource> crawledResources = new ArrayList<Resource>();
    int n = 10;
    for (Resource r : generateTestingResources(n)) {
        crawledResources.add(r);
    }
    TestJanitorCrawler crawler = new TestJanitorCrawler(crawledResources);
    TestJanitorResourceTracker resourceTracker = new TestJanitorResourceTracker(new HashMap<String, Resource>());
    TestAbstractJanitor janitor = new TestAbstractJanitor(new TestJanitorContext(TEST_REGION, new BasicJanitorRuleEngine().addRule(new IsEvenRule()), crawler, resourceTracker, new TestMonkeyCalendar()), TestResourceType.TEST_RESOURCE_TYPE);
    janitor.setLeashed(false);
    Assert.assertEquals(crawler.resources(TestResourceType.TEST_RESOURCE_TYPE).size(), n);
    Assert.assertEquals(janitor.markedResourceIds.size(), 0);
    janitor.markResources();
    Assert.assertEquals(janitor.getMarkedResources().size(), n / 2);
    Assert.assertEquals(janitor.markedResourceIds.size(), n / 2);
    for (int i = 1; i <= n; i += 2) {
        Assert.assertTrue(janitor.markedResourceIds.contains(String.valueOf(i)));
    }
    Assert.assertEquals(janitor.cleanedResourceIds.size(), 0);
    janitor.cleanupResources();
    Assert.assertEquals(janitor.getCleanedResources().size(), n / 2);
    Assert.assertEquals(janitor.getFailedToCleanResources().size(), 0);
    Assert.assertEquals(resourceTracker.getResources(TestResourceType.TEST_RESOURCE_TYPE, CleanupState.JANITOR_TERMINATED, TEST_REGION).size(), n / 2);
    Assert.assertEquals(janitor.cleanedResourceIds.size(), n / 2);
    for (int i = 1; i <= n; i += 2) {
        Assert.assertTrue(janitor.cleanedResourceIds.contains(String.valueOf(i)));
    }
    Assert.assertEquals(janitor.getResourcesCleanedCount(), janitor.cleanedResourceIds.size());
    Assert.assertEquals(janitor.getMarkedResourcesCount(), janitor.markedResourceIds.size());
    Assert.assertEquals(janitor.getFailedToCleanResourcesCount(), 0);
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) BasicJanitorRuleEngine(com.netflix.simianarmy.basic.janitor.BasicJanitorRuleEngine) Test(org.testng.annotations.Test)

Example 79 with TestMonkeyCalendar

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

the class TestJanitorContext method testJanitorWithoutHoldingOffCleanup.

@Test
public static void testJanitorWithoutHoldingOffCleanup() {
    Collection<Resource> crawledResources = new ArrayList<Resource>();
    int n = 10;
    for (Resource r : generateTestingResources(n)) {
        crawledResources.add(r);
    }
    TestJanitorCrawler crawler = new TestJanitorCrawler(crawledResources);
    TestJanitorResourceTracker resourceTracker = new TestJanitorResourceTracker(new HashMap<String, Resource>());
    DateTime now = DateTime.now();
    TestAbstractJanitor janitor = new TestAbstractJanitor(new TestJanitorContext(TEST_REGION, new BasicJanitorRuleEngine().addRule(new ImmediateCleanupRule(now)), crawler, resourceTracker, new TestMonkeyCalendar()), TestResourceType.TEST_RESOURCE_TYPE);
    janitor.setLeashed(false);
    Assert.assertEquals(crawler.resources(TestResourceType.TEST_RESOURCE_TYPE).size(), n);
    Assert.assertEquals(janitor.markedResourceIds.size(), 0);
    janitor.markResources();
    Assert.assertEquals(janitor.getMarkedResources().size(), n);
    Assert.assertEquals(janitor.markedResourceIds.size(), n);
    for (int i = 1; i <= n; i++) {
        Assert.assertTrue(janitor.markedResourceIds.contains(String.valueOf(i)));
    }
    Assert.assertEquals(janitor.cleanedResourceIds.size(), 0);
    janitor.cleanupResources();
    // No resource is cleaned since the notification is later than expected termination time.
    Assert.assertEquals(janitor.getCleanedResources().size(), n);
    Assert.assertEquals(janitor.getFailedToCleanResources().size(), 0);
    Assert.assertEquals(resourceTracker.getResources(TestResourceType.TEST_RESOURCE_TYPE, CleanupState.JANITOR_TERMINATED, TEST_REGION).size(), n);
    Assert.assertEquals(janitor.cleanedResourceIds.size(), n);
    Assert.assertEquals(janitor.getResourcesCleanedCount(), janitor.cleanedResourceIds.size());
    Assert.assertEquals(janitor.getMarkedResourcesCount(), janitor.markedResourceIds.size());
    Assert.assertEquals(janitor.getFailedToCleanResourcesCount(), 0);
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) DateTime(org.joda.time.DateTime) TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) BasicJanitorRuleEngine(com.netflix.simianarmy.basic.janitor.BasicJanitorRuleEngine) 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