@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();
    }
  }
  @Test
  public void testSuccessFirst() throws Exception {
    try {
      String testName = "testSuccessFirst";
      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.getTopicManager().getLinkStrategy(), response, "create");
      System.out.println("create: " + sender);
      Link pushSubscriptions =
          MessageTestBase.getLinkByTitle(
              manager.getTopicManager().getLinkStrategy(), response, "push-subscriptions");
      System.out.println("push subscriptions: " + pushSubscriptions);

      String sub1 = generateURL("/subscribers/1");
      String sub2 = generateURL("/subscribers/2");

      PushTopicRegistration reg = new PushTopicRegistration();
      reg.setDurable(true);
      XmlLink target = new XmlLink();
      target.setHref(sub1);
      reg.setTarget(target);
      response = pushSubscriptions.request().body("application/xml", reg).post();
      response.releaseConnection();
      Assert.assertEquals(201, response.getStatus());

      reg = new PushTopicRegistration();
      reg.setDurable(true);
      target = new XmlLink();
      target.setHref(sub2);
      reg.setTarget(target);
      response = pushSubscriptions.request().body("application/xml", reg).post();
      response.releaseConnection();
      Assert.assertEquals(201, response.getStatus());

      shutdown();
      startup();
      deployTopic(testName);

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

      Receiver.latch.await(1, TimeUnit.SECONDS);

      Assert.assertEquals("1", Receiver.subscriber1);
      Assert.assertEquals("1", Receiver.subscriber2);

      manager.getTopicManager().getPushStore().removeAll();
    } finally {
      shutdown();
    }
  }
Esempio n. 3
0
  public static void main(String[] args) throws Exception {
    // get the push consumers factory resource
    ClientRequest request = new ClientRequest("http://localhost:9095/queues/jms.queue.orders");
    ClientResponse res = request.head();
    Link pushConsumers = res.getHeaderAsLink("msg-push-consumers");

    // next create the XML document that represents the registration
    // Really, just create a link with the shipping URL and the type you want posted
    PushRegistration reg = new PushRegistration();
    BasicAuth authType = new BasicAuth();
    authType.setUsername("guest");
    authType.setPassword("guest");
    Authentication auth = new Authentication();
    auth.setType(authType);
    reg.setAuthenticationMechanism(auth);
    XmlLink target = new XmlLink();
    target.setHref("http://localhost:9095/queues/jms.queue.shipping");
    target.setType("application/xml");
    target.setRelationship("destination");
    reg.setTarget(target);

    res = pushConsumers.request().body("application/xml", reg).post();
    System.out.println(
        "Create push registration.  Resource URL: " + res.getLocationLink().getHref());
  }
  @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();
  }
Esempio n. 5
0
  @Test
  public void testPull() throws Exception {
    ClientRequest request = new ClientRequest(generateURL("/topics/" + topicName));

    ClientResponse<?> response = request.head();
    response.releaseConnection();
    Assert.assertEquals(200, response.getStatus());
    Link consumers =
        MessageTestBase.getLinkByTitle(
            manager.getQueueManager().getLinkStrategy(), response, "pull-subscriptions");
    System.out.println("pull: " + consumers);
    response =
        consumers
            .request()
            .formParameter("autoAck", "true")
            .formParameter("selector", "MyTag = '1'")
            .post();
    response.releaseConnection();

    Link consumeOne =
        MessageTestBase.getLinkByTitle(
            manager.getQueueManager().getLinkStrategy(), response, "consume-next");
    System.out.println("consumeOne: " + consumeOne);
    response =
        consumers
            .request()
            .formParameter("autoAck", "true")
            .formParameter("selector", "MyTag = '2'")
            .post();
    response.releaseConnection();
    Link consumeTwo =
        MessageTestBase.getLinkByTitle(
            manager.getQueueManager().getLinkStrategy(), response, "consume-next");
    System.out.println("consumeTwo: " + consumeTwo);

    // test that Accept header is used to set content-type
    {
      Order order = new Order();
      order.setName("1");
      order.setAmount("$5.00");
      publish(topicName, order, null, "1");
      order.setName("2");
      publish(topicName, order, null, "2");
      order.setName("3");
      publish(topicName, order, null, "2");
      order.setName("4");
      publish(topicName, order, null, "1");
      order.setName("5");
      publish(topicName, order, null, "1");
      order.setName("6");
      publish(topicName, order, null, "1");

      {
        order.setName("1");
        consumeOne = consumeOrder(order, consumeOne);
        order.setName("2");
        consumeTwo = consumeOrder(order, consumeTwo);
        order.setName("3");
        consumeTwo = consumeOrder(order, consumeTwo);
        order.setName("4");
        consumeOne = consumeOrder(order, consumeOne);
        order.setName("5");
        consumeOne = consumeOrder(order, consumeOne);
        order.setName("6");
        consumeOne = consumeOrder(order, consumeOne);
      }
    }
  }
Esempio n. 6
0
  @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 =
        MessageTestBase.getLinkByTitle(
            manager.getQueueManager().getLinkStrategy(), response, "push-subscriptions");
    System.out.println("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.getLocation();

    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.getLocation();

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

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

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

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

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

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

    response = oneSubscription.request().delete();
    response.releaseConnection();
    response = twoSubscription.request().delete();
    response.releaseConnection();
  }
  @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);
    System.out.println("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);
    System.out.println("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());
  }