Author: rupertlssmith
Date: Fri Jan 11 08:02:09 2008
New Revision: 611212

URL: http://svn.apache.org/viewvc?rev=611212&view=rev
Log:
QPID-734. More TTL tests.

Added:
    
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/BrokerLifecycleAware.java
    
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/CauseFailure.java
    
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/CauseFailureUserPrompt.java
    
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/qpid/CauseFailureDecorator.java
    
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/qpid/CauseFailureInVM.java
Modified:
    
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/FrameworkBaseCase.java
    
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/clocksynch/UDPClockReference.java
    
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/distributedtesting/Coordinator.java
    
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/qpid/InVMBrokerDecorator.java

Added: 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/BrokerLifecycleAware.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/BrokerLifecycleAware.java?rev=611212&view=auto
==============================================================================
--- 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/BrokerLifecycleAware.java
 (added)
+++ 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/BrokerLifecycleAware.java
 Fri Jan 11 08:02:09 2008
@@ -0,0 +1,70 @@
+/*
+ *
+ * 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.
+ *
+ */
+package org.apache.qpid.test.framework;
+
+/**
+ * BrokerLifecycleAware is an awareness interface implemented by test cases 
that can run control the life-cycle of
+ * the brokers on which they run. Its purpose is to expose additional 
instrumentation of brokers during testing, that
+ * enables tests to use an automated failure mechanism to simulate broker 
failures, and to re-start failed brokers.
+ *
+ * <p/><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Indicate whether or not a test case is using an in-vm broker.
+ * <tr><td> Track which in-vm broker is currently in use.
+ * <tr><td> Accept setting of a failure mechanism. <td> [EMAIL PROTECTED] 
CauseFailure}.
+ * </table>
+ *
+ * @todo Need to think about how to present the brokers through this 
interface. Thinking numbering the available
+ *       brokers from 1 will do. Then can kill 1 and assume failing onto 2. 
Restart 1 and kill 2 and fail back onto
+ *       1 again?
+ */
+public interface BrokerLifecycleAware
+{
+    public void setInVmBrokers();
+
+    /**
+     * Indicates whether or not a test case is using in-vm brokers.
+     *
+     * @return <tt>true</tt> if the test is using in-vm brokers, 
<tt>false</tt> otherwise.
+     */
+    public boolean usingInVmBroker();
+
+    /**
+     * Sets the currently live in-vm broker.
+     *
+     * @param i The currently live in-vm broker.
+     */
+    public void setLiveBroker(int i);
+
+    /**
+     * Reports the currently live in-vm broker.
+     *
+     * @return The currently live in-vm broker.
+     */
+    public int getLiveBroker();
+
+    /**
+     * Accepts a failure mechanism.
+     *
+     * @param failureMechanism The failure mechanism.
+     */
+    public void setFailureMechanism(CauseFailure failureMechanism);
+}

Added: 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/CauseFailure.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/CauseFailure.java?rev=611212&view=auto
==============================================================================
--- 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/CauseFailure.java
 (added)
+++ 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/CauseFailure.java
 Fri Jan 11 08:02:09 2008
@@ -0,0 +1,42 @@
+/*
+ *
+ * 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.
+ *
+ */
+package org.apache.qpid.test.framework;
+
+/**
+ * CauseFailure provides a method to cause a failure in a messaging broker, 
usually used in conjunction with fail-over
+ * or other failure mode testing. In some cases failures may be automated, for 
example by shutting down an in-vm broker,
+ * or by sending a special control signal to a broker over a network 
connection. In other cases, it may be preferable
+ * to ask a user interactively to cause a failure scenario, in which case an 
implementation may display a prompt or
+ * dialog box asking for notification once the failure has been caused. The 
purpose of this interface is to abstract
+ * the exact cause and nature of a failure out of failure test cases.
+ *
+ * <p/><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities
+ * <tr><td> Cause messaging broker failure.
+ * </table>
+ */
+public interface CauseFailure
+{
+    /**
+     * Causes the active message broker to fail.
+     */
+    void causeFailure();
+}

Added: 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/CauseFailureUserPrompt.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/CauseFailureUserPrompt.java?rev=611212&view=auto
==============================================================================
--- 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/CauseFailureUserPrompt.java
 (added)
+++ 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/CauseFailureUserPrompt.java
 Fri Jan 11 08:02:09 2008
