modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/configuration/ConfigurationManagerBean.java
| 3
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/configuration/ConfigurationManagerLocal.java
| 19 +-
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/configuration/ConfigurationManagerBeanTest.java
| 71 +++++-----
3 files changed, 54 insertions(+), 39 deletions(-)
New commits:
commit 8a99109184c38e490ea7c793db7b3eb8bdf314bd
Author: Ian P. Springer <ips(a)jetengine.(none)>
Date: Thu Apr 1 13:17:45 2010 -0400
fix annoying sporadic test failures in ConfigurationManagerBeanTest
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/configuration/ConfigurationManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/configuration/ConfigurationManagerBean.java
index dbd2395..4158d8b 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/configuration/ConfigurationManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/configuration/ConfigurationManagerBean.java
@@ -840,6 +840,9 @@ public class ConfigurationManagerBean implements
ConfigurationManagerLocal, Conf
Resource resource = entityManager.find(Resource.class, resourceId);
+ // TODO (ips, 04/01/10): Our id's are not guaranteed to be sequential,
because our sequences are configured to
+ // pre-create and cache blocks of 10 sequence id's, so
it may be better to order by
+ // "cu.createdTime", rather than
"cu.id".
pc.initDefaultOrderingField("cu.id", PageOrdering.DESC);
String queryName = ResourceConfigurationUpdate.QUERY_FIND_ALL_BY_RESOURCE_ID;
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/configuration/ConfigurationManagerLocal.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/configuration/ConfigurationManagerLocal.java
index 774f44c..2854544 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/configuration/ConfigurationManagerLocal.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/configuration/ConfigurationManagerLocal.java
@@ -107,29 +107,38 @@ public interface ConfigurationManagerLocal {
Long endDate, PageControl pc);
/**
- * Returns the list of all resource configuration updates for the given resource.
This will show you an audit trail
- * of the update history for the resource (who updated it, when and what did they
do). You can pick one
+ * Returns the list of all Resource configuration updates for the given Resource, in
reverse of the order in which
+ * they were created (i.e. most recent update will be the first item in the list).
This will show you an audit trail
+ * of the update history for the Resource (who updated it, when and what did they
change). You can pick one
* configuration version to later rollback to that version via
* {@link #updateResourceConfiguration(Subject, int, Configuration)}.
*
- * @param subject the user who wants to see the information
+ * @param subject the user who wants to see the information
* @param resourceId the resource whose update requests are to be returned, if
null will not filter by resourceId
* @param beginDate filter used to show only results occurring after this epoch
millis parameter, nullable
* @param endDate filter used to show only results occurring before this
epoch millis parameter, nullable
* @param suppressOldest if true, will not include the oldest element in the history
(usually the initial update)
* @param pc the pagination controls
*
- * @return the resource's complete list of updates (will be empty (not
<code>null</code>) if none)
+ * @return the Resource's complete list of updates (will be empty (not
<code>null</code>) if none)
*/
PageList<ResourceConfigurationUpdate> findResourceConfigurationUpdates(Subject
subject, Integer resourceId,
Long beginDate, Long endDate, boolean suppressOldest, PageControl pc);
+ /**
+ * Returns a single plugin configuration update.
+ *
+ * @param subject the user who wants to see the information
+ * @param configurationUpdateId the ID of the configuration update entity to return
+ *
+ * @return the plugin configuration update
+ */
PluginConfigurationUpdate getPluginConfigurationUpdate(Subject subject, int
configurationUpdateId);
/**
* Returns a single resource configuration update
*
- * @param subject the user who wants to see the information
+ * @param subject the user who wants to see the information
* @param configurationUpdateId the ID of the configuration update entity to return
*
* @return the resource configuration update
diff --git
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/configuration/ConfigurationManagerBeanTest.java
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/configuration/ConfigurationManagerBeanTest.java
index 45164d2..c79506d 100644
---
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/configuration/ConfigurationManagerBeanTest.java
+++
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/configuration/ConfigurationManagerBeanTest.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2010 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -23,7 +23,6 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Collection;
import javax.persistence.EntityManager;
@@ -46,7 +45,6 @@ import org.rhq.core.domain.configuration.ConfigurationUpdateStatus;
import org.rhq.core.domain.configuration.PluginConfigurationUpdate;
import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.configuration.ResourceConfigurationUpdate;
-import org.rhq.core.domain.configuration.RawConfiguration;
import org.rhq.core.domain.configuration.group.GroupPluginConfigurationUpdate;
import org.rhq.core.domain.discovery.AvailabilityReport;
import org.rhq.core.domain.discovery.InventoryReport;
@@ -78,7 +76,7 @@ public class ConfigurationManagerBeanTest extends AbstractEJB3Test {
private Resource newResource1;
private Resource newResource2;
private ResourceGroup compatibleGroup;
- private PageControl pageControl;
+ private PageControl configUpdatesPageControl;
private Agent agent;
private Subject overlord;
@@ -87,9 +85,12 @@ public class ConfigurationManagerBeanTest extends AbstractEJB3Test {
*/
@BeforeClass
public void beforeClass() {
- // make sure page control sorts so the latest config is last
- pageControl = PageControl.getUnlimitedInstance();
- pageControl.addDefaultOrderingField("cu.id", PageOrdering.ASC);
+ // Make sure page control sorts so the latest config update is last (the default
is for the latest to be first).
+ configUpdatesPageControl = PageControl.getUnlimitedInstance();
+ // (ips, 04/01/10): Use createdTime, rather than id, to order by, since the
id's are not guaranteed to be
+ // ordered sequentially (this is because, dbsetup configures our
sequences to pre-create
+ // and cache sequence values 10 at a time.
+ configUpdatesPageControl.addDefaultOrderingField("cu.createdTime",
PageOrdering.ASC);
configurationManager = LookupUtil.getConfigurationManager();
resourceManager = LookupUtil.getResourceManager();
@@ -224,7 +225,7 @@ public class ConfigurationManagerBeanTest extends AbstractEJB3Test {
assert history1 != null;
PropertySimple myprop =
history1.getConfiguration().getSimple("myboolean");
assert myprop != null;
- assert myprop.getStringValue().equals("true");
+ assert "true".equals(myprop.getStringValue());
// now update to that second config - the "agent" will sleep for a bit
before it completes
// so we will have an INPROGRESS configuration for a few seconds before it goes
to SUCCESS
@@ -244,7 +245,7 @@ public class ConfigurationManagerBeanTest extends AbstractEJB3Test {
assert history2.getId() == history1.getId();
myprop = history2.getConfiguration().getSimple("myboolean");
assert myprop != null;
- assert myprop.getStringValue().equals("true");
+ assert "true".equals(myprop.getStringValue());
myprop = history2.getConfiguration().getSimple("mysleep"); //
this wasn't in the first config
assert myprop == null;
// record that this test case ran, we expect it will if the agent delay
is there
@@ -256,9 +257,10 @@ public class ConfigurationManagerBeanTest extends AbstractEJB3Test {
assert history2.getId() != history1.getId();
myprop = history2.getConfiguration().getSimple("myboolean");
assert myprop != null;
- assert myprop.getStringValue().equals("false");
+ assert "false".equals(myprop.getStringValue());
myprop = history2.getConfiguration().getSimple("mysleep");
- assert myprop.getLongValue() == 7000L;
+ assert myprop.getLongValue() != null;
+ assert myprop.getLongValue().longValue() == 7000L;
}
} while (inProgress);
@@ -555,7 +557,7 @@ public class ConfigurationManagerBeanTest extends AbstractEJB3Test {
configurationManager.updateResourceConfiguration(overlord, resource.getId(),
configuration);
- Thread.sleep(4000); // wait for the test agent to complete the request
+ Thread.sleep(2000); // wait for the test agent to complete the request
// our test service pretends the agent got an error - it will set some errors
and the call to
// completedConfigurationUpdate is made inline (in the real code, this would
be asynchronous)
@@ -626,13 +628,13 @@ public class ConfigurationManagerBeanTest extends AbstractEJB3Test
{
configurationManager.updateResourceConfiguration(overlord, resource.getId(),
configuration);
- Thread.sleep(4000); // wait for the test agent to complete the request
+ Thread.sleep(2000); // wait for the test agent to complete the request
// 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,
- pageControl);
+ configUpdatesPageControl);
assert requests.size() == 1;
assert requests.get(0) != null;
@@ -663,7 +665,7 @@ public class ConfigurationManagerBeanTest extends AbstractEJB3Test {
assert live != null;
mybool = live.getSimple("myboolean");
assert mybool != null;
- assert mybool.getStringValue().equals("true");
+ assert "true".equals(mybool.getStringValue());
assert mybool.getErrorMessage() == null;
// purging a non-existing request is a no-op
@@ -674,7 +676,7 @@ public class ConfigurationManagerBeanTest extends AbstractEJB3Test {
configurationManager.purgeResourceConfigurationUpdate(overlord, request.getId(),
false);
requests = configurationManager.findResourceConfigurationUpdates(overlord,
resource.getId(), null, null, false,
- pageControl);
+ configUpdatesPageControl);
assert requests.size() == 1; // it will create one for us from the
"live" configuration
}
@@ -704,34 +706,35 @@ public class ConfigurationManagerBeanTest extends AbstractEJB3Test
{
List<ResourceConfigurationUpdate> history;
history = configurationManager.findResourceConfigurationUpdates(overlord,
resource.getId(), null, null, false,
- pageControl);
+ configUpdatesPageControl);
assert history != null;
assert history.size() == 3;
- Configuration currentConfiguration = history.get(2).getConfiguration(); // the
last is the current one
+
+ Configuration currentConfiguration = history.get(2).getConfiguration();
PropertySimple mybool = currentConfiguration.getSimple("myboolean");
assert mybool != null;
- assert mybool.getStringValue().equals("TRUE");
+ assert "TRUE".equals(mybool.getStringValue()) : "actual: " +
mybool.getStringValue();
// now grab one of the earlier configurations and rollback to it
Configuration rollbackToHere = history.get(1).getConfiguration(); // the
"false" one
mybool = rollbackToHere.getSimple("myboolean");
assert mybool != null;
- assert mybool.getStringValue().equals("false");
+ assert "false".equals(mybool.getStringValue()) : "actual: " +
mybool.getStringValue();
configurationManager.updateResourceConfiguration(overlord, resource.getId(),
rollbackToHere);
Thread.sleep(2000); // wait for the test agent to complete the request
history = configurationManager.findResourceConfigurationUpdates(overlord,
resource.getId(), null, null, false,
- pageControl);
+ configUpdatesPageControl);
assert history != null;
assert history.size() == 4;
- ResourceConfigurationUpdate newConfigUpdate = history.get(3);
- Configuration newConfiguration = newConfigUpdate.getConfiguration(); // the last
is the new one
+ ResourceConfigurationUpdate newConfigUpdate = history.get(3); // the last one is
the new one
+ Configuration newConfiguration = newConfigUpdate.getConfiguration();
assert newConfiguration.getId() != rollbackToHere.getId();
mybool = newConfiguration.getSimple("myboolean");
assert mybool != null;
- assert mybool.getStringValue().equals("false");
+ assert "false".equals(mybool.getStringValue());
assert mybool.getErrorMessage() == null;
ResourceConfigurationUpdate current =
configurationManager.getLatestResourceConfigurationUpdate(overlord,
@@ -768,7 +771,7 @@ public class ConfigurationManagerBeanTest extends AbstractEJB3Test {
List<ResourceConfigurationUpdate> requests;
requests = configurationManager.findResourceConfigurationUpdates(overlord,
resource.getId(), null, null, false,
- pageControl);
+ configUpdatesPageControl);
assert requests != null;
assert requests.size() == 1 : "Got " + requests.size() + " config
update requests - expected 1.";
@@ -799,7 +802,7 @@ public class ConfigurationManagerBeanTest extends AbstractEJB3Test {
List<ResourceConfigurationUpdate> requests;
requests = configurationManager.findResourceConfigurationUpdates(overlord,
resource.getId(), null, null, false,
- pageControl);
+ configUpdatesPageControl);
assert requests != null;
assert requests.size() == 2 : "Got " + requests.size() + " config
update requests - expected 2.";
@@ -813,7 +816,7 @@ public class ConfigurationManagerBeanTest extends AbstractEJB3Test {
// now get the current configs/requests and
// make sure we deleted just the one configuration, leaving one left
requests = configurationManager.findResourceConfigurationUpdates(overlord,
resource.getId(), null, null, false,
- pageControl);
+ configUpdatesPageControl);
assert requests.size() == 1;
assert requests.get(0).getId() == savedRequest.getId();
@@ -835,14 +838,14 @@ public class ConfigurationManagerBeanTest extends AbstractEJB3Test
{
Configuration activeConfigurationBefore =
configurationManager.getResourceConfiguration(resource.getId());
configurationManager.updateResourceConfiguration(overlord, resource.getId(),
configuration1);
- Thread.sleep(4000); // wait for the test agent to complete the request
+ 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(4000); // wait for the test agent to complete the request
+ 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";
@@ -851,19 +854,19 @@ public class ConfigurationManagerBeanTest extends AbstractEJB3Test
{
assert activeProperties.containsKey("myboolean");
PropertySimple activeProperty = activeProperties.get("myboolean");
assert activeProperty.getName().equals("myboolean");
- assert activeProperty.getStringValue().equals("true");
+ 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,
- pageControl);
+ configUpdatesPageControl);
assert requests != null;
assert requests.size() == 2; // one succeeded and one failed
- assert requests.get(0).getStatus() == ConfigurationUpdateStatus.FAILURE;
- assert requests.get(1).getStatus() == ConfigurationUpdateStatus.SUCCESS;
+ 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
@@ -873,7 +876,7 @@ public class ConfigurationManagerBeanTest extends AbstractEJB3Test {
// now get the current configs/requests and
// make sure we deleted the only one configuration that succeeded, leaving one
update record
requests = configurationManager.findResourceConfigurationUpdates(overlord,
resource.getId(), null, null, false,
- pageControl);
+ configUpdatesPageControl);
assert requests.size() == 1;