Examples of AsynchronousFileImpl


Examples of org.hornetq.core.asyncio.impl.AsynchronousFileImpl

      Assert.assertEquals(0, errors.get());
   }

   public void testSize() throws Exception
   {
      final AsynchronousFileImpl controller = new AsynchronousFileImpl(executor, pollerExecutor);

      final int NUMBER_LINES = 10;
      final int SIZE = 1024;

      controller.open(FILE_NAME, 1);

      controller.fill(0, 1, NUMBER_LINES * SIZE, (byte)'j');

      Assert.assertEquals(NUMBER_LINES * SIZE, controller.size());

      controller.close();

   }
View Full Code Here

Examples of org.hornetq.core.asyncio.impl.AsynchronousFileImpl

   }

   private void executeTest(final boolean sync) throws Throwable
   {
      MultiThreadAsynchronousFileTest.debug(sync ? "Sync test:" : "Async test");
      AsynchronousFileImpl jlibAIO = new AsynchronousFileImpl(executor, pollerExecutor);
      jlibAIO.open(FILE_NAME, 21000);
      try
      {
         MultiThreadAsynchronousFileTest.debug("Preallocating file");

         jlibAIO.fill(0l,
                      MultiThreadAsynchronousFileTest.NUMBER_OF_THREADS,
                      MultiThreadAsynchronousFileTest.SIZE * MultiThreadAsynchronousFileTest.NUMBER_OF_LINES,
                      (byte)0);
         MultiThreadAsynchronousFileTest.debug("Done Preallocating file");

         CountDownLatch latchStart = new CountDownLatch(MultiThreadAsynchronousFileTest.NUMBER_OF_THREADS + 1);

         ArrayList<ThreadProducer> list = new ArrayList<ThreadProducer>(MultiThreadAsynchronousFileTest.NUMBER_OF_THREADS);
         for (int i = 0; i < MultiThreadAsynchronousFileTest.NUMBER_OF_THREADS; i++)
         {
            ThreadProducer producer = new ThreadProducer("Thread " + i, latchStart, jlibAIO, sync);
            list.add(producer);
            producer.start();
         }

         latchStart.countDown();
         latchStart.await();

         long startTime = System.currentTimeMillis();

         for (ThreadProducer producer : list)
         {
            producer.join();
            if (producer.failed != null)
            {
               throw producer.failed;
            }
         }
         long endTime = System.currentTimeMillis();

         MultiThreadAsynchronousFileTest.debug((sync ? "Sync result:" : "Async result:") + " Records/Second = " +
                                               MultiThreadAsynchronousFileTest.NUMBER_OF_THREADS *
                                               MultiThreadAsynchronousFileTest.NUMBER_OF_LINES *
                                               1000 /
                                               (endTime - startTime) +
                                               " total time = " +
                                               (endTime - startTime) +
                                               " total number of records = " +
                                               MultiThreadAsynchronousFileTest.NUMBER_OF_THREADS *
                                               MultiThreadAsynchronousFileTest.NUMBER_OF_LINES);
      }
      finally
      {
         jlibAIO.close();
      }

   }
View Full Code Here

Examples of org.hornetq.core.asyncio.impl.AsynchronousFileImpl

    * Opening and closing a file immediately can lead to races on the native layer,
    * creating crash conditions.
    * */
   public void testOpenClose() throws Exception
   {
      final AsynchronousFileImpl controller = new AsynchronousFileImpl(executor, pollerExecutor);
      for (int i = 0; i < 1000; i++)
      {
         controller.open(FILE_NAME, 10000);
         controller.close();

      }
   }
View Full Code Here

