From eb1a3eb77bf0ce823ba5f4891ef7a546edce5321 Mon Sep 17 00:00:00 2001 From: gtully Date: Wed, 10 May 2017 11:30:30 +0100 Subject: [PATCH] [AMQ-6670] - harden the test to avoid ci failure --- .../JournalCorruptionExceptionTest.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/JournalCorruptionExceptionTest.java b/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/JournalCorruptionExceptionTest.java index 3f554b5947..30f062eb10 100644 --- a/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/JournalCorruptionExceptionTest.java +++ b/activemq-kahadb-store/src/test/java/org/apache/activemq/store/kahadb/JournalCorruptionExceptionTest.java @@ -22,6 +22,8 @@ import org.apache.activemq.broker.region.policy.PolicyEntry; import org.apache.activemq.broker.region.policy.PolicyMap; import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.store.kahadb.disk.journal.DataFile; +import org.apache.activemq.store.kahadb.disk.journal.Journal; +import org.apache.activemq.util.ByteSequence; import org.apache.activemq.util.RecoverableRandomAccessFile; import org.junit.After; import org.junit.Test; @@ -67,10 +69,12 @@ public class JournalCorruptionExceptionTest { public static Iterable parameters() { // corruption can be valid record type values return Arrays.asList(new Object[][]{ + {Byte.valueOf("0"), 6}, + {Byte.valueOf("1"), 8}, + {Byte.valueOf("-1"), 6}, {Byte.valueOf("0"), 10}, {Byte.valueOf("1"), 10}, - {Byte.valueOf("1"), 9}, - {Byte.valueOf("2"), 20}, + {Byte.valueOf("2"), 10}, {Byte.valueOf("-1"), 10} }); } @@ -143,10 +147,18 @@ public class JournalCorruptionExceptionTest { DataFile dataFile = (DataFile) files.toArray()[id]; RecoverableRandomAccessFile randomAccessFile = dataFile.openRandomAccessFile(); - int offset = 2415; - if (fillLength < 10) { - offset += (fillLength * 2); + final ByteSequence header = new ByteSequence(Journal.BATCH_CONTROL_RECORD_HEADER); + byte data[] = new byte[1024 * 20]; + ByteSequence bs = new ByteSequence(data, 0, randomAccessFile.read(data, 0, data.length)); + + int offset = bs.indexOf(header, 0); + + offset += Journal.BATCH_CONTROL_RECORD_SIZE; + + if (fillLength >= 10) { + offset += 4; // location size + offset += 1; // location type } LOG.info("Whacking batch record in file:" + id + ", at offset: " + offset + " with fill:" + fill);