Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Open Subsurface Data Universe Software
Platform
System
Lib
cloud
azure
OS Core Lib Azure
Commits
905c406f
Commit
905c406f
authored
May 31, 2021
by
Ronak Sakhuja
Browse files
Replaced logging
parent
f164e679
Pipeline
#43469
failed with stage
in 38 seconds
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/opengroup/osdu/azure/di/BlobStoreRetryConfiguration.java
View file @
905c406f
...
...
@@ -18,12 +18,10 @@ import com.azure.storage.common.policy.RequestRetryOptions;
import
com.azure.storage.common.policy.RetryPolicyType
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.opengroup.osdu.core.common.logging.ILogger
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.opengroup.osdu.azure.logging.CoreLoggerFactory
;
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.
...
...
@@ -34,8 +32,9 @@ import java.util.Collections;
@Setter
public
class
BlobStoreRetryConfiguration
{
@Autowired
private
ILogger
logger
;
public
static
final
String
LOGGER_NAME
=
BlobStoreRetryConfiguration
.
class
.
getName
();
private
static
final
int
DEFAULT_INT_VALUE
=
-
1
;
private
static
final
String
DEFAULT_STRING_VALUE
=
""
;
...
...
@@ -52,7 +51,7 @@ public class BlobStoreRetryConfiguration {
* @return true if value is configured in app.properties
*/
private
boolean
valueConfigured
(
final
int
val
)
{
if
(
val
!=
-
1
)
{
if
(
val
!=
DEFAULT_INT_VALUE
)
{
return
true
;
}
return
false
;
...
...
@@ -64,7 +63,7 @@ public class BlobStoreRetryConfiguration {
* @return true if value is configured in app.properties
*/
private
boolean
valueConfigured
(
final
String
val
)
{
if
(
val
==
null
||
val
.
isEmpty
(
))
{
if
(
val
==
null
||
val
.
equals
(
DEFAULT_STRING_VALUE
))
{
return
false
;
}
return
true
;
...
...
@@ -79,8 +78,13 @@ public class BlobStoreRetryConfiguration {
// Check whether the variables have been set, else keep them as null.
// 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
retryPolicyType
;
try
{
retryPolicyType
=
valueConfigured
(
retryPolicyTypeValue
)
?
RetryPolicyType
.
valueOf
(
retryPolicyTypeValue
)
:
RetryPolicyType
.
EXPONENTIAL
;
}
catch
(
Exception
ex
)
{
retryPolicyType
=
RetryPolicyType
.
EXPONENTIAL
;
}
RetryPolicyType
retryPolicyType
=
valueConfigured
(
retryPolicyTypeValue
)
?
RetryPolicyType
.
valueOf
(
retryPolicyTypeValue
)
:
RetryPolicyType
.
EXPONENTIAL
;
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
;
...
...
@@ -90,8 +94,8 @@ public class BlobStoreRetryConfiguration {
RequestRetryOptions
requestRetryOptions
=
new
RequestRetryOptions
(
retryPolicyType
,
maxTriesValue
,
tryTimeout
,
retryDelay
,
maxRetryDelay
,
secondaryHostValue
);
this
.
logger
.
info
(
"BlobStoreRetryConfiguration"
,
String
.
format
(
"Retry Options on BlobStorage with RetryPolicyType = %s , maxTries = %d , tryTimeout = %d , retryDelay = %d , maxRetryDelay = %d , secondaryHost = %s."
,
retryPolicyType
.
toString
(),
requestRetryOptions
.
getMaxTries
(),
requestRetryOptions
.
getTryTimeoutDuration
().
getSeconds
(),
requestRetryOptions
.
getRetryDelay
().
toMillis
(),
requestRetryOptions
.
getMaxRetryDelay
().
toMillis
(),
requestRetryOptions
.
getSecondaryHost
())
,
Collections
.
emptyMap
()
);
CoreLoggerFactory
.
getInstance
().
getLogger
(
LOGGER_NAME
).
info
(
String
.
format
(
"Retry Options on BlobStorage with RetryPolicyType = %s , maxTries = %d , tryTimeout = %d , retryDelay = %d , maxRetryDelay = %d , secondaryHost = %s."
,
retryPolicyType
.
toString
(),
requestRetryOptions
.
getMaxTries
(),
requestRetryOptions
.
getTryTimeoutDuration
().
getSeconds
(),
requestRetryOptions
.
getRetryDelay
().
toMillis
(),
requestRetryOptions
.
getMaxRetryDelay
().
toMillis
(),
requestRetryOptions
.
getSecondaryHost
()));
return
requestRetryOptions
;
}
...
...
src/test/java/org/opengroup/osdu/azure/di/BlobStoreRetryConfigurationTest.java
View file @
905c406f
...
...
@@ -15,16 +15,23 @@
package
org.opengroup.osdu.azure.di
;
import
com.azure.storage.common.policy.RequestRetryOptions
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.junit.jupiter.MockitoExtension
;
import
org.opengroup.osdu.azure.logging.CoreLogger
;
import
org.opengroup.osdu.azure.logging.CoreLoggerFactory
;
import
org.opengroup.osdu.core.common.logging.ILogger
;
import
java.lang.reflect.Field
;
import
java.time.Duration
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyString
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
mockito
.
MockitoAnnotations
.
openMocks
;
@ExtendWith
(
MockitoExtension
.
class
)
...
...
@@ -34,10 +41,50 @@ public class BlobStoreRetryConfigurationTest {
@Mock
private
ILogger
logger
;
RequestRetryOptions
defaultRequestRetryOptions
=
new
RequestRetryOptions
();
@Mock
private
CoreLoggerFactory
coreLoggerFactory
;
@Mock
private
CoreLogger
coreLogger
;
/**
* Workaround for inability to mock static methods like getInstance().
*
* @param mock CoreLoggerFactory mock instance
*/
private
void
mockSingleton
(
CoreLoggerFactory
mock
)
{
try
{
Field
instance
=
CoreLoggerFactory
.
class
.
getDeclaredField
(
"instance"
);
instance
.
setAccessible
(
true
);
instance
.
set
(
null
,
mock
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
/**
* Reset workaround for inability to mock static methods like getInstance().
*/
private
void
resetSingleton
()
{
try
{
Field
instance
=
CoreLoggerFactory
.
class
.
getDeclaredField
(
"instance"
);
instance
.
setAccessible
(
true
);
instance
.
set
(
null
,
null
);
instance
.
setAccessible
(
false
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
@BeforeEach
void
setUp
()
{
openMocks
(
this
);
mockSingleton
(
coreLoggerFactory
);
when
(
coreLoggerFactory
.
getLogger
(
anyString
())).
thenReturn
(
coreLogger
);
}
@AfterEach
public
void
takeDown
()
{
resetSingleton
();
}
@Test
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment