Java Code Examples for org.jboss.resteasy.client.ClientResponse#getLocationLink()

The following examples show how to use org.jboss.resteasy.client.ClientResponse#getLocationLink() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PushQueueConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private Link createPushRegistration(String queueToPushTo,
                                    Link pushSubscriptions,
                                    PushRegistrationType pushRegistrationType,
                                    int sessionCount) throws Exception {
   PushRegistration reg = new PushRegistration();
   reg.setDurable(false);
   XmlLink target = new XmlLink();
   if (pushRegistrationType == PushRegistrationType.CLASS) {
      target.setHref(generateURL(Util.getUrlPath(queueToPushTo)));
      target.setClassName(ActiveMQPushStrategy.class.getName());
   } else if (pushRegistrationType == PushRegistrationType.BRIDGE) {
      target.setHref(generateURL(Util.getUrlPath(queueToPushTo)));
      target.setRelationship("destination");
   } else if (pushRegistrationType == PushRegistrationType.TEMPLATE) {
      target.setHref(queueToPushTo);
      target.setRelationship("template");
   } else if (pushRegistrationType == PushRegistrationType.URI) {
      target.setMethod("put");
      target.setHref(queueToPushTo);
   }
   reg.setTarget(target);
   reg.setSessionCount(sessionCount);
   ClientResponse pushRegistrationResponse = pushSubscriptions.request().body("application/xml", reg).post();
   pushRegistrationResponse.releaseConnection();
   Assert.assertEquals(201, pushRegistrationResponse.getStatus());
   Link pushSubscription = pushRegistrationResponse.getLocationLink();
   return pushSubscription;
}
 
Example 2
Source File: BaseResponse.java    From oxAuth with MIT License 5 votes vote down vote up
public BaseResponse(ClientResponse<String> clientResponse) {
    if (clientResponse != null) {
        status = clientResponse.getStatus();
        if (clientResponse.getLocationLink() != null) {
            location = clientResponse.getLocationLink().getHref();
        }
        entity = clientResponse.getEntity(String.class);
        headers = clientResponse.getMetadata();
    }
}
 
Example 3
Source File: AutoAckTopicTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testNewSubNotBlockedByTimeoutTask() throws Exception {
   // Default config is 1s interval, 300s timeout.

   // Create a topic
   String testName = "AutoAckTopicTest.testNewSubNotBlockedByTimeoutTask";
   TopicDeployment deployment = new TopicDeployment();
   deployment.setDuplicatesAllowed(true);
   deployment.setDurableSend(false);
   deployment.setName(testName);
   manager.getTopicManager().deploy(deployment);

   // Create a consumer
   ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/topics/" + testName));
   ClientResponse<?> response = request.head();
   response.releaseConnection();
   Assert.assertEquals(200, response.getStatus());
   Link sender = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "create");
   Link subscriptions = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "pull-subscriptions");

   // Create the pull-subscription itself.
   ClientResponse<?> res = subscriptions.request().post();
   res.releaseConnection();
   Assert.assertEquals(201, res.getStatus());
   Link sub1 = res.getLocationLink();
   Assert.assertNotNull(sub1);
   Link consumeNext1 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
   Assert.assertNotNull(consumeNext1);

   // Pull on the topic for 8s (long enoguh to guarantee the rest of the test
   // will pass/fail due to the timeouttask + test operations)
   AcceptWaitListener awlistener = new AcceptWaitListener(consumeNext1.getHref());
   Thread t = new Thread(awlistener);
   t.start();
   // Wait 2 seconds to ensure a new TimeoutTask is running concurrently.
   Thread.sleep(2000);
   // Attempt to create a new pull-subscription. Validate that it takes no longer than 2 seconds
   // (it should take like 20ms, but give it a relatively huge amount of leeway)
   NewPullSubscriber nps = new NewPullSubscriber(subscriptions.getHref());
   Thread npsThread = new Thread(nps);
   npsThread.start();
   Thread.sleep(2000);
   Assert.assertTrue("NewPullSubscriber did not finish in 2 seconds!", nps.isFinished());
   Assert.assertFalse("AcceptWaitListener failed to open connection!", awlistener.isFailed());
   Assert.assertFalse("NewPullSubscriber failed to open new subscription!", nps.isFailed());
   npsThread.interrupt();
   t.interrupt();
}
 
Example 4
Source File: FindDestinationTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testFindTopic() throws Exception {
   server.getActiveMQServer().addAddressInfo(new AddressInfo(SimpleString.toSimpleString("testTopic"), RoutingType.MULTICAST));
   server.getActiveMQServer().createQueue(new QueueConfiguration("testTopic")
                                             .setRoutingType(RoutingType.MULTICAST)
                                             .setDurable(false));
   ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/topics/testTopic"));

   ClientResponse<?> response = request.head();
   response.releaseConnection();
   Assert.assertEquals(200, response.getStatus());
   Link sender = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "create");
   Link subscriptions = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "pull-subscriptions");

   ClientResponse<?> res = subscriptions.request().post();
   Assert.assertEquals(201, res.getStatus());
   Link sub1 = res.getLocationLink();
   res.releaseConnection();
   Assert.assertNotNull(sub1);
   Link consumeNext1 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
   Assert.assertNotNull(consumeNext1);
   log.debug("consumeNext1: " + consumeNext1);

   res = subscriptions.request().post();
   Assert.assertEquals(201, res.getStatus());
   Link sub2 = res.getLocationLink();
   res.releaseConnection();
   Assert.assertNotNull(sub2);
   Link consumeNext2 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
   Assert.assertNotNull(consumeNext1);

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

   res = consumeNext1.request().post(String.class);
   Assert.assertEquals(200, res.getStatus());
   Assert.assertEquals("1", res.getEntity(String.class));
   res.releaseConnection();
   consumeNext1 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");

   res = consumeNext1.request().post(String.class);
   Assert.assertEquals(200, res.getStatus());
   Assert.assertEquals("2", res.getEntity(String.class));
   res.releaseConnection();

   res = consumeNext2.request().post(String.class);
   Assert.assertEquals(200, res.getStatus());
   Assert.assertEquals("1", res.getEntity(String.class));
   res.releaseConnection();
   consumeNext2 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");

   res = consumeNext2.request().post(String.class);
   Assert.assertEquals(200, res.getStatus());
   Assert.assertEquals("2", res.getEntity(String.class));
   res.releaseConnection();

   res = sub1.request().delete();
   res.releaseConnection();
   Assert.assertEquals(204, res.getStatus());

   res = sub2.request().delete();
   res.releaseConnection();
   Assert.assertEquals(204, res.getStatus());
}
 
Example 5
Source File: PostOrder.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
   // first get the create URL for the shipping queue
   ClientRequest request = new ClientRequest("http://localhost:8080/queues/orders");
   ClientResponse res = request.head();
   Link create = res.getHeaderAsLink("msg-create");

   System.out.println("Send Bill's order...");
   Order order = new Order();
   order.setName("Bill");
   order.setItem("iPhone4");
   order.setAmount("$199.99");

   res = create.request().body("application/xml", order).post();

   if (res.getStatus() == 307) {
      Link redirect = res.getLocationLink();
      res.releaseConnection();
      res = redirect.request().body("application/xml", order).post();
   }

   if (res.getStatus() != 201)
      throw new RuntimeException("Failed to post");

   create = res.getHeaderAsLink("msg-create-next");

   if (res.getStatus() != 201)
      throw new RuntimeException("Failed to post");

   System.out.println("Send Monica's order...");
   order.setName("Monica");

   res.releaseConnection();
   res = create.request().body("application/xml", order).post();

   if (res.getStatus() != 201)
      throw new RuntimeException("Failed to post");

   System.out.println("Resend Monica's order over same create-next link...");

   res.releaseConnection();
   res = create.request().body("application/xml", order).post();

   if (res.getStatus() != 201)
      throw new RuntimeException("Failed to post");
}
 
