Package org.hornetq.core.client.impl

Examples of org.hornetq.core.client.impl.LargeMessageControllerImpl


   }


   public void testStreamDataWaitCompletionOnSlowComingBuffer() throws Exception
   {
      final LargeMessageControllerImpl outBuffer = new LargeMessageControllerImpl(new FakeConsumerInternal(), 5, 1000);


      class FakeOutputStream extends OutputStream
      {
         @Override
         public void write(int b) throws IOException
         {
         }
      }

      outBuffer.setOutputStream(new FakeOutputStream());

      Thread sender = new Thread()
      {
         public void run()
         {
            try
            {
               Thread.sleep(200);
               outBuffer.addPacket(new FakePacket(-1, new byte[] { 0 }, true, false));
               Thread.sleep(1000);
               outBuffer.addPacket(new FakePacket(-1, new byte[] { 0 }, true, false));
               Thread.sleep(1000);
               outBuffer.addPacket(new FakePacket(-1, new byte[] { 0 }, false, false));
            }
            catch (Exception e)
            {
            }
         }
      };

      sender.start();
      outBuffer.waitCompletion(0);
      sender.join();
   }
View Full Code Here


   }

   public void testErrorOnSetStreaming() throws Exception
   {
      long start = System.currentTimeMillis();
      final LargeMessageControllerImpl outBuffer = new LargeMessageControllerImpl(new FakeConsumerInternal(), 5, 30000);

      outBuffer.addPacket(new FakePacket(-1, new byte[] { 0, 1, 2, 3, 4 }, true, false));

      final CountDownLatch latchBytesWritten1 = new CountDownLatch(5);
      final CountDownLatch latchBytesWritten2 = new CountDownLatch(10);

      outBuffer.setOutputStream(new OutputStream()
      {
         @Override
         public void write(final int b) throws IOException
         {
            latchBytesWritten1.countDown();
            latchBytesWritten2.countDown();
         }
      });

      latchBytesWritten1.await();

      try
      {
         outBuffer.readByte();
         Assert.fail("supposed to throw an exception");
      }
      catch (IllegalAccessError ignored)
      {
      }
View Full Code Here

   }

   public void testReadPartialData() throws Exception
   {

      final LargeMessageControllerImpl buffer = new LargeMessageControllerImpl(new FakeConsumerInternal(), 10, 10000);

      buffer.addPacket(new FakePacket(-1, new byte[] { 0, 1, 2, 3, 4 }, true, true));

      byte bytes[] = new byte[30];
      buffer.readBytes(bytes, 0, 5);

      for (byte i = 0; i < 5; i++)
      {
         Assert.assertEquals(i, bytes[i]);
      }

      final CountDownLatch latchGo = new CountDownLatch(1);

      final AtomicInteger errorCount = new AtomicInteger(0);

      Thread t = new Thread()
      {
         @Override
         public void run()
         {

            try
            {
               latchGo.countDown();
               buffer.readBytes(new byte[5]);
            }
            catch (IndexOutOfBoundsException ignored)
            {
            }
            catch (IllegalAccessError ignored)
            {

            }
            catch (Throwable e)
            {
               e.printStackTrace();
               errorCount.incrementAndGet();
            }
         }
      };

      t.start();

      latchGo.await();

      buffer.cancel();

      t.join();

      Assert.assertEquals(0, errorCount.get());
View Full Code Here

   }

   public void testInterruptData() throws Exception
   {
      LargeMessageControllerImpl readBuffer = splitBuffer(3, new byte[] { 0, 1, 2, 3, 4 });

      byte bytes[] = new byte[30];
      readBuffer.readBytes(bytes, 0, 5);

      for (byte i = 0; i < 5; i++)
      {
         Assert.assertEquals(i, bytes[i]);
      }
View Full Code Here

      }
   }

   public void testSplitBufferOnFile() throws Exception
   {
      LargeMessageControllerImpl outBuffer = new LargeMessageControllerImpl(new FakeConsumerInternal(),
                                                                    1024 * 1024,
                                                                    1,
                                                                    getTestFile(),
                                                                    1024);
      try
      {

         long count = 0;
         for (int i = 0; i < 10; i++)
         {
            byte buffer[] = new byte[10240];
            for (int j = 0; j < 10240; j++)
            {
               buffer[j] = getSamplebyte(count++);
            }
            outBuffer.addPacket(new FakePacket(1, buffer, true, false));
         }

         outBuffer.readerIndex(0);

         for (int i = 0; i < 10240 * 10; i++)
         {
            assertEquals("position " + i, getSamplebyte(i), outBuffer.readByte());
         }

         outBuffer.readerIndex(0);

         for (int i = 0; i < 10240 * 10; i++)
         {
            assertEquals("position " + i, getSamplebyte(i), outBuffer.readByte());
         }
      }
      finally
      {
         outBuffer.close();
      }

   }
