Skip to content
GitLab
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
b8e158df
Commit
b8e158df
authored
Jan 28, 2021
by
Kishore Battula
Browse files
Merge branch 'log-cosmosdb-calls' into 'master'
Add dependency logging to CosmosStore See merge request
!55
parents
93afc761
dd1a0cfd
Pipeline
#23890
passed with stages
in 9 minutes and 44 seconds
Changes
4
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
b8e158df
...
...
@@ -20,7 +20,7 @@
<groupId>
org.opengroup.osdu
</groupId>
<artifactId>
core-lib-azure
</artifactId>
<packaging>
jar
</packaging>
<version>
0.0.6
3
</version>
<version>
0.0.6
6
</version>
<name>
core-lib-azure
</name>
<properties>
...
...
src/main/java/org/opengroup/osdu/azure/cosmosdb/CosmosStore.java
View file @
b8e158df
This diff is collapsed.
Click to expand it.
src/main/java/org/opengroup/osdu/azure/logging/DependencyPayload.java
View file @
b8e158df
...
...
@@ -28,8 +28,8 @@ public final class DependencyPayload {
/**
* Instantiate payload with specified values.
*
* @param dependency
Data
the name of the command initiated with this dependency call
* @param dependency
Name
the command initiated by this dependency call
* @param dependency
Name
the name of the command initiated with this dependency call
* @param dependency
Data
the command initiated by this dependency call
* @param dependencyDuration the request duration
* @param dependencyResultCode the result code of the call
* @param dependencySuccess indication of successful or unsuccessful call
...
...
src/test/java/org/opengroup/osdu/azure/cosmosdb/CosmosStoreTest.java
View file @
b8e158df
...
...
@@ -26,6 +26,7 @@ import com.azure.cosmos.implementation.NotFoundException;
import
com.azure.cosmos.models.CosmosItemRequestOptions
;
import
com.azure.cosmos.models.CosmosItemResponse
;
import
com.azure.cosmos.models.PartitionKey
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.Assertions
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
...
...
@@ -34,9 +35,13 @@ import org.mockito.ArgumentCaptor;
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.azure.multitenancy.TenantInfoDoc
;
import
org.opengroup.osdu.core.common.model.http.AppException
;
import
java.lang.reflect.Field
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertThrows
;
...
...
@@ -44,11 +49,7 @@ import static org.junit.jupiter.api.Assertions.fail;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyString
;
import
static
org
.
mockito
.
ArgumentMatchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
doReturn
;
import
static
org
.
mockito
.
Mockito
.
doThrow
;
import
static
org
.
mockito
.
Mockito
.
lenient
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.*;
@ExtendWith
(
MockitoExtension
.
class
)
class
CosmosStoreTest
{
...
...
@@ -61,6 +62,11 @@ class CosmosStoreTest {
private
static
final
String
DATA_PARTITION_ID
=
"data-partition-id"
;
private
static
final
String
ITEM
=
"ITEM"
;
@Mock
private
CoreLoggerFactory
coreLoggerFactory
;
@Mock
private
CoreLogger
coreLogger
;
@Mock
private
CosmosContainer
container
;
...
...
@@ -91,8 +97,40 @@ class CosmosStoreTest {
@InjectMocks
private
CosmosStore
cosmosStore
;
/**
* 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
(
instance
,
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
init
()
throws
CosmosException
{
mockSingleton
(
coreLoggerFactory
);
when
(
coreLoggerFactory
.
getLogger
(
anyString
())).
thenReturn
(
coreLogger
);
// mock the common cosmos request/response pattern that most tests need. because
// not all tests will leverage these, we make the mocks lenient.
...
...
@@ -104,6 +142,11 @@ class CosmosStoreTest {
lenient
().
doReturn
(
container
).
when
(
cosmosDatabase
).
getContainer
(
anyString
());
}
@AfterEach
public
void
takeDown
()
{
resetSingleton
();
}
@Test
void
delete_throws404_ifNotFound
()
throws
CosmosException
{
doThrow
(
NotFoundException
.
class
).
when
(
container
).
deleteItem
(
any
(),
any
(),
any
());
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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