Example 6
Source File: SelectorTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testPush() throws Exception {
   server.getJaxrsServer().getDeployment().getRegistry().addPerRequestResource(PushReceiver.class);
   ClientRequest request = new ClientRequest(generateURL("/topics/" + topicName));

   ClientResponse<?> response = request.head();
   response.releaseConnection();
   Assert.assertEquals(200, response.getStatus());
   Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "push-subscriptions");
   log.debug("push: " + consumers);

   PushTopicRegistration oneReg = new PushTopicRegistration();
   oneReg.setDurable(false);
   XmlLink target = new XmlLink();
   target.setMethod("post");
   target.setHref(generateURL("/push/one"));
   target.setType("application/xml");
   oneReg.setTarget(target);
   oneReg.setSelector("MyTag = '1'");
   response = consumers.request().body("application/xml", oneReg).post();
   response.releaseConnection();
   Link oneSubscription = response.getLocationLink();

   PushTopicRegistration twoReg = new PushTopicRegistration();
   twoReg.setDurable(false);
   target = new XmlLink();
   target.setMethod("post");
   target.setHref(generateURL("/push/two"));
   target.setType("application/xml");
   twoReg.setTarget(target);
   twoReg.setSelector("MyTag = '2'");
   response = consumers.request().body("application/xml", twoReg).post();
   response.releaseConnection();
   Link twoSubscription = response.getLocationLink();

   Order order = new Order();
   order.setName("1");
   order.setAmount("$5.00");
   publish(prefixedTopicName, order, null, "1");
   Thread.sleep(200);
   Assert.assertEquals(order, PushReceiver.oneOrder);

   order.setName("2");
   publish(prefixedTopicName, order, null, "2");
   Thread.sleep(200);
   Assert.assertEquals(order, PushReceiver.twoOrder);

   order.setName("3");
   publish(prefixedTopicName, order, null, "2");
   Thread.sleep(200);
   Assert.assertEquals(order, PushReceiver.twoOrder);

   order.setName("4");
   publish(prefixedTopicName, order, null, "1");
   Thread.sleep(200);
   Assert.assertEquals(order, PushReceiver.oneOrder);

   order.setName("5");
   publish(prefixedTopicName, order, null, "1");
   Thread.sleep(200);
   Assert.assertEquals(order, PushReceiver.oneOrder);

   order.setName("6");
   publish(prefixedTopicName, order, null, "1");
   Thread.sleep(200);
   Assert.assertEquals(order, PushReceiver.oneOrder);

   response = oneSubscription.request().delete();
   response.releaseConnection();
   response = twoSubscription.request().delete();
   response.releaseConnection();
}
 
Example 7
Source File: PersistentPushTopicConsumerTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@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");
      log.debug("create: " + sender);
      Link pushSubscriptions = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "push-subscriptions");
      log.debug("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();
   }
}
 
Example 8
Source File: CreateDestinationTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testCreateTopic() throws Exception {
   String queueConfig = "<topic name=\"testTopic\"></topic>";
   ClientRequest create = new ClientRequest(TestPortProvider.generateURL("/topics"));
   ClientResponse cRes = create.body("application/activemq.jms.topic+xml", queueConfig).post();
   cRes.releaseConnection();
   Assert.assertEquals(201, cRes.getStatus());

   ClientRequest request = cRes.getLocationLink().request();

   ClientResponse<?> response = request.head();
   response.releaseConnection();
   Assert.assertEquals(200, response.getStatus());
   Link sender = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "create");
   Link subscriptions = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "pull-subscriptions");

   ClientResponse<?> res = subscriptions.request().post();
   res.releaseConnection();
   Assert.assertEquals(201, res.getStatus());
   Link sub1 = res.getLocationLink();
   Assert.assertNotNull(sub1);
   Link consumeNext1 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
   Assert.assertNotNull(consumeNext1);
   log.debug("consumeNext1: " + consumeNext1);

   res = subscriptions.request().post();
   res.releaseConnection();
   Assert.assertEquals(201, res.getStatus());
   Link sub2 = res.getLocationLink();
   Assert.assertNotNull(sub2);
   Link consumeNext2 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
   Assert.assertNotNull(consumeNext1);

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

   res = consumeNext1.request().post(String.class);
   Assert.assertEquals(200, res.getStatus());
   Assert.assertEquals("1", res.getEntity(String.class));
   res.releaseConnection();
   consumeNext1 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");

   res = consumeNext1.request().post(String.class);
   Assert.assertEquals(200, res.getStatus());
   Assert.assertEquals("2", res.getEntity(String.class));
   res.releaseConnection();
   consumeNext1 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");

   res = consumeNext2.request().post(String.class);
   Assert.assertEquals(200, res.getStatus());
   Assert.assertEquals("1", res.getEntity(String.class));
   res.releaseConnection();
   consumeNext2 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");

   res = consumeNext2.request().post(String.class);
   Assert.assertEquals(200, res.getStatus());
   Assert.assertEquals("2", res.getEntity(String.class));
   res.releaseConnection();
   consumeNext2 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
   res = sub1.request().delete();
   res.releaseConnection();
   Assert.assertEquals(204, res.getStatus());
   res = sub2.request().delete();
   res.releaseConnection();
   Assert.assertEquals(204, res.getStatus());
}
 
