Commit c85ef178 authored by Rostislav Vatolin [SLB]'s avatar Rostislav Vatolin [SLB]
Browse files

Merge branch 'create_bean_on_startup' into 'master'

Create redis spring bean beforehand

See merge request !70
parents 18f3ca3a e88aa6b7
Pipeline #37839 passed with stages
in 17 minutes and 8 seconds
......@@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
@Configuration
public class CacheConfig {
......@@ -30,7 +31,12 @@ public class CacheConfig {
@Value("${spring.application.name}")
private String applicationName;
/**
* To make sure a connection to redis is created beforehand,
* we need to create this spring bean on application startup
*/
@Bean
@Lazy(false)
public RedisCache<String, ParentReferences> groupCacheRedis() {
return new RedisCache<>(getRedisHostname(), redisPort, getRedisPassword(), redisTtlSeconds, redisDatabase, String.class,
ParentReferences.class);
......
......@@ -9,6 +9,7 @@ import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.entitlements.v2.azure.config.CacheConfig;
import org.opengroup.osdu.entitlements.v2.azure.model.NodeVertex;
import org.opengroup.osdu.entitlements.v2.azure.spi.gremlin.connection.GremlinConnector;
import org.opengroup.osdu.entitlements.v2.azure.spi.gremlin.constant.EdgePropertyNames;
......@@ -18,6 +19,7 @@ import org.opengroup.osdu.entitlements.v2.model.NodeType;
import org.opengroup.osdu.entitlements.v2.model.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Arrays;
......@@ -34,6 +36,8 @@ public class GraphTraversalSourceUtilServiceTest {
private GremlinConnector gremlinConnector;
@Autowired
private GraphTraversalSourceUtilService graphTraversalSourceUtilService;
@MockBean
private CacheConfig cacheConfig;
@After
public void cleanup() {
......
......@@ -13,6 +13,7 @@ import org.mockito.stubbing.Answer;
import org.opengroup.osdu.core.common.cache.RedisCache;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.entitlements.v2.azure.config.CacheConfig;
import org.opengroup.osdu.entitlements.v2.azure.service.metrics.hitsnmisses.HitsNMissesMetricService;
import org.opengroup.osdu.entitlements.v2.model.EntityNode;
import org.opengroup.osdu.entitlements.v2.model.ParentReference;
......@@ -87,6 +88,8 @@ public class GroupCacheServiceAzureTest {
@MockBean
private JaxRsDpsLog log;
@MockBean
private CacheConfig cacheConfig;
@MockBean
private PartitionCacheTtlService partitionCacheTtlService;
@Mock
private ParentTreeDto parentTreeDto;
......
......@@ -8,10 +8,12 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.opengroup.osdu.core.common.cache.ICache;
import org.opengroup.osdu.entitlements.v2.azure.config.CacheConfig;
import org.opengroup.osdu.entitlements.v2.model.ParentReferences;
import org.opengroup.osdu.entitlements.v2.service.HealthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.junit4.SpringRunner;
import redis.embedded.RedisServer;
......@@ -23,6 +25,9 @@ public class HealthServiceAzureTest {
@Autowired
private HealthService healthService;
@MockBean
private CacheConfig cacheConfig;
@SpyBean
private ICache<String, ParentReferences> redisGroupCache;
......
......@@ -9,6 +9,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.opengroup.osdu.core.common.logging.audit.AuditStatus;
import org.opengroup.osdu.entitlements.v2.azure.config.CacheConfig;
import org.opengroup.osdu.entitlements.v2.azure.spi.gremlin.connection.GremlinConnector;
import org.opengroup.osdu.entitlements.v2.azure.spi.gremlin.constant.EdgePropertyNames;
import org.opengroup.osdu.entitlements.v2.azure.spi.gremlin.constant.VertexPropertyNames;
......@@ -38,6 +39,9 @@ public class AddMemberRepoGremlinTest {
@MockBean
private AuditLogger auditLogger;
@MockBean
private CacheConfig cacheConfig;
@After
public void cleanup() {
gremlinConnector.getGraphTraversalSource().V().drop().iterate();
......
......@@ -8,6 +8,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.opengroup.osdu.core.common.logging.audit.AuditStatus;
import org.opengroup.osdu.entitlements.v2.azure.config.CacheConfig;
import org.opengroup.osdu.entitlements.v2.azure.spi.gremlin.connection.GremlinConnector;
import org.opengroup.osdu.entitlements.v2.azure.spi.gremlin.constant.VertexPropertyNames;
import org.opengroup.osdu.entitlements.v2.logging.AuditLogger;
......@@ -36,6 +37,9 @@ public class CreateGroupRepoGremlinTest {
@MockBean
private AuditLogger auditLogger;
@MockBean
private CacheConfig cacheConfig;
@Autowired
private CreateGroupRepo createGroupRepo;
......
......@@ -6,6 +6,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.opengroup.osdu.core.common.logging.audit.AuditStatus;
import org.opengroup.osdu.entitlements.v2.azure.config.CacheConfig;
import org.opengroup.osdu.entitlements.v2.azure.spi.gremlin.addmember.AddMemberRepoGremlin;
import org.opengroup.osdu.entitlements.v2.azure.spi.gremlin.connection.GremlinConnector;
import org.opengroup.osdu.entitlements.v2.azure.spi.gremlin.constant.VertexPropertyNames;
......@@ -36,6 +37,9 @@ public class DeleteGroupRepoGremlinTest {
@MockBean
private AuditLogger auditLogger;
@MockBean
private CacheConfig cacheConfig;
@After
public void cleanup() {
gremlinConnector.getGraphTraversalSource().V().drop().iterate();
......
......@@ -5,6 +5,7 @@ import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opengroup.osdu.entitlements.v2.azure.config.CacheConfig;
import org.opengroup.osdu.entitlements.v2.azure.spi.gremlin.addmember.AddMemberRepoGremlin;
import org.opengroup.osdu.entitlements.v2.azure.spi.gremlin.connection.GremlinConnector;
import org.opengroup.osdu.entitlements.v2.azure.spi.gremlin.constant.EdgePropertyNames;
......@@ -40,6 +41,9 @@ public class ListMemberRepoGremlinTest {
@MockBean
private AuditLogger auditLogger;
@MockBean
private CacheConfig cacheConfig;
@Test
public void shouldLoadDirectChildrenSuccessfully() {
GraphTraversalSource graphTraversalSource = gremlinConnector.getGraphTraversalSource();
......
......@@ -7,6 +7,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.opengroup.osdu.core.common.logging.audit.AuditStatus;
import org.opengroup.osdu.entitlements.v2.azure.config.CacheConfig;
import org.opengroup.osdu.entitlements.v2.azure.spi.gremlin.addmember.AddMemberRepoGremlin;
import org.opengroup.osdu.entitlements.v2.azure.spi.gremlin.connection.GremlinConnector;
import org.opengroup.osdu.entitlements.v2.azure.spi.gremlin.constant.VertexPropertyNames;
......@@ -42,6 +43,9 @@ public class RemoveMemberRepoGremlinTest {
@MockBean
private AuditLogger auditLogger;
@MockBean
private CacheConfig cacheConfig;
@After
public void cleanup() {
GraphTraversalSource graphTraversalSource = gremlinConnector.getGraphTraversalSource();
......
......@@ -10,6 +10,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.opengroup.osdu.core.common.logging.audit.AuditStatus;
import org.opengroup.osdu.entitlements.v2.azure.config.CacheConfig;
import org.opengroup.osdu.entitlements.v2.azure.service.AddEdgeDto;
import org.opengroup.osdu.entitlements.v2.azure.service.GraphTraversalSourceUtilService;
import org.opengroup.osdu.entitlements.v2.azure.service.VertexUtilService;
......@@ -42,6 +43,8 @@ public class RenameGroupRepoGremlinTest {
@MockBean
private AuditLogger auditLogger;
@MockBean
private CacheConfig cacheConfig;
@Autowired
private RenameGroupRepo renameGroupRepo;
@Autowired
......
......@@ -7,6 +7,7 @@ import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.entitlements.v2.azure.config.CacheConfig;
import org.opengroup.osdu.entitlements.v2.azure.service.GraphTraversalSourceUtilService;
import org.opengroup.osdu.entitlements.v2.azure.spi.gremlin.addmember.AddMemberRepoGremlin;
import org.opengroup.osdu.entitlements.v2.azure.spi.gremlin.connection.GremlinConnector;
......@@ -54,6 +55,8 @@ public class RetrieveGroupRepoGremlinTest {
private AddMemberRepoGremlin addMemberRepoGremlin;
@MockBean
private AuditLogger auditLogger;
@MockBean
private CacheConfig cacheConfig;
@After
public void cleanup() {
......
......@@ -10,6 +10,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.opengroup.osdu.core.common.logging.audit.AuditStatus;
import org.opengroup.osdu.entitlements.v2.azure.config.CacheConfig;
import org.opengroup.osdu.entitlements.v2.azure.service.AddEdgeDto;
import org.opengroup.osdu.entitlements.v2.azure.service.GraphTraversalSourceUtilService;
import org.opengroup.osdu.entitlements.v2.azure.service.VertexUtilService;
......@@ -43,6 +44,8 @@ public class UpdateAppIdsRepoGremlinTest {
@MockBean
private AuditLogger auditLogger;
@MockBean
private CacheConfig cacheConfig;
@Autowired
private UpdateAppIdsRepo updateAppIdsRepo;
@Autowired
......
......@@ -21,6 +21,7 @@ import org.opengroup.osdu.entitlements.v2.api.DeleteGroupApi;
import org.opengroup.osdu.entitlements.v2.api.DeleteMemberApi;
import org.opengroup.osdu.entitlements.v2.auth.AuthorizationService;
import org.opengroup.osdu.entitlements.v2.azure.AzureAppProperties;
import org.opengroup.osdu.entitlements.v2.azure.config.CacheConfig;
import org.opengroup.osdu.entitlements.v2.azure.service.PartitionCacheTtlService;
import org.opengroup.osdu.entitlements.v2.logging.AuditLogger;
import org.opengroup.osdu.entitlements.v2.model.GroupType;
......@@ -95,6 +96,8 @@ public class CreateMembershipsWorkflowSinglePartitionTest {
@MockBean
private RedisCache<String, ParentReferences> redisGroupCache;
@MockBean
private CacheConfig cacheConfig;
@MockBean
private RedissonClient redissonClient;
@Mock
private RLock cacheLock;
......
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