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

feat(mail): implement sending mail #352

Merged
merged 32 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
536b0b2
feat: 메일 기능 구현
MyaGya Oct 19, 2021
b49560d
feat: 메일 폼 구현
MyaGya Oct 19, 2021
ad7e12a
feat: 메일 폼 구현
MyaGya Oct 19, 2021
1ed932f
refactor: MultipartFile Byte 변경 최적화
MyaGya Oct 19, 2021
f002999
feat: html 코드에 대응하고 템플릿을 이용하여 전송하는 기능 추가
MyaGya Oct 20, 2021
8cd0a6c
feat: common 메일 템플릿 title 제거
SunYoungKwon Oct 20, 2021
6327ac5
feat: 첨부 파일 삭제시 삭제되도록 삭제 기능 추가
MyaGya Oct 20, 2021
b174c42
refactor: 코드리뷰 반영
MyaGya Oct 20, 2021
4a6913f
refactor: 사용하지 않는 이메일, 타이틀 제거
MyaGya Oct 20, 2021
41469a1
refactor: 코드 포맷팅 변경
MyaGya Oct 20, 2021
ac18b3f
refactor: 사용이 끝난 BytearrayOutputStream 을 close
MyaGya Oct 21, 2021
045873e
refactor(mail): bcc 메시지 생성 로직 간소화
woowahan-neo Jul 15, 2022
f731050
refactor(mail): attachFiles -> attachments 이름 변경
woowahan-neo Jul 18, 2022
c17566a
refactor(mail): sendBcc 받는 이메일 타입 Array -> List 변경
woowahan-neo Jul 18, 2022
5cf262d
refactor(mail): 동시 전송 인원 상수화
woowahan-neo Jul 18, 2022
51eea62
fix(mail): 발송 확인을 위해 받은 사람에 우테코 메일을 지정
woowahan-neo Jul 18, 2022
90879cb
style(mail): 정렬
woowahan-neo Jul 18, 2022
4342dcb
feat(mail): 메일 발송 권한 체크
woowahan-neo Jul 18, 2022
7e5ef08
feat(mail): 메일 발송 시 초당 최대 전송 속도 처리
woowahan-neo Jul 21, 2022
0d5c7c2
refactor(mail): 렌더링 로직 Sender -> Service 이동
woowahan-neo Jul 21, 2022
7f2d705
chore(mail): 불필요한 쉼표 제거
woowahan-neo Jul 21, 2022
62d2a1e
refactor(mail): 메일 발송 후 히스토리를 남기도록 수정
woowahan-neo Jul 21, 2022
261d41e
fix(mail): change user
woowahan-neo Jul 22, 2022
f8ee988
Merge branch 'develop' into feature/mail-send-api
woowahan-pjs Jul 22, 2022
54f6a6e
refactor(test): remove unused features
woowahan-pjs Jul 22, 2022
cf18525
style: polish the code
woowahan-pjs Jul 22, 2022
b2cbf09
refactor(test): migrate request limiter tests to kotest
woowahan-pjs Jul 22, 2022
7fc8599
refactor(support): move from the apply package to the support package
woowahan-pjs Jul 23, 2022
5a03859
fix(mail): add the missing sender
woowahan-pjs Jul 23, 2022
ca6e986
fix(mail): specify the size of the attachment according to the settin…
woowahan-pjs Jul 25, 2022
b894da0
refactor(mail): distinguish between mail success and failure
woowahan-pjs Jul 25, 2022
1083edc
test(support): add more rate limiter tests using coroutines
woowahan-pjs Jul 25, 2022
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 src/main/kotlin/support/infra/RateLimiter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class RateLimiter(
private fun sync(requestTime: Long) {
while (available.isNotEmpty()) {
val elapsedTime = requestTime - available.peek()
require(elapsedTime >= 0) { "잘못된 요청 시간입니다." }
if (elapsedTime.milliseconds < 1.seconds) {
break
}
Expand Down
68 changes: 39 additions & 29 deletions src/test/kotlin/support/infra/RateLimiterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,63 @@ import io.kotest.assertions.assertSoftly
import io.kotest.assertions.throwables.shouldNotThrowAny
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.StringSpec
import io.kotest.inspectors.forAll
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.runTest
import kotlin.time.Duration.Companion.milliseconds

private val Int.ms: Long get() = milliseconds.inWholeMilliseconds
Copy link
Contributor

Choose a reason for hiding this comment

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

확장함수!👍


class RateLimiterTest : StringSpec({
"초당 1회로 제한할 경우 1초 간격 요청은 성공한다" {
val limiter = RateLimiter(1)
val current = System.currentTimeMillis()
assertSoftly(limiter) {
shouldNotThrowAny { acquire(current) }
shouldNotThrowAny { acquire(current + 1000) }
shouldNotThrowAny { acquire(current + 2000) }
listOf(0.ms, 1000.ms, 2000.ms).forAll {
shouldNotThrowAny { limiter.acquire(it) }
}
}

"초당 1회로 제한할 경우 초당 2번 요청하면 실패한다" {
val limiter = RateLimiter(1)
val current = System.currentTimeMillis()
assertSoftly(limiter) {
shouldNotThrowAny { acquire(current) }
shouldThrow<ExceededRequestException> { acquire(current + 500) }
shouldNotThrowAny { acquire(current + 1000) }
shouldThrow<ExceededRequestException> { acquire(current + 1500) }
val limiter = RateLimiter(1).apply {
acquire(0.ms)
}
listOf(100.ms, 500.ms, 900.ms).forAll {
shouldThrow<ExceededRequestException> { limiter.acquire(it) }
}
}

"초당 2회로 제한할 경우 초당 2회 요청은 성공한다" {
val limiter = RateLimiter(2)
val current = System.currentTimeMillis()
assertSoftly(limiter) {
shouldNotThrowAny { acquire(current) }
shouldNotThrowAny { acquire(current) }
shouldNotThrowAny { acquire(current + 1000) }
shouldNotThrowAny { acquire(current + 1500) }
shouldNotThrowAny { acquire(current + 2000) }
listOf(0.ms, 500.ms, 1000.ms, 1500.ms, 2000.ms).forAll {
shouldNotThrowAny { limiter.acquire(it) }
}
}

"초당 2회로 제한할 경우 초당 3번 요청하면 실패한다" {
val limiter = RateLimiter(2)
val current = System.currentTimeMillis()
val limiter = RateLimiter(2).apply {
acquire(500.ms)
acquire(600.ms)
}
assertSoftly(limiter) {
shouldNotThrowAny { acquire(current) }
shouldNotThrowAny { acquire(current) }
shouldThrow<ExceededRequestException> { acquire(current) }
shouldNotThrowAny { acquire(current + 1000) }
shouldNotThrowAny { acquire(current + 1500) }
shouldThrow<ExceededRequestException> { acquire(current + 1600) }
shouldNotThrowAny { acquire(current + 2000) }
shouldThrow<ExceededRequestException> { acquire(current + 2100) }
shouldThrow<ExceededRequestException> { acquire(1400.ms) }
shouldNotThrowAny { acquire(1500.ms) }
}
}

"요청은 순서대로 이루어져야 한다" {
val limiter = RateLimiter(2).apply {
acquire(1000.ms)
}
shouldThrow<IllegalArgumentException> { limiter.acquire(0.ms) }
}

"경쟁 상태에서도 순서를 유지한다" {
runTest {
val limiter = RateLimiter(1000)
launch {
repeat(1000) {
shouldNotThrowAny { limiter.acquire() }
}
}.join()
}
}
})