use of com.netflix.simianarmy.aws.AWSResource in project SimianArmy by Netflix.
the class TestOldDetachedVolumeRule method testOldDetachedVolumeBeforeDaylightSavingsCutover.
/** This test exists to check logic on a utility method.
* The tagging rule for resource expiry uses a variable nubmer of days.
* However, JodaTime date arithmetic for DAYS uses calendar days. It does NOT
* treat a day as 24 hours in this case (HOUR arithmetic, however, does).
* Therefore, a termination policy of 4 days (96 hours) will actually occur in
* 95 hours if the resource is tagged with that rule within 4 days of the DST
* cutover.
*
* We experienced test case failures around the 2014 spring DST cutover that
* prevented us from getting green builds. So, the assertion logic was loosened
* to check that we were within a day of the expected date. For the test case,
* all but 4 days of the year this problem never shows up. To verify that our
* fix was correct, this test case explicitly sets the date. The other tests
* that use a DateTime of "DateTime.now()" are not true unit tests, because the
* test does not isolate the date. They are actually a partial integration test,
* as they leave the date up to the system where the test executes.
*
* We have to mock the call to MonkeyCalendar.now() because the constructor
* for that class uses Calendar.getInstance() internally.
*
*/
@Test
public void testOldDetachedVolumeBeforeDaylightSavingsCutover() {
int ageThreshold = 5;
//here we set the create date to a few days before a known DST cutover, where
//we observed DST failures
DateTime closeToSpringAheadDst = new DateTime(2014, 3, 7, 0, 0, DateTimeZone.forID("America/Los_Angeles"));
Resource resource = new AWSResource().withId("vol-12345678901234567").withResourceType(AWSResourceType.EBS_VOLUME).withLaunchTime(new Date(closeToSpringAheadDst.minusDays(ageThreshold + 1).getMillis()));
((AWSResource) resource).setAWSResourceState("available");
Date lastDetachTime = new Date(closeToSpringAheadDst.minusDays(ageThreshold + 1).getMillis());
String metaTag = VolumeTaggingMonkey.makeMetaTag(null, null, lastDetachTime);
resource.setTag(JanitorMonkey.JANITOR_META_TAG, metaTag);
int retentionDays = 4;
//set the "now" to the fixed execution date for this rule and create a partial mock
Calendar fixed = Calendar.getInstance(TimeZone.getTimeZone("America/Los_Angeles"));
fixed.setTimeInMillis(closeToSpringAheadDst.getMillis());
MonkeyCalendar monkeyCalendar = new TestMonkeyCalendar();
MonkeyCalendar spyCalendar = spy(monkeyCalendar);
when(spyCalendar.now()).thenReturn(fixed);
//use the partial mock for the OldDetachedVolumeRule
OldDetachedVolumeRule rule = new OldDetachedVolumeRule(spyCalendar, ageThreshold, retentionDays);
//this volume should be seen as invalid
Assert.assertFalse(rule.isValid(resource));
//3.26.2014. Commenting out DST cutover verification. A line in
//OldDetachedVolumeRule.isValid actually creates a new date from the Tag value.
//while this unit test tries its best to use invariants, the tag does not contain timezone
//information, so a time set in the Los Angeles timezone and tagged, then parsed as
//UTC (if that's how the VM running the test is set) will fail.
/////////////////////////////
//Leaving the code in place to be uncommnented later if that class is refactored
//to support a design that promotes more complete testing.
//now verify that the difference between "now" and the cutoff is slightly under the intended
//retention limit, as the DST cutover makes us lose one hour
//verifyDSTCutoverHappened(resource, retentionDays, closeToSpringAheadDst);
/////////////////////////////
//now verify that our projected termination time is within one day of what was asked for
TestUtils.verifyTerminationTimeRough(resource, retentionDays, closeToSpringAheadDst);
}
use of com.netflix.simianarmy.aws.AWSResource in project SimianArmy by Netflix.
the class TestOldDetachedVolumeRule method testNoMetaTag.
@Test
public void testNoMetaTag() {
int ageThreshold = 5;
DateTime now = DateTime.now();
Resource resource = new AWSResource().withId("vol-12345678901234567").withResourceType(AWSResourceType.EBS_VOLUME).withLaunchTime(new Date(now.minusDays(ageThreshold + 1).getMillis()));
((AWSResource) resource).setAWSResourceState("available");
int retentionDays = 4;
OldDetachedVolumeRule rule = new OldDetachedVolumeRule(new TestMonkeyCalendar(), ageThreshold, retentionDays);
resource.setTag(JanitorMonkey.JANITOR_TAG, "donotmark");
Assert.assertTrue(rule.isValid(resource));
Assert.assertNull(resource.getExpectedTerminationTime());
}
use of com.netflix.simianarmy.aws.AWSResource in project SimianArmy by Netflix.
the class TestOldDetachedVolumeRule method testUserSpecifiedTerminationDate.
@Test
public void testUserSpecifiedTerminationDate() {
int ageThreshold = 5;
DateTime now = DateTime.now();
Resource resource = new AWSResource().withId("vol-12345678901234567").withResourceType(AWSResourceType.EBS_VOLUME).withLaunchTime(new Date(now.minusDays(ageThreshold + 1).getMillis()));
((AWSResource) resource).setAWSResourceState("available");
int retentionDays = 4;
DateTime userDate = new DateTime(now.plusDays(3).withTimeAtStartOfDay());
resource.setTag(JanitorMonkey.JANITOR_TAG, OldDetachedVolumeRule.TERMINATION_DATE_FORMATTER.print(userDate));
OldDetachedVolumeRule rule = new OldDetachedVolumeRule(new TestMonkeyCalendar(), ageThreshold, retentionDays);
Assert.assertFalse(rule.isValid(resource));
Assert.assertEquals(resource.getExpectedTerminationTime().getTime(), userDate.getMillis());
}
use of com.netflix.simianarmy.aws.AWSResource in project SimianArmy by Netflix.
the class AlwaysInvalidRule method testWithExclusionRuleMatch1.
@Test
void testWithExclusionRuleMatch1() {
Resource resource = new AWSResource().withId("id");
DateTime now = DateTime.now();
BasicJanitorRuleEngine engine = new BasicJanitorRuleEngine().addExclusionRule(new AlwaysValidRule()).addRule(new AlwaysInvalidRule(now, 1));
Assert.assertTrue(engine.isValid(resource));
}
use of com.netflix.simianarmy.aws.AWSResource in project SimianArmy by Netflix.
the class AlwaysInvalidRule method testEmptyRuleSet.
@Test
public void testEmptyRuleSet() {
Resource resource = new AWSResource().withId("id");
BasicJanitorRuleEngine engine = new BasicJanitorRuleEngine();
Assert.assertTrue(engine.isValid(resource));
}
Aggregations