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));
}
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);
}
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);
}
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);
}
Aggregations