Package com.comcast.cns.persistence

Examples of com.comcast.cns.persistence.ICNSSubscriptionPersistence


    String nextToken = null;
    int round = 0;

    List<CNSSubscription> confirmedSubscriptions = new ArrayList<CNSSubscription>();
    ICNSSubscriptionPersistence subscriptionHandler = new CNSSubscriptionCassandraPersistence();

    while (round == 0 || nextToken != null) {

      List<CNSSubscription> subscriptions = subscriptionHandler.listAllSubscriptionsByTopic(nextToken, topicArn, protocol);

      if (subscriptions.size() > 0) {
        nextToken = subscriptions.get(subscriptions.size()-1).getArn();
      } else {
        nextToken = null;
      }

      for (CNSSubscription s : subscriptions) {

        if (!s.isConfirmed()) {
          CNSSubscription confirmedSubscription = subscriptionHandler.confirmSubscription(false, s.getToken(), topicArn);
          confirmedSubscriptions.add(confirmedSubscription);
        }
      }

      round++;
View Full Code Here


            String userId2 = user2.getUserId();

            CNSTopic t = topicHandler.createTopic(topicName, topicName, userId2);
            topicArn = t.getArn();

            ICNSSubscriptionPersistence subscriptionHandler = new CNSSubscriptionCassandraPersistence();
            subscriptionHandler.subscribe(CMBTestingConstants.HTTP_ENDPOINT_BASE_URL + "recv/1234", CnsSubscriptionProtocol.http, t.getArn(), userId1);
           
        } catch (Exception ex) {
           
            fail(ex.toString());
View Full Code Here

            } catch (Exception e) { }
           
            t = topicHandler.createTopic(topicName, topicName, userId2);
            topicArn = t.getArn();

      ICNSSubscriptionPersistence subscriptionHandler = new CNSSubscriptionCassandraPersistence();
      long beforeSubscribeCount = subscriptionHandler.getCountSubscription(t.getArn(), "subscriptionPending");

      CNSSubscription s = subscriptionHandler.subscribe(CMBTestingConstants.HTTP_ENDPOINT_BASE_URL + "recv/1234", CnsSubscriptionProtocol.http, t.getArn(), userId1);

      long afterSubscribeCount = subscriptionHandler.getCountSubscription(t.getArn(), "subscriptionPending");
     
      // check default delivery policy on topic1
     
      CNSSubscriptionAttributes attributes = attributeHandler.getSubscriptionAttributes(s.getArn());
     
      assertTrue("Expected 3 retries in healthy policy, instead found " + attributes.getEffectiveDeliveryPolicy().getHealthyRetryPolicy().getNumRetries(), attributes.getEffectiveDeliveryPolicy().getHealthyRetryPolicy().getNumRetries() == 3);
     
      List<CNSSubscription> l = subscriptionHandler.listSubscriptions(null, null, userId1);

      assertTrue("Could not verify PendingConfirmation state", l.size() == 1 && l.get(0).getArn().equals("PendingConfirmation"));

      s = subscriptionHandler.confirmSubscription(false, s.getToken(), t.getArn());

      l = subscriptionHandler.listSubscriptions(null, null, userId1);

      assertTrue("Expected 1 subscription, instead found " + l.size(), l.size() == 1);

      l = subscriptionHandler.listSubscriptionsByTopic(null, t.getArn(), null);

      assertTrue("Expected 1 subscription, instead found " + l.size(), l.size() == 1);

      l = subscriptionHandler.listSubscriptionsByTopic(null, t.getArn(), CnsSubscriptionProtocol.http);

      assertTrue("Expected 1 subscription, instead found " + l.size(), l.size() == 1);
     
      l = subscriptionHandler.listSubscriptionsByTopic(null, t.getArn(), CnsSubscriptionProtocol.email);

      assertTrue("Expected 0 subscription, instead found " + l.size(), l.size() == 0);
     
      assertTrue("Wrong number of subscribers", afterSubscribeCount == beforeSubscribeCount+1);

      try {
        l = subscriptionHandler.listSubscriptionsByTopic(null, com.comcast.cns.util.Util.generateCnsTopicArn("xyz", "east", userId1), null);
      } catch (CMBException ex) {
        assertTrue(ex.getCMBCode().equals(CMBErrorCodes.NotFound.getCMBCode()));
      }
     
      CNSSubscription sdup = subscriptionHandler.getSubscription(s.getArn());
     
      assertTrue("Subscriptions are not identical: " + s + "; " + sdup, s.equals(sdup));
     
      long beforeUnsubscribeCount = subscriptionHandler.getCountSubscription(t.getArn(), "subscriptionDeleted");

      subscriptionHandler.unsubscribe(s.getArn());
     
      long afterUnsubscribeCount = subscriptionHandler.getCountSubscription(t.getArn(), "subscriptionDeleted");

      l = subscriptionHandler.listSubscriptions(null, null, userId1);

      assertTrue("Expected 0 subscription, instead found " + l.size(), l.size() == 0);
     
      assertTrue("Wrong number of subscribers", afterUnsubscribeCount == beforeUnsubscribeCount + 1);
