activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r358539 - in /incubator/activemq/trunk/activemq-core: ./ src/test/java/org/activemq/ src/test/java/org/activemq/broker/ src/test/java/org/activemq/proxy/ src/test/java/org/activemq/transport/discovery/
Date Thu, 22 Dec 2005 09:14:50 GMT
Author: aco
Date: Thu Dec 22 01:14:26 2005
New Revision: 358539

URL: http://svn.apache.org/viewcvs?rev=358539&view=rev
Log:
Added an AutoFailTestSupport as the super class of CombinationTestSupport. If enabled, this
enforces each test case to run only on a predefined time frame (by default 5 mins). After
the allotted time, a separate thread will force the vm to exit abnormally to prevent hanging
the test case. The AutoFailTestSupport is disabled by default. Should be noted, when the test
case exits abnormally, no output is written to the test reports, but there is output in the
log4j log file.

Enabled auto fail for ProxyConnectorTest and DiscoveryTransportBrokerTest. Added ProxyConnectorTest
to testing.

Propagated the setUp and tearDown method in BrokerTestSupport.

Added:
    incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/AutoFailTestSupport.java
Modified:
    incubator/activemq/trunk/activemq-core/project.xml
    incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/CombinationTestSupport.java
    incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/broker/BrokerTestSupport.java
    incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/proxy/ProxyConnectorTest.java
    incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/transport/discovery/DiscoveryTransportBrokerTest.java

Modified: incubator/activemq/trunk/activemq-core/project.xml
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/project.xml?rev=358539&r1=358538&r2=358539&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/project.xml (original)
+++ incubator/activemq/trunk/activemq-core/project.xml Thu Dec 22 01:14:26 2005
@@ -339,10 +339,7 @@
                 
 		        <!-- These are performance tests so take too long to run -->
                 <exclude>**/perf/*</exclude>
-                
-                <!-- This test sometimes hangs -->
-                <exclude>**/ProxyConnectorTest.*</exclude>
-                
+
                 <!-- This test currently fails -->
                 <exclude>**/ItStillMarshallsTheSameTest.*</exclude>
             </excludes>

Added: incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/AutoFailTestSupport.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/AutoFailTestSupport.java?rev=358539&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/AutoFailTestSupport.java
(added)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/AutoFailTestSupport.java
Thu Dec 22 01:14:26 2005
@@ -0,0 +1,133 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.activemq;
+
+import junit.framework.TestCase;
+
+import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+/**
+ * Enforces a test case to run for only an allotted time to prevent them from hanging
+ * and breaking the whole testing.
+ * 
+ * @version $Revision: 1.0 $
+ */
+
+public class AutoFailTestSupport extends TestCase {
+     private static final Log log = LogFactory.getLog(AutoFailTestSupport.class);
+
+    public static final int EXIT_SUCCESS = 0;
+    public static final int EXIT_ERROR   = 1;
+
+    private long          maxTestTime = 5 * 60 * 1000; // 5 mins by default
+    private Thread        autoFailThread;
+
+    private boolean       verbose     = true;
+    private boolean       useAutoFail = false; // Disable auto fail by default
+    private AtomicBoolean isTestSuccess = new AtomicBoolean(false);
+
+    protected void setUp() throws Exception {
+        // Runs the auto fail thread before performing any setup
+        if (isAutoFail()) {
+            startAutoFailThread();
+        }
+        super.setUp();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+
+        // Stops the auto fail thread only after performing any clean up
+        stopAutoFailThread();
+    }
+
+    /**
+     * Manually start the auto fail thread. To start it automatically, just set the auto
fail to true before calling
+     * any setup methods. As a rule, this method is used only when you are not sure, if the
setUp and tearDown method
+     * is propagated correctly.
+     */
+    public void startAutoFailThread() {
+        setAutoFail(true);
+        autoFailThread = new Thread(new Runnable() {
+            public void run() {
+                try {
+                    // Wait for test to finish succesfully
+                    Thread.sleep(getMaxTestTime());
+                } catch (InterruptedException e) {
+                    // This usually means the test was successful
+                } finally {
+                    // Check if the test was able to tear down succesfully, which usually
means, it has finished its run.
+                    if (!isTestSuccess.get()) {
+                        System.err.println("Test case has exceeded the maximum allotted time
to run of: " + getMaxTestTime() + " ms.");
+                        log.fatal("Test case has exceeded the maximum allotted time to run
of: " + getMaxTestTime() + " ms.");
+                        System.exit(EXIT_ERROR);
+                    }
+                }
+            }
+        }, "AutoFailThread");
+
+        if (verbose) {
+            System.out.println("Starting auto fail thread...");
+        }
+
+        log.info("Starting auto fail thread...");
+        autoFailThread.start();
+    }
+
+    /**
+     * Manually stops the auto fail thread. As a rule, this method is used only when you
are not sure, if the
+     * setUp and tearDown method is propagated correctly.
+     */
+    public void stopAutoFailThread() {
+        if (isAutoFail() && autoFailThread != null && autoFailThread.isAlive())
{
+            isTestSuccess.set(true);
+
+            if (verbose) {
+                System.out.println("Stopping auto fail thread...");
+            }
+
+            log.info("Stopping auto fail thread...");
+            autoFailThread.interrupt();
+        }
+    }
+
+    /**
+     * Sets the auto fail value. As a rule, this should be used only before any setup methods
is called to automatically
+     * enable the auto fail thread in the setup method of the test case.
+     * @param val
+     */
+    public void setAutoFail(boolean val) {
+        this.useAutoFail = val;
+    }
+
+    public boolean isAutoFail() {
+        return this.useAutoFail;
+    }
+
+    /**
+     * The assigned value will only be reflected when the auto fail thread has started its
run. Value is in milliseconds.
+     * @param val
+     */
+    public void setMaxTestTime(long val) {
+        this.maxTestTime = val;
+    }
+
+    public long getMaxTestTime() {
+        return this.maxTestTime;
+    }
+}

Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/CombinationTestSupport.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/CombinationTestSupport.java?rev=358539&r1=358538&r2=358539&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/CombinationTestSupport.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/CombinationTestSupport.java
Thu Dec 22 01:14:26 2005
@@ -30,7 +30,6 @@
 import java.util.Map;
 
 import junit.framework.Test;
-import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
 /**
@@ -63,7 +62,7 @@
  * 
  * @version $Revision: 1.5 $
  */
-public class CombinationTestSupport extends TestCase {
+public class CombinationTestSupport extends AutoFailTestSupport {
 
     private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
             .getLog(CombinationTestSupport.class);

Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/broker/BrokerTestSupport.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/broker/BrokerTestSupport.java?rev=358539&r1=358538&r2=358539&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/broker/BrokerTestSupport.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/broker/BrokerTestSupport.java
Thu Dec 22 01:14:26 2005
@@ -75,6 +75,7 @@
 
 
     protected void setUp() throws Exception {
+        super.setUp();
         broker = createBroker();
         broker.start();
     }
@@ -85,6 +86,7 @@
     
     protected void tearDown() throws Exception {
         broker.stop();
+        super.tearDown();
     }
     
     protected ConsumerInfo createConsumerInfo(SessionInfo sessionInfo, ActiveMQDestination
destination) throws Throwable {

Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/proxy/ProxyConnectorTest.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/proxy/ProxyConnectorTest.java?rev=358539&r1=358538&r2=358539&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/proxy/ProxyConnectorTest.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/proxy/ProxyConnectorTest.java
Thu Dec 22 01:14:26 2005
@@ -43,7 +43,12 @@
     public byte destinationType;
     public int deliveryMode;
 
-    public void initCombosForTestSendAndConsume() {    
+    public void setUp() throws Exception {
+        super.setAutoFail(true);
+        super.setUp();
+    }
+
+    public void initCombosForTestSendAndConsume() {
         addCombinationValues( "deliveryMode", new Object[]{ 
                 new Integer(DeliveryMode.NON_PERSISTENT), 
                 new Integer(DeliveryMode.PERSISTENT)
@@ -84,7 +89,7 @@
         } catch (Exception e) {
             e.printStackTrace();
         }
-        
+
         // Send the message to the local broker.
         connection1.request(createMessage(producerInfo, destination, deliveryMode));
                 

Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/transport/discovery/DiscoveryTransportBrokerTest.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/transport/discovery/DiscoveryTransportBrokerTest.java?rev=358539&r1=358538&r2=358539&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/transport/discovery/DiscoveryTransportBrokerTest.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/activemq/transport/discovery/DiscoveryTransportBrokerTest.java
Thu Dec 22 01:14:26 2005
@@ -43,6 +43,11 @@
     
 	static final private Log log = LogFactory.getLog(DiscoveryTransportBrokerTest.class);
 
+    public void setUp() throws Exception {
+        super.setAutoFail(true);
+        super.setUp();
+    }
+
 	public void testPublisherFailsOver() throws Throwable {
         ActiveMQDestination destination = new ActiveMQQueue("TEST");
         int deliveryMode = DeliveryMode.NON_PERSISTENT;



Mime
View raw message