activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajdav...@apache.org
Subject svn commit: r659082 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/util/BitArrayBin.java test/java/org/apache/activemq/ActiveMQMessageAuditTest.java test/java/org/apache/activemq/util/BitArrayBinTest.java
Date Thu, 22 May 2008 11:38:34 GMT
Author: rajdavies
Date: Thu May 22 04:38:33 2008
New Revision: 659082

URL: http://svn.apache.org/viewvc?rev=659082&view=rev
Log:
Apply patch for https://issues.apache.org/activemq/browse/AMQ-1742

Added:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/BitArrayBinTest.java
  (with props)
Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/BitArrayBin.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/ActiveMQMessageAuditTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/BitArrayBin.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/BitArrayBin.java?rev=659082&r1=659081&r2=659082&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/BitArrayBin.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/BitArrayBin.java Thu
May 22 04:38:33 2008
@@ -28,7 +28,6 @@
     private LinkedList<BitArray> list;
     private int maxNumberOfArrays;
     private int firstIndex = -1;
-    private int firstBin = -1;
     private long lastInOrderBit=-1;
 
     /**
@@ -54,16 +53,13 @@
      * @return true if set
      */
     public boolean setBit(long index, boolean value) {
-        boolean answer = true;
+        boolean answer = false;
         BitArray ba = getBitArray(index);
         if (ba != null) {
             int offset = getOffset(index);
             if (offset >= 0) {
                 answer = ba.set(offset, value);
             }
-            if (value) {
-            }else {
-            }
         }
         return answer;
     }
