-
Notifications
You must be signed in to change notification settings - Fork 0
[Refactor] 동시성 테스트 스레드 카운트 톰켓 스레드 수치 동결 #46
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
Open
taek2222
wants to merge
7
commits into
dev
Choose a base branch
from
refactor/29
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
57d3e85
test: 동시성 Helper 스레드 수 기반 동작 변환
taek2222 48e8f7b
test: 동시성 테스트 결과 객체 추가 및 Runnable→Callable로 전환
taek2222 635c976
test: Exception 예외 상태 코드 증가 추가
taek2222 edd84bc
test: 동시성 테스트 잘못된 부분 수정
taek2222 9be059f
test: 동시성 Helper 패키지 위치 변경
taek2222 100b566
test: Error Count 및 Cause 추가
taek2222 2eaae6c
test: assertAll 형태로 변경
taek2222 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 0 additions & 46 deletions
46
src/test/java/com/daedan/festabook/global/lock/ConcurrencyTestHelper.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/test/java/com/daedan/festabook/support/ConcurrencyTestHelper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package com.daedan.festabook.support; | ||
|
|
||
| import io.restassured.response.Response; | ||
| import java.util.concurrent.Callable; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.Executors; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| public class ConcurrencyTestHelper { | ||
|
|
||
| @Value("${server.tomcat.threads.max}") | ||
| private int tomcatThreadCount; | ||
|
|
||
| @SafeVarargs | ||
| public final ConcurrencyTestResult execute(Callable<Response>... requests) { | ||
| validateRequests(requests); | ||
| ConcurrencyTestResult result = new ConcurrencyTestResult(); | ||
|
|
||
| try (ExecutorService executorService = Executors.newFixedThreadPool(tomcatThreadCount)) { | ||
| CountDownLatch startLatch = new CountDownLatch(1); | ||
| CountDownLatch endLatch = new CountDownLatch(tomcatThreadCount); | ||
|
|
||
| for (int i = 0; i < tomcatThreadCount; i++) { | ||
| int currentCount = i % requests.length; | ||
| executorService.submit(() -> { | ||
| try { | ||
| startLatch.await(); | ||
| Response response = requests[currentCount].call(); | ||
|
|
||
| HttpStatus httpStatus = HttpStatus.valueOf(response.getStatusCode()); | ||
| result.recordStatusCode(httpStatus); | ||
| } catch (Exception e) { | ||
| log.error("동시성 테스트 실행 중 예외 발생", e); | ||
| result.recordError(e); | ||
| } finally { | ||
| endLatch.countDown(); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| startLatch.countDown(); | ||
| endLatch.await(); | ||
| } catch (InterruptedException ignore) { | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| @SafeVarargs | ||
| private void validateRequests(Callable<Response>... requests) { | ||
| if (requests == null || requests.length == 0) { | ||
| throw new IllegalArgumentException("실행할 API 인자는 최소 1개 이상이어야 합니다."); | ||
| } | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
src/test/java/com/daedan/festabook/support/ConcurrencyTestResult.java
taek2222 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package com.daedan.festabook.support; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.Queue; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.ConcurrentLinkedQueue; | ||
| import java.util.concurrent.atomic.AtomicLong; | ||
| import org.springframework.http.HttpStatus; | ||
|
|
||
| public class ConcurrencyTestResult { | ||
|
|
||
| private final Map<HttpStatus, Integer> statusCodeCounts = new ConcurrentHashMap<>(); | ||
| private final AtomicLong requestCount = new AtomicLong(); | ||
| private final AtomicLong errorCount = new AtomicLong(); | ||
| private final Queue<Throwable> errorCauses = new ConcurrentLinkedQueue<>(); | ||
|
|
||
| public void recordStatusCode(HttpStatus status) { | ||
| statusCodeCounts.merge(status, 1, Integer::sum); | ||
| requestCount.incrementAndGet(); | ||
| } | ||
taek2222 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public void recordError(Throwable e) { | ||
| errorCount.incrementAndGet(); | ||
| errorCauses.add(e); | ||
| } | ||
|
|
||
| public int getStatusCodeCount(HttpStatus status) { | ||
| return statusCodeCounts.getOrDefault(status, 0); | ||
| } | ||
|
|
||
| public long getRequestCount() { | ||
| return requestCount.get(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,3 +31,8 @@ secret: | |
| fcm: | ||
| topic: | ||
| festival-prefix: example-festival | ||
|
|
||
| server: | ||
| tomcat: | ||
| threads: | ||
| max: 15 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.