From e89bed87104bc961dcf98175829c7a9e0a1f35ef Mon Sep 17 00:00:00 2001 From: geneaky Date: Sun, 6 Oct 2024 00:25:52 +0900 Subject: [PATCH] remove: flyway --- build.gradle | 1 - .../bookchat/localtest/LocalTestConfig.java | 17 +----- .../rest/bookshelf/BookShelfAPI.http | 15 ++--- .../db/{migration/V1__init.sql => ddl.sql} | 59 ++++++++++--------- .../db/migration/V2_1__column_size.sql | 15 ----- .../V2__remove_host_id_in_chatroom.sql | 1 - .../service/ChatServiceConcurrentTest.java | 24 ++++---- .../ParticipantServiceConcurrentTest.java | 27 ++------- src/test/resources/application.yaml | 7 ++- 9 files changed, 66 insertions(+), 100 deletions(-) rename src/main/resources/db/{migration/V1__init.sql => ddl.sql} (80%) delete mode 100644 src/main/resources/db/migration/V2_1__column_size.sql delete mode 100644 src/main/resources/db/migration/V2__remove_host_id_in_chatroom.sql diff --git a/build.gradle b/build.gradle index 6f123ec0..ed2bea25 100644 --- a/build.gradle +++ b/build.gradle @@ -68,7 +68,6 @@ dependencies { implementation "com.querydsl:querydsl-jpa:${queryDslVersion}" implementation "com.querydsl:querydsl-apt:${queryDslVersion}" implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.8.1' - implementation 'org.flywaydb:flyway-core' runtimeOnly 'mysql:mysql-connector-java' implementation 'org.springframework.boot:spring-boot-starter-security' diff --git a/src/main/java/toy/bookchat/bookchat/localtest/LocalTestConfig.java b/src/main/java/toy/bookchat/bookchat/localtest/LocalTestConfig.java index 5f726d32..d633fd8d 100644 --- a/src/main/java/toy/bookchat/bookchat/localtest/LocalTestConfig.java +++ b/src/main/java/toy/bookchat/bookchat/localtest/LocalTestConfig.java @@ -4,15 +4,13 @@ import java.util.List; import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import org.flywaydb.core.Flyway; import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; -import toy.bookchat.bookchat.domain.user.ROLE; -import toy.bookchat.bookchat.domain.user.ReadingTaste; import toy.bookchat.bookchat.db_module.user.UserEntity; import toy.bookchat.bookchat.db_module.user.repository.UserRepository; +import toy.bookchat.bookchat.domain.user.ROLE; +import toy.bookchat.bookchat.domain.user.ReadingTaste; import toy.bookchat.bookchat.security.oauth.OAuth2Provider; import toy.bookchat.bookchat.security.token.jwt.JwtTokenManager; import toy.bookchat.bookchat.security.user.TokenPayload; @@ -23,18 +21,14 @@ public class LocalTestConfig implements JwtTokenManager { private final UserRepository userRepository; - private final Flyway flyway; private UserEntity userEntity; - public LocalTestConfig(UserRepository userRepository, Flyway flyway) { + public LocalTestConfig(UserRepository userRepository) { this.userRepository = userRepository; - this.flyway = flyway; } @PostConstruct public void init() { - flyway.clean(); - flyway.migrate(); userEntity = UserEntity.builder() .name("google123") .nickname("geneaky") @@ -49,11 +43,6 @@ public void init() { userRepository.save(userEntity); } - @PreDestroy - public void finalize() { - userRepository.deleteAll(); - } - @Override public String extractTokenFromAuthorizationHeader(String header) { return null; diff --git a/src/main/java/toy/bookchat/bookchat/localtest/rest/bookshelf/BookShelfAPI.http b/src/main/java/toy/bookchat/bookchat/localtest/rest/bookshelf/BookShelfAPI.http index 8b2c4fe8..a8df5778 100644 --- a/src/main/java/toy/bookchat/bookchat/localtest/rest/bookshelf/BookShelfAPI.http +++ b/src/main/java/toy/bookchat/bookchat/localtest/rest/bookshelf/BookShelfAPI.http @@ -1,18 +1,19 @@ ### 서재에 책 등록 POST localhost:8080/v1/api/bookshelves -Authorization: {{jwt_token}} +#Authorization: {{jwt_token}} +Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJCb29rQ2hhdCIsImRlZmF1bHRQcm9maWxlSW1hZ2VUeXBlIjoxLCJwcm92aWRlciI6Imdvb2dsZSIsInVzZXJOaWNrbmFtZSI6Iu2VnOudvOu0iTIyIiwidXNlck5hbWUiOiIxMDE3MzM1MTIzNDA3MjA5ODU1OTRnb29nbGUiLCJ1c2VyUHJvZmlsZUltYWdlVXJpIjoiaHR0cHM6Ly9ib29rY2hhdC1vcmlnaW5hbC5zMy5hcC1ub3J0aGVhc3QtMi5hbWF6b25hd3MuY29tL3VzZXJfcHJvZmlsZV9pbWFnZS8zMi05MC00MjAyN2Q1MzJjNDAtZTliNi00M2FiLTljYTMtNzViMDQ1OWE2YzBjLndlYnAiLCJ1c2VyUm9sZSI6IlJPTEVfVVNFUiIsImV4cCI6MTcyODEzNzUzNCwidXNlcklkIjoiMSIsImVtYWlsIjpudWxsfQ.2HpnEuxn2IqiOnCUJATGe2sY62KgFdHDEUZ6H0wf5Qc Content-Type: application/json { "bookRequest": { - "isbn": "1162240035 9791162240038", - "title": "Effective C#(이펙티브5)", + "isbn": "1156640199 9791156640196", + "title": "디자인 시스템 실무 with 피그마", "authors": [ - "빌 와그너" + "이영주" ], - "publisher": "한빛미디어", - "bookCoverImageUrl": "https://search1.kakaocdn.net/thumb/R120x174.q85/?fname=http%3A%2F%2Ft1.daumcdn.net%2Flbook%2Fimage%2F1611826%3Ftimestamp%3D20221107221559", - "publishAt": "2017-11-06" + "publisher": "한빛아카데미", + "publishAt": "2024-02-09", + "bookCoverImageUrl": "https://search1.kakaocdn.net/thumb/R120x174.q85/?fname=http%3A%2F%2Ft1.daumcdn.net%2Flbook%2Fimage%2F6558820%3Ftimestamp%3D20241001160358" }, "readingStatus": "READING", "star": null diff --git a/src/main/resources/db/migration/V1__init.sql b/src/main/resources/db/ddl.sql similarity index 80% rename from src/main/resources/db/migration/V1__init.sql rename to src/main/resources/db/ddl.sql index 0b4e085d..4230e035 100644 --- a/src/main/resources/db/migration/V1__init.sql +++ b/src/main/resources/db/ddl.sql @@ -1,10 +1,14 @@ +drop schema if exists test; +create schema test; +use test; + create table user ( id bigint auto_increment primary key, name varchar(255) null, provider varchar(255) null, email varchar(255) null, - nickname varchar(255) null, + nickname varchar(20) null, default_profile_image_type int null, profile_image_url varchar(255) null, role int null, @@ -14,7 +18,7 @@ create table user constraint uk_user_nickname unique (nickname) ); -create table refresh_token +create table if not exists refresh_token ( id bigint auto_increment primary key, user_id bigint null, @@ -24,14 +28,14 @@ create table refresh_token constraint uk_refresh_token_user_id unique (user_id) ); -create table user_reading_tastes +create table if not exists user_reading_tastes ( user_id bigint not null, reading_tastes int null, constraint fk_user_reading_tastes_user_id foreign key (user_id) references user (id) ); -create table book +create table if not exists book ( id bigint auto_increment primary key, isbn varchar(255) not null, @@ -44,13 +48,13 @@ create table book constraint uq_book_isbn_publish_at unique (isbn, publish_at) ); -create table book_authors ( - book_id bigint not null, - authors varchar(255), - constraint fk_book_authors_book_id foreign key (book_id) references book (id) +create table if not exists book_authors ( + book_id bigint not null, + authors varchar(255), + constraint fk_book_authors_book_id foreign key (book_id) references book (id) ); -create table book_shelf +create table if not exists book_shelf ( id bigint auto_increment primary key, book_id bigint not null, @@ -63,33 +67,32 @@ create table book_shelf constraint uq_book_shelf_user_id_book_id unique (user_id, book_id) ); -create table agony +create table if not exists agony ( id bigint auto_increment primary key, book_shelf_id bigint not null, - title varchar(255) null, + title varchar(500) null, hex_color_code varchar(255) null, created_at datetime(6) null, updated_at datetime(6) null ); -create table agony_record +create table if not exists agony_record ( id bigint auto_increment primary key, agony_id bigint not null, - title varchar(255) null, - content varchar(255) null, + title varchar(500) null, + content text null, created_at datetime(6) null, updated_at datetime(6) null ); -create table chat_room +create table if not exists chat_room ( id bigint auto_increment primary key, book_id bigint not null, - host_id bigint not null, room_sid varchar(255) null, - room_name varchar(255) null, + room_name varchar(30) null, room_size int not null, default_room_image_type int not null, room_image_uri varchar(255) null, @@ -98,18 +101,18 @@ create table chat_room constraint uk_chat_room_room_sid unique (room_sid) ); -create table hash_tag +create table if not exists hash_tag ( id bigint auto_increment primary key, created_at datetime(6) null, updated_at datetime(6) null, - tag_name varchar(255) null, + tag_name varchar(50) null, constraint uk_hash_tag_tag_name unique (tag_name) ); -create table chat_room_hash_tag +create table if not exists chat_room_hash_tag ( id bigint auto_increment primary key, chat_room_id bigint not null, @@ -119,7 +122,7 @@ create table chat_room_hash_tag constraint uk_chat_room_hash_tag_chat_room_id_hash_tag_id unique (chat_room_id, hash_tag_id) ); -create table chat_room_blocked_user +create table if not exists chat_room_blocked_user ( id bigint auto_increment primary key, chat_room_id bigint not null, @@ -127,7 +130,7 @@ create table chat_room_blocked_user constraint uk_chat_room_blocked_user_user_id_chat_room_id unique (user_id, chat_room_id) ); -create table chat +create table if not exists chat ( id bigint auto_increment primary key, chat_room_id bigint not null, @@ -137,7 +140,7 @@ create table chat updated_at datetime(6) null ); -create table participant +create table if not exists participant ( id bigint auto_increment primary key, chat_room_id bigint not null, @@ -147,17 +150,17 @@ create table participant constraint uk_participant_user_id_chat_room_id unique (user_id, chat_room_id) ); -create table book_report +create table if not exists book_report ( id bigint auto_increment primary key, book_shelf_id bigint not null, - title varchar(255) null, - content longtext null, + title varchar(500) null, + content text null, created_at datetime(6) null, updated_at datetime(6) null ); -create table device +create table if not exists device ( id bigint auto_increment primary key, user_id bigint not null, @@ -167,7 +170,7 @@ create table device updated_at datetime(6) null ); -create table scrap +create table if not exists scrap ( id bigint auto_increment primary key, book_shelf_id bigint not null, diff --git a/src/main/resources/db/migration/V2_1__column_size.sql b/src/main/resources/db/migration/V2_1__column_size.sql deleted file mode 100644 index 1a99a901..00000000 --- a/src/main/resources/db/migration/V2_1__column_size.sql +++ /dev/null @@ -1,15 +0,0 @@ -alter table agony modify title varchar(500) null; - -alter table agony_record modify title varchar(500) null; - -alter table agony_record modify content text null; - -alter table hash_tag modify tag_name varchar(50) null; - -alter table chat_room modify room_name varchar(30) null; - -alter table book_report modify title varchar(500) null; - -alter table book_report modify content text null; - -alter table user modify nickname varchar(20) null; \ No newline at end of file diff --git a/src/main/resources/db/migration/V2__remove_host_id_in_chatroom.sql b/src/main/resources/db/migration/V2__remove_host_id_in_chatroom.sql deleted file mode 100644 index 72d92037..00000000 --- a/src/main/resources/db/migration/V2__remove_host_id_in_chatroom.sql +++ /dev/null @@ -1 +0,0 @@ -alter table chat_room drop column host_id; \ No newline at end of file diff --git a/src/test/java/toy/bookchat/bookchat/domain/chat/service/ChatServiceConcurrentTest.java b/src/test/java/toy/bookchat/bookchat/domain/chat/service/ChatServiceConcurrentTest.java index 3e62f3fe..fa814bf6 100644 --- a/src/test/java/toy/bookchat/bookchat/domain/chat/service/ChatServiceConcurrentTest.java +++ b/src/test/java/toy/bookchat/bookchat/domain/chat/service/ChatServiceConcurrentTest.java @@ -1,8 +1,8 @@ package toy.bookchat.bookchat.domain.chat.service; import static org.assertj.core.api.Assertions.assertThat; -import static toy.bookchat.bookchat.support.Status.ACTIVE; import static toy.bookchat.bookchat.domain.participant.ParticipantStatus.HOST; +import static toy.bookchat.bookchat.support.Status.ACTIVE; import java.time.LocalDate; import java.util.ArrayList; @@ -11,6 +11,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -47,11 +48,20 @@ class ChatServiceConcurrentTest { @MockBean private MessagePublisher messagePublisher; + @BeforeEach + public void tearDown() { + userRepository.deleteAll(); + bookRepository.deleteAllInBatch(); + chatRoomRepository.deleteAllInBatch(); + chatRepository.deleteAllInBatch(); + participantRepository.deleteAllInBatch(); + } + @Test @DisplayName("제한된 인원수 채팅방 입장 동시성 테스트 성공") void enterChatRoom() throws Exception { - int roomSize = 5; - int count = 10; + int roomSize = 3; + int count = 5; BookEntity bookEntity = BookEntity.builder() .isbn("4640485366") @@ -99,7 +109,7 @@ void enterChatRoom() throws Exception { userRepository.saveAll(userEntityList); CountDownLatch countDownLatch = new CountDownLatch(count); - ExecutorService executorService = Executors.newFixedThreadPool(10); + ExecutorService executorService = Executors.newFixedThreadPool(count); AtomicInteger result = new AtomicInteger(0); for (UserEntity userEntity : userEntityList) { executorService.execute(() -> { @@ -115,12 +125,6 @@ void enterChatRoom() throws Exception { countDownLatch.await(); assertThat(result.get()).isEqualTo(roomSize - 1); - - userRepository.deleteAll(); - bookRepository.deleteAllInBatch(); - chatRoomRepository.deleteAllInBatch(); - chatRepository.deleteAllInBatch(); - participantRepository.deleteAllInBatch(); } } diff --git a/src/test/java/toy/bookchat/bookchat/domain/participant/service/ParticipantServiceConcurrentTest.java b/src/test/java/toy/bookchat/bookchat/domain/participant/service/ParticipantServiceConcurrentTest.java index 09695ac7..7389fafa 100644 --- a/src/test/java/toy/bookchat/bookchat/domain/participant/service/ParticipantServiceConcurrentTest.java +++ b/src/test/java/toy/bookchat/bookchat/domain/participant/service/ParticipantServiceConcurrentTest.java @@ -10,11 +10,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import lombok.extern.slf4j.Slf4j; -import org.flywaydb.core.Flyway; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -27,13 +23,12 @@ import toy.bookchat.bookchat.db_module.user.UserEntity; import toy.bookchat.bookchat.db_module.user.repository.UserRepository; import toy.bookchat.bookchat.domain.participant.ParticipantStatus; -import toy.bookchat.bookchat.infrastructure.rabbitmq.MessagePublisher; import toy.bookchat.bookchat.infrastructure.fcm.service.PushService; +import toy.bookchat.bookchat.infrastructure.rabbitmq.MessagePublisher; import toy.bookchat.bookchat.security.oauth.OAuth2Provider; @Slf4j @SpringBootTest -@TestInstance(TestInstance.Lifecycle.PER_CLASS) class ParticipantServiceConcurrentTest { @Autowired @@ -46,8 +41,6 @@ class ParticipantServiceConcurrentTest { private BookRepository bookRepository; @Autowired private ChatRoomRepository chatRoomRepository; - @Autowired - private Flyway flyway; @MockBean private MessagePublisher messagePublisher; @MockBean @@ -55,18 +48,6 @@ class ParticipantServiceConcurrentTest { @MockBean private FirebaseMessaging firebaseMessaging; - @BeforeAll - public void tearUp() { - flyway.clean(); - flyway.migrate(); - } - - @AfterAll - public void tearDown() { - flyway.clean(); - flyway.migrate(); - } - @Test void 게스트_방장_위임_동시성_테스트() throws Exception { int count = 50; @@ -92,7 +73,6 @@ public void tearDown() { bookRepository.save(bookEntity); ChatRoomEntity chatRoomEntity = ChatRoomEntity.builder() -// .hostId(userEntityList.get(0).getId()) .bookId(bookEntity.getId()) .defaultRoomImageType(1) .roomSize(200) @@ -140,5 +120,10 @@ public void tearDown() { .filter(p -> p.getParticipantStatus() == ParticipantStatus.HOST).count(); assertThat(hostCount).isOne(); + + participantRepository.deleteAllInBatch(); + chatRoomRepository.deleteAllInBatch(); + userRepository.deleteAll(); + bookRepository.deleteAllInBatch(); } } \ No newline at end of file diff --git a/src/test/resources/application.yaml b/src/test/resources/application.yaml index fa071498..b8d2dd6d 100644 --- a/src/test/resources/application.yaml +++ b/src/test/resources/application.yaml @@ -9,9 +9,10 @@ spring: hibernate: default_batch_fetch_size: 100 open-in-view: false - flyway: - enabled: true - baseline-on-migrate: true + sql: + init: + mode: always + schema-locations: classpath:db/test_ddl.sql decorator: datasource: