From e73713ceb4ac275ee444280c3833352c7f370e87 Mon Sep 17 00:00:00 2001 From: NThakur4 <nthakur4@slb.com> Date: Tue, 8 Oct 2024 13:45:54 -0500 Subject: [PATCH] comments --- .../azure/config/RetryPolicyConfig.java | 23 ++++++++++++++----- .../service/UrlFetchServiceAzureImplTest.java | 20 ++++++++++++---- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/config/RetryPolicyConfig.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/config/RetryPolicyConfig.java index 01f9b8229..6cec10c92 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/config/RetryPolicyConfig.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/config/RetryPolicyConfig.java @@ -1,14 +1,25 @@ -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 { diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/UrlFetchServiceAzureImplTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/UrlFetchServiceAzureImplTest.java index 3a0ad4ad8..dfb8ae836 100644 --- a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/UrlFetchServiceAzureImplTest.java +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/UrlFetchServiceAzureImplTest.java @@ -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); -- GitLab