Examples of AsynchronousFileImpl


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

      destroy(newBuffer);
   }

   private void asyncData(final int numberOfLines, final int size, final int aioLimit) throws Exception
   {
      controller = new AsynchronousFileImpl(executor, pollerExecutor);
      controller.open(FILE_NAME, aioLimit);



      CountDownLatch latchDone = new CountDownLatch(numberOfLines);
View Full Code Here

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

   {

      final int NUMBER_LINES = 3000;
      final int SIZE = 1024;

      controller = new AsynchronousFileImpl(executor, pollerExecutor);
      controller.open(FILE_NAME, 2000);

      buffer = AsynchronousFileImpl.newBuffer(SIZE);
      encodeBufer(buffer);
View Full Code Here

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

   }


   public void testInternalWrite() throws Exception
   {
      controller = new AsynchronousFileImpl(executor, pollerExecutor);
      controller.open(FILE_NAME, 2000);

      final int SIZE = 10 * 512;

      buffer = AsynchronousFileImpl.newBuffer(SIZE);
View Full Code Here

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

   }


   public void testInvalidWrite() throws Exception
   {
      controller = new AsynchronousFileImpl(executor, pollerExecutor);
      controller.open(FILE_NAME, 2000);

      final int SIZE = 512;

      buffer = AsynchronousFileImpl.newBuffer(SIZE);
View Full Code Here

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

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

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

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

      controller.open(FILE_NAME, 1);
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

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 void testBufferCallbackAwaysSameBuffer() throws Exception
   {
      boolean closed = false;
      final AsynchronousFileImpl controller = new AsynchronousFileImpl(executor, pollerExecutor);
      ByteBuffer buffer = null;
      try
      {
         final int NUMBER_LINES = 1000;
         final int SIZE = 512;

         controller.open(FILE_NAME, 1000);

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

         final ArrayList<ByteBuffer> buffers = new ArrayList<ByteBuffer>();

         BufferCallback bufferCallback = new BufferCallback()
         {
            public void bufferDone(final ByteBuffer buffer)
            {
               buffers.add(buffer);
            }
         };

         controller.setBufferCallback(bufferCallback);

         CountDownLatch latch = new CountDownLatch(NUMBER_LINES);

         buffer = AsynchronousFileImpl.newBuffer(SIZE);
         buffer.rewind();
         for (int j = 0; j < SIZE; j++)
         {
            buffer.put((byte)(j % Byte.MAX_VALUE));
         }

         ArrayList<Integer> result = new ArrayList<Integer>();

         for (int i = 0; i < NUMBER_LINES; i++)
         {
            CountDownCallback aio = new CountDownCallback(latch, null, result, i);
            controller.write(i * SIZE, SIZE, buffer, aio);
         }

         // The buffer callback is only called after the complete callback was
         // called.
         // Because of that a race could happen on the assertions to
         // buffers.size what would invalidate the test
         // We close the file and that would guarantee the buffer callback was
         // called for all the elements
         controller.close();
         closed = true;

         CountDownCallback.checkResults(NUMBER_LINES, result);

         Assert.assertEquals(NUMBER_LINES, buffers.size());

         // Make sure all the buffers are unique
         ByteBuffer lineOne = null;
         for (ByteBuffer bufferTmp : buffers)
         {
            if (lineOne == null)
            {
               lineOne = bufferTmp;
            }
            else
            {
               Assert.assertTrue(lineOne == bufferTmp);
            }
         }

         buffers.clear();

      }
      finally
      {
         AsynchronousFileImpl.destroyBuffer(buffer);
         if (!closed)
         {
            controller.close();
         }
      }
   }
View Full Code Here

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

      }
   }

   public void testRead() throws Exception
   {
      final AsynchronousFileImpl controller = new AsynchronousFileImpl(executor, pollerExecutor);
      controller.setBufferCallback(new BufferCallback()
      {

         public void bufferDone(final ByteBuffer buffer)
         {
            AsynchronousFileImpl.destroyBuffer(buffer);
         }

      });

      ByteBuffer readBuffer = null;
      try
      {

         final int NUMBER_LINES = 1000;
         final int SIZE = 1024;

         controller.open(FILE_NAME, 1000);

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

         {
            CountDownLatch latch = new CountDownLatch(NUMBER_LINES);
            ArrayList<Integer> result = new ArrayList<Integer>();

            AtomicInteger errors = new AtomicInteger(0);

            for (int i = 0; i < NUMBER_LINES; i++)
            {
               if (i % 100 == 0)
               {
                  System.out.println("Wrote " + i + " lines");
               }
               ByteBuffer buffer = AsynchronousFileImpl.newBuffer(SIZE);
               for (int j = 0; j < SIZE; j++)
               {
                  buffer.put(UnitTestCase.getSamplebyte(j));
               }

               CountDownCallback aio = new CountDownCallback(latch, errors, result, i);
               controller.write(i * SIZE, SIZE, buffer, aio);
            }

            latch.await();

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

            CountDownCallback.checkResults(NUMBER_LINES, result);
         }

         // If you call close you're supposed to wait events to finish before
         // closing it
         controller.close();
         controller.setBufferCallback(null);

         controller.open(FILE_NAME, 10);

         readBuffer = AsynchronousFileImpl.newBuffer(SIZE);

         for (int i = 0; i < NUMBER_LINES; i++)
         {
            if (i % 100 == 0)
            {
               System.out.println("Read " + i + " lines");
            }
            AsynchronousFileImpl.clearBuffer(readBuffer);

            CountDownLatch latch = new CountDownLatch(1);
            AtomicInteger errors = new AtomicInteger(0);
            CountDownCallback aio = new CountDownCallback(latch, errors, null, 0);

            controller.read(i * SIZE, SIZE, readBuffer, aio);

            latch.await();
            Assert.assertEquals(0, errors.get());
            Assert.assertTrue(aio.doneCalled);

            byte bytesRead[] = new byte[SIZE];
            readBuffer.get(bytesRead);

            for (int count = 0; count < SIZE; count++)
            {
               Assert.assertEquals("byte position " + count + " differs on line " + i + " position = " + count,
                                   UnitTestCase.getSamplebyte(count),
                                   bytesRead[count]);
            }
         }
      }
      finally
      {
         if (readBuffer != null)
         {
            AsynchronousFileImpl.destroyBuffer(readBuffer);
         }
         try
         {
            controller.close();
         }
         catch (Throwable ignored)
         {
         }

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.