View Full Code Here

   }

   public void testStreamData() throws Exception
   {
      final LargeMessageControllerImpl outBuffer = new LargeMessageControllerImpl(new FakeConsumerInternal(),
                                                                          1024 * 11 + 123,
                                                                          10000);

      final PipedOutputStream output = new PipedOutputStream();
      final PipedInputStream input = new PipedInputStream(output);

      final AtomicInteger errors = new AtomicInteger(0);

      // Done reading 3 elements
      final CountDownLatch done1 = new CountDownLatch(1);
      // Done with the thread
      final CountDownLatch done2 = new CountDownLatch(1);

      final AtomicInteger count = new AtomicInteger(0);
      final AtomicInteger totalBytes = new AtomicInteger(0);

      Thread treader = new Thread("treader")
      {
         @Override
         public void run()
         {
            try
            {

               byte line[] = new byte[1024];
               int dataRead = 0;
               while (dataRead >= 0)
               {
                  dataRead = input.read(line);
                  if (dataRead > 0)
                  {
                     System.out.println("Read one line with " + dataRead + " bytes");
                     totalBytes.addAndGet(dataRead);
                     if (count.incrementAndGet() == 3)
                     {
                        done1.countDown();
                     }
                  }
               }
            }
            catch (Exception e)
            {
               e.printStackTrace();
               errors.incrementAndGet();
            }
            finally
            {
               done1.countDown();
               done2.countDown();
            }
         }
      };

      treader.setDaemon(true);
      treader.start();

      for (int i = 0; i < 3; i++)
      {
         outBuffer.addPacket(new FakePacket(-1, new byte[1024], true, false));
      }

      outBuffer.setOutputStream(output);

      final CountDownLatch waiting = new CountDownLatch(1);

      Thread twaiter = new Thread("twaiter")
      {
         @Override
         public void run()
         {
            try
            {
               outBuffer.waitCompletion(0);
               waiting.countDown();
            }
            catch (Exception e)
            {
               e.printStackTrace();
               errors.incrementAndGet();
            }
         }
      };

      twaiter.setDaemon(true);
      twaiter.start();

      Assert.assertTrue(done1.await(10, TimeUnit.SECONDS));

      Assert.assertEquals(3, count.get());
      Assert.assertEquals(1024 * 3, totalBytes.get());

      for (int i = 0; i < 8; i++)
      {
         outBuffer.addPacket(new FakePacket(-1, new byte[1024], true, false));
      }

      Assert.assertEquals(1, waiting.getCount());

      outBuffer.addPacket(new FakePacket(-1, new byte[123], false, false));

      Assert.assertTrue(done2.await(10, TimeUnit.SECONDS));

      Assert.assertTrue(waiting.await(10, TimeUnit.SECONDS));

View Full Code Here

   }

   public void testStreamDataWaitCompletionOnCompleteBuffer() throws Exception
   {
      final LargeMessageControllerImpl outBuffer = create15BytesSample();

      outBuffer.saveBuffer(new OutputStream()
      {
         @Override
         public void write(final int b) throws IOException
         {
            // nohting to be done
View Full Code Here

      });
   }

   public void testStreamDataWaitCompletionOnInCompleteBuffer() throws Exception
   {
      final LargeMessageControllerImpl outBuffer = new LargeMessageControllerImpl(new FakeConsumerInternal(), 5, 1000);


      class FakeOutputStream extends OutputStream
      {
         @Override
         public void write(int b) throws IOException
         {
         }
      }

      outBuffer.setOutputStream(new FakeOutputStream());

      long time = System.currentTimeMillis();
      try
      {
         outBuffer.waitCompletion(0);
         fail("supposed to throw an exception");
      }
      catch (HornetQException e)
      {
      }
View Full Code Here

   }


   public void testStreamDataWaitCompletionOnSlowComingBuffer() throws Exception
   {
      final LargeMessageControllerImpl outBuffer = new LargeMessageControllerImpl(new FakeConsumerInternal(), 5, 1000);


      class FakeOutputStream extends OutputStream
      {
         @Override
         public void write(int b) throws IOException
         {
         }
      }

      outBuffer.setOutputStream(new FakeOutputStream());

      Thread sender = new Thread()
      {
         public void run()
         {
            try
            {
               Thread.sleep(200);
               outBuffer.addPacket(new FakePacket(-1, new byte[] { 0 }, true, false));
               Thread.sleep(1000);
               outBuffer.addPacket(new FakePacket(-1, new byte[] { 0 }, true, false));
               Thread.sleep(1000);
               outBuffer.addPacket(new FakePacket(-1, new byte[] { 0 }, false, false));
            }
            catch (Exception e)
            {
            }
         }
      };

      sender.start();
      outBuffer.waitCompletion(0);
      sender.join();
   }
View Full Code Here

   }

   public void testErrorOnSetStreaming() throws Exception
   {
      long start = System.currentTimeMillis();
      final LargeMessageControllerImpl outBuffer = new LargeMessageControllerImpl(new FakeConsumerInternal(), 5, 30000);

      outBuffer.addPacket(new FakePacket(-1, new byte[] { 0, 1, 2, 3, 4 }, true, false));

      final CountDownLatch latchBytesWritten1 = new CountDownLatch(5);
      final CountDownLatch latchBytesWritten2 = new CountDownLatch(10);

      outBuffer.setOutputStream(new OutputStream()
      {
         @Override
         public void write(final int b) throws IOException
         {
            latchBytesWritten1.countDown();
            latchBytesWritten2.countDown();
         }
      });

      latchBytesWritten1.await();

      try
      {
         outBuffer.readByte();
         Assert.fail("supposed to throw an exception");
      }
      catch (IllegalAccessError ignored)
      {
      }
View Full Code Here

TOP

Related Classes of org.hornetq.core.client.impl.LargeMessageControllerImpl

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.