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
787984a9
Commit
787984a9
authored
May 06, 2021
by
Krishna Nikhil Vedurumudi
Browse files
Replace CosmosCache with Map
parent
2463b36f
Changes
3
Show whitespace changes
Inline
Side-by-side
pom.xml
View file @
787984a9
...
...
@@ -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.0-
COSMOS-
SNAPSHOT
</version>
<name>
core-lib-azure
</name>
<properties>
...
...
src/main/java/org/opengroup/osdu/azure/cosmosdb/CosmosClientFactoryImpl.java
View file @
787984a9
...
...
@@ -2,7 +2,6 @@ package org.opengroup.osdu.azure.cosmosdb;
import
com.azure.cosmos.CosmosClient
;
import
com.azure.cosmos.CosmosClientBuilder
;
import
org.opengroup.osdu.azure.cache.CosmosClientCache
;
import
org.opengroup.osdu.azure.partition.PartitionInfoAzure
;
import
org.opengroup.osdu.azure.partition.PartitionServiceClient
;
import
org.opengroup.osdu.common.Validators
;
...
...
@@ -10,6 +9,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.PostConstruct
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* Implementation for ICosmosClientFactory.
*/
...
...
@@ -21,9 +24,15 @@ public class CosmosClientFactoryImpl implements ICosmosClientFactory {
@Autowired
private
PartitionServiceClient
partitionService
;
@Lazy
@Autowired
private
CosmosClientCache
syncClientCache
;
private
Map
<
String
,
CosmosClient
>
cosmosClientMap
;
/**
* Initializes the private variables as required.
*/
@PostConstruct
public
void
initialize
()
{
cosmosClientMap
=
new
HashMap
<>();
}
/**
* @param dataPartitionId Data Partition Id
...
...
@@ -34,8 +43,8 @@ public class CosmosClientFactoryImpl implements ICosmosClientFactory {
Validators
.
checkNotNullAndNotEmpty
(
dataPartitionId
,
"dataPartitionId"
);
String
cacheKey
=
String
.
format
(
"%s-cosmosClient"
,
dataPartitionId
);
if
(
this
.
sync
Client
Cache
.
containsKey
(
cacheKey
))
{
return
this
.
sync
Client
Cache
.
get
(
cacheKey
);
if
(
this
.
cosmos
Client
Map
.
containsKey
(
cacheKey
))
{
return
this
.
cosmos
Client
Map
.
get
(
cacheKey
);
}
PartitionInfoAzure
pi
=
this
.
partitionService
.
getPartition
(
dataPartitionId
);
...
...
@@ -44,9 +53,8 @@ public class CosmosClientFactoryImpl implements ICosmosClientFactory {
.
key
(
pi
.
getCosmosPrimaryKey
())
.
buildClient
();
this
.
sync
Client
Cache
.
put
(
cacheKey
,
cosmosClient
);
this
.
cosmos
Client
Map
.
put
(
cacheKey
,
cosmosClient
);
return
cosmosClient
;
}
}
src/test/java/org/opengroup/osdu/azure/cosmosdb/CosmosClientFactoryImplTest.java
View file @
787984a9
...
...
@@ -54,7 +54,6 @@ public class CosmosClientFactoryImplTest {
}
}
@Test
public
void
should_return_cachedClient_when_cachedEarlier
()
{
CosmosClient
cosmosClient
=
mock
(
CosmosClient
.
class
);
final
String
cacheKey
=
String
.
format
(
"%s-cosmosClient"
,
PARTITION_ID
);
...
...
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