[hornetq-commits] JBoss hornetq SVN: r11092 - branches/Branch_2_2_EAP_cluster_clean2/tests/src/org/hornetq/tests/integration/client.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Aug 1 17:08:32 EDT 2011


Author: clebert.suconic at jboss.com
Date: 2011-08-01 17:08:32 -0400 (Mon, 01 Aug 2011)
New Revision: 11092

Modified:
   branches/Branch_2_2_EAP_cluster_clean2/tests/src/org/hornetq/tests/integration/client/JMSPagingFileDeleteTest.java
Log:
oops

Modified: branches/Branch_2_2_EAP_cluster_clean2/tests/src/org/hornetq/tests/integration/client/JMSPagingFileDeleteTest.java
===================================================================
--- branches/Branch_2_2_EAP_cluster_clean2/tests/src/org/hornetq/tests/integration/client/JMSPagingFileDeleteTest.java	2011-08-01 19:39:43 UTC (rev 11091)
+++ branches/Branch_2_2_EAP_cluster_clean2/tests/src/org/hornetq/tests/integration/client/JMSPagingFileDeleteTest.java	2011-08-01 21:08:32 UTC (rev 11092)
@@ -15,15 +15,12 @@
 
 import javax.jms.BytesMessage;
 import javax.jms.Connection;
-import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.jms.MessageConsumer;
 import javax.jms.MessageProducer;
 import javax.jms.Session;
 import javax.jms.Topic;
 
-import junit.framework.Assert;
-
 import org.hornetq.api.core.SimpleString;
 import org.hornetq.core.logging.Logger;
 import org.hornetq.core.paging.PagingStore;
@@ -33,9 +30,19 @@
 public class JMSPagingFileDeleteTest extends JMSTestBase
 {
    static Logger log = Logger.getLogger(JMSPagingFileDeleteTest.class);
-
+   
    Topic topic1;
 
+   Connection connection;
+
+   Session session;
+
+   MessageConsumer subscriber1;
+
+   MessageConsumer subscriber2;
+
+   PagingStore pagingStore;
+
    private static final int MESSAGE_SIZE = 1024;
 
    private static final int PAGE_SIZE = 10 * 1024;
@@ -73,195 +80,113 @@
       topic1 = null;
       super.tearDown();
    }