Example 9
Source File: DupQueueTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testDup() throws Exception {
   String testName = "testDup";
   QueueDeployment deployment = new QueueDeployment();
   deployment.setDuplicatesAllowed(false);
   deployment.setDurableSend(false);
   deployment.setName(testName);
   manager.getQueueManager().deploy(deployment);

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

   ClientResponse<?> response = request.head();
   Assert.assertEquals(200, response.getStatus());
   Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
   log.debug("create: " + sender);
   Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
   log.debug("pull: " + consumers);
   response = Util.setAutoAck(consumers, true);
   Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
   log.debug("poller: " + consumeNext);

   ClientResponse<?> res = sender.request().body("text/plain", Integer.toString(1)).post();
   Assert.assertEquals(307, res.getStatus());
   sender = res.getLocationLink();
   res.releaseConnection();
   log.debug("create-next: " + sender);
   Assert.assertNotNull(sender);
   res = sender.request().body("text/plain", Integer.toString(1)).post();
   res.releaseConnection();
   Assert.assertEquals(201, res.getStatus());
   res = sender.request().body("text/plain", Integer.toString(1)).post();
   res.releaseConnection();
   Assert.assertEquals(201, res.getStatus());
   sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "create-next");
   res = sender.request().body("text/plain", Integer.toString(2)).post();
   res.releaseConnection();
   Assert.assertEquals(201, res.getStatus());

   res = consumeNext.request().post(String.class);
   Assert.assertEquals(200, res.getStatus());
   Assert.assertEquals("1", res.getEntity(String.class));
   res.releaseConnection();
   Link session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
   log.debug("session: " + session);
   consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
   log.debug("consumeNext: " + consumeNext);

   res = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
   Assert.assertEquals(200, res.getStatus());
   res.releaseConnection();
   session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
   log.debug("session: " + session);
   consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
   log.debug("consumeNext: " + consumeNext);
   res = consumeNext.request().post(String.class);
   res.releaseConnection();

   res = session.request().delete();
   res.releaseConnection();
   Assert.assertEquals(204, res.getStatus());
}
 
Example 10
Source File: PushTopicConsumerTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testUriWithMultipleSessions() throws Exception {
   final int CONCURRENT = 10;

   TopicDeployment deployment = new TopicDeployment();
   deployment.setDuplicatesAllowed(true);
   deployment.setDurableSend(false);
   deployment.setName("testUriWithMultipleSessions");
   manager.getTopicManager().deploy(deployment);

   ClientRequest request = new ClientRequest(generateURL("/topics/testUriWithMultipleSessions"));
   server.getJaxrsServer().getDeployment().getRegistry().addPerRequestResource(MyConcurrentResource.class);

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

   PushTopicRegistration reg = new PushTopicRegistration();
   reg.setDurable(false);
   XmlLink target = new XmlLink();
   target.setMethod("put");
   target.setHref(generateURL("/myConcurrent"));
   reg.setTarget(target);
   reg.setSessionCount(CONCURRENT);
   response = pushSubscriptions.request().body("application/xml", reg).post();
   Assert.assertEquals(201, response.getStatus());
   Link pushSubscription = response.getLocationLink();
   response.releaseConnection();

   for (int i = 0; i < CONCURRENT; i++) {
      response = sender.request().body("text/plain", Integer.toString(1)).post();
      response.releaseConnection();
      Assert.assertEquals(201, response.getStatus());
   }

   // wait until all the invocations have completed
   while (MyConcurrentResource.concurrentInvocations.get() > 0) {
      Thread.sleep(100);
   }

   Assert.assertEquals(CONCURRENT, MyConcurrentResource.maxConcurrentInvocations.get());

   response = pushSubscription.request().delete();
   response.releaseConnection();
   Assert.assertEquals(204, response.getStatus());
}
 
Example 11
Source File: PushTopicConsumerTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testUri() throws Exception {
   TopicDeployment deployment = new TopicDeployment();
   deployment.setDuplicatesAllowed(true);
   deployment.setDurableSend(false);
   deployment.setName("testUri");
   manager.getTopicManager().deploy(deployment);

   ClientRequest request = new ClientRequest(generateURL("/topics/testUri"));
   server.getJaxrsServer().getDeployment().getRegistry().addPerRequestResource(MyResource.class);

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

   PushTopicRegistration reg = new PushTopicRegistration();
   reg.setDurable(false);
   XmlLink target = new XmlLink();
   target.setMethod("put");
   target.setHref(generateURL("/my"));
   reg.setTarget(target);
   response = pushSubscriptions.request().body("application/xml", reg).post();
   Assert.assertEquals(201, response.getStatus());
   Link pushSubscription = response.getLocationLink();
   response.releaseConnection();

   response = sender.request().body("text/plain", Integer.toString(1)).post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());

   Thread.sleep(100);

   Assert.assertEquals("1", MyResource.gotit);
   response = pushSubscription.request().delete();
   response.releaseConnection();
   Assert.assertEquals(204, response.getStatus());
}
 
