ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1536997 - in /ace/trunk/org.apache.ace.log: ./ test/org/apache/ace/log/server/task/LogTaskTest.java
Date Wed, 30 Oct 2013 08:09:18 GMT
Author: jawi
Date: Wed Oct 30 08:09:17 2013
New Revision: 1536997

URL: http://svn.apache.org/r1536997
Log:
ACE-389 - fixed failing unit test.

Modified:
    ace/trunk/org.apache.ace.log/   (props changed)
    ace/trunk/org.apache.ace.log/test/org/apache/ace/log/server/task/LogTaskTest.java

Propchange: ace/trunk/org.apache.ace.log/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Wed Oct 30 08:09:17 2013
@@ -4,3 +4,4 @@ generated
 store
 bundle-cache
 felix-cache
+test-output

Modified: ace/trunk/org.apache.ace.log/test/org/apache/ace/log/server/task/LogTaskTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.log/test/org/apache/ace/log/server/task/LogTaskTest.java?rev=1536997&r1=1536996&r2=1536997&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.log/test/org/apache/ace/log/server/task/LogTaskTest.java (original)
+++ ace/trunk/org.apache.ace.log/test/org/apache/ace/log/server/task/LogTaskTest.java Wed
Oct 30 08:09:17 2013
@@ -19,8 +19,10 @@
 package org.apache.ace.log.server.task;
 
 import static org.apache.ace.test.utils.TestUtils.UNIT;
+import static org.testng.Assert.*;
 
 import java.io.IOException;
+import java.io.StringWriter;
 import java.io.Writer;
 import java.util.ArrayList;
 import java.util.List;
