Package org.hornetq.core.journal.impl

Examples of org.hornetq.core.journal.impl.TimedBuffer


         {
            return 1024 * 1024;
         }
      }

      TimedBuffer timedBuffer = new TimedBuffer(100, TimedBufferTest.ONE_SECOND, false);

      timedBuffer.start();

      try
      {

         timedBuffer.setObserver(new TestObserver());

         int x = 0;
         for (int i = 0; i < 10; i++)
         {
            byte[] bytes = new byte[10];
            for (int j = 0; j < 10; j++)
            {
               bytes[j] = UnitTestCase.getSamplebyte(x++);
            }

            HornetQBuffer buff = HornetQBuffers.wrappedBuffer(bytes);

            timedBuffer.checkSize(10);
            timedBuffer.addBytes(buff, false, dummyCallback);
         }

         timedBuffer.checkSize(1);

         Assert.assertEquals(1, flushTimes.get());

         ByteBuffer flushedBuffer = buffers.get(0);

         Assert.assertEquals(100, flushedBuffer.limit());

         Assert.assertEquals(100, flushedBuffer.capacity());

         flushedBuffer.rewind();

         for (int i = 0; i < 100; i++)
         {
            Assert.assertEquals(UnitTestCase.getSamplebyte(i), flushedBuffer.get());
         }
      }
      finally
      {
         timedBuffer.stop();
      }

   }
View Full Code Here


         {
            return 1024 * 1024;
         }
      }

      TimedBuffer timedBuffer = new TimedBuffer(100, TimedBufferTest.ONE_SECOND / 10, false);

      timedBuffer.start();

      try
      {

         timedBuffer.setObserver(new TestObserver());

         int x = 0;

         byte[] bytes = new byte[10];
         for (int j = 0; j < 10; j++)
         {
            bytes[j] = UnitTestCase.getSamplebyte(x++);
         }

         HornetQBuffer buff = HornetQBuffers.wrappedBuffer(bytes);

         timedBuffer.checkSize(10);
         timedBuffer.addBytes(buff, false, dummyCallback);

         Thread.sleep(200);

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

         bytes = new byte[10];
         for (int j = 0; j < 10; j++)
         {
            bytes[j] = UnitTestCase.getSamplebyte(x++);
         }

         buff = HornetQBuffers.wrappedBuffer(bytes);

         timedBuffer.checkSize(10);
         timedBuffer.addBytes(buff, true, dummyCallback);

         Thread.sleep(500);

         Assert.assertEquals(1, flushTimes.get());

         ByteBuffer flushedBuffer = buffers.get(0);

         Assert.assertEquals(20, flushedBuffer.limit());

         Assert.assertEquals(20, flushedBuffer.capacity());

         flushedBuffer.rewind();

         for (int i = 0; i < 20; i++)
         {
            Assert.assertEquals(UnitTestCase.getSamplebyte(i), flushedBuffer.get());
         }
      }
      finally
      {
         timedBuffer.stop();
      }

   }
View Full Code Here

         {
            return 1024 * 1024;
         }
      }

      TimedBuffer timedBuffer = new TimedBuffer(100, TimedBufferTest.ONE_SECOND, false);

      timedBuffer.start();

      try
      {

         timedBuffer.setObserver(new TestObserver());

         int x = 0;
         for (int i = 0; i < 10; i++)
         {
            byte[] bytes = new byte[10];
            for (int j = 0; j < 10; j++)
            {
               bytes[j] = UnitTestCase.getSamplebyte(x++);
            }

            HornetQBuffer buff = HornetQBuffers.wrappedBuffer(bytes);

            timedBuffer.checkSize(10);
            timedBuffer.addBytes(buff, false, dummyCallback);
         }

         timedBuffer.checkSize(1);

         Assert.assertEquals(1, flushTimes.get());

         ByteBuffer flushedBuffer = buffers.get(0);

         Assert.assertEquals(100, flushedBuffer.limit());

         Assert.assertEquals(100, flushedBuffer.capacity());

         flushedBuffer.rewind();

         for (int i = 0; i < 100; i++)
         {
            Assert.assertEquals(UnitTestCase.getSamplebyte(i), flushedBuffer.get());
         }
      }
      finally
      {
         timedBuffer.stop();
      }

   }
View Full Code Here

         {
            return 1024 * 1024;
         }
      }

      TimedBuffer timedBuffer = new TimedBuffer(100, TimedBufferTest.ONE_SECOND / 10, false);

      timedBuffer.start();

      try
      {

         timedBuffer.setObserver(new TestObserver());

         int x = 0;

         byte[] bytes = new byte[10];
         for (int j = 0; j < 10; j++)
         {
            bytes[j] = UnitTestCase.getSamplebyte(x++);
         }

         HornetQBuffer buff = HornetQBuffers.wrappedBuffer(bytes);

         timedBuffer.checkSize(10);
         timedBuffer.addBytes(buff, false, dummyCallback);

         Thread.sleep(200);

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

         bytes = new byte[10];
         for (int j = 0; j < 10; j++)
         {
            bytes[j] = UnitTestCase.getSamplebyte(x++);
         }

         buff = HornetQBuffers.wrappedBuffer(bytes);

         timedBuffer.checkSize(10);
         timedBuffer.addBytes(buff, true, dummyCallback);

         Thread.sleep(500);

         Assert.assertEquals(1, flushTimes.get());

         ByteBuffer flushedBuffer = buffers.get(0);

         Assert.assertEquals(20, flushedBuffer.limit());

         Assert.assertEquals(20, flushedBuffer.capacity());

         flushedBuffer.rewind();

         for (int i = 0; i < 20; i++)
         {
            Assert.assertEquals(UnitTestCase.getSamplebyte(i), flushedBuffer.get());
         }
      }
      finally
      {
         timedBuffer.stop();
      }

   }
View Full Code Here

TOP

Related Classes of org.hornetq.core.journal.impl.TimedBuffer

Copyright © 2018 www.massapicom. 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.