[jboss-cvs] JBoss Messaging SVN: r4700 - in trunk: tests/src/org/jboss/messaging/tests and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jul 21 17:25:52 EDT 2008


Author: clebert.suconic at jboss.com
Date: 2008-07-21 17:25:52 -0400 (Mon, 21 Jul 2008)
New Revision: 4700

Added:
   trunk/tests/src/org/jboss/messaging/tests/stress/
   trunk/tests/src/org/jboss/messaging/tests/stress/StressTestBase.java
   trunk/tests/src/org/jboss/messaging/tests/stress/journal/
   trunk/tests/src/org/jboss/messaging/tests/stress/journal/ValidateTransactionHealthTest.java
   trunk/tests/src/org/jboss/messaging/tests/stress/journal/remote/
   trunk/tests/src/org/jboss/messaging/tests/stress/journal/remote/RemoteJournalAppender.java
Modified:
   trunk/build-messaging.xml
   trunk/build.xml
Log:
Adding stress tests for journal

Modified: trunk/build-messaging.xml
===================================================================
--- trunk/build-messaging.xml	2008-07-21 15:41:43 UTC (rev 4699)
+++ trunk/build-messaging.xml	2008-07-21 21:25:52 UTC (rev 4700)
@@ -765,6 +765,7 @@
              timeout="${junit.timeout}">
 
          <jvmarg value="-Xmx1024M"/>
+         <jvmarg value="-Djava.library.path=native/bin"/>
          <!--<jvmarg line="-Xmx512M -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"/>-->
          <!--<jvmarg value="-ea"/>-->
          <classpath refid="unit.test.execution.classpath"/>

Modified: trunk/build.xml
===================================================================
--- trunk/build.xml	2008-07-21 15:41:43 UTC (rev 4699)
+++ trunk/build.xml	2008-07-21 21:25:52 UTC (rev 4700)
@@ -138,6 +138,11 @@
       <ant antfile="build-messaging.xml" target="compile-reports"/>
    </target>
    
+   <target name="stress-tests" depends="createthirdparty">
+      <ant antfile="build-messaging.xml" target="stress-tests"/>
+      <ant antfile="build-messaging.xml" target="compile-reports"/>
+   </target>
+   
 
    <target name="jms-tests" depends="createthirdparty">
       <ant antfile="build-messaging.xml" target="jms-tests"/>