-
+   
    public void testTopics() throws Exception
    {
-      Connection connection = null;
+      connection = null;
 
       try
       {
          connection = cf.createConnection();
          connection.setClientID("cid");
 
-         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
 
          MessageProducer producer = session.createProducer(topic1);
-         MessageConsumer subscriber1 = session.createDurableSubscriber(topic1, "subscriber-1");
-         MessageConsumer subscriber2 = session.createDurableSubscriber(topic1, "subscriber-2");
+         subscriber1 = session.createDurableSubscriber(topic1, "subscriber-1");
+         subscriber2 = session.createDurableSubscriber(topic1, "subscriber-2");
 
-         int numMessages = sendMessages(createMessage(session), producer);
+         // -----------------(Step1) Publish Messages to make Paging Files. --------------------
+         System.out.println("---------- Send messages. ----------");
+         BytesMessage bytesMessage = session.createBytesMessage();
+         bytesMessage.writeBytes(new byte[JMSPagingFileDeleteTest.MESSAGE_SIZE]);
+         for (int i = 0; i < JMSPagingFileDeleteTest.MESSAGE_NUM; i++)
+         {
+            producer.send(bytesMessage);
+         }
+         System.out.println("Sent " + JMSPagingFileDeleteTest.MESSAGE_NUM + " messages.");
 
-         printPageStoreInfo();
+         pagingStore = server.getPagingManager().getPageStore(new SimpleString("jms.topic.topic1"));
+         printPageStoreInfo(pagingStore);
 
-         Assert.assertTrue(getPagingStore().isPaging());
+         assertTrue(pagingStore.isPaging());
 
          connection.start();
 
          // -----------------(Step2) Restart the server. --------------------------------------
-         // If try this test without restarting server, please comment out this section;
-         close(connection);
-         stopAndStartServer();
+         stopAndStartServer(); // If try this test without restarting server, please comment out this line;
 
-         connection = cf.createConnection();
-         connection.setClientID("cid");
-         session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         subscriber1 = session.createDurableSubscriber(topic1, "subscriber-1");
-         subscriber2 = session.createDurableSubscriber(topic1, "subscriber-2");
-         connection.start();
-
          // -----------------(Step3) Subscribe to all the messages from the topic.--------------
          System.out.println("---------- Receive all messages. ----------");
-         for (int i = 0; i < numMessages; i++)
+         for (int i = 0; i < JMSPagingFileDeleteTest.MESSAGE_NUM; i++)
          {
-            Assert.assertNotNull(subscriber1.receive(JMSPagingFileDeleteTest.RECEIVE_TIMEOUT));
-            Assert.assertNotNull(subscriber2.receive(JMSPagingFileDeleteTest.RECEIVE_TIMEOUT));
+            Message message1 = subscriber1.receive(JMSPagingFileDeleteTest.RECEIVE_TIMEOUT);
+            assertNotNull(message1);
+            Message message2 = subscriber2.receive(JMSPagingFileDeleteTest.RECEIVE_TIMEOUT);
+            assertNotNull(message2);
          }
 
-         waitUntilPagingStops(5000);
+         pagingStore = server.getPagingManager().getPageStore(new SimpleString("jms.topic.topic1"));
+         long timeout = System.currentTimeMillis() + 5000;
+         while (timeout > System.currentTimeMillis() && pagingStore.isPaging())
+         {
+            Thread.sleep(100);
+         }
+         assertFalse(pagingStore.isPaging());
+         
+         printPageStoreInfo(pagingStore);
 
-         printPageStoreInfo();
-
-         Assert.assertEquals(0, getPagingStore().getAddressSize());
+         assertEquals(0, pagingStore.getAddressSize());
          // assertEquals(1, pagingStore.getNumberOfPages()); //I expected number of the page is 1, but It was not.
-         Assert.assertFalse(getPagingStore().isPaging()); // I expected IsPaging is false, but It was true.
+         assertFalse(pagingStore.isPaging()); // I expected IsPaging is false, but It was true.
          // If the server is not restart, this test pass.
 
          // -----------------(Step4) Publish a message. the message is stored in the paging file.
          producer = session.createProducer(topic1);
-         sendMessage(createMessage(session), producer);
+         bytesMessage = session.createBytesMessage();
+         bytesMessage.writeBytes(new byte[JMSPagingFileDeleteTest.MESSAGE_SIZE]);
+         producer.send(bytesMessage);
 
-         printPageStoreInfo();
+         printPageStoreInfo(pagingStore);
 
-         Assert.assertEquals(1, getPagingStore().getNumberOfPages()); // I expected number of the page is 1, but It was
-                                                                      // not.
+         assertEquals(1, pagingStore.getNumberOfPages()); //I expected number of the page is 1, but It was not.
       }
       finally
       {
-         close(connection);
-      }
-   }
-
-   public void testTopics_nonDurable() throws Exception
-   {
-      Connection connection = null;
-
-      try
-      {
-         connection = cf.createConnection();
-
-         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-         MessageProducer producer = session.createProducer(topic1);
-
-         printPageStoreInfo();
-
-         connection.start();
-
-         MessageConsumer subscriber = session.createConsumer(topic1);
-         final Message message = createMessage(session);
-         int numMessages = sendJustEnoughMessagesForPaging(message, producer);
-
-         // ###Works if uncomment this to send one extra message or if use sendMessages instead above
-         // printPageStoreInfo();
-         sendMessage(message, producer);
-         // numMessages++;
-
-         printPageStoreInfo();
-
-         for (int i = 0; i < numMessages; i++)
-         {
-            Assert.assertNotNull(subscriber.receive(JMSPagingFileDeleteTest.RECEIVE_TIMEOUT));
-            System.out.println("Messages recd:" + (i + 1));
-         }
-         
-         assertNull(subscriber.receive(1000));
-
-         waitUntilPagingStops(5000);
-
-         printPageStoreInfo();
-      }
-      finally
-      {
-         close(connection);
-      }
-   }
-
-   private void close(final Connection connection)
-   {
-      try
-      {
          if (connection != null)
          {
             connection.close();
          }
       }
-      catch (JMSException e)
-      {
-         e.printStackTrace();
-      }
    }
 
