modules/common/cassandra-common-itests/src/main/java/org/rhq/cassandra/CassandraClusterManager.java | 6 ++- modules/common/cassandra-common-itests/src/test/java/org/rhq/cassandra/common/BootstrapDeployerTest.java | 18 +++++----- modules/common/cassandra-common/src/main/java/org/rhq/cassandra/DeploymentOptions.java | 18 +++++----- 3 files changed, 23 insertions(+), 19 deletions(-)
New commits: commit fa4b609c4c15456fd28a89e6d842b92dd4b3de95 Author: John Sanda jsanda@redhat.com Date: Wed Oct 31 22:12:03 2012 -0400
Moving logic out of DeploymentOptions constructor and into new load method
The default constructor of DeploymentOptions initialized its properties first looking at system properties then at values in cassandra.properties. This was kind of awkward for tests as they had to populate a Properties object and pass that into the DeploymentOptions(Properties) constructor. The logic in the default constructor has been moved to a new load method. This makes it easier for tests to simply call setter methods on properties then invoke the load method to get default values for other, remaining properties.
diff --git a/modules/common/cassandra-common-itests/src/main/java/org/rhq/cassandra/CassandraClusterManager.java b/modules/common/cassandra-common-itests/src/main/java/org/rhq/cassandra/CassandraClusterManager.java index 669f5ba..0fa49b8 100644 --- a/modules/common/cassandra-common-itests/src/main/java/org/rhq/cassandra/CassandraClusterManager.java +++ b/modules/common/cassandra-common-itests/src/main/java/org/rhq/cassandra/CassandraClusterManager.java @@ -82,7 +82,11 @@ public class CassandraClusterManager implements IInvokedMethodListener { DeploymentOptions deploymentOptions = new DeploymentOptions(); deploymentOptions.setClusterDir(clusterDir.getAbsolutePath()); deploymentOptions.setNumNodes(numNodes); - deploymentOptions.setLoggingLevel("DEBUG"); + try { + deploymentOptions.load(); + } catch (IOException e) { + throw new RuntimeException("Unable to load deployment options.", e); + }
BootstrapDeployer deployer = new BootstrapDeployer(); deployer.setDeploymentOptions(deploymentOptions); diff --git a/modules/common/cassandra-common-itests/src/test/java/org/rhq/cassandra/common/BootstrapDeployerTest.java b/modules/common/cassandra-common-itests/src/test/java/org/rhq/cassandra/common/BootstrapDeployerTest.java index 0819a51..e1eef5c 100644 --- a/modules/common/cassandra-common-itests/src/test/java/org/rhq/cassandra/common/BootstrapDeployerTest.java +++ b/modules/common/cassandra-common-itests/src/test/java/org/rhq/cassandra/common/BootstrapDeployerTest.java @@ -30,9 +30,9 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue;
import java.io.File; +import java.io.IOException; import java.util.List; import java.util.Map; -import java.util.Properties;
import org.testng.annotations.Listeners; import org.testng.annotations.Test; @@ -61,14 +61,14 @@ public class BootstrapDeployerTest { File clusterDir = new File(basedir, "cassandra"); int numNodes = 2;
- Properties properties = new Properties(); - properties.setProperty("rhq.cassandra.cluster.dir", clusterDir.getAbsolutePath()); - properties.setProperty("rhq.cassandra.logging.level", "DEBUG"); - properties.setProperty("rhq.cassandra.cluster.num-nodes", "2"); - properties.setProperty("rhq.cassandra.ring.delay", "1000"); - properties.setProperty("rhq.cassandra.node.num-tokens", "256"); - - DeploymentOptions deploymentOptions = new DeploymentOptions(properties); + DeploymentOptions deploymentOptions = new DeploymentOptions(); + try { + deploymentOptions.setClusterDir(clusterDir.getAbsolutePath()); + deploymentOptions.setRingDelay(1000L); + deploymentOptions.load(); + } catch (IOException e) { + throw new CassandraException(e); + }
BootstrapDeployer deployer = new BootstrapDeployer(); deployer.setDeploymentOptions(deploymentOptions); diff --git a/modules/common/cassandra-common/src/main/java/org/rhq/cassandra/DeploymentOptions.java b/modules/common/cassandra-common/src/main/java/org/rhq/cassandra/DeploymentOptions.java index 60cb9a3..831ee3f 100644 --- a/modules/common/cassandra-common/src/main/java/org/rhq/cassandra/DeploymentOptions.java +++ b/modules/common/cassandra-common/src/main/java/org/rhq/cassandra/DeploymentOptions.java @@ -51,20 +51,24 @@ public class DeploymentOptions { private Integer numTokens;
public DeploymentOptions() { - init(loadProperties()); }
- private Properties loadProperties() { + public DeploymentOptions(Properties properties) { + init(properties); + } + + public void load() throws IOException { InputStream stream = null; try { stream = getClass().getResourceAsStream("/cassandra.properties"); Properties props = new Properties(); props.load(stream);
- return props; + init(props); } catch (IOException e) { - throw new RuntimeException("Unable to create DeploymentOptions. An error occurred while loading " + - "cassandra.properties", e); + log.warn("Unable to load deployment options from cassandra.properties."); + log.info("The following error occurred while trying to load options.", e); + throw e; } finally { if (stream != null) { try { @@ -77,10 +81,6 @@ public class DeploymentOptions { } }
- public DeploymentOptions(Properties properties) { - init(properties); - } - private void init(Properties properties) { setBundleFileName(properties.getProperty("rhq.cassandra.bundle.filename")); setBundleName(properties.getProperty("rhq.cassandra.bundle.name"));
rhq-commits@lists.fedorahosted.org