Skip to content
Snippets Groups Projects
Commit e73713ce authored by Neelesh Thakur's avatar Neelesh Thakur
Browse files

comments

parent 05b23092
No related branches found
No related tags found
1 merge request!819Change indexer service retry from 5 to 3 times
Pipeline #287927 failed
Pipeline: Indexer

#287930

    package org.opengroup.osdu.indexer.azure.config;
    // Copyright © SLB
    //
    // Licensed under the Apache License, Version 2.0 (the "License");
    // you may not use this file except in compliance with the License.
    // You may obtain a copy of the License at
    //
    // http://www.apache.org/licenses/LICENSE-2.0
    //
    // Unless required by applicable law or agreed to in writing, software
    // distributed under the License is distributed on an "AS IS" BASIS,
    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    // See the License for the specific language governing permissions and
    // limitations under the License.
    import org.springframework.boot.context.properties.ConfigurationProperties;
    import org.springframework.stereotype.Component;
    package org.opengroup.osdu.indexer.azure.config;
    import lombok.Builder;
    import lombok.Data;
    import org.springframework.boot.context.properties.ConfigurationProperties;
    import org.springframework.context.annotation.Configuration;
    @Data
    @Component
    @Builder
    @Configuration
    @ConfigurationProperties(prefix = "azure.storage.client.retry")
    public class RetryPolicyConfig {
    ......
    ......@@ -14,6 +14,7 @@
    package org.opengroup.osdu.indexer.azure.service;
    import org.junit.BeforeClass;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.mockito.InjectMocks;
    ......@@ -26,7 +27,9 @@ import org.opengroup.osdu.core.common.model.http.HttpResponse;
    import org.opengroup.osdu.indexer.azure.config.RetryPolicyConfig;
    import static org.mockito.ArgumentMatchers.any;
    import static org.mockito.Mockito.*;
    import static org.mockito.Mockito.atMost;
    import static org.mockito.Mockito.verify;
    import static org.mockito.Mockito.when;
    @RunWith(MockitoJUnitRunner.class)
    ......@@ -45,7 +48,7 @@ public class UrlFetchServiceAzureImplTest {
    @InjectMocks
    private UrlFetchServiceAzureImpl urlFetchServiceAzure;
    private RetryPolicyConfig retryPolicyConfig = RetryPolicyConfig.builder().MAX_ATTEMPTS(3).INITIAL_DELAY(1000).build();
    private static RetryPolicyConfig retryPolicyConfig;
    private static final String JSON1 = "{\n" +
    " \"records\": [\n" +
    ......@@ -96,11 +99,18 @@ public class UrlFetchServiceAzureImplTest {
    private static final String STORAGE_API_URL = "https://demo/api/storage/v2/schemas";
    private static final String SCHEMA_API_URL = "https://demo/api/schema-service/v1/schema/osdu:file:gom:1.0.0";
    @BeforeClass
    public static void setup() {
    retryPolicyConfig = new RetryPolicyConfig();
    retryPolicyConfig.setINITIAL_DELAY(1000);
    retryPolicyConfig.setMAX_ATTEMPTS(3);
    }
    @Test
    public void shouldRetry_ForJSON1_when_storageQueryRecordCallIsMade() throws Exception {
    response.setBody(JSON1);
    httpRequest.setUrl(BATCH_API_URL);
    when(this.retryPolicy.retryConfig(any())).thenReturn(new RetryPolicy(this.logger,this.retryPolicyConfig).retryConfig(response -> this.retryPolicy.batchRetryPolicy(response)));
    when(this.retryPolicy.retryConfig(any())).thenReturn(new RetryPolicy(this.logger, this.retryPolicyConfig).retryConfig(response -> this.retryPolicy.batchRetryPolicy(response)));
    when(urlFetchService.sendRequest(httpRequest)).thenReturn(response);
    urlFetchServiceAzure.sendRequest(httpRequest);
    ......@@ -112,7 +122,7 @@ public class UrlFetchServiceAzureImplTest {
    public void shouldRetry_ForJSON1_when_schemaRecordCallIsMade() throws Exception {
    response.setBody(JSON1);
    httpRequest.setUrl(SCHEMA_API_URL);
    when(this.retryPolicy.retryConfig(any())).thenReturn(new RetryPolicy(this.logger,this.retryPolicyConfig).retryConfig(response -> this.retryPolicy.schemaRetryPolicy(response)));
    when(this.retryPolicy.retryConfig(any())).thenReturn(new RetryPolicy(this.logger, this.retryPolicyConfig).retryConfig(response -> this.retryPolicy.schemaRetryPolicy(response)));
    when(urlFetchService.sendRequest(httpRequest)).thenReturn(response);
    urlFetchServiceAzure.sendRequest(httpRequest);
    ......@@ -124,7 +134,7 @@ public class UrlFetchServiceAzureImplTest {
    public void shouldRetry_when_anyOtherCallIsMade() throws Exception {
    response.setBody(JSON2);
    httpRequest.setUrl(STORAGE_API_URL);
    when(this.retryPolicy.retryConfig(any())).thenReturn(new RetryPolicy(this.logger,this.retryPolicyConfig).retryConfig(response -> this.retryPolicy.defaultRetryPolicy(response)));
    when(this.retryPolicy.retryConfig(any())).thenReturn(new RetryPolicy(this.logger, this.retryPolicyConfig).retryConfig(response -> this.retryPolicy.defaultRetryPolicy(response)));
    when(urlFetchService.sendRequest(httpRequest)).thenReturn(response);
    urlFetchServiceAzure.sendRequest(httpRequest);
    ......
    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