Example 12
Source File: PersistentPushQueueConsumerTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testFailure() throws Exception {
   try {
      startup();

      String testName = "testFailure";
      QueueDeployment deployment = new QueueDeployment();
      deployment.setDuplicatesAllowed(true);
      deployment.setDurableSend(false);
      deployment.setName(testName);
      manager.getQueueManager().deploy(deployment);

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

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

      PushRegistration reg = new PushRegistration();
      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();
      PushRegistration reg2 = response.getEntity(PushRegistration.class);
      Assert.assertEquals(reg.isDurable(), reg2.isDurable());
      Assert.assertEquals(reg.getTarget().getHref(), reg2.getTarget().getHref());
      Assert.assertFalse(reg2.isEnabled()); // make sure the failure disables the PushRegistration
      response.releaseConnection();

      manager.getQueueManager().getPushStore().removeAll();
   } finally {
      shutdown();
   }
}
 
Example 13
Source File: AutoAckTopicTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testSuccessFirst() throws Exception {
   String testName = "AutoAckTopicTest.testSuccessFirst";
   TopicDeployment deployment = new TopicDeployment();
   deployment.setDuplicatesAllowed(true);
   deployment.setDurableSend(false);
   deployment.setName(testName);
   manager.getTopicManager().deploy(deployment);

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

   ClientResponse<?> response = request.head();
   response.releaseConnection();
   Assert.assertEquals(200, response.getStatus());
   Link sender = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "create");
   Link subscriptions = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "pull-subscriptions");

   ClientResponse<?> res = subscriptions.request().post();
   res.releaseConnection();
   Assert.assertEquals(201, res.getStatus());
   Link sub1 = res.getLocationLink();
   Assert.assertNotNull(sub1);
   Link consumeNext1 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
   Assert.assertNotNull(consumeNext1);
   log.debug("consumeNext1: " + consumeNext1);

   res = subscriptions.request().post();
   res.releaseConnection();
   Assert.assertEquals(201, res.getStatus());
   Link sub2 = res.getLocationLink();
   Assert.assertNotNull(sub2);
   Link consumeNext2 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
   Assert.assertNotNull(consumeNext2);
   log.debug("consumeNext2: " + consumeNext2);

   res = sender.request().body("text/plain", "1").post();
   res.releaseConnection();
   Assert.assertEquals(201, res.getStatus());
   res = sender.request().body("text/plain", "2").post();
   res.releaseConnection();
   Assert.assertEquals(201, res.getStatus());

   res = consumeNext1.request().post(String.class);
   Assert.assertEquals(200, res.getStatus());
   Assert.assertEquals("1", res.getEntity(String.class));
   res.releaseConnection();
   consumeNext1 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");

   res = consumeNext1.request().post(String.class);
   Assert.assertEquals(200, res.getStatus());
   Assert.assertEquals("2", res.getEntity(String.class));
   res.releaseConnection();
   consumeNext1 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");

   res = consumeNext2.request().post(String.class);
   Assert.assertEquals(200, res.getStatus());
   Assert.assertEquals("1", res.getEntity(String.class));
   res.releaseConnection();
   consumeNext2 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");

   res = consumeNext2.request().post(String.class);
   Assert.assertEquals(200, res.getStatus());
   Assert.assertEquals("2", res.getEntity(String.class));
   res.releaseConnection();
   consumeNext2 = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consume-next");
   Assert.assertEquals(204, sub1.request().delete().getStatus());
   Assert.assertEquals(204, sub2.request().delete().getStatus());
}
 
Example 14
Source File: ClientAckTopicTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testPull() throws Exception {
   ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/topics/testQueue"));

   ClientResponse<?> response = request.head();
   response.releaseConnection();
   Assert.assertEquals(200, response.getStatus());
   Link sender = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "create");
   log.debug("create: " + sender);
   Link subscriptions = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "pull-subscriptions");
   response = subscriptions.request().formParameter("autoAck", "false").formParameter("durable", "true").post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());
   Link sub1 = response.getLocationLink();
   Assert.assertNotNull(sub1);
   Link consumeNext = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "acknowledge-next");
   log.debug("poller: " + consumeNext);

   ClientResponse<String> res = consumeNext.request().post(String.class);
   res.releaseConnection();
   Assert.assertEquals(503, res.getStatus());
   consumeNext = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledge-next");
   log.debug(consumeNext);
   res = sender.request().body("text/plain", Integer.toString(1)).post();
   res.releaseConnection();
   Assert.assertEquals(201, res.getStatus());
   res = consumeNext.request().post(String.class);
   Assert.assertEquals(200, res.getStatus());
   Assert.assertEquals(Integer.toString(1), res.getEntity());
   res.releaseConnection();
   Link ack = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledgement");
   log.debug("ack: " + ack);
   ClientResponse ackRes = ack.request().formParameter("acknowledge", "true").post();
   ackRes.releaseConnection();
   Assert.assertEquals(204, ackRes.getStatus());
   res = consumeNext.request().post();
   res.releaseConnection();
   Assert.assertEquals(503, res.getStatus());
   res = sender.request().body("text/plain", Integer.toString(2)).post();
   res.releaseConnection();
   Assert.assertEquals(201, res.getStatus());
   res = sender.request().body("text/plain", Integer.toString(3)).post();
   res.releaseConnection();
   Assert.assertEquals(201, res.getStatus());

   res = consumeNext.request().post(String.class);
   Assert.assertEquals(200, res.getStatus());
   Assert.assertEquals(Integer.toString(2), res.getEntity());
   res.releaseConnection();
   ack = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledgement");
   log.debug("ack: " + ack);
   ackRes = ack.request().formParameter("acknowledge", "true").post();
   ackRes.releaseConnection();
   Assert.assertEquals(204, ackRes.getStatus());

   res = consumeNext.request().post(String.class);
   Assert.assertEquals(200, res.getStatus());
   Assert.assertEquals(Integer.toString(3), res.getEntity());
   res.releaseConnection();
   ack = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledgement");
   log.debug("ack: " + ack);
   ackRes = ack.request().formParameter("acknowledge", "true").post();
   ackRes.releaseConnection();
   Assert.assertEquals(204, ackRes.getStatus());

   res = consumeNext.request().post();
   res.releaseConnection();
   Assert.assertEquals(503, res.getStatus());
   log.debug(sub1);
   res = sub1.request().delete();
   res.releaseConnection();
   Assert.assertEquals(204, res.getStatus());
}
 
Example 15
Source File: ClientAckTopicTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testSuccessFirstNonDurable() throws Exception {
   ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/topics/testQueue"));

   ClientResponse<?> response = request.head();
   response.releaseConnection();
   Assert.assertEquals(200, response.getStatus());
   Link sender = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "create");
   log.debug("create: " + sender);

   Link subscriptions = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "pull-subscriptions");
   response = subscriptions.request().formParameter("autoAck", "false").formParameter("durable", "false").post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());
   Link sub1 = response.getLocationLink();
   Assert.assertNotNull(sub1);
   Link consumeNext = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "acknowledge-next");
   log.debug("poller: " + consumeNext);

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

   log.debug("call ack next");
   res = consumeNext.request().post(String.class);
   res.releaseConnection();
   Assert.assertEquals(200, res.getStatus());
   Link ack = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledgement");
   log.debug("ack: " + ack);
   Assert.assertNotNull(ack);
   Link session = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consumer");
   log.debug("session: " + session);
   consumeNext = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledge-next");
   log.debug("consumeNext: " + consumeNext);
   ClientResponse ackRes = ack.request().formParameter("acknowledge", "true").post();
   ackRes.releaseConnection();
   Assert.assertEquals(204, ackRes.getStatus());
   consumeNext = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), ackRes, "acknowledge-next");

   log.debug("sending next...");
   res = sender.request().body("text/plain", Integer.toString(2)).post();
   res.releaseConnection();
   Assert.assertEquals(201, res.getStatus());

   log.debug(consumeNext);
   res = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
   res.releaseConnection();
   Assert.assertEquals(200, res.getStatus());
   ack = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledgement");
   log.debug("ack: " + ack);
   Assert.assertNotNull(ack);
   getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledge-next");
   log.debug("consumeNext: " + consumeNext);
   ackRes = ack.request().formParameter("acknowledge", "true").post();
   ackRes.releaseConnection();
   Assert.assertEquals(204, ackRes.getStatus());

   Assert.assertEquals(204, sub1.request().delete().getStatus());
}
 