@@ -0,0 +1,65 @@
+/*
+ *
+ * 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.
+ *
+ */
+package org.apache.qpid.test.framework;
+
+import org.apache.qpid.test.framework.CauseFailure;
+
+import java.io.IOException;
+
+/**
+ * Causes a message broker failure by interactively prompting the user to 
cause it.
+ *
+ * <p/><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Cause messaging broker failure.
+ * </table>
+ */
+public class CauseFailureUserPrompt implements CauseFailure
+{
+    /**
+     * Causes the active message broker to fail.
+     */
+    public void causeFailure()
+    {
+        waitForUser("Cause a broker failure now, then press Return.");
+    }
+
+    /**
+     * Outputs a prompt to the console and waits for the user to press return.
+     *
+     * @param prompt The prompt to display on the console.
+     */
+    private void waitForUser(String prompt)
+    {
+        System.out.println(prompt);
+
+        try
+        {
+            System.in.read();
+        }
+        catch (IOException e)
+        {
+            // Ignored.
+        }
+
+        System.out.println("Continuing.");
+    }
+}

Modified: 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/FrameworkBaseCase.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/FrameworkBaseCase.java?rev=611212&r1=611211&r2=611212&view=diff
==============================================================================
--- 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/FrameworkBaseCase.java
 (original)
+++ 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/FrameworkBaseCase.java
 Fri Jan 11 08:02:09 2008
@@ -23,6 +23,7 @@
 import org.apache.log4j.Logger;
 import org.apache.log4j.NDC;
 
+import org.apache.qpid.test.framework.BrokerLifecycleAware;
 import org.apache.qpid.test.framework.sequencers.CircuitFactory;
 
 import uk.co.thebadgerset.junit.extensions.AsymptoticTestCase;
@@ -46,7 +47,8 @@
  * <tr><td> Convert failed assertions to error messages.
  * </table>
  */
-public class FrameworkBaseCase extends AsymptoticTestCase implements 
FrameworkTestContext, SetupTaskAware
+public class FrameworkBaseCase extends AsymptoticTestCase implements 
FrameworkTestContext, SetupTaskAware,
+    BrokerLifecycleAware
 {
     /** Used for debugging purposes. */
     private static final Logger log = 
Logger.getLogger(FrameworkBaseCase.class);
@@ -60,6 +62,12 @@
     /** A default setup task processor to delegate setup tasks to. */
     protected SetupTaskHandler taskHandler = new SetupTaskHandler();
 
+    /** Flag used to track whether the test is in-vm or not. */
+    protected boolean isUsingInVM;
+
+    /** Holds the failure mechanism. */
+    protected CauseFailure failureMechanism = new CauseFailureUserPrompt();
+
     /**
      * Creates a new test case with the specified name.
      *
@@ -233,5 +241,48 @@
     public String getTestCaseNameForTestMethod(String methodName)
     {
         return methodName;
+    }
+
+    public void setInVmBrokers()
+    {
+        isUsingInVM = true;
+    }
+
+    /**
+     * Indicates whether or not a test case is using in-vm brokers.
+     *
+     * @return <tt>true</tt> if the test is using in-vm brokers, 
<tt>false</tt> otherwise.
+     */
+    public boolean usingInVmBroker()
+    {
+        return isUsingInVM;
+    }
+
+    /**
+     * Sets the currently live in-vm broker.
+     *
+     * @param i The currently live in-vm broker.
+     */
+    public void setLiveBroker(int i)
+    { }
+
+    /**
+     * Reports the currently live in-vm broker.
+     *
+     * @return The currently live in-vm broker.
+     */
+    public int getLiveBroker()
+    {
+        return 0;
+    }
+
+    /**
+     * Accepts a failure mechanism.
+     *
+     * @param failureMechanism The failure mechanism.
+     */
+    public void setFailureMechanism(CauseFailure failureMechanism)
+    {
+        this.failureMechanism = failureMechanism;
     }
 }

Modified: 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/clocksynch/UDPClockReference.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/clocksynch/UDPClockReference.java?rev=611212&r1=611211&r2=611212&view=diff
==============================================================================
--- 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/clocksynch/UDPClockReference.java
 (original)
+++ 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/clocksynch/UDPClockReference.java
 Fri Jan 11 08:02:09 2008
@@ -22,12 +22,12 @@
 
 import org.apache.log4j.Logger;
 
+import uk.co.thebadgerset.junit.extensions.ShutdownHookable;
+
 import java.io.IOException;
 import java.net.*;
 import java.nio.ByteBuffer;
 
-import uk.co.thebadgerset.junit.extensions.ShutdownHookable;
-
 /**
  * UDPClockReference supplies a refernce clock signal (generated from 
System.nanoTime()).
  *
@@ -49,7 +49,7 @@
     private static final int TIMEOUT = 200;
 
     /** Defines the port to run the clock reference on. */
