コード例 #1
0
  public void testGetSubscriptions() throws Exception {
    Topic topic = new Topic();
    topic.setName("foo");
    topic.setNs("http://bar");
    topic.setPrefix("s");

    for (int i = 0; i < 10; i++) {
      Subscription subscription =
          new Subscription(
              UUID.randomUUID().toString() + "---" + i,
              "http://subscriber",
              "http://provider",
              topic,
              System.currentTimeMillis());

      registry.addSubscription(subscription);
    }
    List<Subscription> subscriptions = registry.getSubscriptions();
    assertNotNull(subscriptions);

    for (Subscription subscription : subscriptions) {
      System.out.println(subscription);
    }
    assertEquals(10, subscriptions.size());
  }
コード例 #2
0
  @Override
  public Subscription subscribe(String producer, QName topic, String subscriber)
      throws BootstrapFault {
    System.out.println(
        "Subscribe to topic " + topic + " on " + producer + " for subscriber " + subscriber);

    Topic t = new Topic();
    t.setName(topic.getLocalPart());
    t.setNs(topic.getNamespaceURI());
    t.setPrefix(topic.getPrefix());

    return new Subscription("1234565689", subscriber, producer, t, System.currentTimeMillis());
  }
コード例 #3
0
  public void testAdd() throws Exception {

    Topic topic = new Topic();
    topic.setName("foo");
    topic.setNs("http://bar");
    topic.setPrefix("s");
    Subscription subscription =
        new Subscription(
            UUID.randomUUID().toString(),
            "http://subscriber",
            "http://provider",
            topic,
            System.currentTimeMillis());
    registry.addSubscription(subscription);

    // TODO
    // get with mongo api...
  }
コード例 #4
0
  public void testRemoveFromProducer() throws Exception {

    Topic topic = new Topic();
    topic.setName("foo");
    topic.setNs("http://bar");
    topic.setPrefix("s");

    for (int i = 0; i < 3; i++) {
      Subscription subscription =
          new Subscription(
              UUID.randomUUID().toString(),
              "http://subscriber",
              "http://provider" + i,
              topic,
              System.currentTimeMillis());
      registry.addSubscription(subscription);
    }

    for (int i = 0; i < 10; i++) {
      Subscription subscription =
          new Subscription(
              UUID.randomUUID().toString(),
              "http://subscriber" + i,
              "http://provider",
              topic,
              System.currentTimeMillis());
      registry.addSubscription(subscription);
    }

    assertEquals(13, registry.getSubscriptions().size());
    registry.removeAllFromProvider("http://provider");
    assertEquals(3, registry.getSubscriptions().size());

    // TODO : Guava should have the stuff to handle that

    List<Subscription> remain = registry.getSubscriptions();
    for (Subscription subscription : remain) {
      if ("http://provider".equals(subscription.getProvider())) {
        fail("It remains a subscription in the collection!!!");
      }
    }
  }
コード例 #5
0
  public void testGetFilteredSubscriptions() throws Exception {
    Topic topic = new Topic();
    topic.setName("foo");
    topic.setNs("http://bar");
    topic.setPrefix("s");

    for (int i = 0; i < 20; i++) {
      Subscription subscription =
          new Subscription(
              UUID.randomUUID().toString(),
              "http://subscriber" + i,
              "http://provider",
              topic,
              System.currentTimeMillis());
      registry.addSubscription(subscription);
    }

    List<Subscription> filtered = registry.getSubscriptions(null);
    assertEquals(20, filtered.size());

    // get all from provider
    Subscription filter = new Subscription();
    filter.setProvider("http://provider");

    filtered = registry.getSubscriptions(filter);
    assertEquals(20, filtered.size());

    // get all from provider and consumer
    filter = new Subscription();
    filter.setProvider("http://provider");
    filter.setSubscriber("http://subscriber0");

    filtered = registry.getSubscriptions(filter);
    assertEquals(1, filtered.size());

    // get all from bad provider
    filter = new Subscription();
    filter.setProvider("http://fooooo");

    filtered = registry.getSubscriptions(filter);
    assertEquals(0, filtered.size());

    // get all from a provider and bad topic
    filter = new Subscription();
    filter.setProvider("http://provider");
    Topic t = new Topic();
    t.setName("123");
    filter.setTopic(t);

    filtered = registry.getSubscriptions(filter);
    assertEquals(0, filtered.size());

    // get all from topic
    filter = new Subscription();
    Topic tt = new Topic();
    tt.setName("foo");
    filter.setTopic(tt);

    filtered = registry.getSubscriptions(filter);
    assertEquals(20, filtered.size());

    topic = new Topic();
    topic.setName("fooo");
    topic.setNs("http://bar");
    topic.setPrefix("s");

    Subscription subscription =
        new Subscription(
            UUID.randomUUID().toString(),
            "http://subscriberFOO",
            "http://provider",
            topic,
            System.currentTimeMillis());
    registry.addSubscription(subscription);

    filter = new Subscription();
    Topic ttt = new Topic();
    ttt.setName("fooo");
    filter.setTopic(ttt);

    filtered = registry.getSubscriptions(filter);
    assertEquals(1, filtered.size());

    // filter on NS
    filter = new Subscription();
    Topic tttt = new Topic();
    tttt.setNs("http://bar");
    filter.setTopic(tttt);

    filtered = registry.getSubscriptions(filter);
    assertEquals(21, filtered.size());
  }