activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r636037 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/kaha/impl/async/ main/java/org/apache/activemq/store/amq/ test/java/org/apache/activemq/broker/ft/
Date Tue, 11 Mar 2008 17:59:30 GMT
Author: chirino
Date: Tue Mar 11 10:59:24 2008
New Revision: 636037

URL: http://svn.apache.org/viewvc?rev=636037&view=rev
Log:
Fix for the failing QueueMasterSlaveTestUsingSharedFileTest on windows.  The lock on the AsyncDataManager
was not being retried.

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/AsyncDataManager.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQPersistenceAdapter.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/ft/QueueMasterSlaveTest.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/ft/QueueMasterSlaveTestUsingSharedFileTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/AsyncDataManager.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/AsyncDataManager.java?rev=636037&r1=636036&r2=636037&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/AsyncDataManager.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/AsyncDataManager.java
Tue Mar 11 10:59:24 2008
@@ -113,11 +113,7 @@
         }
 
         started = true;
-        directory.mkdirs();
-        synchronized (this) {
-            controlFile = new ControlFile(new File(directory, filePrefix + "control"), CONTROL_RECORD_MAX_LENGTH);
-            controlFile.lock();
-        }
+        lock();
 
         ByteSequence sequence = controlFile.load();
         if (sequence != null && sequence.getLength() > 0) {
@@ -193,6 +189,16 @@
         };
         Scheduler.executePeriodically(cleanupTask, 1000 * 30);
     }