-    public static final int REFERENCE_PORT = 4445;
+    public static final int REFERENCE_PORT = 4444;
 
     /** Holds the socket to receive clock reference requests on. */
     protected DatagramSocket socket = null;

Modified: 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/distributedtesting/Coordinator.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/distributedtesting/Coordinator.java?rev=611212&r1=611211&r2=611212&view=diff
==============================================================================
--- 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/distributedtesting/Coordinator.java
 (original)
+++ 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/distributedtesting/Coordinator.java
 Fri Jan 11 08:02:09 2008
@@ -330,6 +330,7 @@
         {
             log.debug("Top level handler caught execption.", e);
             console.info(e.getMessage());
+            e.printStackTrace();
             System.exit(EXCEPTION_EXIT);
         }
     }

Added: 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/qpid/CauseFailureDecorator.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/qpid/CauseFailureDecorator.java?rev=611212&view=auto
==============================================================================
--- 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/qpid/CauseFailureDecorator.java
 (added)
+++ 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/qpid/CauseFailureDecorator.java
 Fri Jan 11 08:02:09 2008
@@ -0,0 +1,95 @@
+/*
+ *
+ * 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.
+ *
+ */
+package org.apache.qpid.test.framework.qpid;
+
+import junit.framework.Test;
+import junit.framework.TestResult;
+
+import org.apache.qpid.test.framework.BrokerLifecycleAware;
+import org.apache.qpid.test.framework.CauseFailureUserPrompt;
+
+import uk.co.thebadgerset.junit.extensions.WrappedSuiteTestDecorator;
+
+/**
+ * CauseFailureDecorator applies decorations to [EMAIL PROTECTED] 
BrokerLifecycleAware} tests, so that they may use different failure
+ * mechanisms. It is capable of detecting when a test case uses in-vm brokers, 
and setting up an automatic failure
+ * for those tests, so that the current live broker can be shut-down by test 
cases. For external brokers, automatic
+ * failure could be implemented, for example by having a kill script. At the 
moment this sets up the failure to prompt
+ * a user interactively to cause a failure, using [EMAIL PROTECTED] 
CauseFailureUserPrompt}.
+ *
+ * <p/><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Setup automatic failures for in-vm brokers. <td> [EMAIL PROTECTED] 
CauseFailureInVM}
+ * <tr><td> Setup user generated failures for external brokers. <td> [EMAIL 
PROTECTED] CauseFailureUserPrompt}.
+ * <tr><td>
+ * </table>
+ *
+ * @todo Slight problem in that CauseFailureInVM is Qpid specific, whereas 
CauseFailureUserPrompt is not. Would like the
+ *       failure decorator to be non-qpid specific so that it can test failure 
of any JMS implementation too. Either pass
+ *       in class name of failure mechanism, set it up in the in-vm decorator 
instead of here but with prompt user as the
+ *       default for when the in-vm decorator is not used?
+ */
+public class CauseFailureDecorator extends WrappedSuiteTestDecorator
+{
+    /** The test suite to run. */
+    private Test test;
+
+    /**
+     * Creates a wrapped test test decorator from another one.
+     *
+     * @param test The test test.
+     */
+    public CauseFailureDecorator(WrappedSuiteTestDecorator test)
+    {
+        super(test);
+        this.test = test;
+    }
+
+    /**
+     * Runs the tests with a LocalAMQPCircuitFactory. Only tests that extend 
FrameworkBaseCase are decorated.
+     *
+     * @param testResult The the results object to monitor the test results 
with.
+     */
+    public void run(TestResult testResult)
+    {
+        for (Test test : getAllUnderlyingTests())
+        {
+            if (test instanceof BrokerLifecycleAware)
+            {
+                BrokerLifecycleAware failureTest = (BrokerLifecycleAware) test;
+                failureTest.setFailureMechanism(new CauseFailureUserPrompt());
+            }
+        }
+
+        // Run the test.
+        test.run(testResult);
+    }
+
+    /**
+     * Prints the name of the test for debugging purposes.
+     *
+     * @return The name of the test.
+     */
+    public String toString()
+    {
+        return "CauseFailureDecorator: [test = \"" + test + "\"]";
+    }
+}

Added: 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/qpid/CauseFailureInVM.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/qpid/CauseFailureInVM.java?rev=611212&view=auto
==============================================================================
--- 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/qpid/CauseFailureInVM.java
 (added)
