activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject [13/14] activemq git commit: https://issues.apache.org/jira/browse/AMQ-6799 - IOExceptionHandler during the startup
Date Thu, 07 Sep 2017 16:17:49 GMT
https://issues.apache.org/jira/browse/AMQ-6799 - IOExceptionHandler during the startup

(cherry picked from commit c7291f1ecfefec7aad6fcf168e298e2ef0af8ed7)


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/ccf8dbe2
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/ccf8dbe2
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/ccf8dbe2

Branch: refs/heads/activemq-5.15.x
Commit: ccf8dbe28be0961b571b6125c78758dd5fb2cad9
Parents: 0924f98
Author: Dejan Bosanac <dejan@nighttale.net>
Authored: Thu Aug 24 14:04:28 2017 +0200
Committer: Timothy Bish <tabish121@gmail.com>
Committed: Thu Sep 7 12:14:35 2017 -0400

----------------------------------------------------------------------
 .../util/DefaultIOExceptionHandler.java         |  6 ++-
 .../util/DefaultIOExceptionHandlerTest.java     |  5 +++
 .../store/jdbc/LeaseDatabaseLocker.java         |  2 +-
 .../jdbc/JDBCIOExceptionHandlerMockeryTest.java |  2 +
 .../store/jdbc/JDBCIOExceptionHandlerTest.java  | 43 ++++++++++++++++++++
 5 files changed, 55 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/ccf8dbe2/activemq-broker/src/main/java/org/apache/activemq/util/DefaultIOExceptionHandler.java
