Skip to content

Commit

Permalink
Validate the resource's availability state before and during a mainte…
Browse files Browse the repository at this point in the history
…nance window
  • Loading branch information
pnguyen committed Dec 24, 2009
1 parent 16a30b5 commit 80726f6
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/org/hyperic/hq/hqapi1/test/MaintenanceSchedule_test.java
Expand Up @@ -32,6 +32,8 @@
import org.hyperic.hq.hqapi1.MaintenanceApi;
import org.hyperic.hq.hqapi1.types.Alert;
import org.hyperic.hq.hqapi1.types.AlertDefinition;
import org.hyperic.hq.hqapi1.types.DataPoint;
import org.hyperic.hq.hqapi1.types.LastMetricDataResponse;
import org.hyperic.hq.hqapi1.types.MaintenanceEvent;
import org.hyperic.hq.hqapi1.types.MaintenanceResponse;
import org.hyperic.hq.hqapi1.types.MaintenanceState;
Expand Down Expand Up @@ -133,15 +135,20 @@ public void testFireAlertsBeforeSchedulingCompatibleGroup()

// insert a fake 'up' measurement so that
// the alert definitions will fire.
final double AVAIL_UP = 1;
long alertStart = System.currentTimeMillis();
Alert alertFireOnce = fireAvailabilityAlert(alertDefFireOnce, true, 1);
Alert alertFireEveryTime = fireAvailabilityAlert(alertDefFireEveryTime, false, 1);
Alert alertFireOnce = fireAvailabilityAlert(alertDefFireOnce, true, AVAIL_UP);
Alert alertFireEveryTime = fireAvailabilityAlert(alertDefFireEveryTime, false, AVAIL_UP);

// check that availability measurement is enabled before the maintenance
Metric availMetric = findAvailabilityMetric(resource);
assertTrue("Availability measurement is not enabled for " + resource.getName(),
availMetric.isEnabled());

// check that the resource's availability is UP before the maintenance
DataPoint lastAvail = getLastAvailability(availMetric);
assertEquals(AVAIL_UP, lastAvail.getValue());

// schedule maintenance
long maintStart = System.currentTimeMillis() + 5*SECOND;
long maintEnd = maintStart + MINUTE;
Expand All @@ -164,6 +171,12 @@ public void testFireAlertsBeforeSchedulingCompatibleGroup()
assertFalse("Availability measurement is enabled for " + resource.getName(),
availMetric.isEnabled());

// check that the resource's availability is in a PAUSED state
// during the maintenance
final double AVAIL_PAUSED = -0.01;
lastAvail = getLastAvailability(availMetric);
assertEquals(AVAIL_PAUSED, lastAvail.getValue());

// wait for maintenance to end
waitForMaintenanceStateChange(maintGroup, MaintenanceState.COMPLETE);

Expand Down Expand Up @@ -255,6 +268,19 @@ public void testScheduleNoMaintenancePermission() throws Exception {
cleanupGroup(groupWithRole);
}

private DataPoint getLastAvailability(Metric availMetric)
throws Exception {

LastMetricDataResponse lastAvailResponse =
getApi().getMetricDataApi().getData(availMetric);
hqAssertSuccess(lastAvailResponse);
assertNotNull(lastAvailResponse.getLastMetricData());
DataPoint lastAvail = lastAvailResponse.getLastMetricData().getDataPoint();
assertNotNull(lastAvail);

return lastAvail;
}

private void waitForMaintenanceStateChange(Group g, MaintenanceState newState)
throws Exception{

Expand Down

0 comments on commit 80726f6

Please sign in to comment.