Package org.hornetq.core.client.impl

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


         session.commit();
         producer.close();

         session.start();

         ClientConsumerInternal consumer = (ClientConsumerInternal)session.createConsumer(LargeMessageTest.ADDRESS);

         // Wait the consumer to be complete with 10 messages before getting others
         long timeout = System.currentTimeMillis() + 10000;
         while (consumer.getBufferSize() < NUMBER_OF_MESSAGES && timeout > System.currentTimeMillis())
         {
            Thread.sleep(10);
         }
         Assert.assertEquals(NUMBER_OF_MESSAGES, consumer.getBufferSize());

         // Reads the messages, rollback.. read them again
         for (int trans = 0; trans < 2; trans++)
         {

            for (int i = 0; i < NUMBER_OF_MESSAGES; i++)
            {
               ClientMessage msg = consumer.receive(10000);
               Assert.assertNotNull(msg);

               // it will ignore the buffer (not read it) on the first try
               if (trans == 0)
               {
View Full Code Here


      System.out.println("count Exp = " + qEXP.getMessageCount());

      System.out.println("msgCount = " + queue1.getMessageCount());

      // This is just to hold some messages as being delivered
      ClientConsumerInternal cons = (ClientConsumerInternal)session.createConsumer(ADDRESS);

      session.commit();
      producer.close();
      session.close();
View Full Code Here

      session.createQueue(PagingTest.ADDRESS, QUEUE2, null, true);

      ClientProducer producer = session.createProducer(PagingTest.ADDRESS);

      // This is just to hold some messages as being delivered
      ClientConsumerInternal cons = (ClientConsumerInternal)session.createConsumer(ADDRESS);
      ClientConsumerInternal cons2 = (ClientConsumerInternal)session.createConsumer(QUEUE2);

      ClientMessage message = null;

      final int MESSAGE_SIZE = 1024;

      byte[] body = new byte[MESSAGE_SIZE];

      ByteBuffer bb = ByteBuffer.wrap(body);

      for (int j = 1; j <= MESSAGE_SIZE; j++)
      {
         bb.put(getSamplebyte(j));
      }

      for (int i = 0; i < numberOfMessages; i++)
      {
         message = session.createMessage(true);

         HornetQBuffer bodyLocal = message.getBodyBuffer();

         bodyLocal.writeBytes(body);

         producer.send(message);
         if (i % 1000 == 0)
         {
            session.commit();
         }
      }
      session.commit();
      producer.close();
      session.start();

      long timeout = System.currentTimeMillis() + 5000;

      // I want the buffer full to make sure there are pending messages on the server's side
      while (System.currentTimeMillis() < timeout && cons.getBufferSize() < 1000 && cons2.getBufferSize() < 1000)
      {
         System.out.println("cons1 buffer = " + cons.getBufferSize() + ", cons2 buffer = " + cons2.getBufferSize());
         Thread.sleep(100);
      }

      assertTrue(cons.getBufferSize() >= 1000);
      assertTrue(cons2.getBufferSize() >= 1000);

      session.close();

      Queue queue = server.locateQueue(QUEUE2);
View Full Code Here

      System.out.println("count Exp = " + qEXP.getMessageCount());

      System.out.println("msgCount = " + queue1.getMessageCount());

      // This is just to hold some messages as being delivered
      ClientConsumerInternal cons = (ClientConsumerInternal)session.createConsumer(ADDRESS);

      session.commit();
      producer.close();
      session.close();
View Full Code Here

      session.createQueue(PagingTest.ADDRESS, QUEUE2, null, true);

      ClientProducer producer = session.createProducer(PagingTest.ADDRESS);

      // This is just to hold some messages as being delivered
      ClientConsumerInternal cons = (ClientConsumerInternal)session.createConsumer(ADDRESS);
      ClientConsumerInternal cons2 = (ClientConsumerInternal)session.createConsumer(QUEUE2);

      ClientMessage message = null;

      final int MESSAGE_SIZE = 1024;

      byte[] body = new byte[MESSAGE_SIZE];

      ByteBuffer bb = ByteBuffer.wrap(body);

      for (int j = 1; j <= MESSAGE_SIZE; j++)
      {
         bb.put(getSamplebyte(j));
      }

      for (int i = 0; i < numberOfMessages; i++)
      {
         message = session.createMessage(true);

         HornetQBuffer bodyLocal = message.getBodyBuffer();

         bodyLocal.writeBytes(body);

         producer.send(message);
         if (i % 1000 == 0)
         {
            session.commit();
         }
      }
      session.commit();
      producer.close();
      session.start();

      long timeout = System.currentTimeMillis() + 5000;

      // I want the buffer full to make sure there are pending messages on the server's side
      while (System.currentTimeMillis() < timeout && cons.getBufferSize() < 1000 && cons2.getBufferSize() < 1000)
      {
         System.out.println("cons1 buffer = " + cons.getBufferSize() + ", cons2 buffer = " + cons2.getBufferSize());
         Thread.sleep(100);
      }

      assertTrue(cons.getBufferSize() >= 1000);
      assertTrue(cons2.getBufferSize() >= 1000);

      session.close();

      Queue queue = server.locateQueue(QUEUE2);
View Full Code Here

         sessionB = sf.createSession(false, true, true);
         sessionB.start();

         session.start();

         ClientConsumerInternal consNeverUsed = (ClientConsumerInternal)sessionB.createConsumer(ADDRESS);

         ClientProducer prod = session.createProducer(ADDRESS);

         // This will force a credit to be sent, but if the message wasn't received we need to take out that credit from
         // the server
         // or the client will be buffering messages
         Assert.assertNull(consNeverUsed.receive(1));

         ClientMessage msg = createTextMessage(session, "This one will expire");
         if (largeMessages)
         {
            msg.getBodyBuffer().writeBytes(new byte[600]);
         }

         msg.setExpiration(System.currentTimeMillis() + 100);
         prod.send(msg);

         msg = createTextMessage(session, "First-on-non-buffered");

         prod.send(msg);

         Thread.sleep(110);

         // It will be able to receive another message, but it shouldn't send a credit again, as the credit was already
         // sent
         msg = consNeverUsed.receive(TIMEOUT * 1000);
         Assert.assertNotNull(msg);
         Assert.assertEquals("First-on-non-buffered", getTextMessage(msg));
         msg.acknowledge();

         ClientConsumer cons1 = session.createConsumer(ADDRESS);

         for (int i = 0; i < numberOfMessages; i++)
         {
            msg = createTextMessage(session, "Msg" + i);

            if (largeMessages)
            {
               msg.getBodyBuffer().writeBytes(new byte[600]);
            }

            prod.send(msg);
         }

         for (int i = 0; i < numberOfMessages; i++)
         {
            msg = cons1.receive(1000);
            Assert.assertNotNull("expected message at i = " + i, msg);
            Assert.assertEquals("Msg" + i, getTextMessage(msg));
            msg.acknowledge();
         }

         Assert.assertEquals(0, consNeverUsed.getBufferSize());

         session.close();
         session = null;

         sessionB.close();
View Full Code Here

         SimpleString ADDRESS = new SimpleString("some-queue");

         session1.createQueue(ADDRESS, ADDRESS, true);

         ClientConsumerInternal cons1 = (ClientConsumerInternal)session1.createConsumer(ADDRESS);

         // Note we make sure we send the messages *before* cons2 is created

         ClientProducer prod = session1.createProducer(ADDRESS);

         for (int i = 0; i < numberOfMessages; i++)
         {
            ClientMessage msg = createTextMessage(session1, "Msg" + i);
            if (largeMessages)
            {
               msg.getBodyBuffer().writeBytes(new byte[600]);
            }
            prod.send(msg);
         }

         ClientConsumerInternal cons2 = (ClientConsumerInternal)session2.createConsumer(ADDRESS);

         for (int i = 0; i < numberOfMessages / 2; i++)
         {
            ClientMessage msg = cons1.receive(1000);
            Assert.assertNotNull("expected message at i = " + i, msg);

            String str = getTextMessage(msg);
            Assert.assertEquals("Msg" + i, str);

            log.info("got msg " + str);

            msg.acknowledge();

            Assert.assertEquals("A slow consumer shouldn't buffer anything on the client side!",
                                0,
                                cons1.getBufferSize());
         }

         for (int i = numberOfMessages / 2; i < numberOfMessages; i++)
         {
            ClientMessage msg = cons2.receive(1000);

            Assert.assertNotNull("expected message at i = " + i, msg);

            String str = getTextMessage(msg);

            log.info("got msg " + str);

            Assert.assertEquals("Msg" + i, str);

            msg.acknowledge();

            Assert.assertEquals("A slow consumer shouldn't buffer anything on the client side!",
                                0,
                                cons2.getBufferSize());
         }

         session1.close(); // just to make sure everything is flushed and no pending packets on the sending buffer, or
         // the getMessageCount would fail
         session2.close();

         session1 = sf.createSession(false, true, true);
         session1.start();
         session2 = sf.createSession(false, true, true);
         session2.start();

         prod = session1.createProducer(ADDRESS);

         Assert.assertEquals(0, getMessageCount(server, ADDRESS.toString()));

         // This should also work the other way around

         cons1.close();

         cons2.close();

         cons1 = (ClientConsumerInternal)session1.createConsumer(ADDRESS);

         // Note we make sure we send the messages *before* cons2 is created

         for (int i = 0; i < numberOfMessages; i++)
         {
            ClientMessage msg = createTextMessage(session1, "Msg" + i);
            if (largeMessages)
            {
               msg.getBodyBuffer().writeBytes(new byte[600]);
            }
            prod.send(msg);
         }

         cons2 = (ClientConsumerInternal)session2.createConsumer(ADDRESS);

         // Now we receive on cons2 first

         for (int i = 0; i < numberOfMessages / 2; i++)
         {
            ClientMessage msg = cons2.receive(1000);
            Assert.assertNotNull("expected message at i = " + i, msg);

            Assert.assertEquals("Msg" + i, msg.getBodyBuffer().readString());

            msg.acknowledge();

            Assert.assertEquals("A slow consumer shouldn't buffer anything on the client side!",
                                0,
                                cons2.getBufferSize());

         }

         for (int i = numberOfMessages / 2; i < numberOfMessages; i++)
         {
View Full Code Here

         SimpleString ADDRESS = new SimpleString("some-queue");

         session1.createQueue(ADDRESS, ADDRESS, true);

         ClientConsumerInternal cons1 = (ClientConsumerInternal)session1.createConsumer(ADDRESS);

         // Note we make sure we send the messages *before* cons2 is created

         ClientProducer prod = session1.createProducer(ADDRESS);

         for (int i = 0; i < numberOfMessages; i++)
         {
            ClientMessage msg = session1.createMessage(true);
            msg.getBodyBuffer().writeBytes(new byte[600]);
            prod.send(msg);
         }

         for (int i = 0; i < numberOfMessages; i++)
         {
            ClientMessage msg = cons1.receive(1000);
            Assert.assertNotNull("expected message at i = " + i, msg);

            msg.saveToOutputStream(new FakeOutputStream());

            msg.acknowledge();

            Assert.assertEquals("A slow consumer shouldn't buffer anything on the client side!",
                                0,
                                cons1.getBufferSize());
         }

         session1.close(); // just to make sure everything is flushed and no pending packets on the sending buffer, or
         session1.close();
         session1 = null;
View Full Code Here

            producer.send(msg);
         }

         session.commit();

         ClientConsumerInternal consumer = (ClientConsumerInternal)session.createConsumer(ADDRESS);

         session.start();

         for (int repeat = 0; repeat < 100; repeat ++)
         {
            System.out.println("Repeat " + repeat);
            long timeout = System.currentTimeMillis() + 2000;
            // At least 10 messages on the buffer
            while (timeout > System.currentTimeMillis() && consumer.getBufferSize() <= 10)
            {
               Thread.sleep(10);
            }
            assertTrue(consumer.getBufferSize() >= 10);

            ClientMessage msg = consumer.receive(500);
            msg.getBodyBuffer().readByte();
            assertNotNull(msg);
            msg.acknowledge();
            session.rollback();
         }


         for (int i = 0 ; i < numberOfMessages; i++)
         {
            ClientMessage msg = consumer.receive(5000);
            assertNotNull(msg);
            System.out.println("msg " + msg);
            msg.getBodyBuffer().readByte();
            msg.acknowledge();
            session.commit();
View Full Code Here

         sessionB = sf.createSession(false, true, true);
         sessionB.start();

         session.start();

         ClientConsumerInternal consReceiveOneAndHold = (ClientConsumerInternal)sessionB.createConsumer(ADDRESS);

         final CountDownLatch latchReceived = new CountDownLatch(2);

         final CountDownLatch latchDone = new CountDownLatch(1);

         // It can't close the session while the large message is being read
         final CountDownLatch latchRead = new CountDownLatch(1);

         // It should receive two messages and then give up
         class LocalHandler implements MessageHandler
         {
            boolean failed = false;

            int count = 0;

            /* (non-Javadoc)
             * @see org.hornetq.api.core.client.MessageHandler#onMessage(org.hornetq.api.core.client.ClientMessage)
             */
            public synchronized void onMessage(final ClientMessage message)
            {
               try
               {
                  String str = getTextMessage(message);

                  failed = failed || !str.equals("Msg" + count);

                  message.acknowledge();
                  latchReceived.countDown();

                  if (count++ == 1)
                  {
                     // it will hold here for a while
                     if (!latchDone.await(TIMEOUT, TimeUnit.SECONDS)) // a timed wait, so if the test fails, one less
                     // thread around
                     {
                        new Exception("ClientConsuemrWindowSizeTest Handler couldn't receive signal in less than 5 seconds").printStackTrace();
                        failed = true;
                     }

                     if (largeMessages)
                     {
                        message.getBodyBuffer().readBytes(new byte[600]);
                     }

                     latchRead.countDown();
                  }
               }
               catch (Exception e)
               {
                  e.printStackTrace(); // Hudson / JUnit report
                  failed = true;
               }
            }
         }

         LocalHandler handler = new LocalHandler();

         ClientConsumer cons1 = session.createConsumer(ADDRESS);

         ClientProducer prod = session.createProducer(ADDRESS);

         for (int i = 0; i < numberOfMessages; i++)
         {
            ClientMessage msg = createTextMessage(session, "Msg" + i);
            if (largeMessages)
            {
               msg.getBodyBuffer().writeBytes(new byte[600]);
            }
            prod.send(msg);
         }

         consReceiveOneAndHold.setMessageHandler(handler);

         Assert.assertTrue(latchReceived.await(TIMEOUT, TimeUnit.SECONDS));

         Assert.assertEquals(0, consReceiveOneAndHold.getBufferSize());

         for (int i = 2; i < numberOfMessages; i++)
         {
            ClientMessage msg = cons1.receive(1000);
            Assert.assertNotNull("expected message at i = " + i, msg);
            Assert.assertEquals("Msg" + i, getTextMessage(msg));
            msg.acknowledge();
         }

         Assert.assertEquals(0, consReceiveOneAndHold.getBufferSize());

         latchDone.countDown();

         // The test can' t close the session while the message is still being read, or it could interrupt the data
         Assert.assertTrue(latchRead.await(10, TimeUnit.SECONDS));
View Full Code Here

TOP

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

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.