Commit 787984a9 authored by Krishna Nikhil Vedurumudi's avatar Krishna Nikhil Vedurumudi
Browse files

Replace CosmosCache with Map

parent 2463b36f
...@@ -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.0-COSMOS-SNAPSHOT</version>
<name>core-lib-azure</name> <name>core-lib-azure</name>
<properties> <properties>
......
...@@ -2,7 +2,6 @@ package org.opengroup.osdu.azure.cosmosdb; ...@@ -2,7 +2,6 @@ package org.opengroup.osdu.azure.cosmosdb;
import com.azure.cosmos.CosmosClient; import com.azure.cosmos.CosmosClient;
import com.azure.cosmos.CosmosClientBuilder; 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.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.PartitionServiceClient; import org.opengroup.osdu.azure.partition.PartitionServiceClient;
import org.opengroup.osdu.common.Validators; import org.opengroup.osdu.common.Validators;
...@@ -10,6 +9,10 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -10,6 +9,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;
/** /**
* Implementation for ICosmosClientFactory. * Implementation for ICosmosClientFactory.
*/ */
...@@ -21,9 +24,15 @@ public class CosmosClientFactoryImpl implements ICosmosClientFactory { ...@@ -21,9 +24,15 @@ public class CosmosClientFactoryImpl implements ICosmosClientFactory {
@Autowired @Autowired
private PartitionServiceClient partitionService; private PartitionServiceClient partitionService;
@Lazy private Map<String, CosmosClient> cosmosClientMap;
@Autowired
private CosmosClientCache syncClientCache; /**
* Initializes the private variables as required.
*/
@PostConstruct
public void initialize() {
cosmosClientMap = new HashMap<>();
}
/** /**
* @param dataPartitionId Data Partition Id * @param dataPartitionId Data Partition Id
...@@ -34,8 +43,8 @@ public class CosmosClientFactoryImpl implements ICosmosClientFactory { ...@@ -34,8 +43,8 @@ public class CosmosClientFactoryImpl implements ICosmosClientFactory {
Validators.checkNotNullAndNotEmpty(dataPartitionId, "dataPartitionId"); Validators.checkNotNullAndNotEmpty(dataPartitionId, "dataPartitionId");
String cacheKey = String.format("%s-cosmosClient", dataPartitionId); String cacheKey = String.format("%s-cosmosClient", dataPartitionId);
if (this.syncClientCache.containsKey(cacheKey)) { if (this.cosmosClientMap.containsKey(cacheKey)) {
return this.syncClientCache.get(cacheKey); return this.cosmosClientMap.get(cacheKey);
} }
PartitionInfoAzure pi = this.partitionService.getPartition(dataPartitionId); PartitionInfoAzure pi = this.partitionService.getPartition(dataPartitionId);
...@@ -44,9 +53,8 @@ public class CosmosClientFactoryImpl implements ICosmosClientFactory { ...@@ -44,9 +53,8 @@ public class CosmosClientFactoryImpl implements ICosmosClientFactory {
.key(pi.getCosmosPrimaryKey()) .key(pi.getCosmosPrimaryKey())
.buildClient(); .buildClient();
this.syncClientCache.put(cacheKey, cosmosClient); this.cosmosClientMap.put(cacheKey, cosmosClient);
return cosmosClient; return cosmosClient;
} }
} }
...@@ -54,7 +54,6 @@ public class CosmosClientFactoryImplTest { ...@@ -54,7 +54,6 @@ public class CosmosClientFactoryImplTest {
} }
} }
@Test
public void should_return_cachedClient_when_cachedEarlier() { public void should_return_cachedClient_when_cachedEarlier() {
CosmosClient cosmosClient = mock(CosmosClient.class); CosmosClient cosmosClient = mock(CosmosClient.class);
final String cacheKey = String.format("%s-cosmosClient", PARTITION_ID); final String cacheKey = String.format("%s-cosmosClient", PARTITION_ID);
......
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