Skip to content

Commit

Permalink
test: 좋아요 성능 테스트를 위한 서버 재배포
Browse files Browse the repository at this point in the history
  • Loading branch information
EunChanNam committed Nov 27, 2023
1 parent b86f6e4 commit 038d3db
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
package com.inq.wishhair.wesharewishhair;

import java.util.ArrayList;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Profile;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

import com.inq.wishhair.wesharewishhair.hairstyle.domain.HairStyle;
import com.inq.wishhair.wesharewishhair.hairstyle.domain.HairStyleRepository;
import com.inq.wishhair.wesharewishhair.user.domain.UserRepository;
import com.inq.wishhair.wesharewishhair.user.domain.entity.Password;
import com.inq.wishhair.wesharewishhair.user.domain.entity.Sex;
import com.inq.wishhair.wesharewishhair.user.domain.entity.User;

import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;

@SpringBootApplication
public class WeShareWishHairApplication {
Expand All @@ -10,4 +25,27 @@ public static void main(String[] args) {
SpringApplication.run(WeShareWishHairApplication.class, args);
}

@Component
@Profile("prod")
@RequiredArgsConstructor
static class TestData {

private final UserRepository userRepository;
private final HairStyleRepository hairStyleRepository;
private final PasswordEncoder passwordEncoder;

@PostConstruct
public void setUp() {
userRepository.save(User.createUser(
"[email protected]",
Password.encrypt("hello123@", passwordEncoder),
"userA",
"hello",
Sex.MAN
));

hairStyleRepository.save(HairStyle.createHairStyle("hairStyleA", Sex.MAN, new ArrayList<>(), new ArrayList<>()));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class WebConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(final CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:8080", "http://13.59.136.85:8080")
.allowedOrigins("http://localhost:8080", "http://3.21.14.25:8080", "http://localhost:80")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.inq.wishhair.wesharewishhair.review.domain.likereview.LikeReview;
import com.inq.wishhair.wesharewishhair.review.domain.likereview.LikeReviewRepository;

import jakarta.persistence.EntityExistsException;
import lombok.RequiredArgsConstructor;

@Service
Expand All @@ -29,11 +28,7 @@ private Long updateLikeCountFromRedis(Long reviewId) {

@Transactional
public boolean executeLike(Long reviewId, Long userId) {
try {
likeReviewRepository.save(LikeReview.addLike(userId, reviewId));
} catch (EntityExistsException e) {
return false;
}
likeReviewRepository.save(LikeReview.addLike(userId, reviewId));

//락을 걸지않고 값이없으면 좋아요 개수를 로드해서 반영 기능 추가
redisUtils.getData(reviewId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(uniqueConstraints = @UniqueConstraint(columnNames = {"userId", "reviewId"}))
@Table(name = "like_review")
public class LikeReview {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
import com.inq.wishhair.wesharewishhair.global.exception.ErrorCode;
import com.inq.wishhair.wesharewishhair.global.exception.WishHairException;
import com.inq.wishhair.wesharewishhair.hairstyle.domain.hashtag.Tag;
import com.inq.wishhair.wesharewishhair.point.domain.PointLogRepository;
import com.inq.wishhair.wesharewishhair.review.application.ReviewService;
import com.inq.wishhair.wesharewishhair.user.presentation.dto.request.PasswordRefreshRequest;
import com.inq.wishhair.wesharewishhair.user.presentation.dto.request.PasswordUpdateRequest;
import com.inq.wishhair.wesharewishhair.user.presentation.dto.request.SignUpRequest;
import com.inq.wishhair.wesharewishhair.user.presentation.dto.request.UserUpdateRequest;
import com.inq.wishhair.wesharewishhair.user.application.utils.UserValidator;
import com.inq.wishhair.wesharewishhair.user.domain.AiConnector;
import com.inq.wishhair.wesharewishhair.user.domain.UserRepository;
import com.inq.wishhair.wesharewishhair.user.domain.entity.Email;
import com.inq.wishhair.wesharewishhair.user.domain.entity.FaceShape;
import com.inq.wishhair.wesharewishhair.user.domain.entity.Nickname;
import com.inq.wishhair.wesharewishhair.user.domain.entity.Password;
import com.inq.wishhair.wesharewishhair.user.domain.entity.User;
import com.inq.wishhair.wesharewishhair.user.domain.UserRepository;
import com.inq.wishhair.wesharewishhair.point.domain.PointLogRepository;
import com.inq.wishhair.wesharewishhair.user.application.utils.UserValidator;
import com.inq.wishhair.wesharewishhair.user.domain.AiConnector;
import com.inq.wishhair.wesharewishhair.user.presentation.dto.request.PasswordRefreshRequest;
import com.inq.wishhair.wesharewishhair.user.presentation.dto.request.PasswordUpdateRequest;
import com.inq.wishhair.wesharewishhair.user.presentation.dto.request.SignUpRequest;
import com.inq.wishhair.wesharewishhair.user.presentation.dto.request.UserUpdateRequest;

import lombok.RequiredArgsConstructor;

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ decorator:
#JWT key
jwt:
secret-key: abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc
access-token-validity: 1800000
access-token-validity: 180000000
refresh-token-validity: 259200000

# 네이버 클라우드 오브젝트 스토리지
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
import com.inq.wishhair.wesharewishhair.common.support.MockTestSupport;
import com.inq.wishhair.wesharewishhair.global.utils.RedisUtils;
import com.inq.wishhair.wesharewishhair.review.application.dto.response.LikeReviewResponse;
import com.inq.wishhair.wesharewishhair.review.domain.likereview.LikeReview;
import com.inq.wishhair.wesharewishhair.review.domain.likereview.LikeReviewRepository;

import jakarta.persistence.EntityExistsException;

@DisplayName("[LikeReviewService 테스트]")
class LikeReviewServiceTest extends MockTestSupport {

Expand Down Expand Up @@ -71,19 +68,6 @@ void success2() {
verify(redisUtils, timeout(1)).setData(1L, 10L);
}
}

@Test
@DisplayName("[이미 좋아요한 상태여서 false 를 반환한다]")
void returnFalse() {
given(likeReviewRepository.save(any(LikeReview.class)))
.willThrow(new EntityExistsException());

//when
boolean actual = likeReviewService.executeLike(1L, 1L);

//then
assertThat(actual).isFalse();
}
}

@Nested
Expand Down

0 comments on commit 038d3db

Please sign in to comment.