final int NUM_MESSAGES = 50;
final int NUM_MESSAGES = 2;
   public void testDurableSubscriptionReconnect() throws Exception   {      final String CLIENT_ID1 = "test-client-id1";      Connection conn1 = cf.createConnection();      conn1.setClientID(CLIENT_ID1);      Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);      MessageProducer prod = sess1.createProducer(topic);      prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);      MessageConsumer durable = sess1.createDurableSubscriber(topic, "mySubscription");      conn1.start();      final int NUM_MESSAGES = 50;      for (int i = 0; i < NUM_MESSAGES; i++)      {         TextMessage tm = sess1.createTextMessage("hello");         prod.send(topic, tm);      }      final int NUM_TO_RECEIVE1 = 22;      for (int i = 0; i < NUM_TO_RECEIVE1; i++)      {         TextMessage tm = (TextMessage)durable.receive(3000);         if (tm == null)         {            fail();         }      }      //Close the connection      conn1.close();      conn1 = null;      Connection conn2 = cf.createConnection();      conn2.setClientID(CLIENT_ID1);      Session sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);      //Re-subscribe to the subscription      log.trace("Resubscribing");      MessageConsumer durable2 = sess2.createDurableSubscriber(topic, "mySubscription");      conn2.start();      int count = 0;      while (true)      {         TextMessage tm = (TextMessage)durable2.receive(3000);         if (tm == null)         {            break;         }         count++;      }      log.trace("Received " + count  + " messages");      assertEquals(NUM_MESSAGES - NUM_TO_RECEIVE1, count);      sess2.unsubscribe("mySubscription");      conn2.close();   }