modules/core/arquillian-integration/container/src/main/java/org/rhq/test/arquillian/FakeServerInventory.java
| 9 -
modules/core/plugin-container/pom.xml
| 1
modules/core/plugin-test-util/src/main/java/org/rhq/core/plugin/testutil/AbstractAgentPluginTest.java
| 13 +
modules/plugins/jboss-as-7/pom.xml
| 22 ++
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
| 17 +-
modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/standalone/DeploymentRuntimeResourcesTest.java
| 84 ++++++----
modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/standalone/DeploymentTest.java
| 45 +++--
pom.xml
| 6
8 files changed, 138 insertions(+), 59 deletions(-)
New commits:
commit 11125dd1eb846cb9350bcf9b49c3176869e4e304
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Wed Jan 29 14:08:21 2014 -0500
AS7 i-test work, try to get these mf's working... I'm sure this won't
solve
everything but hopefully gets us closer - I want to see what jenkins does now...
- allow superclass mock decls to get defined each time discovery resets
the mocks. (get rid of fake tests annotated with @ServerServicesSetup)
- generate consistent resource ids in the arquillian fake inventory to
avoid mismatch betweeen the PC and the fake server inv.
- do a better job of mvn clean for the as7 itest env
- report 0 byte content uploads to sys out
- remove some (seemingly?) unnecessary class-level annotations
- remove some (seemingly?) unnecessary test sleeps
- beef up the deployment upload method
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 0c66be8..a553a5d 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
@@ -154,7 +154,7 @@ public class FakeServerInventory {
private Resource platform;
private Map<String, Resource> resourceStore = new HashMap<String,
Resource>();
- private int counter;
+ //private int counter;
private AtomicInteger metricScheduleCounter = new AtomicInteger(1); // used when
creating measurement schedules
private boolean failing;
private boolean failUpgrade;
@@ -576,10 +576,11 @@ public class FakeServerInventory {
}
if (persisted == null) {
persisted = new Resource();
- if (agentSideResource.getId() != 0 && counter <
agentSideResource.getId()) {
- counter = agentSideResource.getId() - 1;
+ if (agentSideResource.getId() != 0) {
+ persisted.setId(agentSideResource.getId());
+ } else {
+ persisted.setId(agentSideResource.getUuid().hashCode());
}
- persisted.setId(++counter);
persisted.setUuid(agentSideResource.getUuid());
persisted.setAgent(agentSideResource.getAgent());
persisted.setCurrentAvailability(agentSideResource.getCurrentAvailability());
diff --git
a/modules/core/plugin-test-util/src/main/java/org/rhq/core/plugin/testutil/AbstractAgentPluginTest.java
b/modules/core/plugin-test-util/src/main/java/org/rhq/core/plugin/testutil/AbstractAgentPluginTest.java
index 74773c2..c7a2333 100644
---
a/modules/core/plugin-test-util/src/main/java/org/rhq/core/plugin/testutil/AbstractAgentPluginTest.java
+++
b/modules/core/plugin-test-util/src/main/java/org/rhq/core/plugin/testutil/AbstractAgentPluginTest.java
@@ -153,6 +153,17 @@ public abstract class AbstractAgentPluginTest extends Arquillian {
}
/**
+ * Superclass can override this to add additional mocked services to those already
+ * defined in this abstract base class. The base class will call for injection each
+ * time the mocks are reset.
+ *
+ * @param serverServices
+ */
+ protected void injectMocks(MockingServerServices serverServices) {
+ return;
+ }
+
+ /**
* Set up our fake server discovery ServerService, which will auto-import all
Resources in reports it receives.
*
* @throws Exception if an error occurs
@@ -174,6 +185,8 @@ public abstract class AbstractAgentPluginTest extends Arquillian {
serverInventory.mergeInventoryReport(InventoryStatus.COMMITTED));
Mockito.when(serverServices.getDiscoveryServerService().getResourceSyncInfo(Mockito.any(int.class))).then(
serverInventory.getResourceSyncInfo());
+
+ injectMocks(this.serverServices);
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/modules/plugins/jboss-as-7/pom.xml b/modules/plugins/jboss-as-7/pom.xml
index bfeb587..28d33ff 100644
--- a/modules/plugins/jboss-as-7/pom.xml
+++ b/modules/plugins/jboss-as-7/pom.xml
@@ -448,17 +448,35 @@
</configuration>
</execution>
<execution>
- <id>delete</id>
+ <id>delete-post</id>
<phase>post-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
+ <echo>*** Deleting AS7 ${jboss7.home}...</echo>
<delete dir="${jboss7.home}" />
+ <echo>*** Deleting data ./data...</echo>
+ <delete dir="./data" />
</target>
</configuration>
</execution>
+ <execution>
+ <id>delete-clean</id>
+ <phase>clean</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <target>
+ <echo>*** Deleting AS7 ${jboss7.home}...</echo>
+ <delete dir="${jboss7.home}" />
+ <echo>*** Deleting data ./data...</echo>
+ <delete dir="./data" />
+ </target>
+ </configuration>
+ </execution>
</executions>
</plugin>
@@ -609,7 +627,7 @@
<skipITs>false</skipITs>
<includes>
<!-- only include integration tests; normal unit tests are handled
above by surefire plugin -->
-
<include>org/rhq/modules/plugins/jbossas7/itest/**/*Test.java</include>
+
<include>org/rhq/modules/plugins/jbossas7/itest/**/DeploymentTest.java</include>
<!--<include>org/rhq/modules/plugins/jbossas7/itest/standalone/StandaloneServerComponentTest.java</include>-->
<!--<include>org/rhq/modules/plugins/jbossas7/itest/standalone/InterruptibleOperationsTest.java</include>-->
<!--<include>org/rhq/modules/plugins/jbossas7/itest/standalone/DeploymentTest.java</include>-->
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
index 2451743..000d08c 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
@@ -457,15 +457,28 @@ public class BaseComponent<T extends
ResourceComponent<?>> implements AS7Compone
report.setErrorMessage("An error occured while the agent was preparing
for content download");
return report;
}
+
+ long size = 0L;
try {
- contentServices.downloadPackageBitsForChildResource(cctx, resourceTypeName,
details.getKey(), out);
+ size = contentServices.downloadPackageBitsForChildResource(cctx,
resourceTypeName, details.getKey(),
+ out);
} catch (Exception e) {
uploadConnection.cancelUpload();
report.setStatus(CreateResourceStatus.FAILURE);
- report.setErrorMessage("An error occured while the agent was downloading
the content");
+ report.setErrorMessage("An error occured while the agent was uploading
the content for ["
+ + details.getKey() + "]");
return report;
}
+ if (0L == size) {
+ uploadConnection.cancelUpload();
+ report.setStatus(CreateResourceStatus.FAILURE);
+ report.setErrorMessage("An error occured (0 bytes) while the agent was
uploading the content for ["
+ + details.getKey() + "]");
+ return report;
+
+ }
+
JsonNode uploadResult = uploadConnection.finishUpload();
if (verbose) {
getLog().info(uploadResult);
diff --git
a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/standalone/DeploymentRuntimeResourcesTest.java
b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/standalone/DeploymentRuntimeResourcesTest.java
index 05237ef..3747821 100644
---
a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/standalone/DeploymentRuntimeResourcesTest.java
+++
b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/standalone/DeploymentRuntimeResourcesTest.java
@@ -19,17 +19,14 @@
package org.rhq.modules.plugins.jbossas7.itest.standalone;
-import static java.lang.System.currentTimeMillis;
-import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
-import static
org.rhq.modules.plugins.jbossas7.itest.standalone.DeploymentTest.copyStreamAndReturnCount;
import static
org.rhq.modules.plugins.jbossas7.itest.standalone.DeploymentTest.getMeasurementScheduleRequests;
import static
org.rhq.modules.plugins.jbossas7.itest.standalone.DeploymentTest.getMissingMeasurements;
import static
org.rhq.modules.plugins.jbossas7.itest.standalone.DeploymentTest.getTestDeploymentPackageDetails;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
+import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashSet;
@@ -40,6 +37,7 @@ import org.apache.commons.logging.LogFactory;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
+import org.testng.Assert;
import org.testng.annotations.Test;
import org.rhq.core.clientapi.agent.PluginContainerException;
@@ -59,15 +57,15 @@ import org.rhq.core.pc.util.FacetLockType;
import org.rhq.core.pluginapi.measurement.MeasurementFacet;
import org.rhq.modules.plugins.jbossas7.itest.AbstractJBossAS7PluginTest;
import org.rhq.test.arquillian.DiscoveredResources;
+import org.rhq.test.arquillian.MockingServerServices;
import org.rhq.test.arquillian.RunDiscovery;
-import org.rhq.test.arquillian.ServerServicesSetup;
/**
* This test ensures that "* Runtime" (JPA, Messaging, EJB3) child resources of
a deployment get discovered.
*
* @author Thomas Segismont
*/
-@Test(groups = { "integration", "pc", "standalone" },
singleThreaded = true)
+@Test
public class DeploymentRuntimeResourcesTest extends AbstractJBossAS7PluginTest {
private static final Log LOG =
LogFactory.getLog(DeploymentRuntimeResourcesTest.class);
@@ -100,39 +98,59 @@ public class DeploymentRuntimeResourcesTest extends
AbstractJBossAS7PluginTest {
}
}
- @DiscoveredResources(plugin = PLUGIN_NAME, resourceType = "JBossAS7 Standalone
Server")
- private Set<Resource> standaloneResources;
-
- @DiscoveredResources(plugin = PLUGIN_NAME, resourceType = "Deployment")
- private Set<Resource> deploymentResources;
+ protected void injectMocks(MockingServerServices serverServices) {
+ Mockito.when(
+
serverServices.getContentServerService().downloadPackageBitsGivenResource(Mockito.anyInt(),
+ Mockito.any(PackageDetailsKey.class),
Mockito.any(OutputStream.class))).then(new Answer<Long>() {
+ @Override
+ public Long answer(InvocationOnMock invocation) throws Throwable {
+ OutputStream out = (OutputStream)
invocation.getArguments()[invocation.getArguments().length - 1];
+ return copyStreamAndReturnCount(out);
+ }
+ });
- @ServerServicesSetup
- @Test(enabled = false)
- public void setupContentServices() {
Mockito.when(
serverServices.getContentServerService().downloadPackageBitsForChildResource(Mockito.anyInt(),
Mockito.anyString(), Mockito.any(PackageDetailsKey.class),
Mockito.any(OutputStream.class))).then(
new Answer<Long>() {
@Override
public Long answer(InvocationOnMock invocation) throws Throwable {
- InputStream str = getClass().getClassLoader().getResourceAsStream(
- TestDeployments.JAVAEE6_TEST_APP.getResourcePath());
OutputStream out = (OutputStream)
invocation.getArguments()[invocation.getArguments().length - 1];
- return copyStreamAndReturnCount(str, out);
+ return copyStreamAndReturnCount(out);
}
});
+ }
- Mockito.when(
-
serverServices.getContentServerService().downloadPackageBitsGivenResource(Mockito.anyInt(),
- Mockito.any(PackageDetailsKey.class),
Mockito.any(OutputStream.class))).then(new Answer<Long>() {
- @Override
- public Long answer(InvocationOnMock invocation) throws Throwable {
- InputStream str = getClass().getClassLoader().getResourceAsStream(
- TestDeployments.JAVAEE6_TEST_APP.getResourcePath());
- OutputStream out = (OutputStream)
invocation.getArguments()[invocation.getArguments().length - 1];
- return copyStreamAndReturnCount(str, out);
+ @DiscoveredResources(plugin = PLUGIN_NAME, resourceType = "JBossAS7 Standalone
Server")
+ private Set<Resource> standaloneResources;
+
+ @DiscoveredResources(plugin = PLUGIN_NAME, resourceType = "Deployment")
+ private Set<Resource> deploymentResources;
+
+ private long copyStreamAndReturnCount(OutputStream out) throws IOException {
+ if (null == out) {
+ System.out.println("**** Unexepected null output stream in mock
code!!");
+ return 0L;
+ }
+
+ String path = TestDeployments.JAVAEE6_TEST_APP.getResourcePath();
+ InputStream in = getClass().getClassLoader().getResourceAsStream(path);
+
+ long cnt = 0;
+
+ try {
+ int data;
+ while ((data = in.read()) != -1) {
+ if (out != null) {
+ out.write(data);
+ }
+ cnt++;
}
- });
+ } finally {
+ in.close();
+ out.flush();
+ }
+ return cnt;
}
@Test(priority = 10)
@@ -174,7 +192,7 @@ public class DeploymentRuntimeResourcesTest extends
AbstractJBossAS7PluginTest {
}
private void ensureAllRuntimeServicesAreFound() throws InterruptedException {
- long start = currentTimeMillis();
+ long start = System.currentTimeMillis();
boolean foundAllRuntimeServices = false;
do {
boolean runtimeServiceMissing = false;
@@ -187,10 +205,11 @@ public class DeploymentRuntimeResourcesTest extends
AbstractJBossAS7PluginTest {
}
}
foundAllRuntimeServices = !runtimeServiceMissing;
- Thread.sleep(SECONDS.toMillis(5));
- } while (!foundAllRuntimeServices && (currentTimeMillis() - start) <
MINUTES.toMillis(10));
- assertTrue(foundAllRuntimeServices, "Could not find all runtime
services");
- Thread.sleep(MINUTES.toMillis(5));
+ //Thread.sleep(SECONDS.toMillis(5));
+ } while (!foundAllRuntimeServices
+ && (System.currentTimeMillis() - start) <
java.util.concurrent.TimeUnit.MINUTES.toMillis(10));
+ Assert.assertTrue(foundAllRuntimeServices, "Could not find all runtime
services");
+ //Thread.sleep(MINUTES.toMillis(5));
}
private boolean canGetMeasurementFacet(Set<Resource> resources) {
@@ -247,6 +266,7 @@ public class DeploymentRuntimeResourcesTest extends
AbstractJBossAS7PluginTest {
}
@Test(priority = 99)
+ @RunDiscovery
public void testUndeploy() throws Exception {
Resource deploymentResource = getDeploymentResource();
DeleteResourceRequest request = new DeleteResourceRequest(0,
deploymentResource.getId());
diff --git
a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/standalone/DeploymentTest.java
b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/standalone/DeploymentTest.java
index 24add24..fbdc02b 100644
---
a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/standalone/DeploymentTest.java
+++
b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/standalone/DeploymentTest.java
@@ -67,12 +67,12 @@ import org.rhq.core.util.MessageDigestGenerator;
import org.rhq.modules.plugins.jbossas7.StandaloneASComponent;
import org.rhq.modules.plugins.jbossas7.itest.AbstractJBossAS7PluginTest;
import org.rhq.test.arquillian.DiscoveredResources;
+import org.rhq.test.arquillian.MockingServerServices;
import org.rhq.test.arquillian.ResourceComponentInstances;
import org.rhq.test.arquillian.RunDiscovery;
-import org.rhq.test.arquillian.ServerServicesSetup;
/**
- *
+ *
*
* @author Lukas Krejci
*/
@@ -95,20 +95,16 @@ public class DeploymentTest extends AbstractJBossAS7PluginTest {
private static TestDeployments DEPLOYMENT_TO_SERVE = TestDeployments.DEPLOYMENT_1;
- //this is no test method
- @ServerServicesSetup
- @Test(enabled = false)
- public void setupContentServices() {
+ @Override
+ protected void injectMocks(MockingServerServices serverServices) {
Mockito.when(
serverServices.getContentServerService().downloadPackageBitsForChildResource(Mockito.anyInt(),
Mockito.anyString(), Mockito.any(PackageDetailsKey.class),
Mockito.any(OutputStream.class))).then(
new Answer<Long>() {
@Override
public Long answer(InvocationOnMock invocation) throws Throwable {
- InputStream str = getClass().getClassLoader().getResourceAsStream(
- DEPLOYMENT_TO_SERVE.getResourcePath());
OutputStream out = (OutputStream)
invocation.getArguments()[invocation.getArguments().length - 1];
- return copyStreamAndReturnCount(str, out);
+ return copyStreamAndReturnCount(out);
}
});
@@ -117,10 +113,8 @@ public class DeploymentTest extends AbstractJBossAS7PluginTest {
Mockito.any(PackageDetailsKey.class),
Mockito.any(OutputStream.class))).then(new Answer<Long>() {
@Override
public Long answer(InvocationOnMock invocation) throws Throwable {
- InputStream str = getClass().getClassLoader()
- .getResourceAsStream(DEPLOYMENT_TO_SERVE.getResourcePath());
OutputStream out = (OutputStream)
invocation.getArguments()[invocation.getArguments().length - 1];
- return copyStreamAndReturnCount(str, out);
+ return copyStreamAndReturnCount(out);
}
});
}
@@ -243,6 +237,7 @@ public class DeploymentTest extends AbstractJBossAS7PluginTest {
}
@Test(priority = 16)
+ @RunDiscovery
public void testUndeploy() throws Exception {
Resource deployment = deploymentResources.iterator().next();
DeleteResourceRequest request = new DeleteResourceRequest(0,
deployment.getId());
@@ -300,14 +295,28 @@ public class DeploymentTest extends AbstractJBossAS7PluginTest {
}
}
- static long copyStreamAndReturnCount(InputStream in, OutputStream out) throws
IOException {
- int data;
+ private long copyStreamAndReturnCount(OutputStream out) throws IOException {
+ if (null == out) {
+ System.out.println("**** Unexepected null output stream in mock
code!!");
+ return 0L;
+ }
+
+ String path = DEPLOYMENT_TO_SERVE.getResourcePath();
+ InputStream in = getClass().getClassLoader().getResourceAsStream(path);
+
long cnt = 0;
- while ((data = in.read()) != -1) {
- if (out != null) {
- out.write(data);
+
+ try {
+ int data;
+ while ((data = in.read()) != -1) {
+ if (out != null) {
+ out.write(data);
+ }
+ cnt++;
}
- cnt++;
+ } finally {
+ in.close();
+ out.flush();
}
return cnt;
}
commit c86911c9850e81f498099395e509cc41f4a67dde
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Wed Jan 29 13:08:00 2014 -0500
move trove4j dep version to root pom
diff --git a/modules/core/plugin-container/pom.xml
b/modules/core/plugin-container/pom.xml
index 5fad36b..c9d5d17 100644
--- a/modules/core/plugin-container/pom.xml
+++ b/modules/core/plugin-container/pom.xml
@@ -92,7 +92,6 @@
<dependency>
<groupId>net.sf.trove4j</groupId>
<artifactId>trove4j</artifactId>
- <version>3.0.3</version>
</dependency>
</dependencies>
diff --git a/pom.xml b/pom.xml
index dd797a1..fec00c6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1036,6 +1036,12 @@
<artifactId>snakeyaml</artifactId>
<version>${cassandra.snakeyaml.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>net.sf.trove4j</groupId>
+ <artifactId>trove4j</artifactId>
+ <version>3.0.3</version>
+ </dependency>
</dependencies>
</dependencyManagement>