Package com.comcast.cns.model

Examples of com.comcast.cns.model.CNSRetryPolicy


            "}}";
    
     try {
       JSONObject json = new JSONObject(jsonStr);
       CNSTopicDeliveryPolicy subpolicy = new CNSTopicDeliveryPolicy(json);
       CNSRetryPolicy hrp = subpolicy.getDefaultHealthyRetryPolicy();
       assertTrue(hrp.getMinDelayTarget() == 21);
       assertTrue(hrp.getMaxDelayTarget() == 22);
       assertTrue(hrp.getNumRetries() == 77);
       assertTrue(hrp.getNumMaxDelayRetries() == 24);
       assertTrue(hrp.getNumMinDelayRetries() == 26);
       assertTrue(hrp.getNumNoDelayRetries() == 27);
       assertTrue(hrp.getBackOffFunction() == CnsBackoffFunction.linear);
      
       CNSRetryPolicy srp = subpolicy.getDefaultSicklyRetryPolicy();
       assertTrue(srp.getMinDelayTarget() == 10);
       assertTrue(srp.getMaxDelayTarget() == 11);
       assertTrue(srp.getNumRetries() == 42);
       assertTrue(srp.getNumMaxDelayRetries() == 14);
       assertTrue(srp.getNumMinDelayRetries() == 13);
       assertTrue(srp.getNumNoDelayRetries() == 15);
       assertTrue(srp.getBackOffFunction() == CnsBackoffFunction.geometric);
      
       CNSThrottlePolicy dtp = subpolicy.getDefaultThrottlePolicy();
       assertTrue(dtp != null);
       assertTrue(dtp.getMaxReceivesPerSecond() == 5);
       assertTrue(subpolicy.isDisableSubscriptionOverrides() == false);

      
       JSONObject json2 = new JSONObject(jsonStr2);
       CNSTopicDeliveryPolicy subpolicy2 = new CNSTopicDeliveryPolicy(json2);
       CNSRetryPolicy hrp2 = subpolicy2.getDefaultHealthyRetryPolicy();
       logger.debug("hrp2: " + hrp2.toString());
       assertTrue("minDelayTarget != 1", hrp2.getMinDelayTarget() == 1);
       assertTrue(hrp2.getMaxDelayTarget() == 2);
       assertTrue(hrp2.getNumRetries() == 17);
       assertTrue(hrp2.getNumMaxDelayRetries() == 4);
       assertTrue(hrp2.getNumMinDelayRetries() == 6);
       assertTrue(hrp2.getNumNoDelayRetries() == 7);
       assertTrue(hrp2.getBackOffFunction() == CnsBackoffFunction.linear);
       assertTrue(subpolicy2.getDefaultSicklyRetryPolicy() == null);
       CNSThrottlePolicy dtp2 = subpolicy2.getDefaultThrottlePolicy();
       assertTrue(dtp2 != null);
       assertTrue(dtp2.getMaxReceivesPerSecond() == null);
       assertTrue(subpolicy2.isDisableSubscriptionOverrides() == true);
      
       //Default constructor
       CNSTopicDeliveryPolicy subpolicy3 = new CNSTopicDeliveryPolicy();
       assertTrue(subpolicy3 != null);
       logger.debug("subpolicy3: " + subpolicy3.toString());
       CNSRetryPolicy hrp3 = subpolicy3.getDefaultHealthyRetryPolicy();
       assertTrue(hrp3.getMinDelayTarget() == 20);
       assertTrue(hrp3.getMaxDelayTarget() == 20);
       assertTrue(hrp3.getNumRetries() == 3);
       assertTrue(hrp3.getNumMaxDelayRetries() == 0);
       assertTrue(hrp3.getNumMinDelayRetries() == 0);
       assertTrue(hrp3.getNumNoDelayRetries() == 0);
       assertTrue(hrp3.getBackOffFunction() == CnsBackoffFunction.linear);
       assertTrue(subpolicy3.getDefaultSicklyRetryPolicy() == null);
       CNSThrottlePolicy dtp3 = subpolicy3.getDefaultThrottlePolicy();
       assertTrue(dtp3 != null);
       assertTrue(dtp3.getMaxReceivesPerSecond() == null);
       assertTrue(subpolicy3.isDisableSubscriptionOverrides() == false);
      
       //Default constructor
       JSONObject json3 = new JSONObject(jsonStr3);
       CNSTopicDeliveryPolicy subpolicy4 = new CNSTopicDeliveryPolicy(json3);
       assertTrue(subpolicy4 != null);
       logger.debug("subpolicy4: " + subpolicy4.toString());
       CNSRetryPolicy hrp4 = subpolicy4.getDefaultHealthyRetryPolicy();
       assertTrue(hrp4.getMinDelayTarget() == 20);
       assertTrue(hrp4.getMaxDelayTarget() == 20);
       assertTrue(hrp4.getNumRetries() == 3);
       assertTrue(hrp4.getNumMaxDelayRetries() == 0);
       assertTrue(hrp4.getNumMinDelayRetries() == 0);
       assertTrue(hrp4.getNumNoDelayRetries() == 0);
       assertTrue(hrp4.getBackOffFunction() == CnsBackoffFunction.linear);
       assertTrue(subpolicy4.getDefaultSicklyRetryPolicy() == null);
       CNSThrottlePolicy dtp4 = subpolicy4.getDefaultThrottlePolicy();
       assertTrue(dtp4 != null);
       assertTrue(dtp4.getMaxReceivesPerSecond() == null);
       assertTrue(subpolicy4.isDisableSubscriptionOverrides() == true);
View Full Code Here


       JSONObject json = new JSONObject(jsonStr);
       topicPolicy.update(json);
      
       assertTrue(topicPolicy != null);
       logger.debug("topicPolicy: " + topicPolicy.toString());
       CNSRetryPolicy hrp = topicPolicy.getDefaultHealthyRetryPolicy();
       assertTrue(hrp.getMinDelayTarget() == 21);
       assertTrue(hrp.getMaxDelayTarget() == 22);
       assertTrue(hrp.getNumRetries() == 77);
       assertTrue(hrp.getNumMaxDelayRetries() == 24);
       assertTrue(hrp.getNumMinDelayRetries() == 26);
       assertTrue(hrp.getNumNoDelayRetries() == 27);
       assertTrue(hrp.getBackOffFunction() == CnsBackoffFunction.linear);
       CNSRetryPolicy srp = topicPolicy.getDefaultSicklyRetryPolicy();
       assertTrue(srp.getMinDelayTarget() == 10);
       assertTrue(srp.getMaxDelayTarget() == 11);
       assertTrue(srp.getNumRetries() == 42);
       assertTrue(srp.getNumMaxDelayRetries() == 14);
       assertTrue(srp.getNumMinDelayRetries() == 13);
       assertTrue(srp.getNumNoDelayRetries() == 15);
       assertTrue(srp.getBackOffFunction() == CnsBackoffFunction.geometric);
       CNSThrottlePolicy dtp3 = topicPolicy.getDefaultThrottlePolicy();
       assertTrue(dtp3 != null);
       assertTrue(dtp3.getMaxReceivesPerSecond() == 5);
       assertTrue(topicPolicy.isDisableSubscriptionOverrides() == false);
      
View Full Code Here

      String maxDelayRetries = request.getParameter("maxDelayRetries");
      String maxReceiveRate = request.getParameter("maxReceiveRate");
      String backoffFunc = request.getParameter("backoffFunc");
      String ignoreOverride = request.getParameter("ignoreOverride");
      CNSTopicDeliveryPolicy deliveryPolicy = new CNSTopicDeliveryPolicy();
      CNSRetryPolicy defaultHealthyRetryPolicy = new CNSRetryPolicy();
     
      if (maxDelay.trim().length() > 0) {
        defaultHealthyRetryPolicy.setMaxDelayTarget(Integer.parseInt(maxDelay));
      }
     
      if (minDelay.trim().length() > 0) {
        defaultHealthyRetryPolicy.setMinDelayTarget(Integer.parseInt(minDelay));
      }
     
      if (maxDelayRetries.trim().length() > 0) {
        defaultHealthyRetryPolicy.setNumMaxDelayRetries(Integer.parseInt(maxDelayRetries));
      }
     
      if (minDelayRetries.trim().length() > 0) {
        defaultHealthyRetryPolicy.setNumMinDelayRetries(Integer.parseInt(minDelayRetries));
      }
     
      if (retriesNoDelay.trim().length() > 0) {
        defaultHealthyRetryPolicy.setNumNoDelayRetries(Integer.parseInt(retriesNoDelay));
      }
     
      if (numRetries.trim().length() > 0) {
        defaultHealthyRetryPolicy.setNumRetries(Integer.parseInt(numRetries));
      }
     
      defaultHealthyRetryPolicy.setBackOffFunction(CnsBackoffFunction.valueOf(backoffFunc));
      deliveryPolicy.setDefaultHealthyRetryPolicy(defaultHealthyRetryPolicy);
      deliveryPolicy.setDisableSubscriptionOverrides(ignoreOverride != null ? true: false);
      CNSThrottlePolicy defaultThrottle = new CNSThrottlePolicy();
     
      if (maxReceiveRate.trim().length() > 0) {
        defaultThrottle.setMaxReceivesPerSecond(Integer.parseInt(maxReceiveRate));
      }
     
      deliveryPolicy.setDefaultThrottlePolicy(defaultThrottle );
     
      try {

        SetTopicAttributesRequest setTopicAttributesRequest = new SetTopicAttributesRequest(topicArn, "DeliveryPolicy", deliveryPolicy.toString());
        sns.setTopicAttributes(setTopicAttributesRequest);
       
        logger.debug("event=set_delivery_policy topic_arn=" + topicArn + " userId= " + userId);

      } catch (Exception ex) {
        logger.error("event=set_delivery_policy user_id= " + userId, ex);
        throw new ServletException(ex);
      }
     
      out.println("<body onload='javascript:window.opener.location.reload();window.close();'>");
     
    } else {

      int numRetries=0, retriesNoDelay = 0, minDelay = 0, minDelayRetries = 0, maxDelay = 0, maxDelayRetries = 0, maxReceiveRate = 0;
      String retryBackoff = "linear";
      boolean ignoreOverride = false;
     
      if (topicArn != null) {
     
        Map<String, String> attributes = null;
        CNSTopicDeliveryPolicy deliveryPolicy = null;
       
        try {
          GetTopicAttributesRequest getTopicAttributesRequest = new GetTopicAttributesRequest(topicArn);
          GetTopicAttributesResult getTopicAttributesResult = sns.getTopicAttributes(getTopicAttributesRequest);
          attributes = getTopicAttributesResult.getAttributes();
          deliveryPolicy = new CNSTopicDeliveryPolicy(new JSONObject(attributes.get("DeliveryPolicy")));
        } catch (Exception ex) {
          logger.error("event=failed_to_get_attributes arn=" + topicArn, ex);
          throw new ServletException(ex);
        }

        if (deliveryPolicy != null) {
         
         
          CNSRetryPolicy healPol = deliveryPolicy.getDefaultHealthyRetryPolicy();
         
          if (healPol != null) {
            numRetries= healPol.getNumRetries();
            retriesNoDelay = healPol.getNumNoDelayRetries();
            minDelay = healPol.getMinDelayTarget();
            minDelayRetries = healPol.getNumMinDelayRetries();
            maxDelay = healPol.getMaxDelayTarget();
            maxDelayRetries = healPol.getNumMaxDelayRetries();
            retryBackoff = healPol.getBackOffFunction().toString();
          }
         
          CNSThrottlePolicy throttlePol = deliveryPolicy.getDefaultThrottlePolicy();
         
          if (throttlePol != null) {
View Full Code Here

   }
  
   @Test
   public void testGetterSetter() {
     CNSTopicDeliveryPolicy topicPolicy = new CNSTopicDeliveryPolicy();
     CNSRetryPolicy hrp = new CNSRetryPolicy();
     hrp.setNumRetries(19);
     CNSRetryPolicy srp = new CNSRetryPolicy();
     CNSThrottlePolicy dtp = new CNSThrottlePolicy();
    
     dtp.setMaxReceivesPerSecond(19);
    
     srp.setBackOffFunction(CnsBackoffFunction.geometric);
     topicPolicy.setDefaultHealthyRetryPolicy(hrp);
     topicPolicy.setDefaultSicklyRetryPolicy(srp);
     topicPolicy.setDefaultThrottlePolicy(dtp);
     topicPolicy.setDisableSubscriptionOverrides(true);
    
     CNSRetryPolicy nhrp = topicPolicy.getDefaultHealthyRetryPolicy();
     CNSRetryPolicy nsrp = topicPolicy.getDefaultSicklyRetryPolicy();
     CNSThrottlePolicy ndtp = topicPolicy.getDefaultThrottlePolicy();
     assertTrue("subscription Overrides not set", topicPolicy.isDisableSubscriptionOverrides());
     assertTrue("default healthy retry policy not set correctly", nhrp.getMinDelayTarget() == 20);
     assertTrue("default healthy retry policy not set correctly",nhrp.getMaxDelayTarget() == 20);
     assertTrue("default healthy retry policy not set correctly",nhrp.getNumRetries() == 19);
     assertTrue("default healthy retry policy not set correctly",nhrp.getNumMaxDelayRetries() == 0);
     assertTrue("default healthy retry policy not set correctly",nhrp.getNumMinDelayRetries() == 0);
     assertTrue("default healthy retry policy not set correctly",nhrp.getNumNoDelayRetries() == 0);
     assertTrue("default healthy retry policy not set correctly",nhrp.getBackOffFunction() == CnsBackoffFunction.linear);
    
     assertTrue("default sickly retry policy not set correctly", nsrp.getMinDelayTarget() == 20);
     assertTrue("default sickly retry policy not set correctly",nsrp.getMaxDelayTarget() == 20);
     assertTrue("default sickly retry policy not set correctly",nsrp.getNumRetries() == 3);
     assertTrue("default sickly retry policy not set correctly",nsrp.getNumMaxDelayRetries() == 0);
     assertTrue("default sickly retry policy not set correctly",nsrp.getNumMinDelayRetries() == 0);
     assertTrue("default sickly retry policy not set correctly",nsrp.getNumNoDelayRetries() == 0);
     assertTrue("default sickly retry policy not set correctly",nsrp.getBackOffFunction() == CnsBackoffFunction.geometric);
    
     assertTrue("defaultThrottlePolicy not set correctly", ndtp.getMaxReceivesPerSecond() == 19);
     try {
       JSONObject json = topicPolicy.toJSON();
       logger.debug("Json is:" + json.toString());
View Full Code Here

            if (subAttr == null) {
                throw new CMBException(CMBErrorCodes.InternalError, "Could not get subscription delivery policy for subscripiton " + subArn);
            }
           
            CNSSubscriptionDeliveryPolicy deliveryPolicy = subAttr.getEffectiveDeliveryPolicy();
            CNSRetryPolicy retryPolicy = deliveryPolicy.getHealthyRetryPolicy();

            logger.debug("retry_policy=" + retryPolicy + "sub_arn=" + subArn);
           
            while (numRetries < retryPolicy.getNumNoDelayRetries()) {
               
                logger.debug("event=immediate_retry num_retries=" + numRetries);
               
                // handle immediate retry phase
               
                try {
                    numRetries++;
                    runCommon();
                    return; //suceeded.
                } catch (Exception e) {
                    logger.debug("event=retry_failed phase=" + RetryPhase.ImmediateRetry.name() + " attempt=" + numRetries);
                }
            }                   
           
            // handle pre-backoff phase
           
            if (numRetries < retryPolicy.getNumMinDelayRetries() + retryPolicy.getNumNoDelayRetries()) {
               
                logger.debug("event=pre_backoff num_retries=" + numRetries + " mind_delay_target_secs=" + retryPolicy.getMinDelayTarget());
                numRetries++;
               
                CNSEndpointPublisherJobConsumer.submitForReDelivery(this, retryPolicy.getMinDelayTarget(), TimeUnit.SECONDS);
               
                // add 6 second buffer to avoid race condition (assuming we are enforcing a 5 sec http timeout)
               
                CQSHandler.changeMessageVisibility(queueUrl, receiptHandle, retryPolicy.getMinDelayTarget() + 6);                   
               
                return;
            }
           
            // if reached here, in the backoff phase
           
            if (numRetries < retryPolicy.getNumRetries() - (retryPolicy.getNumMinDelayRetries() + retryPolicy.getNumNoDelayRetries() + retryPolicy.getNumMaxDelayRetries())) {
               
                numRetries++;
               
                int delay = Util.getNextRetryDelay(numRetries - retryPolicy.getNumMinDelayRetries() - retryPolicy.getNumNoDelayRetries(),
                        retryPolicy.getNumRetries() - retryPolicy.getNumMinDelayRetries() - retryPolicy.getNumNoDelayRetries(),
                        retryPolicy.getMinDelayTarget(), retryPolicy.getMaxDelayTarget(), retryPolicy.getBackOffFunction());
               
                logger.debug("event=retry_notification phase=" + RetryPhase.Backoff.name() + " delay=" + delay + " attempt=" + numRetries + " backoff_function=" + retryPolicy.getBackOffFunction().name());
               
                CNSEndpointPublisherJobConsumer.submitForReDelivery(this, delay, TimeUnit.SECONDS);
               
                // add 6 second buffer to avoid race condition (assuming we are enforcing a 6 sec http timeout)

                CQSHandler.changeMessageVisibility(queueUrl, receiptHandle, delay + 6);
               
                return;
            }                   
           
            if (numRetries < retryPolicy.getNumRetries()) { //remainder must be post-backoff
               
                logger.debug("event=post_backoff max_delay_retries=" + maxDelayRetries + " max_delay_target=" + retryPolicy.getMaxDelayTarget());
                maxDelayRetries++;
               
                CNSEndpointPublisherJobConsumer.submitForReDelivery(this, retryPolicy.getMaxDelayTarget(), TimeUnit.SECONDS);
               
                // add 6 second buffer to avoid race condition (assuming we are enforcing a 5 sec http timeout)

                CQSHandler.changeMessageVisibility(queueUrl, receiptHandle, retryPolicy.getMaxDelayTarget() + 6);

                return;
            }
           
            logger.debug("event=retries_exhausted action=skip_message endpoint=" + endpoint + " message=" + message);
View Full Code Here

            if (subAttr == null) {
                throw new CMBException(CMBErrorCodes.InternalError, "Could not get subscription delivery policy for subscripiton " + subArn);
            }
           
            CNSSubscriptionDeliveryPolicy deliveryPolicy = subAttr.getEffectiveDeliveryPolicy();
            CNSRetryPolicy retryPolicy = deliveryPolicy.getHealthyRetryPolicy();

            logger.debug("retry_policy=" + retryPolicy + "sub_arn=" + subArn);
           
            while (numRetries < retryPolicy.getNumNoDelayRetries()) {
               
                logger.debug("event=immediate_retry num_retries=" + numRetries);
               
                // handle immediate retry phase
               
                try {
                    numRetries++;
                    runCommon(pub, protocol, endpoint, subArn, rawDelivery);
                    return; //suceeded.
                } catch (Exception e) {
                    logger.debug("event=retry_failed phase=" + RetryPhase.ImmediateRetry.name() + " attempt=" + numRetries);
                }
            }                   
           
            // handle pre-backoff phase
           
            if (numRetries < retryPolicy.getNumMinDelayRetries() + retryPolicy.getNumNoDelayRetries()) {
               
                logger.debug("event=pre_backoff num_retries=" + numRetries + " mind_delay_target_secs=" + retryPolicy.getMinDelayTarget());
                numRetries++;
               
                CNSEndpointPublisherJobConsumer.submitForReDelivery(this, retryPolicy.getMinDelayTarget(), TimeUnit.SECONDS);
               
                // add 6 second buffer to avoid race condition (assuming we are enforcing a 5 sec http timeout)
               
                CQSHandler.changeMessageVisibility(queueUrl, receiptHandle, retryPolicy.getMinDelayTarget() + 6);                   
               
                return;
            }
           
            // if reached here, in the backoff phase
           
            if (numRetries < retryPolicy.getNumRetries() - (retryPolicy.getNumMinDelayRetries() + retryPolicy.getNumNoDelayRetries() + retryPolicy.getNumMaxDelayRetries())) {
               
                numRetries++;
               
                int delay = Util.getNextRetryDelay(numRetries - retryPolicy.getNumMinDelayRetries() - retryPolicy.getNumNoDelayRetries(),
                        retryPolicy.getNumRetries() - retryPolicy.getNumMinDelayRetries() - retryPolicy.getNumNoDelayRetries(),
                        retryPolicy.getMinDelayTarget(), retryPolicy.getMaxDelayTarget(), retryPolicy.getBackOffFunction());
               
                logger.debug("event=retry_notification phase=" + RetryPhase.Backoff.name() + " delay=" + delay + " attempt=" + numRetries + " backoff_function=" + retryPolicy.getBackOffFunction().name());
               
                CNSEndpointPublisherJobConsumer.submitForReDelivery(this, delay, TimeUnit.SECONDS);
               
                // add 6 second buffer to avoid race condition (assuming we are enforcing a 6 sec http timeout)

                CQSHandler.changeMessageVisibility(queueUrl, receiptHandle, delay + 6);
               
                return;
            }                   
           
            if (numRetries < retryPolicy.getNumRetries()) { //remainder must be post-backoff
               
                logger.debug("event=post_backoff max_delay_retries=" + maxDelayRetries + " max_delay_target=" + retryPolicy.getMaxDelayTarget());
                maxDelayRetries++;
               
                CNSEndpointPublisherJobConsumer.submitForReDelivery(this, retryPolicy.getMaxDelayTarget(), TimeUnit.SECONDS);
               
                // add 6 second buffer to avoid race condition (assuming we are enforcing a 5 sec http timeout)

                CQSHandler.changeMessageVisibility(queueUrl, receiptHandle, retryPolicy.getMaxDelayTarget() + 6);

                return;
            }
           
            logger.debug("event=retries_exhausted action=skip_message endpoint=" + endpoint + " message=" + message);
View Full Code Here

      String maxDelayRetries = request.getParameter("maxDelayRetries");
      String maxReceiveRate = request.getParameter("maxReceiveRate");
      String backoffFunc = request.getParameter("backoffFunc");
     
      CNSSubscriptionDeliveryPolicy effectiveDeliveryPolicy = new CNSSubscriptionDeliveryPolicy();
      CNSRetryPolicy defaultHealthyRetryPolicy = new CNSRetryPolicy();
     
      if (maxDelay.trim().length() > 0) {
        defaultHealthyRetryPolicy.setMaxDelayTarget(Integer.parseInt(maxDelay));
      }
     
      if (minDelay.trim().length() > 0) {
        defaultHealthyRetryPolicy.setMinDelayTarget(Integer.parseInt(minDelay));
      }
     
      if (maxDelayRetries.trim().length() > 0) {
        defaultHealthyRetryPolicy.setNumMaxDelayRetries(Integer.parseInt(maxDelayRetries));
      }
     
      if (minDelayRetries.trim().length() > 0) {
        defaultHealthyRetryPolicy.setNumMinDelayRetries(Integer.parseInt(minDelayRetries));
      }
     
      if (retriesNoDelay.trim().length() > 0) {
        defaultHealthyRetryPolicy.setNumNoDelayRetries(Integer.parseInt(retriesNoDelay));
      }
     
      if (numRetries.trim().length() > 0) {
        defaultHealthyRetryPolicy.setNumRetries(Integer.parseInt(numRetries));
      }
     
      defaultHealthyRetryPolicy.setBackOffFunction(CnsBackoffFunction.valueOf(backoffFunc));
      effectiveDeliveryPolicy.setHealthyRetryPolicy(defaultHealthyRetryPolicy);
      CNSThrottlePolicy defaultThrottlePolicy = new CNSThrottlePolicy();
     
      if (maxReceiveRate.trim().length() > 0) {
        defaultThrottlePolicy.setMaxReceivesPerSecond(Integer.parseInt(maxReceiveRate));
      }
     
      effectiveDeliveryPolicy.setThrottlePolicy(defaultThrottlePolicy);
     
      try {

        SetSubscriptionAttributesRequest setSubscriptionAttributesRequest = new SetSubscriptionAttributesRequest(subArn, "DeliveryPolicy", effectiveDeliveryPolicy.toString());
        sns.setSubscriptionAttributes(setSubscriptionAttributesRequest);
       
        logger.debug("event=set_delivery_policy sub_arn=" + subArn + " user_id= " + userId);

      } catch (Exception ex) {
        logger.error("event=set_subscription_attribute sub_arn=" + subArn + " user_id= " + userId, ex);
        throw new ServletException(ex);
      }
     
      out.println("<body onload='javascript:window.opener.location.reload();window.close();'>");
     
    } else {
     
      int numRetries=0, retriesNoDelay = 0, minDelay = 0, minDelayRetries = 0, maxDelay = 0, maxDelayRetries = 0, maxReceiveRate = 0;
      String retryBackoff = "linear";
     
      if (subArn != null) {
       
        Map<String, String> attributes = null;
        CNSSubscriptionDeliveryPolicy deliveryPolicy = null;
       
        try {
          GetSubscriptionAttributesRequest getSubscriptionAttributesRequest = new GetSubscriptionAttributesRequest(subArn);
          GetSubscriptionAttributesResult getSubscriptionAttributesResult = sns.getSubscriptionAttributes(getSubscriptionAttributesRequest);
          attributes = getSubscriptionAttributesResult.getAttributes();
          deliveryPolicy = new CNSSubscriptionDeliveryPolicy(new JSONObject(attributes.get("DeliveryPolicy")));
        } catch (Exception ex) {
          logger.error("event=get_subscription_attributes sub_arn=" + subArn + " user_id= " + userId, ex);
          throw new ServletException(ex);
        }

        if (deliveryPolicy != null) {
       
          CNSRetryPolicy healthyRetryPolicy = deliveryPolicy.getHealthyRetryPolicy();
         
          if (healthyRetryPolicy != null) {
            numRetries= healthyRetryPolicy.getNumRetries();
            retriesNoDelay = healthyRetryPolicy.getNumNoDelayRetries();
            minDelay = healthyRetryPolicy.getMinDelayTarget();
            minDelayRetries = healthyRetryPolicy.getNumMinDelayRetries();
            maxDelay = healthyRetryPolicy.getMaxDelayTarget();
            maxDelayRetries = healthyRetryPolicy.getNumMaxDelayRetries();
            retryBackoff = healthyRetryPolicy.getBackOffFunction().toString();
          }
         
          CNSThrottlePolicy throttlePolicy = deliveryPolicy.getThrottlePolicy();
         
          if (throttlePolicy != null) {
View Full Code Here

    subscriptionAttributes.setSubscriptionArn(subscription.getArn());
    subscriptionAttributes.setTopicArn(subscription.getTopicArn());
    subscriptionAttributes.setUserId(user.getUserId());
   
    CNSSubscriptionDeliveryPolicy deliveryPolicy = new CNSSubscriptionDeliveryPolicy();
    CNSRetryPolicy healthyRetryPolicy = new CNSRetryPolicy();
    healthyRetryPolicy.setBackOffFunction(CnsBackoffFunction.arithmetic);
    healthyRetryPolicy.setMaxDelayTarget(21);
    healthyRetryPolicy.setMinDelayTarget(19);
    healthyRetryPolicy.setNumMaxDelayRetries(1);
    healthyRetryPolicy.setNumMinDelayRetries(0);
    healthyRetryPolicy.setNumNoDelayRetries(2);
    healthyRetryPolicy.setNumRetries(97);
    deliveryPolicy.setHealthyRetryPolicy(healthyRetryPolicy);       
    CNSThrottlePolicy throttlePolicy = new CNSThrottlePolicy();
    throttlePolicy.setMaxReceivesPerSecond(2);
    deliveryPolicy.setThrottlePolicy(throttlePolicy);
    subscriptionAttributes.setDeliveryPolicy(deliveryPolicy);       
View Full Code Here

                "\"maxDelayTarget\":20,"+
                "\"numRetries\":3" +             
                "}";
       
        JSONObject json = new JSONObject(retryPolicy);
        CNSRetryPolicy rpolicy = new CNSRetryPolicy(json);
        assertTrue(rpolicy.getMinDelayTarget() == 1);
        assertTrue(rpolicy.getMaxDelayTarget() == 2);
        assertTrue(rpolicy.getNumRetries() == 4);
        assertTrue(rpolicy.getNumMaxDelayRetries() == 4);
        assertTrue(rpolicy.getBackOffFunction() == CnsBackoffFunction.linear);
        logger.debug("retryPolicy2: " + retryPolicy2);
        logger.debug("rpolicy is: " + rpolicy.toString());
        assertTrue(rpolicy.toString().equals(retryPolicy2));
       
        JSONObject respJSON = rpolicy.toJSON();
        assertTrue(respJSON.has("backoffFunction"));
        assertTrue(respJSON.getString("backoffFunction").equals("linear"));
        assertTrue(respJSON.has("numMaxDelayRetries"));
        assertTrue(respJSON.getInt("numMaxDelayRetries") == 4);
        assertTrue(respJSON.has("numMinDelayRetries"));
        assertTrue(respJSON.getInt("numMinDelayRetries") == 0);
        assertTrue(respJSON.has("numRetries"));
        assertTrue(respJSON.getInt("numRetries") == 4);
        assertTrue(respJSON.has("minDelayTarget"));
        assertTrue(respJSON.getInt("minDelayTarget") == 1);
        assertTrue(respJSON.has("maxDelayTarget"));
        assertTrue(respJSON.getInt("maxDelayTarget") == 2);
       
        String fakeRetryPolicy = "{"+
              "\"backoffFunction\":\"superlinear\","+
              "\"numMaxDelayRetries\":4,"+
              "\"numRetries\":4,"+
                "\"minDelayTarget\":1,"+
                "\"maxDelayTarget\":2"+               
                  "}";
       
        String fakeRetryPolicy2 = "{"+            
              "\"numMinDelayRetries\":0," +
              "\"numMaxDelayRetries\":4,"+            
                "\"minDelayTarget\":1,"+
                "\"maxDelayTarget\":2,"+       
                "\"numNoDelayRetries\":0," +
                "\"backoffFunction\":\"linear\""+      
                  "}";
       
        String fakeRetryPolicy3 = "{"+
              "\"numMinDelayRetries\":0," +
              "\"numMaxDelayRetries\":4,"+
              "\"numRetries\":\"boo\","+
                "\"minDelayTarget\":1,"+
                "\"maxDelayTarget\":2,"+       
                "\"numNoDelayRetries\":0," +
                "\"backoffFunction\":\"linear\""+      
                  "}";
       
        String fakeRetryPolicy4 = "{"+
              "\"numMinDelayRetries\":0," +
              "\"numMaxDelayRetries\":4,"+
              "\"numRetries\":\"101\","+
                "\"minDelayTarget\":33,"+
                "\"maxDelayTarget\":34,"+       
                "\"numNoDelayRetries\":33," +
                "\"backoffFunction\":\"linear\""+      
                  "}";
       
        String fakeRetryPolicy5 = "{"+
              "\"numMinDelayRetries\":0," +
              "\"numMaxDelayRetries\":4,"+
              "\"numRetries\":\"100\","+
                "\"minDelayTarget\":33,"+
                "\"maxDelayTarget\":34,"+       
                "\"numNoDelayRetries\":-1," +
                "\"backoffFunction\":\"linear\""+      
                  "}";
       
        String fakeRetryPolicy6 = "{"+
              "\"numMinDelayRetries\":0," +
              "\"numMaxDelayRetries\":4,"+
              "\"numRetries\":\"100\","+
                "\"minDelayTarget\":33,"+
                "\"maxDelayTarget\":3601,"+       
                "\"numNoDelayRetries\":1," +
                "\"backoffFunction\":\"linear\""+      
                  "}";
       
        json = new JSONObject(fakeRetryPolicy);
        boolean exceptionOccured = false;
        try {
          new CNSRetryPolicy(json);
        } catch (Exception e) {
          if(e instanceof CNSModelConstructionException) {
            assertTrue(true);
            exceptionOccured = true;
            logger.debug("Exception 1:");
            logger.debug(((CNSModelConstructionException) e).getErrormessage());
          } else {
            assertFalse(true);
          }
        }
        assertTrue(exceptionOccured);
        exceptionOccured = false;
       
        json = new JSONObject(fakeRetryPolicy2);
        try {
          new CNSRetryPolicy(json);
        } catch (Exception e) {
          if(e instanceof CNSModelConstructionException) {
            assertTrue(true);
            exceptionOccured = true;
            logger.debug("Exception 2:");
            logger.debug(((CNSModelConstructionException) e).getErrormessage());
          } else {
            assertFalse(true);
          }
        }
        assertTrue(exceptionOccured);
        exceptionOccured = false;
       
        json = new JSONObject(fakeRetryPolicy3);
        try {
          CNSRetryPolicy rpolicy2 = new CNSRetryPolicy(json);
          logger.debug("rpolicy2 :" + rpolicy2.toString());
        } catch (Exception e) {
          if(e instanceof CNSModelConstructionException) {
            assertTrue(true);
            exceptionOccured = true;
            logger.debug("Exception 3:");
            logger.debug(((CNSModelConstructionException) e).getErrormessage());
          } else {
            assertFalse(true);
          }
        }
        assertTrue(exceptionOccured);
        exceptionOccured = false;
       
        json = new JSONObject(fakeRetryPolicy4);
        try {
          CNSRetryPolicy rpolicy2 = new CNSRetryPolicy(json);
          logger.debug("rpolicy2 :" + rpolicy2.toString());
        } catch (Exception e) {
          if(e instanceof CNSModelConstructionException) {
            assertTrue(true);
            exceptionOccured = true;
            logger.debug("Exception 4:");
            logger.debug(((CNSModelConstructionException) e).getErrormessage());
          } else {
            assertFalse(true);
          }
        }
        assertTrue(exceptionOccured);
        exceptionOccured = false;
       
       
        json = new JSONObject(fakeRetryPolicy5);
        try {
          CNSRetryPolicy rpolicy2 = new CNSRetryPolicy(json);
          logger.debug("rpolicy2 :" + rpolicy2.toString());
        } catch (Exception e) {
          if(e instanceof CNSModelConstructionException) {
            assertTrue(true);
            exceptionOccured = true;
            logger.debug("Exception 5:");
            logger.debug(((CNSModelConstructionException) e).getErrormessage());
          } else {
            assertFalse(true);
          }
        }
        assertTrue(exceptionOccured);
        exceptionOccured = false;
       
       
        json = new JSONObject(fakeRetryPolicy6);
        try {
          CNSRetryPolicy rpolicy2 = new CNSRetryPolicy(json);
          logger.debug("rpolicy2 :" + rpolicy2.toString());
        } catch (Exception e) {
          if(e instanceof CNSModelConstructionException) {
            assertTrue(true);
            exceptionOccured = true;
            logger.debug("Exception 6:");
            logger.debug(((CNSModelConstructionException) e).getErrormessage());
          } else {
            assertFalse(true);
          }
        }
        assertTrue(exceptionOccured);
        exceptionOccured = false;
       
        //Test default policy on empty json
        JSONObject json2 = new JSONObject(retryPolicy3);
        CNSRetryPolicy rpolicy2 = new CNSRetryPolicy(json2);
        assertTrue(rpolicy2.getMinDelayTarget() == 20);
        assertTrue(rpolicy2.getMaxDelayTarget() == 20);
        assertTrue(rpolicy2.getNumRetries() == 3);
        assertTrue(rpolicy2.getNumMaxDelayRetries() == 0);
        assertTrue(rpolicy2.getNumMinDelayRetries() == 0);
        assertTrue(rpolicy2.getBackOffFunction() == CnsBackoffFunction.linear);
       
       
        //Test default constructor
        CNSRetryPolicy rpolicy3 = new CNSRetryPolicy();
        assertTrue(rpolicy3.getMinDelayTarget() == 20);
        assertTrue(rpolicy3.getMaxDelayTarget() == 20);
        assertTrue(rpolicy3.getNumRetries() == 3);
        assertTrue(rpolicy3.getNumMaxDelayRetries() == 0);
        assertTrue(rpolicy3.getNumMinDelayRetries() == 0);
        assertTrue(rpolicy3.getBackOffFunction() == CnsBackoffFunction.linear);
       
        //Test multi variable constructor
        CNSRetryPolicy rpolicy4 = new CNSRetryPolicy(2, 4, 6, 8, 10, 12, CnsBackoffFunction.exponential);
        assertTrue(rpolicy4.getMinDelayTarget() == 2);
        assertTrue(rpolicy4.getMaxDelayTarget() == 4);
        assertTrue(rpolicy4.getNumRetries() == 6);
        assertTrue(rpolicy4.getNumMaxDelayRetries() == 8);
        assertTrue(rpolicy4.getNumMinDelayRetries() == 10);
        assertTrue(rpolicy4.getNumNoDelayRetries() == 12);
        assertTrue(rpolicy4.getBackOffFunction() == CnsBackoffFunction.exponential);
      } catch (Exception e) {
              logger.error("Exception occured", e);
              fail("exception: "+e);
      }
    }
View Full Code Here

                "\"maxDelayTarget\":20,"+
                "\"numRetries\":3" +             
                "}";
       
          JSONObject json = new JSONObject(retryPolicy);
        CNSRetryPolicy rpolicy = new CNSRetryPolicy(json);
        rpolicy.setBackOffFunction(CnsBackoffFunction.arithmetic);
        rpolicy.setMaxDelayTarget(6);
        rpolicy.setMinDelayTarget(7);
        rpolicy.setNumMaxDelayRetries(8);
        rpolicy.setNumMinDelayRetries(12);
        rpolicy.setNumNoDelayRetries(14);
        rpolicy.setNumRetries(9);
        assertTrue(rpolicy.getMinDelayTarget() == 7);
        assertTrue(rpolicy.getMaxDelayTarget() == 6);
        assertTrue(rpolicy.getNumRetries() == 9);
        assertTrue(rpolicy.getNumMaxDelayRetries() == 8);
        assertTrue(rpolicy.getNumMinDelayRetries() == 12);
        assertTrue(rpolicy.getNumNoDelayRetries() == 14);
        assertTrue(rpolicy.getBackOffFunction() == CnsBackoffFunction.arithmetic);
       
       
       
        //Test multi variable constructor
        CNSRetryPolicy rpolicy4 = new CNSRetryPolicy(2, 4, 6, 8, 10, 12, CnsBackoffFunction.exponential);
       
       
        //Test update
        String newRetryPolicy = "{"+
               "\"minDelayTarget\":\"9\","+
              "\"maxDelayTarget\":9," +
              "\"backoffFunction\":\"linear\","+
              "\"numMinDelayRetries\":12," +
              "\"numMaxDelayRetries\":12,"+
              "\"numNoDelayRetries\":14," +
              "\"numRetries\":38"+             
                  "}";
        //Test update2
        String newRetryPolicy2 = "{"+
              "\"minDelayTarget\":10,"+
              "\"maxDelayTarget\":10," +
              "\"numRetries\":5"+       
                  "}";
       
        //Test update3
        String newRetryPolicy3 = "{"+
              "\"minDelayTarget\":\"10\","+
              "\"maxDelayTarget\":10," +
              "\"numRetries\":5,"+       
              "\"backoffFunction\":\"crazygrowth\""+
                  "}";
       
        //Test update4
        String newRetryPolicy4 = "{"+
              "\"minDelayTarget\":\"10\","+
              "\"maxDelayTarget\":10," +      
              "\"backoffFunction\":\"linear\""+
                  "}";
       
        //Test update5
        String newRetryPolicy5 = "{"+
              "\"maxDelayTarget\":10," +  
              "\"numRetries\":5,"+   
              "\"backoffFunction\":\"linear\""+
                  "}";
       
        //Test update6
        String newRetryPolicy6 = "{"+
              "\"minDelayTarget\":\"10\","+
              "\"numRetries\":5,"+   
              "\"backoffFunction\":\"linear\""+
                  "}";
       
        //Test update7
        String newRetryPolicy7 = "{"+
              "\"minDelayTarget\":10,"+
              "\"maxDelayTarget\":9," +      
              "\"numRetries\":5,"+   
              "\"backoffFunction\":\"linear\""+
                  "}";
       
        //Test update8
        String newRetryPolicy8 = "{"+
              "\"minDelayTarget\":10,"+
              "\"maxDelayTarget\":10," +      
              "\"numRetries\":20,"
              "\"numMinDelayRetries\":12," +
              "\"numMaxDelayRetries\":12,"+
              "\"numNoDelayRetries\":14," +
              "\"backoffFunction\":\"linear\""+
                  "}";
       
        //Test update9
        String newRetryPolicy9 = "{"+
              "\"minDelayTarget\":10,"+
              "\"maxDelayTarget\":\"cookie\"," +      
              "\"numRetries\":20,"
              "\"numMinDelayRetries\":12," +
              "\"numMaxDelayRetries\":12,"+
              "\"numNoDelayRetries\":14," +
              "\"backoffFunction\":\"linear\""+
                  "}";
       

        //Test update10
        String newRetryPolicy10 = "{"+
              "\"minDelayTarget\":10,"+
              "\"maxDelayTarget\":\"11\"," +      
              "\"numRetries\":101,"
              "\"numMinDelayRetries\":33," +
              "\"numMaxDelayRetries\":34,"+
              "\"numNoDelayRetries\":34," +
              "\"backoffFunction\":\"linear\""+
                  "}";
       
        //Test update11
        String newRetryPolicy11 = "{"+
              "\"minDelayTarget\":10,"+
              "\"maxDelayTarget\":\"11\"," +      
              "\"numRetries\":100,"
              "\"numMinDelayRetries\":10," +
              "\"numMaxDelayRetries\":11,"+
              "\"numNoDelayRetries\":-1," +
              "\"backoffFunction\":\"linear\""+
                  "}";
       
        //Test update12
        String newRetryPolicy12 = "{"+
              "\"minDelayTarget\":10,"+
              "\"maxDelayTarget\":\"3601\"," +      
              "\"numRetries\":100,"
              "\"numMinDelayRetries\":10," +
              "\"numMaxDelayRetries\":11,"+
              "\"numNoDelayRetries\":0," +
              "\"backoffFunction\":\"linear\""+
                  "}";
       
        json = new JSONObject(newRetryPolicy);
        rpolicy4.update(json);
        assertTrue(rpolicy4.getMinDelayTarget() == 9);
        assertTrue(rpolicy4.getMaxDelayTarget() == 9);
        assertTrue(rpolicy4.getNumRetries() == 38);
        assertTrue(rpolicy4.getNumMinDelayRetries() == 12);
        assertTrue(rpolicy4.getNumMaxDelayRetries() == 12);
        assertTrue(rpolicy4.getNumNoDelayRetries() == 14);
        assertTrue(rpolicy4.getBackOffFunction() == CnsBackoffFunction.linear);
       
        json = new JSONObject(retryPolicy3);
        rpolicy4.update(json);
        assertTrue(rpolicy4.getMinDelayTarget() == 20);
        assertTrue(rpolicy4.getMaxDelayTarget() == 20);
        assertTrue(rpolicy4.getNumRetries() == 3);
        assertTrue(rpolicy4.getNumMaxDelayRetries() == 0);
        assertTrue(rpolicy4.getNumMinDelayRetries() == 0);
       
        json = new JSONObject(newRetryPolicy2);
        rpolicy4.update(json);
        assertTrue(rpolicy4.getMinDelayTarget() == 10);
        assertTrue(rpolicy4.getMaxDelayTarget() == 10);
        assertTrue(rpolicy4.getNumRetries() == 5);
        assertTrue(rpolicy4.getNumMaxDelayRetries() == 0);
        assertTrue(rpolicy4.getNumMinDelayRetries() == 0);
        assertTrue(rpolicy4.getNumNoDelayRetries() == 0);
        assertTrue(rpolicy4.getBackOffFunction() == CnsBackoffFunction.linear);
       
        json = new JSONObject(newRetryPolicy3);
        boolean exceptionOccured = false;
        try {
          rpolicy4.update(json);
        } catch (Exception e) {
          if(e instanceof CNSModelConstructionException) {
            assertTrue(true);
            exceptionOccured = true;
            logger.debug(((CNSModelConstructionException) e).getErrormessage());
          } else {
            assertFalse(true);
          }
        }
        assertTrue(exceptionOccured);
        exceptionOccured = false;
       
        json = new JSONObject(newRetryPolicy4);
        try {
          rpolicy4.update(json);
        } catch (Exception e) {
          if(e instanceof CNSModelConstructionException) {
            assertTrue(true);
            exceptionOccured = true;
            logger.debug(((CNSModelConstructionException) e).getErrormessage());
          } else {
            assertFalse(true);
          }
        }
        assertTrue(exceptionOccured);
        exceptionOccured = false;
       
        json = new JSONObject(newRetryPolicy5);
       
        try {
          rpolicy4.update(json);
        } catch (Exception e) {
          if(e instanceof CNSModelConstructionException) {
            assertTrue(true);
            exceptionOccured = true;
            logger.debug(((CNSModelConstructionException) e).getErrormessage());
          } else {
            assertFalse(true);
          }
        }
        assertTrue(exceptionOccured);
        exceptionOccured = false;
       
        json = new JSONObject(newRetryPolicy6)
        try {
          rpolicy4.update(json);
        } catch (Exception e) {
          if(e instanceof CNSModelConstructionException) {
            assertTrue(true);
            exceptionOccured = true;
            logger.debug(((CNSModelConstructionException) e).getErrormessage());
          } else {
            assertFalse(true);
          }
        }
        assertTrue(exceptionOccured);
        exceptionOccured = false;
       
        json = new JSONObject(newRetryPolicy7)
        try {
          rpolicy4.update(json);
        } catch (Exception e) {
          if(e instanceof CNSModelConstructionException) {
            assertTrue(true);
            exceptionOccured = true;
            logger.debug(((CNSModelConstructionException) e).getErrormessage());
          } else {
            assertFalse(true);
          }
        }
        assertTrue(exceptionOccured);
        exceptionOccured = false;
       
        json = new JSONObject(newRetryPolicy8)
        try {
          rpolicy4.update(json);
        } catch (Exception e) {
          if(e instanceof CNSModelConstructionException) {
            assertTrue(true);
            exceptionOccured = true;
            logger.debug(((CNSModelConstructionException) e).getErrormessage());
          } else {
            assertFalse(true);
          }
        }
        assertTrue(exceptionOccured);
        exceptionOccured = false;
       
        json = new JSONObject(newRetryPolicy9)
        try {
          rpolicy4.update(json);
        } catch (Exception e) {
          if(e instanceof CNSModelConstructionException) {
            assertTrue(true);
            exceptionOccured = true;
            logger.debug(((CNSModelConstructionException) e).getErrormessage());
          } else {
            assertFalse(true);
          }
        }
        assertTrue(exceptionOccured);
        exceptionOccured = false;
             
        json = new JSONObject(newRetryPolicy10)
        try {
          rpolicy4.update(json);
        } catch (Exception e) {
          if(e instanceof CNSModelConstructionException) {
            assertTrue(true);
            exceptionOccured = true;
            logger.debug(((CNSModelConstructionException) e).getErrormessage());
          } else {
            assertFalse(true);
          }
        }
        assertTrue(exceptionOccured);
        exceptionOccured = false;
       
        json = new JSONObject(newRetryPolicy11)
        try {
          rpolicy4.update(json);
        } catch (Exception e) {
          if(e instanceof CNSModelConstructionException) {
            assertTrue(true);
            exceptionOccured = true;
            logger.debug(((CNSModelConstructionException) e).getErrormessage());
          } else {
            assertFalse(true);
          }
        }
        assertTrue(exceptionOccured);
        exceptionOccured = false;
       
        json = new JSONObject(newRetryPolicy12)
        try {
          rpolicy4.update(json);
        } catch (Exception e) {
          if(e instanceof CNSModelConstructionException) {
            assertTrue(true);
            exceptionOccured = true;
            logger.debug(((CNSModelConstructionException) e).getErrormessage());
View Full Code Here

TOP

Related Classes of com.comcast.cns.model.CNSRetryPolicy

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.