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 @@ ...@@ -20,7 +20,7 @@
<groupId>org.opengroup.osdu</groupId> <groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-azure</artifactId> <artifactId>core-lib-azure</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>0.9.0-SNAPSHOT</version> <version>0.9.2-SNAPSHOT</version>
<name>core-lib-azure</name> <name>core-lib-azure</name>
<properties> <properties>
......
...@@ -18,21 +18,27 @@ import com.azure.storage.common.policy.RequestRetryOptions; ...@@ -18,21 +18,27 @@ import com.azure.storage.common.policy.RequestRetryOptions;
import com.azure.storage.common.policy.RetryPolicyType; import com.azure.storage.common.policy.RetryPolicyType;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; 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.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import java.time.Duration; import java.time.Duration;
import java.util.Collections;
/** /**
* Config for BlogStorage Retry. * Config for BlogStorage Retry.
*/ */
@Configuration @Configuration
@ConfigurationProperties("azure.blobStore") @ConfigurationProperties("azure.blobstore")
@Getter @Getter
@Setter @Setter
public class BlobStoreRetryConfiguration { 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 maxTries = -1;
private int tryTimeoutInSeconds = -1; private int tryTimeoutInSeconds = -1;
...@@ -76,7 +82,7 @@ public class BlobStoreRetryConfiguration { ...@@ -76,7 +82,7 @@ public class BlobStoreRetryConfiguration {
// https://azure.github.io/azure-storage-java-async/com/microsoft/azure/storage/blob/RequestRetryOptions.html // https://azure.github.io/azure-storage-java-async/com/microsoft/azure/storage/blob/RequestRetryOptions.html
RetryPolicyType rpt = valueConfigured(retryPolicyType) ? RetryPolicyType.valueOf(retryPolicyType) : RetryPolicyType.EXPONENTIAL; 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 tryTimeout = valueConfigured(tryTimeoutInSeconds) ? Duration.ofSeconds((long) tryTimeoutInSeconds) : null;
Duration retryDelay = valueConfigured(retryDelayInMs) ? Duration.ofMillis(retryDelayInMs) : null; Duration retryDelay = valueConfigured(retryDelayInMs) ? Duration.ofMillis(retryDelayInMs) : null;
Duration maxRetryDelay = valueConfigured(maxRetryDelayInMs) ? Duration.ofMillis(maxRetryDelayInMs) : null; Duration maxRetryDelay = valueConfigured(maxRetryDelayInMs) ? Duration.ofMillis(maxRetryDelayInMs) : null;
...@@ -84,9 +90,9 @@ public class BlobStoreRetryConfiguration { ...@@ -84,9 +90,9 @@ public class BlobStoreRetryConfiguration {
RequestRetryOptions requestRetryOptions = new RequestRetryOptions(rpt, maxTriesValue, tryTimeout, retryDelay, maxRetryDelay, secondaryHostValue); 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 = {}.", 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()); rpt.toString(), requestRetryOptions.getMaxTries(), requestRetryOptions.getTryTimeoutDuration().getSeconds(), requestRetryOptions.getRetryDelay().toMillis(), requestRetryOptions.getMaxRetryDelay().toMillis(), requestRetryOptions.getSecondaryHost()), Collections.emptyMap());
return requestRetryOptions; return requestRetryOptions;
} }
......
...@@ -14,6 +14,7 @@ import org.opengroup.osdu.azure.di.BlobStoreRetryConfiguration; ...@@ -14,6 +14,7 @@ import org.opengroup.osdu.azure.di.BlobStoreRetryConfiguration;
import org.opengroup.osdu.azure.di.BlobStoreConfiguration; import org.opengroup.osdu.azure.di.BlobStoreConfiguration;
import org.opengroup.osdu.azure.partition.PartitionInfoAzure; import org.opengroup.osdu.azure.partition.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.PartitionServiceClient; import org.opengroup.osdu.azure.partition.PartitionServiceClient;
import org.opengroup.osdu.core.common.logging.ILogger;
import org.opengroup.osdu.core.common.partition.Property; import org.opengroup.osdu.core.common.partition.Property;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
...@@ -31,8 +32,6 @@ public class BlobContainerClientFactoryImplTest { ...@@ -31,8 +32,6 @@ public class BlobContainerClientFactoryImplTest {
private BlobContainerClientCache clientCache; private BlobContainerClientCache clientCache;
@Mock @Mock
private BlobStoreConfiguration configuration; private BlobStoreConfiguration configuration;
@Mock
private BlobStoreRetryConfiguration blobStoreRetryConfiguration;
@InjectMocks @InjectMocks
private BlobContainerClientFactoryImpl sut; private BlobContainerClientFactoryImpl sut;
...@@ -75,7 +74,6 @@ public class BlobContainerClientFactoryImplTest { ...@@ -75,7 +74,6 @@ public class BlobContainerClientFactoryImplTest {
PartitionInfoAzure.builder() PartitionInfoAzure.builder()
.idConfig(Property.builder().value(PARTITION_ID).build()) .idConfig(Property.builder().value(PARTITION_ID).build())
.storageAccountNameConfig(Property.builder().value(ACCOUNT_NAME).build()).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); BlobContainerClient containerClient = this.sut.getClient(PARTITION_ID, STORAGE_CONTAINER_NAME);
assertNotNull(containerClient); assertNotNull(containerClient);
} }
...@@ -86,7 +84,6 @@ public class BlobContainerClientFactoryImplTest { ...@@ -86,7 +84,6 @@ public class BlobContainerClientFactoryImplTest {
PartitionInfoAzure.builder() PartitionInfoAzure.builder()
.idConfig(Property.builder().value(PARTITION_ID).build()) .idConfig(Property.builder().value(PARTITION_ID).build())
.storageAccountNameConfig(Property.builder().value(ACCOUNT_NAME).build()).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); BlobContainerClient containerClient = this.sut.getClient(PARTITION_ID, STORAGE_CONTAINER_NAME);
assertNotNull(containerClient); assertNotNull(containerClient);
......
...@@ -16,6 +16,7 @@ package org.opengroup.osdu.azure.blobstorage; ...@@ -16,6 +16,7 @@ package org.opengroup.osdu.azure.blobstorage;
import com.azure.identity.DefaultAzureCredential; import com.azure.identity.DefaultAzureCredential;
import com.azure.storage.blob.BlobServiceClient; import com.azure.storage.blob.BlobServiceClient;
import com.azure.storage.common.policy.RequestRetryOptions;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
...@@ -24,8 +25,10 @@ import org.mockito.Mock; ...@@ -24,8 +25,10 @@ import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.opengroup.osdu.azure.cache.BlobServiceClientCache; import org.opengroup.osdu.azure.cache.BlobServiceClientCache;
import org.opengroup.osdu.azure.di.BlobStoreConfiguration; 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.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.PartitionServiceClient; import org.opengroup.osdu.azure.partition.PartitionServiceClient;
import org.opengroup.osdu.core.common.logging.ILogger;
import org.opengroup.osdu.core.common.partition.Property; import org.opengroup.osdu.core.common.partition.Property;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
...@@ -43,6 +46,10 @@ public class BlobServiceClientFactoryImplTest { ...@@ -43,6 +46,10 @@ public class BlobServiceClientFactoryImplTest {
private BlobServiceClientCache clientCache; private BlobServiceClientCache clientCache;
@Mock @Mock
private BlobStoreConfiguration configuration; private BlobStoreConfiguration configuration;
@Mock
private BlobStoreRetryConfiguration blobStoreRetryConfiguration;
@Mock
private ILogger logger;
@InjectMocks @InjectMocks
private BlobServiceClientFactoryImpl sut; private BlobServiceClientFactoryImpl sut;
...@@ -83,6 +90,7 @@ public class BlobServiceClientFactoryImplTest { ...@@ -83,6 +90,7 @@ public class BlobServiceClientFactoryImplTest {
PartitionInfoAzure.builder() PartitionInfoAzure.builder()
.idConfig(Property.builder().value(PARTITION_ID).build()) .idConfig(Property.builder().value(PARTITION_ID).build())
.storageAccountNameConfig(Property.builder().value(ACCOUNT_NAME).build()).build()); .storageAccountNameConfig(Property.builder().value(ACCOUNT_NAME).build()).build());
when(this.blobStoreRetryConfiguration.getRequestRetryOptions()).thenReturn(new RequestRetryOptions());
BlobServiceClient serviceClient = this.sut.getBlobServiceClient(PARTITION_ID); BlobServiceClient serviceClient = this.sut.getBlobServiceClient(PARTITION_ID);
assertNotNull(serviceClient); assertNotNull(serviceClient);
...@@ -94,6 +102,7 @@ public class BlobServiceClientFactoryImplTest { ...@@ -94,6 +102,7 @@ public class BlobServiceClientFactoryImplTest {
PartitionInfoAzure.builder() PartitionInfoAzure.builder()
.idConfig(Property.builder().value(PARTITION_ID).build()) .idConfig(Property.builder().value(PARTITION_ID).build())
.storageAccountNameConfig(Property.builder().value(ACCOUNT_NAME).build()).build()); .storageAccountNameConfig(Property.builder().value(ACCOUNT_NAME).build()).build());
when(this.blobStoreRetryConfiguration.getRequestRetryOptions()).thenReturn(new RequestRetryOptions());
BlobServiceClient serviceClient = this.sut.getBlobServiceClient(PARTITION_ID); BlobServiceClient serviceClient = this.sut.getBlobServiceClient(PARTITION_ID);
assertNotNull(serviceClient); 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