From do-not-reply at jboss.org Tue Jul 27 16:37:57 2010 Content-Type: multipart/mixed; boundary="===============3844308522698627316==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: hornetq-commits at lists.jboss.org Subject: [hornetq-commits] JBoss hornetq SVN: r9472 - trunk/tests/src/org/hornetq/tests/soak/journal. Date: Tue, 27 Jul 2010 16:37:57 -0400 Message-ID: <201007272037.o6RKbvwm027581@svn01.web.mwc.hst.phx2.redhat.com> --===============3844308522698627316== 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-27 16:37:56 -0400 (Tue, 27 Jul 2010) New Revision: 9472 Added: trunk/tests/src/org/hornetq/tests/soak/journal/JournalSoakTest.java Removed: trunk/tests/src/org/hornetq/tests/soak/journal/SoakJournal.java Log: Rename test Copied: trunk/tests/src/org/hornetq/tests/soak/journal/JournalSoakTest.java= (from rev 9471, 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/JournalSoakTest.java = (rev 0) +++ trunk/tests/src/org/hornetq/tests/soak/journal/JournalSoakTest.java 201= 0-07-27 20:37:56 UTC (rev 9472) @@ -0,0 +1,344 @@ +/* + * 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 JournalSoakTest 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, + JournalSoakTest.class= .getClassLoader()); + + private final ExecutorService threadPool =3D Executors.newFixedThreadPo= ol(20, tFactory); + + OrderedExecutorFactory executorFactory =3D new OrderedExecutorFactory(t= hreadPool); + + @Override + 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(); + + } + + @Override + 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(TimeUnit.HOURS.toMillis(24)); + + 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()); + + @Override + public void run() + { + try + { + + while (running) + { + int txSize =3D RandomUtil.randomMax(1000); + + long txID =3D JournalSoakTest.idGen.generateID(); + + final ArrayList ids =3D new ArrayList(); + + for (int i =3D 0; i < txSize; i++) + { + long id =3D JournalSoakTest.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(final int errorCode, final String er= rorMessage) + { + } + + 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(final LinkedBlockingDeque queue) + { + this.queue =3D queue; + } + + @Override + public void run() + { + try + { + int txSize =3D RandomUtil.randomMax(1000); + int txCount =3D 0; + long ids[] =3D new long[txSize]; + + long txID =3D JournalSoakTest.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 JournalSoakTest.idGen.generateID(); + ids =3D new long[txSize]; + } + } + } + catch (Exception e) + { + e.printStackTrace(); + System.exit(-1); + } + } + } + + class DeleteTask implements IOAsyncTask + { + final long ids[]; + + DeleteTask(final long ids[]) + { + this.ids =3D ids; + } + + public void done() + { + try + { + for (long id : ids) + { + journal.appendDeleteRecord(id, false); + } + } + catch (Exception e) + { + System.err.println("Can't delete id"); + e.printStackTrace(); + } + } + + public void onError(final int errorCode, final 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 + { + @Override + 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 JournalSoakTest.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 JournalSoakTest.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 JournalSoakTest.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 ------------------------------------------------- + +} Deleted: 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 2010-07= -27 19:14:32 UTC (rev 9471) +++ trunk/tests/src/org/hornetq/tests/soak/journal/SoakJournal.java 2010-07= -27 20:37:56 UTC (rev 9472) @@ -1,339 +0,0 @@ -/* - * 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(TimeUnit.HOURS.toMillis(24)); - - 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 ------------------------------------------------- - -} --===============3844308522698627316==--