You are viewing a plain text version of this content. The canonical link for it is here.
Posted to droids-commits@incubator.apache.org by rf...@apache.org on 2011/12/06 16:55:29 UTC

svn commit: r1211018 - in /incubator/droids/trunk/droids-core/src: main/java/org/apache/droids/impl/SimpleTaskQueueWithHistory.java test/java/org/apache/droids/impl/TestSimpleTaskQueueWithHistory.java

Author: rfrovarp
Date: Tue Dec  6 16:55:28 2011
New Revision: 1211018

URL: http://svn.apache.org/viewvc?rev=1211018&view=rev
Log:
Fixes DROIDS-163.
Thank you to Tobias Rübner for reporting and for the patch.

Modified:
    incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/impl/SimpleTaskQueueWithHistory.java
    incubator/droids/trunk/droids-core/src/test/java/org/apache/droids/impl/TestSimpleTaskQueueWithHistory.java

Modified: incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/impl/SimpleTaskQueueWithHistory.java
URL: http://svn.apache.org/viewvc/incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/impl/SimpleTaskQueueWithHistory.java?rev=1211018&r1=1211017&r2=1211018&view=diff
==============================================================================
--- incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/impl/SimpleTaskQueueWithHistory.java (original)
+++ incubator/droids/trunk/droids-core/src/main/java/org/apache/droids/impl/SimpleTaskQueueWithHistory.java Tue Dec  6 16:55:28 2011
@@ -61,7 +61,7 @@ public class SimpleTaskQueueWithHistory<
   {
     boolean hasChanged = false;
     for (T e : c) {
-      hasChanged = hasChanged || this.add(e);
+      hasChanged = this.add(e) || hasChanged;
     }
     return hasChanged;
   }

Modified: incubator/droids/trunk/droids-core/src/test/java/org/apache/droids/impl/TestSimpleTaskQueueWithHistory.java
URL: http://svn.apache.org/viewvc/incubator/droids/trunk/droids-core/src/test/java/org/apache/droids/impl/TestSimpleTaskQueueWithHistory.java?rev=1211018&r1=1211017&r2=1211018&view=diff
==============================================================================
--- incubator/droids/trunk/droids-core/src/test/java/org/apache/droids/impl/TestSimpleTaskQueueWithHistory.java (original)
+++ incubator/droids/trunk/droids-core/src/test/java/org/apache/droids/impl/TestSimpleTaskQueueWithHistory.java Tue Dec  6 16:55:28 2011
@@ -16,11 +16,17 @@
  */
 package org.apache.droids.impl;
 
+import static org.junit.Assert.*;
+
 import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Collection;
 import java.util.LinkedList;
+import java.util.Queue;
+
 import junit.framework.Assert;
 import org.apache.droids.LinkTask;
-import org.apache.droids.robot.walker.FileTask;
+import org.apache.droids.api.Link;
 import org.junit.Test;
 
 public class TestSimpleTaskQueueWithHistory
@@ -28,7 +34,7 @@ public class TestSimpleTaskQueueWithHist
   @Test
   public void testOffer() throws Exception
   {
-    LinkedList<LinkTask> queue;
+    Queue<LinkTask> queue;
     URI	uri;
     LinkTask task;
 
@@ -42,5 +48,40 @@ public class TestSimpleTaskQueueWithHist
     Assert.assertEquals(1, queue.size());
     queue.offer(task);
     Assert.assertEquals(1, queue.size());
+    queue.poll();
+    Assert.assertEquals(0, queue.size());
+    queue.offer(task);
+    Assert.assertEquals(0, queue.size());
+  }
+  
+  @Test
+  public void testAddAll() throws URISyntaxException 
+  {
+	  Collection<Link> links = new LinkedList<Link>();
+	  links.add(new LinkTask(null, new URI("http://www.example.com"), 0));
+	  links.add(new LinkTask(null, new URI("http://www.example.com/1"), 1));
+	  links.add(new LinkTask(null, new URI("http://www.example.com/2"), 1));
+	  links.add(new LinkTask(null, new URI("http://www.example.com/3"), 1));
+	  links.add(new LinkTask(null, new URI("http://www.example.com/4"), 1));
+	  
+	  Queue<Link> queue = new SimpleTaskQueueWithHistory<Link>();
+	  assertEquals(0, queue.size());
+	  queue.addAll(links);
+	  assertEquals(5, queue.size());
+	  
+	  links.add(new LinkTask(null, new URI("http://www.example.com/1"), 1));
+	  links.add(new LinkTask(null, new URI("http://www.example.com/5"), 1));
+	  links.add(new LinkTask(null, new URI("http://www.example.com/2"), 1));
+
+	  queue.addAll(links);
+	  assertEquals(6, queue.size());
+	  
+	  queue.poll();
+
+	  assertEquals(5, queue.size());
+
+	  queue.addAll(links);
+	  assertEquals(5, queue.size());
+
   }
 }