ClientRequest request = new ClientRequest(generateURL("/topics/testAck"));
ClientResponse response = request.head();
Assert.assertEquals(200, response.getStatus());
Link sender = MessageTestBase.getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "create");
System.out.println("create: " + sender);
Link subscriptions = MessageTestBase.getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "pull-subscriptions");
response = subscriptions.request().formParameter("autoAck", "false")
.formParameter("durable", "true")
.post();
Assert.assertEquals(201, response.getStatus());
Link sub1 = response.getLocation();
Assert.assertNotNull(sub1);
Link consumeNext = MessageTestBase.getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "acknowledge-next");
System.out.println("poller: " + consumeNext);
{
ClientResponse res = sender.request().body("text/plain", Integer.toString(1)).post();
Assert.assertEquals(201, res.getStatus());
res = consumeNext.request().post(String.class);
Assert.assertEquals(200, res.getStatus());
Link ack = MessageTestBase.getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledgement");
System.out.println("ack: " + ack);
Assert.assertNotNull(ack);
Link session = MessageTestBase.getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consumer");
System.out.println("session: " + session);
consumeNext = MessageTestBase.getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledge-next");
System.out.println("consumeNext: " + consumeNext);
// test timeout
Thread.sleep(2000);
ClientResponse ackRes = ack.request().formParameter("acknowledge", "true").post();
if (ackRes.getStatus() == 500)
{
System.out.println("Failure: " + ackRes.getEntity(String.class));
}
Assert.assertEquals(412, ackRes.getStatus());
System.out.println("**** Successfully failed ack");
consumeNext = MessageTestBase.getLinkByTitle(manager.getTopicManager().getLinkStrategy(), ackRes, "acknowledge-next");
System.out.println("consumeNext: " + consumeNext);
}
{
ClientResponse res = consumeNext.request().header(Constants.WAIT_HEADER, "2").post(String.class);
Assert.assertEquals(200, res.getStatus());
Link ack = MessageTestBase.getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledgement");
System.out.println("ack: " + ack);
Assert.assertNotNull(ack);
consumeNext = MessageTestBase.getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledge-next");
System.out.println("consumeNext: " + consumeNext);
ClientResponse ackRes = ack.request().formParameter("acknowledge", "true").post();
if (ackRes.getStatus() != 204)
{
System.out.println(ackRes.getEntity(String.class));
}
Assert.assertEquals(204, ackRes.getStatus());