Package com.netflix.simianarmy

Examples of com.netflix.simianarmy.Resource


    /** Make sure the getFieldToValue returns the right field and values.
     * @throws Exception **/
    @Test
    public void testFieldToValueMapWithoutNullForInstance() throws Exception {
        Date now = new Date();
        Resource resource = getTestingResource(now);

        Map<String, String> resourceFieldValueMap = resource.getFieldToValueMap();

        verifyMapsAreEqual(resourceFieldValueMap,
                getTestingFieldValueMap(now, getTestingFields()));
    }
View Full Code Here


    /**
     * When all fields are null, the map returned is empty.
     */
    @Test
    public void testFieldToValueMapWithNull() {
        Resource resource = new AWSResource();
        Map<String, String> resourceFieldValueMap = resource.getFieldToValueMap();
        // The only value in the map is the boolean of opt out
        Assert.assertEquals(resourceFieldValueMap.size(), 1);
    }
View Full Code Here

    }

    @Test
    public void testClone() {
        Date now = new Date();
        Resource resource = getTestingResource(now);
        Resource clone = resource.cloneResource();
        verifyMapsAreEqual(clone.getFieldToValueMap(), resource.getFieldToValueMap());
        verifyTagsAreEqual(clone, resource);
    }
View Full Code Here

        return fieldToValue;
    }

    private Resource getTestingResource(Date now) {
        String id = "resourceId";
        Resource resource = new AWSResource().withId(id).withRegion("region").withResourceType(AWSResourceType.INSTANCE)
                .withState(Resource.CleanupState.MARKED).withDescription("description")
                .withExpectedTerminationTime(now).withActualTerminationTime(now)
                .withLaunchTime(now).withMarkTime(now).withNnotificationTime(now).withOwnerEmail("ownerEmail")
                .withTerminationReason("terminationReason").withOptOutOfJanitor(false);
        ((AWSResource) resource).setAWSResourceState("awsResourceState");

        for (Map.Entry<String, String> field : getTestingFields().entrySet()) {
            resource.setAdditionalField(field.getKey(), field.getValue());
        }

        for (int i = 1; i < 10; i++) {
            resource.setTag("tagKey_" + i, "tagValue_" + i);
        }

        return resource;
    }
View Full Code Here

public class TestBasicJanitorRuleEngine {

    @Test
    public void testEmptyRuleSet() {
        Resource resource = new AWSResource().withId("id");
        BasicJanitorRuleEngine engine = new BasicJanitorRuleEngine();
        Assert.assertTrue(engine.isValid(resource));
    }
View Full Code Here

        Assert.assertTrue(engine.isValid(resource));
    }

    @Test
    public void testAllValid() {
        Resource resource = new AWSResource().withId("id");
        BasicJanitorRuleEngine engine = new BasicJanitorRuleEngine()
        .addRule(new AlwaysValidRule())
        .addRule(new AlwaysValidRule())
        .addRule(new AlwaysValidRule());
        Assert.assertTrue(engine.isValid(resource));
View Full Code Here

        Assert.assertTrue(engine.isValid(resource));
    }

    @Test
    public void testMixed() {
        Resource resource = new AWSResource().withId("id");
        DateTime now = DateTime.now();
        BasicJanitorRuleEngine engine = new BasicJanitorRuleEngine()
        .addRule(new AlwaysValidRule())
        .addRule(new AlwaysInvalidRule(now, 1))
        .addRule(new AlwaysValidRule());
View Full Code Here

    @Test
    public void testIsValidWithNearestTerminationTime() {
        int[][] permutaions = {{1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 1, 2}, {3, 2, 1}};

        for (int[] perm : permutaions) {
            Resource resource = new AWSResource().withId("id");
            DateTime now = DateTime.now();
            BasicJanitorRuleEngine engine = new BasicJanitorRuleEngine()
            .addRule(new AlwaysInvalidRule(now, perm[0]))
            .addRule(new AlwaysInvalidRule(now, perm[1]))
            .addRule(new AlwaysInvalidRule(now, perm[2]));
            Assert.assertFalse(engine.isValid(resource));
            Assert.assertEquals(
                    resource.getExpectedTerminationTime().getTime(),
                    now.plusDays(1).getMillis());
            Assert.assertEquals(resource.getTerminationReason(), "1");
        }
    }
View Full Code Here


public class TestSuspendedASGRule {
    @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));
View Full Code Here

        TestUtils.verifyTerminationTimeRough(resource, retentionDays, now);
    }

    @Test
    public void testEmptyASGSuspendedLessThanThreshold() {
        Resource resource = new AWSResource().withId("asg1").withResourceType(AWSResourceType.ASG);
        resource.setAdditionalField(ASGJanitorCrawler.ASG_FIELD_LC_NAME, "launchConfig");
        resource.setAdditionalField(ASGJanitorCrawler.ASG_FIELD_MAX_SIZE, "0");
        int suspensionAgeThreshold = 2;
        MonkeyCalendar calendar = new TestMonkeyCalendar();
        DateTime now = new DateTime(calendar.now().getTimeInMillis());
        resource.setAdditionalField(ASGJanitorCrawler.ASG_FIELD_LC_CREATION_TIME,
                String.valueOf(now.minusDays(suspensionAgeThreshold + 1).getMillis()));
        int retentionDays = 3;
        SuspendedASGRule rule = new SuspendedASGRule(calendar, suspensionAgeThreshold, retentionDays,
                new DummyASGInstanceValidator());
        Assert.assertTrue(rule.isValid(resource));
        Assert.assertNull(resource.getExpectedTerminationTime());
    }
View Full Code Here

TOP

Related Classes of com.netflix.simianarmy.Resource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.