modules/core/plugin-container-itest/src/test/java/org/rhq/core/pc/inventory/InventoryManagerTest.java
| 29 ++++++++--
modules/core/plugin-container-itest/src/test/java/org/rhq/core/pc/inventory/testplugin/TestResourceDiscoveryComponent.java
| 16 +++++
2 files changed, 42 insertions(+), 3 deletions(-)
New commits:
commit 2c5e267ff8f77108f606877e3f8cc79380077900
Author: Stefan Negrea <snegrea(a)redhat.com>
Date: Tue Jul 31 10:52:46 2012 -0500
add a test that checks if discovery is run more than once per child type
(cherry picked from commit de82e5b9603bf9cd2ec8261b8cb996edbd5a838b)
Conflicts:
modules/core/plugin-container-itest/src/test/java/org/rhq/core/pc/inventory/InventoryManagerTest.java
diff --git
a/modules/core/plugin-container-itest/src/test/java/org/rhq/core/pc/inventory/InventoryManagerTest.java
b/modules/core/plugin-container-itest/src/test/java/org/rhq/core/pc/inventory/InventoryManagerTest.java
index ea11189..b7227ff 100644
---
a/modules/core/plugin-container-itest/src/test/java/org/rhq/core/pc/inventory/InventoryManagerTest.java
+++
b/modules/core/plugin-container-itest/src/test/java/org/rhq/core/pc/inventory/InventoryManagerTest.java
@@ -19,6 +19,11 @@
package org.rhq.core.pc.inventory;
import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.TargetsContainer;
@@ -29,6 +34,7 @@ import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.rhq.core.clientapi.server.discovery.InventoryReport;
import org.rhq.core.domain.resource.InventoryStatus;
import org.rhq.core.domain.resource.Resource;
+import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.pc.PluginContainer;
import org.rhq.core.pc.PluginContainerConfiguration;
import org.rhq.core.pc.inventory.testplugin.TestResourceComponent;
@@ -40,8 +46,6 @@ import org.rhq.test.arquillian.FakeServerInventory;
import org.rhq.test.arquillian.MockingServerServices;
import org.rhq.test.arquillian.RunDiscovery;
import org.rhq.test.shrinkwrap.RhqAgentPluginArchive;
-import org.testng.Assert;
-import org.testng.annotations.Test;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;
@@ -93,7 +97,7 @@ public class InventoryManagerTest extends Arquillian {
}
/**
- * Tests that Resources are properly synchronized after the plugin container is
restarted with a clean data
+ * Tests that Resources are properly synchronized after the inventory manager is
restarted with a clean data
* directory.
*
* @throws Exception if an error occurs
@@ -156,6 +160,25 @@ public class InventoryManagerTest extends Arquillian {
validatePluginContainerInventory();
}
+ /**
+ * Tests that discovery was only run once per ResourceType.
+ *
+ * @throws Exception if an error occurs
+ */
+ @Test(groups = "pc.itest.inventorymanager", dependsOnMethods =
"testSyncUnknownResources")
+ public void testDiscoveryRunsOnlyOncePerType() throws Exception {
+ Map<ResourceType,Integer> executionCountsByResourceType =
TestResourceDiscoveryComponent.getExecutionCountsByResourceType();
+ Map<ResourceType,Integer> flaggedExecutionCountsByResourceType = new
HashMap<ResourceType, Integer>();
+ for (ResourceType resourceType : executionCountsByResourceType.keySet()) {
+ Integer count = executionCountsByResourceType.get(resourceType);
+ if (count > 1) {
+ flaggedExecutionCountsByResourceType.put(resourceType, count);
+ }
+ }
+ Assert.assertTrue(flaggedExecutionCountsByResourceType.isEmpty(),
+ "Discovery was executed more than once for the following types:
" + flaggedExecutionCountsByResourceType);
+ }
+
private void validatePluginContainerInventory() {
System.out.println("Validating PC inventory...");
diff --git
a/modules/core/plugin-container-itest/src/test/java/org/rhq/core/pc/inventory/testplugin/TestResourceDiscoveryComponent.java
b/modules/core/plugin-container-itest/src/test/java/org/rhq/core/pc/inventory/testplugin/TestResourceDiscoveryComponent.java
index 43ccfd4..8091054 100644
---
a/modules/core/plugin-container-itest/src/test/java/org/rhq/core/pc/inventory/testplugin/TestResourceDiscoveryComponent.java
+++
b/modules/core/plugin-container-itest/src/test/java/org/rhq/core/pc/inventory/testplugin/TestResourceDiscoveryComponent.java
@@ -19,6 +19,8 @@
package org.rhq.core.pc.inventory.testplugin;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Set;
import org.rhq.core.domain.resource.ResourceType;
@@ -33,11 +35,21 @@ import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
*/
public class TestResourceDiscoveryComponent implements
ResourceDiscoveryComponent<ResourceComponent<?>> {
+ private static Map<ResourceType, Integer> executionCountsByResourceType = new
HashMap();
+
@Override
public Set<DiscoveredResourceDetails>
discoverResources(ResourceDiscoveryContext<ResourceComponent<?>>
discoveryContext)
throws InvalidPluginConfigurationException, Exception {
ResourceType resourceType = discoveryContext.getResourceType();
+
+ Integer count = executionCountsByResourceType.get(resourceType);
+ if (count == null) {
+ executionCountsByResourceType.put(resourceType, 1);
+ } else {
+ executionCountsByResourceType.put(resourceType, count + 1);
+ }
+
DiscoveredResourceDetails resourceDetails = new
DiscoveredResourceDetails(resourceType,
"SINGLETON", resourceType.getName(), "1.0",
resourceType.getDescription(),
discoveryContext.getDefaultPluginConfiguration(), null);
@@ -45,4 +57,8 @@ public class TestResourceDiscoveryComponent implements
ResourceDiscoveryComponen
return Collections.singleton(resourceDetails);
}
+ public static Map<ResourceType, Integer> getExecutionCountsByResourceType() {
+ return executionCountsByResourceType;
+ }
+
}