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

Updated test cases

parent 2653abd0
Pipeline #42369 failed with stage
in 10 seconds
......@@ -20,7 +20,7 @@
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-azure</artifactId>
<packaging>jar</packaging>
<version>0.9.0-SNAPSHOT</version>
<version>0.9.2-SNAPSHOT</version>
<name>core-lib-azure</name>
<properties>
......
......@@ -18,21 +18,27 @@ import com.azure.storage.common.policy.RequestRetryOptions;
import com.azure.storage.common.policy.RetryPolicyType;
import lombok.Getter;
import lombok.Setter;
import org.opengroup.osdu.azure.logging.CoreLoggerFactory;
import org.opengroup.osdu.core.common.logging.ILogger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import java.time.Duration;
import java.util.Collections;
/**
* Config for BlogStorage Retry.
*/
@Configuration
@ConfigurationProperties("azure.blobStore")
@ConfigurationProperties("azure.blobstore")
@Getter
@Setter
public class BlobStoreRetryConfiguration {
private static final String LOGGER_NAME = BlobStoreRetryConfiguration.class.getName();
private static final Logger LOGGER = LoggerFactory.getLogger(BlobStoreRetryConfiguration.class.getName());
@Autowired
private ILogger logger;
private int maxTries = -1;
private int tryTimeoutInSeconds = -1;
......@@ -76,7 +82,7 @@ public class BlobStoreRetryConfiguration {
// 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 maxTriesValue = valueConfigured(this.maxTries) ? this.maxTries : (Integer) null;
Integer maxTriesValue = valueConfigured(this.maxTries) ? this.maxTries : 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;
......@@ -84,9 +90,9 @@ public class BlobStoreRetryConfiguration {
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());
this.logger.info("BlobStoreRetryConfiguration", String.format("Retry Options on BlobStorage with RetryPolicyType = %s , maxTries = %d , tryTimeout = %d , retryDelay = %d , maxRetryDelay = %d , secondaryHost = %s.",
rpt.toString(), requestRetryOptions.getMaxTries(), requestRetryOptions.getTryTimeoutDuration().getSeconds(), requestRetryOptions.getRetryDelay().toMillis(), requestRetryOptions.getMaxRetryDelay().toMillis(), requestRetryOptions.getSecondaryHost()), Collections.emptyMap());
return requestRetryOptions;
}
......
......@@ -14,6 +14,7 @@ import org.opengroup.osdu.azure.di.BlobStoreRetryConfiguration;
import org.opengroup.osdu.azure.di.BlobStoreConfiguration;
import org.opengroup.osdu.azure.partition.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.PartitionServiceClient;
import org.opengroup.osdu.core.common.logging.ILogger;
import org.opengroup.osdu.core.common.partition.Property;
import static org.junit.jupiter.api.Assertions.*;
......@@ -31,8 +32,6 @@ public class BlobContainerClientFactoryImplTest {
private BlobContainerClientCache clientCache;
@Mock
private BlobStoreConfiguration configuration;
@Mock
private BlobStoreRetryConfiguration blobStoreRetryConfiguration;
@InjectMocks
private BlobContainerClientFactoryImpl sut;
......@@ -75,7 +74,6 @@ public class BlobContainerClientFactoryImplTest {
PartitionInfoAzure.builder()
.idConfig(Property.builder().value(PARTITION_ID).build())
.storageAccountNameConfig(Property.builder().value(ACCOUNT_NAME).build()).build());
when(this.blobStoreRetryConfiguration.getRequestRetryOptions()).thenReturn(new RequestRetryOptions());
BlobContainerClient containerClient = this.sut.getClient(PARTITION_ID, STORAGE_CONTAINER_NAME);
assertNotNull(containerClient);
}
......@@ -86,7 +84,6 @@ public class BlobContainerClientFactoryImplTest {
PartitionInfoAzure.builder()
.idConfig(Property.builder().value(PARTITION_ID).build())
.storageAccountNameConfig(Property.builder().value(ACCOUNT_NAME).build()).build());
when(this.blobStoreRetryConfiguration.getRequestRetryOptions()).thenReturn(new RequestRetryOptions());
BlobContainerClient containerClient = this.sut.getClient(PARTITION_ID, STORAGE_CONTAINER_NAME);
assertNotNull(containerClient);
......
......@@ -16,6 +16,7 @@ package org.opengroup.osdu.azure.blobstorage;
import com.azure.identity.DefaultAzureCredential;
import com.azure.storage.blob.BlobServiceClient;
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;
......@@ -24,8 +25,10 @@ import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opengroup.osdu.azure.cache.BlobServiceClientCache;
import org.opengroup.osdu.azure.di.BlobStoreConfiguration;
import org.opengroup.osdu.azure.di.BlobStoreRetryConfiguration;
import org.opengroup.osdu.azure.partition.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.PartitionServiceClient;
import org.opengroup.osdu.core.common.logging.ILogger;
import org.opengroup.osdu.core.common.partition.Property;
import static org.junit.jupiter.api.Assertions.*;
......@@ -43,6 +46,10 @@ public class BlobServiceClientFactoryImplTest {
private BlobServiceClientCache clientCache;
@Mock
private BlobStoreConfiguration configuration;
@Mock
private BlobStoreRetryConfiguration blobStoreRetryConfiguration;
@Mock
private ILogger logger;
@InjectMocks
private BlobServiceClientFactoryImpl sut;
......@@ -83,6 +90,7 @@ public class BlobServiceClientFactoryImplTest {
PartitionInfoAzure.builder()
.idConfig(Property.builder().value(PARTITION_ID).build())
.storageAccountNameConfig(Property.builder().value(ACCOUNT_NAME).build()).build());
when(this.blobStoreRetryConfiguration.getRequestRetryOptions()).thenReturn(new RequestRetryOptions());
BlobServiceClient serviceClient = this.sut.getBlobServiceClient(PARTITION_ID);
assertNotNull(serviceClient);
......@@ -94,6 +102,7 @@ public class BlobServiceClientFactoryImplTest {
PartitionInfoAzure.builder()
.idConfig(Property.builder().value(PARTITION_ID).build())
.storageAccountNameConfig(Property.builder().value(ACCOUNT_NAME).build()).build());
when(this.blobStoreRetryConfiguration.getRequestRetryOptions()).thenReturn(new RequestRetryOptions());
BlobServiceClient serviceClient = this.sut.getBlobServiceClient(PARTITION_ID);
assertNotNull(serviceClient);
......
package org.opengroup.osdu.azure.di;
import com.azure.cosmos.ThrottlingRetryOptions;
import com.azure.storage.common.policy.RequestRetryOptions;
import io.jsonwebtoken.lang.Assert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.commons.util.StringUtils;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opengroup.osdu.core.common.logging.ILogger;
import org.springframework.beans.factory.annotation.Autowired;
import java.time.Duration;
import static org.mockito.MockitoAnnotations.openMocks;
@ExtendWith(MockitoExtension.class)
public class BlobStoreRetryConfigurationTest {
@InjectMocks
private BlobStoreRetryConfiguration blobStoreRetryConfiguration;
@Mock
private ILogger logger;
RequestRetryOptions defaultRequestRetryOptions = new RequestRetryOptions();
@BeforeEach
void setUp() {
openMocks(this);
}
boolean compareStrings(String str1, String str2) {
if (str1 == null || str2 == null)
return str1 == str2;
return str1.equals(str2);
}
@Test
public void should_set_default_values() {
RequestRetryOptions requestRetryOptions = blobStoreRetryConfiguration.getRequestRetryOptions();
Assert.isTrue(requestRetryOptions.getMaxTries() == defaultRequestRetryOptions.getMaxTries());
Assert.isTrue(requestRetryOptions.getTryTimeoutDuration().equals(defaultRequestRetryOptions.getTryTimeoutDuration()));
Assert.isTrue(requestRetryOptions.getRetryDelay().equals(defaultRequestRetryOptions.getRetryDelay()));
Assert.isTrue(requestRetryOptions.getMaxRetryDelay().equals(defaultRequestRetryOptions.getMaxRetryDelay()));
Assert.isTrue(compareStrings(requestRetryOptions.getSecondaryHost(),defaultRequestRetryOptions.getSecondaryHost()));
}
@Test
public void should_set_maxtries() {
int maxTriesValue = 10;
blobStoreRetryConfiguration.setMaxTries(maxTriesValue);
RequestRetryOptions requestRetryOptions = blobStoreRetryConfiguration.getRequestRetryOptions();
Assert.isTrue(requestRetryOptions.getMaxTries() == maxTriesValue);
Assert.isTrue(requestRetryOptions.getTryTimeoutDuration().equals(defaultRequestRetryOptions.getTryTimeoutDuration()));
Assert.isTrue(requestRetryOptions.getRetryDelay().equals(defaultRequestRetryOptions.getRetryDelay()));
Assert.isTrue(requestRetryOptions.getMaxRetryDelay().equals(defaultRequestRetryOptions.getMaxRetryDelay()));
Assert.isTrue(compareStrings(requestRetryOptions.getSecondaryHost(),defaultRequestRetryOptions.getSecondaryHost()));
}
@Test
public void should_set_try_timeout() {
int tryTimeoutValue = 50;
blobStoreRetryConfiguration.setTryTimeoutInSeconds(tryTimeoutValue);
RequestRetryOptions requestRetryOptions = blobStoreRetryConfiguration.getRequestRetryOptions();
Assert.isTrue(requestRetryOptions.getMaxTries() == defaultRequestRetryOptions.getMaxTries());
Assert.isTrue(requestRetryOptions.getTryTimeoutDuration().equals(Duration.ofSeconds(tryTimeoutValue)));
Assert.isTrue(requestRetryOptions.getRetryDelay().equals(defaultRequestRetryOptions.getRetryDelay()));
Assert.isTrue(requestRetryOptions.getMaxRetryDelay().equals(defaultRequestRetryOptions.getMaxRetryDelay()));
Assert.isTrue(compareStrings(requestRetryOptions.getSecondaryHost(),defaultRequestRetryOptions.getSecondaryHost()));
}
@Test
public void should_set_RetryDelay() {
int retryDelayValue = 50;
int maxRetryDelayValue =100;
blobStoreRetryConfiguration.setRetryDelayInMs(retryDelayValue);
blobStoreRetryConfiguration.setMaxRetryDelayInMs(maxRetryDelayValue);
RequestRetryOptions requestRetryOptions = blobStoreRetryConfiguration.getRequestRetryOptions();
Assert.isTrue(requestRetryOptions.getMaxTries() == defaultRequestRetryOptions.getMaxTries());
Assert.isTrue(requestRetryOptions.getTryTimeoutDuration().equals(defaultRequestRetryOptions.getTryTimeoutDuration()));
Assert.isTrue(requestRetryOptions.getRetryDelay().equals(Duration.ofMillis(retryDelayValue)));
Assert.isTrue(requestRetryOptions.getMaxRetryDelay().equals(Duration.ofMillis(maxRetryDelayValue)));
Assert.isTrue(compareStrings(requestRetryOptions.getSecondaryHost(),defaultRequestRetryOptions.getSecondaryHost()));
}
}
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