Author: cschneider
Date: Tue Aug 30 14:45:53 2011
New Revision: 1163240
URL: http://svn.apache.org/viewvc?rev=1163240&view=rev
Log:
CAMEL-4381 Fix bug where Service status was not reset when Exception occurs
while starting. Added test for this bug. Moved test class to support package
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/support/ServiceSupportTest.java
(contents, props changed)
- copied, changed from r1163153,
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ServiceSupportTest.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/support/ServiceSupport.java
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ServiceSupportTest.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/support/ServiceSupport.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/support/ServiceSupport.java?rev=1163240&r1=1163239&r2=1163240&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/support/ServiceSupport.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/support/ServiceSupport.java
Tue Aug 30 14:45:53 2011
@@ -56,15 +56,24 @@ public abstract class ServiceSupport imp
}
if (starting.compareAndSet(false, true)) {
LOG.trace("Starting service");
- doStart();
- started.set(true);
- starting.set(false);
- stopping.set(false);
- stopped.set(false);
- suspending.set(false);
- suspended.set(false);
- shutdown.set(false);
- shuttingdown.set(false);
+ try {
+ doStart();
+ started.set(true);
+ starting.set(false);
+ stopping.set(false);
+ stopped.set(false);
+ suspending.set(false);
+ suspended.set(false);
+ shutdown.set(false);
+ shuttingdown.set(false);
+ } catch (Exception e) {
+ try {
+ stop();
+ } catch (Exception e2) {
+ // Ignore exceptions as we want to show the original
exception
+ }
+ throw e;
+ }
}
}
Copied:
camel/trunk/camel-core/src/test/java/org/apache/camel/support/ServiceSupportTest.java
(from r1163153,
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ServiceSupportTest.java)
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/support/ServiceSupportTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/support/ServiceSupportTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ServiceSupportTest.java&r1=1163153&r2=1163240&rev=1163240&view=diff
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ServiceSupportTest.java
(original)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/support/ServiceSupportTest.java
Tue Aug 30 14:45:53 2011
@@ -14,13 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.impl;
+package org.apache.camel.support;
import org.apache.camel.TestSupport;
-import org.apache.camel.support.ServiceSupport;
/**
- * @version
+ * @version
*/
public class ServiceSupportTest extends TestSupport {
@@ -92,5 +91,31 @@ public class ServiceSupportTest extends
assertEquals(true, service.isShutdown());
}
+ public void testExceptionOnStart() throws Exception {
+ ServiceSupportTestExOnStart service = new
ServiceSupportTestExOnStart();
+ try {
+ service.start();
+ fail("RuntimeException expected");
+ } catch (RuntimeException e) {
+ assertEquals(true, service.isStopped());
+ assertEquals(false, service.isStopping());
+ assertEquals(false, service.isStarted());
+ assertEquals(false, service.isStarting());
+ }
+ }
+
+ public static class ServiceSupportTestExOnStart extends ServiceSupport {
+
+ @Override
+ protected void doStart() throws Exception {
+ throw new RuntimeException("This service throws an exception when
starting");
+ }
+ @Override
+ protected void doStop() throws Exception {
+ // TODO Auto-generated method stub
+
+ }
+
+ }
}
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/support/ServiceSupportTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/support/ServiceSupportTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date