cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1360188 - in /cxf/trunk/api/src: main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java test/java/org/apache/cxf/workqueue/AutomaticWorkQueueTest.java
Date Wed, 11 Jul 2012 14:25:36 GMT
Author: dkulp
Date: Wed Jul 11 14:25:36 2012
New Revision: 1360188

URL: http://svn.apache.org/viewvc?rev=1360188&view=rev
Log:
[CXF-4417] Fix problem of not throwing rejectedexecutionexception if
runnable was not enqueued.

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java
    cxf/trunk/api/src/test/java/org/apache/cxf/workqueue/AutomaticWorkQueueTest.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java?rev=1360188&r1=1360187&r2=1360188&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/workqueue/AutomaticWorkQueueImpl.java Wed Jul
11 14:25:36 2012
@@ -435,9 +435,11 @@ public class AutomaticWorkQueueImpl impl
             execute(work);
         } catch (RejectedExecutionException ree) {
             try {
-                getExecutor().getQueue().offer(work, timeout, TimeUnit.MILLISECONDS);
+                if (!getExecutor().getQueue().offer(work, timeout, TimeUnit.MILLISECONDS))
{
+                    throw ree;
+                }
             } catch (InterruptedException ie) {
-                throw new RejectedExecutionException(ie);
+                throw ree;
             }
         }    
     }

Modified: cxf/trunk/api/src/test/java/org/apache/cxf/workqueue/AutomaticWorkQueueTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/workqueue/AutomaticWorkQueueTest.java?rev=1360188&r1=1360187&r2=1360188&view=diff
==============================================================================
--- cxf/trunk/api/src/test/java/org/apache/cxf/workqueue/AutomaticWorkQueueTest.java (original)
+++ cxf/trunk/api/src/test/java/org/apache/cxf/workqueue/AutomaticWorkQueueTest.java Wed Jul
11 14:25:36 2012
@@ -77,6 +77,35 @@ public class AutomaticWorkQueueTest exte
         assertEquals(DEFAULT_LOW_WATER_MARK, workqueue.getLowWaterMark());
     }
 
+    
+    @Test
+    public void testEnqueueWithTimeout() throws Exception {
+        workqueue = new AutomaticWorkQueueImpl(2, 2,
+                                               2,
+                                               2,
+                                               DEFAULT_DEQUEUE_TIMEOUT);
+        
+        final Object lock = new Object();
+        int x = 0;
+        try {
+            synchronized (lock) {
+                for (x = 0; x < 6; x++) {
+                    workqueue.execute(new Runnable() {
+                        public void run() {
+                            synchronized (lock) {
+                                //just need to wait until all the runnables are created and
enqueued and such.
+                            }
+                        }
+                    }, 50);
+                }
+            }
+            fail("Should have failed with a RejectedExecutionException as 5th should not
be queuable");
+        } catch (RejectedExecutionException rex) {
+            assertEquals(x, 4);
+        }
+    }
+    
+    
     @Test
     public void testEnqueue() {
         workqueue = new AutomaticWorkQueueImpl(DEFAULT_MAX_QUEUE_SIZE, INITIAL_SIZE,



Mime
View raw message