modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/cloud/StorageNodeManagerBeanTest.java
| 20 ---
modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/test/AbstractEJB3Test.java
| 7 +
modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/test/StrippedDownStartupBean.java
| 58 +++-------
modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/test/StrippedDownStartupBeanPreparation.java
| 43 +++++++
4 files changed, 71 insertions(+), 57 deletions(-)
New commits:
commit 9f02dd2fa407518ba64ecad2409f368364d017f4
Author: John Sanda <jsanda(a)redhat.com>
Date: Tue Jul 9 15:26:04 2013 -0400
fixing broken tests caused from change to persist seed nodes during install
Previously seed storage nodes were persisted at start up. That has been changed
so that seed nodes are now persisted by the installer. This caused the storage
client subsystem to fail to properly initialize. Seed nodes are now persisted
at deployment time (for tests) by StrippedDownStartupBeanPreparation.
diff --git
a/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/cloud/StorageNodeManagerBeanTest.java
b/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/cloud/StorageNodeManagerBeanTest.java
index 4e04447..78c0cff 100644
---
a/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/cloud/StorageNodeManagerBeanTest.java
+++
b/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/cloud/StorageNodeManagerBeanTest.java
@@ -148,26 +148,6 @@ public class StorageNodeManagerBeanTest extends AbstractEJB3Test {
// this method is still needed, because tests calls SLSB methods that are
executed in their own transaction
// and the rollback performed once the TransactionCallback is finished just wont
clean everything
- // We can only filter on the group name because the resource type info might not
exist in the test
- // database.
- ResourceGroupCriteria criteria = new ResourceGroupCriteria();
- criteria.addFilterName(STORAGE_NODE_GROUP_NAME);
-
- List<ResourceGroup> groups =
resourceGroupManager.findResourceGroupsByCriteria(subjectManager.getOverlord(),
- criteria);
-
- if (!groups.isEmpty()) {
- resourceGroupManager.deleteResourceGroup(subjectManager.getOverlord(),
groups.get(0).getId());
- }
-
-// for (ResourceGroup group : groups) {
-// if (group.getName().equals(STORAGE_NODE_GROUP_NAME)) {
-// resourceGroupManager.deleteResourceGroup(subjectManager.getOverlord(),
group.getId());
-// break;
-// }
-// }
-
-
// pause the currently running TX
Transaction runningTransaction = getTransactionManager().suspend();
getTransactionManager().begin();
diff --git
a/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/test/AbstractEJB3Test.java
b/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/test/AbstractEJB3Test.java
index ea7ac6b..9ddba97 100644
---
a/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/test/AbstractEJB3Test.java
+++
b/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/test/AbstractEJB3Test.java
@@ -37,6 +37,7 @@ import java.util.List;
import java.util.Properties;
import java.util.regex.Pattern;
+import javax.ejb.EJB;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
@@ -87,6 +88,7 @@ import org.rhq.enterprise.server.plugin.pc.ServerPluginService;
import org.rhq.enterprise.server.plugin.pc.ServerPluginServiceMBean;
import org.rhq.enterprise.server.scheduler.SchedulerService;
import org.rhq.enterprise.server.scheduler.SchedulerServiceMBean;
+import org.rhq.enterprise.server.storage.StorageClientManagerBean;
import org.rhq.enterprise.server.util.LookupUtil;
import org.rhq.test.AssertUtils;
import org.rhq.test.MatchResult;
@@ -114,6 +116,9 @@ public abstract class AbstractEJB3Test extends Arquillian {
@ArquillianResource
protected InitialContext initialContext;
+ @EJB
+ private StorageClientManagerBean storageClientManager;
+
// We originally (in 4.2.3 days) ran these tests as "unit" tests in the
server/jar module using
// the embedded container. With Arquillian it makes sense to actually deploy an EAR
because
// we need a way to deploy dependent ears needed to support the server/jar classes.
But
@@ -518,7 +523,7 @@ public abstract class AbstractEJB3Test extends Arquillian {
}
}
}
-
+ storageClientManager.init();
beforeMethod();
beforeMethod(method);
diff --git
a/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/test/StrippedDownStartupBean.java
b/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/test/StrippedDownStartupBean.java
index 2e654ab..58273d8 100644
---
a/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/test/StrippedDownStartupBean.java
+++
b/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/test/StrippedDownStartupBean.java
@@ -20,21 +20,26 @@
package org.rhq.enterprise.server.test;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
+import static
org.rhq.enterprise.server.cloud.StorageNodeManagerLocal.STORAGE_NODE_GROUP_NAME;
+
+import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Singleton;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.rhq.core.domain.cloud.Server;
import org.rhq.core.domain.cloud.StorageNode;
+import org.rhq.core.domain.criteria.ResourceGroupCriteria;
+import org.rhq.core.domain.resource.group.ResourceGroup;
import org.rhq.enterprise.server.RHQConstants;
-import org.rhq.enterprise.server.storage.StorageClientManagerBean;
+import org.rhq.enterprise.server.auth.SubjectManagerLocal;
import org.rhq.enterprise.server.core.StartupBean;
import org.rhq.enterprise.server.naming.NamingHack;
+import org.rhq.enterprise.server.resource.group.ResourceGroupManagerLocal;
/**
* This is a replacement for the fullblown {@link StartupBean} of the actual RHQ server.
@@ -45,9 +50,6 @@ public class StrippedDownStartupBean {
public static final String RHQ_SERVER_NAME_PROPERTY =
"rhq.server.high-availability.name";
- @EJB
- StorageClientManagerBean storageClientManager;
-
@PersistenceContext(unitName = RHQConstants.PERSISTENCE_UNIT_NAME)
private EntityManager entityManager;
@@ -55,46 +57,30 @@ public class StrippedDownStartupBean {
NamingHack.bruteForceInitialContextFactoryBuilder();
}
+ @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void init() {
secureNaming();
- // TODO Find a better way to load system properties
- // Cassandra connection info is currently obtained from system properties. I
have
- // yet to find a good way to set system properties for the deployment under
test.
- //
https://github.com/arquillian/arquillian-showcase/tree/master/extensions/...
- // might be worth looking at.
- //
- // jsanda
- loadCassandraConnectionProps();
- storageClientManager.init();
}
/**
- * Purges the test server and any storage nodes created during server initialization
+ * <p>
+ * Purges the storage node resource group, test server, and any storage nodes created
during server initialization
* from a prior test run.
+ * </p>
+ * <p>
+ * Note that the storage node group deletion simply removes the entity from the
rhq_resource_group table. At this
+ * point in the deployment, {@link
ResourceGroupManagerLocal#deleteResourceGroup(org.rhq.core.domain.auth.Subject, int)}
+ * cannot be used; therefore, any test that added storage node resources to the group
should take care of removing
+ * them as well.
+ * </p>
*/
public void purgeTestServerAndStorageNodes() {
+ entityManager.createQuery("DELETE FROM " +
ResourceGroup.class.getName() + " WHERE name = :storageNodeGroup")
+ .setParameter("storageNodeGroup", STORAGE_NODE_GROUP_NAME)
+ .executeUpdate();
entityManager.createQuery("DELETE FROM " +
StorageNode.class.getName()).executeUpdate();
entityManager.createQuery("DELETE FROM " + Server.class.getName() +
" WHERE name = :serverName")
.setParameter("serverName", TestConstants.RHQ_TEST_SERVER_NAME)
.executeUpdate();
}
-
- public void loadCassandraConnectionProps() {
- InputStream stream = null;
- try {
- stream =
getClass().getResourceAsStream("/cassandra-test.properties");
- Properties props = new Properties();
- props.load(stream);
-
- // DO NOT use System.setProperties(Properties). I previously tried that and
it
- // caused some arquillian deployment exception.
- //
- // jsanda
- System.setProperty("rhq.cassandra.username",
props.getProperty("rhq.cassandra.username"));
- System.setProperty("rhq.cassandra.password",
props.getProperty("rhq.cassandra.password"));
- System.setProperty("rhq.cassandra.seeds",
props.getProperty("rhq.cassandra.seeds"));
- } catch (IOException e) {
- throw new RuntimeException(("Failed to load
cassandra-test.properties"));
- }
- }
}
diff --git
a/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/test/StrippedDownStartupBeanPreparation.java
b/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/test/StrippedDownStartupBeanPreparation.java
index c272afe..5f67888 100644
---
a/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/test/StrippedDownStartupBeanPreparation.java
+++
b/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/test/StrippedDownStartupBeanPreparation.java
@@ -20,6 +20,10 @@
package org.rhq.enterprise.server.test;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.EJB;
@@ -28,11 +32,15 @@ import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.TimerConfig;
import javax.ejb.TimerService;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.rhq.core.domain.cloud.Server;
+import org.rhq.core.domain.cloud.StorageNode;
+import org.rhq.enterprise.server.RHQConstants;
import org.rhq.enterprise.server.cloud.instance.ServerManagerLocal;
/**
@@ -56,6 +64,9 @@ public class StrippedDownStartupBeanPreparation {
@EJB
private ServerManagerLocal serverManager;
+ @PersistenceContext(unitName = RHQConstants.PERSISTENCE_UNIT_NAME)
+ private EntityManager entityManager;
+
@Resource
private TimerService timerService; // needed to schedule our startup bean init call
@@ -66,6 +77,8 @@ public class StrippedDownStartupBeanPreparation {
startupBean.purgeTestServerAndStorageNodes();
createTestServer();
+ loadCassandraConnectionProps();
+ createStorageNodes();
}
/**
@@ -86,11 +99,41 @@ public class StrippedDownStartupBeanPreparation {
System.setProperty(TestConstants.RHQ_SERVER_NAME_PROPERTY,
TestConstants.RHQ_TEST_SERVER_NAME);
}
+ private void createStorageNodes() {
+ String[] seedsInfo =
System.getProperty("rhq.cassandra.seeds").split(",");
+ for (String seedInfo : seedsInfo) {
+ StorageNode storageNode = new StorageNode();
+ storageNode.parseNodeInformation(seedInfo);
+ storageNode.setOperationMode(StorageNode.OperationMode.INSTALLED);
+ entityManager.persist(storageNode);
+ }
+ }
+
+ public void loadCassandraConnectionProps() {
+ InputStream stream = null;
+ try {
+ stream =
getClass().getResourceAsStream("/cassandra-test.properties");
+ Properties props = new Properties();
+ props.load(stream);
+
+ // DO NOT use System.setProperties(Properties). I previously tried that and
it
+ // caused some arquillian deployment exception.
+ //
+ // jsanda
+ System.setProperty("rhq.cassandra.username",
props.getProperty("rhq.cassandra.username"));
+ System.setProperty("rhq.cassandra.password",
props.getProperty("rhq.cassandra.password"));
+ System.setProperty("rhq.cassandra.seeds",
props.getProperty("rhq.cassandra.seeds"));
+ } catch (IOException e) {
+ throw new RuntimeException(("Failed to load
cassandra-test.properties"));
+ }
+ }
+
@Timeout
public void initializeServer() throws RuntimeException {
try {
log.info("Initializing the testing RHQ deployment");
this.startupBean.init();
+ log.info("Initialization complete");
} catch (Throwable t) {
// do NOT allow exceptions to bubble out of our method because then
// the EJB container would simply re-trigger the timer and call us again