assert requests.get(0).getId() == savedRequest.getId();
}
@Test(enabled = ENABLE_TESTS)
public void testPurgeConfigurationHistoryWithFailedUpdateRequest() throws Exception {
Resource resource = newResource1;
Subject overlord = LookupUtil.getSubjectManager().getOverlord();
// create a couple update/requests in history - one request will fail, so only a single config in history will be there
Configuration configuration1 = new Configuration();
configuration1.put(new PropertySimple("myboolean", "invalid-boolean"));
Configuration configuration2 = new Configuration();
configuration2.put(new PropertySimple("myboolean", "true"));
Configuration activeConfigurationBefore = configurationManager.getResourceConfiguration(resource.getId());
configurationManager.updateResourceConfiguration(overlord, resource.getId(), configuration1);
Thread.sleep(2000); // wait for the test agent to complete the request
Configuration activeConfigurationAfter = configurationManager.getResourceConfiguration(resource.getId());
assert activeConfigurationBefore.equals(activeConfigurationAfter) : "ActiveResourceConfiguration was not supposed to change for a failed update -- old was: "
+ activeConfigurationBefore + ", new was: " + activeConfigurationAfter;
configurationManager.updateResourceConfiguration(overlord, resource.getId(), configuration2);
Thread.sleep(2000); // wait for the test agent to complete the request
Configuration activeConfiguration = configurationManager.getResourceConfiguration(resource.getId());
assert activeConfiguration != null : "ActiveResourceConfiguration was not updated with configuration2";
Map<String, PropertySimple> activeProperties = activeConfiguration.getSimpleProperties();
assert activeProperties.size() == 1;
assert activeProperties.containsKey("myboolean");
PropertySimple activeProperty = activeProperties.get("myboolean");
assert activeProperty.getName().equals("myboolean");
assert "true".equals(activeProperty.getStringValue());
// at this point in time, the round trip messaging is done and we have the agent response
List<ResourceConfigurationUpdate> requests;
requests = configurationManager.findResourceConfigurationUpdates(overlord, resource.getId(), null, null, false,
configUpdatesPageControl);
assert requests != null;
assert requests.size() == 2; // one succeeded and one failed
assert requests.get(0).getStatus() == ConfigurationUpdateStatus.FAILURE : "actual: "
+ requests.get(0).getStatus();
assert requests.get(1).getStatus() == ConfigurationUpdateStatus.SUCCESS : "actual: "
+ requests.get(1).getStatus();
ResourceConfigurationUpdate savedRequest = requests.get(0); // this is the one that failed
ResourceConfigurationUpdate doomedRequest = requests.get(1); // this is the one that succeeded
configurationManager.purgeResourceConfigurationUpdate(overlord, doomedRequest.getId(), false);
// now get the current configs/requests and
// make sure we deleted the only one configuration that succeeded, leaving one update record
ResourceConfigurationUpdateCriteria criteria = new ResourceConfigurationUpdateCriteria();
criteria.addFilterResourceIds(resource.getId());
criteria.fetchConfiguration(true);
criteria.addSortCreatedTime(PageOrdering.ASC);
requests = configurationManager.findResourceConfigurationUpdatesByCriteria(overlord, criteria);