Commit 362c331c authored by Mingyang Zhu's avatar Mingyang Zhu
Browse files

config connection timeout in the application.properties

parent 5806afc4
...@@ -43,10 +43,13 @@ public class RedisConfig { ...@@ -43,10 +43,13 @@ public class RedisConfig {
@Value("${redis.database}") @Value("${redis.database}")
private int database; private int database;
@Value("${redis.connection.timeout}")
private long timeout;
@Bean @Bean
public RedisCache<String, PartitionInfo> partitionServiceCache(@Named("REDIS_HOST") String host, @Named("REDIS_PASSWORD") String password) { public RedisCache<String, PartitionInfo> partitionServiceCache(@Named("REDIS_HOST") String host, @Named("REDIS_PASSWORD") String password) {
ClientOptions clientOptions = ClientOptions.builder() ClientOptions clientOptions = ClientOptions.builder()
.socketOptions(SocketOptions.builder().connectTimeout(15, TimeUnit.SECONDS).build()) .socketOptions(SocketOptions.builder().connectTimeout(timeout, TimeUnit.SECONDS).build())
.build(); .build();
return new RedisCache<>(host, port, password, expiration, database, clientOptions, String.class, PartitionInfo.class); return new RedisCache<>(host, port, password, expiration, database, clientOptions, String.class, PartitionInfo.class);
} }
...@@ -54,7 +57,7 @@ public class RedisConfig { ...@@ -54,7 +57,7 @@ public class RedisConfig {
@Bean @Bean
public RedisCache<String, List<String>> partitionListCache(@Named("REDIS_HOST") String host, @Named("REDIS_PASSWORD") String password) { public RedisCache<String, List<String>> partitionListCache(@Named("REDIS_HOST") String host, @Named("REDIS_PASSWORD") String password) {
ClientOptions clientOptions = ClientOptions.builder() ClientOptions clientOptions = ClientOptions.builder()
.socketOptions(SocketOptions.builder().connectTimeout(15, TimeUnit.SECONDS).build()) .socketOptions(SocketOptions.builder().connectTimeout(timeout, TimeUnit.SECONDS).build())
.build(); .build();
return new RedisCache(host, port, password, expiration, database, clientOptions, String.class, List.class); return new RedisCache(host, port, password, expiration, database, clientOptions, String.class, List.class);
} }
...@@ -74,10 +77,13 @@ public class RedisConfig { ...@@ -74,10 +77,13 @@ public class RedisConfig {
@Value("${redis.database}") @Value("${redis.database}")
private int database; private int database;
@Value("${redis.connection.timeout}")
private long timeout;
@Bean @Bean
public RedisCache<String, PartitionInfo> partitionServiceCache(@Named("REDIS_HOST") String host) { public RedisCache<String, PartitionInfo> partitionServiceCache(@Named("REDIS_HOST") String host) {
ClientOptions clientOptions = ClientOptions.builder() ClientOptions clientOptions = ClientOptions.builder()
.socketOptions(SocketOptions.builder().connectTimeout(15, TimeUnit.SECONDS).build()) .socketOptions(SocketOptions.builder().connectTimeout(timeout, TimeUnit.SECONDS).build())
.build(); .build();
return new RedisCache<>(host, port, expiration, database, clientOptions, String.class, PartitionInfo.class); return new RedisCache<>(host, port, expiration, database, clientOptions, String.class, PartitionInfo.class);
} }
...@@ -85,7 +91,7 @@ public class RedisConfig { ...@@ -85,7 +91,7 @@ public class RedisConfig {
@Bean @Bean
public RedisCache<String, List<String>> partitionListCache(@Named("REDIS_HOST") String host) { public RedisCache<String, List<String>> partitionListCache(@Named("REDIS_HOST") String host) {
ClientOptions clientOptions = ClientOptions.builder() ClientOptions clientOptions = ClientOptions.builder()
.socketOptions(SocketOptions.builder().connectTimeout(15, TimeUnit.SECONDS).build()) .socketOptions(SocketOptions.builder().connectTimeout(timeout, TimeUnit.SECONDS).build())
.build(); .build();
return new RedisCache(host, port, expiration, database, clientOptions, String.class, List.class); return new RedisCache(host, port, expiration, database, clientOptions, String.class, List.class);
} }
......
...@@ -34,8 +34,9 @@ cache.maxSize=1000 ...@@ -34,8 +34,9 @@ cache.maxSize=1000
redis.port=6380 redis.port=6380
redis.expiration=3600 redis.expiration=3600
redis.ssl.enabled=true redis.ssl.enabled=true
redis.connection.timeout=15
redis.database=${REDIS_DATABASE} redis.database=${REDIS_DATABASE}
service.cryptography.enabled=false azure.cryptography.enabled=false
service.eventgrid.topic.enabled=false azure.eventgrid.topic.enabled=false
service.eventgrid.manager.enabled=false azure.eventgrid.manager.enabled=false
...@@ -9,7 +9,6 @@ import org.opengroup.osdu.partition.util.BaseTestTemplate; ...@@ -9,7 +9,6 @@ import org.opengroup.osdu.partition.util.BaseTestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public abstract class UpdatePartitionTest extends BaseTestTemplate { public abstract class UpdatePartitionTest extends BaseTestTemplate {
...@@ -71,8 +70,7 @@ public abstract class UpdatePartitionTest extends BaseTestTemplate { ...@@ -71,8 +70,7 @@ public abstract class UpdatePartitionTest extends BaseTestTemplate {
deleteResource(); deleteResource();
assertEquals(response.getStatus(), HttpStatus.NO_CONTENT.value()); assertEquals(response.getStatus(), HttpStatus.NO_CONTENT.value());
assertEquals("GET, POST, PUT, DELETE, OPTIONS, HEAD, PATCH", response.getHeaders().getFirst("Access-Control-Allow-Methods")); assertEquals("GET, POST, PUT, DELETE, OPTIONS, HEAD, PATCH", response.getHeaders().getFirst("Access-Control-Allow-Methods"));
assertTrue("origin, content-type, accept, authorization, data-partition-id, correlation-id, appkey".equals(response.getHeaders().getFirst("Access-Control-Allow-Headers")) || assertEquals("origin, content-type, accept, authorization, data-partition-id, correlation-id, appkey", response.getHeaders().getFirst("Access-Control-Allow-Headers"));
"access-control-allow-origin, origin, content-type, accept, authorization, data-partition-id, correlation-id, appkey".equals(response.getHeaders().getFirst("Access-Control-Allow-Headers")));
assertEquals("*", response.getHeaders().getFirst("Access-Control-Allow-Origin")); assertEquals("*", response.getHeaders().getFirst("Access-Control-Allow-Origin"));
assertEquals("true", response.getHeaders().getFirst("Access-Control-Allow-Credentials")); assertEquals("true", response.getHeaders().getFirst("Access-Control-Allow-Credentials"));
assertEquals("default-src 'self'", response.getHeaders().getFirst("Content-Security-Policy")); assertEquals("default-src 'self'", response.getHeaders().getFirst("Content-Security-Policy"));
......
...@@ -20,7 +20,6 @@ import com.sun.jersey.api.client.ClientResponse; ...@@ -20,7 +20,6 @@ import com.sun.jersey.api.client.ClientResponse;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public abstract class BaseTestTemplate extends TestBase { public abstract class BaseTestTemplate extends TestBase {
...@@ -70,8 +69,7 @@ public abstract class BaseTestTemplate extends TestBase { ...@@ -70,8 +69,7 @@ public abstract class BaseTestTemplate extends TestBase {
deleteResource(); deleteResource();
assertEquals(error(response.getStatus() == 204 ? "" : response.getEntity(String.class)), expectedOkResponseCode(), response.getStatus()); assertEquals(error(response.getStatus() == 204 ? "" : response.getEntity(String.class)), expectedOkResponseCode(), response.getStatus());
assertEquals("GET, POST, PUT, DELETE, OPTIONS, HEAD, PATCH", response.getHeaders().getFirst("Access-Control-Allow-Methods")); assertEquals("GET, POST, PUT, DELETE, OPTIONS, HEAD, PATCH", response.getHeaders().getFirst("Access-Control-Allow-Methods"));
assertTrue("origin, content-type, accept, authorization, data-partition-id, correlation-id, appkey".equals(response.getHeaders().getFirst("Access-Control-Allow-Headers")) || assertEquals("origin, content-type, accept, authorization, data-partition-id, correlation-id, appkey", response.getHeaders().getFirst("Access-Control-Allow-Headers"));
"access-control-allow-origin, origin, content-type, accept, authorization, data-partition-id, correlation-id, appkey".equals(response.getHeaders().getFirst("Access-Control-Allow-Headers")));
assertEquals("*", response.getHeaders().getFirst("Access-Control-Allow-Origin")); assertEquals("*", response.getHeaders().getFirst("Access-Control-Allow-Origin"));
assertEquals("true", response.getHeaders().getFirst("Access-Control-Allow-Credentials")); assertEquals("true", response.getHeaders().getFirst("Access-Control-Allow-Credentials"));
assertEquals("default-src 'self'", response.getHeaders().getFirst("Content-Security-Policy")); assertEquals("default-src 'self'", response.getHeaders().getFirst("Content-Security-Policy"));
......
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