Example 16
Source File: ClientAckTopicTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testSuccessFirst() throws Exception {
   ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/topics/testQueue"));

   ClientResponse<?> response = request.head();
   response.releaseConnection();
   Assert.assertEquals(200, response.getStatus());
   Link sender = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "create");
   log.debug("create: " + sender);

   Link subscriptions = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "pull-subscriptions");
   response = subscriptions.request().formParameter("autoAck", "false").formParameter("durable", "true").post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());
   Link sub1 = response.getLocationLink();
   Assert.assertNotNull(sub1);
   Link consumeNext = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), response, "acknowledge-next");
   log.debug("poller: " + consumeNext);

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

   log.debug("call ack next");
   res = consumeNext.request().post(String.class);
   res.releaseConnection();
   Assert.assertEquals(200, res.getStatus());
   Link ack = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledgement");
   log.debug("ack: " + ack);
   Assert.assertNotNull(ack);
   Link session = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "consumer");
   log.debug("session: " + session);
   consumeNext = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledge-next");
   log.debug("consumeNext: " + consumeNext);
   ClientResponse ackRes = ack.request().formParameter("acknowledge", "true").post();
   ackRes.releaseConnection();
   Assert.assertEquals(204, ackRes.getStatus());
   consumeNext = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), ackRes, "acknowledge-next");

   log.debug("sending next...");
   res = sender.request().body("text/plain", Integer.toString(2)).post();
   res.releaseConnection();
   Assert.assertEquals(201, res.getStatus());

   log.debug(consumeNext);
   res = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
   res.releaseConnection();
   Assert.assertEquals(200, res.getStatus());
   ack = getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledgement");
   log.debug("ack: " + ack);
   Assert.assertNotNull(ack);
   getLinkByTitle(manager.getTopicManager().getLinkStrategy(), res, "acknowledge-next");
   log.debug("consumeNext: " + consumeNext);
   ackRes = ack.request().formParameter("acknowledge", "true").post();
   ackRes.releaseConnection();
   Assert.assertEquals(204, ackRes.getStatus());

   Assert.assertEquals(204, sub1.request().delete().getStatus());
}
 
Example 17
Source File: SessionTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testTopicRestartFromAckSession() throws Exception {
   ClientRequest request = new ClientRequest(generateURL("/topics/testTopic"));

   ClientResponse<?> response = request.head();
   response.releaseConnection();
   Assert.assertEquals(200, response.getStatus());
   Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
   log.debug("create: " + sender);
   Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-subscriptions");
   log.debug("pull: " + consumers);
   response = Util.setAutoAck(consumers, false);
   Link session = response.getLocationLink();
   response = session.request().head();
   response.releaseConnection();
   Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledge-next");
   log.debug("consume-next: " + consumeNext);
   Link ack = null;

   response = sender.request().body("text/plain", Integer.toString(1)).post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());

   // consume
   response = consumeNext.request().header(Constants.WAIT_HEADER, "1").post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("1", response.getEntity(String.class));
   response.releaseConnection();
   response = session.request().get();
   response.releaseConnection();
   consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledge-next");
   Assert.assertNull(consumeNext);
   ack = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledgement");
   Assert.assertNotNull(ack);

   // acknowledge
   response = ack.request().formParameter("acknowledge", "true").post();
   response.releaseConnection();
   response = session.request().head();
   response.releaseConnection();
   consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledge-next");
   Assert.assertNotNull(consumeNext);
   ack = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledgement");
   Assert.assertNull(ack);

   response = sender.request().body("text/plain", Integer.toString(2)).post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());

   // consume
   response = consumeNext.request().header(Constants.WAIT_HEADER, "1").post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("2", response.getEntity(String.class));
   response.releaseConnection();
   response = session.request().get();
   response.releaseConnection();
   consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledge-next");
   Assert.assertNull(consumeNext);
   ack = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledgement");
   Assert.assertNotNull(ack);

   // acknowledge
   response = ack.request().formParameter("acknowledge", "true").post();
   response.releaseConnection();
   response = session.request().head();
   response.releaseConnection();
   consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledge-next");
   Assert.assertNotNull(consumeNext);
   ack = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledgement");
   Assert.assertNull(ack);

   response = session.request().delete();
   response.releaseConnection();
   Assert.assertEquals(204, response.getStatus());
}
 
