From do-not-reply at jboss.org Mon Jul 26 01:03:59 2010 Content-Type: multipart/mixed; boundary="===============3673349964919458390==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: hornetq-commits at lists.jboss.org Subject: [hornetq-commits] JBoss hornetq SVN: r9464 - in trunk/tests/src/org/hornetq/tests: soak/journal and 1 other directories. Date: Mon, 26 Jul 2010 01:03:59 -0400 Message-ID: <201007260503.o6Q53xam012612@svn01.web.mwc.hst.phx2.redhat.com> --===============3673349964919458390== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: clebert.suconic(a)jboss.com Date: 2010-07-26 01:03:59 -0400 (Mon, 26 Jul 2010) New Revision: 9464 Added: trunk/tests/src/org/hornetq/tests/soak/journal/ trunk/tests/src/org/hornetq/tests/soak/journal/SoakJournal.java Modified: trunk/tests/src/org/hornetq/tests/util/RandomUtil.java Log: Adding a soak test for the journal Added: trunk/tests/src/org/hornetq/tests/soak/journal/SoakJournal.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/tests/src/org/hornetq/tests/soak/journal/SoakJournal.java = (rev 0) +++ trunk/tests/src/org/hornetq/tests/soak/journal/SoakJournal.java 2010-07= -26 05:03:59 UTC (rev 9464) @@ -0,0 +1,339 @@ +/* + * Copyright 2010 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package org.hornetq.tests.soak.journal; + +import java.io.File; +import java.util.ArrayList; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; + +import org.hornetq.core.config.impl.FileConfiguration; +import org.hornetq.core.journal.IOAsyncTask; +import org.hornetq.core.journal.impl.AIOSequentialFileFactory; +import org.hornetq.core.journal.impl.JournalImpl; +import org.hornetq.core.persistence.impl.journal.OperationContextImpl; +import org.hornetq.tests.util.RandomUtil; +import org.hornetq.tests.util.ServiceTestBase; +import org.hornetq.utils.HornetQThreadFactory; +import org.hornetq.utils.OrderedExecutorFactory; +import org.hornetq.utils.SimpleIDGenerator; +import org.hornetq.utils.concurrent.LinkedBlockingDeque; + +/** + * A SoakJournal + * + * @author Clebert Suconic<= /a> + * + * + */ +public class SoakJournal extends ServiceTestBase +{ + + public static SimpleIDGenerator idGen =3D new SimpleIDGenerator(1); + + private volatile boolean running; + + private JournalImpl journal; + + ThreadFactory tFactory =3D new HornetQThreadFactory("SoakTest" + System= .identityHashCode(this), + false, + SoakJournal.class.get= ClassLoader()); + + private ExecutorService threadPool =3D Executors.newFixedThreadPool(20,= tFactory); + + OrderedExecutorFactory executorFactory =3D new OrderedExecutorFactory(t= hreadPool); + + public void setUp() throws Exception + { + super.setUp(); + + File dir =3D new File(getTemporaryDir()); + dir.mkdirs(); + + FileConfiguration fileConf =3D new FileConfiguration(); + + fileConf.setJournalDirectory(getTemporaryDir()); + + fileConf.setCreateJournalDir(true); + + fileConf.setCreateBindingsDir(true); + + fileConf.start(); + + fileConf.setJournalMinFiles(10); + + journal =3D new JournalImpl(fileConf.getJournalFileSize(), + fileConf.getJournalMinFiles(), + fileConf.getJournalCompactMinFiles(), + fileConf.getJournalCompactPercentage(), + new AIOSequentialFileFactory(fileConf.getJ= ournalDirectory()), + "hornetq-data", + "hq", + fileConf.getJournalMaxIO_NIO()); + + journal.start(); + journal.loadInternalOnly(); + + } + + public void tearDown() throws Exception + { + journal.stop(); + } + + public void testAppend() throws Exception + { + running =3D true; + SlowAppenderNoTX t1 =3D new SlowAppenderNoTX(); + + int NTHREADS =3D 5; + + FastAppenderTx appenders[] =3D new FastAppenderTx[NTHREADS]; + FastUpdateTx updaters[] =3D new FastUpdateTx[NTHREADS]; + + for (int i =3D 0; i < NTHREADS; i++) + { + appenders[i] =3D new FastAppenderTx(); + updaters[i] =3D new FastUpdateTx(appenders[i].queue); + } + + t1.start(); + + for (int i =3D 0; i < NTHREADS; i++) + { + appenders[i].start(); + updaters[i].start(); + } + + Thread.sleep(3600000000l); + + running =3D false; + + for (Thread t : appenders) + { + t.join(); + } + + for (Thread t : updaters) + { + t.join(); + } + + t1.join(); + } + + private byte[] generateRecord() + { + int size =3D RandomUtil.randomPositiveInt() % 10000; + if (size =3D=3D 0) + { + size =3D 10000; + } + return RandomUtil.randomBytes(size); + } + + class FastAppenderTx extends Thread + { + LinkedBlockingDeque queue =3D new LinkedBlockingDeque(); + + OperationContextImpl ctx =3D new OperationContextImpl(executorFactor= y.getExecutor()); + + public void run() + { + try + { + + while (running) + { + int txSize =3D RandomUtil.randomMax(1000); + + long txID =3D idGen.generateID(); + + final ArrayList ids =3D new ArrayList(); + + for (int i =3D 0; i < txSize; i++) + { + long id =3D idGen.generateID(); + ids.add(id); + journal.appendAddRecordTransactional(txID, id, (byte)0, = generateRecord()); + Thread.sleep(1); + } + journal.appendCommitRecord(txID, true, ctx); + ctx.executeOnCompletion(new IOAsyncTask() + { + + public void onError(int errorCode, String errorMessage) + { + } + + public void done() + { + for (Long id : ids) + { + queue.add(id); + } + } + }); + } + } + catch (Exception e) + { + e.printStackTrace(); + System.exit(-1); + } + } + } + + class FastUpdateTx extends Thread + { + final LinkedBlockingDeque queue; + + OperationContextImpl ctx =3D new OperationContextImpl(executorFactor= y.getExecutor()); + + public FastUpdateTx(LinkedBlockingDeque queue) + { + this.queue =3D queue; + } + + public void run() + { + try + { + int txSize =3D RandomUtil.randomMax(1000); + int txCount =3D 0; + long ids[] =3D new long[txSize]; + + long txID =3D idGen.generateID(); + + while (running) + { + + long id =3D queue.poll(60, TimeUnit.MINUTES); + ids[txCount] =3D id; + journal.appendUpdateRecordTransactional(txID, id, (byte)0, = generateRecord()); + Thread.sleep(1); + if (++txCount =3D=3D txSize) + { + journal.appendCommitRecord(txID, true, ctx); + ctx.executeOnCompletion(new DeleteTask(ids)); + txCount =3D 0; + txSize =3D RandomUtil.randomMax(1000); + txID =3D idGen.generateID(); + ids =3D new long[txSize]; + } + } + } + catch (Exception e) + { + e.printStackTrace(); + System.exit(-1); + } + } + } + + class DeleteTask implements IOAsyncTask + { + final long ids[]; + + DeleteTask(long ids[]) + { + this.ids =3D ids; + } + + public void done() + { + try + { + for (int i =3D 0; i < ids.length; i++) + { + journal.appendDeleteRecord(ids[i], false); + } + } + catch (Exception e) + { + System.err.println("Can't delete id"); + e.printStackTrace(); + } + } + + public void onError(int errorCode, String errorMessage) + { + } + + } + + /** Adds stuff to the journal, but it will take a long time to remove t= hem. + * This will cause cleanup and compacting to happen more often + */ + class SlowAppenderNoTX extends Thread + { + public void run() + { + try + { + while (running) + { + long ids[] =3D new long[1000]; + // Append + for (int i =3D 0; running & i < 1000; i++) + { + ids[i] =3D idGen.generateID(); + journal.appendAddRecord(ids[i], (byte)1, generateRecord(= ), true); + Thread.sleep(300); + } + // Update + for (int i =3D 0; running & i < 1000; i++) + { + ids[i] =3D idGen.generateID(); + journal.appendUpdateRecord(ids[i], (byte)1, generateReco= rd(), true); + Thread.sleep(300); + } + // Delete + for (int i =3D 0; running & i < 1000; i++) + { + ids[i] =3D idGen.generateID(); + journal.appendUpdateRecord(ids[i], (byte)1, generateReco= rd(), true); + Thread.sleep(300); + } + } + } + catch (Exception e) + { + e.printStackTrace(); + System.exit(-1); + } + } + } + + // Constants ----------------------------------------------------- + + // Attributes ---------------------------------------------------- + + // Static -------------------------------------------------------- + + // Constructors -------------------------------------------------- + + // Public -------------------------------------------------------- + + // Package protected --------------------------------------------- + + // Protected ----------------------------------------------------- + + // Private ------------------------------------------------------- + + // Inner classes ------------------------------------------------- + +} Modified: trunk/tests/src/org/hornetq/tests/util/RandomUtil.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/tests/src/org/hornetq/tests/util/RandomUtil.java 2010-07-23 08:13= :58 UTC (rev 9463) +++ trunk/tests/src/org/hornetq/tests/util/RandomUtil.java 2010-07-26 05:03= :59 UTC (rev 9464) @@ -71,6 +71,18 @@ { return Math.abs(RandomUtil.randomInt()); } + = + public static int randomMax(int max) + { + int value =3D randomPositiveInt() % max; + = + if (value =3D=3D 0) + { + value =3D max; + } + = + return value; + } = public static int randomPort() { --===============3673349964919458390==--