@@ -117,14 +113,16 @@
         int bin = getBin(index);
         BitArray answer = null;
         if (bin >= 0) {
-            if (firstIndex < 0) {
-                firstIndex = 0;
-            }
-            if (bin >= list.size()) {
-                list.removeFirst();
-                firstIndex += BitArray.LONG_SIZE;
-                list.add(new BitArray());
-                bin = list.size() - 1;
+            if (bin >= maxNumberOfArrays) {
+                int overShoot = bin - maxNumberOfArrays + 1;
+                while (overShoot > 0) {
+                    list.removeFirst();
+                    firstIndex += BitArray.LONG_SIZE;
+                    list.add(new BitArray());
+                    overShoot--;
+                }
+                
+                bin = maxNumberOfArrays - 1;
             }
             answer = list.get(bin);
             if (answer == null) {
@@ -143,8 +141,8 @@
      */
     private int getBin(long index) {
         int answer = 0;
-        if (firstBin < 0) {
-            firstBin = 0;
+        if (firstIndex < 0) {
+            firstIndex = (int) (index - (index % BitArray.LONG_SIZE));
         } else if (firstIndex >= 0) {
             answer = (int)((index - firstIndex) / BitArray.LONG_SIZE);
         }

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/ActiveMQMessageAuditTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/ActiveMQMessageAuditTest.java?rev=659082&r1=659081&r2=659082&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/ActiveMQMessageAuditTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/ActiveMQMessageAuditTest.java
Thu May 22 04:38:33 2008
@@ -67,8 +67,9 @@
             list.add(id);
             assertFalse(audit.isDuplicate(id));
         }
-        for (String id : list) {
-            assertTrue(audit.isDuplicate(id));
+        List<String> windowList = list.subList(list.size() -1 -audit.getAuditDepth(),
list.size() -1);
+        for (String id : windowList) {
+            assertTrue("duplicate, id:" + id, audit.isDuplicate(id));
         }
     }
 
@@ -90,8 +91,9 @@
             list.add(msg);
             assertFalse(audit.isDuplicate(msg.getMessageId()));
         }
-        for (MessageReference msg : list) {
-            assertTrue(audit.isDuplicate(msg));
+        List<MessageReference> windowList = list.subList(list.size() -1 -audit.getAuditDepth(),
list.size() -1);
+        for (MessageReference msg : windowList) {
+            assertTrue("duplicate msg:" + msg, audit.isDuplicate(msg));
         }
     }
     

Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/BitArrayBinTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/BitArrayBinTest.java?rev=659082&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/BitArrayBinTest.java
(added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/BitArrayBinTest.java
Thu May 22 04:38:33 2008
@@ -0,0 +1,108 @@
+package org.apache.activemq.util;
+
+import junit.framework.TestCase;
+
+public class BitArrayBinTest extends TestCase {
+        
+    public void testSetAroundWindow() throws Exception {
+        doTestSetAroundWindow(500, 2000);
+        doTestSetAroundWindow(512, 2000);
+        doTestSetAroundWindow(128, 512);
+    }
+       
+    private void doTestSetAroundWindow(int window, int dataSize) throws Exception {
+
+        BitArrayBin toTest = new BitArrayBin(window);
+        
+        for (int i=0; i <= dataSize; i++) {
+            assertTrue("not already set", !toTest.setBit(i, Boolean.TRUE));
+        }
+
+        int windowOfValidData = roundWindow(dataSize, window);
+        int i=dataSize;
+        for (; i >= dataSize -windowOfValidData; i--) {
+            assertTrue("was already set, id=" + i, toTest.setBit(i, Boolean.TRUE));
+        }
+        
+        for (; i >= 0; i--) {
+            assertTrue("was not already set, id=" + i, !toTest.setBit(i, Boolean.TRUE));
+        }
+        
+        for (int j= dataSize +1; j<(2*dataSize); j++) {
+            assertTrue("not already set: id=" + j, !toTest.setBit(j, Boolean.TRUE));
+        }
+    }
+    
+    public void testSetUnsetAroundWindow() throws Exception {
+        doTestSetUnSetAroundWindow(500, 2000);
+        doTestSetUnSetAroundWindow(512, 2000);
+        doTestSetUnSetAroundWindow(128, 512);
+    }
+    
+    private void doTestSetUnSetAroundWindow(int dataSize, int window) throws Exception {
+
+        BitArrayBin toTest = new BitArrayBin(window);
+        
+        for (int i=0; i <=dataSize; i++) {
+            assertTrue("not already set", !toTest.setBit(i, Boolean.TRUE));
+        }
+                
+        int windowOfValidData = roundWindow(dataSize, window);
+        for (int i=dataSize; i >= 0 && i >=dataSize -windowOfValidData; i--)
{
+            assertTrue("was already set, id=" + i, toTest.setBit(i, Boolean.FALSE));
+        }
+
+        for (int i=0; i <=dataSize; i++) {
+            assertTrue("not already set, id:" + i, !toTest.setBit(i, Boolean.TRUE));
+        }
+
+        for (int j= 2*dataSize; j< 4*dataSize; j++) {
+            assertTrue("not already set: id=" + j, !toTest.setBit(j, Boolean.TRUE));
+        }
+    }
+    
+    public void testSetAroundLongSizeMultiplier() throws Exception {
+        int window = 512;
+        int dataSize = 1000;
+        for (int muliplier=1; muliplier <8; muliplier++) {
+            for (int value=0; value <dataSize; value++) {
+                BitArrayBin toTest = new BitArrayBin(window);
+                
+                int instance = value +muliplier*BitArray.LONG_SIZE;
+                assertTrue("not already set: id=" + instance, !toTest.setBit(instance, Boolean.TRUE));
+                assertTrue("not already set: id=" + value, !toTest.setBit(value, Boolean.TRUE));
+            }
+        }
+    }
+    
+    public void testLargeGapInData(int window) throws Exception {
+        doTestLargeGapInData(128);
+        doTestLargeGapInData(500);
+    }
+    
+    public void doTestLargeGapInData(int window) throws Exception {
+        BitArrayBin toTest = new BitArrayBin(window);
+        
+        int instance = BitArray.LONG_SIZE;
+        assertTrue("not already set: id=" + instance,  !toTest.setBit(instance, Boolean.TRUE));
+        
+        instance = 12 *BitArray.LONG_SIZE;
+        assertTrue("not already set: id=" + instance,  !toTest.setBit(instance, Boolean.TRUE));
+        
+        instance = 9 *BitArray.LONG_SIZE;
+        assertTrue("not already set: id=" + instance,  !toTest.setBit(instance, Boolean.TRUE));
+    }
+    
+    // window moves in increments of BitArray.LONG_SIZE.
+    // valid data window on low end can be larger than window
+    private int roundWindow(int dataSetEnd, int windowSize) {
+        
+        int validData = dataSetEnd - windowSize;
+        int validDataBin = validData / BitArray.LONG_SIZE;
+        validDataBin += (windowSize % BitArray.LONG_SIZE > 0? 1:0);
+        int startOfValid = validDataBin * BitArray.LONG_SIZE;
+        
+        return dataSetEnd - startOfValid;        
+    }
+
+}

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/util/BitArrayBinTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message