You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2010/08/20 22:01:11 UTC

svn commit: r987621 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializer.java test/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializerTest.java

Author: oheger
Date: Fri Aug 20 20:01:10 2010
New Revision: 987621

URL: http://svn.apache.org/viewvc?rev=987621&view=rev
Log:
Added a new isSuccessful() method to the result object of MultiBackgroundInitializer.

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializer.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializerTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializer.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializer.java?rev=987621&r1=987620&r2=987621&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializer.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializer.java Fri Aug 20 20:01:10 2010
@@ -319,6 +319,16 @@ public class MultiBackgroundInitializer
         }
 
         /**
+         * Returns a flag whether the whole initialization was successful. This
+         * is the case if no child initializer has thrown an exception.
+         *
+         * @return a flag whether the initialization was successful
+         */
+        public boolean isSuccessful() {
+            return exceptions.isEmpty();
+        }
+
+        /**
          * Checks whether an initializer with the given name exists. If not,
          * throws an exception. If it exists, the associated child initializer
          * is returned.

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializerTest.java?rev=987621&r1=987620&r2=987621&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializerTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/concurrent/MultiBackgroundInitializerTest.java Fri Aug 20 20:01:10 2010
@@ -286,6 +286,37 @@ public class MultiBackgroundInitializerT
     }
 
     /**
+     * Tests the isSuccessful() method of the result object if no child
+     * initializer has thrown an exception.
+     */
+    @Test
+    public void testInitializeResultsIsSuccessfulTrue()
+            throws ConcurrentException {
+        ChildBackgroundInitializer child = new ChildBackgroundInitializer();
+        initializer.addInitializer(CHILD_INIT, child);
+        initializer.start();
+        MultiBackgroundInitializer.MultiBackgroundInitializerResults res = initializer
+                .get();
+        assertTrue("Wrong success flag", res.isSuccessful());
+    }
+
+    /**
+     * Tests the isSuccessful() method of the result object if at least one
+     * child initializer has thrown an exception.
+     */
+    @Test
+    public void testInitializeResultsIsSuccessfulFalse()
+            throws ConcurrentException {
+        ChildBackgroundInitializer child = new ChildBackgroundInitializer();
+        child.ex = new Exception();
+        initializer.addInitializer(CHILD_INIT, child);
+        initializer.start();
+        MultiBackgroundInitializer.MultiBackgroundInitializerResults res = initializer
+                .get();
+        assertFalse("Wrong success flag", res.isSuccessful());
+    }
+
+    /**
      * Tests whether MultiBackgroundInitializers can be combined in a nested
      * way.
      */