+
+	public void lock() throws IOException {
+		synchronized (this) {
+			if( controlFile == null ) {
+		        directory.mkdirs();
+				controlFile = new ControlFile(new File(directory, filePrefix + "control"), CONTROL_RECORD_MAX_LENGTH);
+			}
+            controlFile.lock();
+        }
+	}
 
     protected Location recoveryCheck(DataFile dataFile, Location location) throws IOException
{
         if (location == null) {

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQPersistenceAdapter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQPersistenceAdapter.java?rev=636037&r1=636036&r2=636037&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQPersistenceAdapter.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQPersistenceAdapter.java
Tue Mar 11 10:59:24 2008
@@ -30,9 +30,9 @@
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicLong;
-import java.util.concurrent.locks.ReentrantLock;
 
 import org.apache.activeio.journal.Journal;
+import org.apache.activeio.journal.active.JournalLockedException;
 import org.apache.activemq.broker.BrokerService;
 import org.apache.activemq.broker.BrokerServiceAware;
 import org.apache.activemq.broker.ConnectionContext;
@@ -90,6 +90,7 @@
     private static final String PROPERTY_PREFIX = "org.apache.activemq.store.amq";
     private static final boolean BROKEN_FILE_LOCK;
     private static final boolean DISABLE_LOCKING;
+    private static final int JOURNAL_LOCKED_WAIT_DELAY = 10 * 1000;
 
     private AsyncDataManager asyncDataManager;
     private ReferenceStoreAdapter referenceStoreAdapter;
@@ -125,6 +126,7 @@
     private RandomAccessFile lockFile;
     private FileLock lock;
     private boolean disableLocking = DISABLE_LOCKING;
+	private boolean failIfJournalIsLocked;
 
     public String getBrokerName() {
         return this.brokerName;
@@ -186,6 +188,24 @@
         if (taskRunnerFactory == null) {
             taskRunnerFactory = createTaskRunnerFactory();
         }
+        
+        if (failIfJournalIsLocked) {
+            asyncDataManager.lock();
+        } else {
+            while (true) {
+                try {
+                    asyncDataManager.lock();
+                    break;
+                } catch (IOException e) {
+                    LOG.info("Journal is locked... waiting " + (JOURNAL_LOCKED_WAIT_DELAY
/ 1000) + " seconds for the journal to be unlocked.");
+                    try {
+                        Thread.sleep(JOURNAL_LOCKED_WAIT_DELAY);
+                    } catch (InterruptedException e1) {
+                    }
+                }
+            }
+        }
+        
         asyncDataManager.start();
         if (deleteAllMessages) {
             asyncDataManager.delete();

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/ft/QueueMasterSlaveTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/ft/QueueMasterSlaveTest.java?rev=636037&r1=636036&r2=636037&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/ft/QueueMasterSlaveTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/ft/QueueMasterSlaveTest.java
Tue Mar 11 10:59:24 2008
@@ -17,6 +17,10 @@
 package org.apache.activemq.broker.ft;
 
 import java.io.File;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.JmsTopicSendReceiveWithTwoConnectionsTest;
 import org.apache.activemq.broker.BrokerService;
@@ -32,7 +36,8 @@
     private static final transient Log LOG = LogFactory.getLog(QueueMasterSlaveTest.class);
 
     protected BrokerService master;
-    protected BrokerService slave;
+    protected AtomicReference<BrokerService> slave = new AtomicReference<BrokerService>();
+    protected CountDownLatch slaveStarted = new CountDownLatch(1);
     protected int inflightMessageCount;
     protected int failureCount = 50;
     protected String uriString = "failover://(tcp://localhost:62001,tcp://localhost:62002)?randomize=false";
@@ -62,7 +67,12 @@
 
     protected void tearDown() throws Exception {
         super.tearDown();
-        slave.stop();
+        
+    	slaveStarted.await(5, TimeUnit.SECONDS);
+        BrokerService brokerService = slave.get();
+        if( brokerService!=null ) {
+        	brokerService.stop();
+        }
         master.stop();
     }
 
@@ -84,16 +94,18 @@
     }
     
     protected void createMaster() throws Exception {
-        BrokerFactoryBean brokerFactory = new BrokerFactoryBean(new ClassPathResource(getMasterXml()));
-        brokerFactory.afterPropertiesSet();
-        master = brokerFactory.getBroker();
-        master.start();
+		BrokerFactoryBean brokerFactory = new BrokerFactoryBean(new ClassPathResource(getMasterXml()));
+		brokerFactory.afterPropertiesSet();
+		master = brokerFactory.getBroker();
+		master.start();
     }
     
     protected void createSlave() throws Exception {
-        BrokerFactoryBean brokerFactory = new BrokerFactoryBean(new ClassPathResource(getSlaveXml()));
+    	BrokerFactoryBean brokerFactory = new BrokerFactoryBean(new ClassPathResource(getSlaveXml()));
         brokerFactory.afterPropertiesSet();
-        slave = brokerFactory.getBroker();
-        slave.start();
+        BrokerService broker = brokerFactory.getBroker();
+        broker.start();
+        slave.set(broker);
+        slaveStarted.countDown();
     }
 }

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/ft/QueueMasterSlaveTestUsingSharedFileTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/ft/QueueMasterSlaveTestUsingSharedFileTest.java?rev=636037&r1=636036&r2=636037&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/ft/QueueMasterSlaveTestUsingSharedFileTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/ft/QueueMasterSlaveTestUsingSharedFileTest.java
Tue Mar 11 10:59:24 2008
@@ -16,10 +16,6 @@
  */
 package org.apache.activemq.broker.ft;
 
-import org.apache.activemq.xbean.BrokerFactoryBean;
-import org.springframework.core.io.ClassPathResource;
-
-
 public class QueueMasterSlaveTestUsingSharedFileTest extends
         QueueMasterSlaveTest {
     
@@ -31,17 +27,15 @@
         return "org/apache/activemq/broker/ft/sharedFileMaster.xml";
     }
     
-    protected void createSlave() throws Exception {
+    protected void createSlave() throws Exception {    	
+    	// Start the Brokers async since starting them up could be a blocking operation..
         new Thread(new Runnable() {
-
             public void run() {
                 try {
                     QueueMasterSlaveTestUsingSharedFileTest.super.createSlave();
                 } catch (Exception e) {
-
                     e.printStackTrace();
                 }
-
             }
 
         }).start();



Mime
View raw message