[jboss-cvs] JBoss Messaging SVN: r3782 - projects/jaio/trunk/jaio/java/tests/org/jboss/jaio/libaioimpl/test.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Feb 24 22:43:39 EST 2008


Author: clebert.suconic at jboss.com
Date: 2008-02-24 22:43:39 -0500 (Sun, 24 Feb 2008)
New Revision: 3782

Modified:
   projects/jaio/trunk/jaio/java/tests/org/jboss/jaio/libaioimpl/test/MultiThreadTests.java
Log:
Changing test to use an executor

Modified: projects/jaio/trunk/jaio/java/tests/org/jboss/jaio/libaioimpl/test/MultiThreadTests.java
===================================================================
--- projects/jaio/trunk/jaio/java/tests/org/jboss/jaio/libaioimpl/test/MultiThreadTests.java	2008-02-25 03:30:05 UTC (rev 3781)
+++ projects/jaio/trunk/jaio/java/tests/org/jboss/jaio/libaioimpl/test/MultiThreadTests.java	2008-02-25 03:43:39 UTC (rev 3782)
@@ -2,17 +2,15 @@
 
 import java.io.File;
 import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetEncoder;
 import java.util.LinkedList;
 import java.util.ArrayList;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.jboss.jaio.api.AIOCallback;
 import org.jboss.jaio.libaioimpl.JLibAIO;
 
-import EDU.oswego.cs.dl.util.concurrent.SynchronizedInt;
 
 
 import junit.framework.TestCase;
@@ -20,22 +18,61 @@
 public class MultiThreadTests extends TestCase
 {
 
-    static SynchronizedInt position = new SynchronizedInt(0);
+    static AtomicInteger position = new AtomicInteger(0);
     
     String FILE_NAME="/tmp/libaio.log";
     
     static final int SIZE = 1024;
-    static final int NUMBER_OF_THREADS = 20;
-    static final int NUMBER_OF_LINES = 5000;
+    static final int NUMBER_OF_THREADS = 40;
+    static final int NUMBER_OF_LINES = 10000;
     
+//    Executor exec
     
-    private static void addData(JLibAIO aio, ByteBuffer buffer, AIOCallback callback)
+    static ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
+
+    
+    static class ExecClass implements Runnable
     {
-        aio.write(getNewPosition()*SIZE, SIZE, buffer, callback);
+        
+        JLibAIO aio;
+        ByteBuffer buffer;
+        AIOCallback callback;
+        
+        
+        public ExecClass(JLibAIO aio, ByteBuffer buffer, AIOCallback callback)
+        {
+            this.aio = aio;
+            this.buffer = buffer;
+            this.callback = callback;
+        }
+
+        public void run()
+        {
+            try
+            {
+                aio.write(getNewPosition()*SIZE, SIZE, buffer, callback);
+                
+            }
+            catch (Exception e)
+            {
+                callback.onError(-1, e.toString());
+                e.printStackTrace();
+            }
+        }
+        
     }
+
     
     
+    private synchronized static void addData(JLibAIO aio, ByteBuffer buffer, AIOCallback callback)
+    {
+        //aio.write(getNewPosition()*SIZE, SIZE, buffer, callback);
+        executor.execute(new ExecClass(aio, buffer, callback));
+    }
     
+    
+    
+    
     protected void setUp() throws Exception
     {
         super.setUp();
@@ -58,7 +95,7 @@
     private void executeTest(boolean sync) throws Throwable
     {
         JLibAIO jlibAIO = new JLibAIO();
-        jlibAIO.open(FILE_NAME, 50000);
+        jlibAIO.open(FILE_NAME, 21000);
         System.out.println("Preallocating file");
         jlibAIO.preAllocate(1, NUMBER_OF_THREADS * SIZE * NUMBER_OF_LINES);
         System.out.println("Done Preallocating file");
@@ -105,7 +142,7 @@
     
     private static int getNewPosition()
     {
-        return position.add(1);
+        return position.addAndGet(1);
     }
     
     static class ThreadProducer extends Thread




More information about the jboss-cvs-commits mailing list