+++ 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/qpid/CauseFailureInVM.java
 Fri Jan 11 08:02:09 2008
@@ -0,0 +1,70 @@
+/*
+ *
+ * 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.
+ *
+ */
+package org.apache.qpid.test.framework.qpid;
+
+import org.apache.qpid.client.transport.TransportConnection;
+import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.test.framework.CauseFailure;
+import org.apache.qpid.test.framework.BrokerLifecycleAware;
+
+/**
+ * <p/><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Cause messaging broker failure on the active in-vm broker.
+ *     <td> [EMAIL PROTECTED] TransportConnection}, [EMAIL PROTECTED] 
ApplicationRegistry}
+ * </table>
+ */
+public class CauseFailureInVM implements CauseFailure
+{
+    /** Holds the in-vm broker instrumented test case to create failures for. 
*/
+    private BrokerLifecycleAware inVMTest;
+
+    /**
+     * Creates an automated failure mechanism for testing against in-vm 
brokers. The test to create the mechanism
+     * for is specified, and as this failure is for in-vm brokers, the test 
must be [EMAIL PROTECTED] org.apache.qpid.test.framework.BrokerLifecycleAware}. 
The test
+     * must also report that it is currently being run against an in-vm 
broker, and it is a runtime error if it is not,
+     * as the creator of this failure mechanism should already have checked 
that it is.
+     *
+     * @param inVMTest The test case to create an automated failure mechanism 
for.
+     */
+    public CauseFailureInVM(BrokerLifecycleAware inVMTest)
+    {
+        // Check that the test is really using in-vm brokers.
+        if (!inVMTest.usingInVmBroker())
+        {
+            throw new RuntimeException(
+                "Cannot create in-vm broker failure mechanism for a test that 
is not using in-vm brokers.");
+        }
+
+        this.inVMTest = inVMTest;
+    }
+
+    /**
+     * Causes the active message broker to fail.
+     */
+    public void causeFailure()
+    {
+        int liveBroker = inVMTest.getLiveBroker();
+
+        TransportConnection.killVMBroker(liveBroker);
+        ApplicationRegistry.remove(liveBroker);
+    }
+}

Modified: 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/qpid/InVMBrokerDecorator.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/qpid/InVMBrokerDecorator.java?rev=611212&r1=611211&r2=611212&view=diff
==============================================================================
--- 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/qpid/InVMBrokerDecorator.java
 (original)
+++ 
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/framework/qpid/InVMBrokerDecorator.java
 Fri Jan 11 08:02:09 2008
@@ -26,6 +26,7 @@
 import org.apache.qpid.client.transport.TransportConnection;
 import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
 import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.test.framework.BrokerLifecycleAware;
 import org.apache.qpid.test.framework.FrameworkBaseCase;
 
 import uk.co.thebadgerset.junit.extensions.SetupTaskAware;
@@ -43,6 +44,11 @@
  *
  * @todo May need to add a more fine grained injection point for the in-vm 
broker management, as this acts at the
  *       suite level, rather than the individual test level.
+ *
+ * @todo Management of in-vm brokers for failure testing. Failure test setups 
may need to set their connection url to
+ *       use multiple broker (vm://:1;vm://:2), with fail-over between them. 
There is round-robin fail-over, but also
+ *       retry? A test case using an in-vm broker needs to record which one it 
is using, so that it can be
+ *       killed/restarted.
  */
 public class InVMBrokerDecorator extends WrappedSuiteTestDecorator
 {
@@ -71,7 +77,7 @@
         {
             // Check that the test to have an in-vm broker setup/teardown task 
added to it, is actually a framework
             // test that can handle setup tasks.
-            if ((test instanceof FrameworkBaseCase) && (test instanceof 
SetupTaskAware))
+            if ((test instanceof SetupTaskAware))
             {
                 SetupTaskAware frameworkTest = (SetupTaskAware) test;
 
@@ -100,6 +106,16 @@
                             ApplicationRegistry.remove(1);
                         }
                     });
+
+                // Check if the test is aware whether or not it can control 
the broker life cycle, and if so provide
+                // additional instrumentation for it to control the in-vm 
broker through.
+                if (test instanceof BrokerLifecycleAware)
+                {
+                    BrokerLifecycleAware inVMTest = (BrokerLifecycleAware) 
test;
+                    inVMTest.setInVmBrokers();
+                    inVMTest.setLiveBroker(1);
+                    inVMTest.setFailureMechanism(new 
CauseFailureInVM(inVMTest));
+                }
             }
         }
 


Reply via email to