Added: trunk/tests/src/org/jboss/messaging/tests/stress/StressTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/stress/StressTestBase.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/stress/StressTestBase.java	2008-07-21 21:25:52 UTC (rev 4700)
@@ -0,0 +1,214 @@
+/*
+ * 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;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.tests.util.UnitTestCase;
+
+public class StressTestBase extends UnitTestCase
+{
+   
+   // Constants -----------------------------------------------------
+   
+   // Attributes ----------------------------------------------------
+   
+   // Static --------------------------------------------------------
+   
+   private static Logger log = Logger.getLogger(StressTestBase.class);
+
+   // Constructors --------------------------------------------------
+   
+   // Public --------------------------------------------------------
+   
+   // Package protected ---------------------------------------------
+   
+   // Protected -----------------------------------------------------
+   
+   protected RemoteProcess startProcess (boolean startOutputThreads, String className, String ... arguments) throws Exception
+   {
+      StringBuffer buffer = new StringBuffer();
+      buffer.append("java -Xmx1024M ");
+      
+      String classPath = System.getProperty("java.class.path");
+
+      if (System.getProperty("os.name").toLowerCase().contains("windows"))
+      {
+         buffer.append("-cp \"").append(classPath).append("\" ");
+      }
+      else
+      {
+         buffer.append("-cp ").append(classPath).append(" ");
+      }
+      
+      buffer.append("-Djava.library.path=").append(System.getProperty("java.library.path", "./native/bin")).append(" ");
+      
+      buffer.append(className);
+      
+      for (String argument: arguments)
+      {
+         buffer.append(" ").append(argument);
+      }
+      
+
+      Process process = Runtime.getRuntime().exec(buffer.toString());
+      
+      final BufferedReader readerStdout = new BufferedReader(new InputStreamReader(process.getInputStream()));
+      final BufferedReader readerStderr = new BufferedReader(new InputStreamReader(process.getErrorStream()));
+
+      Thread threadStdout = null;
+      Thread threadStderr = null;
+      
+      
+      if (startOutputThreads)
+      {
+         threadStdout = new Thread(new Runnable()
+         {
+            public void run()
+            {
+               try
+               {
+                  String line;
+
+                  while((line = readerStdout.readLine()) != null)
+                  {
+                     System.out.println("Process stdout: " + line);
+                  }
+               }
+               catch(Exception e)
+               {
+                  log.error("exception", e);
+               }
+            }
+
+         }, "Process stdout reader");
+         
+         threadStdout.start();
+
+         threadStderr = new Thread(new Runnable()
+         {
+            public void run()
+            {
+               try
+               {
+                  String line;
+
+                  while((line = readerStderr.readLine()) != null)
+                  {
+                     System.out.println("Process stderr: " + line);
+                  }
+               }
+               catch(Exception e)
+               {
+                  log.error("exception", e);
+               }
+            }
+
+         }, "Process stderr reader");
+         
+         threadStderr.start();
+         
+      }
+      return new RemoteProcess(process, readerStdout, readerStderr, threadStdout, threadStderr );
+   }
+   
+   // Private -------------------------------------------------------
+   
+   // Inner classes -------------------------------------------------
+   
+   protected class RemoteProcess
+   {
+      private Process process;
+      private Reader stdoutReader;
+      private Reader errorReader;
+      private Thread stdoutThread;
+      private Thread errorThread;
+      
+      public RemoteProcess(Process process, Reader stdoutReader,
+            Reader errorReader, Thread stdoutThread, Thread errorThread)
+      {
+         super();
+         this.process = process;
+         this.stdoutReader = stdoutReader;
+         this.errorReader = errorReader;
+         this.stdoutThread = stdoutThread;
+         this.errorThread = errorThread;
+      }
+      
+      public Process getProcess()
+      {
+         return process;
+      }
+      
+      public void setProcess(Process process)
+      {
+         this.process = process;
+      }
+      
+      public Reader getStdoutReader()
+      {
+         return stdoutReader;
+      }
+      
+      public void setStdoutReader(Reader stdoutReader)
+      {
+         this.stdoutReader = stdoutReader;
+      }
+      
+      public Reader getErrorReader()
+      {
+         return errorReader;
+      }
+      
+      public void setErrorReader(Reader errorReader)
+      {
+         this.errorReader = errorReader;
+      }
+      
+      public Thread getStdoutThread()
+      {
+         return stdoutThread;
+      }
+      
+      public void setStdoutThread(Thread stdoutThread)
+      {
+         this.stdoutThread = stdoutThread;
+      }
+      
+      public Thread getErrorThread()
+      {
+         return errorThread;
+      }
+      
+      public void setErrorThread(Thread errorThread)
+      {
+         this.errorThread = errorThread;
+      }
+      
+   }
+   
+}

Added: trunk/tests/src/org/jboss/messaging/tests/stress/journal/ValidateTransactionHealthTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/stress/journal/ValidateTransactionHealthTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/stress/journal/ValidateTransactionHealthTest.java	2008-07-21 21:25:52 UTC (rev 4700)
@@ -0,0 +1,197 @@
+/*
+ * 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.nio.ByteBuffer;
+
+import org.jboss.messaging.core.asyncio.impl.AsynchronousFileImpl;
+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.impl.JournalImpl;
+import org.jboss.messaging.tests.stress.StressTestBase;
+import org.jboss.messaging.tests.stress.journal.remote.RemoteJournalAppender;
+
+public class ValidateTransactionHealthTest extends StressTestBase
+{
+   
+   // Constants -----------------------------------------------------
+   
+   // Attributes ----------------------------------------------------
+   
+   // Static --------------------------------------------------------
+   
+   // Constructors --------------------------------------------------
+   
+   // Public --------------------------------------------------------
+   
+   public void testAIO() throws Exception
+   {
+      internalTest("aio", "/tmp/aiojournal", 100000, 100, true, true);
+   }
+   
+   public void testAIONonTransactional() throws Exception
+   {
+      internalTest("aio", "/tmp/aiojournal", 100000, 0, true, true);
+   }
+   
+   public void testAIONonTransactionalNoExternalProcess() throws Exception
+   {
+      internalTest("aio", "/tmp/aiojournal", 100000, 0, true, false);
+   }
+   
+   public void testNIO() throws Exception
+   {
+      internalTest("nio", "/tmp/niojournal", 100000, 100, true, true);
+   }
+   
+   public void testNIONonTransactional() throws Exception
+   {
+      internalTest("nio", "/tmp/niojournal", 100000, 0, true, true);
+   }
+   
+   // Package protected ---------------------------------------------
+   
+   // Protected -----------------------------------------------------
+   
+   // Private -------------------------------------------------------
+   
+   private void internalTest(String type, String journalDir,
+         long numberOfRecords, int transactionSize, boolean append, boolean externalProcess) throws Exception
+   {
+      if (type.equals("aio") && !AsynchronousFileImpl.isLoaded())
+      {
+         // Using System.out as this output will go towards junit report
+         System.out.println("AIO not found, test being ignored on this platform");
+         return;
+      }
+      
+      // This property could be set to false for debug purposes.
+      if (append)
+      {
+         File file = new File(journalDir);
+         deleteDirectory(file);
+         file.mkdir();
+         
+         if (externalProcess)
+         {
+            RemoteProcess process = startProcess(true, RemoteJournalAppender.class
+                  .getCanonicalName(), type, journalDir, Long
+                  .toString(numberOfRecords), Integer.toString(transactionSize));
+            process.getProcess().waitFor();
+            assertEquals(RemoteJournalAppender.OK, process.getProcess().exitValue());
+         }
+         else
+         {
+            JournalImpl journal = RemoteJournalAppender.appendData(type, journalDir, numberOfRecords, transactionSize);
+            journal.stop();
+         }
+      }
+      
+      //reload(type, journalDir, numberOfRecords);
+   }
+   
+   private void reload(String type, String journalDir, long numberOfRecords)
+         throws Exception
+   {
+      JournalImpl journal = RemoteJournalAppender.createJournal(type,
+            journalDir);
+      
+      journal.start();
+      Loader loadTest = new Loader(numberOfRecords);
+      journal.load(loadTest);
+      assertEquals(numberOfRecords, loadTest.numberOfAdds);
+      assertEquals(0, loadTest.numberOfPreparedTransactions);
+      assertEquals(0, loadTest.numberOfUpdates);
+      assertEquals(0, loadTest.numberOfDeletes);
+      
+      if (loadTest.ex != null)
+      {
+         throw loadTest.ex;
+      }
+   }
+   
+   // Inner classes -------------------------------------------------
+   
+   class Loader implements LoadManager
+   {
+      int numberOfPreparedTransactions = 0;
+      int numberOfAdds = 0;
+      int numberOfDeletes = 0;
+      int numberOfUpdates = 0;
+      long expectedRecords = 0;
+      
+      Exception ex = null;
+      
+      long lastID = 0;
+      
+      public Loader(long expectedRecords)
+      {
+         this.expectedRecords = expectedRecords;
+      }
+      
+      public void addPreparedTransaction(
+            PreparedTransactionInfo preparedTransaction)
+      {
+         numberOfPreparedTransactions++;
+         
+      }
+      
+      public void addRecord(RecordInfo info)
+      {
+         if (info.id - lastID > 1)
+         {
+            System.out.println("id = " + info.id + " last id = " + lastID);
+         }
+         
+         ByteBuffer buffer = ByteBuffer.wrap(info.data);
+         long recordValue = buffer.getLong();
+         
+         if (recordValue != (expectedRecords - info.id))
+         {
+            ex = new Exception("Content not as expected (" + recordValue
+                  + " != " + info.id + ")");
+            
+         }
+         
+         lastID = info.id;
+         numberOfAdds++;
+         
+      }
+      
+      public void deleteRecord(long id)
+      {
+         numberOfDeletes++;
+         
+      }
+      
+      public void updateRecord(RecordInfo info)
+      {
+         numberOfUpdates++;
+         
+      }
+      
+   }
+   
+}

Added: trunk/tests/src/org/jboss/messaging/tests/stress/journal/remote/RemoteJournalAppender.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/stress/journal/remote/RemoteJournalAppender.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/stress/journal/remote/RemoteJournalAppender.java	2008-07-21 21:25:52 UTC (rev 4700)
@@ -0,0 +1,174 @@
+/*
+ * 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.remote;
+
+import java.nio.ByteBuffer;
+
+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.core.journal.impl.NIOSequentialFileFactory;
+
+public class RemoteJournalAppender
+{
+   
+   // Constants -----------------------------------------------------
+   
+   public static final int OK = 10;
+   // Attributes ----------------------------------------------------
+   
+   // Static --------------------------------------------------------
+   
+   public static void main(String args[]) throws Exception
+   {
+      
+      if (args.length != 4)
+      {
+         System.err
+               .println("Use: java -cp <classpath> "
+                     + RemoteJournalAppender.class.getCanonicalName()
+                     + " aio|nio <journalDirectory> <NumberOfElements> <TransactionSize>");
+         System.exit(-1);
+      }
+      String journalType = args[0];
+      String journalDir = args[1];
+      long numberOfElements = Long.parseLong(args[2]);
+      int transactionSize = Integer.parseInt(args[3]);
+      
+
+      try
+      {
+         JournalImpl journal = appendData(journalType, journalDir,
+               numberOfElements, transactionSize);
+         
+         journal.stop();
+         
+      }
+      catch (Exception e)
+      {
+         e.printStackTrace();
+         System.exit(-1);
+      }
+      
+      System.exit(OK);
+   }
+
+   public static JournalImpl appendData(String journalType, String journalDir,
+         long numberOfElements, int transactionSize) throws Exception
+   {
+      JournalImpl journal = createJournal(journalType, journalDir);
+      
+      journal.start();
+      journal.load(new LoadManager()
+      {
+         
+         public void addPreparedTransaction(
+               PreparedTransactionInfo preparedTransaction)
+         {
+         }
+         
+         public void addRecord(RecordInfo info)
+         {
+         }
+         
+         public void deleteRecord(long id)
+         {
+         }
+         
+         public void updateRecord(RecordInfo info)
+         {
+         }
+      });
+      
+      int transactionCounter = 0;
+      
+      long transactionId = 1;
+      
+      for (long i = 0; i < numberOfElements; i++)
+      {
+         
+         ByteBuffer buffer = ByteBuffer.allocate(512*3);
+         buffer.putLong(numberOfElements - i);
+         
+         if (transactionSize != 0)
+         {
+            journal.appendAddRecordTransactional(transactionId, i, (byte)99, buffer.array());
+  
+            if (++transactionCounter == transactionSize)
+            {
+               System.out.println("Commit transaction " + transactionId);
+               journal.appendCommitRecord(transactionId);
+               transactionCounter = 0;
+               transactionId ++;
+            }
+         }
+         else
+         {
+            journal.appendAddRecord(i, (byte)99, buffer.array());
+         }
+      }
+
+      if (transactionCounter != 0)
+      {
+         journal.appendCommitRecord(transactionId);
+      }
+      return journal;
+   }
+
+   public static JournalImpl createJournal(String journalType, String journalDir)
+   {
+      JournalImpl journal = new JournalImpl(10485760, 2, true,
+            false, getFactory(journalType, journalDir), "journaltst", "tst", 5000,
+            60000);
+      return journal;
+   }
+   
+   public static SequentialFileFactory getFactory(String factoryType,
+         String directory)
+   {
+      if (factoryType.equals("aio"))
+      {
+         return new AIOSequentialFileFactory(directory);
+      }
+      else
+      {
+         return new NIOSequentialFileFactory(directory);
+      }
+   }
+   // Constructors --------------------------------------------------
+   
+   // Public --------------------------------------------------------
+   
+   // Package protected ---------------------------------------------
+   
+   // Protected -----------------------------------------------------
+   
+   
+   // Private -------------------------------------------------------
+   
+   // Inner classes -------------------------------------------------
+   
+}




More information about the jboss-cvs-commits mailing list