modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/CassandraNodeComponent.java
| 38 +++++++--
modules/plugins/rhq-storage/pom.xml
| 16 +++
modules/plugins/rhq-storage/src/test/java/org/rhq/plugins/storage/StorageNodeComponentITest.java
| 26 +++++-
modules/plugins/rhq-storage/src/test/resources/log4j.properties
| 42 ----------
modules/plugins/rhq-storage/src/test/resources/log4j.xml
| 40 +++++++++
5 files changed, 109 insertions(+), 53 deletions(-)
New commits:
commit 20f29263bca99d540b4027b63b690f805663ed13
Author: Thomas Segismont <tsegismo(a)redhat.com>
Date: Wed Jul 24 18:55:25 2013 +0200
Fix StorageNodeComponentITest.shutdownStorageNode
Fixed storage node module pom typo
Made test Cassandra server start with relative paths in classpath (otherwise the
command line is too long and gets truncated in /proc/pid/cmdline this preventing the
process query to find the server)
Made CassandraNodeComponent shutdown operation to wait for server to go down
diff --git
a/modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/CassandraNodeComponent.java
b/modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/CassandraNodeComponent.java
index 8d74ccc..c41e8e7 100644
---
a/modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/CassandraNodeComponent.java
+++
b/modules/plugins/cassandra/src/main/java/org/rhq/plugins/cassandra/CassandraNodeComponent.java
@@ -132,12 +132,7 @@ public class CassandraNodeComponent extends
JMXServerComponent<ResourceComponent
long start = System.nanoTime();
try {
// Get a fresh snapshot of the process
- ProcessInfoSnapshot processInfoSnapshot = (processInfo == null) ? null :
processInfo.freshSnapshot();
- if (processInfoSnapshot == null || !processInfoSnapshot.isRunning()) {
- processInfo = getResourceContext().getNativeProcess();
- // Safe to get prior snapshot here, we've just recreated the process
info instance
- processInfoSnapshot = (processInfo == null) ? null :
processInfo.priorSnaphot();
- }
+ ProcessInfoSnapshot processInfoSnapshot = getProcessInfoSnapshot();
return (processInfoSnapshot != null &&
processInfoSnapshot.isRunning()) ? AvailabilityType.UP
: AvailabilityType.DOWN;
} finally {
@@ -151,11 +146,23 @@ public class CassandraNodeComponent extends
JMXServerComponent<ResourceComponent
}
}
+ private ProcessInfoSnapshot getProcessInfoSnapshot() {
+ ProcessInfoSnapshot processInfoSnapshot = (processInfo == null) ? null :
processInfo.freshSnapshot();
+ if (processInfoSnapshot == null || !processInfoSnapshot.isRunning()) {
+ processInfo = getResourceContext().getNativeProcess();
+ // Safe to get prior snapshot here, we've just recreated the process info
instance
+ processInfoSnapshot = (processInfo == null) ? null :
processInfo.priorSnaphot();
+ }
+ return processInfoSnapshot;
+ }
+
@Override
public OperationResult invokeOperation(String name, Configuration parameters) throws
Exception {
if (name.equals("shutdown")) {
- return shutdownNode();
+ OperationResult operationResult = shutdownNode();
+ waitForNodeToGoDown();
+ return operationResult;
} else if (name.equals("start")) {
return startNode();
} else if (name.equals("restart")) {
@@ -167,6 +174,23 @@ public class CassandraNodeComponent extends
JMXServerComponent<ResourceComponent
return null;
}
+ private void waitForNodeToGoDown() throws InterruptedException {
+ for (ProcessInfoSnapshot processInfoSnapshot = getProcessInfoSnapshot();;
processInfoSnapshot = getProcessInfoSnapshot()) {
+ if (processInfoSnapshot == null || !processInfoSnapshot.isRunning()) {
+ // Process not found, so it died, that's fine
+ // OR
+ // Process info says process is no longer running, that's fine as
well
+ break;
+ }
+ if (getResourceContext().getComponentInvocationContext().isInterrupted()) {
+ // Operation canceled or timed out
+ throw new InterruptedException();
+ }
+ // Process is still running, wait a second and check again
+ Thread.sleep(SECONDS.toMillis(1));
+ }
+ }
+
@SuppressWarnings("rawtypes")
protected OperationResult shutdownNode() {
ResourceContext<?> context = getResourceContext();
diff --git a/modules/plugins/rhq-storage/pom.xml b/modules/plugins/rhq-storage/pom.xml
index df79e40..b1d50b8 100644
--- a/modules/plugins/rhq-storage/pom.xml
+++ b/modules/plugins/rhq-storage/pom.xml
@@ -55,6 +55,20 @@
</dependency>
<dependency>
+ <groupId>${rhq.groupId}</groupId>
+ <artifactId>test-utils</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-nop</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+
+ <dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rhq-cassandra-schema</artifactId>
<version>${project.version}</version>
@@ -70,7 +84,7 @@
<phase>pre-integration-test</phase>
<configuration>
<target>
- <property name="sigar.dir"
value="${project.build.directory/sigar}"/>
+ <property name="sigar.dir"
value="${project.build.directory}/sigar"/>
<mkdir dir="${pc.basedir}"/>
<mkdir dir="${pc.lib.dir}"/>
diff --git
a/modules/plugins/rhq-storage/src/test/java/org/rhq/plugins/storage/StorageNodeComponentITest.java
b/modules/plugins/rhq-storage/src/test/java/org/rhq/plugins/storage/StorageNodeComponentITest.java
index b668073..5bc8b31 100644
---
a/modules/plugins/rhq-storage/src/test/java/org/rhq/plugins/storage/StorageNodeComponentITest.java
+++
b/modules/plugins/rhq-storage/src/test/java/org/rhq/plugins/storage/StorageNodeComponentITest.java
@@ -1,3 +1,22 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-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 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
package org.rhq.plugins.storage;
import static java.util.Arrays.asList;
@@ -94,8 +113,10 @@ public class StorageNodeComponentITest {
File binDir = new File(basedir, "bin");
SystemInfo systemInfo = SystemInfoFactory.createSystemInfo();
- File startScript = new File(binDir, "cassandra");
+ File startScript = new File("./cassandra");
ProcessExecution startScriptExe =
ProcessExecutionUtility.createProcessExecution(startScript);
+ startScriptExe.setWorkingDirectory(binDir.getAbsolutePath());
+ startScriptExe.setCheckExecutableExists(false);
startScriptExe.addArguments(asList("-p", "cassandra.pid"));
startScriptExe.setCaptureOutput(true);
@@ -176,8 +197,7 @@ public class StorageNodeComponentITest {
assertFalse(pidFile.exists(), pidFile + " should be deleted when the storage
node is shutdown.");
- // TODO why is this failing?
- //assertNodeIsDown("Expected " + storageNode + " to be DOWN after
shutting it down");
+ assertNodeIsDown("Expected " + storageNode + " to be DOWN after
shutting it down");
}
@Test(dependsOnMethods = "shutdownStorageNode")
diff --git a/modules/plugins/rhq-storage/src/test/resources/log4j.properties
b/modules/plugins/rhq-storage/src/test/resources/log4j.properties
deleted file mode 100644
index 67db049..0000000
--- a/modules/plugins/rhq-storage/src/test/resources/log4j.properties
+++ /dev/null
@@ -1,42 +0,0 @@
-#
-# /*
-# * RHQ Management Platform
-# * Copyright (C) 2005-2012 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.
-# */
-#
-
-log4j.rootCategory=WARN, FILE, CONSOLE
-
-log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
-log4j.appender.FILE.DatePattern='.'yyyy-MM-dd
-log4j.appender.FILE.File=./target/test.log
-log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
-log4j.appender.FILE.layout.ConversionPattern=%d{ABSOLUTE} %-5p %c %m%n
-#log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
-log4j.appender.FILE.Append=false
-
-log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
-log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
-#log4j.appender.CONSOLE.layout.ConversionPattern=%5p %d{HH:mm:ss,SSS} %m%n
-log4j.appender.CONSOLE.layout.ConversionPattern=%d{ABSOLUTE} %-5p %c %m%n
-
-log4j.logger.org.rhq=DEBUG
-log4j.logger.com.datastax=DEBUG
diff --git a/modules/plugins/rhq-storage/src/test/resources/log4j.xml
b/modules/plugins/rhq-storage/src/test/resources/log4j.xml
new file mode 100644
index 0000000..ec3cd98
--- /dev/null
+++ b/modules/plugins/rhq-storage/src/test/resources/log4j.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- | For more configuration information and examples, see the Jakarta Log4j |
website:
http://jakarta.apache.org/log4j -->
+
+<log4j:configuration
xmlns:log4j="http://jakarta.apache.org/log4j/">
+
+ <appender name="CONSOLE"
class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out" />
+ <param name="Threshold" value="WARN" />
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%-5p %d{dd-MM
HH:mm:ss,SSS} (%F:%M:%L) - %m%n" />
+ </layout>
+ </appender>
+
+ <appender name="FILE"
class="org.apache.log4j.RollingFileAppender">
+ <param name="File" value="target/test.log" />
+ <param name="Append" value="false" />
+ <param name="Threshold" value="DEBUG" />
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%-5p %d{dd-MM
HH:mm:ss,SSS} (%F:%M:%L) - %m%n" />
+ </layout>
+ </appender>
+
+ <logger name="org.rhq">
+ <level value="DEBUG" />
+ </logger>
+
+ <logger name="com.datastax">
+ <level value="DEBUG" />
+ </logger>
+
+ <root>
+ <level value="WARN" />
+ <appender-ref ref="CONSOLE" />
+ <appender-ref ref="FILE" />
+ </root>
+
+</log4j:configuration>