durable2.close();
   public void testDurableSubscriptionReconnect() throws Exception   {      final String CLIENT_ID1 = "test-client-id1";      Connection conn1 = null;      Connection conn2 = null;      try      {         conn1 = cf.createConnection();         conn1.setClientID(CLIENT_ID1);         Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);         MessageProducer prod = sess1.createProducer(topic);         prod.setDeliveryMode(DeliveryMode.PERSISTENT);         log.debug("creating durable subscription");         MessageConsumer durable = sess1.createDurableSubscriber(topic, "mySubscription");         log.debug("durable subscription created");         conn1.start();         final int NUM_MESSAGES = 2;         log.debug("sending messages ...");         for (int i = 0; i < NUM_MESSAGES; i++)         {            TextMessage tm = sess1.createTextMessage("hello");            prod.send(topic, tm);         }         final int NUM_TO_RECEIVE = NUM_MESSAGES - 1;         log.debug("receiving messages ...");         for (int i = 0; i < NUM_TO_RECEIVE; i++)         {            TextMessage tm = (TextMessage)durable.receive(3000);            assertNotNull(tm);         }         // Close the connection         conn1.close();         conn1 = null;         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(1500);            if (tm == null)            {               break;            }            count++;         }         log.trace("Received " + count  + " messages");         assertEquals(NUM_MESSAGES - NUM_TO_RECEIVE, count);         sess2.unsubscribe("mySubscription");      }      finally      {         if (conn1 != null)         {            conn1.close();         }         if (conn2 != null)         {            conn2.close();         }      }   }