modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/ClearPersistedData.java
| 70 ++++
modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/FakeServerInventory.java
| 16
modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/When.java
| 31 +
modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/DataCleanupExecutor.java
| 170 ++++++++++
modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/RhqAgentPluginContainer.java
| 25 +
modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/RhqAgentPluginContainerConfiguration.java
| 12
modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/RhqAgentPluginContainerExtension.java
| 3
modules/core/arquillian-integration/container/src/test/java/org/rhq/test/arquillian/CleanUpTest.java
| 154 +++++++++
modules/core/arquillian-integration/container/src/test/java/org/rhq/test/arquillian/TestResourceComponent.java
| 24 +
modules/core/arquillian-integration/container/src/test/resources/arquillian.xml
| 8
10 files changed, 498 insertions(+), 15 deletions(-)
New commits:
commit bd0c4929b07ef9d481a3031aa01434cd38e9f8a5
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Mar 29 18:04:50 2013 +0100
@ClearPersistedData annotation handling in Arq plugin container tests.
The tests can declare the @ClearPersistedData annotation on the test to
define what of the data that plugin container and its plugins store,
and when should be cleared prior or after the test execution.
diff --git
a/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/ClearPersistedData.java
b/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/ClearPersistedData.java
new file mode 100644
index 0000000..c37eca7
--- /dev/null
+++
b/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/ClearPersistedData.java
@@ -0,0 +1,70 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2013 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, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * 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 and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.test.arquillian;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * When a test method is annotated with this annotation, the data persisted by the plugin
container during its lifetime
+ * can be automatically cleaned up.
+ *
+ * @author Lukas Krejci
+ */
+(a)Retention(RetentionPolicy.RUNTIME)
+(a)Target(ElementType.METHOD)
+public @interface ClearPersistedData {
+
+ /**
+ * Special marker string to express the wish to affect all the plugins.
+ */
+ final String ALL_PLUGINS = "__ALL__";
+
+ /**
+ * The time when the clearing of the data should occur.
+ * Defaults to before the invocation of the test method but can also be after or
both.
+ */
+ When[] when() default { When.BEFORE_TEST };
+
+ /**
+ * Whether to clear the inventory.dat file (i.e. the persisted inventory).
+ * Defaults to true.
+ */
+ boolean ofInventory() default true;
+
+ /**
+ * Whether to clear the "changesets" directory storing the drift data.
+ * Defaults to true.
+ */
+ boolean ofDrift() default true;
+
+ /**
+ * The list of the names of the plugins to clear the data of.
+ * Defaults to list containing the special {@link #ALL_PLUGINS} string that means to
delete
+ * the data of all plugins.
+ */
+ String[] ofPlugins() default { ALL_PLUGINS };
+}
diff --git
a/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/FakeServerInventory.java
b/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/FakeServerInventory.java
index b1ac175..96b86e1 100644
---
a/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/FakeServerInventory.java
+++
b/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/FakeServerInventory.java
@@ -82,12 +82,14 @@ public class FakeServerInventory {
* @author Lukas Krejci
*/
public static class CompleteDiscoveryChecker {
- private boolean depthReached;
+ private volatile boolean depthReached;
private final int expectedDepth;
private final Object sync = new Object();
+ private volatile boolean finished;
public CompleteDiscoveryChecker(int expectedDepth) {
this.expectedDepth = expectedDepth;
+ this.depthReached = expectedDepth == 0;
}
public void waitForDiscoveryComplete() throws InterruptedException {
@@ -106,6 +108,8 @@ public class FakeServerInventory {
LOG.debug("Discovery already complete... no need to wait on
" + this);
}
}
+
+ finished = true;
}
}
@@ -132,11 +136,13 @@ public class FakeServerInventory {
} catch (InterruptedException e) {
//well, we are going to finish in a few anyway
} finally {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Notifying about discovery complete on
" + CompleteDiscoveryChecker.this);
- }
synchronized (sync) {
- sync.notifyAll();
+ if (!finished) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Notifying about discovery
complete on " + CompleteDiscoveryChecker.this);
+ }
+ sync.notifyAll();
+ }
}
}
}
diff --git
a/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/When.java
b/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/When.java
new file mode 100644
index 0000000..1910a66
--- /dev/null
+++
b/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/When.java
@@ -0,0 +1,31 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2013 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, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * 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 and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.test.arquillian;
+
+/**
+* @author Lukas Krejci
+*/
+public enum When {
+ BEFORE_TEST, AFTER_TEST
+}
diff --git
a/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/DataCleanupExecutor.java
b/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/DataCleanupExecutor.java
new file mode 100644
index 0000000..a823e23
--- /dev/null
+++
b/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/DataCleanupExecutor.java
@@ -0,0 +1,170 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2013 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, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * 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 and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.test.arquillian.impl;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.jboss.arquillian.core.api.Instance;
+import org.jboss.arquillian.core.api.annotation.Inject;
+import org.jboss.arquillian.core.api.annotation.Observes;
+import org.jboss.arquillian.test.spi.event.suite.After;
+
+import org.rhq.core.util.file.FileUtil;
+import org.rhq.test.arquillian.ClearPersistedData;
+import org.rhq.test.arquillian.When;
+import org.rhq.test.arquillian.spi.events.PluginContainerDiscovered;
+
+/**
+ * @author Lukas Krejci
+ */
+public class DataCleanupExecutor {
+
+ private static final String INVENTORY_DAT = "inventory.dat";
+ private static final Log LOG = LogFactory.getLog(DataCleanupExecutor.class);
+
+ @Inject
+ private Instance<RhqAgentPluginContainer> pcContainer;
+
+ public void process(@Observes PluginContainerDiscovered pcDiscovered) {
+ doCleanup(pcDiscovered.getTestMethod(), true);
+ }
+
+ public void process(@Observes After test) {
+ doCleanup(test.getTestMethod(), false);
+ }
+
+ private void doCleanup(Method testMethod, boolean isBefore) {
+ ClearPersistedData clearData =
testMethod.getAnnotation(ClearPersistedData.class);
+ if (clearData != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Clean up for: " + testMethod);
+ }
+
+ //b a x y
+ //0 0 0 nogo
+ //0 0 1 nogo
+ //0 1 0 go
+ //0 1 1 nogo
+ //1 0 0 nogo
+ //1 0 1 go
+ //1 1 0 go
+ //1 1 1 go
+ EnumSet<When> when = toEnumSet(When.class, clearData.when());
+ boolean hasBefore = when.contains(When.BEFORE_TEST);
+ boolean hasAfter = when.contains(When.AFTER_TEST);
+
+ if ((!hasBefore && !hasAfter) ||
+ (!hasBefore && isBefore) ||
+ (hasBefore && !hasAfter && !isBefore)) {
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Skipping clean up. Currently " + (isBefore ?
"before" : "after") + " test but scheduled to run:" +
when);
+ }
+ return;
+ }
+
+ LOG.info("Stopping Plugin Container to clean up data");
+ pcContainer.get().stopPc();
+
+ File dataDir = pcContainer.get().getConfiguration().getDataDirectory();
+ File tmpDir = pcContainer.get().getConfiguration().getTemporaryDirectory();
+
+ FileUtil.purge(tmpDir, false);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Purged temp dir");
+ }
+
+ if (clearData.ofInventory()) {
+ File inventoryDat = new File(dataDir, INVENTORY_DAT);
+ if (inventoryDat.exists()) {
+ inventoryDat.delete();
+ }
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Purged inventory dat");
+ }
+ }
+
+ if (clearData.ofDrift()) {
+ FileUtil.purge(new File(dataDir, "changesets"), false);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Purged drift changesets");
+ }
+ }
+
+ List<String> plugins = Arrays.asList(clearData.ofPlugins());
+ if (plugins.contains(ClearPersistedData.ALL_PLUGINS)) {
+ removeAllDataBut(dataDir, new String[] {"inventory.dat",
"changesets"});
+ } else {
+ for(String n : plugins) {
+ FileUtil.purge(new File(dataDir, n), true);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Purged plugin dir: " + n);
+ }
+ }
+ }
+
+ LOG.info("Starting Plugin Container after data cleanup.");
+ pcContainer.get().startPc();
+ }
+ }
+
+ private void removeAllDataBut(File dataDir, final String[] excludedNames) {
+ File[] files = dataDir.listFiles(new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ for(String n : excludedNames) {
+ if (name.equals(n)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+ });
+
+ for(File f : files) {
+ FileUtil.purge(f, true);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Purged dir: " + f.getName());
+ }
+ }
+ }
+
+ private <T extends Enum<T>> EnumSet<T> toEnumSet(Class<T> c,
T... values) {
+ EnumSet<T> ret = EnumSet.noneOf(c);
+ for(T e : values) {
+ ret.add(e);
+ }
+
+ return ret;
+ }
+}
diff --git
a/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/RhqAgentPluginContainer.java
b/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/RhqAgentPluginContainer.java
index 917fc67..0950865 100644
---
a/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/RhqAgentPluginContainer.java
+++
b/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/RhqAgentPluginContainer.java
@@ -47,6 +47,7 @@ import
org.jboss.arquillian.container.spi.client.protocol.ProtocolDescription;
import org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData;
import org.jboss.arquillian.core.api.Instance;
import org.jboss.arquillian.core.api.annotation.Inject;
+import org.jboss.arquillian.test.spi.annotation.TestScoped;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ArchivePath;
import org.jboss.shrinkwrap.api.ArchivePaths;
@@ -342,9 +343,12 @@ public class RhqAgentPluginContainer implements
DeployableContainer<RhqAgentPlug
/**
* Starts the plugin container.
+ * This method is package private so that other instances can start/stop the PC the
same way as the container
+ * itself even outside the default lifecycle of the container.
+ *
* @return true if the plugin container needed to be started (i.e. was not running
before), false otherwise.
*/
- private boolean startPc() {
+ boolean startPc() {
LOG.debug("Starting PluginContainer on demand...");
PluginContainer pc = PluginContainer.getInstance();
@@ -367,9 +371,12 @@ public class RhqAgentPluginContainer implements
DeployableContainer<RhqAgentPlug
/**
* Stops the plugin container.
+ * This method is package private so that other instances can start/stop the PC the
same way as the container
+ * itself even outside the default lifecycle of the container.
+ *
* @return true if PC was running before this call, false otherwise
*/
- private boolean stopPc() {
+ boolean stopPc() {
LOG.debug("Stopping PluginContainer on demand...");
PluginContainer pc = PluginContainer.getInstance();
boolean wasStarted = pc.isStarted();
diff --git
a/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/RhqAgentPluginContainerExtension.java
b/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/RhqAgentPluginContainerExtension.java
index c5f23c9..342727c 100644
---
a/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/RhqAgentPluginContainerExtension.java
+++
b/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/RhqAgentPluginContainerExtension.java
@@ -49,7 +49,8 @@ public class RhqAgentPluginContainerExtension implements
LoadableExtension {
.observer(PluginContainerPreparatorExecutor.class)
.observer(PluginContainerOperationExecutor.class)
.observer(PluginContainerRemedyExecutor.class)
- .observer(PostPrepareEnricherExecutor.class);
+ .observer(PostPrepareEnricherExecutor.class)
+ .observer(DataCleanupExecutor.class);
builder.service(DeployableContainer.class, RhqAgentPluginContainer.class)
.service(ResourceProvider.class, PluginContainerProvider.class)
diff --git
a/modules/core/arquillian-integration/container/src/test/java/org/rhq/test/arquillian/CleanUpTest.java
b/modules/core/arquillian-integration/container/src/test/java/org/rhq/test/arquillian/CleanUpTest.java
new file mode 100644
index 0000000..4483cba
--- /dev/null
+++
b/modules/core/arquillian-integration/container/src/test/java/org/rhq/test/arquillian/CleanUpTest.java
@@ -0,0 +1,154 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2013 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, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * 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 and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.test.arquillian;
+
+import java.util.Arrays;
+import java.util.HashSet;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.when;
+import static org.testng.Assert.assertEquals;
+
+import org.testng.annotations.Test;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.container.test.api.TargetsContainer;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.arquillian.testng.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+
+import org.rhq.core.clientapi.server.discovery.InventoryReport;
+import org.rhq.core.domain.resource.InventoryStatus;
+import org.rhq.core.pc.PluginContainerConfiguration;
+import org.rhq.test.shrinkwrap.RhqAgentPluginArchive;
+
+/**
+ * @author Lukas Krejci
+ */
+public class CleanUpTest extends Arquillian {
+
+ @Deployment(name = "1")
+ @TargetsContainer("cleaned-up-pc")
+ public static RhqAgentPluginArchive getDeepTestPlugin() {
+ return ShrinkWrap.create(RhqAgentPluginArchive.class,
"test-cleanup-deep-plugin-1.0.0.jar")
+ .addClasses(TestDiscoveryComponent.class, TestResourceComponent.class)
+ .setPluginDescriptor("test-deep-rhq-plugin.xml");
+ }
+
+ @Deployment(name = "2")
+ @TargetsContainer("cleaned-up-pc")
+ public static RhqAgentPluginArchive getTestPlugin() {
+ return ShrinkWrap.create(RhqAgentPluginArchive.class,
"test-cleanup-plugin-1.0.0.jar")
+ .addClasses(TestDiscoveryComponent.class, TestResourceComponent.class)
+ .setPluginDescriptor("test-rhq-plugin.xml");
+ }
+
+ @ArquillianResource
+ private PluginContainerConfiguration pluginContainerConfig;
+
+ @ArquillianResource
+ private MockingServerServices serverServices;
+
+ private FakeServerInventory fakeServerInventory;
+ private FakeServerInventory.CompleteDiscoveryChecker discoveryCompleteChecker;
+
+ private void setupDiscoveryServerMocks(int expectedDiscoveryDepth) throws Exception
{
+ serverServices.resetMocks();
+ fakeServerInventory = new FakeServerInventory();
+ discoveryCompleteChecker =
fakeServerInventory.createAsyncDiscoveryCompletionChecker(expectedDiscoveryDepth);
+ //autoimport everything
+
when(serverServices.getDiscoveryServerService().mergeInventoryReport(any(InventoryReport.class))).then(
+ fakeServerInventory.mergeInventoryReport(InventoryStatus.COMMITTED));
+ }
+
+ @BeforeDiscovery(testMethods = {"testCleanAll",
"testClearingAfterTest",
"checkDiscoveryCanRunFullBecauseInventoryClear"})
+ public void setupDiscoveryMocksWithCleanInventory() throws Exception {
+ setupDiscoveryServerMocks(3);
+ }
+
+ @BeforeDiscovery(testMethods = "testCleanAllButInventoryDat")
+ public void setupDiscoveryMocksWithInventory() throws Exception {
+ //do nothing here... we want the faked server to pretend the stuff was left in
it.
+ //we don't want the agent to think that it has obsolete resources which would
cause it
+ //to stop the resources from the persisted inventory, which would cause our
marker files
+ //to be put on the filesystem and fail the test.
+ }
+
+ @AfterDiscovery(testMethods = {"testCleanAll",
"testClearingAfterTest",
"checkDiscoveryCanRunFullBecauseInventoryClear"})
+ public void waitForAsyncDiscoveries() throws Exception {
+ if (discoveryCompleteChecker != null) {
+ discoveryCompleteChecker.waitForDiscoveryComplete();
+ }
+ }
+
+ @RunDiscovery
+ @ClearPersistedData
+ @Test
+ public void testCleanAll() {
+ String[] files = pluginContainerConfig.getDataDirectory().list();
+ assertExpected(files, new String[]{}, "No other files should be in the data
dir.");
+ }
+
+ @RunDiscovery
+ @ClearPersistedData(ofInventory = false)
+ @Test(dependsOnMethods = "testCleanAll")
+ public void testCleanAllButInventoryDat() {
+ String[] files = pluginContainerConfig.getDataDirectory().list();
+ assertExpected(files, new String[]{"inventory.dat"}, "No other
files should be in the data dir.");
+ }
+
+ @RunDiscovery
+ @ClearPersistedData(ofPlugins = {})
+ @Test(dependsOnMethods = "testCleanAllButInventoryDat")
+ public void testCleanJustInventoryDat() {
+ String[] files = pluginContainerConfig.getDataDirectory().list();
+
+ assertExpected(files, new String[]{"testDeepPlugin",
"testPlugin"},
+ "No other files should be in the data dir.");
+ }
+
+ @ClearPersistedData(when = {When.AFTER_TEST})
+ @Test(dependsOnMethods = "testCleanJustInventoryDat")
+ public void testClearingAfterTest() {
+ //nothing to be done here... we just want stuff to be cleared after this test
+ //and actually check in the next test that it was successful
+ }
+
+ @RunDiscovery
+ @Test(dependsOnMethods = "testClearingAfterTest")
+ public void checkClearAfterTestWorked() {
+ String[] files = pluginContainerConfig.getDataDirectory().list();
+ assertExpected(files, new String[]{}, "No other files should be in the data
dir.");
+ }
+
+ private void assertExpected(String[] actualFiles, String[] expectedFiles, String
message) {
+ HashSet<Object> sActual = new
HashSet<Object>(Arrays.asList(actualFiles));
+ HashSet<Object> sExpected = new
HashSet<Object>(Arrays.asList(expectedFiles));
+
+ //the "changesets" directory is going to always be there because it is
eagerly created during PC startup.
+ sExpected.add("changesets");
+
+ assertEquals(sActual, sExpected, message);
+ }
+}
diff --git
a/modules/core/arquillian-integration/container/src/test/java/org/rhq/test/arquillian/TestResourceComponent.java
b/modules/core/arquillian-integration/container/src/test/java/org/rhq/test/arquillian/TestResourceComponent.java
index cd19c25..3fe50d5 100644
---
a/modules/core/arquillian-integration/container/src/test/java/org/rhq/test/arquillian/TestResourceComponent.java
+++
b/modules/core/arquillian-integration/container/src/test/java/org/rhq/test/arquillian/TestResourceComponent.java
@@ -19,6 +19,12 @@
package org.rhq.test.arquillian;
+import java.io.File;
+import java.io.IOException;
+
+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;
@@ -31,6 +37,10 @@ import org.rhq.core.pluginapi.inventory.ResourceContext;
*/
public class TestResourceComponent implements
ResourceComponent<ResourceComponent<?>> {
+ private static final Log LOG = LogFactory.getLog(TestResourceComponent.class);
+
+ private ResourceContext<?> context;
+
@Override
public AvailabilityType getAvailability() {
return AvailabilityType.UP;
@@ -39,9 +49,23 @@ public class TestResourceComponent implements
ResourceComponent<ResourceComponen
@Override
public void start(ResourceContext<ResourceComponent<?>> context) throws
InvalidPluginConfigurationException,
Exception {
+
+ this.context = context;
}
@Override
public void stop() {
+ context.getDataDirectory().mkdirs();
+ try {
+ File f = new File(context.getDataDirectory(), "test-plugin.data");
+ if (!f.exists()) {
+ f.createNewFile();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Create file " + f);
+ }
+ }
+ } catch (IOException e) {
+ throw new IllegalStateException("Could not touch a marker file.");
+ }
}
}
diff --git
a/modules/core/arquillian-integration/container/src/test/resources/arquillian.xml
b/modules/core/arquillian-integration/container/src/test/resources/arquillian.xml
index 3bf9e46..134cac4 100644
--- a/modules/core/arquillian-integration/container/src/test/resources/arquillian.xml
+++ b/modules/core/arquillian-integration/container/src/test/resources/arquillian.xml
@@ -25,6 +25,14 @@
<property
name="nativeSystemInfoEnabled">true</property>
</configuration>
</container>
+
+ <container qualifier="cleaned-up-pc">
+ <configuration>
+ <property name="startManagementBean">false</property>
+ <property name="insideAgent">true</property>
+ <property
name="serverServicesImplementationClassName">org.rhq.test.arquillian.MockingServerServices</property>
+ </configuration>
+ </container>
</group>
<!-- We actually have to exclude all the classes from instrumentation by Arquillian
Jacoco extension, because our
commit 8cfcd136621c1d5241cea4156154bf0e07712c75
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Wed Mar 27 09:58:53 2013 +0100
Arq support for cleaning PC's data dir on shutdown.
It can now be done using the "clearDataOnShutdown" configuration
property in the container configuration in arquillian.xml.
diff --git
a/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/RhqAgentPluginContainer.java
b/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/RhqAgentPluginContainer.java
index 203e2bb..917fc67 100644
---
a/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/RhqAgentPluginContainer.java
+++
b/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/RhqAgentPluginContainer.java
@@ -95,8 +95,6 @@ public class RhqAgentPluginContainer implements
DeployableContainer<RhqAgentPlug
sigar = new File(root, "sigar");
sigar.mkdir();
} catch (IOException e) {
- root = null;
- deployments = null;
throw new IllegalStateException(
"Could not create the root directory for RHQ plugin container test
deployments");
}
@@ -374,17 +372,23 @@ public class RhqAgentPluginContainer implements
DeployableContainer<RhqAgentPlug
private boolean stopPc() {
LOG.debug("Stopping PluginContainer on demand...");
PluginContainer pc = PluginContainer.getInstance();
- if (pc.isStarted()) {
+ boolean wasStarted = pc.isStarted();
+ if (wasStarted) {
boolean shutdownGracefully = pc.shutdown();
if (shutdownGracefully) {
LOG.debug("Stopped PluginContainer gracefully.");
} else {
LOG.debug("Stopped PluginContainer.");
}
- return true;
}
- return false;
+ FileUtil.purge(configuration.getTemporaryDirectory(), false);
+
+ if (configuration.isClearDataOnShutdown()) {
+ FileUtil.purge(configuration.getDataDirectory(), false);
+ }
+
+ return wasStarted;
}
private void deployPlugin(RhqAgentPluginArchive plugin) {
diff --git
a/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/RhqAgentPluginContainerConfiguration.java
b/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/RhqAgentPluginContainerConfiguration.java
index cdc697d..3fc34eb 100644
---
a/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/RhqAgentPluginContainerConfiguration.java
+++
b/modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/impl/RhqAgentPluginContainerConfiguration.java
@@ -18,7 +18,8 @@ public class RhqAgentPluginContainerConfiguration extends
PluginContainerConfigu
private String serverServicesImplementationClassName;
private boolean nativeSystemInfoEnabled;
private String additionalPackagesForRootPluginClassLoaderToExclude;
-
+ private boolean clearDataOnShutdown;
+
private static final long HUNDRED_YEARS = 100L * 365 * 24 * 60 * 60;
public RhqAgentPluginContainerConfiguration() {
@@ -95,6 +96,14 @@ public class RhqAgentPluginContainerConfiguration extends
PluginContainerConfigu
setRootPluginClassLoaderRegex(newRegex.toString());
}
+ public boolean isClearDataOnShutdown() {
+ return clearDataOnShutdown;
+ }
+
+ public void setClearDataOnShutdown(boolean clearDataOnShutdown) {
+ this.clearDataOnShutdown = clearDataOnShutdown;
+ }
+
@Override
public void validate() throws ConfigurationException {
RhqAgentPluginContainer.init();
@@ -113,5 +122,4 @@ public class RhqAgentPluginContainerConfiguration extends
PluginContainerConfigu
+ getServerServicesImplementationClassName() + "].", e);
}
}
-
}