[jboss-cvs] JBoss Messaging SVN: r4804 - in trunk: tests/src/org/jboss/messaging/tests/stress/journal and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Aug 14 17:55:50 EDT 2008
Author: clebert.suconic at jboss.com
Date: 2008-08-14 17:55:49 -0400 (Thu, 14 Aug 2008)
New Revision: 4804
Added:
trunk/tests/src/org/jboss/messaging/tests/stress/journal/AddAndRemoveStressTest.java
Modified:
trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/AlignedJournalImplTest.java
Log:
Fixing a bug with reloads & restarts on the journal
Modified: trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java 2008-08-14 13:30:46 UTC (rev 4803)
+++ trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java 2008-08-14 21:55:49 UTC (rev 4804)
@@ -1193,7 +1193,7 @@
currentFile.getFile().position(currentFile.getFile().calculateBlockStart(lastDataPos));
- currentFile.setOffset(lastDataPos);
+ currentFile.setOffset(currentFile.getFile().position());
}
else
{
@@ -1772,6 +1772,7 @@
{
file.getFile().open();
file.getFile().position(file.getFile().calculateBlockStart(SIZE_HEADER));
+ file.setOffset(file.getFile().calculateBlockStart(SIZE_HEADER));
}
private int generateOrderingID()
Added: trunk/tests/src/org/jboss/messaging/tests/stress/journal/AddAndRemoveStressTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/stress/journal/AddAndRemoveStressTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/stress/journal/AddAndRemoveStressTest.java 2008-08-14 21:55:49 UTC (rev 4804)
@@ -0,0 +1,161 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, 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.stress.journal;
+
+
+import java.io.File;
+import java.util.ArrayList;
+
+import org.jboss.messaging.core.journal.LoadManager;
+import org.jboss.messaging.core.journal.PreparedTransactionInfo;
+import org.jboss.messaging.core.journal.RecordInfo;
+import org.jboss.messaging.core.journal.SequentialFileFactory;
+import org.jboss.messaging.core.journal.impl.AIOSequentialFileFactory;
+import org.jboss.messaging.core.journal.impl.JournalImpl;
+import org.jboss.messaging.tests.unit.core.journal.impl.fakes.SimpleEncoding;
+import org.jboss.messaging.tests.util.UnitTestCase;
+
+/**
+ *
+ * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
+ *
+ */
+public class AddAndRemoveStressTest extends UnitTestCase
+{
+
+ protected String journalDir = System.getProperty("java.io.tmpdir", "/tmp") + "/journal-test";
+
+ // Constants -----------------------------------------------------
+
+ private static final LoadManager dummyLoader = new LoadManager(){
+
+ public void addPreparedTransaction(
+ PreparedTransactionInfo preparedTransaction)
+ {
+ }
+
+ public void addRecord(RecordInfo info)
+ {
+ }
+
+ public void deleteRecord(long id)
+ {
+ }
+
+ public void updateRecord(RecordInfo info)
+ {
+ }};
+
+
+ private static final long NUMBER_OF_MESSAGES = 210000l;
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testInsertAndLoad() throws Exception
+ {
+
+ File file = new File(journalDir);
+ deleteDirectory(file);
+ file.mkdirs();
+
+ SequentialFileFactory factory = new AIOSequentialFileFactory(journalDir);
+ JournalImpl impl = new JournalImpl(10*1024*1024, 60, true, false, factory, "jbm", "jbm", 1000);
+
+ System.out.println("Starting journal");
+ impl.start();
+
+ impl.load(dummyLoader);
+
+ for (long i = 1; i <= NUMBER_OF_MESSAGES; i++)
+ {
+ if (i % 10000 == 0)
+ {
+ System.out.println("Append " + i);
+ }
+ impl.appendAddRecord(i, (byte)0, new SimpleEncoding(1024, (byte)'f'));
+ }
+
+ impl.stop();
+
+
+ factory = new AIOSequentialFileFactory(journalDir);
+ impl = new JournalImpl(10*1024*1024, 60, true, false, factory, "jbm", "jbm", 1000);
+
+ impl.start();
+
+ impl.load(dummyLoader);
+
+ for (long i = 1; i <= NUMBER_OF_MESSAGES; i++)
+ {
+ if (i % 10000 == 0)
+ {
+ System.out.println("Delete " + i);
+ }
+
+ impl.appendDeleteRecord(i);
+ }
+
+ impl.stop();
+
+ factory = new AIOSequentialFileFactory(journalDir);
+ impl = new JournalImpl(10*1024*1024, 60, true, false, factory, "jbm", "jbm", 1000);
+
+ impl.start();
+
+
+
+ ArrayList<RecordInfo> info = new ArrayList<RecordInfo>();
+ ArrayList<PreparedTransactionInfo> trans = new ArrayList<PreparedTransactionInfo>();
+
+ impl.load(info, trans);
+
+
+ System.out.println("Info# - " + info.size());
+
+ if (info.size() > 0)
+ {
+ System.out.println("Info ID: " + info.get(0).id);
+ }
+
+ assertEquals(0, info.size());
+ assertEquals(0, trans.size());
+
+
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/AlignedJournalImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/AlignedJournalImplTest.java 2008-08-14 13:30:46 UTC (rev 4803)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/AlignedJournalImplTest.java 2008-08-14 21:55:49 UTC (rev 4804)
@@ -23,6 +23,7 @@
package org.jboss.messaging.tests.unit.core.journal.impl;
+import java.io.File;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.concurrent.BlockingQueue;
@@ -32,10 +33,12 @@
import java.util.concurrent.atomic.AtomicInteger;
import org.jboss.messaging.core.journal.EncodingSupport;
+import org.jboss.messaging.core.journal.LoadManager;
import org.jboss.messaging.core.journal.PreparedTransactionInfo;
import org.jboss.messaging.core.journal.RecordInfo;
import org.jboss.messaging.core.journal.SequentialFile;
import org.jboss.messaging.core.journal.SequentialFileFactory;
+import org.jboss.messaging.core.journal.impl.AIOSequentialFileFactory;
import org.jboss.messaging.core.journal.impl.JournalImpl;
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory;
@@ -51,7 +54,28 @@
{
// Constants -----------------------------------------------------
+
+ private static final LoadManager dummyLoader = new LoadManager(){
+
+ public void addPreparedTransaction(
+ PreparedTransactionInfo preparedTransaction)
+ {
+ }
+
+ public void addRecord(RecordInfo info)
+ {
+ }
+
+ public void deleteRecord(long id)
+ {
+ }
+
+ public void updateRecord(RecordInfo info)
+ {
+ }};
+
+
// Attributes ----------------------------------------------------
private SequentialFileFactory factory;
@@ -1137,6 +1161,51 @@
}
+ public void testAlignmentOverReload() throws Exception
+ {
+
+ SequentialFileFactory factory = new FakeSequentialFileFactory(512, false);
+ JournalImpl impl = new JournalImpl(512 + 512 * 3, 20, true, false, factory, "jbm", "jbm", 1000);
+
+ impl.start();
+
+ impl.load(dummyLoader);
+
+ impl.appendAddRecord(1l, (byte)0, new SimpleEncoding(100, (byte)'a'));
+ impl.appendAddRecord(2l, (byte)0, new SimpleEncoding(100, (byte)'b'));
+ impl.appendAddRecord(3l, (byte)0, new SimpleEncoding(100, (byte)'b'));
+ impl.appendAddRecord(4l, (byte)0, new SimpleEncoding(100, (byte)'b'));
+
+ impl.stop();
+
+ impl = new JournalImpl(512 + 1024 + 512, 20, true, false, factory, "jbm", "jbm", 1000);
+ impl.start();
+ impl.load(dummyLoader);
+
+
+ // It looks silly, but this forceMoveNextFile is in place to replicate one specific bug caught during development
+ impl.forceMoveNextFile();
+
+ impl.appendDeleteRecord(1l);
+ impl.appendDeleteRecord(2l);
+ impl.appendDeleteRecord(3l);
+ impl.appendDeleteRecord(4l);
+
+ impl.stop();
+
+
+ impl = new JournalImpl(512 + 1024 + 512, 20, true, false, factory, "jbm", "jbm", 1000);
+ impl.start();
+
+ ArrayList<RecordInfo> info = new ArrayList<RecordInfo>();
+ ArrayList<PreparedTransactionInfo> trans = new ArrayList<PreparedTransactionInfo>();
+
+ impl.load(info, trans);
+
+ assertEquals(0, info.size());
+ assertEquals(0, trans.size());
+
+ }
// Package protected ---------------------------------------------
More information about the jboss-cvs-commits
mailing list