Skip to content

Commit

Permalink
Merge branch 'main' into chore/prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
mirageoasis committed Aug 20, 2024
2 parents b0d9e84 + 86ef50f commit d1b6826
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 58 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: unit test on push
on: [ pull_request ]

jobs:
deploy:
name: unit test
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.PRIVATE_TOKEN }}
submodules: true

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'

- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew --info test
2 changes: 1 addition & 1 deletion backend-config
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(TicketingException.class)
public ResponseEntity<ErrorResponse<Void>> handleTicketingException(TicketingException e) {
ErrorCode errorCode = e.getErrorCode();
log.warn("예외 발생. 메세지={}", e.getMessage(), e);
return ResponseEntity.status(errorCode.getHttpStatusValue())
.body(ErrorResponse.of(errorCode));
}
Expand All @@ -20,6 +25,7 @@ public ResponseEntity<ErrorResponse<Void>> handleTicketingException(TicketingExc
public ResponseEntity<ErrorResponse<List<ValidationErrorDetail>>>
handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
ErrorResponse<List<ValidationErrorDetail>> errorResponse = ErrorResponse.of(e);
log.info("API 요청 데이터 오류. 메세지={}", e.getMessage());
return ResponseEntity.badRequest().body(errorResponse);
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@
package com.thirdparty.ticketing.global.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Profile({"local", "default"})
@Configuration
public class LettuceConfig {
public class LocalRedisConfig {

@Bean
public LettuceConnectionFactory lettuceConnectionFactory(
private final int port;
private final String host;

public LocalRedisConfig(
@Value("${spring.data.redis.port}") int port,
@Value("${spring.data.redis.host}") String host) {
return new LettuceConnectionFactory(host, port);
this.port = port;
this.host = host;
}

@Bean
public RedissonClient redissonClient() {
Config config = new Config();
SingleServerConfig serverConfig = config.useSingleServer();
serverConfig.setAddress("redis://" + host + ":" + port);
return Redisson.create(config);
}

@Bean
public LettuceConnectionFactory lettuceConnectionFactory() {
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
config.setHostName(host);
config.setPort(port);
return new LettuceConnectionFactory(config);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.thirdparty.ticketing.global.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;

@Profile("prod")
@Configuration
public class ProductionRedisConfig {

private final int port;
private final String host;
private final String password;

public ProductionRedisConfig(
@Value("${spring.data.redis.port}") int port,
@Value("${spring.data.redis.host}") String host,
@Value("${spring.data.redis.password}") String password) {
this.port = port;
this.host = host;
this.password = password;
}

@Bean
public RedissonClient redissonClient() {
Config config = new Config();
SingleServerConfig serverConfig = config.useSingleServer();
serverConfig.setAddress("redis://" + host + ":" + port);
serverConfig.setPassword(password);
return Redisson.create(config);
}

@Bean
public LettuceConnectionFactory lettuceConnectionFactory() {
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
config.setHostName(host);
config.setPort(port);
config.setPassword(password);
return new LettuceConnectionFactory(config);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
import com.thirdparty.ticketing.support.TestContainerStarter;

@SpringBootTest
class RedissonConfigTest extends TestContainerStarter {
class ProductionRedisConfigTest extends TestContainerStarter {

@Autowired private RedissonClient redissonClient;

@Autowired private StringRedisTemplate redissonRedisTemplate;
@Autowired private StringRedisTemplate redisTemplate;

@Test
void testRedissonClient() {
assertThat(redissonClient).isNotNull();
}

@Test
void testRedissonRedisTemplate() {
assertThat(redissonRedisTemplate).isNotNull();
redissonRedisTemplate.opsForValue().set("testKey", "testValue");
String value = redissonRedisTemplate.opsForValue().get("testKey");
void testLettuceRedisTemplate() {
assertThat(redisTemplate).isNotNull();
redisTemplate.opsForValue().set("testKey", "testValue");
String value = redisTemplate.opsForValue().get("testKey");
assertThat(value).isEqualTo("testValue");
}
}

0 comments on commit d1b6826

Please sign in to comment.