"\"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());