modules/core/plugin-container/pom.xml
| 100 ++
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/FakeServerInventory.java
| 164 ++--
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeFailureHandlingTest.java
| 223 +++++
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
| 344 ++------
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java
| 410 ++++++++++
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseDiscoveryComponent.java
| 80 +
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseResourceComponent.java
| 67 +
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseUpgradingDiscoveryComponent.java
| 63 +
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/rhq-plugin.xml
| 39
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep1/rhq-plugin.xml
| 32
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep2/rhq-plugin.xml
| 31
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml
| 32
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml
| 31
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/root/rhq-plugin.xml
| 25
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml
| 28
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml
| 25
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml
| 45 +
modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml
| 43 +
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/OverviewView.java
| 8
19 files changed, 1454 insertions(+), 336 deletions(-)
New commits:
commit 14fd25e86c1a4013c1047c343f3860720a3f9c68
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Oct 1 12:55:37 2010 +0200
Adapted the resource upgrade test infrastructure to work with the new requirements of
the failure handling tests and added the first round of the failure handling tests.
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/FakeServerInventory.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/FakeServerInventory.java
index adb3989..39597ee 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/FakeServerInventory.java
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/FakeServerInventory.java
@@ -59,68 +59,69 @@ public class FakeServerInventory {
private Map<String, Resource> resourceStore = new HashMap<String,
Resource>();
private int counter;
private boolean failing;
-
+
private static final Comparator<Resource> ID_COMPARATOR = new
Comparator<Resource>() {
public int compare(Resource o1, Resource o2) {
return o1.getId() - o2.getId();
}
};
-
+
private static final Comparator<Resource> RESOURCE_TYPE_COMPARATOR = new
Comparator<Resource>() {
public int compare(Resource o1, Resource o2) {
return o1.getResourceType().equals(o2.getResourceType()) ? 0 : o1.getId() -
o2.getId();
}
};
-
+
public FakeServerInventory() {
this(false);
}
-
+
public FakeServerInventory(boolean failing) {
this.failing = failing;
}
-
+
//need to synchronize, because resource upgrade is async and can overlap with
//resource discovery.
public synchronized CustomAction mergeInventoryReport(final InventoryStatus
requiredInventoryStatus) {
return new CustomAction("updateServerSideInventory") {
public Object invoke(Invocation invocation) throws Throwable {
throwIfFailing();
-
+
InventoryReport inventoryReport = (InventoryReport)
invocation.getParameter(0);
-
- for(Resource res : inventoryReport.getAddedRoots()) {
+
+ for (Resource res : inventoryReport.getAddedRoots()) {
+ Resource persisted = fakePersist(res, requiredInventoryStatus, new
HashSet<String>());
+
if (res.getParentResource() == Resource.ROOT) {
- platform = fakePersist(res, requiredInventoryStatus, new
HashSet<String>());
- break;
+ platform = persisted;
}
}
return getSyncInfo();
- }
+ }
};
}
-
+
public synchronized CustomAction clearPlatform() {
return new CustomAction("updateServerSideInventory - report platform deleted
on the server") {
public Object invoke(Invocation invocation) throws Throwable {
throwIfFailing();
-
+
platform = null;
-
+
return getSyncInfo();
}
};
}
-
+
public synchronized CustomAction upgradeResources() {
return new CustomAction("upgradeServerSideInventory") {
- @SuppressWarnings({"serial", "unchecked"})
+ @SuppressWarnings({ "serial", "unchecked" })
public Object invoke(Invocation invocation) throws Throwable {
throwIfFailing();
-
+
Set<ResourceUpgradeRequest> requests =
(Set<ResourceUpgradeRequest>) invocation.getParameter(0);
Set<ResourceUpgradeResponse> responses = new
HashSet<ResourceUpgradeResponse>();
-
+
for (final ResourceUpgradeRequest request : requests) {
Resource resource = findResource(platform, new Resource() {
public int getId() {
@@ -134,16 +135,18 @@ public class FakeServerInventory {
if (request.getNewName() != null) {
resource.setName(request.getNewName());
}
-
+
if (request.getNewResourceKey() != null) {
resource.setResourceKey(request.getNewResourceKey());
}
-
+
if (request.getUpgradeErrorMessage() != null) {
- ResourceError error = new ResourceError(resource,
ResourceErrorType.UPGRADE, request.getUpgradeErrorMessage(),
request.getUpgradeErrorStackTrace(), request.getTimestamp());
+ ResourceError error = new ResourceError(resource,
ResourceErrorType.UPGRADE,
+ request.getUpgradeErrorMessage(),
request.getUpgradeErrorStackTrace(),
+ request.getTimestamp());
resource.getResourceErrors().add(error);
}
-
+
ResourceUpgradeResponse resp = new ResourceUpgradeResponse();
resp.setResourceId(resource.getId());
resp.setUpgradedResourceName(resource.getName());
@@ -156,21 +159,21 @@ public class FakeServerInventory {
}
};
}
-
+
public synchronized CustomAction getResources() {
return new CustomAction("getResources") {
@SuppressWarnings("unchecked")
public Object invoke(Invocation invocation) throws Throwable {
throwIfFailing();
-
- Set<Integer> resourceIds =
(Set<Integer>)invocation.getParameter(0);
+
+ Set<Integer> resourceIds = (Set<Integer>)
invocation.getParameter(0);
boolean includeDescendants = (Boolean) invocation.getParameter(1);
-
+
return getResources(resourceIds, includeDescendants);
}
- };
+ };
}
-
+
public boolean isFailing() {
return failing;
}
@@ -191,12 +194,12 @@ public class FakeServerInventory {
}
return result;
}
-
+
@SuppressWarnings("serial")
- private Set<Resource> getResources(Set<Integer> resourceIds, boolean
includeDescendants) {
+ private Set<Resource> getResources(Set<Integer> resourceIds, boolean
includeDescendants) {
Set<Resource> result = new HashSet<Resource>();
-
- for(final Integer id : resourceIds) {
+
+ for (final Integer id : resourceIds) {
Resource r = findResource(platform, new Resource() {
public int getId() {
return id;
@@ -204,19 +207,20 @@ public class FakeServerInventory {
}, ID_COMPARATOR);
if (r != null) {
result.add(r);
-
+
if (includeDescendants) {
- for(Resource child : r.getChildResources()) {
+ for (Resource child : r.getChildResources()) {
result.addAll(getResources(Collections.singleton(child.getId()),
true));
}
}
}
}
-
+
return result;
}
-
- private Resource fakePersist(Resource agentSideResource, InventoryStatus
requiredInventoryStatus, Set<String> inProgressUUIds) {
+
+ private Resource fakePersist(Resource agentSideResource, InventoryStatus
requiredInventoryStatus,
+ Set<String> inProgressUUIds) {
Resource persisted = resourceStore.get(agentSideResource.getUuid());
if (!inProgressUUIds.add(agentSideResource.getUuid())) {
return persisted;
@@ -237,94 +241,114 @@ public class FakeServerInventory {
persisted.setInventoryStatus(requiredInventoryStatus);
persisted.setResourceKey(agentSideResource.getResourceKey());
persisted.setResourceType(agentSideResource.getResourceType());
-
+
Resource parent = agentSideResource.getParentResource();
if (parent != null && parent != Resource.ROOT) {
-
persisted.setParentResource(fakePersist(agentSideResource.getParentResource(),
requiredInventoryStatus, inProgressUUIds));
+
persisted.setParentResource(fakePersist(agentSideResource.getParentResource(),
requiredInventoryStatus,
+ inProgressUUIds));
} else {
persisted.setParentResource(parent);
}
Set<Resource> childResources = new HashSet<Resource>();
persisted.setChildResources(childResources);
- for(Resource child : agentSideResource.getChildResources()) {
+ for (Resource child : agentSideResource.getChildResources()) {
childResources.add(fakePersist(child, requiredInventoryStatus,
inProgressUUIds));
}
-
+
inProgressUUIds.remove(agentSideResource.getUuid());
-
+
return persisted;
}
-
+
private ResourceSyncInfo getSyncInfo() {
return platform != null ? convert(platform) : null;
}
-
+
private void throwIfFailing() {
if (failing) {
throw new RuntimeException("Fake server inventory is in the failing
mode.");
}
}
-
+
private static ResourceSyncInfo convert(Resource root) {
+ return convertInternal(root, new HashMap<String, ResourceSyncInfo>());
+ }
+
+ private static ResourceSyncInfo convertInternal(Resource root, Map<String,
ResourceSyncInfo> intermediateResults) {
+ ResourceSyncInfo ret = intermediateResults.get(root.getUuid());
+
+ if (ret != null) {
+ return ret;
+ }
+
try {
- ResourceSyncInfo ret = new ResourceSyncInfo();
-
+ ret = new ResourceSyncInfo();
+
+ intermediateResults.put(root.getUuid(), ret);
+
Class<ResourceSyncInfo> clazz = ResourceSyncInfo.class;
getPrivateField(clazz, "id").set(ret, root.getId());
getPrivateField(clazz, "uuid").set(ret, root.getUuid());
getPrivateField(clazz, "mtime").set(ret, root.getMtime());
getPrivateField(clazz, "inventoryStatus").set(ret,
root.getInventoryStatus());
- getPrivateField(clazz, "parent").set(ret, null);
-
+
+ ResourceSyncInfo parent = root.getParentResource() == null ? null :
convertInternal(
+ root.getParentResource(), intermediateResults);
+
+ getPrivateField(clazz, "parent").set(ret, parent);
+
Set<ResourceSyncInfo> children = new
LinkedHashSet<ResourceSyncInfo>();
- for(Resource child : root.getChildResources()) {
- ResourceSyncInfo syncChild = convert(child);
- getPrivateField(clazz, "parent").set(syncChild, ret);
-
- children.add(convert(child));
- }
+ for (Resource child : root.getChildResources()) {
+ ResourceSyncInfo syncChild = convertInternal(child,
intermediateResults);
+
+ children.add(syncChild);
+ }
getPrivateField(clazz, "childSyncInfos").set(ret, children);
-
+
return ret;
} catch (Exception e) {
fail("Failed to convert resource " + root + " to a
ResourceSyncInfo. This should not happen.", e);
return null;
}
- }
-
+ }
+
private static Field getPrivateField(Class<?> clazz, String fieldName) throws
NoSuchFieldException {
Field field = clazz.getDeclaredField(fieldName);
if (!field.isAccessible()) {
field.setAccessible(true);
}
-
+
return field;
}
-
+
private static Resource findResource(Resource root, Resource template,
Comparator<Resource> comparator) {
- if (root == null) return null;
+ if (root == null)
+ return null;
if (comparator.compare(root, template) == 0) {
return root;
} else {
- for(Resource child : root.getChildResources()) {
+ for (Resource child : root.getChildResources()) {
Resource found = findResource(child, template, comparator);
- if (found != null) return found;
+ if (found != null)
+ return found;
}
}
-
+
return null;
- }
-
- private static void findResources(Resource root, Resource template,
Set<Resource> result, Comparator<Resource> comparator) {
- if (root == null) return;
+ }
+
+ private static void findResources(Resource root, Resource template,
Set<Resource> result,
+ Comparator<Resource> comparator) {
+ if (root == null)
+ return;
if (comparator.compare(root, template) == 0) {
result.add(root);
} else {
- for(Resource child : root.getChildResources()) {
+ for (Resource child : root.getChildResources()) {
findResources(child, template, result, comparator);
}
- }
+ }
}
}
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeFailureHandlingTest.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeFailureHandlingTest.java
index 25eca30..5949b76 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeFailureHandlingTest.java
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeFailureHandlingTest.java
@@ -19,11 +19,29 @@
package org.rhq.core.pc.upgrade;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
import org.testng.annotations.Test;
+import org.rhq.core.clientapi.server.discovery.InvalidInventoryReportException;
+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.pluginapi.upgrade.ResourceUpgradeFacet;
+
/**
* The plugins and their resource types form the following dependency structure:
* <pre>
@@ -35,6 +53,10 @@ import org.testng.annotations.Test;
* </pre>
* The dependencies in the above "chart" are formed using either the
<code><runs-inside></code>
* or <code>sourcePlugin/sourceType</code> approaches just to test that both
are handled correctly.
+ * <p>
+ * The <code>parentdep</code>, <code>parentsibling</code>,
<code>test</code> and <code>sibling</code> plugins are present
+ * in two versions and support the {@link ResourceUpgradeFacet}, while the rest of the
plugins is
+ * present only in single version.
*
* @author Lukas Krejci
*/
@@ -53,29 +75,149 @@ public class ResourceUpgradeFailureHandlingTest extends
ResourceUpgradeTestBase
private static final String TEST_V1_PLUGIN_NAME =
"/resource-upgrade-test-plugin-multi-test-1.0.0.jar";
private static final String TEST_V2_PLUGIN_NAME =
"/resource-upgrade-test-plugin-multi-test-2.0.0.jar";
+ private static final String UPGRADED_RESOURCE_KEY_PREFIX = "UPGRADED";
+
+ private static final HashMap<String, List<String>> DEPS;
+
+ static {
+ DEPS = new HashMap<String, List<String>>();
+
+ DEPS.put(BASE_PLUGIN_NAME, Collections.<String> emptyList());
+ DEPS.put(PARENT_DEP_V1_PLUGIN_NAME, Arrays.asList(BASE_PLUGIN_NAME,
ROOT_PLUGIN_NAME));
+ DEPS.put(PARENT_DEP_V2_PLUGIN_NAME, DEPS.get(PARENT_DEP_V1_PLUGIN_NAME));
+ DEPS.put(PARENT_SIBLING_V1_PLUGIN_NAME, Arrays.asList(BASE_PLUGIN_NAME,
ROOT_PLUGIN_NAME));
+ DEPS.put(PARENT_SIBLING_V2_PLUGIN_NAME,
DEPS.get(PARENT_SIBLING_V1_PLUGIN_NAME));
+ DEPS.put(ROOT_PLUGIN_NAME, Arrays.asList(BASE_PLUGIN_NAME));
+ DEPS.put(SIBLING_V1_PLUGIN_NAME, Arrays.asList(BASE_PLUGIN_NAME,
ROOT_PLUGIN_NAME, PARENT_DEP_V1_PLUGIN_NAME));
+ DEPS.put(SIBLING_V2_PLUGIN_NAME, Arrays.asList(BASE_PLUGIN_NAME,
ROOT_PLUGIN_NAME, PARENT_DEP_V2_PLUGIN_NAME));
+ DEPS.put(TEST_V1_PLUGIN_NAME,
+ Arrays.asList(BASE_PLUGIN_NAME, ROOT_PLUGIN_NAME, PARENT_DEP_V1_PLUGIN_NAME,
SIBLING_V1_PLUGIN_NAME));
+ DEPS.put(TEST_V2_PLUGIN_NAME,
+ Arrays.asList(BASE_PLUGIN_NAME, ROOT_PLUGIN_NAME, PARENT_DEP_V1_PLUGIN_NAME,
SIBLING_V2_PLUGIN_NAME));
+ }
+
+ private static final ResType TEST_TYPE = new ResType("TestResource",
"test");
+ private static final ResType SIBLING_TYPE = new
ResType("TestResourceSibling", "test");
+ private static final ResType PARENT_TYPE = new
ResType("TestResourceParent", "test");
+ private static final ResType PARENT_DEP_TYPE = new
ResType("ParentDependency", "parentdep");
+ private static final ResType PARENT_SIBLING_TYPE = new
ResType("ParentDepSibling", "parentsibling");
+ private static final ResType ROOT_TYPE = new ResType("Root",
"root");
+
protected Collection<String> getRequiredPlugins() {
return Arrays.asList(BASE_PLUGIN_NAME, PARENT_DEP_V1_PLUGIN_NAME,
PARENT_DEP_V2_PLUGIN_NAME,
PARENT_SIBLING_V1_PLUGIN_NAME, PARENT_SIBLING_V2_PLUGIN_NAME,
ROOT_PLUGIN_NAME, SIBLING_V1_PLUGIN_NAME,
SIBLING_V2_PLUGIN_NAME, TEST_V1_PLUGIN_NAME, TEST_V2_PLUGIN_NAME);
}
-
+
@Test
- public void testSuccess() {
- //TODO implement
- //check that all the stuff is properly upgraded on success
+ public void testSuccess() throws Exception {
+ setCurrentServerSideInventory(new FakeServerInventory());
+
+ //let it all run in v1
+ executeTestWithPlugins(getAllDepsFor(TEST_V1_PLUGIN_NAME,
PARENT_SIBLING_V1_PLUGIN_NAME),
+ new AbstractTestPayload(true, Collections.<ResType> emptyList()) {
+ public void test(Map<ResType, Set<Resource>>
resourceUpgradeTestResources) {
+ }
+
+ public Expectations getExpectations(Mockery context) throws Exception {
+ return new Expectations() {
+ {
+ defineDefaultExpectations(this);
+ }
+ };
+ }
+ });
+
+ //now let's run with v2 plugins and check the layout of the inventory
+ executeTestWithPlugins(
+ getAllDepsFor(TEST_V2_PLUGIN_NAME, PARENT_SIBLING_V2_PLUGIN_NAME),
+ new AbstractTestPayload(false, Arrays.asList(TEST_TYPE, SIBLING_TYPE,
PARENT_TYPE, PARENT_DEP_TYPE,
+ PARENT_SIBLING_TYPE, ROOT_TYPE)) {
+
+ public void test(Map<ResType, Set<Resource>> resources) {
+ checkPresenceOfResourceTypes(resources, getExpectedResourceTypes());
+
+ checkNumberOfResources(resources, ROOT_TYPE, 1);
+ checkNumberOfResources(resources, PARENT_DEP_TYPE, 1);
+ checkNumberOfResources(resources, PARENT_SIBLING_TYPE, 1);
+ checkNumberOfResources(resources, PARENT_TYPE, 2);
+ checkNumberOfResources(resources, SIBLING_TYPE, 30);
+ checkNumberOfResources(resources, TEST_TYPE, 30);
+
+ //check that the resources are upgraded
+ checkResourcesUpgraded(resources.get(PARENT_SIBLING_TYPE));
+ checkResourcesUpgraded(resources.get(PARENT_TYPE));
+ checkResourcesUpgraded(resources.get(SIBLING_TYPE));
+ checkResourcesUpgraded(resources.get(TEST_TYPE));
+ }
+
+ public Expectations getExpectations(Mockery context) throws Exception {
+ return new Expectations() {
+ {
+ defineDefaultExpectations(this);
+ }
+ };
+ }
+ });
}
-
+
@Test
public void testFailureOnLeaf() {
//TODO implement
//check that the system behaves correctly if there is an upgrade failure
//at the leaf node of the plugin dep graph
}
-
+
@Test
public void testFailureOnDependencies() {
//TODO implement
//check that stuff works if there is an upgrade failure on some of the resources
//in the plugin some "in the middle" of the plugin dep graph
}
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected void defineDefaultExpectations(Expectations expectations) {
+ super.defineDefaultExpectations(expectations);
+ try {
+ expectations.allowing(getCurrentDiscoveryServerService())
+
.mergeInventoryReport(expectations.with(Expectations.any(InventoryReport.class)));
+
expectations.will(getCurrentServerSideInventory().mergeInventoryReport(InventoryStatus.COMMITTED));
+
+
expectations.allowing(getCurrentDiscoveryServerService()).upgradeResources(expectations.with(Expectations.any(Set.class)));
+ expectations.will(getCurrentServerSideInventory().upgradeResources());
+
+
expectations.allowing(getCurrentDiscoveryServerService()).postProcessNewlyCommittedResources(
+ expectations.with(Expectations.any(Set.class)));
+
+ } catch (InvalidInventoryReportException e) {
+ //this is not going to happen because we're mocking the invocation
+ }
+ }
+
+ private Set<String> getAllDepsFor(String... plugins) {
+ HashSet<String> deps = new HashSet<String>();
+ for (String plugin : plugins) {
+ deps.add(plugin);
+ deps.addAll(DEPS.get(plugin));
+ }
+
+ return deps;
+ }
+
+ private static void checkPresenceOfResourceTypes(Map<ResType,
Set<Resource>> resources, Set<ResType> expectedTypes) {
+ for (ResType resType : expectedTypes) {
+ assertNotNull(resources.get(resType), "Expecting some resources of type
" + resType);
+ }
+ }
+
+ private static void checkNumberOfResources(Map<ResType, Set<Resource>>
resources, ResType type, int count) {
+ assertEquals(resources.get(type).size(), count, "Unexpected number of "
+ type + " discovered.");
+ }
+
+ private static void checkResourcesUpgraded(Set<Resource> resources) {
+ for(Resource res : resources) {
+ assertTrue(res.getResourceKey().startsWith(UPGRADED_RESOURCE_KEY_PREFIX),
"Resource " + res + " doesn't seem to be upgraded even though it
should.");
+ }
+ }
}
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
index 8cfec36..d47d00c 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
@@ -31,6 +31,8 @@ import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.jmock.Expectations;
@@ -54,8 +56,13 @@ public class ResourceUpgradeTest extends ResourceUpgradeTestBase {
private static final String PLUGIN_V2_FILENAME =
"/resource-upgrade-test-plugin-2.0.0.jar";
private static final String FAILING_PLUGIN_FILE_NAME =
"/resource-upgrade-test-plugin-3.0.0.jar";
- static final String SINGLETON_RESOURCE_TYPE_NAME = "Resource";
- static final String SINGLETON_RESOURCE_TYPE_PLUGIN_NAME =
"ResourceUpgradeTest";
+ private static final String SINGLETON_RESOURCE_TYPE_NAME = "Resource";
+ private static final String SINGLETON_RESOURCE_TYPE_PLUGIN_NAME =
"ResourceUpgradeTest";
+ private static final ResType SINGLETON_TYPE = new
ResType(SINGLETON_RESOURCE_TYPE_NAME, SINGLETON_RESOURCE_TYPE_PLUGIN_NAME);
+
+ private static List<ResType> getMyExpectedTypes() {
+ return Arrays.asList(SINGLETON_TYPE);
+ }
protected Collection<String> getRequiredPlugins() {
return Arrays.asList(PLUGIN_V1_FILENAME, PLUGIN_V2_FILENAME,
FAILING_PLUGIN_FILE_NAME);
@@ -66,11 +73,11 @@ public class ResourceUpgradeTest extends ResourceUpgradeTestBase {
setCurrentServerSideInventory(new FakeServerInventory());
initialSyncAndDiscovery(InventoryStatus.NEW);
- TestPayload testNoChange = new AbstractTestPayload(false,
SINGLETON_RESOURCE_TYPE_NAME, SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
- public void test(Set<Resource> discoveredResources) {
+ TestPayload testNoChange = new AbstractTestPayload(false, getMyExpectedTypes()) {
+ public void test(Map<ResType, Set<Resource>> discoveredResources)
{
assertEquals(discoveredResources.size(), 1, "Expected single test
resource but multiple found.");
- Resource discoveredResource = discoveredResources.iterator().next();
+ Resource discoveredResource =
discoveredResources.get(SINGLETON_TYPE).iterator().next();
assertEquals(discoveredResource.getResourceKey(),
"resource-key-v1");
assertEquals(discoveredResource.getName(),
"resource-name-v1");
@@ -111,11 +118,11 @@ public class ResourceUpgradeTest extends ResourceUpgradeTestBase {
getCurrentServerSideInventory().setFailing(true);
- TestPayload test = new AbstractTestPayload(false, SINGLETON_RESOURCE_TYPE_NAME,
SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
- public void test(Set<Resource> discoveredResources) {
+ TestPayload test = new AbstractTestPayload(false, getMyExpectedTypes()) {
+ public void test(Map<ResType, Set<Resource>> discoveredResources)
{
assertEquals(discoveredResources.size(), 1, "Expected single test
resource but multiple found.");
- Resource discoveredResource = discoveredResources.iterator().next();
+ Resource discoveredResource =
discoveredResources.get(SINGLETON_TYPE).iterator().next();
assertEquals(discoveredResource.getResourceKey(),
"resource-key-v1");
assertEquals(discoveredResource.getName(),
"resource-name-v1");
@@ -145,11 +152,11 @@ public class ResourceUpgradeTest extends ResourceUpgradeTestBase {
setCurrentServerSideInventory(new FakeServerInventory());
initialSyncAndDiscovery(InventoryStatus.COMMITTED);
- TestPayload test = new AbstractTestPayload(false, SINGLETON_RESOURCE_TYPE_NAME,
SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
- public void test(Set<Resource> discoveredResources) {
+ TestPayload test = new AbstractTestPayload(false, getMyExpectedTypes()) {
+ public void test(Map<ResType, Set<Resource>> discoveredResources)
{
assertEquals(discoveredResources.size(), 1, "Expected single test
resource but multiple found.");
- Resource discoveredResource = discoveredResources.iterator().next();
+ Resource discoveredResource =
discoveredResources.get(SINGLETON_TYPE).iterator().next();
assertEquals(discoveredResource.getResourceKey(),
"resource-key-v2");
assertEquals(discoveredResource.getName(),
"resource-name-v2");
@@ -193,11 +200,11 @@ public class ResourceUpgradeTest extends ResourceUpgradeTestBase {
setCurrentServerSideInventory(new FakeServerInventory());
initialSyncAndDiscovery(InventoryStatus.COMMITTED);
- TestPayload test = new AbstractTestPayload(false, SINGLETON_RESOURCE_TYPE_NAME,
SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
- public void test(Set<Resource> resourceUpgradeTestResources) {
+ TestPayload test = new AbstractTestPayload(false, getMyExpectedTypes()) {
+ public void test(Map<ResType, Set<Resource>>
resourceUpgradeTestResources) {
assertEquals(resourceUpgradeTestResources.size(), 1, "Expected
single test resource but multiple found.");
- Resource discoveredResource =
resourceUpgradeTestResources.iterator().next();
+ Resource discoveredResource =
resourceUpgradeTestResources.get(SINGLETON_TYPE).iterator().next();
assertTrue(discoveredResource.getResourceErrors().size() > 0,
"There should be upgrade errors persisted on the server side.");
@@ -231,11 +238,11 @@ public class ResourceUpgradeTest extends ResourceUpgradeTestBase {
private void initialSyncAndDiscovery(final InventoryStatus requiredInventoryStatus)
throws Exception {
cleanDataDir();
- executeTestWithPlugins(Collections.singleton(PLUGIN_V1_FILENAME), new
AbstractTestPayload(true, SINGLETON_RESOURCE_TYPE_NAME,
SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
- public void test(Set<Resource> discoveredResources) {
+ executeTestWithPlugins(Collections.singleton(PLUGIN_V1_FILENAME), new
AbstractTestPayload(true, getMyExpectedTypes()) {
+ public void test(Map<ResType, Set<Resource>> discoveredResources)
{
assertEquals(discoveredResources.size(), 1, "Expected single test
resource but multiple found.");
- Resource discoveredResource = discoveredResources.iterator().next();
+ Resource discoveredResource =
discoveredResources.get(SINGLETON_TYPE).iterator().next();
assertEquals(discoveredResource.getResourceKey(),
"resource-key-v1");
assertEquals(discoveredResource.getName(),
"resource-name-v1");
@@ -260,11 +267,11 @@ public class ResourceUpgradeTest extends ResourceUpgradeTestBase {
private void upgradeTest(boolean clearInventoryDat) throws Exception {
initialSyncAndDiscovery(InventoryStatus.COMMITTED);
- executeTestWithPlugins(Collections.singleton(PLUGIN_V2_FILENAME), new
AbstractTestPayload(clearInventoryDat, SINGLETON_RESOURCE_TYPE_NAME,
SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
- public void test(Set<Resource> discoveredResources) {
+ executeTestWithPlugins(Collections.singleton(PLUGIN_V2_FILENAME), new
AbstractTestPayload(clearInventoryDat, getMyExpectedTypes()) {
+ public void test(Map<ResType, Set<Resource>> discoveredResources)
{
assertEquals(discoveredResources.size(), 1, "Expected single test
resource but multiple found.");
- Resource discoveredResource = discoveredResources.iterator().next();
+ Resource discoveredResource =
discoveredResources.get(SINGLETON_TYPE).iterator().next();
assertEquals(discoveredResource.getResourceKey(),
"resource-key-v2");
assertEquals(discoveredResource.getName(),
"resource-name-v2");
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java
index 3aa772b..0aefafd 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java
@@ -25,6 +25,9 @@ import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import org.apache.commons.io.FileUtils;
@@ -73,6 +76,78 @@ public abstract class ResourceUpgradeTestBase {
private ResourceFactoryServerService currentResourceFactoryServerService;
private FakeServerInventory currentServerSideInventory;
+ protected static class ResType {
+ private String resourceTypeName;
+ private String resourceTypePluginName;
+
+ public ResType(String resourceTypeName, String resourceTypePluginName) {
+ super();
+ this.resourceTypeName = resourceTypeName;
+ this.resourceTypePluginName = resourceTypePluginName;
+ }
+
+ public String getResourceTypeName() {
+ return resourceTypeName;
+ }
+
+ public String getResourceTypePluginName() {
+ return resourceTypePluginName;
+ }
+
+ @Override
+ public int hashCode() {
+ return resourceTypeName.hashCode() * resourceTypePluginName.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == this) {
+ return true;
+ }
+
+ if (!(other instanceof ResType)) {
+ return false;
+ }
+
+ ResType o = (ResType)other;
+
+ return resourceTypeName.equals(o.getResourceTypeName()) &&
resourceTypePluginName.equals(o.getResourceTypePluginName());
+ }
+
+ @Override
+ public String toString() {
+ return "ResType[name='" + resourceTypeName + "',
plugin='" + resourceTypePluginName + "']";
+ }
+ }
+
+ protected interface TestPayload {
+ Expectations getExpectations(Mockery context) throws Exception;
+
+ void test(Map<ResType,Set<Resource>> resourceUpgradeTestResources);
+
+ boolean isClearInventoryDat();
+
+ Set<ResType> getExpectedResourceTypes();
+ }
+
+ protected static abstract class AbstractTestPayload implements TestPayload {
+ private boolean clearInventoryDat;
+ private Set<ResType> resourceTypes;
+
+ public AbstractTestPayload(boolean clearInventoryDat, Collection<ResType>
resourceTypes) {
+ this.clearInventoryDat = clearInventoryDat;
+ this.resourceTypes = new HashSet<ResType>(resourceTypes);
+ }
+
+ public boolean isClearInventoryDat() {
+ return clearInventoryDat;
+ }
+
+ public Set<ResType> getExpectedResourceTypes() {
+ return resourceTypes;
+ }
+ }
+
@BeforeClass
public void init() {
tmpDir = getTmpDirectory();
@@ -81,21 +156,21 @@ public abstract class ResourceUpgradeTestBase {
dataDir = new File(tmpDir, DATA_DIR_NAME);
assertTrue(dataDir.mkdir(), "Could not create plugin container data
directory.");
}
-
+
@BeforeClass
public void verifyPluginsExist() {
for (String plugin : getRequiredPlugins()) {
verifyPluginExists(plugin);
}
}
-
+
@AfterClass
public void undeployPlugins() throws IOException {
FileUtils.deleteDirectory(tmpDir);
}
-
+
protected abstract Collection<String> getRequiredPlugins();
-
+
protected void setCurrentServerSideInventory(FakeServerInventory
currentServerSideInventory) {
this.currentServerSideInventory = currentServerSideInventory;
}
@@ -103,8 +178,9 @@ public abstract class ResourceUpgradeTestBase {
protected FakeServerInventory getCurrentServerSideInventory() {
return currentServerSideInventory;
}
-
- protected void setCurrentResourceFactoryServerService(ResourceFactoryServerService
currentResourceFactoryServerService) {
+
+ protected void setCurrentResourceFactoryServerService(
+ ResourceFactoryServerService currentResourceFactoryServerService) {
this.currentResourceFactoryServerService = currentResourceFactoryServerService;
}
@@ -178,24 +254,24 @@ public abstract class ResourceUpgradeTestBase {
protected static File getTmpDirectory() {
File ret = new File(System.getProperty("java.io.tmpdir"),
"resource-upgrade-test" + System.currentTimeMillis());
-
+
while (ret.exists() || !ret.mkdir()) {
ret = new File(System.getProperty("java.io.tmpdir"),
"resource-upgrade-test" + System.currentTimeMillis());
}
-
+
return ret;
}
private PluginContainerConfiguration createPluginContainerConfiguration(Mockery
context) throws Exception {
PluginContainerConfiguration conf = new PluginContainerConfiguration();
-
+
conf.setPluginDirectory(new File(tmpDir, PLUGINS_DIR_NAME));
conf.setDataDirectory(new File(tmpDir, DATA_DIR_NAME));
conf.setTemporaryDirectory(new File(tmpDir, TMP_DIR_NAME));
conf.setInsideAgent(true); //pc must think it's inside an agent so that it
persists the inventory between restarts
conf.setPluginFinder(new FileSystemPluginFinder(conf.getPluginDirectory()));
- conf.setCreateResourceClassloaders(false);
-
+ conf.setCreateResourceClassloaders(false);
+
//we're not interested in any scans happening out of our control
conf.setAvailabilityScanInitialDelay(Long.MAX_VALUE);
conf.setConfigurationDiscoveryInitialDelay(Long.MAX_VALUE);
@@ -204,7 +280,7 @@ public abstract class ResourceUpgradeTestBase {
conf.setMeasurementCollectionInitialDelay(Long.MAX_VALUE);
conf.setServerDiscoveryInitialDelay(Long.MAX_VALUE);
conf.setServiceDiscoveryInitialDelay(Long.MAX_VALUE);
-
+
setCurrentBundleServerService(context.mock(BundleServerService.class));
setCurrentConfigurationServerService(context.mock(ConfigurationServerService.class));
setCurrentContentServerService(context.mock(ContentServerService.class));
@@ -214,7 +290,7 @@ public abstract class ResourceUpgradeTestBase {
setCurrentMeasurementServerService(context.mock(MeasurementServerService.class));
setCurrentOperationServerService(context.mock(OperationServerService.class));
setCurrentResourceFactoryServerService(context.mock(ResourceFactoryServerService.class));
-
+
ServerServices serverServices = new ServerServices();
serverServices.setBundleServerService(getCurrentBundleServerService());
serverServices.setConfigurationServerService(getCurrentConfigurationServerService());
@@ -225,9 +301,9 @@ public abstract class ResourceUpgradeTestBase {
serverServices.setMeasurementServerService(getCurrentMeasurementServerService());
serverServices.setOperationServerService(getCurrentOperationServerService());
serverServices.setResourceFactoryServerService(getCurrentResourceFactoryServerService());
-
+
conf.setServerServices(serverServices);
-
+
return conf;
}
@@ -236,104 +312,76 @@ public abstract class ResourceUpgradeTestBase {
*/
protected void verifyPluginExists(String pluginResourcePath) {
URL url = getClass().getResource(pluginResourcePath);
-
+
File pluginFile = FileUtils.toFile(url);
-
+
assertTrue(pluginFile.exists(), pluginFile.getAbsoluteFile() + " plugin jar
could not be found.");
}
private void copyPlugin(String pluginResourcePath, File pluginDirectory) throws
IOException {
URL pluginUrl = getClass().getResource(pluginResourcePath);
-
+
File pluginFile = new File(pluginResourcePath);
String pluginFileName = pluginFile.getName();
-
- FileUtils.copyURLToFile(pluginUrl, new File(pluginDirectory, pluginFileName));
- }
-
- protected interface TestPayload {
- Expectations getExpectations(Mockery context) throws Exception;
- void test(Set<Resource> resourceUpgradeTestResources);
- boolean isClearInventoryDat();
- String getResourceTypeName();
- String getResourceTypePluginName();
- }
-
- protected static abstract class AbstractTestPayload implements TestPayload {
- private boolean clearInventoryDat;
- private String resourceTypeName;
- private String resourceTypePluginName;
-
- public AbstractTestPayload(boolean clearInventoryDat, String
resourceTypeName, String resourceTypePluginName) {
- this.clearInventoryDat = clearInventoryDat;
- this.resourceTypeName = resourceTypeName;
- this.resourceTypePluginName = resourceTypePluginName;
- }
-
- public boolean isClearInventoryDat() {
- return clearInventoryDat;
- }
-
- public String getResourceTypeName() {
- return resourceTypeName;
- }
-
- public String getResourceTypePluginName() {
- return resourceTypePluginName;
- }
- }
- /**
- *
- */
- public ResourceUpgradeTestBase() {
- super();
+ FileUtils.copyURLToFile(pluginUrl, new File(pluginDirectory, pluginFileName));
}
private Set<Resource> getTestingResources(String resourceTypeName, String
resourceTypePluginName) {
- ResourceType resType =
PluginContainer.getInstance().getPluginManager().getMetadataManager().getType(resourceTypeName,
resourceTypePluginName);
-
+ ResourceType resType =
PluginContainer.getInstance().getPluginManager().getMetadataManager()
+ .getType(resourceTypeName, resourceTypePluginName);
+
return getCurrentServerSideInventory().findResourcesByType(resType);
}
protected void executeTestWithPlugins(Set<String> pluginResourcePaths,
TestPayload test) throws Exception {
FileUtils.cleanDirectory(new File(tmpDir, PLUGINS_DIR_NAME));
-
- for(String pluginResourcePath : pluginResourcePaths) {
+
+ for (String pluginResourcePath : pluginResourcePaths) {
copyPlugin(pluginResourcePath, pluginDir);
}
-
+
Mockery context = new Mockery();
-
+
PluginContainerConfiguration pcConfig =
createPluginContainerConfiguration(context);
-
+
if (test.isClearInventoryDat()) {
File inventoryDat = new File(pcConfig.getDataDirectory(),
"inventory.dat");
inventoryDat.delete();
}
-
+
context.checking(test.getExpectations(context));
-
+
PluginContainer.getInstance().setConfiguration(pcConfig);
PluginContainer.getInstance().initialize();
-
+
try {
//give the pc the time to finish resource upgrade
Thread.sleep(1000);
-
+
//execute full discovery
InventoryManager im = PluginContainer.getInstance().getInventoryManager();
im.executeServerScanImmediately();
- im.executeServiceScanImmediately();
-
- Set<Resource> resources =
getTestingResources(test.getResourceTypeName(), test.getResourceTypePluginName());
-
+
+ //do the service scan a couple of times so that we can commit
+ //the resources deep in the type hierarchy
+ for(int i = 0; i < 10; ++i) {
+ im.executeServiceScanImmediately();
+ }
+
+ Map<ResType, Set<Resource>> resources = new HashMap<ResType,
Set<Resource>>();
+
+ for(ResType type : test.getExpectedResourceTypes()) {
+ Set<Resource> rs = getTestingResources(type.getResourceTypeName(),
type.getResourceTypePluginName());
+ resources.put(type, rs);
+ }
+
test.test(resources);
-
+
context.assertIsSatisfied();
} finally {
- PluginContainer.getInstance().shutdown();
- }
+ PluginContainer.getInstance().shutdown();
+ }
}
@SuppressWarnings("unchecked")
@@ -346,11 +394,13 @@ public abstract class ResourceUpgradeTestBase {
expectations.ignoring(getCurrentMeasurementServerService());
expectations.ignoring(getCurrentOperationServerService());
expectations.ignoring(getCurrentResourceFactoryServerService());
-
+
//just ignore these invocations if we get a availability scan in the PC...
-
expectations.allowing(getCurrentDiscoveryServerService()).mergeAvailabilityReport(expectations.with(Expectations.any(AvailabilityReport.class)));
-
-
expectations.allowing(getCurrentDiscoveryServerService()).getResources(expectations.with(Expectations.any(Set.class)),
expectations.with(Expectations.any(boolean.class)));
+
expectations.allowing(getCurrentDiscoveryServerService()).mergeAvailabilityReport(
+ expectations.with(Expectations.any(AvailabilityReport.class)));
+
+ expectations.allowing(getCurrentDiscoveryServerService()).getResources(
+ expectations.with(Expectations.any(Set.class)),
expectations.with(Expectations.any(boolean.class)));
expectations.will(getCurrentServerSideInventory().getResources());
}
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseDiscoveryComponent.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseDiscoveryComponent.java
index 61d4fe0..a03dff5 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseDiscoveryComponent.java
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseDiscoveryComponent.java
@@ -46,15 +46,25 @@ public class BaseDiscoveryComponent<T extends ResourceComponent>
implements Reso
String keyTemplate = pluginConfig.getSimpleValue("key", null);
int count = pluginConfig.getSimple("count").getIntegerValue();
- int parentN =
context.getParentResourceContext().getPluginConfiguration().getSimple("ordinal")
- .getIntegerValue();
+ int parentN = 0;
+
+ if (context.getParentResourceContext() != null) {
+ PropertySimple parentOrdinalProperty =
context.getParentResourceContext().getPluginConfiguration()
+ .getSimple("ordinal");
+
+ if (parentOrdinalProperty != null) {
+ parentN = parentOrdinalProperty.getIntegerValue();
+ }
+ }
for (int i = 0; i < count; ++i) {
String key = getResourceKey(keyTemplate, i, parentN);
+ pluginConfig = context.getDefaultPluginConfiguration();
+
pluginConfig.put(new PropertySimple("ordinal", i));
-
+
DiscoveredResourceDetails detail = new
DiscoveredResourceDetails(context.getResourceType(), key, key, null,
null, pluginConfig, null);
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseUpgradingDiscoveryComponent.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseUpgradingDiscoveryComponent.java
index beb36db..ec1cb20 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseUpgradingDiscoveryComponent.java
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseUpgradingDiscoveryComponent.java
@@ -28,34 +28,36 @@ import org.rhq.core.pluginapi.upgrade.ResourceUpgradeFacet;
*
* @author Lukas Krejci
*/
-public class BaseUpgradingDiscoveryComponent<T extends BaseResourceComponent>
extends BaseDiscoveryComponent<T> implements ResourceUpgradeFacet<T> {
+public class BaseUpgradingDiscoveryComponent<T extends BaseResourceComponent>
extends BaseDiscoveryComponent<T>
+ implements ResourceUpgradeFacet<T> {
public ResourceUpgradeReport upgrade(ResourceUpgradeContext<T>
inventoriedResource) {
Configuration pluginConfig = inventoriedResource.getPluginConfiguration();
-
+
BaseResourceComponent<?> parent =
inventoriedResource.getParentResourceComponent();
int ordinal = pluginConfig.getSimple("ordinal").getIntegerValue();
int parentOrdinal = parent == null ? 0 : parent.getOrdinal();
-
+
boolean fail =
Boolean.getBoolean(pluginConfig.getSimpleValue("failUpgrade",
"false"));
-
+
if (!fail && parent != null) {
fail = parent.getChildrenToFailUpgrade().contains(Integer.valueOf(ordinal));
}
-
+
if (fail) {
throw new RuntimeException("Failing the resource upgrade
purposefully.");
}
-
+
String newKey = pluginConfig.getSimpleValue("upgradedKey", null);
-
+
if (newKey == null) {
return null;
}
-
+
ResourceUpgradeReport report = new ResourceUpgradeReport();
-
+
report.setNewResourceKey(getResourceKey(newKey, ordinal, parentOrdinal));
- return null;
+
+ return report;
}
}
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml
index f5e6920..608793c 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml
@@ -22,8 +22,8 @@
<plugin-configuration>
<c:simple-property name="count" default="1" />
- <c:simple-property name="key"
default="test-resource-parent-sibling-%n,parent-%p" />
- <c:simple-property name="upgradedKey"
default="UPGRADED-test-resource-parent-sibling-%n,parent-%p" />
+ <c:simple-property name="key"
default="test-resource-parent-dep-sibling-%n,parent-%p" />
+ <c:simple-property name="upgradedKey"
default="UPGRADED-test-resource-parent-dep-sibling-%n,parent-%p" />
</plugin-configuration>
</server>
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml
index d138066..ddda11a 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml
@@ -22,7 +22,7 @@
<plugin-configuration>
<c:simple-property name="count" default="1" />
- <c:simple-property name="key"
default="UPGRADED-test-resource-parent-sibling-%n,parent-%p" />
+ <c:simple-property name="key"
default="UPGRADED-test-resource-parent-dep-sibling-%n,parent-%p" />
</plugin-configuration>
</server>
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml
index 44a1033..d3ea7b7 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml
@@ -11,10 +11,18 @@
<depends plugin="base" useClasses="true"/>
- <!-- This service is put in the type hierarchy in the v1/v2 test plugins -->
- <service name="TestResourceSibling"
- discovery="BaseDiscoveryComponent"
- class="BaseResourceComponent" />
+ <server name="Bogus" class="BaseDiscoveryComponent">
+ <!-- This service is put in the type hierarchy in the v1/v2 test plugins -->
+ <service name="TestResourceSibling"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+ <plugin-configuration>
+ <c:simple-property name="count" default="10" />
+ <c:simple-property name="key"
default="test-resource-sibling-%n,parent-%p" />
+ <c:simple-property name="upgradedKey"
default="UPGRADED-test-resource-sibling-%n,parent-%p" />
+ </plugin-configuration>
+ </service>
+ </server>
</plugin>
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml
index aeab68f..f7f7a2c 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml
@@ -10,10 +10,16 @@
<depends plugin="base" useClasses="true"/>
+ <server name="Bogus" class="BaseDiscoveryComponent">
<!-- This service is put in the type hierarchy in the v1/v2 test plugins -->
<service name="TestResourceSibling"
discovery="BaseUpgradingDiscoveryComponent"
- class="BaseResourceComponent" />
-
+ class="BaseResourceComponent">
+ <plugin-configuration>
+ <c:simple-property name="count" default="15" />
<!-- This intentionally differs from v1 -->
+ <c:simple-property name="key"
default="UPGRADED-test-resource-sibling-%n,parent-%p" />
+ </plugin-configuration>
+ </service>
+ </server>
</plugin>
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml
index e934494..ebe9793 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml
@@ -37,13 +37,8 @@
</plugin-configuration>
</service>
- <service name="TestResourceSibling" sourcePlugin="sibling"
sourceType="TestResourceSibling">
- <plugin-configuration>
- <c:simple-property name="count" default="10" />
- <c:simple-property name="key"
default="test-resource-sibling-%n,parent-%p" />
- <c:simple-property name="upgradedKey"
default="UPGRADED-test-resource-sibling-%n,parent-%p" />
- </plugin-configuration>
- </service>
+ <service name="TestResourceSibling" sourcePlugin="sibling"
sourceType="TestResourceSibling"
+ class="BaseResourceComponent"
discovery="BaseDiscoveryComponent" />
</server>
</plugin>
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml
index 96658e3..3d709b0 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml
@@ -26,7 +26,7 @@
</plugin-configuration>
<service name="TestResource"
- discovery="BaseDiscoveryComponent"
+ discovery="BaseUpgradingDiscoveryComponent"
class="BaseResourceComponent">
<plugin-configuration>
<c:simple-property name="count" default="15" />
<!-- This intentionally differs from v1 -->
@@ -35,13 +35,8 @@
</service>
- <service name="TestResourceSibling" sourcePlugin="sibling"
sourceType="TestResourceSibling">
- <plugin-configuration>
- <c:simple-property name="count" default="15" />
<!-- This intentionally differs from v1 -->
- <c:simple-property name="key"
default="UPGRADED-test-resource-sibling-%n,parent-%p" />
- </plugin-configuration>
- </service>
-
+ <service name="TestResourceSibling" sourcePlugin="sibling"
sourceType="TestResourceSibling"
+ class="BaseResourceComponent"
discovery="BaseUpgradingDiscoveryComponent" />
</server>
</plugin>
commit c99d68dd036f243a2f28e000e10385d27bbdb785
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Wed Sep 29 13:53:45 2010 +0200
Adding a skeleton of what will need to be tested for upgrade failure handling.
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeFailureHandlingTest.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeFailureHandlingTest.java
new file mode 100644
index 0000000..25eca30
--- /dev/null
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeFailureHandlingTest.java
@@ -0,0 +1,81 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.core.pc.upgrade;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.testng.annotations.Test;
+
+/**
+ * The plugins and their resource types form the following dependency structure:
+ * <pre>
+ * Root(root)
+ * / \
+ * ParentDependency(parentdep) ParentDepSibling(parentsibling)
+ * / \
+ * TestResource(test) TestResourceSibling(sibling)
+ * </pre>
+ * The dependencies in the above "chart" are formed using either the
<code><runs-inside></code>
+ * or <code>sourcePlugin/sourceType</code> approaches just to test that both
are handled correctly.
+ *
+ * @author Lukas Krejci
+ */
+@Test(sequential = true, invocationCount = 1)
+public class ResourceUpgradeFailureHandlingTest extends ResourceUpgradeTestBase {
+
+ //plugin names
+ private static final String BASE_PLUGIN_NAME =
"/resource-upgrade-test-plugin-multi-base-1.0.0.jar";
+ private static final String PARENT_DEP_V1_PLUGIN_NAME =
"/resource-upgrade-test-plugin-multi-parentdep-1.0.0.jar";
+ private static final String PARENT_DEP_V2_PLUGIN_NAME =
"/resource-upgrade-test-plugin-multi-parentdep-2.0.0.jar";
+ private static final String PARENT_SIBLING_V1_PLUGIN_NAME =
"/resource-upgrade-test-plugin-multi-parentsibling-1.0.0.jar";
+ private static final String PARENT_SIBLING_V2_PLUGIN_NAME =
"/resource-upgrade-test-plugin-multi-parentsibling-2.0.0.jar";
+ private static final String ROOT_PLUGIN_NAME =
"/resource-upgrade-test-plugin-multi-root-1.0.0.jar";
+ private static final String SIBLING_V1_PLUGIN_NAME =
"/resource-upgrade-test-plugin-multi-sibling-1.0.0.jar";
+ private static final String SIBLING_V2_PLUGIN_NAME =
"/resource-upgrade-test-plugin-multi-sibling-2.0.0.jar";
+ private static final String TEST_V1_PLUGIN_NAME =
"/resource-upgrade-test-plugin-multi-test-1.0.0.jar";
+ private static final String TEST_V2_PLUGIN_NAME =
"/resource-upgrade-test-plugin-multi-test-2.0.0.jar";
+
+ protected Collection<String> getRequiredPlugins() {
+ return Arrays.asList(BASE_PLUGIN_NAME, PARENT_DEP_V1_PLUGIN_NAME,
PARENT_DEP_V2_PLUGIN_NAME,
+ PARENT_SIBLING_V1_PLUGIN_NAME, PARENT_SIBLING_V2_PLUGIN_NAME,
ROOT_PLUGIN_NAME, SIBLING_V1_PLUGIN_NAME,
+ SIBLING_V2_PLUGIN_NAME, TEST_V1_PLUGIN_NAME, TEST_V2_PLUGIN_NAME);
+ }
+
+ @Test
+ public void testSuccess() {
+ //TODO implement
+ //check that all the stuff is properly upgraded on success
+ }
+
+ @Test
+ public void testFailureOnLeaf() {
+ //TODO implement
+ //check that the system behaves correctly if there is an upgrade failure
+ //at the leaf node of the plugin dep graph
+ }
+
+ @Test
+ public void testFailureOnDependencies() {
+ //TODO implement
+ //check that stuff works if there is an upgrade failure on some of the resources
+ //in the plugin some "in the middle" of the plugin dep graph
+ }
+}
commit 4f504f582fc9040bcf5ed7f7dd24cfd3bc2adbad
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Wed Sep 29 13:49:24 2010 +0200
some more minor changes to class structure and plugin names.
diff --git a/modules/core/plugin-container/pom.xml
b/modules/core/plugin-container/pom.xml
index 035bf36..4d6e753 100644
--- a/modules/core/plugin-container/pom.xml
+++ b/modules/core/plugin-container/pom.xml
@@ -281,7 +281,7 @@
<!-- <copy
toDir="${project.build.testOutputDirectory}/tmp/multi/v1/org/rhq/core/pc/upgrade/plugins/multi/v1">
<fileset
file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/v1/*.class"
/>
</copy> -->
- <jar
destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-1.0.0.jar">
+ <jar
destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-test-1.0.0.jar">
<fileset
dir="${project.build.testOutputDirectory}/tmp/multi/v1"
includes="**/*.class,**/rhq-plugin.xml" />
</jar>
@@ -291,7 +291,7 @@
<!-- <copy
toDir="${project.build.testOutputDirectory}/tmp/multi/v2/org/rhq/core/pc/upgrade/plugins/multi/v2">
<fileset
file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/v2/*.class"
/>
</copy> -->
- <jar
destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-2.0.0.jar">
+ <jar
destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-test-2.0.0.jar">
<fileset
dir="${project.build.testOutputDirectory}/tmp/multi/v2"
includes="**/*.class,**/rhq-plugin.xml" />
</jar>
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
index e13ea3d..8cfec36 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
@@ -28,6 +28,8 @@ import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import java.io.File;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.Set;
@@ -38,7 +40,6 @@ import org.rhq.core.domain.resource.InventoryStatus;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.pc.PluginContainer;
import org.rhq.core.pc.inventory.ResourceContainer;
-import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
@@ -56,11 +57,8 @@ public class ResourceUpgradeTest extends ResourceUpgradeTestBase {
static final String SINGLETON_RESOURCE_TYPE_NAME = "Resource";
static final String SINGLETON_RESOURCE_TYPE_PLUGIN_NAME =
"ResourceUpgradeTest";
- @BeforeClass
- public void sanityCheck() {
- verifyPluginExists(PLUGIN_V1_FILENAME);
- verifyPluginExists(PLUGIN_V2_FILENAME);
- verifyPluginExists(FAILING_PLUGIN_FILE_NAME);
+ protected Collection<String> getRequiredPlugins() {
+ return Arrays.asList(PLUGIN_V1_FILENAME, PLUGIN_V2_FILENAME,
FAILING_PLUGIN_FILE_NAME);
}
@Test
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java
index f03f2a4..3aa772b 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java
@@ -24,6 +24,7 @@ import static org.testng.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.net.URL;
+import java.util.Collection;
import java.util.Set;
import org.apache.commons.io.FileUtils;
@@ -53,7 +54,7 @@ import org.testng.annotations.BeforeClass;
*
* @author Lukas Krejci
*/
-public class ResourceUpgradeTestBase {
+public abstract class ResourceUpgradeTestBase {
private static final String PLUGINS_DIR_NAME = "plugins";
private static final String DATA_DIR_NAME = "data";
@@ -81,11 +82,20 @@ public class ResourceUpgradeTestBase {
assertTrue(dataDir.mkdir(), "Could not create plugin container data
directory.");
}
+ @BeforeClass
+ public void verifyPluginsExist() {
+ for (String plugin : getRequiredPlugins()) {
+ verifyPluginExists(plugin);
+ }
+ }
+
@AfterClass
public void undeployPlugins() throws IOException {
FileUtils.deleteDirectory(tmpDir);
}
+ protected abstract Collection<String> getRequiredPlugins();
+
protected void setCurrentServerSideInventory(FakeServerInventory
currentServerSideInventory) {
this.currentServerSideInventory = currentServerSideInventory;
}
commit b97e79bcbd5c557fba29030f7aa0f8b4c629c56f
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Wed Sep 29 13:48:28 2010 +0200
Simplify plugin names, declare correct discovery components for upgrade failure test
plugins.
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/rhq-plugin.xml
index 7edfba1..d262c75 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/rhq-plugin.xml
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/rhq-plugin.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin name="ResourceUpgradeMultiTestBase"
+<plugin name="base"
displayName=""
description=""
package="org.rhq.core.pc.upgrade.plugins.multi.base"
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep1/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep1/rhq-plugin.xml
index 3612974..8cadc84 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep1/rhq-plugin.xml
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep1/rhq-plugin.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin name="ResourceUpgradeMultiTestParentDep"
+<plugin name="parentdep"
displayName="Resource Upgrade Multi Test"
description="Resource Upgrade Multi Test"
package="org.rhq.core.pc.upgrade.plugins.multi.base"
@@ -9,15 +9,15 @@
xmlns="urn:xmlns:rhq-plugin"
xmlns:c="urn:xmlns:rhq-configuration">
- <depends plugin="ResourceUpgradeMultiTestBase"
useClasses="true"/>
- <depends plugin="ResourceUpgradeMultiTestRoot"/>
+ <depends plugin="base" useClasses="true"/>
+ <depends plugin="root"/>
<server name="ParentDependency"
discovery="BaseDiscoveryComponent"
class="BaseResourceComponent">
<runs-inside>
- <parent-resource-type name="Root"
plugin="ResourceUpgradeMultiTestRoot"/>
+ <parent-resource-type name="Root" plugin="root"/>
</runs-inside>
<plugin-configuration>
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep2/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep2/rhq-plugin.xml
index 6b95114..8169122 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep2/rhq-plugin.xml
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep2/rhq-plugin.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin name="ResourceUpgradeMultiTestParentDep"
+<plugin name="parentdep"
displayName="Resource Upgrade Multi Test"
description="Resource Upgrade Multi Test"
package="org.rhq.core.pc.upgrade.plugins.multi.base"
@@ -9,15 +9,15 @@
xmlns="urn:xmlns:rhq-plugin"
xmlns:c="urn:xmlns:rhq-configuration">
- <depends plugin="ResourceUpgradeMultiTestBase"
useClasses="true"/>
- <depends plugin="ResourceUpgradeMultiTestRoot"/>
+ <depends plugin="base" useClasses="true"/>
+ <depends plugin="root"/>
<server name="ParentDependency"
- discovery="BaseDiscoveryComponent"
+ discovery="BaseUpgradingDiscoveryComponent"
class="BaseResourceComponent">
<runs-inside>
- <parent-resource-type name="Root"
plugin="ResourceUpgradeMultiTestRoot"/>
+ <parent-resource-type name="Root" plugin="root"/>
</runs-inside>
<plugin-configuration>
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml
index fbade54..f5e6920 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin name="ResourceUpgradeMultiTestParentSibling"
+<plugin name="parentsibling"
displayName="Resource Upgrade Multi Test"
description="Resource Upgrade Multi Test"
package="org.rhq.core.pc.upgrade.plugins.multi.base"
@@ -9,15 +9,15 @@
xmlns="urn:xmlns:rhq-plugin"
xmlns:c="urn:xmlns:rhq-configuration">
- <depends plugin="ResourceUpgradeMultiTestBase"
useClasses="true"/>
- <depends plugin="ResourceUpgradeMultiTestRoot"/>
+ <depends plugin="base" useClasses="true"/>
+ <depends plugin="root"/>
<server name="ParentDepSibling"
discovery="BaseDiscoveryComponent"
class="BaseResourceComponent">
<runs-inside>
- <parent-resource-type name="Root"
plugin="ResourceUpgradeMultiTestRoot"/>
+ <parent-resource-type name="Root" plugin="root"/>
</runs-inside>
<plugin-configuration>
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml
index f16d526..d138066 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin name="ResourceUpgradeMultiTestParentSibling"
+<plugin name="parentsibling"
displayName="Resource Upgrade Multi Test"
description="Resource Upgrade Multi Test"
package="org.rhq.core.pc.upgrade.plugins.multi.base"
@@ -9,15 +9,15 @@
xmlns="urn:xmlns:rhq-plugin"
xmlns:c="urn:xmlns:rhq-configuration">
- <depends plugin="ResourceUpgradeMultiTestBase"
useClasses="true"/>
- <depends plugin="ResourceUpgradeMultiTestRoot"/>
+ <depends plugin="base" useClasses="true"/>
+ <depends plugin="root"/>
<server name="ParentDepSibling"
- discovery="BaseDiscoveryComponent"
+ discovery="BaseUpgradingDiscoveryComponent"
class="BaseResourceComponent">
<runs-inside>
- <parent-resource-type name="Root"
plugin="ResourceUpgradeMultiTestRoot"/>
+ <parent-resource-type name="Root" plugin="root"/>
</runs-inside>
<plugin-configuration>
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/root/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/root/rhq-plugin.xml
index b5efbb1..e95c9bd 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/root/rhq-plugin.xml
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/root/rhq-plugin.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin name="ResourceUpgradeMultiTestRoot"
+<plugin name="root"
displayName=""
description=""
package="org.rhq.core.pc.upgrade.plugins.multi.base"
@@ -9,6 +9,8 @@
xmlns="urn:xmlns:rhq-plugin"
xmlns:c="urn:xmlns:rhq-configuration">
+ <depends plugin="base" useClasses="true"/>
+
<server name="Root"
discovery="BaseDiscoveryComponent"
class="BaseResourceComponent">
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml
index f87ef4d..44a1033 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin name="ResourceUpgradeMultiTestSibling"
+<plugin name="sibling"
displayName="Resource Upgrade Multi Test"
description="Resource Upgrade Multi Test"
package="org.rhq.core.pc.upgrade.plugins.multi.base"
@@ -9,30 +9,12 @@
xmlns="urn:xmlns:rhq-plugin"
xmlns:c="urn:xmlns:rhq-configuration">
- <depends plugin="ResourceUpgradeMultiTestBase"
useClasses="true"/>
- <depends plugin="ResourceUpgradeMultiTestParentDep"/>
+ <depends plugin="base" useClasses="true"/>
- <server name="TestResourceParentSibling"
- discovery="BaseDiscoveryComponent"
- class="BaseResourceComponent">
-
- <plugin-configuration>
- <c:simple-property name="count" default="2" />
- <c:simple-property name="key"
default="test-resource-parent-sibling-%n,parent-%p" />
- <c:simple-property name="upgradedKey"
default="UPGRADED-test-resource-parent-sibling-%n,parent-%p" />
- </plugin-configuration>
-
- <service name="TestResourceSibling"
+ <!-- This service is put in the type hierarchy in the v1/v2 test plugins -->
+ <service name="TestResourceSibling"
discovery="BaseDiscoveryComponent"
- class="BaseResourceComponent">
- <plugin-configuration>
- <c:simple-property name="count" default="10" />
- <c:simple-property name="key"
default="test-resource-sibling-%n,parent-%p" />
- <c:simple-property name="upgradedKey"
default="UPGRADED-test-resource-sibling-%n,parent-%p" />
- </plugin-configuration>
-
- </service>
- </server>
+ class="BaseResourceComponent" />
</plugin>
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml
index e6ab95f..aeab68f 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin name="ResourceUpgradeMultiTestSibling"
+<plugin name="sibling"
displayName="Resource Upgrade Multi Test"
description="Resource Upgrade Multi Test"
package="org.rhq.core.pc.upgrade.plugins.multi.base"
@@ -8,34 +8,12 @@
xmlns="urn:xmlns:rhq-plugin"
xmlns:c="urn:xmlns:rhq-configuration">
- <depends plugin="ResourceUpgradeMultiTestBase"
useClasses="true"/>
- <depends plugin="ResourceUpgradeMultiTestParentDep"/>
+ <depends plugin="base" useClasses="true"/>
- <server name="TestResourceParentSibling"
- discovery="BaseUpgradingDiscoveryComponent"
- class="BaseResourceComponent">
-
- <runs-inside>
- <parent-resource-type name="ParentDependency"
plugin="ResourceUpgradeMultiTestParentDep"/>
- </runs-inside>
-
- <plugin-configuration>
- <c:simple-property name="count" default="2" />
- <c:simple-property name="key"
default="UPGRADED-test-resource-parent-sibling-%n,parent-%p" />
- </plugin-configuration>
-
- <service name="TestResourceSibling"
- discovery="BaseDiscoveryComponent"
- class="BaseResourceComponent">
- <plugin-configuration>
- <c:simple-property name="count" default="15" />
- <c:simple-property name="key"
default="UPGRADED-test-resource-sibling-%n,parent-%p" />
- </plugin-configuration>
-
- </service>
-
-
- </server>
+ <!-- This service is put in the type hierarchy in the v1/v2 test plugins -->
+ <service name="TestResourceSibling"
+ discovery="BaseUpgradingDiscoveryComponent"
+ class="BaseResourceComponent" />
</plugin>
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml
index 32ad438..e934494 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin name="ResourceUpgradeMultiTest"
+<plugin name="test"
displayName="Resource Upgrade Multi Test"
description="Resource Upgrade Multi Test"
package="org.rhq.core.pc.upgrade.plugins.multi.base"
@@ -9,15 +9,16 @@
xmlns="urn:xmlns:rhq-plugin"
xmlns:c="urn:xmlns:rhq-configuration">
- <depends plugin="ResourceUpgradeMultiTestBase"
useClasses="true"/>
- <depends plugin="ResourceUpgradeMultiTestParentDep"/>
+ <depends plugin="base" useClasses="true"/>
+ <depends plugin="parentdep"/>
+ <depends plugin="sibling" />
<server name="TestResourceParent"
discovery="BaseDiscoveryComponent"
class="BaseResourceComponent">
<runs-inside>
- <parent-resource-type name="ParentDependency"
plugin="ResourceUpgradeMultiTestParentDep"/>
+ <parent-resource-type name="ParentDependency"
plugin="parentdep"/>
</runs-inside>
<plugin-configuration>
@@ -29,13 +30,20 @@
<service name="TestResource"
discovery="BaseDiscoveryComponent"
class="BaseResourceComponent">
- <plugin-configuration>
- <c:simple-property name="count" default="10" />
- <c:simple-property name="key"
default="test-resource-%n,parent-%p" />
- <c:simple-property name="upgradedKey"
default="UPGRADED-test-resource-%n,parent-%p" />
- </plugin-configuration>
-
- </service>
+ <plugin-configuration>
+ <c:simple-property name="count" default="10" />
+ <c:simple-property name="key"
default="test-resource-%n,parent-%p" />
+ <c:simple-property name="upgradedKey"
default="UPGRADED-test-resource-%n,parent-%p" />
+ </plugin-configuration>
+ </service>
+
+ <service name="TestResourceSibling" sourcePlugin="sibling"
sourceType="TestResourceSibling">
+ <plugin-configuration>
+ <c:simple-property name="count" default="10" />
+ <c:simple-property name="key"
default="test-resource-sibling-%n,parent-%p" />
+ <c:simple-property name="upgradedKey"
default="UPGRADED-test-resource-sibling-%n,parent-%p" />
+ </plugin-configuration>
+ </service>
</server>
</plugin>
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml
index 824d3fe..96658e3 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin name="ResourceUpgradeMultiTest"
+<plugin name="test"
displayName="Resource Upgrade Multi Test"
description="Resource Upgrade Multi Test"
package="org.rhq.core.pc.upgrade.plugins.multi.base"
@@ -8,15 +8,16 @@
xmlns="urn:xmlns:rhq-plugin"
xmlns:c="urn:xmlns:rhq-configuration">
- <depends plugin="ResourceUpgradeMultiTestBase"
useClasses="true"/>
- <depends plugin="ResourceUpgradeMultiTestParentDep"/>
+ <depends plugin="base" useClasses="true"/>
+ <depends plugin="parentdep"/>
+ <depends plugin="sibling"/>
<server name="TestResourceParent"
discovery="BaseUpgradingDiscoveryComponent"
class="BaseResourceComponent">
<runs-inside>
- <parent-resource-type name="ParentDependency"
plugin="ResourceUpgradeMultiTestParentDep"/>
+ <parent-resource-type name="ParentDependency"
plugin="parentdep"/>
</runs-inside>
<plugin-configuration>
@@ -27,13 +28,19 @@
<service name="TestResource"
discovery="BaseDiscoveryComponent"
class="BaseResourceComponent">
- <plugin-configuration>
- <c:simple-property name="count" default="15" />
- <c:simple-property name="key"
default="UPGRADED-test-resource-%n,parent-%p" />
- </plugin-configuration>
+ <plugin-configuration>
+ <c:simple-property name="count" default="15" />
<!-- This intentionally differs from v1 -->
+ <c:simple-property name="key"
default="UPGRADED-test-resource-%n,parent-%p" />
+ </plugin-configuration>
</service>
+ <service name="TestResourceSibling" sourcePlugin="sibling"
sourceType="TestResourceSibling">
+ <plugin-configuration>
+ <c:simple-property name="count" default="15" />
<!-- This intentionally differs from v1 -->
+ <c:simple-property name="key"
default="UPGRADED-test-resource-sibling-%n,parent-%p" />
+ </plugin-configuration>
+ </service>
</server>
commit 097f744dec27c5584cf6203bbaff6fc041753b26
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Wed Sep 29 13:12:09 2010 +0200
Extracted a base class from the upgrade test in preparation for adding another round
of tests.
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
index 0a2a660..e13ea3d 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
@@ -23,43 +23,23 @@
package org.rhq.core.pc.upgrade;
-import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
import java.io.File;
-import java.io.IOException;
-import java.net.URL;
import java.util.Collections;
import java.util.Set;
-import org.apache.commons.io.FileUtils;
import org.jmock.Expectations;
import org.jmock.Mockery;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import org.rhq.core.clientapi.server.bundle.BundleServerService;
-import org.rhq.core.clientapi.server.configuration.ConfigurationServerService;
-import org.rhq.core.clientapi.server.content.ContentServerService;
-import org.rhq.core.clientapi.server.core.CoreServerService;
-import org.rhq.core.clientapi.server.discovery.DiscoveryServerService;
import org.rhq.core.clientapi.server.discovery.InventoryReport;
-import org.rhq.core.clientapi.server.event.EventServerService;
-import org.rhq.core.clientapi.server.inventory.ResourceFactoryServerService;
-import org.rhq.core.clientapi.server.measurement.MeasurementServerService;
-import org.rhq.core.clientapi.server.operation.OperationServerService;
-import org.rhq.core.domain.discovery.AvailabilityReport;
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.ServerServices;
-import org.rhq.core.pc.inventory.InventoryManager;
import org.rhq.core.pc.inventory.ResourceContainer;
-import org.rhq.core.pc.plugin.FileSystemPluginFinder;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
/**
* Test cases for resource upgrade.
@@ -67,39 +47,14 @@ import org.rhq.core.pc.plugin.FileSystemPluginFinder;
* @author Lukas Krejci
*/
@Test(sequential = true, invocationCount = 1)
-public class ResourceUpgradeTest {
+public class ResourceUpgradeTest extends ResourceUpgradeTestBase {
private static final String PLUGIN_V1_FILENAME =
"/resource-upgrade-test-plugin-1.0.0.jar";
private static final String PLUGIN_V2_FILENAME =
"/resource-upgrade-test-plugin-2.0.0.jar";
private static final String FAILING_PLUGIN_FILE_NAME =
"/resource-upgrade-test-plugin-3.0.0.jar";
- private static final String PLUGINS_DIR_NAME = "plugins";
- private static final String DATA_DIR_NAME = "data";
- private static final String TMP_DIR_NAME = "tmp";
-
- private static final String SINGLETON_RESOURCE_TYPE_NAME = "Resource";
- private static final String SINGLETON_RESOURCE_TYPE_PLUGIN_NAME =
"ResourceUpgradeTest";
-
- private File tmpDir;
- private File pluginDir;
- private File dataDir;
-
- private BundleServerService currentBundleServerService;
- private ConfigurationServerService currentConfigurationServerService;
- private ContentServerService currentContentServerService;
- private CoreServerService currentCoreServerService;
- private DiscoveryServerService currentDiscoveryServerService;
- private EventServerService currentEventServerService;
- private MeasurementServerService currentMeasurementServerService;
- private OperationServerService currentOperationServerService;
- private ResourceFactoryServerService currentResourceFactoryServerService;
-
- private FakeServerInventory currentServerSideInventory;
-
- @AfterClass
- public void undeployPlugins() throws IOException {
- FileUtils.deleteDirectory(tmpDir);
- }
+ static final String SINGLETON_RESOURCE_TYPE_NAME = "Resource";
+ static final String SINGLETON_RESOURCE_TYPE_PLUGIN_NAME =
"ResourceUpgradeTest";
@BeforeClass
public void sanityCheck() {
@@ -108,18 +63,9 @@ public class ResourceUpgradeTest {
verifyPluginExists(FAILING_PLUGIN_FILE_NAME);
}
- @BeforeClass(dependsOnMethods = "sanityCheck")
- public void init() {
- tmpDir = getTmpDirectory();
- pluginDir = new File(tmpDir, PLUGINS_DIR_NAME);
- assertTrue(pluginDir.mkdir(), "Could not create plugin deploy
directory.");
- dataDir = new File(tmpDir, DATA_DIR_NAME);
- assertTrue(dataDir.mkdir(), "Could not create plugin container data
directory.");
- }
-
@Test
public void testIgnoreUncommittedResources() throws Exception {
- currentServerSideInventory = new FakeServerInventory();
+ setCurrentServerSideInventory(new FakeServerInventory());
initialSyncAndDiscovery(InventoryStatus.NEW);
TestPayload testNoChange = new AbstractTestPayload(false,
SINGLETON_RESOURCE_TYPE_NAME, SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
@@ -138,8 +84,8 @@ public class ResourceUpgradeTest {
{
defineDefaultExpectations(this);
- between(1,
4).of(currentDiscoveryServerService).mergeInventoryReport(with(any(InventoryReport.class)));
-
will(currentServerSideInventory.mergeInventoryReport(InventoryStatus.COMMITTED));
+ between(1,
4).of(getCurrentDiscoveryServerService()).mergeInventoryReport(with(any(InventoryReport.class)));
+
will(getCurrentServerSideInventory().mergeInventoryReport(InventoryStatus.COMMITTED));
}
};
}
@@ -150,22 +96,22 @@ public class ResourceUpgradeTest {
@Test
public void testUpgradeData() throws Exception {
- currentServerSideInventory = new FakeServerInventory();
+ setCurrentServerSideInventory(new FakeServerInventory());
upgradeTest(false);
}
@Test
public void testInventoryReinitializationFromServerDuringUpgrade() throws Exception
{
- currentServerSideInventory = new FakeServerInventory();
+ setCurrentServerSideInventory(new FakeServerInventory());
upgradeTest(true);
}
@Test
public void testSkipUpgradeWhenServerUnavailable() throws Exception {
- currentServerSideInventory = new FakeServerInventory();
+ setCurrentServerSideInventory(new FakeServerInventory());
initialSyncAndDiscovery(InventoryStatus.COMMITTED);
- currentServerSideInventory.setFailing(true);
+ getCurrentServerSideInventory().setFailing(true);
TestPayload test = new AbstractTestPayload(false, SINGLETON_RESOURCE_TYPE_NAME,
SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
public void test(Set<Resource> discoveredResources) {
@@ -184,10 +130,10 @@ public class ResourceUpgradeTest {
{
defineDefaultExpectations(this);
- between(1,
4).of(currentDiscoveryServerService).mergeInventoryReport(with(any(InventoryReport.class)));
-
will(currentServerSideInventory.mergeInventoryReport(InventoryStatus.COMMITTED));
+ between(1,
4).of(getCurrentDiscoveryServerService()).mergeInventoryReport(with(any(InventoryReport.class)));
+
will(getCurrentServerSideInventory().mergeInventoryReport(InventoryStatus.COMMITTED));
-
never(currentDiscoveryServerService).upgradeResources(with(any(Set.class)));
+
never(getCurrentDiscoveryServerService()).upgradeResources(with(any(Set.class)));
}
};
}
@@ -198,7 +144,7 @@ public class ResourceUpgradeTest {
@Test
public void testUpgradeWithPlatformDeletedOnServer() throws Exception {
- currentServerSideInventory = new FakeServerInventory();
+ setCurrentServerSideInventory(new FakeServerInventory());
initialSyncAndDiscovery(InventoryStatus.COMMITTED);
TestPayload test = new AbstractTestPayload(false, SINGLETON_RESOURCE_TYPE_NAME,
SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
@@ -227,15 +173,15 @@ public class ResourceUpgradeTest {
//the first merge will be triggered from within the upgrade
process and we are
//going to report null sync.
-
oneOf(currentDiscoveryServerService).mergeInventoryReport(with(any(InventoryReport.class)));
- will(currentServerSideInventory.clearPlatform());
+
oneOf(getCurrentDiscoveryServerService()).mergeInventoryReport(with(any(InventoryReport.class)));
+ will(getCurrentServerSideInventory().clearPlatform());
//the rest of the inventory merges are executed by discoveries,
so let's import the
//discovered stuff into the server-side inventory.
- between(1,
3).of(currentDiscoveryServerService).mergeInventoryReport(with(any(InventoryReport.class)));
-
will(currentServerSideInventory.mergeInventoryReport(InventoryStatus.COMMITTED));
+ between(1,
3).of(getCurrentDiscoveryServerService()).mergeInventoryReport(with(any(InventoryReport.class)));
+
will(getCurrentServerSideInventory().mergeInventoryReport(InventoryStatus.COMMITTED));
-
never(currentDiscoveryServerService).upgradeResources(with(any(Set.class)));
+
never(getCurrentDiscoveryServerService()).upgradeResources(with(any(Set.class)));
}
};
}
@@ -246,7 +192,7 @@ public class ResourceUpgradeTest {
@Test
public void testUpgradeFailureHandling() throws Exception {
- currentServerSideInventory = new FakeServerInventory();
+ setCurrentServerSideInventory(new FakeServerInventory());
initialSyncAndDiscovery(InventoryStatus.COMMITTED);
TestPayload test = new AbstractTestPayload(false, SINGLETON_RESOURCE_TYPE_NAME,
SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
@@ -272,11 +218,11 @@ public class ResourceUpgradeTest {
{
defineDefaultExpectations(this);
- between(1,
4).of(currentDiscoveryServerService).mergeInventoryReport(with(any(InventoryReport.class)));
-
will(currentServerSideInventory.mergeInventoryReport(InventoryStatus.COMMITTED));
+ between(1,
4).of(getCurrentDiscoveryServerService()).mergeInventoryReport(with(any(InventoryReport.class)));
+
will(getCurrentServerSideInventory().mergeInventoryReport(InventoryStatus.COMMITTED));
-
oneOf(currentDiscoveryServerService).upgradeResources(with(any(Set.class)));
- will(currentServerSideInventory.upgradeResources());
+
oneOf(getCurrentDiscoveryServerService()).upgradeResources(with(any(Set.class)));
+ will(getCurrentServerSideInventory().upgradeResources());
}
};
}
@@ -297,20 +243,21 @@ public class ResourceUpgradeTest {
assertEquals(discoveredResource.getName(),
"resource-name-v1");
assertEquals(discoveredResource.getDescription(),
"resource-description-v1");
}
-
+
public Expectations getExpectations(Mockery context) throws Exception {
return new Expectations() {
{
defineDefaultExpectations(this);
- between(1,
4).of(currentDiscoveryServerService).mergeInventoryReport(with(any(InventoryReport.class)));
-
will(currentServerSideInventory.mergeInventoryReport(requiredInventoryStatus));
+ between(1,
4).of(getCurrentDiscoveryServerService()).mergeInventoryReport(with(any(InventoryReport.class)));
+
will(getCurrentServerSideInventory().mergeInventoryReport(requiredInventoryStatus));
}
};
}
});
}
+
private void upgradeTest(boolean clearInventoryDat) throws Exception {
initialSyncAndDiscovery(InventoryStatus.COMMITTED);
@@ -339,189 +286,14 @@ public class ResourceUpgradeTest {
{
defineDefaultExpectations(this);
- between(1,
4).of(currentDiscoveryServerService).mergeInventoryReport(with(any(InventoryReport.class)));
-
will(currentServerSideInventory.mergeInventoryReport(InventoryStatus.COMMITTED));
+ between(1,
4).of(getCurrentDiscoveryServerService()).mergeInventoryReport(with(any(InventoryReport.class)));
+
will(getCurrentServerSideInventory().mergeInventoryReport(InventoryStatus.COMMITTED));
-
oneOf(currentDiscoveryServerService).upgradeResources(with(any(Set.class)));
- will(currentServerSideInventory.upgradeResources());
+
oneOf(getCurrentDiscoveryServerService()).upgradeResources(with(any(Set.class)));
+ will(getCurrentServerSideInventory().upgradeResources());
}
};
}
});
}
-
- private PluginContainerConfiguration createPluginContainerConfiguration(Mockery
context) throws Exception {
- PluginContainerConfiguration conf = new PluginContainerConfiguration();
-
- conf.setPluginDirectory(new File(tmpDir, PLUGINS_DIR_NAME));
- conf.setDataDirectory(new File(tmpDir, DATA_DIR_NAME));
- conf.setTemporaryDirectory(new File(tmpDir, TMP_DIR_NAME));
- conf.setInsideAgent(true); //pc must think it's inside an agent so that it
persists the inventory between restarts
- conf.setPluginFinder(new FileSystemPluginFinder(conf.getPluginDirectory()));
- conf.setCreateResourceClassloaders(false);
-
- //we're not interested in any scans happening out of our control
- conf.setAvailabilityScanInitialDelay(Long.MAX_VALUE);
- conf.setConfigurationDiscoveryInitialDelay(Long.MAX_VALUE);
- conf.setContentDiscoveryInitialDelay(Long.MAX_VALUE);
- conf.setEventSenderInitialDelay(Long.MAX_VALUE);
- conf.setMeasurementCollectionInitialDelay(Long.MAX_VALUE);
- conf.setServerDiscoveryInitialDelay(Long.MAX_VALUE);
- conf.setServiceDiscoveryInitialDelay(Long.MAX_VALUE);
-
- currentBundleServerService = context.mock(BundleServerService.class);
- currentConfigurationServerService =
context.mock(ConfigurationServerService.class);
- currentContentServerService = context.mock(ContentServerService.class);
- currentCoreServerService = context.mock(CoreServerService.class);
- currentDiscoveryServerService = context.mock(DiscoveryServerService.class);
- currentEventServerService = context.mock(EventServerService.class);
- currentMeasurementServerService = context.mock(MeasurementServerService.class);
- currentOperationServerService = context.mock(OperationServerService.class);
- currentResourceFactoryServerService =
context.mock(ResourceFactoryServerService.class);
-
- ServerServices serverServices = new ServerServices();
- serverServices.setBundleServerService(currentBundleServerService);
- serverServices.setConfigurationServerService(currentConfigurationServerService);
- serverServices.setContentServerService(currentContentServerService);
- serverServices.setCoreServerService(currentCoreServerService);
- serverServices.setDiscoveryServerService(currentDiscoveryServerService);
- serverServices.setEventServerService(currentEventServerService);
- serverServices.setMeasurementServerService(currentMeasurementServerService);
- serverServices.setOperationServerService(currentOperationServerService);
-
serverServices.setResourceFactoryServerService(currentResourceFactoryServerService);
-
- conf.setServerServices(serverServices);
-
- return conf;
- }
-
- /**
- * @param pluginResourcePath
- */
- private void verifyPluginExists(String pluginResourcePath) {
- URL url = getClass().getResource(pluginResourcePath);
-
- File pluginFile = FileUtils.toFile(url);
-
- assertTrue(pluginFile.exists(), pluginFile.getAbsoluteFile() + " plugin jar
could not be found.");
- }
-
- private void copyPlugin(String pluginResourcePath, File pluginDirectory) throws
IOException {
- URL pluginUrl = getClass().getResource(pluginResourcePath);
-
- File pluginFile = new File(pluginResourcePath);
- String pluginFileName = pluginFile.getName();
-
- FileUtils.copyURLToFile(pluginUrl, new File(pluginDirectory, pluginFileName));
- }
-
- private static File getTmpDirectory() {
- File ret = new File(System.getProperty("java.io.tmpdir"),
"resource-upgrade-test" + System.currentTimeMillis());
-
- while (ret.exists() || !ret.mkdir()) {
- ret = new File(System.getProperty("java.io.tmpdir"),
"resource-upgrade-test" + System.currentTimeMillis());
- }
-
- return ret;
- }
-
- private interface TestPayload {
- Expectations getExpectations(Mockery context) throws Exception;
- void test(Set<Resource> resourceUpgradeTestResources);
- boolean isClearInventoryDat();
- String getResourceTypeName();
- String getResourceTypePluginName();
- }
-
- private static abstract class AbstractTestPayload implements TestPayload {
- private boolean clearInventoryDat;
- private String resourceTypeName;
- private String resourceTypePluginName;
-
- public AbstractTestPayload(boolean clearInventoryDat, String resourceTypeName,
String resourceTypePluginName) {
- this.clearInventoryDat = clearInventoryDat;
- this.resourceTypeName = resourceTypeName;
- this.resourceTypePluginName = resourceTypePluginName;
- }
-
- public boolean isClearInventoryDat() {
- return clearInventoryDat;
- }
-
- public String getResourceTypeName() {
- return resourceTypeName;
- }
-
- public String getResourceTypePluginName() {
- return resourceTypePluginName;
- }
- }
-
- private Set<Resource> getTestingResources(String resourceTypeName, String
resourceTypePluginName) {
- ResourceType resType =
PluginContainer.getInstance().getPluginManager().getMetadataManager().getType(resourceTypeName,
resourceTypePluginName);
-
- return currentServerSideInventory.findResourcesByType(resType);
- }
-
- private void executeTestWithPlugins(Set<String> pluginResourcePaths,
TestPayload test) throws Exception {
- FileUtils.cleanDirectory(new File(tmpDir, PLUGINS_DIR_NAME));
-
- for(String pluginResourcePath : pluginResourcePaths) {
- copyPlugin(pluginResourcePath, pluginDir);
- }
-
- Mockery context = new Mockery();
-
- PluginContainerConfiguration pcConfig =
createPluginContainerConfiguration(context);
-
- if (test.isClearInventoryDat()) {
- File inventoryDat = new File(pcConfig.getDataDirectory(),
"inventory.dat");
- inventoryDat.delete();
- }
-
- context.checking(test.getExpectations(context));
-
- PluginContainer.getInstance().setConfiguration(pcConfig);
- PluginContainer.getInstance().initialize();
-
- try {
- //give the pc the time to finish resource upgrade
- Thread.sleep(1000);
-
- //execute full discovery
- InventoryManager im = PluginContainer.getInstance().getInventoryManager();
- im.executeServerScanImmediately();
- im.executeServiceScanImmediately();
-
- Set<Resource> resources =
getTestingResources(test.getResourceTypeName(), test.getResourceTypePluginName());
-
- test.test(resources);
-
- context.assertIsSatisfied();
- } finally {
- PluginContainer.getInstance().shutdown();
- }
- }
-
- @SuppressWarnings("unchecked")
- private void defineDefaultExpectations(Expectations expectations) {
- expectations.ignoring(currentBundleServerService);
- expectations.ignoring(currentConfigurationServerService);
- expectations.ignoring(currentContentServerService);
- expectations.ignoring(currentCoreServerService);
- expectations.ignoring(currentEventServerService);
- expectations.ignoring(currentMeasurementServerService);
- expectations.ignoring(currentOperationServerService);
- expectations.ignoring(currentResourceFactoryServerService);
-
- //just ignore these invocations if we get a availability scan in the PC...
-
expectations.allowing(currentDiscoveryServerService).mergeAvailabilityReport(expectations.with(Expectations.any(AvailabilityReport.class)));
-
-
expectations.allowing(currentDiscoveryServerService).getResources(expectations.with(Expectations.any(Set.class)),
expectations.with(Expectations.any(boolean.class)));
- expectations.will(currentServerSideInventory.getResources());
- }
-
- private void cleanDataDir() throws IOException {
- FileUtils.cleanDirectory(new File(tmpDir, DATA_DIR_NAME));
- }
}
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java
new file mode 100644
index 0000000..f03f2a4
--- /dev/null
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTestBase.java
@@ -0,0 +1,350 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.core.pc.upgrade;
+
+import static org.testng.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Set;
+
+import org.apache.commons.io.FileUtils;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.rhq.core.clientapi.server.bundle.BundleServerService;
+import org.rhq.core.clientapi.server.configuration.ConfigurationServerService;
+import org.rhq.core.clientapi.server.content.ContentServerService;
+import org.rhq.core.clientapi.server.core.CoreServerService;
+import org.rhq.core.clientapi.server.discovery.DiscoveryServerService;
+import org.rhq.core.clientapi.server.event.EventServerService;
+import org.rhq.core.clientapi.server.inventory.ResourceFactoryServerService;
+import org.rhq.core.clientapi.server.measurement.MeasurementServerService;
+import org.rhq.core.clientapi.server.operation.OperationServerService;
+import org.rhq.core.domain.discovery.AvailabilityReport;
+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.ServerServices;
+import org.rhq.core.pc.inventory.InventoryManager;
+import org.rhq.core.pc.plugin.FileSystemPluginFinder;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+
+/**
+ *
+ * @author Lukas Krejci
+ */
+public class ResourceUpgradeTestBase {
+
+ private static final String PLUGINS_DIR_NAME = "plugins";
+ private static final String DATA_DIR_NAME = "data";
+ private static final String TMP_DIR_NAME = "tmp";
+ private File tmpDir;
+ private File pluginDir;
+ private File dataDir;
+ private BundleServerService currentBundleServerService;
+ private ConfigurationServerService currentConfigurationServerService;
+ private ContentServerService currentContentServerService;
+ private CoreServerService currentCoreServerService;
+ private DiscoveryServerService currentDiscoveryServerService;
+ private EventServerService currentEventServerService;
+ private MeasurementServerService currentMeasurementServerService;
+ private OperationServerService currentOperationServerService;
+ private ResourceFactoryServerService currentResourceFactoryServerService;
+ private FakeServerInventory currentServerSideInventory;
+
+ @BeforeClass
+ public void init() {
+ tmpDir = getTmpDirectory();
+ pluginDir = new File(tmpDir, PLUGINS_DIR_NAME);
+ assertTrue(pluginDir.mkdir(), "Could not create plugin deploy
directory.");
+ dataDir = new File(tmpDir, DATA_DIR_NAME);
+ assertTrue(dataDir.mkdir(), "Could not create plugin container data
directory.");
+ }
+
+ @AfterClass
+ public void undeployPlugins() throws IOException {
+ FileUtils.deleteDirectory(tmpDir);
+ }
+
+ protected void setCurrentServerSideInventory(FakeServerInventory
currentServerSideInventory) {
+ this.currentServerSideInventory = currentServerSideInventory;
+ }
+
+ protected FakeServerInventory getCurrentServerSideInventory() {
+ return currentServerSideInventory;
+ }
+
+ protected void setCurrentResourceFactoryServerService(ResourceFactoryServerService
currentResourceFactoryServerService) {
+ this.currentResourceFactoryServerService = currentResourceFactoryServerService;
+ }
+
+ protected ResourceFactoryServerService getCurrentResourceFactoryServerService() {
+ return currentResourceFactoryServerService;
+ }
+
+ protected void setCurrentOperationServerService(OperationServerService
currentOperationServerService) {
+ this.currentOperationServerService = currentOperationServerService;
+ }
+
+ protected OperationServerService getCurrentOperationServerService() {
+ return currentOperationServerService;
+ }
+
+ protected void setCurrentMeasurementServerService(MeasurementServerService
currentMeasurementServerService) {
+ this.currentMeasurementServerService = currentMeasurementServerService;
+ }
+
+ protected MeasurementServerService getCurrentMeasurementServerService() {
+ return currentMeasurementServerService;
+ }
+
+ protected void setCurrentEventServerService(EventServerService
currentEventServerService) {
+ this.currentEventServerService = currentEventServerService;
+ }
+
+ protected EventServerService getCurrentEventServerService() {
+ return currentEventServerService;
+ }
+
+ protected void setCurrentDiscoveryServerService(DiscoveryServerService
currentDiscoveryServerService) {
+ this.currentDiscoveryServerService = currentDiscoveryServerService;
+ }
+
+ protected DiscoveryServerService getCurrentDiscoveryServerService() {
+ return currentDiscoveryServerService;
+ }
+
+ protected void setCurrentCoreServerService(CoreServerService
currentCoreServerService) {
+ this.currentCoreServerService = currentCoreServerService;
+ }
+
+ protected CoreServerService getCurrentCoreServerService() {
+ return currentCoreServerService;
+ }
+
+ protected void setCurrentContentServerService(ContentServerService
currentContentServerService) {
+ this.currentContentServerService = currentContentServerService;
+ }
+
+ protected ContentServerService getCurrentContentServerService() {
+ return currentContentServerService;
+ }
+
+ protected void setCurrentConfigurationServerService(ConfigurationServerService
currentConfigurationServerService) {
+ this.currentConfigurationServerService = currentConfigurationServerService;
+ }
+
+ protected ConfigurationServerService getCurrentConfigurationServerService() {
+ return currentConfigurationServerService;
+ }
+
+ protected void setCurrentBundleServerService(BundleServerService
currentBundleServerService) {
+ this.currentBundleServerService = currentBundleServerService;
+ }
+
+ protected BundleServerService getCurrentBundleServerService() {
+ return currentBundleServerService;
+ }
+
+ protected static File getTmpDirectory() {
+ File ret = new File(System.getProperty("java.io.tmpdir"),
"resource-upgrade-test" + System.currentTimeMillis());
+
+ while (ret.exists() || !ret.mkdir()) {
+ ret = new File(System.getProperty("java.io.tmpdir"),
"resource-upgrade-test" + System.currentTimeMillis());
+ }
+
+ return ret;
+ }
+
+ private PluginContainerConfiguration createPluginContainerConfiguration(Mockery
context) throws Exception {
+ PluginContainerConfiguration conf = new PluginContainerConfiguration();
+
+ conf.setPluginDirectory(new File(tmpDir, PLUGINS_DIR_NAME));
+ conf.setDataDirectory(new File(tmpDir, DATA_DIR_NAME));
+ conf.setTemporaryDirectory(new File(tmpDir, TMP_DIR_NAME));
+ conf.setInsideAgent(true); //pc must think it's inside an agent so that it
persists the inventory between restarts
+ conf.setPluginFinder(new FileSystemPluginFinder(conf.getPluginDirectory()));
+ conf.setCreateResourceClassloaders(false);
+
+ //we're not interested in any scans happening out of our control
+ conf.setAvailabilityScanInitialDelay(Long.MAX_VALUE);
+ conf.setConfigurationDiscoveryInitialDelay(Long.MAX_VALUE);
+ conf.setContentDiscoveryInitialDelay(Long.MAX_VALUE);
+ conf.setEventSenderInitialDelay(Long.MAX_VALUE);
+ conf.setMeasurementCollectionInitialDelay(Long.MAX_VALUE);
+ conf.setServerDiscoveryInitialDelay(Long.MAX_VALUE);
+ conf.setServiceDiscoveryInitialDelay(Long.MAX_VALUE);
+
+ setCurrentBundleServerService(context.mock(BundleServerService.class));
+
setCurrentConfigurationServerService(context.mock(ConfigurationServerService.class));
+ setCurrentContentServerService(context.mock(ContentServerService.class));
+ setCurrentCoreServerService(context.mock(CoreServerService.class));
+ setCurrentDiscoveryServerService(context.mock(DiscoveryServerService.class));
+ setCurrentEventServerService(context.mock(EventServerService.class));
+
setCurrentMeasurementServerService(context.mock(MeasurementServerService.class));
+ setCurrentOperationServerService(context.mock(OperationServerService.class));
+
setCurrentResourceFactoryServerService(context.mock(ResourceFactoryServerService.class));
+
+ ServerServices serverServices = new ServerServices();
+ serverServices.setBundleServerService(getCurrentBundleServerService());
+
serverServices.setConfigurationServerService(getCurrentConfigurationServerService());
+ serverServices.setContentServerService(getCurrentContentServerService());
+ serverServices.setCoreServerService(getCurrentCoreServerService());
+ serverServices.setDiscoveryServerService(getCurrentDiscoveryServerService());
+ serverServices.setEventServerService(getCurrentEventServerService());
+
serverServices.setMeasurementServerService(getCurrentMeasurementServerService());
+ serverServices.setOperationServerService(getCurrentOperationServerService());
+
serverServices.setResourceFactoryServerService(getCurrentResourceFactoryServerService());
+
+ conf.setServerServices(serverServices);
+
+ return conf;
+ }
+
+ /**
+ * @param pluginResourcePath
+ */
+ protected void verifyPluginExists(String pluginResourcePath) {
+ URL url = getClass().getResource(pluginResourcePath);
+
+ File pluginFile = FileUtils.toFile(url);
+
+ assertTrue(pluginFile.exists(), pluginFile.getAbsoluteFile() + " plugin jar
could not be found.");
+ }
+
+ private void copyPlugin(String pluginResourcePath, File pluginDirectory) throws
IOException {
+ URL pluginUrl = getClass().getResource(pluginResourcePath);
+
+ File pluginFile = new File(pluginResourcePath);
+ String pluginFileName = pluginFile.getName();
+
+ FileUtils.copyURLToFile(pluginUrl, new File(pluginDirectory, pluginFileName));
+ }
+
+ protected interface TestPayload {
+ Expectations getExpectations(Mockery context) throws Exception;
+ void test(Set<Resource> resourceUpgradeTestResources);
+ boolean isClearInventoryDat();
+ String getResourceTypeName();
+ String getResourceTypePluginName();
+ }
+
+ protected static abstract class AbstractTestPayload implements TestPayload {
+ private boolean clearInventoryDat;
+ private String resourceTypeName;
+ private String resourceTypePluginName;
+
+ public AbstractTestPayload(boolean clearInventoryDat, String
resourceTypeName, String resourceTypePluginName) {
+ this.clearInventoryDat = clearInventoryDat;
+ this.resourceTypeName = resourceTypeName;
+ this.resourceTypePluginName = resourceTypePluginName;
+ }
+
+ public boolean isClearInventoryDat() {
+ return clearInventoryDat;
+ }
+
+ public String getResourceTypeName() {
+ return resourceTypeName;
+ }
+
+ public String getResourceTypePluginName() {
+ return resourceTypePluginName;
+ }
+ }
+
+ /**
+ *
+ */
+ public ResourceUpgradeTestBase() {
+ super();
+ }
+
+ private Set<Resource> getTestingResources(String resourceTypeName, String
resourceTypePluginName) {
+ ResourceType resType =
PluginContainer.getInstance().getPluginManager().getMetadataManager().getType(resourceTypeName,
resourceTypePluginName);
+
+ return getCurrentServerSideInventory().findResourcesByType(resType);
+ }
+
+ protected void executeTestWithPlugins(Set<String> pluginResourcePaths,
TestPayload test) throws Exception {
+ FileUtils.cleanDirectory(new File(tmpDir, PLUGINS_DIR_NAME));
+
+ for(String pluginResourcePath : pluginResourcePaths) {
+ copyPlugin(pluginResourcePath, pluginDir);
+ }
+
+ Mockery context = new Mockery();
+
+ PluginContainerConfiguration pcConfig =
createPluginContainerConfiguration(context);
+
+ if (test.isClearInventoryDat()) {
+ File inventoryDat = new File(pcConfig.getDataDirectory(),
"inventory.dat");
+ inventoryDat.delete();
+ }
+
+ context.checking(test.getExpectations(context));
+
+ PluginContainer.getInstance().setConfiguration(pcConfig);
+ PluginContainer.getInstance().initialize();
+
+ try {
+ //give the pc the time to finish resource upgrade
+ Thread.sleep(1000);
+
+ //execute full discovery
+ InventoryManager im = PluginContainer.getInstance().getInventoryManager();
+ im.executeServerScanImmediately();
+ im.executeServiceScanImmediately();
+
+ Set<Resource> resources =
getTestingResources(test.getResourceTypeName(), test.getResourceTypePluginName());
+
+ test.test(resources);
+
+ context.assertIsSatisfied();
+ } finally {
+ PluginContainer.getInstance().shutdown();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void defineDefaultExpectations(Expectations expectations) {
+ expectations.ignoring(getCurrentBundleServerService());
+ expectations.ignoring(getCurrentConfigurationServerService());
+ expectations.ignoring(getCurrentContentServerService());
+ expectations.ignoring(getCurrentCoreServerService());
+ expectations.ignoring(getCurrentEventServerService());
+ expectations.ignoring(getCurrentMeasurementServerService());
+ expectations.ignoring(getCurrentOperationServerService());
+ expectations.ignoring(getCurrentResourceFactoryServerService());
+
+ //just ignore these invocations if we get a availability scan in the PC...
+
expectations.allowing(getCurrentDiscoveryServerService()).mergeAvailabilityReport(expectations.with(Expectations.any(AvailabilityReport.class)));
+
+
expectations.allowing(getCurrentDiscoveryServerService()).getResources(expectations.with(Expectations.any(Set.class)),
expectations.with(Expectations.any(boolean.class)));
+ expectations.will(getCurrentServerSideInventory().getResources());
+ }
+
+ protected void cleanDataDir() throws IOException {
+ FileUtils.cleanDirectory(new File(tmpDir, DATA_DIR_NAME));
+ }
+}
commit 1863f1ab0c4473e6a79c469c16b73b6810733325
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Wed Sep 29 12:58:32 2010 +0200
Preparing the upgrade tests to accept more complicated scenarios.
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
index 1479345..0a2a660 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/ResourceUpgradeTest.java
@@ -77,6 +77,9 @@ public class ResourceUpgradeTest {
private static final String DATA_DIR_NAME = "data";
private static final String TMP_DIR_NAME = "tmp";
+ private static final String SINGLETON_RESOURCE_TYPE_NAME = "Resource";
+ private static final String SINGLETON_RESOURCE_TYPE_PLUGIN_NAME =
"ResourceUpgradeTest";
+
private File tmpDir;
private File pluginDir;
private File dataDir;
@@ -119,8 +122,12 @@ public class ResourceUpgradeTest {
currentServerSideInventory = new FakeServerInventory();
initialSyncAndDiscovery(InventoryStatus.NEW);
- TestPayload testNoChange = new TestPayload() {
- public void test(Resource discoveredResource) {
+ TestPayload testNoChange = new AbstractTestPayload(false,
SINGLETON_RESOURCE_TYPE_NAME, SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
+ public void test(Set<Resource> discoveredResources) {
+ assertEquals(discoveredResources.size(), 1, "Expected single test
resource but multiple found.");
+
+ Resource discoveredResource = discoveredResources.iterator().next();
+
assertEquals(discoveredResource.getResourceKey(),
"resource-key-v1");
assertEquals(discoveredResource.getName(),
"resource-name-v1");
assertEquals(discoveredResource.getDescription(),
"resource-description-v1");
@@ -138,7 +145,7 @@ public class ResourceUpgradeTest {
}
};
- executeTestWithPlugins(Collections.singleton(PLUGIN_V2_FILENAME), false,
testNoChange);
+ executeTestWithPlugins(Collections.singleton(PLUGIN_V2_FILENAME), testNoChange);
}
@Test
@@ -160,8 +167,12 @@ public class ResourceUpgradeTest {
currentServerSideInventory.setFailing(true);
- TestPayload test = new TestPayload() {
- public void test(Resource discoveredResource) {
+ TestPayload test = new AbstractTestPayload(false, SINGLETON_RESOURCE_TYPE_NAME,
SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
+ public void test(Set<Resource> discoveredResources) {
+ assertEquals(discoveredResources.size(), 1, "Expected single test
resource but multiple found.");
+
+ Resource discoveredResource = discoveredResources.iterator().next();
+
assertEquals(discoveredResource.getResourceKey(),
"resource-key-v1");
assertEquals(discoveredResource.getName(),
"resource-name-v1");
assertEquals(discoveredResource.getDescription(),
"resource-description-v1");
@@ -182,7 +193,7 @@ public class ResourceUpgradeTest {
}
};
- executeTestWithPlugins(Collections.singleton(PLUGIN_V2_FILENAME), false, test);
+ executeTestWithPlugins(Collections.singleton(PLUGIN_V2_FILENAME), test);
}
@Test
@@ -190,8 +201,12 @@ public class ResourceUpgradeTest {
currentServerSideInventory = new FakeServerInventory();
initialSyncAndDiscovery(InventoryStatus.COMMITTED);
- TestPayload test = new TestPayload() {
- public void test(Resource discoveredResource) {
+ TestPayload test = new AbstractTestPayload(false, SINGLETON_RESOURCE_TYPE_NAME,
SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
+ public void test(Set<Resource> discoveredResources) {
+ assertEquals(discoveredResources.size(), 1, "Expected single test
resource but multiple found.");
+
+ Resource discoveredResource = discoveredResources.iterator().next();
+
assertEquals(discoveredResource.getResourceKey(),
"resource-key-v2");
assertEquals(discoveredResource.getName(),
"resource-name-v2");
assertEquals(discoveredResource.getDescription(),
"resource-description-v2");
@@ -226,7 +241,7 @@ public class ResourceUpgradeTest {
}
};
- executeTestWithPlugins(Collections.singleton(PLUGIN_V2_FILENAME), false, test);
+ executeTestWithPlugins(Collections.singleton(PLUGIN_V2_FILENAME), test);
}
@Test
@@ -234,12 +249,16 @@ public class ResourceUpgradeTest {
currentServerSideInventory = new FakeServerInventory();
initialSyncAndDiscovery(InventoryStatus.COMMITTED);
- TestPayload test = new TestPayload() {
- public void test(Resource resourceUpgradeTestResource) {
- assertTrue(resourceUpgradeTestResource.getResourceErrors().size() > 0,
"There should be upgrade errors persisted on the server side.");
+ TestPayload test = new AbstractTestPayload(false, SINGLETON_RESOURCE_TYPE_NAME,
SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
+ public void test(Set<Resource> resourceUpgradeTestResources) {
+ assertEquals(resourceUpgradeTestResources.size(), 1, "Expected
single test resource but multiple found.");
+
+ Resource discoveredResource =
resourceUpgradeTestResources.iterator().next();
+
+ assertTrue(discoveredResource.getResourceErrors().size() > 0,
"There should be upgrade errors persisted on the server side.");
//the discovery of the failed resource mustn't have run
- ResourceContainer container =
PluginContainer.getInstance().getInventoryManager().getResourceContainer(resourceUpgradeTestResource);
+ ResourceContainer container =
PluginContainer.getInstance().getInventoryManager().getResourceContainer(discoveredResource);
File dataDir = container.getResourceContext().getDataDirectory();
File marker = new File(dataDir, "failing-discovery-ran");
@@ -263,13 +282,17 @@ public class ResourceUpgradeTest {
}
};
- executeTestWithPlugins(Collections.singleton(FAILING_PLUGIN_FILE_NAME), false,
test);
+ executeTestWithPlugins(Collections.singleton(FAILING_PLUGIN_FILE_NAME), test);
}
private void initialSyncAndDiscovery(final InventoryStatus requiredInventoryStatus)
throws Exception {
cleanDataDir();
- executeTestWithPlugins(Collections.singleton(PLUGIN_V1_FILENAME), true, new
TestPayload() {
- public void test(Resource discoveredResource) {
+ executeTestWithPlugins(Collections.singleton(PLUGIN_V1_FILENAME), new
AbstractTestPayload(true, SINGLETON_RESOURCE_TYPE_NAME,
SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
+ public void test(Set<Resource> discoveredResources) {
+ assertEquals(discoveredResources.size(), 1, "Expected single test
resource but multiple found.");
+
+ Resource discoveredResource = discoveredResources.iterator().next();
+
assertEquals(discoveredResource.getResourceKey(),
"resource-key-v1");
assertEquals(discoveredResource.getName(),
"resource-name-v1");
assertEquals(discoveredResource.getDescription(),
"resource-description-v1");
@@ -292,8 +315,12 @@ public class ResourceUpgradeTest {
private void upgradeTest(boolean clearInventoryDat) throws Exception {
initialSyncAndDiscovery(InventoryStatus.COMMITTED);
- executeTestWithPlugins(Collections.singleton(PLUGIN_V2_FILENAME),
clearInventoryDat, new TestPayload() {
- public void test(Resource discoveredResource) {
+ executeTestWithPlugins(Collections.singleton(PLUGIN_V2_FILENAME), new
AbstractTestPayload(clearInventoryDat, SINGLETON_RESOURCE_TYPE_NAME,
SINGLETON_RESOURCE_TYPE_PLUGIN_NAME) {
+ public void test(Set<Resource> discoveredResources) {
+ assertEquals(discoveredResources.size(), 1, "Expected single test
resource but multiple found.");
+
+ Resource discoveredResource = discoveredResources.iterator().next();
+
assertEquals(discoveredResource.getResourceKey(),
"resource-key-v2");
assertEquals(discoveredResource.getName(),
"resource-name-v2");
assertEquals(discoveredResource.getDescription(),
"resource-description-v2");
@@ -400,16 +427,43 @@ public class ResourceUpgradeTest {
private interface TestPayload {
Expectations getExpectations(Mockery context) throws Exception;
- void test(Resource resourceUpgradeTestResource);
+ void test(Set<Resource> resourceUpgradeTestResources);
+ boolean isClearInventoryDat();
+ String getResourceTypeName();
+ String getResourceTypePluginName();
}
- private Set<Resource> getTestingResources() {
- ResourceType resType =
PluginContainer.getInstance().getPluginManager().getMetadataManager().getType("Resource",
"ResourceUpgradeTest");
+ private static abstract class AbstractTestPayload implements TestPayload {
+ private boolean clearInventoryDat;
+ private String resourceTypeName;
+ private String resourceTypePluginName;
+
+ public AbstractTestPayload(boolean clearInventoryDat, String resourceTypeName,
String resourceTypePluginName) {
+ this.clearInventoryDat = clearInventoryDat;
+ this.resourceTypeName = resourceTypeName;
+ this.resourceTypePluginName = resourceTypePluginName;
+ }
+
+ public boolean isClearInventoryDat() {
+ return clearInventoryDat;
+ }
+
+ public String getResourceTypeName() {
+ return resourceTypeName;
+ }
+
+ public String getResourceTypePluginName() {
+ return resourceTypePluginName;
+ }
+ }
+
+ private Set<Resource> getTestingResources(String resourceTypeName, String
resourceTypePluginName) {
+ ResourceType resType =
PluginContainer.getInstance().getPluginManager().getMetadataManager().getType(resourceTypeName,
resourceTypePluginName);
return currentServerSideInventory.findResourcesByType(resType);
}
- private void executeTestWithPlugins(Set<String> pluginResourcePaths, boolean
clearInventoryDat, TestPayload test) throws Exception {
+ private void executeTestWithPlugins(Set<String> pluginResourcePaths,
TestPayload test) throws Exception {
FileUtils.cleanDirectory(new File(tmpDir, PLUGINS_DIR_NAME));
for(String pluginResourcePath : pluginResourcePaths) {
@@ -420,7 +474,7 @@ public class ResourceUpgradeTest {
PluginContainerConfiguration pcConfig =
createPluginContainerConfiguration(context);
- if (clearInventoryDat) {
+ if (test.isClearInventoryDat()) {
File inventoryDat = new File(pcConfig.getDataDirectory(),
"inventory.dat");
inventoryDat.delete();
}
@@ -439,14 +493,9 @@ public class ResourceUpgradeTest {
im.executeServerScanImmediately();
im.executeServiceScanImmediately();
- Set<Resource> resources = getTestingResources();
-
- assertEquals(resources.size(), 1, "There should be only a single testing
resource but " + resources
- + " were found.");
-
- Resource discoveredResource = resources.iterator().next();
+ Set<Resource> resources =
getTestingResources(test.getResourceTypeName(), test.getResourceTypePluginName());
- test.test(discoveredResource);
+ test.test(resources);
context.assertIsSatisfied();
} finally {
commit 659920513807b095cdd0ac91c3f1c2e091d090a7
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Wed Sep 29 12:57:21 2010 +0200
Setting the height of the errorsGrid to a fixed value so that it stays at the bottom
of the page.
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/OverviewView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/OverviewView.java
index 95bec5f..b439d44 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/OverviewView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/summary/OverviewView.java
@@ -23,11 +23,7 @@ import org.rhq.core.domain.resource.composite.ResourceComposite;
import org.rhq.enterprise.gui.coregui.client.components.table.Table;
import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
-import com.smartgwt.client.data.DSCallback;
-import com.smartgwt.client.data.DSRequest;
-import com.smartgwt.client.data.DSResponse;
import com.smartgwt.client.types.Alignment;
-import com.smartgwt.client.types.GroupStartOpen;
import com.smartgwt.client.widgets.HTMLPane;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.Window;
@@ -44,13 +40,11 @@ import com.smartgwt.client.widgets.grid.events.CellClickHandler;
*/
public class OverviewView extends LocatableVLayout {
- private ResourceComposite resourceComposite;
private OverviewForm form;
private Table errorsGrid;
public OverviewView(String locatorId, ResourceComposite resourceComposite) {
super(locatorId);
- this.resourceComposite = resourceComposite;
form = new OverviewForm(extendLocatorId("form"), resourceComposite);
errorsGrid = new Table(extendLocatorId("errors"), "Detected
errors", null, null, new String[] { ResourceErrorsDataSource.DETAIL_ID });
@@ -61,7 +55,7 @@ public class OverviewView extends LocatableVLayout {
errorsGrid.setDataSource(errors);
form.setHeight("*");
- errorsGrid.setHeight("10%");
+ errorsGrid.setHeight(200); //this should be just enough to fit the maximum of 3
rows in this table (there's at most 1 error per type)
addMember(form);
addMember(errorsGrid);
commit c704c79f4acfedf4d959de6d7d27db1b22efa1f3
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Wed Sep 29 12:44:55 2010 +0200
Adding a bunch of test plugins for dependency resolution during resource upgrade
failure handling.
diff --git a/modules/core/plugin-container/pom.xml
b/modules/core/plugin-container/pom.xml
index 4b09ef8..035bf36 100644
--- a/modules/core/plugin-container/pom.xml
+++ b/modules/core/plugin-container/pom.xml
@@ -195,6 +195,106 @@
<fileset
dir="${project.build.testOutputDirectory}/tmp/failing"
includes="**/*.class,**/rhq-plugin.xml" />
</jar>
+ <copy
toDir="${project.build.testOutputDirectory}/tmp/multi/base/META-INF">
+ <fileset
file="${project.build.testSourceDirectory}/org/rhq/core/pc/upgrade/plugins/multi/base/rhq-plugin.xml"
/>
+ </copy>
+ <copy
toDir="${project.build.testOutputDirectory}/tmp/multi/base/org/rhq/core/pc/upgrade/plugins/multi/base">
+ <fileset
file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/base/*.class"
/>
+ </copy>
+ <jar
destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-base-1.0.0.jar">
+ <fileset
dir="${project.build.testOutputDirectory}/tmp/multi/base"
includes="**/*.class,**/rhq-plugin.xml" />
+ </jar>
+
+ <copy
toDir="${project.build.testOutputDirectory}/tmp/multi/parentdep1/META-INF">
+ <fileset
file="${project.build.testSourceDirectory}/org/rhq/core/pc/upgrade/plugins/multi/parentdep1/rhq-plugin.xml"
/>
+ </copy>
+ <!-- <copy
toDir="${project.build.testOutputDirectory}/tmp/multi/parentdep1/org/rhq/core/pc/upgrade/plugins/multi/parentdep1">
+ <fileset
file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/parentdep1/*.class"
/>
+ </copy> -->
+ <jar
destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-parentdep-1.0.0.jar">
+ <fileset
dir="${project.build.testOutputDirectory}/tmp/multi/parentdep1"
includes="**/*.class,**/rhq-plugin.xml" />
+ </jar>
+
+ <copy
toDir="${project.build.testOutputDirectory}/tmp/multi/parentdep2/META-INF">
+ <fileset
file="${project.build.testSourceDirectory}/org/rhq/core/pc/upgrade/plugins/multi/parentdep2/rhq-plugin.xml"
/>
+ </copy>
+ <!-- <copy
toDir="${project.build.testOutputDirectory}/tmp/multi/parentdep2/org/rhq/core/pc/upgrade/plugins/multi/parentdep2">
+ <fileset
file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/parentdep2/*.class"
/>
+ </copy> -->
+ <jar
destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-parentdep-2.0.0.jar">
+ <fileset
dir="${project.build.testOutputDirectory}/tmp/multi/parentdep2"
includes="**/*.class,**/rhq-plugin.xml" />
+ </jar>
+
+ <copy
toDir="${project.build.testOutputDirectory}/tmp/multi/parentsibling1/META-INF">
+ <fileset
file="${project.build.testSourceDirectory}/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml"
/>
+ </copy>
+ <!-- <copy
toDir="${project.build.testOutputDirectory}/tmp/multi/parentsibling1/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1">
+ <fileset
file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/*.class"
/>
+ </copy> -->
+ <jar
destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-parentsibling-1.0.0.jar">
+ <fileset
dir="${project.build.testOutputDirectory}/tmp/multi/parentsibling1"
includes="**/*.class,**/rhq-plugin.xml" />
+ </jar>
+
+ <copy
toDir="${project.build.testOutputDirectory}/tmp/multi/parentsibling2/META-INF">
+ <fileset
file="${project.build.testSourceDirectory}/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml"
/>
+ </copy>
+ <!-- <copy
toDir="${project.build.testOutputDirectory}/tmp/multi/parentsibling2/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2">
+ <fileset
file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/*.class"
/>
+ </copy> -->
+ <jar
destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-parentsibling-2.0.0.jar">
+ <fileset
dir="${project.build.testOutputDirectory}/tmp/multi/parentsibling2"
includes="**/*.class,**/rhq-plugin.xml" />
+ </jar>
+
+ <copy
toDir="${project.build.testOutputDirectory}/tmp/multi/root/META-INF">
+ <fileset
file="${project.build.testSourceDirectory}/org/rhq/core/pc/upgrade/plugins/multi/root/rhq-plugin.xml"
/>
+ </copy>
+ <!-- <copy
toDir="${project.build.testOutputDirectory}/tmp/multi/root/org/rhq/core/pc/upgrade/plugins/multi/root">
+ <fileset
file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/root/*.class"
/>
+ </copy> -->
+ <jar
destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-root-1.0.0.jar">
+ <fileset
dir="${project.build.testOutputDirectory}/tmp/multi/root"
includes="**/*.class,**/rhq-plugin.xml" />
+ </jar>
+
+ <copy
toDir="${project.build.testOutputDirectory}/tmp/multi/sibling1/META-INF">
+ <fileset
file="${project.build.testSourceDirectory}/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml"
/>
+ </copy>
+ <!-- <copy
toDir="${project.build.testOutputDirectory}/tmp/multi/sibling1/org/rhq/core/pc/upgrade/plugins/multi/sibling1">
+ <fileset
file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/sibling1/*.class"
/>
+ </copy> -->
+ <jar
destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-sibling-1.0.0.jar">
+ <fileset
dir="${project.build.testOutputDirectory}/tmp/multi/sibling1"
includes="**/*.class,**/rhq-plugin.xml" />
+ </jar>
+
+ <copy
toDir="${project.build.testOutputDirectory}/tmp/multi/sibling2/META-INF">
+ <fileset
file="${project.build.testSourceDirectory}/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml"
/>
+ </copy>
+ <!-- <copy
toDir="${project.build.testOutputDirectory}/tmp/multi/sibling2/org/rhq/core/pc/upgrade/plugins/multi/sibling2">
+ <fileset
file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/sibling2/*.class"
/>
+ </copy> -->
+ <jar
destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-sibling-2.0.0.jar">
+ <fileset
dir="${project.build.testOutputDirectory}/tmp/multi/sibling2"
includes="**/*.class,**/rhq-plugin.xml" />
+ </jar>
+
+ <copy
toDir="${project.build.testOutputDirectory}/tmp/multi/v1/META-INF">
+ <fileset
file="${project.build.testSourceDirectory}/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml"
/>
+ </copy>
+ <!-- <copy
toDir="${project.build.testOutputDirectory}/tmp/multi/v1/org/rhq/core/pc/upgrade/plugins/multi/v1">
+ <fileset
file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/v1/*.class"
/>
+ </copy> -->
+ <jar
destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-1.0.0.jar">
+ <fileset
dir="${project.build.testOutputDirectory}/tmp/multi/v1"
includes="**/*.class,**/rhq-plugin.xml" />
+ </jar>
+
+ <copy
toDir="${project.build.testOutputDirectory}/tmp/multi/v2/META-INF">
+ <fileset
file="${project.build.testSourceDirectory}/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml"
/>
+ </copy>
+ <!-- <copy
toDir="${project.build.testOutputDirectory}/tmp/multi/v2/org/rhq/core/pc/upgrade/plugins/multi/v2">
+ <fileset
file="${project.build.testOutputDirectory}/org/rhq/core/pc/upgrade/plugins/multi/v2/*.class"
/>
+ </copy> -->
+ <jar
destfile="${project.build.testOutputDirectory}/resource-upgrade-test-plugin-multi-2.0.0.jar">
+ <fileset
dir="${project.build.testOutputDirectory}/tmp/multi/v2"
includes="**/*.class,**/rhq-plugin.xml" />
+ </jar>
+
<delete
dir="${project.build.testOutputDirectory}/tmp"/>
</tasks>
</configuration>
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseDiscoveryComponent.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseDiscoveryComponent.java
new file mode 100644
index 0000000..61d4fe0
--- /dev/null
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseDiscoveryComponent.java
@@ -0,0 +1,70 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.core.pc.upgrade.plugins.multi.base;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.rhq.core.pluginapi.inventory.ResourceComponent;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
+
+/**
+ *
+ * @author Lukas Krejci
+ */
+public class BaseDiscoveryComponent<T extends ResourceComponent> implements
ResourceDiscoveryComponent<T> {
+
+ public Set<DiscoveredResourceDetails>
discoverResources(ResourceDiscoveryContext<T> context)
+ throws InvalidPluginConfigurationException, Exception {
+
+ HashSet<DiscoveredResourceDetails> results = new
HashSet<DiscoveredResourceDetails>();
+
+ Configuration pluginConfig = context.getDefaultPluginConfiguration();
+
+ String keyTemplate = pluginConfig.getSimpleValue("key", null);
+ int count = pluginConfig.getSimple("count").getIntegerValue();
+
+ int parentN =
context.getParentResourceContext().getPluginConfiguration().getSimple("ordinal")
+ .getIntegerValue();
+
+ for (int i = 0; i < count; ++i) {
+
+ String key = getResourceKey(keyTemplate, i, parentN);
+
+ pluginConfig.put(new PropertySimple("ordinal", i));
+
+ DiscoveredResourceDetails detail = new
DiscoveredResourceDetails(context.getResourceType(), key, key, null,
+ null, pluginConfig, null);
+
+ results.add(detail);
+ }
+
+ return results;
+ }
+
+ protected static String getResourceKey(String template, int n, int parentN) {
+ return template.replace("%n",
Integer.toString(n)).replace("%p", Integer.toString(parentN));
+ }
+}
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseResourceComponent.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseResourceComponent.java
new file mode 100644
index 0000000..c5bbf3a
--- /dev/null
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseResourceComponent.java
@@ -0,0 +1,67 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.core.pc.upgrade.plugins.multi.base;
+
+import java.util.Collections;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.measurement.AvailabilityType;
+import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
+import org.rhq.core.pluginapi.inventory.ResourceComponent;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+
+/**
+ *
+ * @author Lukas Krejci
+ */
+public class BaseResourceComponent<T extends ResourceComponent> implements
ResourceComponent<T> {
+
+ private ResourceContext<T> context;
+ private final Log log = LogFactory.getLog(getClass());
+
+ private Set<Integer> childrenToFailUpgrade;
+
+ public AvailabilityType getAvailability() {
+ return AvailabilityType.UP;
+ }
+
+ public void start(ResourceContext<T> context) throws
InvalidPluginConfigurationException, Exception {
+ log.info("Starting multi resource child component with resource key
'" + context.getResourceKey() + "'.");
+ this.context = context;
+ }
+
+ public void stop() {
+ log.info("Stopping multi resource child component with resource key
'" + context.getResourceKey() + "'.");
+ }
+
+ public int getOrdinal() {
+ return
context.getPluginConfiguration().getSimple("ordinal").getIntegerValue();
+ }
+
+ public Set<Integer> getChildrenToFailUpgrade() {
+ return childrenToFailUpgrade == null ? Collections.<Integer>emptySet() :
childrenToFailUpgrade;
+ }
+
+ public void setChildrenToFailUpgrade(Set<Integer> childrenToFailUpgrade) {
+ this.childrenToFailUpgrade = childrenToFailUpgrade;
+ }
+}
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseUpgradingDiscoveryComponent.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseUpgradingDiscoveryComponent.java
new file mode 100644
index 0000000..beb36db
--- /dev/null
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/BaseUpgradingDiscoveryComponent.java
@@ -0,0 +1,61 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2010 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.core.pc.upgrade.plugins.multi.base;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.resource.ResourceUpgradeReport;
+import org.rhq.core.pluginapi.upgrade.ResourceUpgradeContext;
+import org.rhq.core.pluginapi.upgrade.ResourceUpgradeFacet;
+
+/**
+ *
+ * @author Lukas Krejci
+ */
+public class BaseUpgradingDiscoveryComponent<T extends BaseResourceComponent>
extends BaseDiscoveryComponent<T> implements ResourceUpgradeFacet<T> {
+
+ public ResourceUpgradeReport upgrade(ResourceUpgradeContext<T>
inventoriedResource) {
+ Configuration pluginConfig = inventoriedResource.getPluginConfiguration();
+
+ BaseResourceComponent<?> parent =
inventoriedResource.getParentResourceComponent();
+ int ordinal = pluginConfig.getSimple("ordinal").getIntegerValue();
+ int parentOrdinal = parent == null ? 0 : parent.getOrdinal();
+
+ boolean fail =
Boolean.getBoolean(pluginConfig.getSimpleValue("failUpgrade",
"false"));
+
+ if (!fail && parent != null) {
+ fail = parent.getChildrenToFailUpgrade().contains(Integer.valueOf(ordinal));
+ }
+
+ if (fail) {
+ throw new RuntimeException("Failing the resource upgrade
purposefully.");
+ }
+
+ String newKey = pluginConfig.getSimpleValue("upgradedKey", null);
+
+ if (newKey == null) {
+ return null;
+ }
+
+ ResourceUpgradeReport report = new ResourceUpgradeReport();
+
+ report.setNewResourceKey(getResourceKey(newKey, ordinal, parentOrdinal));
+ return null;
+ }
+}
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/rhq-plugin.xml
new file mode 100644
index 0000000..7edfba1
--- /dev/null
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/base/rhq-plugin.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin name="ResourceUpgradeMultiTestBase"
+ displayName=""
+ description=""
+ package="org.rhq.core.pc.upgrade.plugins.multi.base"
+ version="1.0.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin"
+ xmlns:c="urn:xmlns:rhq-configuration">
+
+ <!--
+ Only the inheriting plugins create the concrete resources based on the
+ classes defined in this abstract base plugin.
+
+ These are the plugin configuration properties needed by the base plugin:
+
+ key = the template to create the resource key from
+ count = the number of resources to discover
+ upgradedKey = this *must* be specified on the resource type *to be upgraded* and
+ *must* be the same as the key template on the resource type that
+ it is upgraded to (i.e. the plugin.v1.upgradedKey ==
plugin.v2.key)
+
+ the discovery add a new property called "ordinal" to the plugin config
+ of the created resources, which contains the index of that resource amongst
+ its siblings.
+
+ the key template can contain %n which is replaced by the ordinal and %p which
+ is replaced by the ordinal of its parent.
+
+
+
+ if the discovery component of the concrete resource is (or inherits from)
+ BaseUpgradingDiscoveryComponent, it can specify further plugin config properties
+ influencing the upgrade:
+
+ failUpgrade = true to throw an exception during upgrade
+ -->
+
+</plugin>
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep1/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep1/rhq-plugin.xml
new file mode 100644
index 0000000..3612974
--- /dev/null
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep1/rhq-plugin.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<plugin name="ResourceUpgradeMultiTestParentDep"
+ displayName="Resource Upgrade Multi Test"
+ description="Resource Upgrade Multi Test"
+ package="org.rhq.core.pc.upgrade.plugins.multi.base"
+ version="1.0.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin"
+ xmlns:c="urn:xmlns:rhq-configuration">
+
+ <depends plugin="ResourceUpgradeMultiTestBase"
useClasses="true"/>
+ <depends plugin="ResourceUpgradeMultiTestRoot"/>
+
+ <server name="ParentDependency"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+
+ <runs-inside>
+ <parent-resource-type name="Root"
plugin="ResourceUpgradeMultiTestRoot"/>
+ </runs-inside>
+
+ <plugin-configuration>
+ <c:simple-property name="count" default="1" />
+ <c:simple-property name="key"
default="test-resource-parent-dep-%n,parent-%p" />
+ <c:simple-property name="upgradedKey"
default="UPGRADED-test-resource-parent-dep-%n,parent-%p" />
+ </plugin-configuration>
+
+ </server>
+
+</plugin>
+
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep2/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep2/rhq-plugin.xml
new file mode 100644
index 0000000..6b95114
--- /dev/null
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentdep2/rhq-plugin.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<plugin name="ResourceUpgradeMultiTestParentDep"
+ displayName="Resource Upgrade Multi Test"
+ description="Resource Upgrade Multi Test"
+ package="org.rhq.core.pc.upgrade.plugins.multi.base"
+ version="2.0.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin"
+ xmlns:c="urn:xmlns:rhq-configuration">
+
+ <depends plugin="ResourceUpgradeMultiTestBase"
useClasses="true"/>
+ <depends plugin="ResourceUpgradeMultiTestRoot"/>
+
+ <server name="ParentDependency"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+
+ <runs-inside>
+ <parent-resource-type name="Root"
plugin="ResourceUpgradeMultiTestRoot"/>
+ </runs-inside>
+
+ <plugin-configuration>
+ <c:simple-property name="count" default="1" />
+ <c:simple-property name="key"
default="UPGRADED-test-resource-parent-dep-%n,parent-%p" />
+ </plugin-configuration>
+
+ </server>
+
+</plugin>
+
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml
new file mode 100644
index 0000000..fbade54
--- /dev/null
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling1/rhq-plugin.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<plugin name="ResourceUpgradeMultiTestParentSibling"
+ displayName="Resource Upgrade Multi Test"
+ description="Resource Upgrade Multi Test"
+ package="org.rhq.core.pc.upgrade.plugins.multi.base"
+ version="1.0.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin"
+ xmlns:c="urn:xmlns:rhq-configuration">
+
+ <depends plugin="ResourceUpgradeMultiTestBase"
useClasses="true"/>
+ <depends plugin="ResourceUpgradeMultiTestRoot"/>
+
+ <server name="ParentDepSibling"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+
+ <runs-inside>
+ <parent-resource-type name="Root"
plugin="ResourceUpgradeMultiTestRoot"/>
+ </runs-inside>
+
+ <plugin-configuration>
+ <c:simple-property name="count" default="1" />
+ <c:simple-property name="key"
default="test-resource-parent-sibling-%n,parent-%p" />
+ <c:simple-property name="upgradedKey"
default="UPGRADED-test-resource-parent-sibling-%n,parent-%p" />
+ </plugin-configuration>
+
+ </server>
+
+</plugin>
+
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml
new file mode 100644
index 0000000..f16d526
--- /dev/null
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/parentsibling2/rhq-plugin.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<plugin name="ResourceUpgradeMultiTestParentSibling"
+ displayName="Resource Upgrade Multi Test"
+ description="Resource Upgrade Multi Test"
+ package="org.rhq.core.pc.upgrade.plugins.multi.base"
+ version="2.0.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin"
+ xmlns:c="urn:xmlns:rhq-configuration">
+
+ <depends plugin="ResourceUpgradeMultiTestBase"
useClasses="true"/>
+ <depends plugin="ResourceUpgradeMultiTestRoot"/>
+
+ <server name="ParentDepSibling"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+
+ <runs-inside>
+ <parent-resource-type name="Root"
plugin="ResourceUpgradeMultiTestRoot"/>
+ </runs-inside>
+
+ <plugin-configuration>
+ <c:simple-property name="count" default="1" />
+ <c:simple-property name="key"
default="UPGRADED-test-resource-parent-sibling-%n,parent-%p" />
+ </plugin-configuration>
+
+ </server>
+
+</plugin>
+
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/root/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/root/rhq-plugin.xml
new file mode 100644
index 0000000..b5efbb1
--- /dev/null
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/root/rhq-plugin.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<plugin name="ResourceUpgradeMultiTestRoot"
+ displayName=""
+ description=""
+ package="org.rhq.core.pc.upgrade.plugins.multi.base"
+ version="1.0.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin"
+ xmlns:c="urn:xmlns:rhq-configuration">
+
+ <server name="Root"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+
+ <plugin-configuration>
+ <c:simple-property name="count" default="1" />
+ <c:simple-property name="key"
default="test-resource-root-%n" />
+ </plugin-configuration>
+ </server>
+
+</plugin>
+
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml
new file mode 100644
index 0000000..f87ef4d
--- /dev/null
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling1/rhq-plugin.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<plugin name="ResourceUpgradeMultiTestSibling"
+ displayName="Resource Upgrade Multi Test"
+ description="Resource Upgrade Multi Test"
+ package="org.rhq.core.pc.upgrade.plugins.multi.base"
+ version="1.0.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin"
+ xmlns:c="urn:xmlns:rhq-configuration">
+
+ <depends plugin="ResourceUpgradeMultiTestBase"
useClasses="true"/>
+ <depends plugin="ResourceUpgradeMultiTestParentDep"/>
+
+ <server name="TestResourceParentSibling"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+
+ <plugin-configuration>
+ <c:simple-property name="count" default="2" />
+ <c:simple-property name="key"
default="test-resource-parent-sibling-%n,parent-%p" />
+ <c:simple-property name="upgradedKey"
default="UPGRADED-test-resource-parent-sibling-%n,parent-%p" />
+ </plugin-configuration>
+
+ <service name="TestResourceSibling"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+ <plugin-configuration>
+ <c:simple-property name="count" default="10" />
+ <c:simple-property name="key"
default="test-resource-sibling-%n,parent-%p" />
+ <c:simple-property name="upgradedKey"
default="UPGRADED-test-resource-sibling-%n,parent-%p" />
+ </plugin-configuration>
+
+ </service>
+ </server>
+
+</plugin>
+
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml
new file mode 100644
index 0000000..e6ab95f
--- /dev/null
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/sibling2/rhq-plugin.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin name="ResourceUpgradeMultiTestSibling"
+ displayName="Resource Upgrade Multi Test"
+ description="Resource Upgrade Multi Test"
+ package="org.rhq.core.pc.upgrade.plugins.multi.base"
+ version="2.0.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin"
+ xmlns:c="urn:xmlns:rhq-configuration">
+
+ <depends plugin="ResourceUpgradeMultiTestBase"
useClasses="true"/>
+ <depends plugin="ResourceUpgradeMultiTestParentDep"/>
+
+ <server name="TestResourceParentSibling"
+ discovery="BaseUpgradingDiscoveryComponent"
+ class="BaseResourceComponent">
+
+ <runs-inside>
+ <parent-resource-type name="ParentDependency"
plugin="ResourceUpgradeMultiTestParentDep"/>
+ </runs-inside>
+
+ <plugin-configuration>
+ <c:simple-property name="count" default="2" />
+ <c:simple-property name="key"
default="UPGRADED-test-resource-parent-sibling-%n,parent-%p" />
+ </plugin-configuration>
+
+ <service name="TestResourceSibling"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+ <plugin-configuration>
+ <c:simple-property name="count" default="15" />
+ <c:simple-property name="key"
default="UPGRADED-test-resource-sibling-%n,parent-%p" />
+ </plugin-configuration>
+
+ </service>
+
+
+ </server>
+
+</plugin>
+
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml
new file mode 100644
index 0000000..32ad438
--- /dev/null
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v1/rhq-plugin.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<plugin name="ResourceUpgradeMultiTest"
+ displayName="Resource Upgrade Multi Test"
+ description="Resource Upgrade Multi Test"
+ package="org.rhq.core.pc.upgrade.plugins.multi.base"
+ version="1.0.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin"
+ xmlns:c="urn:xmlns:rhq-configuration">
+
+ <depends plugin="ResourceUpgradeMultiTestBase"
useClasses="true"/>
+ <depends plugin="ResourceUpgradeMultiTestParentDep"/>
+
+ <server name="TestResourceParent"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+
+ <runs-inside>
+ <parent-resource-type name="ParentDependency"
plugin="ResourceUpgradeMultiTestParentDep"/>
+ </runs-inside>
+
+ <plugin-configuration>
+ <c:simple-property name="count" default="2" />
+ <c:simple-property name="key"
default="test-resource-parent-%n,parent-%p" />
+ <c:simple-property name="upgradedKey"
default="UPGRADED-test-resource-parent-%n,parent-%p" />
+ </plugin-configuration>
+
+ <service name="TestResource"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+ <plugin-configuration>
+ <c:simple-property name="count" default="10" />
+ <c:simple-property name="key"
default="test-resource-%n,parent-%p" />
+ <c:simple-property name="upgradedKey"
default="UPGRADED-test-resource-%n,parent-%p" />
+ </plugin-configuration>
+
+ </service>
+ </server>
+
+</plugin>
+
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml
new file mode 100644
index 0000000..824d3fe
--- /dev/null
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/upgrade/plugins/multi/v2/rhq-plugin.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin name="ResourceUpgradeMultiTest"
+ displayName="Resource Upgrade Multi Test"
+ description="Resource Upgrade Multi Test"
+ package="org.rhq.core.pc.upgrade.plugins.multi.base"
+ version="2.0.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:xmlns:rhq-plugin"
+ xmlns:c="urn:xmlns:rhq-configuration">
+
+ <depends plugin="ResourceUpgradeMultiTestBase"
useClasses="true"/>
+ <depends plugin="ResourceUpgradeMultiTestParentDep"/>
+
+ <server name="TestResourceParent"
+ discovery="BaseUpgradingDiscoveryComponent"
+ class="BaseResourceComponent">
+
+ <runs-inside>
+ <parent-resource-type name="ParentDependency"
plugin="ResourceUpgradeMultiTestParentDep"/>
+ </runs-inside>
+
+ <plugin-configuration>
+ <c:simple-property name="count" default="2" />
+ <c:simple-property name="key"
default="UPGRADED-test-resource-parent-%n,parent-%p" />
+ </plugin-configuration>
+
+ <service name="TestResource"
+ discovery="BaseDiscoveryComponent"
+ class="BaseResourceComponent">
+ <plugin-configuration>
+ <c:simple-property name="count" default="15" />
+ <c:simple-property name="key"
default="UPGRADED-test-resource-%n,parent-%p" />
+ </plugin-configuration>
+
+ </service>
+
+
+ </server>
+
+</plugin>
+