Examples of org.hornetq.core.asyncio.impl.AsynchronousFileImpl

      }
   }

   public void testReleaseBuffers() throws Exception
   {
      AsynchronousFileImpl controller = new AsynchronousFileImpl(executor, pollerExecutor);
      WeakReference<ByteBuffer> bufferCheck = null;
      try
      {
         controller.open(FILE_NAME, 10000);
         bufferCheck = new WeakReference<ByteBuffer>(controller.getHandler());
         controller.fill(0, 10, 1024, (byte)0);
  
         ByteBuffer write = AsynchronousFileImpl.newBuffer(1024);
  
         for (int i = 0; i < 1024; i++)
         {
            write.put(UnitTestCase.getSamplebyte(i));
         }
  
         final CountDownLatch latch = new CountDownLatch(1);
  
         controller.write(0, 1024, write, new AIOCallback()
         {
  
            public void onError(final int errorCode, final String errorMessage)
            {
            }
  
            public void done()
            {
               latch.countDown();
            }
         });
  
         Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
  
         WeakReference<ByteBuffer> bufferCheck2 = new WeakReference<ByteBuffer>(write);
  
         AsynchronousFileImpl.destroyBuffer(write);
  
         write = null;
  
         UnitTestCase.forceGC(bufferCheck2, 5000);
  
         Assert.assertNull(bufferCheck2.get());
      }
      finally
      {
         controller.close();
      }

      controller = null;

      UnitTestCase.forceGC(bufferCheck, 5000);
View Full Code Here

Examples of org.hornetq.core.asyncio.impl.AsynchronousFileImpl

      Assert.assertNull(bufferCheck.get());
   }

   public void testFileNonExistent() throws Exception
   {
      final AsynchronousFileImpl controller = new AsynchronousFileImpl(executor, pollerExecutor);
      for (int i = 0; i < 1000; i++)
      {
         try
         {
            controller.open("/non-existent/IDontExist.error", 10000);
            Assert.fail("Exception expected! The test could create a file called /non-existent/IDontExist.error when it was supposed to fail.");
         }
         catch (Exception ignored)
         {
         }
         try
         {
            controller.close();
            Assert.fail("Supposed to throw exception as the file wasn't opened");
         }
         catch (Exception ignored)
         {
         }
View Full Code Here

Examples of org.hornetq.core.asyncio.impl.AsynchronousFileImpl

    * simultaneous files without loose any callbacks. This test made the native
    * layer to crash at some point during development
    */
   public void testTwoFiles() throws Exception
   {
      final AsynchronousFileImpl controller = new AsynchronousFileImpl(executor, pollerExecutor);
      final AsynchronousFileImpl controller2 = new AsynchronousFileImpl(executor, pollerExecutor);
      controller.open(FILE_NAME + ".1", 10000);
      controller2.open(FILE_NAME + ".2", 10000);

      int numberOfLines = 1000;
      int size = 1024;

      ArrayList<Integer> listResult1 = new ArrayList<Integer>();
      ArrayList<Integer> listResult2 = new ArrayList<Integer>();

      AtomicInteger errors = new AtomicInteger(0);

      ByteBuffer buffer = null;
      try
      {
         CountDownLatch latchDone = new CountDownLatch(numberOfLines);
         CountDownLatch latchDone2 = new CountDownLatch(numberOfLines);

         buffer = AsynchronousFileImpl.newBuffer(size);
         encodeBufer(buffer);

         preAlloc(controller, numberOfLines * size);
         preAlloc(controller2, numberOfLines * size);

         ArrayList<CountDownCallback> list = new ArrayList<CountDownCallback>();
         ArrayList<CountDownCallback> list2 = new ArrayList<CountDownCallback>();

         for (int i = 0; i < numberOfLines; i++)
         {
            list.add(new CountDownCallback(latchDone, errors, listResult1, i));
            list2.add(new CountDownCallback(latchDone2, errors, listResult2, i));
         }

         int counter = 0;

         Iterator<CountDownCallback> iter2 = list2.iterator();

         for (CountDownCallback cb1 : list)
         {
            CountDownCallback cb2 = iter2.next();

            controller.write(counter * size, size, buffer, cb1);
            controller2.write(counter * size, size, buffer, cb2);
            ++counter;

         }

         latchDone.await();
         latchDone2.await();

         CountDownCallback.checkResults(numberOfLines, listResult1);
         CountDownCallback.checkResults(numberOfLines, listResult2);

         for (CountDownCallback callback : list)
         {
            Assert.assertEquals(1, callback.timesDoneCalled.get());
            Assert.assertTrue(callback.doneCalled);
         }

         for (CountDownCallback callback : list2)
         {
            Assert.assertEquals(1, callback.timesDoneCalled.get());
            Assert.assertTrue(callback.doneCalled);
         }

         Assert.assertEquals(0, errors.get());

         controller.close();
      }
      finally
      {
         AsynchronousFileImpl.destroyBuffer(buffer);
         try
         {
            controller.close();
         }
         catch (Exception ignored)
         {
         }
         try
         {
            controller2.close();
         }
         catch (Exception ignored)
         {
         }
      }
View Full Code Here

Examples of org.hornetq.core.asyncio.impl.AsynchronousFileImpl

            error = true;
            latch.countDown();
         }
      }

      AsynchronousFileImpl controller = new AsynchronousFileImpl(executor, pollerExecutor);
      ByteBuffer buffer = null;
      try
      {

         final int SIZE = 512;

         controller.open(FILE_NAME, 10);
         controller.close();

         controller = new AsynchronousFileImpl(executor, pollerExecutor);

         controller.open(FILE_NAME, 10);

         controller.fill(0, 1, 512, (byte)'j');

         buffer = AsynchronousFileImpl.newBuffer(SIZE);

         buffer.clear();

         for (int i = 0; i < SIZE; i++)
         {
            buffer.put((byte)(i % 100));
         }

         LocalCallback callbackLocal = new LocalCallback();

         controller.write(0, 512, buffer, callbackLocal);

         callbackLocal.latch.await();

         ByteBuffer newBuffer = ByteBuffer.allocateDirect(50);

         callbackLocal = new LocalCallback();

         controller.read(0, 50, newBuffer, callbackLocal);

         callbackLocal.latch.await();

         Assert.assertTrue(callbackLocal.error);

         callbackLocal = new LocalCallback();

         byte bytes[] = new byte[512];

         try
         {
            newBuffer = ByteBuffer.wrap(bytes);

            controller.read(0, 512, newBuffer, callbackLocal);

            Assert.fail("An exception was supposed to be thrown");
         }
         catch (HornetQException ignored)
         {
         }

         newBuffer = AsynchronousFileImpl.newBuffer(512);
         callbackLocal = new LocalCallback();
         controller.read(0, 512, newBuffer, callbackLocal);
         callbackLocal.latch.await();
         Assert.assertFalse(callbackLocal.error);

         newBuffer.rewind();

         byte[] bytesRead = new byte[SIZE];

         newBuffer.get(bytesRead);

         for (int i = 0; i < SIZE; i++)
         {
            Assert.assertEquals((byte)(i % 100), bytesRead[i]);
         }
      }
      finally
      {
         AsynchronousFileImpl.destroyBuffer(buffer);

         try
         {
            controller.close();
         }
         catch (HornetQException ignored)
         {
         }
View Full Code Here

Examples of org.hornetq.core.asyncio.impl.AsynchronousFileImpl

   public synchronized void open(final int maxIO, final boolean useExecutor) throws Exception
   {
      opened = true;

      aioFile = new AsynchronousFileImpl(useExecutor ? writerExecutor : null, pollerExecutor, this);

      try
      {
         aioFile.open(getFile().getAbsolutePath(), maxIO);
      }
View Full Code Here

Examples of org.hornetq.core.asyncio.impl.AsynchronousFileImpl

   public synchronized void open(final int maxIO, final boolean useExecutor) throws Exception
   {
      opened = true;

      aioFile = new AsynchronousFileImpl(useExecutor ? writerExecutor : null, pollerExecutor);

      aioFile.open(getFile().getAbsolutePath(), maxIO);

      position.set(0);
View Full Code Here

Examples of org.hornetq.core.asyncio.impl.AsynchronousFileImpl

   public synchronized void open(final int maxIO, final boolean useExecutor) throws HornetQException
   {
      opened = true;

      aioFile = new AsynchronousFileImpl(useExecutor ? writerExecutor : null, pollerExecutor, this);

      try
      {
         aioFile.open(getFile().getAbsolutePath(), maxIO);
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.