From 61abfde6ec5907bee5666cfec6505916d90439a3 Mon Sep 17 00:00:00 2001 From: t-muskans <t-muskans@microsoft.com> Date: Mon, 31 May 2021 14:47:25 +0530 Subject: [PATCH] resolved comments --- .../indexer/azure/service/RetryPolicy.java | 20 ++++++++++++------- .../azure/service/RetryPolicyTest.java | 8 -------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/service/RetryPolicy.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/service/RetryPolicy.java index 0a329615b..720a5d801 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/service/RetryPolicy.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/service/RetryPolicy.java @@ -19,8 +19,12 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import io.github.resilience4j.retry.RetryConfig; +import lombok.Data; import lombok.extern.java.Log; import org.opengroup.osdu.core.common.model.http.HttpResponse; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import java.time.Duration; @@ -30,20 +34,22 @@ import java.time.Duration; * to resolve intermittent CosmosDb Not found issue */ @Log -@Service +@Component +@Data +@ConfigurationProperties(prefix = "azure.urlfetchservice.retry") public class RetryPolicy { - private final int ATTEMPTS = 3; - private final int WAIT_DURATION_IN_MILLIS = 1000; - private final String RECORD_NOT_FOUND = "notFound"; + private int attempts = 3; + private int waitDuration = 1000; + private String recordNotFound = "notFound"; /** * @return RetryConfig with 3 attempts and 1 sec wait time */ public RetryConfig retryConfig() { return RetryConfig.<HttpResponse>custom() - .maxAttempts(ATTEMPTS) - .waitDuration(Duration.ofMillis(WAIT_DURATION_IN_MILLIS)) + .maxAttempts(attempts) + .waitDuration(Duration.ofMillis(waitDuration)) .retryOnResult(response -> isRetryRequired(response)) .build(); } @@ -58,7 +64,7 @@ public class RetryPolicy { return false; } JsonObject jsonObject = new JsonParser().parse(response.getBody()).getAsJsonObject(); - JsonElement notFoundElement = (JsonArray) jsonObject.get(RECORD_NOT_FOUND); + JsonElement notFoundElement = (JsonArray) jsonObject.get(recordNotFound); if (notFoundElement == null || !notFoundElement.isJsonArray() || notFoundElement.getAsJsonArray().size() == 0 || diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/RetryPolicyTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/RetryPolicyTest.java index 412897693..65d48565c 100644 --- a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/RetryPolicyTest.java +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/RetryPolicyTest.java @@ -125,14 +125,6 @@ public class RetryPolicyTest { @InjectMocks private RetryPolicy retryPolicy; - @Test - public void number_of_Attempts_must_be_3() { - RetryConfig config = this.retryPolicy.retryConfig(); - int attempts = config.getMaxAttempts(); - int max_attempts = 3; - - assert (max_attempts == attempts); - } @Test public void retry_should_be_true_for_json1() { -- GitLab