-   private int sendMessages(final Message message, final MessageProducer producer) throws JMSException
+   private void stopAndStartServer() throws Exception
    {
-      System.out.println("---------- Send messages. ----------");
-      for (int i = 0; i < JMSPagingFileDeleteTest.MESSAGE_NUM; i++)
-      {
-         sendMessage(message, producer);
-      }
-      System.out.println("Sent " + JMSPagingFileDeleteTest.MESSAGE_NUM + " messages.");
+      System.out.println("---------- Restart server. ----------");
+      connection.close();
 
-      return JMSPagingFileDeleteTest.MESSAGE_NUM;
-   }
+      jmsServer.stop();
 
-   private int sendJustEnoughMessagesForPaging(final Message message, final MessageProducer producer) throws Exception
-   {
-      int messagesSendCount = 0;
-      while (!getPagingStore().isPaging())
-      {
-         sendMessage(message, producer);
-         messagesSendCount++;
-      }
+      jmsServer.start();
+      jmsServer.activated();
+      registerConnectionFactory();
 
-      System.out.println(messagesSendCount + " messages sent before paging started");
-
-      return messagesSendCount;
+      printPageStoreInfo(pagingStore);
+      reconnect();
    }
 
-   private void sendMessage(final Message message, final MessageProducer producer) throws JMSException
+   private void reconnect() throws Exception
    {
-      producer.send(message);
+      connection = cf.createConnection();
+      connection.setClientID("cid");
+      session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      subscriber1 = session.createDurableSubscriber(topic1, "subscriber-1");
+      subscriber2 = session.createDurableSubscriber(topic1, "subscriber-2");
+      connection.start();
    }
 
-   private Message createMessage(final Session session) throws JMSException
+   private void printPageStoreInfo(PagingStore pagingStore) throws Exception
    {
-      BytesMessage bytesMessage = session.createBytesMessage();
-      bytesMessage.writeBytes(new byte[JMSPagingFileDeleteTest.MESSAGE_SIZE]);
-      return bytesMessage;
-   }
-
-   private void waitUntilPagingStops(final int timeoutMillis) throws Exception, InterruptedException
-   {
-      long timeout = System.currentTimeMillis() + timeoutMillis;
-      while (timeout > System.currentTimeMillis() && getPagingStore().isPaging())
-      {
-         Thread.sleep(100);
-      }
-      
-      if (!getPagingStore().isPaging())
-      {
-         System.exit(-1);
-      }
-      Assert.assertFalse("Paging should have stopped", getPagingStore().isPaging());
-   }
-
-   private PagingStore getPagingStore() throws Exception
-   {
-      return server.getPagingManager().getPageStore(new SimpleString("jms.topic.topic1"));
-   }
-
-   private void printPageStoreInfo() throws Exception
-   {
-      PagingStore pagingStore = getPagingStore();
       System.out.println("---------- Paging Store Info ----------");
       System.out.println(" CurrentPage = " + pagingStore.getCurrentPage());
       System.out.println(" FirstPage = " + pagingStore.getFirstPage());
@@ -269,17 +194,4 @@
       System.out.println(" Address Size = " + pagingStore.getAddressSize());
       System.out.println(" Is Paging = " + pagingStore.isPaging());
    }
-
-   private void stopAndStartServer() throws Exception
-   {
-      System.out.println("---------- Restart server. ----------");
-
-      jmsServer.stop();
-
-      jmsServer.start();
-      jmsServer.activated();
-      registerConnectionFactory();
-
-      printPageStoreInfo();
-   }
 }
\ No newline at end of file



More information about the hornetq-commits mailing list