activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cshan...@apache.org
Subject [1/3] activemq git commit: https://issues.apache.org/jira/browse/AMQ-6097
Date Tue, 22 Dec 2015 13:26:21 GMT
Repository: activemq
Updated Branches:
  refs/heads/activemq-5.12.x 819e2371d -> 7eb142573


https://issues.apache.org/jira/browse/AMQ-6097

Fixing JournalCorruptionEofIndexRecoveryTest class

Because of the size being stored in the message order index, the test
testRecoveryAftercorruptionCheckSumExistingIndex was no longer passing
as that test was corrupting the size value in the journal, but not the
size value in the index.  The test now corrupts both values so that the
expect exception occurs again.

(cherry picked from commit 507d40a79f15449ba6d79ef85d7fdf6bf50a3a65)


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/7eb14257
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/7eb14257
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/7eb14257

Branch: refs/heads/activemq-5.12.x
Commit: 7eb1425733324caeac7619d9510288c6c1527300
Parents: 0411916
Author: Christopher L. Shannon (cshannon) <christopher.l.shannon@gmail.com>
Authored: Mon Dec 21 16:45:02 2015 +0000
Committer: Christopher L. Shannon (cshannon) <christopher.l.shannon@gmail.com>
Committed: Tue Dec 22 13:26:14 2015 +0000

----------------------------------------------------------------------
 .../JournalCorruptionEofIndexRecoveryTest.java  | 38 +++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/7eb14257/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/JournalCorruptionEofIndexRecoveryTest.java
----------------------------------------------------------------------
diff --git a/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/JournalCorruptionEofIndexRecoveryTest.java
b/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/JournalCorruptionEofIndexRecoveryTest.java
index a39496d..459bcba 100644
--- a/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/JournalCorruptionEofIndexRecoveryTest.java
+++ b/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/JournalCorruptionEofIndexRecoveryTest.java
@@ -18,11 +18,12 @@ package org.apache.activemq.store.kahadb;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
-
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map.Entry;
 
 import javax.jms.Connection;
 import javax.jms.Destination;
@@ -34,8 +35,11 @@ import javax.jms.Session;
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.broker.BrokerService;
 import org.apache.activemq.command.ActiveMQQueue;
+import org.apache.activemq.store.kahadb.MessageDatabase.MessageKeys;
+import org.apache.activemq.store.kahadb.MessageDatabase.StoredDestination;
 import org.apache.activemq.store.kahadb.disk.journal.DataFile;
 import org.apache.activemq.store.kahadb.disk.journal.Journal;
+import org.apache.activemq.store.kahadb.disk.page.Transaction;
 import org.apache.activemq.util.ByteSequence;
 import org.apache.activemq.util.IOHelper;
 import org.apache.activemq.util.RecoverableRandomAccessFile;
@@ -222,6 +226,7 @@ public class JournalCorruptionEofIndexRecoveryTest {
         size -= 1;
         LOG.info("rewrite incorrect location size @:" + (pos + Journal.BATCH_CONTROL_RECORD_SIZE)
+ " as: " + size);
         randomAccessFile.writeInt(size);
+        corruptOrderIndex(id, size);
 
         randomAccessFile.getChannel().force(true);
     }
@@ -241,6 +246,37 @@ public class JournalCorruptionEofIndexRecoveryTest {
         randomAccessFile.getChannel().force(true);
     }
 
+    private void corruptOrderIndex(final int num, final int size) throws Exception {
+        //This is because of AMQ-6097, now that the MessageOrderIndex stores the size in
the Location,
+        //we need to corrupt that value as well
+        final KahaDBStore kahaDbStore = (KahaDBStore) ((KahaDBPersistenceAdapter) broker.getPersistenceAdapter()).getStore();
+        kahaDbStore.indexLock.writeLock().lock();
+        try {
+            kahaDbStore.pageFile.tx().execute(new Transaction.Closure<IOException>()
{
+                @Override
+                public void execute(Transaction tx) throws IOException {
+                    StoredDestination sd = kahaDbStore.getStoredDestination(kahaDbStore.convert(
+                            (ActiveMQQueue)destination), tx);
+                    int i = 1;
+                    for (Iterator<Entry<Long, MessageKeys>> iterator = sd.orderIndex.iterator(tx);
iterator.hasNext();) {
+                        Entry<Long, MessageKeys> entry = iterator.next();
+                        if (i == num) {
+                            //change the size value to the wrong size
+                            sd.orderIndex.get(tx, entry.getKey());
+                            MessageKeys messageKeys = entry.getValue();
+                            messageKeys.location.setSize(size);
+                            sd.orderIndex.put(tx, sd.orderIndex.lastGetPriority(), entry.getKey(),
messageKeys);
+                            break;
+                        }
+                        i++;
+                    }
+                }
+            });
+        } finally {
+            kahaDbStore.indexLock.writeLock().unlock();
+        }
+    }
+
     private ArrayList<Integer> findBatch(RecoverableRandomAccessFile randomAccessFile,
int where) throws IOException {
         final ArrayList<Integer> batchPositions = new ArrayList<Integer>();
         final ByteSequence header = new ByteSequence(Journal.BATCH_CONTROL_RECORD_HEADER);


Mime
View raw message