[jboss-cvs] JBoss Messaging SVN: r7392 - in trunk: tests/src/org/jboss/messaging/tests/unit/core and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jun 18 16:04:31 EDT 2009


Author: clebert.suconic at jboss.com
Date: 2009-06-18 16:04:31 -0400 (Thu, 18 Jun 2009)
New Revision: 7392

Added:
   trunk/tests/src/org/jboss/messaging/tests/unit/core/duplicateDetection/
   trunk/tests/src/org/jboss/messaging/tests/unit/core/duplicateDetection/DuplicateDetectionUnitTest.java
Modified:
   trunk/src/main/org/jboss/messaging/core/postoffice/impl/DuplicateIDCacheImpl.java
Log:
JBMESSAGING-1660 - DuplicateIDCache fix

Modified: trunk/src/main/org/jboss/messaging/core/postoffice/impl/DuplicateIDCacheImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/impl/DuplicateIDCacheImpl.java	2009-06-18 15:17:30 UTC (rev 7391)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/impl/DuplicateIDCacheImpl.java	2009-06-18 20:04:31 UTC (rev 7392)
@@ -69,7 +69,6 @@
 
    private final boolean persist;
 
-   
    public DuplicateIDCacheImpl(final SimpleString address,
                                final int size,
                                final StorageManager storageManager,
@@ -97,9 +96,9 @@
          if (count < cacheSize)
          {
             ByteArrayHolder bah = new ByteArrayHolder(id.a);
-            
+
             Pair<ByteArrayHolder, Long> pair = new Pair<ByteArrayHolder, Long>(bah, id.b);
-            
+
             cache.add(bah);
 
             ids.add(pair);
@@ -123,7 +122,14 @@
          storageManager.commit(txID);
       }
 
-      pos = theIds.size();
+      pos = ids.size();
+      
+      if (pos++ >= cacheSize - 1)
+      {
+         pos = 0;
+      }
+
+      
    }
 
    public boolean contains(final byte[] duplID)
@@ -159,7 +165,7 @@
       }
    }
 
-   private void addToCacheInMemory(final byte[] duplID, final long recordID) throws Exception
+   private synchronized void addToCacheInMemory(final byte[] duplID, final long recordID) throws Exception
    {
       cache.add(new ByteArrayHolder(duplID));
 
@@ -188,7 +194,7 @@
          ids.add(id);
       }
 
-      if (pos++ == cacheSize - 1)
+      if (pos++ >= cacheSize - 1)
       {
          pos = 0;
       }
@@ -254,7 +260,7 @@
       }
 
    }
