Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NO-JIRA] dev deploy 5th #206

Merged
merged 5 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/dev-build-and-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- main
- dev

pull_request:
branches:
- main
Expand Down
Original file line number Diff line number Diff line change
@@ -1,119 +1,119 @@
package org.depromeet.spot.application;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicLong;

import org.depromeet.spot.domain.member.Level;
import org.depromeet.spot.domain.member.Member;
import org.depromeet.spot.domain.member.enums.MemberRole;
import org.depromeet.spot.domain.member.enums.SnsProvider;
import org.depromeet.spot.domain.review.Review;
import org.depromeet.spot.usecase.port.in.review.ReadReviewUsecase;
import org.depromeet.spot.usecase.port.out.member.LevelRepository;
import org.depromeet.spot.usecase.port.out.member.MemberRepository;
import org.depromeet.spot.usecase.service.review.like.ReviewLikeService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
import org.springframework.test.context.jdbc.SqlGroup;
import org.springframework.transaction.annotation.Transactional;
import org.testcontainers.junit.jupiter.Testcontainers;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@SpringBootTest
@Testcontainers
@ActiveProfiles("test")
@TestPropertySource("classpath:application-test.yml")
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@SqlGroup({
@Sql(
value = "/sql/delete-data-after-review-like.sql",
executionPhase = ExecutionPhase.AFTER_TEST_METHOD),
@Sql(
value = "/sql/review-like-service-data.sql",
executionPhase = ExecutionPhase.BEFORE_TEST_METHOD),
})
class ReviewLikeServiceTest {

@Autowired private ReviewLikeService reviewLikeService;

@Autowired private ReadReviewUsecase readReviewUsecase;

@Autowired private MemberRepository memberRepository;

@Autowired private LevelRepository levelRepository;

private static final int NUMBER_OF_THREAD = 100;

@BeforeEach
@Transactional
void init() {
Level level = levelRepository.findByValue(0);
AtomicLong memberIdGenerator = new AtomicLong(1);

for (int i = 0; i < NUMBER_OF_THREAD; i++) {
long memberId = memberIdGenerator.getAndIncrement();
memberRepository.save(
Member.builder()
.id(memberId)
.snsProvider(SnsProvider.KAKAO)
.teamId(1L)
.role(MemberRole.ROLE_ADMIN)
.idToken("idToken" + memberId)
.nickname(String.valueOf(memberId))
.phoneNumber(String.valueOf(memberId))
.email("email" + memberId)
.build(),
level);
}
}

@Test
void λ©€ν‹°_μŠ€λ ˆλ“œ_ν™˜κ²½μ—μ„œ_리뷰_곡감_수λ₯Ό_μ •μƒμ μœΌλ‘œ_μ¦κ°€μ‹œν‚¬_수_μžˆλ‹€() throws InterruptedException {
// given
final long reviewId = 1L;
AtomicLong memberIdGenerator = new AtomicLong(1);
final ExecutorService executorService = Executors.newFixedThreadPool(NUMBER_OF_THREAD);
final CountDownLatch latch = new CountDownLatch(NUMBER_OF_THREAD);

// when
for (int i = 0; i < NUMBER_OF_THREAD; i++) {
long memberId = memberIdGenerator.getAndIncrement();
executorService.execute(
() -> {
try {
reviewLikeService.toggleLike(memberId, reviewId);
System.out.println(
"Thread " + Thread.currentThread().getId() + " - 성곡");
} catch (Throwable e) {
System.out.println(
"Thread "
+ Thread.currentThread().getId()
+ " - μ‹€νŒ¨"
+ e.getClass().getName());
e.printStackTrace();
} finally {
latch.countDown();
}
});
}
latch.await();
executorService.shutdown();

// then
Review review = readReviewUsecase.findById(reviewId);
assertEquals(100, review.getLikesCount());
}
}
// package org.depromeet.spot.application;
//
// import static org.junit.jupiter.api.Assertions.assertEquals;
//
// import java.util.concurrent.CountDownLatch;
// import java.util.concurrent.ExecutorService;
// import java.util.concurrent.Executors;
// import java.util.concurrent.atomic.AtomicLong;
//
// import org.depromeet.spot.domain.member.Level;
// import org.depromeet.spot.domain.member.Member;
// import org.depromeet.spot.domain.member.enums.MemberRole;
// import org.depromeet.spot.domain.member.enums.SnsProvider;
// import org.depromeet.spot.domain.review.Review;
// import org.depromeet.spot.usecase.port.in.review.ReadReviewUsecase;
// import org.depromeet.spot.usecase.port.out.member.LevelRepository;
// import org.depromeet.spot.usecase.port.out.member.MemberRepository;
// import org.depromeet.spot.usecase.service.review.like.ReviewLikeService;
// import org.junit.jupiter.api.BeforeEach;
// import org.junit.jupiter.api.Test;
// import org.springframework.beans.factory.annotation.Autowired;
// import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
// import org.springframework.boot.test.context.SpringBootTest;
// import org.springframework.test.context.ActiveProfiles;
// import org.springframework.test.context.TestPropertySource;
// import org.springframework.test.context.jdbc.Sql;
// import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
// import org.springframework.test.context.jdbc.SqlGroup;
// import org.springframework.transaction.annotation.Transactional;
// import org.testcontainers.junit.jupiter.Testcontainers;
//
// import lombok.extern.slf4j.Slf4j;
//
// @Slf4j
// @SpringBootTest
// @Testcontainers
// @ActiveProfiles("test")
// @TestPropertySource("classpath:application-test.yml")
// @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
// @SqlGroup({
// @Sql(
// value = "/sql/delete-data-after-review-like.sql",
// executionPhase = ExecutionPhase.AFTER_TEST_METHOD),
// @Sql(
// value = "/sql/review-like-service-data.sql",
// executionPhase = ExecutionPhase.BEFORE_TEST_METHOD),
// })
// class ReviewLikeServiceTest {
//
// @Autowired private ReviewLikeService reviewLikeService;
//
// @Autowired private ReadReviewUsecase readReviewUsecase;
//
// @Autowired private MemberRepository memberRepository;
//
// @Autowired private LevelRepository levelRepository;
//
// private static final int NUMBER_OF_THREAD = 100;
//
// @BeforeEach
// @Transactional
// void init() {
// Level level = levelRepository.findByValue(0);
// AtomicLong memberIdGenerator = new AtomicLong(1);
//
// for (int i = 0; i < NUMBER_OF_THREAD; i++) {
// long memberId = memberIdGenerator.getAndIncrement();
// memberRepository.save(
// Member.builder()
// .id(memberId)
// .snsProvider(SnsProvider.KAKAO)
// .teamId(1L)
// .role(MemberRole.ROLE_ADMIN)
// .idToken("idToken" + memberId)
// .nickname(String.valueOf(memberId))
// .phoneNumber(String.valueOf(memberId))
// .email("email" + memberId)
// .build(),
// level);
// }
// }
//
// @Test
// void λ©€ν‹°_μŠ€λ ˆλ“œ_ν™˜κ²½μ—μ„œ_리뷰_곡감_수λ₯Ό_μ •μƒμ μœΌλ‘œ_μ¦κ°€μ‹œν‚¬_수_μžˆλ‹€() throws InterruptedException {
// // given
// final long reviewId = 1L;
// AtomicLong memberIdGenerator = new AtomicLong(1);
// final ExecutorService executorService = Executors.newFixedThreadPool(NUMBER_OF_THREAD);
// final CountDownLatch latch = new CountDownLatch(NUMBER_OF_THREAD);
//
// // when
// for (int i = 0; i < NUMBER_OF_THREAD; i++) {
// long memberId = memberIdGenerator.getAndIncrement();
// executorService.execute(
// () -> {
// try {
// reviewLikeService.toggleLike(memberId, reviewId);
// System.out.println(
// "Thread " + Thread.currentThread().getId() + " - 성곡");
// } catch (Throwable e) {
// System.out.println(
// "Thread "
// + Thread.currentThread().getId()
// + " - μ‹€νŒ¨"
// + e.getClass().getName());
// e.printStackTrace();
// } finally {
// latch.countDown();
// }
// });
// }
// latch.await();
// executorService.shutdown();
//
// // then
// Review review = readReviewUsecase.findById(reviewId);
// assertEquals(100, review.getLikesCount());
// }
// }
6 changes: 3 additions & 3 deletions application/src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ aws:
accessKey: ${AWS_S3_ACCESS_KEY}
secretKey: ${AWS_S3_SECRET_KEY}
bucketName: ${AWS_S3_BUCKET_NAME}
redis:
host: localhost
port: 6379
# redis:
# host: localhost
# port: 6379

oauth:
kakaoClientId: ${KAKAO_CLIENT_ID}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
import org.depromeet.spot.infrastructure.common.util.SpringELParser;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Component;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Aspect
@Component
// @Component
@RequiredArgsConstructor
public class DistributedLockAop {

Expand Down
Loading
Loading