Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;

import static com.example.eightyage.domain.user.entity.UserRole.Authority.ADMIN;
import static com.example.eightyage.domain.user.entity.UserRole.Authority.USER;
import static com.example.eightyage.domain.user.userrole.UserRole.Authority.ADMIN;
import static com.example.eightyage.domain.user.userrole.UserRole.Authority.USER;

@RestController
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public class Product extends TimeStamped {
@Temporal(TemporalType.TIMESTAMP)
private LocalDateTime deletedAt;

public Product(Long id) {
this.id = id;
}

@Builder
public Product(String name, Category category, String content, Integer price, SaleState saleState) {
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@ public class ProductBulkRepository {
public void bulkInsertProduct(List<Product> products) {
String sql = "INSERT INTO product (category, name, sale_state) values (?, ?, ?)";

Random random = new Random();

jdbcTemplate.batchUpdate(sql, products, BATCH_SIZE, (ps, argument) -> {
Category randomCategory = Category.values()[random.nextInt(Category.values().length)];
ps.setString(1, randomCategory.name());
ps.setString(1, argument.getCategory().name());
ps.setString(2, argument.getName());
ps.setString(3, random.nextBoolean() ? SaleState.FOR_SALE.name() : SaleState.SOLD_OUT.name());
ps.setString(3, argument.getSaleState().name());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,6 @@ public Product findProductByIdOrElseThrow(Long productId) {
() -> new NotFoundException("해당 제품이 존재하지 않습니다.")
);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ public class ReviewBulkRepository {
public void bulkInsertReviews(List<Review> reviews) {
String sql = "INSERT INTO review (user_id, product_id, score) values (?, ?, ?)";

Random random = new Random();

jdbcTemplate.batchUpdate(sql, reviews, BATCH_SIZE, (ps, argument) -> {
ps.setInt(1, 1);
ps.setInt(2, random.nextInt(1000) + 1);
ps.setDouble(3, random.nextDouble() * 5);
ps.setLong(1, argument.getUser().getId());
ps.setLong(2, argument.getProduct().getId());
ps.setDouble(3, argument.getScore());
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.eightyage.domain.user.entity;

import com.example.eightyage.domain.user.userrole.UserRole;
import com.example.eightyage.global.dto.AuthUser;
import com.example.eightyage.global.entity.TimeStamped;
import jakarta.persistence.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ public class UserBulkRepository {
private final int BATCH_SIZE = 1000;

public void bulkInsertUsers(List<User> users) {
String sql = "INSERT INTO user (email, password, nickname, deleted_at) values (?, ?, ?, ?)";

Random random = new Random();
String sql = "INSERT INTO user (email, password, nickname) values (?, ?, ?)";

jdbcTemplate.batchUpdate(sql, users, BATCH_SIZE, (ps, argument) -> {
ps.setString(1, argument.getEmail());
ps.setString(2, argument.getPassword());
ps.setString(3, argument.getNickname());
ps.setString(4, random.nextBoolean() ? null : LocalDateTime.now().toString()); // 랜덤으로 유저 삭제
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.example.eightyage.domain.user.dto.request.UserDeleteRequestDto;
import com.example.eightyage.domain.user.entity.User;
import com.example.eightyage.domain.user.entity.UserRole;
import com.example.eightyage.domain.user.userrole.UserRole;
import com.example.eightyage.domain.user.repository.UserRepository;
import com.example.eightyage.global.dto.AuthUser;
import com.example.eightyage.global.exception.BadRequestException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.eightyage.domain.user.entity;
package com.example.eightyage.domain.user.userrole;

import com.example.eightyage.global.exception.UnauthorizedException;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.eightyage.global.dto;

import com.example.eightyage.domain.user.entity.UserRole;
import com.example.eightyage.domain.user.userrole.UserRole;
import lombok.Builder;
import lombok.Getter;
import org.springframework.security.core.GrantedAuthority;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.eightyage.global.filter;

import com.example.eightyage.domain.user.entity.UserRole;
import com.example.eightyage.domain.user.userrole.UserRole;
import com.example.eightyage.global.config.JwtAuthenticationToken;
import com.example.eightyage.global.util.JwtUtil;
import com.example.eightyage.global.dto.AuthUser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.security.Keys;
import com.example.eightyage.domain.user.entity.UserRole;
import com.example.eightyage.domain.user.userrole.UserRole;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
Expand Down
15 changes: 12 additions & 3 deletions src/test/java/com/example/eightyage/bulk/ProductBulkTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//package com.example.eightyage.bulk;
//
//import com.example.eightyage.domain.product.entity.Category;
//import com.example.eightyage.domain.product.entity.Product;
//import com.example.eightyage.domain.product.entity.SaleState;
//import com.example.eightyage.domain.product.repository.ProductBulkRepository;
//import org.junit.jupiter.api.Test;
//import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -9,6 +11,7 @@
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Random;
//import java.util.UUID;
//
//@SpringBootTest
Expand All @@ -29,15 +32,21 @@
// insertCount = 1000000; // 로컬, 개발 서버 등에서는 많게
// }
//
// Random random = new Random();
//
// List<Product> batchList = new ArrayList<>();
//
// for (int i = 0; i < insertCount; i++) {
// Category randomCategory = Category.values()[random.nextInt(Category.values().length)];
// Product product = Product.builder()
// .name(UUID.randomUUID().toString())
// .build();
// .category(randomCategory)
// .name(UUID.randomUUID().toString())
// .saleState(random.nextBoolean() ? SaleState.FOR_SALE : SaleState.SOLD_OUT)
// .build();
//
// batchList.add(product);
//
// if (batchList.size() == insertCount) {
// if (batchList.size() == insertCount / 100) {
// productBulkRepository.bulkInsertProduct(batchList);
// batchList.clear();
//
Expand Down
13 changes: 10 additions & 3 deletions src/test/java/com/example/eightyage/bulk/ReviewBulkTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
//package com.example.eightyage.bulk;
//
//import com.example.eightyage.domain.product.entity.Product;
//import com.example.eightyage.domain.review.entity.Review;
//import com.example.eightyage.domain.review.repository.ReviewBulkRepository;
//import com.example.eightyage.domain.user.entity.User;
//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 java.util.ArrayList;
//import java.util.List;
//import java.util.Random;
//
//@SpringBootTest
//@ActiveProfiles("ci")
Expand All @@ -28,17 +31,21 @@
// insertCount = 1000000; // 로컬, 개발 서버 등에서는 많게
// }
//
// Random random = new Random();
// List<Review> batchList = new ArrayList<>();
//
// for (int i = 0; i < insertCount; i++) {
// Review review = new Review();
// User user = User.builder().id(1L).build();
// Product product = new Product((long) (random.nextInt(100) + 1));
//
// Review review = new Review(user, product, random.nextDouble() * 5, "content" + i);
// batchList.add(review);
//
// if (batchList.size() == insertCount) {
// if (batchList.size() == insertCount / 100) {
// reviewBulkRepository.bulkInsertReviews(batchList);
// batchList.clear();
//
// sleep(500);
//// sleep(500);
// }
// }
//
Expand Down
11 changes: 6 additions & 5 deletions src/test/java/com/example/eightyage/bulk/UserBulkTest.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//package com.example.eightyage.bulk;
//
//import com.example.eightyage.domain.user.entity.User;
//import com.example.eightyage.domain.user.entity.UserRole;
//import com.example.eightyage.domain.user.userrole.UserRole;
//import com.example.eightyage.domain.user.repository.UserBulkRepository;
//import com.example.eightyage.global.util.RandomCodeGenerator;
//import org.junit.jupiter.api.Test;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -19,7 +20,7 @@
// private UserBulkRepository userBulkRepository;
//
// @Test
// void 유저_데이터_백만건_생성() {
// void 유저_데이터_생성() {
//
// int insertCount;
//
Expand All @@ -33,18 +34,18 @@
//
// for (int i = 0; i < insertCount; i++) {
// User user = User.builder()
// .email(i + "@email.com")
// .email(RandomCodeGenerator.generateCouponCode(8) + "@email.com")
// .nickname("nickname" + i)
// .password("password")
// .userRole(UserRole.ROLE_USER)
// .build();
// batchList.add(user);
//
// if (batchList.size() == insertCount) {
// if (batchList.size() == insertCount / 100) {
// userBulkRepository.bulkInsertUsers(batchList);
// batchList.clear();
//
// sleep(500);
//// sleep(500);
// }
// }
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.example.eightyage.domain.auth.dto.request.AuthSignupRequestDto;
import com.example.eightyage.domain.auth.dto.response.AuthTokensResponseDto;
import com.example.eightyage.domain.user.entity.User;
import com.example.eightyage.domain.user.entity.UserRole;
import com.example.eightyage.domain.user.userrole.UserRole;
import com.example.eightyage.domain.user.service.UserService;
import com.example.eightyage.global.exception.BadRequestException;
import com.example.eightyage.global.exception.UnauthorizedException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.example.eightyage.domain.auth.entity.RefreshToken;
import com.example.eightyage.domain.auth.repository.RefreshTokenRepository;
import com.example.eightyage.domain.user.entity.User;
import com.example.eightyage.domain.user.entity.UserRole;
import com.example.eightyage.domain.user.userrole.UserRole;
import com.example.eightyage.domain.user.service.UserService;
import com.example.eightyage.global.exception.NotFoundException;
import com.example.eightyage.global.exception.UnauthorizedException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.example.eightyage.domain.user.dto.request.UserDeleteRequestDto;
import com.example.eightyage.domain.user.entity.User;
import com.example.eightyage.domain.user.entity.UserRole;
import com.example.eightyage.domain.user.userrole.UserRole;
import com.example.eightyage.domain.user.repository.UserRepository;
import com.example.eightyage.global.dto.AuthUser;
import com.example.eightyage.global.exception.BadRequestException;
Expand Down
21 changes: 19 additions & 2 deletions src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,27 @@ spring:

jpa:
hibernate:
ddl-auto: create
ddl-auto: update
properties:
hibernate:
show_sql: true
format_sql: true
use_sql_comments: true
dialect: org.hibernate.dialect.MySQLDialect
dialect: org.hibernate.dialect.MySQLDialect
cloud:
aws:
credentials:
access-key: ${AWS_ACCESS_KEY}
secret-key: ${AWS_SECRET_KEY}
region:
static: ap-northeast-2
s3:
bucket: my-gom-bucket

aws:
credentials:
access-key: ${AWS_ACCESS_KEY}
secret-key: ${AWS_SECRET_KEY}
region: ap-northeast-2
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

region이랑 bucket 이름 이제 제거하셔도 됩니다! 그리고 현재 aws 관련 설정이 위/아래 2개로 중복되어서 하나 삭제하셔야 될 것 같아요.

s3:
bucket: my-gom-bucket