Example 18
Source File: SessionTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testRestartFromAckSession() throws Exception {
   ClientRequest request = new ClientRequest(generateURL("/queues/testQueue"));

   ClientResponse<?> response = request.head();
   response.releaseConnection();
   Assert.assertEquals(200, response.getStatus());
   Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
   log.debug("create: " + sender);
   Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
   log.debug("pull: " + consumers);
   response = Util.setAutoAck(consumers, false);
   Link session = response.getLocationLink();
   response = session.request().head();
   response.releaseConnection();
   Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledge-next");
   log.debug("consume-next: " + consumeNext);
   Link ack = null;

   response = sender.request().body("text/plain", Integer.toString(1)).post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());

   // consume
   response = consumeNext.request().header(Constants.WAIT_HEADER, "3").post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("1", response.getEntity(String.class));
   response.releaseConnection();
   response = session.request().get();
   response.releaseConnection();
   consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledge-next");
   Assert.assertNull(consumeNext);
   ack = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledgement");
   Assert.assertNotNull(ack);

   // acknowledge
   response = ack.request().formParameter("acknowledge", "true").post();
   response.releaseConnection();
   response = session.request().head();
   response.releaseConnection();
   consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledge-next");
   Assert.assertNotNull(consumeNext);
   ack = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledgement");
   Assert.assertNull(ack);

   response = sender.request().body("text/plain", Integer.toString(2)).post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());

   // consume
   response = consumeNext.request().header(Constants.WAIT_HEADER, "1").post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("2", response.getEntity(String.class));
   response.releaseConnection();
   response = session.request().get();
   response.releaseConnection();
   consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledge-next");
   Assert.assertNull(consumeNext);
   ack = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledgement");
   Assert.assertNotNull(ack);

   // acknowledge
   response = ack.request().formParameter("acknowledge", "true").post();
   response.releaseConnection();
   response = session.request().head();
   response.releaseConnection();
   consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledge-next");
   Assert.assertNotNull(consumeNext);
   ack = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "acknowledgement");
   Assert.assertNull(ack);

   response = session.request().delete();
   response.releaseConnection();
   Assert.assertEquals(204, response.getStatus());
}
 
Example 19
Source File: SessionTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testTopicRestartFromAutoAckSession() throws Exception {
   ClientRequest request = new ClientRequest(generateURL("/topics/testTopic"));

   ClientResponse<?> response = request.head();
   response.releaseConnection();
   Assert.assertEquals(200, response.getStatus());
   Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
   log.debug("create: " + sender);
   Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-subscriptions");
   log.debug("pull: " + consumers);
   response = Util.setAutoAck(consumers, true);
   Link session = response.getLocationLink();
   response = session.request().head();
   response.releaseConnection();
   Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
   log.debug("consume-next: " + consumeNext);

   response = sender.request().body("text/plain", Integer.toString(1)).post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());

   response = consumeNext.request().post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("1", response.getEntity(String.class));
   response.releaseConnection();
   response = session.request().get();
   response.releaseConnection();
   consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");

   response = sender.request().body("text/plain", Integer.toString(2)).post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());

   response = consumeNext.request().post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("2", response.getEntity(String.class));
   response.releaseConnection();
   response = session.request().head();
   response.releaseConnection();
   consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");

   response = sender.request().body("text/plain", Integer.toString(3)).post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());

   response = consumeNext.request().post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("3", response.getEntity(String.class));
   response.releaseConnection();

   response = session.request().delete();
   response.releaseConnection();
   Assert.assertEquals(204, response.getStatus());
}
 
Example 20
Source File: SessionTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testRestartFromAutoAckSession() throws Exception {
   ClientRequest request = new ClientRequest(generateURL("/queues/testQueue"));

   ClientResponse<?> response = request.head();
   response.releaseConnection();
   Assert.assertEquals(200, response.getStatus());
   Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
   log.debug("create: " + sender);
   Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
   log.debug("pull: " + consumers);
   response = Util.setAutoAck(consumers, true);
   Link session = response.getLocationLink();
   response = session.request().head();
   response.releaseConnection();
   Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
   log.debug("consume-next: " + consumeNext);

   response = sender.request().body("text/plain", Integer.toString(1)).post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());

   response = consumeNext.request().post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("1", response.getEntity(String.class));
   response.releaseConnection();
   response = session.request().get();
   consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");

   response = sender.request().body("text/plain", Integer.toString(2)).post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());

   response = consumeNext.request().post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("2", response.getEntity(String.class));
   response.releaseConnection();
   response = session.request().head();
   consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");

   response = sender.request().body("text/plain", Integer.toString(3)).post();
   response.releaseConnection();
   Assert.assertEquals(201, response.getStatus());

   response = consumeNext.request().post(String.class);
   Assert.assertEquals(200, response.getStatus());
   Assert.assertEquals("3", response.getEntity(String.class));
   response.releaseConnection();

   response = session.request().delete();
   response.releaseConnection();
   Assert.assertEquals(204, response.getStatus());
}