@Test
  public void testFailure() throws Exception {
    try {
      String testName = "testFailure";
      startup();
      deployTopic(testName);

      ClientRequest request = new ClientRequest(generateURL("/topics/" + testName));

      ClientResponse<?> response = request.head();
      response.releaseConnection();
      Assert.assertEquals(200, response.getStatus());
      Link sender =
          MessageTestBase.getLinkByTitle(
              manager.getQueueManager().getLinkStrategy(), response, "create");
      System.out.println("create: " + sender);
      Link pushSubscriptions =
          MessageTestBase.getLinkByTitle(
              manager.getQueueManager().getLinkStrategy(), response, "push-subscriptions");
      System.out.println("push subscriptions: " + pushSubscriptions);

      PushTopicRegistration reg = new PushTopicRegistration();
      reg.setDurable(true);
      XmlLink target = new XmlLink();
      target.setHref("http://localhost:3333/error");
      target.setRelationship("uri");
      reg.setTarget(target);
      reg.setDisableOnFailure(true);
      reg.setMaxRetries(3);
      reg.setRetryWaitMillis(10);
      response = pushSubscriptions.request().body("application/xml", reg).post();
      Assert.assertEquals(201, response.getStatus());
      Link pushSubscription = response.getLocationLink();
      response.releaseConnection();

      ClientResponse<?> res = sender.request().body("text/plain", Integer.toString(1)).post();
      res.releaseConnection();
      Assert.assertEquals(201, res.getStatus());

      Thread.sleep(5000);

      response = pushSubscription.request().get();
      PushTopicRegistration reg2 = response.getEntity(PushTopicRegistration.class);
      response.releaseConnection();
      Assert.assertEquals(reg.isDurable(), reg2.isDurable());
      Assert.assertEquals(reg.getTarget().getHref(), reg2.getTarget().getHref());
      Assert.assertFalse(reg2.isEnabled());
      response.releaseConnection();

      String destination = reg2.getDestination();
      ClientSession session =
          manager.getQueueManager().getSessionFactory().createSession(false, false, false);
      ClientSession.QueueQuery query = session.queueQuery(new SimpleString(destination));
      Assert.assertFalse(query.isExists());

      manager.getQueueManager().getPushStore().removeAll();
    } finally {
      shutdown();
    }
  }
  private boolean subscriptionExists(String subscriptionId) {
    ClientSession session = null;
    try {
      session = sessionFactory.createSession();

      ClientSession.QueueQuery query = session.queueQuery(new SimpleString(subscriptionId));
      return query.isExists();
    } catch (HornetQException e) {
      throw new RuntimeException(e);
    } finally {
      if (session != null) {
        try {
          session.close();
        } catch (HornetQException e) {
        }
      }
    }
  }