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

[BUG/ticket] 성공/실패 요청 수 측정 오류 해결 #20

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 ticket/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: "3.9"
services:
db:
container_name: ticket-db
image: mysql:8.0.28
platform: linux/x86_64
restart: always
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ void setUp() {

int threadCount = memberCount * MemberTicket.MEMBER_TICKET_COUNT_MAX;
TimeMeasure.measureTime(() -> {
try (ExecutorService executorService = Executors.newFixedThreadPool(threadCount)) {
sendMultipleRequests(executorService, members, ticket);
}
sendMultipleRequests(threadCount, members, ticket);
});

assertThat(getTicketQuantity(ticket)).isEqualTo(0);
Expand All @@ -78,9 +76,7 @@ void setUp() {

int threadCount = memberCount * ticketIssueCount;
TimeMeasure.measureTime(() -> {
try (ExecutorService executorService = Executors.newFixedThreadPool(threadCount)) {
sendMultipleRequests(executorService, members, jupiterTicket, marsTicket);
}
sendMultipleRequests(threadCount, members, jupiterTicket, marsTicket);
});

assertThat(getTicketQuantity(jupiterTicket)).isGreaterThanOrEqualTo(0);
Expand All @@ -99,9 +95,7 @@ void setUp() {

int threadCount = memberCount * MemberTicket.MEMBER_TICKET_COUNT_MAX;
TimeMeasure.measureTime(() -> {
try (ExecutorService executorService = Executors.newFixedThreadPool(threadCount)) {
sendMultipleRequests(executorService, members, ticket);
}
sendMultipleRequests(threadCount, members, ticket);
});

assertThat(getTicketQuantity(ticket)).isEqualTo(0);
Expand All @@ -110,21 +104,23 @@ void setUp() {
}
}

private void sendMultipleRequests(ExecutorService executorService, List<Member> members, Ticket... tickets) {
private void sendMultipleRequests(Integer threadCount, List<Member> members, Ticket... tickets) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
private void sendMultipleRequests(Integer threadCount, List<Member> members, Ticket... tickets) {
private void sendMultipleRequests(int ticketIssueCount, List<Member> members, Ticket... tickets) {

AtomicInteger succeedRequestCount = new AtomicInteger(0);
AtomicInteger failRequestCount = new AtomicInteger(0);

for (Member member : members) {
for (int i = 0; i < MemberTicket.MEMBER_TICKET_COUNT_MAX; i++) {
executorService.submit(() -> {
try {
memberTicketService.issue(member.getId(), getRandomTicket(tickets).getId());
succeedRequestCount.incrementAndGet();
} catch (Exception e) {
log.error("멤버 티켓 발행 중 오류 발생", e);
failRequestCount.incrementAndGet();
}
});
try (ExecutorService executorService = Executors.newFixedThreadPool(threadCount)) {
for (Member member : members) {
for (int i = 0; i < MemberTicket.MEMBER_TICKET_COUNT_MAX; i++) {
Comment on lines +111 to +113
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
try (ExecutorService executorService = Executors.newFixedThreadPool(threadCount)) {
for (Member member : members) {
for (int i = 0; i < MemberTicket.MEMBER_TICKET_COUNT_MAX; i++) {
int threadCount = members.size() * ticketIssueCount;
try (ExecutorService executorService = Executors.newFixedThreadPool(threadCount)) {
for (Member member : members) {
for (int i = 0; i < ticketIssueCount; i++) {

Copy link
Collaborator

Choose a reason for hiding this comment

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

이런 식으로 수정해 보는 건 어떨까요? 멤버당_티켓_발급_제한을_초과하는_요청_시_정상_처리_여부를_검증한다 테스트에서 멤버 티켓 발급 제한을 초과하지 않고 있는 문제가 있습니다

executorService.submit(() -> {
try {
memberTicketService.issue(member.getId(), getRandomTicket(tickets).getId());
succeedRequestCount.incrementAndGet();
} catch (Exception e) {
log.error("멤버 티켓 발행 중 오류 발생", e);
failRequestCount.incrementAndGet();
}
});
}
}
}

Expand Down