----------------------------------------------------------------------
diff --git a/activemq-broker/src/main/java/org/apache/activemq/util/DefaultIOExceptionHandler.java
b/activemq-broker/src/main/java/org/apache/activemq/util/DefaultIOExceptionHandler.java
index 7668364..022707d 100644
--- a/activemq-broker/src/main/java/org/apache/activemq/util/DefaultIOExceptionHandler.java
+++ b/activemq-broker/src/main/java/org/apache/activemq/util/DefaultIOExceptionHandler.java
@@ -51,7 +51,7 @@ import org.slf4j.LoggerFactory;
 
     @Override
     public void handle(IOException exception) {
-        if (ignoreAllErrors) {
+        if (!broker.isStarted() || ignoreAllErrors) {
             allowIOResumption();
             LOG.info("Ignoring IO exception, " + exception, exception);
             return;
@@ -167,7 +167,9 @@ import org.slf4j.LoggerFactory;
 
     protected void allowIOResumption() {
         try {
-            broker.getPersistenceAdapter().allowIOResumption();
+            if (broker.getPersistenceAdapter() != null) {
+                broker.getPersistenceAdapter().allowIOResumption();
+            }
         } catch (IOException e) {
             LOG.warn("Failed to allow IO resumption", e);
         }

http://git-wip-us.apache.org/repos/asf/activemq/blob/ccf8dbe2/activemq-broker/src/test/java/org/apache/activemq/util/DefaultIOExceptionHandlerTest.java
----------------------------------------------------------------------
diff --git a/activemq-broker/src/test/java/org/apache/activemq/util/DefaultIOExceptionHandlerTest.java
b/activemq-broker/src/test/java/org/apache/activemq/util/DefaultIOExceptionHandlerTest.java
index ea46809..f8d1ee9 100644
--- a/activemq-broker/src/test/java/org/apache/activemq/util/DefaultIOExceptionHandlerTest.java
+++ b/activemq-broker/src/test/java/org/apache/activemq/util/DefaultIOExceptionHandlerTest.java
@@ -49,6 +49,11 @@ public class DefaultIOExceptionHandlerTest {
         underTest.setSystemExitOnShutdown(exitPlease);
         underTest.setBrokerService(new BrokerService() {
             @Override
+            public boolean isStarted() {
+                return true;
+            }
+
+            @Override
             public void stop() throws Exception {
                 shutdownOnExitSet.set(isSystemExitOnShutdown());
                 stopCalled.countDown();

http://git-wip-us.apache.org/repos/asf/activemq/blob/ccf8dbe2/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/LeaseDatabaseLocker.java
----------------------------------------------------------------------
diff --git a/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/LeaseDatabaseLocker.java
b/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/LeaseDatabaseLocker.java
index cbbc73d..f6e7f2a 100644
--- a/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/LeaseDatabaseLocker.java
+++ b/activemq-jdbc-store/src/main/java/org/apache/activemq/store/jdbc/LeaseDatabaseLocker.java
@@ -91,7 +91,7 @@ public class LeaseDatabaseLocker extends AbstractJDBCLocker {
                                     + e, e);
                 }
                 if (handleStartException) {
-                    lockable.getBrokerService().handleIOException(IOExceptionSupport.create(e));
+                    throw e;
                 }
             } finally {
                 close(statement);

http://git-wip-us.apache.org/repos/asf/activemq/blob/ccf8dbe2/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerMockeryTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerMockeryTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerMockeryTest.java
index 8a7dc63..e7224b6 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerMockeryTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerMockeryTest.java
@@ -65,6 +65,8 @@ public class JDBCIOExceptionHandlerMockeryTest {
 
         // simulate jdbc up between hasLock and checkpoint, so hasLock fails to verify
         context.checking(new Expectations() {{
+            allowing(brokerService).isStarted();
+            will(returnValue(true));
             allowing(brokerService).isRestartAllowed();
             will(returnValue(false));
             allowing(brokerService).setSystemExitOnShutdown(with(false));

http://git-wip-us.apache.org/repos/asf/activemq/blob/ccf8dbe2/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerTest.java
index 5144182..a4bd832 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerTest.java
@@ -28,6 +28,7 @@ import javax.jms.Connection;
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.broker.BrokerService;
 import org.apache.activemq.broker.ft.SyncCreateDataSource;
+import org.apache.activemq.bugs.embedded.ThreadExplorer;
 import org.apache.activemq.util.IOHelper;
 import org.apache.activemq.util.LeaseLockerIOExceptionHandler;
 import org.apache.activemq.util.Wait;
@@ -101,6 +102,47 @@ public class JDBCIOExceptionHandlerTest {
         return broker;
     }
 
+    @Test
+    public void testStartWithDatabaseDown() throws Exception {
+        BrokerService broker = new BrokerService();
+
+        JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
+        EmbeddedDataSource embeddedDataSource = (EmbeddedDataSource) jdbc.getDataSource();
+        // create a wrapper to EmbeddedDataSource to allow the connection be
+        // reestablished to derby db
+        dataSource = new ReconnectingEmbeddedDataSource(new SyncCreateDataSource(embeddedDataSource));
+        dataSource.stopDB();
+        jdbc.setDataSource(dataSource);
+
+        jdbc.setLockKeepAlivePeriod(1000l);
+        LeaseDatabaseLocker leaseDatabaseLocker = new LeaseDatabaseLocker();
+        leaseDatabaseLocker.setHandleStartException(true);
+        leaseDatabaseLocker.setLockAcquireSleepInterval(2000l);
+        jdbc.setLocker(leaseDatabaseLocker);
+
+        broker.setPersistenceAdapter(jdbc);
+        LeaseLockerIOExceptionHandler ioExceptionHandler = new LeaseLockerIOExceptionHandler();
+        ioExceptionHandler.setResumeCheckSleepPeriod(1000l);
+        ioExceptionHandler.setStopStartConnectors(true);
+        broker.setIoExceptionHandler(ioExceptionHandler);
+        try {
+            broker.start();
+            fail("Broker should have been stopped!");
+        } catch (Exception e) {
+            Thread.sleep(5000);
+            assertTrue("Broker should have been stopped!", broker.isStopped());
+            Thread[] threads = ThreadExplorer.listThreads();
+            for (int i = 0; i < threads.length; i++) {
+                if (threads[i].getName().startsWith("IOExceptionHandler")) {
+                    fail("IOExceptionHanlder still active");
+                }
+            }
+        } finally {
+            dataSource = null;
+            broker = null;
+        }
+    }
+
     /*
      * run test without JMX enabled
      */
@@ -223,6 +265,7 @@ public class JDBCIOExceptionHandlerTest {
         } finally {
             LOG.debug("*** broker is stopping...");
             broker.stop();
+            broker.waitUntilStopped();
         }
     }
 


Mime
View raw message