[rhmessaging-commits] rhmessaging commits: r3811 - in store/branches/java/0.5-release: src and 8 other directories.
rhmessaging-commits at lists.jboss.org
rhmessaging-commits at lists.jboss.org
Wed Jan 20 05:16:49 EST 2010
Author: rgemmell
Date: 2010-01-20 05:16:49 -0500 (Wed, 20 Jan 2010)
New Revision: 3811
Added:
store/branches/java/0.5-release/java.testprofile
store/branches/java/0.5-release/src/systests/
store/branches/java/0.5-release/src/systests/java/
store/branches/java/0.5-release/src/systests/java/org/
store/branches/java/0.5-release/src/systests/java/org/apache/
store/branches/java/0.5-release/src/systests/java/org/apache/qpid/
store/branches/java/0.5-release/src/systests/java/org/apache/qpid/server/
store/branches/java/0.5-release/src/systests/java/org/apache/qpid/server/store/
store/branches/java/0.5-release/src/systests/java/org/apache/qpid/server/store/berkeleydb/
store/branches/java/0.5-release/src/systests/java/org/apache/qpid/server/store/berkeleydb/BDBStoreBindingsWorkaroundSystemTest.java
Modified:
store/branches/java/0.5-release/build.xml
Log:
Add a systest for the bindings workaround tool. Extend build.xml to allow starting a full/external broker.
Modified: store/branches/java/0.5-release/build.xml
===================================================================
--- store/branches/java/0.5-release/build.xml 2010-01-20 10:15:23 UTC (rev 3810)
+++ store/branches/java/0.5-release/build.xml 2010-01-20 10:16:49 UTC (rev 3811)
@@ -8,6 +8,7 @@
<property name="src.tools.dir" location="src/tools/java"/>
<property name="src.main.dir" location="src/main/java"/>
<property name="src.test.dir" location="src/test/java"/>
+ <property name="src.systests.dir" location="src/systests/java"/>
<property name="build.dir" location="build"/>
<property name="lib.dir" location="lib"/>
<property name="bin.dir" location="bin"/>
@@ -21,6 +22,7 @@
<property name="build.classes" location="build/classes"/>
<property name="build.test.classes" location="build/test/classes"/>
+ <property name="build.systests.classes" location="build/systests/classes"/>
<property name="build.tools.classes" location="build/tools/classes"/>
<property name="build.results" location="build/results"/>
<property name="build.failed" location="${build.results}/FAILED"/>
@@ -38,6 +40,14 @@
<available property="src.test.dir.exists" file="${src.test.dir}"/>
+ <condition property="config" value="${profile}.testprofile" else="default.testprofile">
+ <and>
+ <isset property="profile"/>
+ <available file="${project.root}/${profile}.testprofile" type="file"/>
+ </and>
+ </condition>
+
+ <property file="${project.root}/${config}"/>
<property file="${project.root}/default.testprofile"/>
<path id="class.path">
@@ -59,10 +69,18 @@
<pathelement path="${build.tools.classes}"/>
<pathelement path="${build.test.classes}"/>
</path>
+
+ <path id="systests.class.path">
+ <path refid="class.path"/>
+ <pathelement path="${build.classes}"/>
+ <pathelement path="${build.tools.classes}"/>
+ <pathelement path="${build.systests.classes}"/>
+ </path>
<target name="init">
<mkdir dir="${build.classes}"/>
<mkdir dir="${build.test.classes}"/>
+ <mkdir dir="${build.systests.classes}"/>
<mkdir dir="${build.tools.classes}"/>
<mkdir dir="${build.results}"/>
</target>
@@ -86,6 +104,12 @@
destdir="${build.test.classes}"
classpathref="test.class.path" debug="on"/>
</target>
+
+ <target name="build-systests" depends="init,build-main">
+ <javac srcdir="${src.systests.dir}"
+ destdir="${build.systests.classes}"
+ classpathref="systests.class.path" debug="on"/>
+ </target>
<target name="build-tools" depends="init,build-main">
<javac srcdir="${src.tools.dir}"
@@ -156,7 +180,59 @@
<fail if="failed" message="TEST SUITE FAILED"/>
</target>
+
+
+ <target name="systests" depends="build-systests,prepare-tests" if="src.test.dir.exists"
+ unless="${dontruntest}" description="execute unit tests">
+ <delete file="${build.failed}"/>
+
+ <junit fork="${test.fork}" maxmemory="${test.mem}" reloading="no"
+ haltonfailure="${haltonfailure}" haltonerror="${haltonerror}"
+ failureproperty="test.failures" printsummary="on" timeout="600000" >
+ <sysproperty key="amqj.logging.level" value="${amqj.logging.level}"/>
+ <sysproperty key="root.logging.level" value="${root.logging.level}"/>
+ <sysproperty key="log4j.configuration" value="${log4j.configuration}"/>
+ <sysproperty key="java.naming.factory.initial" value="${java.naming.factory.initial}"/>
+ <sysproperty key="java.naming.provider.url" value="${java.naming.provider.url}"/>
+ <sysproperty key="broker" value="${broker}"/>
+ <sysproperty key="broker.clean" value="${broker.clean}"/>
+ <sysproperty key="broker.version" value="${broker.version}"/>
+ <sysproperty key="broker.ready" value="${broker.ready}" />
+ <sysproperty key="test.excludes" value="${test.excludes}"/>
+ <sysproperty key="test.excludesfile" value="${test.excludesfile}"/>
+ <sysproperty key="max_prefetch" value ="${max_prefetch}"/>
+ <sysproperty key="example.plugin.target" value="${project.root}/build/lib/plugins"/>
+ <sysproperty key="QPID_HOME" value="${project.root}/build"/>
+ <sysproperty key="QPID_WORK" value="${project.root}/build/test-work"/>
+ <sysproperty key="test.excludes" value="false"/>
+
+
+ <formatter type="plain"/>
+ <formatter type="xml"/>
+
+ <classpath refid="systests.class.path"/>
+
+ <batchtest fork="${test.fork}" todir="${build.results}">
+ <fileset dir="${src.systests.dir}" excludes="${module.test.excludes}">
+ <include name="**/${test}.java"/>
+ </fileset>
+ </batchtest>
+ </junit>
+
+ <antcall target="touch-failed"/>
+
+ <condition property="failed">
+ <and>
+ <isfalse value="${test.failures.ignore}"/>
+ <available file="${build.failed}"/>
+ </and>
+ </condition>
+
+ <fail if="failed" message="TEST SUITE FAILED"/>
+
+ </target>
+
<target name="touch-failed" if="test.failures">
<touch file="${build.failed}"/>
</target>
Added: store/branches/java/0.5-release/java.testprofile
===================================================================
--- store/branches/java/0.5-release/java.testprofile (rev 0)
+++ store/branches/java/0.5-release/java.testprofile 2010-01-20 10:16:49 UTC (rev 3811)
@@ -0,0 +1,24 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+broker.language=java
+broker=${project.root}/build/bin/qpid-server -p @PORT -m @MPORT -c @CONFIG_FILE
+broker.clean=${project.root}/clean-dir ${build.data}
+broker.ready=Qpid Broker Ready
+
+test.excludesfile=${project.root}/ExcludeList ${project.root}/XAExcludeList ${project.root}/08ExcludeList-nonvm
Added: store/branches/java/0.5-release/src/systests/java/org/apache/qpid/server/store/berkeleydb/BDBStoreBindingsWorkaroundSystemTest.java
===================================================================
--- store/branches/java/0.5-release/src/systests/java/org/apache/qpid/server/store/berkeleydb/BDBStoreBindingsWorkaroundSystemTest.java (rev 0)
+++ store/branches/java/0.5-release/src/systests/java/org/apache/qpid/server/store/berkeleydb/BDBStoreBindingsWorkaroundSystemTest.java 2010-01-20 10:16:49 UTC (rev 3811)
@@ -0,0 +1,336 @@
+package org.apache.qpid.server.store.berkeleydb;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import javax.management.MBeanServerConnection;
+import javax.management.MBeanServerInvocationHandler;
+import javax.management.ObjectName;
+import javax.management.openmbean.TabularData;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+import org.apache.qpid.server.exchange.ManagedExchange;
+import org.apache.qpid.server.management.ManagedBroker;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class BDBStoreBindingsWorkaroundSystemTest extends QpidTestCase
+{
+ private static final String QPID_HOME = "QPID_HOME";
+ private static final String QPID_WORK = "QPID_WORK";
+ private static final String WORKAROUND_COMPLETE = "Workaround process complete";
+
+ private static final int JMX_PORT = 8999;
+ private static final String JMX_USER = "admin";
+ private static final String JMX_PASS = "admin";
+ private static final String VHOST = "test";
+ private static final String EXCHANGE = "amq.direct";
+ private static final String CMD = System.getProperty("QPID_HOME") + File.separator + "bin"
+ + File.separator + "bindingsWorkaround.sh";
+
+ private static final String CONFIG = System.getProperty("QPID_HOME") + File.separator + "etc"
+ + File.separator + "persistent_config.xml";
+
+ private File BDB_DIR;
+ private JMXConnector _jmxc;
+ private MBeanServerConnection _mbsc;
+
+ public void setUp() throws Exception
+ {
+ if(System.getProperty(QPID_HOME) == null)
+ {
+ fail("QPID_HOME is not set");
+ }
+
+ if(System.getProperty(QPID_WORK) == null)
+ {
+ fail("QPID_WORK is not set");
+ }
+
+ _configFile = new File(System.getProperty(QPID_HOME) + File.separator + "etc" + File.separator + "persistent_config.xml");
+
+ BDB_DIR = new File(System.getProperty(QPID_WORK) + File.separator + "bdbstore");
+
+ if (BDB_DIR.exists())
+ {
+ if(!deleteDirectory(BDB_DIR))
+ {
+ fail("Unable to clean existing BDB directory");
+ }
+ }
+
+ super.setUp();
+ }
+
+ public void tearDown() throws Exception
+ {
+ closeJMXConnection();
+
+ super.tearDown();
+
+ if (BDB_DIR.exists())
+ {
+ deleteDirectory(BDB_DIR);
+ }
+ }
+
+ private void openJMXConnection() throws Exception
+ {
+ JMXServiceURL jmxUrl = new JMXServiceURL(
+ "service:jmx:rmi:///jndi/rmi://" + "localhost" + ":" + JMX_PORT + "/jmxrmi");
+
+ //Add user credential's to environment map for RMIConnector startup.
+ //These will be used for authentication by the remote RMIConnectorServer if supported,
+ //or ignored otherwise.
+ Map<String, Object> env = new HashMap<String, Object>();
+ env.put(JMXConnector.CREDENTIALS, new String[] {JMX_USER,JMX_PASS});
+
+ _jmxc = JMXConnectorFactory.connect(jmxUrl, env);
+ _mbsc = _jmxc.getMBeanServerConnection();
+ }
+
+ private void closeJMXConnection()
+ {
+ try
+ {
+ _jmxc.close();
+ }
+ catch (IOException e)
+ {
+ //ignore
+ }
+ }
+
+ private ManagedExchange getExchangeMBean() throws Exception
+ {
+ ObjectName exchangeObjectName = new ObjectName(
+ "org.apache.qpid:" +
+ "type=VirtualHost.Exchange," +
+ "VirtualHost=" + VHOST + "," +
+ "name=" + EXCHANGE + "," +
+ "ExchangeType=direct,*");
+
+ Set<ObjectName> exchanges = _mbsc.queryNames(exchangeObjectName, null);
+
+ if(exchanges.size() == 0)
+ {
+ fail("Did not find the MBean for Exchange: " + EXCHANGE);
+ }
+
+ //create the MBean proxy
+ ManagedExchange managedExchange = (ManagedExchange) MBeanServerInvocationHandler.newProxyInstance(
+ _mbsc, (ObjectName) exchanges.toArray()[0], ManagedExchange.class, false);
+
+ return managedExchange;
+ }
+
+ private ManagedBroker getVhostManagerMBean() throws Exception
+ {
+ ObjectName hostManagerObjectName = new ObjectName(
+ "org.apache.qpid:" +
+ "type=VirtualHost.VirtualHostManager," +
+ "VirtualHost=" + VHOST + ",*");
+
+ Set<ObjectName> vhostManagers = _mbsc.queryNames(hostManagerObjectName, null);
+
+ if(vhostManagers.size() == 0)
+ {
+ //The vhostManager MBean wasnt found
+ fail("Failed to find Vhost Manager MBean");
+ }
+
+ ManagedBroker vhostManager = (ManagedBroker) MBeanServerInvocationHandler.newProxyInstance(
+ _mbsc, (ObjectName) vhostManagers.toArray()[0], ManagedBroker.class, false);
+
+ return vhostManager;
+ }
+
+ private void runWorkaroundTool() throws Exception
+ {
+
+ ProcessBuilder pb = new ProcessBuilder((CMD + " -c " + CONFIG).split("\\s+"));
+ pb.redirectErrorStream(true);
+
+ Map<String, String> env = pb.environment();
+
+ String qpidHome = System.getProperty(QPID_HOME);
+ env.put(QPID_HOME, qpidHome);
+
+ //Augment Path with bin directory in QPID_HOME.
+ env.put("PATH", env.get("PATH").concat(File.pathSeparator + qpidHome + "/bin"));
+
+ Process process = pb.start();
+
+ Piper p = new Piper(process.getInputStream(),WORKAROUND_COMPLETE);
+
+ p.start();
+
+ if (!p.await(10, TimeUnit.SECONDS))
+ {
+ fail("Tool has not yet reported successful completion");
+ }
+
+ try
+ {
+ //Hack: wait 1sec to give time for the VirtualHosts to close
+ //and the JVM to exit after the tool reports its completion.
+ Thread.sleep(1000);
+
+ int exit = process.exitValue();
+ if(exit != 0)
+ {
+ fail("Workaround tool exited in an error state");
+ }
+ }
+ catch (IllegalThreadStateException e)
+ {
+ fail("Workaround tool has not yet exited");
+ }
+ }
+
+
+ public void testWorkaroundTool() throws Exception
+ {
+ openJMXConnection();
+
+ ManagedBroker vhostManager = getVhostManagerMBean();
+ ManagedExchange managedExchange = getExchangeMBean();
+
+ //gather the current exchange bindings count
+ TabularData bindings = managedExchange.bindings();
+ int origBindingsCount = bindings.size();
+
+ //create and bind new durable queue.
+ vhostManager.createNewQueue("testWorkaroundTool.Queue1", null, true);
+ managedExchange.createNewBinding("testWorkaroundTool.Queue1", "testWorkaroundTool.Queue1");
+
+ //verify the binding count increased
+ bindings = managedExchange.bindings();
+ assertEquals("No additional bindings were detected",bindings.size(), origBindingsCount +1);
+
+ closeJMXConnection();
+
+ restartBroker();
+
+ openJMXConnection();
+
+ //verify the binding count decreased because the bindings were not recovered
+ vhostManager = getVhostManagerMBean();
+ managedExchange = getExchangeMBean();
+
+ bindings = managedExchange.bindings();
+ assertEquals("The binding was recovered, expected it not to be",bindings.size(), origBindingsCount);
+
+ stopBroker();
+
+ runWorkaroundTool();
+
+ startBroker();
+
+ openJMXConnection();
+
+ //verify the binding count increased again because the bindings are now recovered.
+ vhostManager = getVhostManagerMBean();
+ managedExchange = getExchangeMBean();
+
+ bindings = managedExchange.bindings();
+ assertEquals("The binding was not recovered, expected it to be",bindings.size(), origBindingsCount+1);
+ }
+
+ public static boolean deleteDirectory(File dir)
+ {
+ if (dir.isDirectory())
+ {
+ String[] children = dir.list();
+ for (int i = 0; i < children.length; i++)
+ {
+ if (!deleteDirectory(new File(dir, children[i])))
+ {
+ return false;
+ }
+ }
+ }
+
+ return (dir.delete());
+ }
+
+ private static final class Piper extends Thread
+ {
+
+ private LineNumberReader in;
+ private String ready;
+ private CountDownLatch latch;
+ private boolean seenReady;
+
+ public Piper(InputStream in, String ready)
+ {
+ this.in = new LineNumberReader(new InputStreamReader(in));
+ this.ready = ready;
+ this.seenReady = false;
+ if (this.ready != null && !this.ready.equals(""))
+ {
+ this.latch = new CountDownLatch(1);
+ }
+ else
+ {
+ this.latch = null;
+ }
+ }
+
+ public Piper(InputStream in)
+ {
+ this(in, null);
+ }
+
+ public boolean await(long timeout, TimeUnit unit) throws InterruptedException
+ {
+ if (latch == null)
+ {
+ return true;
+ }
+ else
+ {
+ latch.await(timeout, unit);
+ return seenReady;
+ }
+ }
+
+ public void run()
+ {
+ try
+ {
+ String line;
+ while ((line = in.readLine()) != null)
+ {
+ System.out.println(line);
+ if (latch != null && line.contains(ready))
+ {
+ seenReady = true;
+ latch.countDown();
+ }
+ }
+ }
+ catch (IOException e)
+ {
+ // this seems to happen regularly even when
+ // exits are normal
+ }
+ finally
+ {
+ if (latch != null)
+ {
+ latch.countDown();
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
More information about the rhmessaging-commits
mailing list