Skip to content

Commit

Permalink
More timing fixes - specifically to avoid intermittent "Empty long re…
Browse files Browse the repository at this point in the history
…ason" messages on alert validation (caused by asynchronous creation of AlertConditionLogs)
  • Loading branch information
Jennifer Hickey committed Oct 28, 2009
1 parent 2e55be8 commit 815029d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions src/org/hyperic/hq/hqapi1/test/AlertTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ protected void validateAlert(Alert a) throws Exception {
assertTrue("Alert id is incorrect", a.getId() > 0);
assertTrue("Empty long reason", a.getReason().length() > 0);
}

protected boolean validateAlertAttributes(Alert a) throws Exception {
return a.getCtime() > 0 && a.getResourceId() > 0 &&
a.getAlertDefinitionId() > 0 && a.getName() != null && a.getId() >0 &&
a.getReason().length() > 0;
}

protected Escalation createEscalation() throws Exception {
EscalationApi escalationApi = getApi().getEscalationApi();
Expand Down Expand Up @@ -136,12 +142,21 @@ protected Alert generateAlerts(final Resource resource,
dataPoints.add(dp);
StatusResponse dataResponse = dataApi.addData(availMetric, dataPoints);
hqAssertSuccess(dataResponse);
SpinBarrier alertsGenerated = new SpinBarrier(100000l,100l,new SpinBarrierCondition() {
SpinBarrier alertsGenerated = new SpinBarrier(new SpinBarrierCondition() {
public boolean evaluate() {
try {
return getGeneratedAlert(resource,start,e,def) != null;
} catch (IOException e) {
fail("Error obtaining alerts: " + e.getMessage());
Alert a = getGeneratedAlert(resource,start,e,def);
if(a == null) {
return false;
}
//We found an alert, but all fields may not be populated yet. Specifically reason may still be blank.
boolean alertValid = validateAlertAttributes(a);
if(alertValid == false) {
System.out.println("WARN: Found an alert, but it is missing required attributes");
}
return alertValid;
} catch (Exception e) {
fail("Error obtaining or validating alerts: " + e.getMessage());
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/hyperic/hq/hqapi1/test/SpinBarrier.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
*/
public class SpinBarrier {
private long timeout = 5000l;
private long timeout = 120000l;
private long retryInterval = 250l;
private final SpinBarrierCondition condition;

Expand Down

0 comments on commit 815029d

Please sign in to comment.