View Full Code Here

      String topicName = "T" + rand.nextLong();
      CNSTopic t = topicHandler.createTopic(topicName, topicName, userId1);
      topicArn = t.getArn();

      ICNSSubscriptionPersistence subscriptionHandler = new CNSSubscriptionCassandraPersistence();

      for (int i=1; i<=96; i++) {
        subscriptionHandler.subscribe(CMBTestingConstants.HTTP_ENDPOINT_BASE_URL + "recv/" + i, CnsSubscriptionProtocol.http, t.getArn(), userId1);
      }
     
      CNSTestingUtils.confirmPendingSubscriptionsByTopic(t.getArn(), userId1, CnsSubscriptionProtocol.http);
     
      for (int i=97; i<=103; i++) {
     
        subscriptionHandler.subscribe(CMBTestingConstants.HTTP_ENDPOINT_BASE_URL + "recv/" + i, CnsSubscriptionProtocol.http, t.getArn(), userId1);
        CNSTestingUtils.confirmPendingSubscriptionsByTopic(t.getArn(), userId1, CnsSubscriptionProtocol.http);
        Set<String> keys = new TreeSet<String>();
       
        List<CNSSubscription> l = subscriptionHandler.listSubscriptions(null, null, userId1);
        List<CNSSubscription> a = new ArrayList<CNSSubscription>();
       
        while (l.size() > 0) {
         
          a.addAll(l);
         
          for (CNSSubscription scr : l) {
           
            if (keys.contains(scr.getArn())) {
              fail("Duplicate subscription arn " + scr);
            } else {
              keys.add(scr.getArn());
            }
          }
         
          l = subscriptionHandler.listSubscriptions(l.get(l.size()-1).getArn(), null, userId1);
        }
       
        assertTrue("Wrong number of subscriptions: " + a.size() + " versus " + i, a.size() == i);
       
        logger.info(i + " subscriptions ok");
View Full Code Here

            String topicName = "T" + rand.nextLong();
            CNSTopic t = topicHandler.createTopic(topicName, topicName, userId1);
            topicArn = t.getArn();

            ICNSSubscriptionPersistence subscriptionHandler = new CNSSubscriptionCassandraPersistence();

            for (int i=1; i<=200; i++) {
                subscriptionHandler.subscribe(CMBTestingConstants.HTTP_ENDPOINT_BASE_URL + "recv/" + i, CnsSubscriptionProtocol.http, t.getArn(), userId1);
            }
           
            CNSTestingUtils.confirmPendingSubscriptionsByTopic(t.getArn(), userId1, CnsSubscriptionProtocol.http);
            ts1 = System.currentTimeMillis();
            List<CNSSubscription> l = subscriptionHandler.listSubscriptionsByTopic(null, t.getArn(), null, 1000);
            int totalSize = 0;
       
            while (totalSize != 200 && l.size() > 0) {
                totalSize += l.size();
                logger.info("Number of subscriptions is " + totalSize);
                l = subscriptionHandler.listSubscriptionsByTopic(l.get(l.size() - 1).getArn(), t.getArn(), null, 1000);
            }
           
            if (totalSize != 200) {
                fail("Expected 200 subscriptions, instead found " + totalSize);
            }
View Full Code Here

TOP

Related Classes of com.comcast.cns.persistence.ICNSSubscriptionPersistence

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.