@@ -33,18 +35,25 @@ import org.testng.annotations.Test;
 
 public class LogTaskTest {
 
-    private class MockLogSyncTask extends LogSyncTask {
+    private static class MockLogSyncTask extends LogSyncTask {
         public List<Descriptor> m_calledWith = new ArrayList<Descriptor>();
 
         public MockLogSyncTask(String endpoint, String name) {
             super(endpoint, name, LogSyncTask.Mode.PUSH);
         }
 
+        public void clear() {
+            m_calledWith.clear();
+        }
+
+        public int size() {
+            return m_calledWith.size();
+        }
+
         @Override
         protected void writeDescriptor(Descriptor descriptor, Writer writer) throws IOException
{
             m_calledWith.add(descriptor);
         }
-
     }
 
     /**
@@ -55,53 +64,74 @@ public class LogTaskTest {
         // TODO: Test the new LogDescriptor.
         List<Descriptor> src = new ArrayList<Descriptor>();
         List<Descriptor> dest = new ArrayList<Descriptor>();
+
+        String targetID = "targetID";
         MockLogSyncTask task = new MockLogSyncTask("mocklog", "mocklog");
+        Writer mockWriter = new StringWriter();
+
         // compare two empty lists
-        task.writeDelta(task.calculateDelta(src, dest), null);
-        assert task.m_calledWith.isEmpty() : "Delta of two empty lists should be empty";
+        task.writeDelta(task.calculateDelta(src, dest), mockWriter);
+
+        assertTrue(task.m_calledWith.isEmpty(), "Delta of two empty lists should be empty");
+
         // add something to the source
-        src.add(new Descriptor("gwid", 1, new SortedRangeSet("1-5")));
-        task.writeDelta(task.calculateDelta(src, dest), null);
-        assert task.m_calledWith.size() == 1 : "Delta should be 1 instead of: " + task.m_calledWith.size();
-        task.m_calledWith.clear();
+        src.add(new Descriptor(targetID, 1, new SortedRangeSet("1-5")));
+        task.writeDelta(task.calculateDelta(src, dest), mockWriter);
+
+        assertEquals(task.size(), 1, "Incorrect delta");
+
+        task.clear();
+
         // add an overlapping destination
-        dest.add(new Descriptor("gwid", 1, new SortedRangeSet("1-3")));
-        task.writeDelta(task.calculateDelta(src, dest), null);
-        assert task.m_calledWith.size() == 1 : "Delta should be 1 instead of: " + task.m_calledWith.size();
+        dest.add(new Descriptor(targetID, 1, new SortedRangeSet("1-3")));
+        task.writeDelta(task.calculateDelta(src, dest), mockWriter);
+
+        assertEquals(task.size(), 1, "Incorrect delta");
+
         RangeIterator i = task.m_calledWith.get(0).getRangeSet().iterator();
-        assert i.next() == 4 : "Illegal value in SortedRangeSet";
-        assert i.next() == 5 : "Illegal value in SortedRangeSet";
-        assert !i.hasNext() : "Illegal value in SortedRangeSet";
-        task.m_calledWith.clear();
+        assertEquals(i.next(), 4, "Illegal value in SortedRangeSet");
+        assertEquals(i.next(), 5, "Illegal value in SortedRangeSet");
+        assertFalse(i.hasNext(), "Illegal value in SortedRangeSet");
+
+        task.clear();
+
         // add a non-overlapping destination
-        dest.add(new Descriptor("gwid", 2, new SortedRangeSet("50-100")));
-        task.writeDelta(task.calculateDelta(src, dest), null);
-        assert task.m_calledWith.size() == 1 : "Delta should be 1 instead of: " + task.m_calledWith.size();
+        dest.add(new Descriptor(targetID, 2, new SortedRangeSet("50-100")));
+        task.writeDelta(task.calculateDelta(src, dest), mockWriter);
+
+        assertEquals(task.size(), 1, "Incorrect delta");
+
         i = task.m_calledWith.get(0).getRangeSet().iterator();
-        assert i.next() == 4 : "Illegal value in SortedRangeSet";
-        assert i.next() == 5 : "Illegal value in SortedRangeSet";
-        assert !i.hasNext() : "Illegal value in SortedRangeSet";
-        task.m_calledWith.clear();
+        assertEquals(i.next(), 4, "Illegal value in SortedRangeSet");
+        assertEquals(i.next(), 5, "Illegal value in SortedRangeSet");
+        assertFalse(i.hasNext(), "Illegal value in SortedRangeSet");
+
+        task.clear();
+
         // add non-overlapping source
-        src.add(new Descriptor("gwid", 2, new SortedRangeSet("1-49")));
-        task.writeDelta(task.calculateDelta(src, dest), null);
-        assert task.m_calledWith.size() == 2 : "Delta should be 2 instead of: " + task.m_calledWith.size();
-        task.m_calledWith.clear();
+        src.add(new Descriptor(targetID, 2, new SortedRangeSet("1-49")));
+        task.writeDelta(task.calculateDelta(src, dest), mockWriter);
+
+        assertEquals(task.size(), 2, "Incorrect delta");
+
+        task.clear();
+
         // add a source with gaps
-        src.add(new Descriptor("gwid", 3, new SortedRangeSet("1-10")));
-        dest.add(new Descriptor("gwid", 3, new SortedRangeSet("3,5-8")));
-        task.writeDelta(task.calculateDelta(src, dest), null);
-        assert task.m_calledWith.size() == 3 : "Delta should be 3 instead of: " + task.m_calledWith.size();
+        src.add(new Descriptor(targetID, 3, new SortedRangeSet("1-10")));
+        dest.add(new Descriptor(targetID, 3, new SortedRangeSet("3,5-8")));
+        task.writeDelta(task.calculateDelta(src, dest), mockWriter);
+
+        assertEquals(task.size(), 3, "Incorrect delta");
         for (Descriptor l : task.m_calledWith) {
             if (l.getStoreID() == 3) {
                 i = l.getRangeSet().iterator();
             }
         }
-        assert i.next() == 1 : "Illegal value in SortedRangeSet";
-        assert i.next() == 2 : "Illegal value in SortedRangeSet";
-        assert i.next() == 4 : "Illegal value in SortedRangeSet";
-        assert i.next() == 9 : "Illegal value in SortedRangeSet";
-        assert i.next() == 10 : "Illegal value in SortedRangeSet";
-        assert !i.hasNext() : "Illegal value in SortedRangeSet";
+        assertEquals(i.next(), 1, "Illegal value in SortedRangeSet");
+        assertEquals(i.next(), 2, "Illegal value in SortedRangeSet");
+        assertEquals(i.next(), 4, "Illegal value in SortedRangeSet");
+        assertEquals(i.next(), 9, "Illegal value in SortedRangeSet");
+        assertEquals(i.next(), 10, "Illegal value in SortedRangeSet");
+        assertFalse(i.hasNext(), "Illegal value in SortedRangeSet");
     }
 }



Mime
View raw message