-   
+
    private static final class ByteArrayHolder
    {
       ByteArrayHolder(final byte[] bytes)

Added: trunk/tests/src/org/jboss/messaging/tests/unit/core/duplicateDetection/DuplicateDetectionUnitTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/duplicateDetection/DuplicateDetectionUnitTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/duplicateDetection/DuplicateDetectionUnitTest.java	2009-06-18 20:04:31 UTC (rev 7392)
@@ -0,0 +1,283 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.unit.core.duplicateDetection;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.concurrent.Executors;
+
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.paging.PageTransactionInfo;
+import org.jboss.messaging.core.paging.PagingManager;
+import org.jboss.messaging.core.paging.PagingStore;
+import org.jboss.messaging.core.persistence.QueueBindingInfo;
+import org.jboss.messaging.core.persistence.StorageManager;
+import org.jboss.messaging.core.persistence.impl.journal.JournalStorageManager;
+import org.jboss.messaging.core.postoffice.PostOffice;
+import org.jboss.messaging.core.postoffice.impl.DuplicateIDCacheImpl;
+import org.jboss.messaging.core.server.JournalType;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.core.server.ServerMessage;
+import org.jboss.messaging.core.transaction.impl.ResourceManagerImpl;
+import org.jboss.messaging.tests.util.RandomUtil;
+import org.jboss.messaging.tests.util.ServiceTestBase;
+import org.jboss.messaging.utils.Pair;
+import org.jboss.messaging.utils.SimpleString;
+
+/**
+ * A DuplicateDetectionUnitTest
+ *
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ *
+ *
+ */
+public class DuplicateDetectionUnitTest extends ServiceTestBase
+{
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+   }
+   
+   // Public --------------------------------------------------------
+
+   public void testReloadDuplication() throws Exception
+   {
+
+      clearData();
+      
+      SimpleString ADDRESS = new SimpleString("address");
+
+      Configuration configuration = createConfigForJournal();
+
+      configuration.start();
+
+      configuration.setJournalType(JournalType.ASYNCIO);
+
+      JournalStorageManager journal = new JournalStorageManager(configuration, Executors.newCachedThreadPool());
+
+      journal.start();
+      journal.loadBindingJournal(new ArrayList<QueueBindingInfo>());
+
+      HashMap<SimpleString, List<Pair<byte[], Long>>> mapDups = new HashMap<SimpleString, List<Pair<byte[], Long>>>();
+
+      journal.loadMessageJournal(new FakePagingManager(),
+                                 new ResourceManagerImpl(0, 0),
+                                 new HashMap<Long, Queue>(),
+                                 mapDups);
+      
+      
+      assertEquals(0, mapDups.size());
+
+      DuplicateIDCacheImpl cacheID = new DuplicateIDCacheImpl(ADDRESS, 10, journal, true);
+
+      for (int i = 0; i < 100; i++)
+      {
+         cacheID.addToCache(RandomUtil.randomBytes(), null);
+      }
+
+      journal.stop();
+
+      journal = new JournalStorageManager(configuration, Executors.newCachedThreadPool());
+      journal.start();
+      journal.loadBindingJournal(new ArrayList<QueueBindingInfo>());
+
+      journal.loadMessageJournal(new FakePagingManager(),
+                                 new ResourceManagerImpl(0, 0),
+                                 new HashMap<Long, Queue>(),
+                                 mapDups);
+      
+      
+      assertEquals(1, mapDups.size());
+      
+      
+      List<Pair<byte[], Long>> values = mapDups.get(ADDRESS); 
+      
+      assertEquals(10, values.size());
+      
+      
+      cacheID = new DuplicateIDCacheImpl(ADDRESS, 10, journal, true);
+      cacheID.load(values);
+      
+      
+      for (int i = 0; i < 100; i++)
+      {
+         cacheID.addToCache(RandomUtil.randomBytes(), null);
+      }
+
+      
+      journal.stop();
+      
+      mapDups.clear();
+
+      journal = new JournalStorageManager(configuration, Executors.newCachedThreadPool());
+      journal.start();
+      journal.loadBindingJournal(new ArrayList<QueueBindingInfo>());
+
+      journal.loadMessageJournal(new FakePagingManager(),
+                                 new ResourceManagerImpl(0, 0),
+                                 new HashMap<Long, Queue>(),
+                                 mapDups);
+      
+      
+      assertEquals(1, mapDups.size());
+      
+      
+      values = mapDups.get(ADDRESS); 
+      
+      assertEquals(10, values.size());
+
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+   class FakePagingManager implements PagingManager
+   {
+
+      public void activate()
+      {
+      }
+
+      public long addSize(final long size)
+      {
+         return 0;
+      }
+
+      public void addTransaction(final PageTransactionInfo pageTransaction)
+      {
+      }
+
+      public PagingStore createPageStore(final SimpleString destination) throws Exception
+      {
+         return null;
+      }
+
+      public long getGlobalPageSize()
+      {
+         return ConfigurationImpl.DEFAULT_GLOBAL_PAGE_SIZE;
+      }
+
+      public long getTotalMemory()
+      {
+         return 0;
+      }
+
+      public long getMaxMemory()
+      {
+         return 0;
+      }
+
+      public PagingStore getPageStore(final SimpleString address) throws Exception
+      {
+         return null;
+      }
+
+      public PageTransactionInfo getTransaction(final long transactionID)
+      {
+         return null;
+      }
+
+      public boolean isBackup()
+      {
+         return false;
+      }
+
+      public boolean isGlobalPageMode()
+      {
+         return false;
+      }
+
+      public boolean isPaging(final SimpleString destination) throws Exception
+      {
+         return false;
+      }
+
+      public boolean page(final ServerMessage message, final boolean duplicateDetection) throws Exception
+      {
+         return false;
+      }
+
+      public boolean page(final ServerMessage message, final long transactionId, final boolean duplicateDetection) throws Exception
+      {
+         return false;
+      }
+
+      public void reloadStores() throws Exception
+      {
+      }
+
+      public void removeTransaction(final long transactionID)
+      {
+
+      }
+
+      public void setGlobalPageMode(final boolean globalMode)
+      {
+      }
+
+      public void setPostOffice(final PostOffice postOffice)
+      {
+      }
+
+      public void startGlobalDepage()
+      {
+      }
+
+      public void sync(final Collection<SimpleString> destinationsToSync) throws Exception
+      {
+      }
+
+      public boolean isStarted()
+      {
+         return false;
+      }
+
+      public void start() throws Exception
+      {
+      }
+
+      public void stop() throws Exception
+      {
+      }
+
+   }
+
+}




More information about the jboss-cvs-commits mailing list