Commit 0c1dd6cd authored by Ronak Sakhuja's avatar Ronak Sakhuja
Browse files

Updated tests

parent efbac6ca
Pipeline #42005 failed with stage
in 11 seconds
......@@ -24,12 +24,15 @@ import org.springframework.context.annotation.Configuration;
import java.time.Duration;
/**
* Config for BlogStorage Retry.
*/
@Configuration
@ConfigurationProperties("azure.blobstorage")
@Getter
@Setter
public class BlobStorageRetryConfiguration {
private final String LOGGER_NAME = BlobStorageRetryConfiguration.class.getName();
private static final String LOGGER_NAME = BlobStorageRetryConfiguration.class.getName();
private int maxTries = -1;
private int tryTimeoutInSeconds = -1;
......@@ -39,31 +42,31 @@ public class BlobStorageRetryConfiguration {
private String secondaryHost = "";
/**
* Checks whether an int variable value is configured or not
* Checks whether an int variable value is configured or not.
* @param val integer value to be checked
* @return true if value is configured in app.properties
*/
private boolean valueConfigured(int val) {
if(val != -1) {
private boolean valueConfigured(final int val) {
if (val != -1) {
return true;
}
return false;
}
/**
* Checks whether an string variable value is configured or not
* Checks whether an string variable value is configured or not.
* @param val string value to be checked
* @return true if value is configured in app.properties
*/
private boolean valueConfigured(String val) {
if(val==null || val.isEmpty()) {
private boolean valueConfigured(final String val) {
if (val == null || val.isEmpty()) {
return false;
}
return true;
}
/**
* Method to get RequestRetryOptions object based on configuration set in applicaiton.properties
* Method to get RequestRetryOptions object based on configuration set in applicaiton.properties.
* @return RequestRetryOption object with appropriate configurations.
*/
public RequestRetryOptions getRequestRetryOptions() {
......@@ -72,18 +75,18 @@ public class BlobStorageRetryConfiguration {
// Value has to be sent as null incase where they are not configured to use the default configurations (As specified in RequestRetryOptions.class)
// https://azure.github.io/azure-storage-java-async/com/microsoft/azure/storage/blob/RequestRetryOptions.html
RetryPolicyType rpt = valueConfigured(retryPolicyType)?RetryPolicyType.valueOf(retryPolicyType) : RetryPolicyType.EXPONENTIAL;
int maxTries = valueConfigured(this.maxTries) ? this.maxTries : (Integer) null;
Duration tryTimeout = valueConfigured(tryTimeoutInSeconds)?Duration.ofSeconds((long) tryTimeoutInSeconds) : null;
Duration retryDelay = valueConfigured(retryDelayInMs)?Duration.ofMillis(retryDelayInMs):null;
Duration maxRetryDelay = valueConfigured(maxRetryDelayInMs)?Duration.ofMillis(maxRetryDelayInMs): null;
String secondaryHost = valueConfigured(this.secondaryHost) ? this.secondaryHost : null;
RetryPolicyType rpt = valueConfigured(retryPolicyType) ? RetryPolicyType.valueOf(retryPolicyType) : RetryPolicyType.EXPONENTIAL;
int maxTriesValue = valueConfigured(this.maxTries) ? this.maxTries : (Integer) null;
Duration tryTimeout = valueConfigured(tryTimeoutInSeconds) ? Duration.ofSeconds((long) tryTimeoutInSeconds) : null;
Duration retryDelay = valueConfigured(retryDelayInMs) ? Duration.ofMillis(retryDelayInMs) : null;
Duration maxRetryDelay = valueConfigured(maxRetryDelayInMs) ? Duration.ofMillis(maxRetryDelayInMs) : null;
String secondaryHostValue = valueConfigured(this.secondaryHost) ? this.secondaryHost : null;
RequestRetryOptions requestRetryOptions = new RequestRetryOptions(rpt , maxTries, tryTimeout, retryDelay, maxRetryDelay, secondaryHost);
RequestRetryOptions requestRetryOptions = new RequestRetryOptions(rpt, maxTriesValue, tryTimeout, retryDelay, maxRetryDelay, secondaryHostValue);
CoreLoggerFactory.getInstance().getLogger(LOGGER_NAME)
.info("Retry Options on BlobStorage with RetryPolicyType = {} , maxTries = {} , tryTimeout = {} , retryDelay = {} , maxRetryDelay = {} , secondaryHost = {}.",
rpt.toString(),requestRetryOptions.getMaxTries(),requestRetryOptions.getTryTimeoutDuration().getSeconds(),requestRetryOptions.getRetryDelay().toMillis(),requestRetryOptions.getMaxRetryDelay().toMillis(),requestRetryOptions.getSecondaryHost());
rpt.toString(), requestRetryOptions.getMaxTries(), requestRetryOptions.getTryTimeoutDuration().getSeconds(), requestRetryOptions.getRetryDelay().toMillis(), requestRetryOptions.getMaxRetryDelay().toMillis(), requestRetryOptions.getSecondaryHost());
return requestRetryOptions;
}
......
......@@ -2,6 +2,7 @@ package org.opengroup.osdu.azure.blobstorage;
import com.azure.identity.DefaultAzureCredential;
import com.azure.storage.blob.BlobContainerClient;
import com.azure.storage.common.policy.RequestRetryOptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
......@@ -9,6 +10,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opengroup.osdu.azure.cache.BlobContainerClientCache;
import org.opengroup.osdu.azure.di.BlobStorageRetryConfiguration;
import org.opengroup.osdu.azure.di.BlobStoreConfiguration;
import org.opengroup.osdu.azure.partition.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.PartitionServiceClient;
......@@ -29,9 +31,12 @@ public class BlobContainerClientFactoryImplTest {
private BlobContainerClientCache clientCache;
@Mock
private BlobStoreConfiguration configuration;
@Mock
private BlobStorageRetryConfiguration blobStorageRetryConfiguration;
@InjectMocks
private BlobContainerClientFactoryImpl sut;
private static final String ACCOUNT_NAME = "testAccount";
private static final String PARTITION_ID = "dataPartitionId";
private static final String STORAGE_CONTAINER_NAME = "containerName";
......@@ -70,7 +75,7 @@ public class BlobContainerClientFactoryImplTest {
PartitionInfoAzure.builder()
.idConfig(Property.builder().value(PARTITION_ID).build())
.storageAccountNameConfig(Property.builder().value(ACCOUNT_NAME).build()).build());
when(this.blobStorageRetryConfiguration.getRequestRetryOptions()).thenReturn(new RequestRetryOptions());
BlobContainerClient containerClient = this.sut.getClient(PARTITION_ID, STORAGE_CONTAINER_NAME);
assertNotNull(containerClient);
}
......@@ -81,7 +86,7 @@ public class BlobContainerClientFactoryImplTest {
PartitionInfoAzure.builder()
.idConfig(Property.builder().value(PARTITION_ID).build())
.storageAccountNameConfig(Property.builder().value(ACCOUNT_NAME).build()).build());
when(this.blobStorageRetryConfiguration.getRequestRetryOptions()).thenReturn(new RequestRetryOptions());
BlobContainerClient containerClient = this.sut.getClient(PARTITION_ID, STORAGE_CONTAINER_NAME);
assertNotNull(containerClient);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment