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;
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 ||
......
......@@ -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() {
......
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