Skip to content
Snippets Groups Projects
Commit 61abfde6 authored by Muskan Srivastava's avatar Muskan Srivastava
Browse files

resolved comments

parent c7a8ab57
No related branches found
No related tags found
1 merge request!147Enabling retry for indexer to storage service calls
Pipeline #43509 failed
...@@ -19,8 +19,12 @@ import com.google.gson.JsonElement; ...@@ -19,8 +19,12 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import io.github.resilience4j.retry.RetryConfig; import io.github.resilience4j.retry.RetryConfig;
import lombok.Data;
import lombok.extern.java.Log; import lombok.extern.java.Log;
import org.opengroup.osdu.core.common.model.http.HttpResponse; 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 org.springframework.stereotype.Service;
import java.time.Duration; import java.time.Duration;
...@@ -30,20 +34,22 @@ import java.time.Duration; ...@@ -30,20 +34,22 @@ import java.time.Duration;
* to resolve intermittent CosmosDb Not found issue * to resolve intermittent CosmosDb Not found issue
*/ */
@Log @Log
@Service @Component
@Data
@ConfigurationProperties(prefix = "azure.urlfetchservice.retry")
public class RetryPolicy { public class RetryPolicy {
private final int ATTEMPTS = 3; private int attempts = 3;
private final int WAIT_DURATION_IN_MILLIS = 1000; private int waitDuration = 1000;
private final String RECORD_NOT_FOUND = "notFound"; private String recordNotFound = "notFound";
/** /**
* @return RetryConfig with 3 attempts and 1 sec wait time * @return RetryConfig with 3 attempts and 1 sec wait time
*/ */
public RetryConfig retryConfig() { public RetryConfig retryConfig() {
return RetryConfig.<HttpResponse>custom() return RetryConfig.<HttpResponse>custom()
.maxAttempts(ATTEMPTS) .maxAttempts(attempts)
.waitDuration(Duration.ofMillis(WAIT_DURATION_IN_MILLIS)) .waitDuration(Duration.ofMillis(waitDuration))
.retryOnResult(response -> isRetryRequired(response)) .retryOnResult(response -> isRetryRequired(response))
.build(); .build();
} }
...@@ -58,7 +64,7 @@ public class RetryPolicy { ...@@ -58,7 +64,7 @@ public class RetryPolicy {
return false; return false;
} }
JsonObject jsonObject = new JsonParser().parse(response.getBody()).getAsJsonObject(); 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 || if (notFoundElement == null ||
!notFoundElement.isJsonArray() || !notFoundElement.isJsonArray() ||
notFoundElement.getAsJsonArray().size() == 0 || notFoundElement.getAsJsonArray().size() == 0 ||
......
...@@ -125,14 +125,6 @@ public class RetryPolicyTest { ...@@ -125,14 +125,6 @@ public class RetryPolicyTest {
@InjectMocks @InjectMocks
private RetryPolicy retryPolicy; 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 @Test
public void retry_should_be_true_for_json1() { public void retry_should_be_true_for_json1() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment