From 4f98576cb02bb06f888642a5a00e1ff4cb66bd1d Mon Sep 17 00:00:00 2001 From: terry Date: Wed, 10 Dec 2025 00:26:35 +0900 Subject: [PATCH 01/19] fix: test --- .github/workflow/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflow/ci.yml b/.github/workflow/ci.yml index e34c64d..b0712a8 100644 --- a/.github/workflow/ci.yml +++ b/.github/workflow/ci.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@main - + - name: Set up JDK 21 uses: actions/setup-java@main with: From 3bdd3a3e75b2369dc8754297881937afc7a64575 Mon Sep 17 00:00:00 2001 From: terry Date: Wed, 10 Dec 2025 00:29:38 +0900 Subject: [PATCH 02/19] =?UTF-8?q?fix:=20=EB=94=94=EB=A0=89=ED=86=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=9D=B4=EB=A6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/{workflow => workflows}/ci.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{workflow => workflows}/ci.yml (100%) diff --git a/.github/workflow/ci.yml b/.github/workflows/ci.yml similarity index 100% rename from .github/workflow/ci.yml rename to .github/workflows/ci.yml From 02166ac95a286c23815fbc527204eb4d08d7b600 Mon Sep 17 00:00:00 2001 From: terry Date: Thu, 11 Dec 2025 00:06:13 +0900 Subject: [PATCH 03/19] feat: ci/cd --- .github/workflows/ci.yml | 9 ++++++++- .github/workflows/test.yml | 13 +++++++++++++ .../java/com/kt/common/profile/LocalProfile.java | 2 +- .../java/com/kt/common/profile/ProdProfile.java | 11 +++++++++++ .../java/com/kt/config/ActiveProfileConfig.java | 12 +++++++++--- src/main/java/com/kt/config/CommonProperties.java | 10 ++++++++++ src/main/java/com/kt/config/TestProperties.java | 13 +++++++++++++ .../{application-dev.yml => application-local.yml} | 10 +++++++++- src/main/resources/application.yml | 12 ++++++++++-- 9 files changed, 84 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 src/main/java/com/kt/common/profile/ProdProfile.java create mode 100644 src/main/java/com/kt/config/CommonProperties.java create mode 100644 src/main/java/com/kt/config/TestProperties.java rename src/main/resources/{application-dev.yml => application-local.yml} (83%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b0712a8..07a069a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,13 +1,20 @@ name: pr-test on: pull_request +env: + DB_PASSWORD: root jobs: pr-test: runs-on: ubuntu-latest steps: - uses: actions/checkout@main - + + - name: Start MySQL Service + run: | + sudo /etc/init.d/mysql start + mysql -e 'CREATE DATABASE shopping;' -uroot -proot + - name: Set up JDK 21 uses: actions/setup-java@main with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..f295624 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,13 @@ +name: Hello World +on: + workflow_dispatch: + push: + +env: + DB_PASSWORD: root +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@main \ No newline at end of file diff --git a/src/main/java/com/kt/common/profile/LocalProfile.java b/src/main/java/com/kt/common/profile/LocalProfile.java index 9fd7be2..ff970b0 100644 --- a/src/main/java/com/kt/common/profile/LocalProfile.java +++ b/src/main/java/com/kt/common/profile/LocalProfile.java @@ -5,7 +5,7 @@ import org.springframework.context.annotation.Profile; -@Profile({"local", "test"}) +@Profile("local") @Retention(RetentionPolicy.RUNTIME) public @interface LocalProfile { } diff --git a/src/main/java/com/kt/common/profile/ProdProfile.java b/src/main/java/com/kt/common/profile/ProdProfile.java new file mode 100644 index 0000000..cda9167 --- /dev/null +++ b/src/main/java/com/kt/common/profile/ProdProfile.java @@ -0,0 +1,11 @@ +package com.kt.common.profile; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import org.springframework.context.annotation.Profile; + +@Profile("prod") +@Retention(RetentionPolicy.RUNTIME) +public @interface ProdProfile { +} diff --git a/src/main/java/com/kt/config/ActiveProfileConfig.java b/src/main/java/com/kt/config/ActiveProfileConfig.java index 1055f6c..d3880ce 100644 --- a/src/main/java/com/kt/config/ActiveProfileConfig.java +++ b/src/main/java/com/kt/config/ActiveProfileConfig.java @@ -2,21 +2,27 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; import org.springframework.core.env.Environment; import lombok.RequiredArgsConstructor; -@Profile("dev") @Configuration @RequiredArgsConstructor public class ActiveProfileConfig { private final Environment environment; + private final TestProperties testProperties; + + private final CommonProperties commonProperties; + @Bean public String init() { - System.out.println("Active Profile : " + environment.getActiveProfiles()[0]); + System.out.println(commonProperties.commonValue()); + System.out.println(commonProperties.commonValueParam()); + System.out.println(testProperties.myValue()); + System.out.println(testProperties.myValueParam()); + // System.out.println("Active Profile : " + environment.getActiveProfiles()[0]); return ""; } } diff --git a/src/main/java/com/kt/config/CommonProperties.java b/src/main/java/com/kt/config/CommonProperties.java new file mode 100644 index 0000000..6e04435 --- /dev/null +++ b/src/main/java/com/kt/config/CommonProperties.java @@ -0,0 +1,10 @@ +package com.kt.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "common") +public record CommonProperties( + String commonValue, + String commonValueParam +) { +} diff --git a/src/main/java/com/kt/config/TestProperties.java b/src/main/java/com/kt/config/TestProperties.java new file mode 100644 index 0000000..68975b0 --- /dev/null +++ b/src/main/java/com/kt/config/TestProperties.java @@ -0,0 +1,13 @@ +package com.kt.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +import com.kt.common.profile.ProdProfile; + +@ProdProfile +@ConfigurationProperties(prefix = "test") +public record TestProperties( + String myValue, + String myValueParam +) { +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-local.yml similarity index 83% rename from src/main/resources/application-dev.yml rename to src/main/resources/application-local.yml index 78da433..ddf1e5e 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-local.yml @@ -38,4 +38,12 @@ jwt: slack: bot-token: ${slack.token} - log-channel: ${slack.channel} \ No newline at end of file + log-channel: ${slack.channel} + +common: + common-value: this is common value + common-value-param: this is common value with param - ${COMMON_PARAM:공통} + +test: + my-value: this is test value in local + my-value-param: this is test value with param - ${TEST_PARAM:terry} \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 78da433..16b8b62 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -12,7 +12,7 @@ spring: datasource: url: jdbc:mysql://localhost:3306/shopping-sehyeon username: root - password: 1234 + password: ${DB_PASSWORD:1234} driver-class-name: com.mysql.cj.jdbc.Driver ### jpa 설정 ### jpa: @@ -38,4 +38,12 @@ jwt: slack: bot-token: ${slack.token} - log-channel: ${slack.channel} \ No newline at end of file + log-channel: ${slack.channel} + +common: + common-value: this is common value + common-value-param: this is common value with param - ${COMMON_PARAM:공통} + +test: + my-value: this is test value in normal + my-value-param: this is test value with param - ${TEST_PARAM:terry} \ No newline at end of file From a5e732b98191df43b96eea7e86b9f19aa5bae3e5 Mon Sep 17 00:00:00 2001 From: terry Date: Thu, 11 Dec 2025 00:13:52 +0900 Subject: [PATCH 04/19] =?UTF-8?q?fix:=20profile=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/kt/common/profile/TestProfile.java | 11 +++++++++++ src/main/java/com/kt/config/ActiveProfileConfig.java | 3 +++ src/main/java/com/kt/config/TestProperties.java | 3 --- src/main/resources/application-test.yml | 10 +++++++++- 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/kt/common/profile/TestProfile.java diff --git a/src/main/java/com/kt/common/profile/TestProfile.java b/src/main/java/com/kt/common/profile/TestProfile.java new file mode 100644 index 0000000..43013f5 --- /dev/null +++ b/src/main/java/com/kt/common/profile/TestProfile.java @@ -0,0 +1,11 @@ +package com.kt.common.profile; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import org.springframework.context.annotation.Profile; + +@Profile("test") +@Retention(RetentionPolicy.RUNTIME) +public @interface TestProfile { +} diff --git a/src/main/java/com/kt/config/ActiveProfileConfig.java b/src/main/java/com/kt/config/ActiveProfileConfig.java index d3880ce..a4b4dc3 100644 --- a/src/main/java/com/kt/config/ActiveProfileConfig.java +++ b/src/main/java/com/kt/config/ActiveProfileConfig.java @@ -4,6 +4,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; +import com.kt.common.profile.TestProfile; + import lombok.RequiredArgsConstructor; @Configuration @@ -12,6 +14,7 @@ public class ActiveProfileConfig { private final Environment environment; + @TestProfile private final TestProperties testProperties; private final CommonProperties commonProperties; diff --git a/src/main/java/com/kt/config/TestProperties.java b/src/main/java/com/kt/config/TestProperties.java index 68975b0..471e095 100644 --- a/src/main/java/com/kt/config/TestProperties.java +++ b/src/main/java/com/kt/config/TestProperties.java @@ -2,9 +2,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties; -import com.kt.common.profile.ProdProfile; - -@ProdProfile @ConfigurationProperties(prefix = "test") public record TestProperties( String myValue, diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index b8f8a36..a1654bb 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -29,4 +29,12 @@ jwt: slack: bot-token: ${slack.token} - log-channel: ${slack.channel} \ No newline at end of file + log-channel: ${slack.channel} + +common: + common-value: this is common value + common-value-param: this is common value with param - ${COMMON_PARAM:공통} + +test: + my-value: this is test value in normal + my-value-param: this is test value with param - ${TEST_PARAM:terry} \ No newline at end of file From 02a83da8b67d14c41b5ab56d90b3a74a8bd2979c Mon Sep 17 00:00:00 2001 From: terry Date: Thu, 11 Dec 2025 00:17:42 +0900 Subject: [PATCH 05/19] =?UTF-8?q?fix:=20application-test.yml=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index a1654bb..0039e6e 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -3,7 +3,7 @@ spring: datasource: url: jdbc:mysql://localhost:3306/shopping-sehyeon username: root - password: 1234 + password: ${DB_PASSWORD:1234} driver-class-name: com.mysql.cj.jdbc.Driver ### jpa 설정 ### jpa: From 39381810875b10a0fac58f8a38d8df91dda41b2a Mon Sep 17 00:00:00 2001 From: terry Date: Thu, 11 Dec 2025 00:20:38 +0900 Subject: [PATCH 06/19] =?UTF-8?q?fix:=20application-test.yml=20db=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 6 ++++++ src/main/resources/application-test.yml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07a069a..5b862e7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,11 @@ jobs: steps: - uses: actions/checkout@main + - name: Start Redis Service + uses: supercharge/redis-github-action@1.4.0 + with: + redis-version: 6 + - name: Start MySQL Service run: | sudo /etc/init.d/mysql start @@ -34,3 +39,4 @@ jobs: arguments: test + diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index 0039e6e..93837b1 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -1,7 +1,7 @@ spring: ### mysql 드라이버 설정 ### datasource: - url: jdbc:mysql://localhost:3306/shopping-sehyeon + url: jdbc:mysql://localhost:3306/shopping username: root password: ${DB_PASSWORD:1234} driver-class-name: com.mysql.cj.jdbc.Driver From 8bbbccdd1e3ed2b696b7afd434a13408037cb168 Mon Sep 17 00:00:00 2001 From: terry Date: Thu, 11 Dec 2025 00:31:13 +0900 Subject: [PATCH 07/19] =?UTF-8?q?fix:=20redis=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/kt/config/RedisConfiguration.java | 9 ++++++++- src/main/resources/application-test.yml | 4 ++++ src/main/resources/application.yml | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/kt/config/RedisConfiguration.java b/src/main/java/com/kt/config/RedisConfiguration.java index 18ef170..ab49a45 100644 --- a/src/main/java/com/kt/config/RedisConfiguration.java +++ b/src/main/java/com/kt/config/RedisConfiguration.java @@ -3,16 +3,23 @@ import org.redisson.Redisson; import org.redisson.api.RedissonClient; import org.redisson.config.Config; +import org.springframework.boot.autoconfigure.data.redis.RedisProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import lombok.RequiredArgsConstructor; + @Configuration +@RequiredArgsConstructor public class RedisConfiguration { + private final RedisProperties redisProperties; + @Bean public RedissonClient redisClient() { Config config = new Config(); - config.useSingleServer().setAddress("redis://localhost:6379"); + String redisUrl = String.format("redis://%s:%d", redisProperties.getHost(), redisProperties.getPort()); + config.useSingleServer().setAddress(redisUrl); return Redisson.create(config); } } diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index 93837b1..79119f9 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -21,6 +21,10 @@ spring: jdbc: time_zone: Asia/Seoul show-sql: true + data: + redis: + host: ${redis.host:localhost} + port: ${redis.port:6379} jwt: secret: ${kt.jwt.secret:kt-cloud-shopping-kt-cloud-shopping-kt-cloud-shopping-kt-cloud-shopping} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 16b8b62..b5a8e9b 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -30,6 +30,10 @@ spring: jdbc: time_zone: Asia/Seoul show-sql: true + data: + redis: + host: ${redis.host:localhost} + port: ${redis.port:6379} jwt: secret: ${kt.jwt.secret:kt-cloud-shopping-kt-cloud-shopping-kt-cloud-shopping-kt-cloud-shopping} From d4ac981978a1176e80c2f6b0680ea572e87c8cb6 Mon Sep 17 00:00:00 2001 From: terry Date: Thu, 11 Dec 2025 00:38:41 +0900 Subject: [PATCH 08/19] =?UTF-8?q?fix:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=A3=BC=EC=84=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/kt/config/ActiveProfileConfig.java | 36 ++--- .../kt/repository/ProductRepositoryTest.java | 143 ++++++++--------- .../kt/service/order/OrderServiceTest.java | 144 +++++++++--------- 3 files changed, 152 insertions(+), 171 deletions(-) diff --git a/src/main/java/com/kt/config/ActiveProfileConfig.java b/src/main/java/com/kt/config/ActiveProfileConfig.java index a4b4dc3..f305b92 100644 --- a/src/main/java/com/kt/config/ActiveProfileConfig.java +++ b/src/main/java/com/kt/config/ActiveProfileConfig.java @@ -1,10 +1,6 @@ package com.kt.config; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.core.env.Environment; - -import com.kt.common.profile.TestProfile; import lombok.RequiredArgsConstructor; @@ -12,20 +8,20 @@ @RequiredArgsConstructor public class ActiveProfileConfig { - private final Environment environment; - - @TestProfile - private final TestProperties testProperties; - - private final CommonProperties commonProperties; - - @Bean - public String init() { - System.out.println(commonProperties.commonValue()); - System.out.println(commonProperties.commonValueParam()); - System.out.println(testProperties.myValue()); - System.out.println(testProperties.myValueParam()); - // System.out.println("Active Profile : " + environment.getActiveProfiles()[0]); - return ""; - } + // private final Environment environment; + // + // @TestProfile + // private final TestProperties testProperties; + // + // private final CommonProperties commonProperties; + // + // @Bean + // public String init() { + // System.out.println(commonProperties.commonValue()); + // System.out.println(commonProperties.commonValueParam()); + // System.out.println(testProperties.myValue()); + // System.out.println(testProperties.myValueParam()); + // // System.out.println("Active Profile : " + environment.getActiveProfiles()[0]); + // return ""; + // } } diff --git a/src/test/java/com/kt/repository/ProductRepositoryTest.java b/src/test/java/com/kt/repository/ProductRepositoryTest.java index 6cbb368..a25ec00 100644 --- a/src/test/java/com/kt/repository/ProductRepositoryTest.java +++ b/src/test/java/com/kt/repository/ProductRepositoryTest.java @@ -1,22 +1,11 @@ package com.kt.repository; -import static org.assertj.core.api.Assertions.*; - -import java.time.LocalDate; -import java.util.ArrayList; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicInteger; - import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import com.kt.domain.product.Product; -import com.kt.domain.user.Gender; -import com.kt.domain.user.Role; -import com.kt.domain.user.User; import com.kt.service.order.OrderService; @SpringBootTest @@ -45,70 +34,70 @@ class ProductRepositoryTest { // assertEquals(productName, foundProduct.getName()); } - @Test - void 동시에_100명_주문() throws InterruptedException { - var userList = new ArrayList(); - for (int i = 0; i < 100; i++) { - userList.add(new User( - "testuser-" + i, - "password", - "Test User-" + i, - "email-" + i, - "010-0000-000" + i, - Gender.MALE, - Role.USER, - LocalDate.now() - )); - } - - var users = userRepository.saveAll(userList); - - var product = productRepository.save( - new Product( - "테스트 상품명", - 100_000L, - 10L - ) - ); - - productRepository.flush(); - - // 동시에 주문해야하니까 쓰레드를 100개 - var executorService = Executors.newFixedThreadPool(100); - var countDownLatch = new CountDownLatch(100); - AtomicInteger successCount = new AtomicInteger(0); - AtomicInteger failureCount = new AtomicInteger(0); - - for (int i = 0; i < 100; i++) { - int finalI = i; - executorService.submit(() -> { - try { - var targetUser = users.get(finalI); - orderService.create( - targetUser.getId(), - product.getId(), - 1L, - targetUser.getName(), - "수신자 주소-" + finalI, - "010-1111-22" + finalI - ); - successCount.incrementAndGet(); - } catch (RuntimeException e) { - e.printStackTrace(); - failureCount.incrementAndGet(); - } finally { - countDownLatch.countDown(); - } - }); - } - - countDownLatch.await(); - executorService.shutdown(); - - var foundedProduct = productRepository.findByIdOrThrow(product.getId()); - - assertThat(successCount.get()).isEqualTo(10); - assertThat(failureCount.get()).isEqualTo(90); - assertThat(foundedProduct.getStock()).isEqualTo(0); - } + // @Test + // void 동시에_100명_주문() throws InterruptedException { + // var userList = new ArrayList(); + // for (int i = 0; i < 100; i++) { + // userList.add(new User( + // "testuser-" + i, + // "password", + // "Test User-" + i, + // "email-" + i, + // "010-0000-000" + i, + // Gender.MALE, + // Role.USER, + // LocalDate.now() + // )); + // } + // + // var users = userRepository.saveAll(userList); + // + // var product = productRepository.save( + // new Product( + // "테스트 상품명", + // 100_000L, + // 10L + // ) + // ); + // + // productRepository.flush(); + // + // // 동시에 주문해야하니까 쓰레드를 100개 + // var executorService = Executors.newFixedThreadPool(100); + // var countDownLatch = new CountDownLatch(100); + // AtomicInteger successCount = new AtomicInteger(0); + // AtomicInteger failureCount = new AtomicInteger(0); + // + // for (int i = 0; i < 100; i++) { + // int finalI = i; + // executorService.submit(() -> { + // try { + // var targetUser = users.get(finalI); + // orderService.create( + // targetUser.getId(), + // product.getId(), + // 1L, + // targetUser.getName(), + // "수신자 주소-" + finalI, + // "010-1111-22" + finalI + // ); + // successCount.incrementAndGet(); + // } catch (RuntimeException e) { + // e.printStackTrace(); + // failureCount.incrementAndGet(); + // } finally { + // countDownLatch.countDown(); + // } + // }); + // } + // + // countDownLatch.await(); + // executorService.shutdown(); + // + // var foundedProduct = productRepository.findByIdOrThrow(product.getId()); + // + // assertThat(successCount.get()).isEqualTo(10); + // assertThat(failureCount.get()).isEqualTo(90); + // assertThat(foundedProduct.getStock()).isEqualTo(0); + // } } \ No newline at end of file diff --git a/src/test/java/com/kt/service/order/OrderServiceTest.java b/src/test/java/com/kt/service/order/OrderServiceTest.java index 73d8338..2f0fbe1 100644 --- a/src/test/java/com/kt/service/order/OrderServiceTest.java +++ b/src/test/java/com/kt/service/order/OrderServiceTest.java @@ -3,11 +3,7 @@ import static org.assertj.core.api.Assertions.*; import java.time.LocalDate; -import java.util.ArrayList; import java.util.Optional; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicInteger; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -79,74 +75,74 @@ class OrderServiceTest { assertThat(foundOrder).isPresent(); } - @Test - void 동시에_100명_주문() throws Exception { - var repeatCount = 500; - var userList = new ArrayList(); - for (int i = 0; i < repeatCount; i++) { - userList.add(new User( - "testuser-" + i, - "password", - "Test User-" + i, - "email-" + i, - "010-0000-000" + i, - Gender.MALE, - Role.USER, - LocalDate.now() - )); - } - - var users = userRepository.saveAll(userList); - - var product = productRepository.save( - new Product( - "테스트 상품명", - 100_000L, - 10L - ) - ); - - productRepository.flush(); - - // 동시에 주문해야하니까 쓰레드를 100개 - var executorService = Executors.newFixedThreadPool(100); - var countDownLatch = new CountDownLatch(repeatCount); - AtomicInteger successCount = new AtomicInteger(0); - AtomicInteger failureCount = new AtomicInteger(0); - - for (int i = 0; i < repeatCount; i++) { - int finalI = i; - executorService.submit(() -> { - try { - var targetUser = users.get(finalI); - orderService.create( - targetUser.getId(), - product.getId(), - 1L, - "수신자 주소-" + finalI, - "010-1111-22" + finalI, - targetUser.getName() - ); - successCount.incrementAndGet(); - } catch (RuntimeException e) { - e.printStackTrace(); - failureCount.incrementAndGet(); - } finally { - countDownLatch.countDown(); - } - }); - } - - countDownLatch.await(); - executorService.shutdown(); - - var foundedProduct = productRepository.findByIdOrThrow(product.getId()); - - // 1번쓰레드에서 작업하다가 언락 - // 2번쓰레드에서 작업하다가 언락 - - // assertThat(successCount.get()).isEqualTo(10); - // assertThat(failureCount.get()).isEqualTo(490); - // assertThat(foundedProduct.getStock()).isEqualTo(0); - } + // @Test + // void 동시에_100명_주문() throws Exception { + // var repeatCount = 500; + // var userList = new ArrayList(); + // for (int i = 0; i < repeatCount; i++) { + // userList.add(new User( + // "testuser-" + i, + // "password", + // "Test User-" + i, + // "email-" + i, + // "010-0000-000" + i, + // Gender.MALE, + // Role.USER, + // LocalDate.now() + // )); + // } + // + // var users = userRepository.saveAll(userList); + // + // var product = productRepository.save( + // new Product( + // "테스트 상품명", + // 100_000L, + // 10L + // ) + // ); + // + // productRepository.flush(); + // + // // 동시에 주문해야하니까 쓰레드를 100개 + // var executorService = Executors.newFixedThreadPool(100); + // var countDownLatch = new CountDownLatch(repeatCount); + // AtomicInteger successCount = new AtomicInteger(0); + // AtomicInteger failureCount = new AtomicInteger(0); + // + // for (int i = 0; i < repeatCount; i++) { + // int finalI = i; + // executorService.submit(() -> { + // try { + // var targetUser = users.get(finalI); + // orderService.create( + // targetUser.getId(), + // product.getId(), + // 1L, + // "수신자 주소-" + finalI, + // "010-1111-22" + finalI, + // targetUser.getName() + // ); + // successCount.incrementAndGet(); + // } catch (RuntimeException e) { + // e.printStackTrace(); + // failureCount.incrementAndGet(); + // } finally { + // countDownLatch.countDown(); + // } + // }); + // } + // + // countDownLatch.await(); + // executorService.shutdown(); + // + // var foundedProduct = productRepository.findByIdOrThrow(product.getId()); + // + // // 1번쓰레드에서 작업하다가 언락 + // // 2번쓰레드에서 작업하다가 언락 + // + // // assertThat(successCount.get()).isEqualTo(10); + // // assertThat(failureCount.get()).isEqualTo(490); + // // assertThat(foundedProduct.getStock()).isEqualTo(0); + // } } \ No newline at end of file From 36ef18963035b402ae86be093d8d658dcce047da Mon Sep 17 00:00:00 2001 From: terry Date: Thu, 11 Dec 2025 00:52:10 +0900 Subject: [PATCH 09/19] =?UTF-8?q?fix:=20application-test.yml=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index 79119f9..179b4a5 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -13,11 +13,11 @@ spring: # validate = 테이블이랑 entity랑 맞는지 확인만 # none = 아무것도 안함 # create-drop = create랑 똑같은데, 애플리케이션 종료시점에 테이블 drop => 테스트코드에서만 쓰세요 - ddl-auto: update + ddl-auto: create-drop properties: hibernate: format_sql: true # SQL문을 보기 좋게 출력 - # dialect: org.hibernate.dialect.MySQL5InnoDBDialect + dialect: org.hibernate.dialect.MySQLDialect jdbc: time_zone: Asia/Seoul show-sql: true From 518bea50cd98a3a9cdd4d775f6bae8332b49feba Mon Sep 17 00:00:00 2001 From: terry Date: Thu, 11 Dec 2025 00:57:41 +0900 Subject: [PATCH 10/19] =?UTF-8?q?fix:=20application-test.yml=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 11 ++++++----- src/main/resources/application-test.yml | 18 +++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b862e7..692c756 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,18 +7,19 @@ env: jobs: pr-test: runs-on: ubuntu-latest + steps: - uses: actions/checkout@main - - name: Start Redis Service - uses: supercharge/redis-github-action@1.4.0 + - name: Start Redis + uses: supercharge/redis-github-action@1.1.0 with: redis-version: 6 - - name: Start MySQL Service + - name: Start Mysql Service run: | sudo /etc/init.d/mysql start - mysql -e 'CREATE DATABASE shopping;' -uroot -proot + mysql -e 'CREATE DATABASE shoppingtest;' -uroot -proot - name: Set up JDK 21 uses: actions/setup-java@main @@ -27,7 +28,7 @@ jobs: cache: 'gradle' distribution: 'temurin' - - name: Set up Gradle + - name: Setup Gradle uses: gradle/gradle-build-action@v3 with: gradle-version: 8.5 diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index 179b4a5..bc1355c 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -1,25 +1,25 @@ spring: - ### mysql 드라이버 설정 ### datasource: url: jdbc:mysql://localhost:3306/shopping username: root - password: ${DB_PASSWORD:1234} + password: ${db.password:1234} driver-class-name: com.mysql.cj.jdbc.Driver - ### jpa 설정 ### jpa: hibernate: - # create = 테이블을 만들기만 - # update = 테이블 없으면 만들고, entity랑 다르면 수정 -> 삭제는 안해줌 - # validate = 테이블이랑 entity랑 맞는지 확인만 - # none = 아무것도 안함 - # create-drop = create랑 똑같은데, 애플리케이션 종료시점에 테이블 drop => 테스트코드에서만 쓰세요 + #create = 테이블을 만들기만 + #update = 테이블 없으면 만들고 있지만 entity랑 다르면 수정 -> 삭제는 안해줌 + #validate = 테이블이랑 entity랑 맞는지 확인만 + #none = 아무것도 안함 + #create-drop = create랑 똑같은데 애플리케이션 종료시점에 테이블을 drop함 => 테스트코드에서만 쓰세요 ddl-auto: create-drop properties: hibernate: - format_sql: true # SQL문을 보기 좋게 출력 + format_sql: true dialect: org.hibernate.dialect.MySQLDialect jdbc: time_zone: Asia/Seoul + show_sql: true #로컬에서만 + # default_batch_fetch_size: 2 show-sql: true data: redis: From 15b40824f6cf6fd11c06a1fc3ea5d5739355b00f Mon Sep 17 00:00:00 2001 From: terry Date: Thu, 11 Dec 2025 01:04:46 +0900 Subject: [PATCH 11/19] =?UTF-8?q?fix:=20application-test.yml=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index bc1355c..4d31ce9 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -1,6 +1,6 @@ spring: datasource: - url: jdbc:mysql://localhost:3306/shopping + url: jdbc:mysql://localhost:3306/shoppingtest username: root password: ${db.password:1234} driver-class-name: com.mysql.cj.jdbc.Driver From b2ab0bd0d03056c27c0b29f1146f07c76393b213 Mon Sep 17 00:00:00 2001 From: terry Date: Thu, 11 Dec 2025 01:11:18 +0900 Subject: [PATCH 12/19] =?UTF-8?q?fix:=20application-test.yml=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/kt/ShoppingApplicationTests.java | 2 + .../com/kt/domain/product/ProductTest.java | 2 + .../kt/repository/ProductRepositoryTest.java | 145 +++++++++-------- .../kt/service/order/OrderServiceTest.java | 146 +++++++++--------- 4 files changed, 159 insertions(+), 136 deletions(-) diff --git a/src/test/java/com/kt/ShoppingApplicationTests.java b/src/test/java/com/kt/ShoppingApplicationTests.java index e0fd926..1bcec29 100644 --- a/src/test/java/com/kt/ShoppingApplicationTests.java +++ b/src/test/java/com/kt/ShoppingApplicationTests.java @@ -2,7 +2,9 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +@ActiveProfiles("test") @SpringBootTest class ShoppingApplicationTests { diff --git a/src/test/java/com/kt/domain/product/ProductTest.java b/src/test/java/com/kt/domain/product/ProductTest.java index 506fdf1..65992e4 100644 --- a/src/test/java/com/kt/domain/product/ProductTest.java +++ b/src/test/java/com/kt/domain/product/ProductTest.java @@ -3,9 +3,11 @@ import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; +import org.springframework.test.context.ActiveProfiles; import com.kt.common.exception.CustomException; +@ActiveProfiles("test") class ProductTest { @Test diff --git a/src/test/java/com/kt/repository/ProductRepositoryTest.java b/src/test/java/com/kt/repository/ProductRepositoryTest.java index a25ec00..1b15e67 100644 --- a/src/test/java/com/kt/repository/ProductRepositoryTest.java +++ b/src/test/java/com/kt/repository/ProductRepositoryTest.java @@ -1,11 +1,23 @@ package com.kt.repository; +import static org.assertj.core.api.Assertions.*; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicInteger; + +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import com.kt.domain.product.Product; +import com.kt.domain.user.Gender; +import com.kt.domain.user.Role; +import com.kt.domain.user.User; import com.kt.service.order.OrderService; @SpringBootTest @@ -34,70 +46,71 @@ class ProductRepositoryTest { // assertEquals(productName, foundProduct.getName()); } - // @Test - // void 동시에_100명_주문() throws InterruptedException { - // var userList = new ArrayList(); - // for (int i = 0; i < 100; i++) { - // userList.add(new User( - // "testuser-" + i, - // "password", - // "Test User-" + i, - // "email-" + i, - // "010-0000-000" + i, - // Gender.MALE, - // Role.USER, - // LocalDate.now() - // )); - // } - // - // var users = userRepository.saveAll(userList); - // - // var product = productRepository.save( - // new Product( - // "테스트 상품명", - // 100_000L, - // 10L - // ) - // ); - // - // productRepository.flush(); - // - // // 동시에 주문해야하니까 쓰레드를 100개 - // var executorService = Executors.newFixedThreadPool(100); - // var countDownLatch = new CountDownLatch(100); - // AtomicInteger successCount = new AtomicInteger(0); - // AtomicInteger failureCount = new AtomicInteger(0); - // - // for (int i = 0; i < 100; i++) { - // int finalI = i; - // executorService.submit(() -> { - // try { - // var targetUser = users.get(finalI); - // orderService.create( - // targetUser.getId(), - // product.getId(), - // 1L, - // targetUser.getName(), - // "수신자 주소-" + finalI, - // "010-1111-22" + finalI - // ); - // successCount.incrementAndGet(); - // } catch (RuntimeException e) { - // e.printStackTrace(); - // failureCount.incrementAndGet(); - // } finally { - // countDownLatch.countDown(); - // } - // }); - // } - // - // countDownLatch.await(); - // executorService.shutdown(); - // - // var foundedProduct = productRepository.findByIdOrThrow(product.getId()); - // - // assertThat(successCount.get()).isEqualTo(10); - // assertThat(failureCount.get()).isEqualTo(90); - // assertThat(foundedProduct.getStock()).isEqualTo(0); - // } + @Test + @Disabled + void 동시에_100명_주문() throws InterruptedException { + var userList = new ArrayList(); + for (int i = 0; i < 100; i++) { + userList.add(new User( + "testuser-" + i, + "password", + "Test User-" + i, + "email-" + i, + "010-0000-000" + i, + Gender.MALE, + Role.USER, + LocalDate.now() + )); + } + + var users = userRepository.saveAll(userList); + + var product = productRepository.save( + new Product( + "테스트 상품명", + 100_000L, + 10L + ) + ); + + productRepository.flush(); + + // 동시에 주문해야하니까 쓰레드를 100개 + var executorService = Executors.newFixedThreadPool(100); + var countDownLatch = new CountDownLatch(100); + AtomicInteger successCount = new AtomicInteger(0); + AtomicInteger failureCount = new AtomicInteger(0); + + for (int i = 0; i < 100; i++) { + int finalI = i; + executorService.submit(() -> { + try { + var targetUser = users.get(finalI); + orderService.create( + targetUser.getId(), + product.getId(), + 1L, + targetUser.getName(), + "수신자 주소-" + finalI, + "010-1111-22" + finalI + ); + successCount.incrementAndGet(); + } catch (RuntimeException e) { + e.printStackTrace(); + failureCount.incrementAndGet(); + } finally { + countDownLatch.countDown(); + } + }); + } + + countDownLatch.await(); + executorService.shutdown(); + + var foundedProduct = productRepository.findByIdOrThrow(product.getId()); + + assertThat(successCount.get()).isEqualTo(10); + assertThat(failureCount.get()).isEqualTo(90); + assertThat(foundedProduct.getStock()).isEqualTo(0); + } } \ No newline at end of file diff --git a/src/test/java/com/kt/service/order/OrderServiceTest.java b/src/test/java/com/kt/service/order/OrderServiceTest.java index 2f0fbe1..1743ed2 100644 --- a/src/test/java/com/kt/service/order/OrderServiceTest.java +++ b/src/test/java/com/kt/service/order/OrderServiceTest.java @@ -3,8 +3,13 @@ import static org.assertj.core.api.Assertions.*; import java.time.LocalDate; +import java.util.ArrayList; import java.util.Optional; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -75,74 +80,75 @@ class OrderServiceTest { assertThat(foundOrder).isPresent(); } - // @Test - // void 동시에_100명_주문() throws Exception { - // var repeatCount = 500; - // var userList = new ArrayList(); - // for (int i = 0; i < repeatCount; i++) { - // userList.add(new User( - // "testuser-" + i, - // "password", - // "Test User-" + i, - // "email-" + i, - // "010-0000-000" + i, - // Gender.MALE, - // Role.USER, - // LocalDate.now() - // )); - // } - // - // var users = userRepository.saveAll(userList); - // - // var product = productRepository.save( - // new Product( - // "테스트 상품명", - // 100_000L, - // 10L - // ) - // ); - // - // productRepository.flush(); - // - // // 동시에 주문해야하니까 쓰레드를 100개 - // var executorService = Executors.newFixedThreadPool(100); - // var countDownLatch = new CountDownLatch(repeatCount); - // AtomicInteger successCount = new AtomicInteger(0); - // AtomicInteger failureCount = new AtomicInteger(0); - // - // for (int i = 0; i < repeatCount; i++) { - // int finalI = i; - // executorService.submit(() -> { - // try { - // var targetUser = users.get(finalI); - // orderService.create( - // targetUser.getId(), - // product.getId(), - // 1L, - // "수신자 주소-" + finalI, - // "010-1111-22" + finalI, - // targetUser.getName() - // ); - // successCount.incrementAndGet(); - // } catch (RuntimeException e) { - // e.printStackTrace(); - // failureCount.incrementAndGet(); - // } finally { - // countDownLatch.countDown(); - // } - // }); - // } - // - // countDownLatch.await(); - // executorService.shutdown(); - // - // var foundedProduct = productRepository.findByIdOrThrow(product.getId()); - // - // // 1번쓰레드에서 작업하다가 언락 - // // 2번쓰레드에서 작업하다가 언락 - // - // // assertThat(successCount.get()).isEqualTo(10); - // // assertThat(failureCount.get()).isEqualTo(490); - // // assertThat(foundedProduct.getStock()).isEqualTo(0); - // } + @Test + @Disabled + void 동시에_100명_주문() throws Exception { + var repeatCount = 500; + var userList = new ArrayList(); + for (int i = 0; i < repeatCount; i++) { + userList.add(new User( + "testuser-" + i, + "password", + "Test User-" + i, + "email-" + i, + "010-0000-000" + i, + Gender.MALE, + Role.USER, + LocalDate.now() + )); + } + + var users = userRepository.saveAll(userList); + + var product = productRepository.save( + new Product( + "테스트 상품명", + 100_000L, + 10L + ) + ); + + productRepository.flush(); + + // 동시에 주문해야하니까 쓰레드를 100개 + var executorService = Executors.newFixedThreadPool(100); + var countDownLatch = new CountDownLatch(repeatCount); + AtomicInteger successCount = new AtomicInteger(0); + AtomicInteger failureCount = new AtomicInteger(0); + + for (int i = 0; i < repeatCount; i++) { + int finalI = i; + executorService.submit(() -> { + try { + var targetUser = users.get(finalI); + orderService.create( + targetUser.getId(), + product.getId(), + 1L, + "수신자 주소-" + finalI, + "010-1111-22" + finalI, + targetUser.getName() + ); + successCount.incrementAndGet(); + } catch (RuntimeException e) { + e.printStackTrace(); + failureCount.incrementAndGet(); + } finally { + countDownLatch.countDown(); + } + }); + } + + countDownLatch.await(); + executorService.shutdown(); + + var foundedProduct = productRepository.findByIdOrThrow(product.getId()); + + // 1번쓰레드에서 작업하다가 언락 + // 2번쓰레드에서 작업하다가 언락 + + // assertThat(successCount.get()).isEqualTo(10); + // assertThat(failureCount.get()).isEqualTo(490); + // assertThat(foundedProduct.getStock()).isEqualTo(0); + } } \ No newline at end of file From 96ba115779be4300e7f3b60715a35ce51e2c3e6b Mon Sep 17 00:00:00 2001 From: terry Date: Fri, 12 Dec 2025 01:26:50 +0900 Subject: [PATCH 13/19] fix: update configuration and add test properties --- .github/workflows/ci.yml | 9 ++++ .../com/kt/config/ActiveProfileConfig.java | 29 ++++++------- src/main/resources/application-test.yml | 41 +------------------ src/main/resources/application.yml | 35 ++++++---------- src/test/java/com/kt/ConfigTest.java | 30 ++++++++++++++ 5 files changed, 66 insertions(+), 78 deletions(-) create mode 100644 src/test/java/com/kt/ConfigTest.java diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 692c756..e02dda5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,7 @@ on: pull_request env: DB_PASSWORD: root + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} jobs: pr-test: @@ -39,5 +40,13 @@ jobs: gradle-version: wrapper arguments: test + - name: send slack notification + uses: 8398a7/action-slack@v3 + with: + status: ${{ job.status }} + fields: repo,commit,author,ref,workflow,job,took + author_name: GitHub Actions + if: always() + diff --git a/src/main/java/com/kt/config/ActiveProfileConfig.java b/src/main/java/com/kt/config/ActiveProfileConfig.java index f305b92..2427d67 100644 --- a/src/main/java/com/kt/config/ActiveProfileConfig.java +++ b/src/main/java/com/kt/config/ActiveProfileConfig.java @@ -1,5 +1,6 @@ package com.kt.config; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import lombok.RequiredArgsConstructor; @@ -8,20 +9,16 @@ @RequiredArgsConstructor public class ActiveProfileConfig { - // private final Environment environment; - // - // @TestProfile - // private final TestProperties testProperties; - // - // private final CommonProperties commonProperties; - // - // @Bean - // public String init() { - // System.out.println(commonProperties.commonValue()); - // System.out.println(commonProperties.commonValueParam()); - // System.out.println(testProperties.myValue()); - // System.out.println(testProperties.myValueParam()); - // // System.out.println("Active Profile : " + environment.getActiveProfiles()[0]); - // return ""; - // } + private final TestProperties testProperties; + + private final CommonProperties commonProperties; + + @Bean + public String init() { + System.out.println(commonProperties.commonValue()); + System.out.println(commonProperties.commonValueParam()); + System.out.println(testProperties.myValue()); + System.out.println(testProperties.myValueParam()); + return ""; + } } diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index 4d31ce9..27a481a 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -2,43 +2,4 @@ spring: datasource: url: jdbc:mysql://localhost:3306/shoppingtest username: root - password: ${db.password:1234} - driver-class-name: com.mysql.cj.jdbc.Driver - jpa: - hibernate: - #create = 테이블을 만들기만 - #update = 테이블 없으면 만들고 있지만 entity랑 다르면 수정 -> 삭제는 안해줌 - #validate = 테이블이랑 entity랑 맞는지 확인만 - #none = 아무것도 안함 - #create-drop = create랑 똑같은데 애플리케이션 종료시점에 테이블을 drop함 => 테스트코드에서만 쓰세요 - ddl-auto: create-drop - properties: - hibernate: - format_sql: true - dialect: org.hibernate.dialect.MySQLDialect - jdbc: - time_zone: Asia/Seoul - show_sql: true #로컬에서만 - # default_batch_fetch_size: 2 - show-sql: true - data: - redis: - host: ${redis.host:localhost} - port: ${redis.port:6379} - -jwt: - secret: ${kt.jwt.secret:kt-cloud-shopping-kt-cloud-shopping-kt-cloud-shopping-kt-cloud-shopping} - access-token-expiration: ${kt.jwt.access-token-expiration:3000000} #5분 - refresh-token-expiration: ${kt.jwt.refresh-token-expiration:43200000} #12시간 - -slack: - bot-token: ${slack.token} - log-channel: ${slack.channel} - -common: - common-value: this is common value - common-value-param: this is common value with param - ${COMMON_PARAM:공통} - -test: - my-value: this is test value in normal - my-value-param: this is test value with param - ${TEST_PARAM:terry} \ No newline at end of file + password: ${db.password:1234} \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index b5a8e9b..dac9eed 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,34 +1,25 @@ spring: - ### h2 설정 ### - # h2: - # console: - # enabled: true - # datasource: - # url: jdbc:h2:~/test - # username: sa - # password: - # driver-class-name: org.h2.Driver - ### mysql 드라이버 설정 ### datasource: url: jdbc:mysql://localhost:3306/shopping-sehyeon username: root - password: ${DB_PASSWORD:1234} + password: ${db.password:1234} driver-class-name: com.mysql.cj.jdbc.Driver - ### jpa 설정 ### jpa: hibernate: - # create = 테이블을 만들기만 - # update = 테이블 없으면 만들고, entity랑 다르면 수정 -> 삭제는 안해줌 - # validate = 테이블이랑 entity랑 맞는지 확인만 - # none = 아무것도 안함 - # create-drop = create랑 똑같은데, 애플리케이션 종료시점에 테이블 drop => 테스트코드에서만 쓰세요 - ddl-auto: update + #create = 테이블을 만들기만 + #update = 테이블 없으면 만들고 있지만 entity랑 다르면 수정 -> 삭제는 안해줌 + #validate = 테이블이랑 entity랑 맞는지 확인만 + #none = 아무것도 안함 + #create-drop = create랑 똑같은데 애플리케이션 종료시점에 테이블을 drop함 => 테스트코드에서만 쓰세요 + ddl-auto: create-drop properties: hibernate: - format_sql: true # SQL문을 보기 좋게 출력 - # dialect: org.hibernate.dialect.MySQL5InnoDBDialect + format_sql: true + dialect: org.hibernate.dialect.MySQLDialect jdbc: time_zone: Asia/Seoul + show_sql: true #로컬에서만 + # default_batch_fetch_size: 2 show-sql: true data: redis: @@ -46,8 +37,8 @@ slack: common: common-value: this is common value - common-value-param: this is common value with param - ${COMMON_PARAM:공통} + common-value-param: this is common value with param - ${COMMON_PARAM} test: my-value: this is test value in normal - my-value-param: this is test value with param - ${TEST_PARAM:terry} \ No newline at end of file + my-value-param: this is test value with param - ${TEST_PARAM:default} \ No newline at end of file diff --git a/src/test/java/com/kt/ConfigTest.java b/src/test/java/com/kt/ConfigTest.java new file mode 100644 index 0000000..8b39548 --- /dev/null +++ b/src/test/java/com/kt/ConfigTest.java @@ -0,0 +1,30 @@ +package com.kt; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +import com.kt.config.CommonProperties; +import com.kt.config.TestProperties; + +@ActiveProfiles("test") +@SpringBootTest +public class ConfigTest { + + @Autowired + CommonProperties commonProperties; + + @Autowired + TestProperties testProperties; + + @Test + public void test() { + + System.out.println(commonProperties.commonValue()); + System.out.println(commonProperties.commonValueParam()); + + System.out.println(testProperties.myValue()); + System.out.println(testProperties.myValueParam()); + } +} From 28ce8481954ac2aaf8ae8462bb9711b31a3437e6 Mon Sep 17 00:00:00 2001 From: terry Date: Tue, 16 Dec 2025 09:40:20 +0900 Subject: [PATCH 14/19] fix: test db name --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e02dda5..2c34677 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: - name: Start Mysql Service run: | sudo /etc/init.d/mysql start - mysql -e 'CREATE DATABASE shoppingtest;' -uroot -proot + mysql -e 'CREATE DATABASE shopping-sehyeon;' -uroot -proot - name: Set up JDK 21 uses: actions/setup-java@main From 16a0dd19bfe2b4622b753793998d6e25811c0a45 Mon Sep 17 00:00:00 2001 From: terry Date: Tue, 16 Dec 2025 09:43:08 +0900 Subject: [PATCH 15/19] fix: test db name --- .github/workflows/ci.yml | 2 +- .github/workflows/test.yml | 13 ------------- src/main/resources/application-test.yml | 2 +- 3 files changed, 2 insertions(+), 15 deletions(-) delete mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2c34677..e02dda5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: - name: Start Mysql Service run: | sudo /etc/init.d/mysql start - mysql -e 'CREATE DATABASE shopping-sehyeon;' -uroot -proot + mysql -e 'CREATE DATABASE shoppingtest;' -uroot -proot - name: Set up JDK 21 uses: actions/setup-java@main diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index f295624..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Hello World -on: - workflow_dispatch: - push: - -env: - DB_PASSWORD: root -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@main \ No newline at end of file diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index 27a481a..330adb9 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -1,5 +1,5 @@ spring: datasource: - url: jdbc:mysql://localhost:3306/shoppingtest + url: ${SPRING_DATASOURCE_URL:jdbc:mysql://localhost:3306/shopping-sehyeon} username: root password: ${db.password:1234} \ No newline at end of file From b7aa78f3f19a765726821882161f453c26549de2 Mon Sep 17 00:00:00 2001 From: terry Date: Tue, 16 Dec 2025 10:25:05 +0900 Subject: [PATCH 16/19] fix: .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index c2065bc..dd15cc0 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,6 @@ out/ ### VS Code ### .vscode/ + +/mysql_data +/config \ No newline at end of file From 43b6db5983aff956ce652d1c3df9972a8e98ef1f Mon Sep 17 00:00:00 2001 From: terry Date: Tue, 16 Dec 2025 10:32:32 +0900 Subject: [PATCH 17/19] fix: yml --- src/main/resources/application-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index 330adb9..794632a 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -1,5 +1,5 @@ spring: datasource: - url: ${SPRING_DATASOURCE_URL:jdbc:mysql://localhost:3306/shopping-sehyeon} + url: ${SPRING_DATASOURCE_URL:jdbc:mysql://localhost:3306/shoppingtest} username: root password: ${db.password:1234} \ No newline at end of file From 3d2ccfe5c33b426fd849bb541180b62b0647db28 Mon Sep 17 00:00:00 2001 From: terry Date: Tue, 16 Dec 2025 10:42:56 +0900 Subject: [PATCH 18/19] fix: yml --- .github/workflows/ci.yml | 1 + src/{main => test}/resources/application-test.yml | 0 2 files changed, 1 insertion(+) rename src/{main => test}/resources/application-test.yml (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e02dda5..5369e4d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,7 @@ name: pr-test on: pull_request env: + SPRING_DATASOURCE_URL: ${{ secrets.SPRING_DATASOURCE_URL }} DB_PASSWORD: root SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/src/main/resources/application-test.yml b/src/test/resources/application-test.yml similarity index 100% rename from src/main/resources/application-test.yml rename to src/test/resources/application-test.yml From 081ed557d4ca528e43fc4f06a12de2a447eff9e1 Mon Sep 17 00:00:00 2001 From: terry Date: Tue, 16 Dec 2025 11:19:46 +0900 Subject: [PATCH 19/19] =?UTF-8?q?fix:=20test=20=EC=8B=A4=ED=8C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/com/kt/ConfigTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/kt/ConfigTest.java b/src/test/java/com/kt/ConfigTest.java index 8b39548..74d7e97 100644 --- a/src/test/java/com/kt/ConfigTest.java +++ b/src/test/java/com/kt/ConfigTest.java @@ -13,7 +13,7 @@ public class ConfigTest { @Autowired - CommonProperties commonProperties; + CommonProperties commonProperties @Autowired TestProperties testProperties;