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

병합 충돌 해결 #750

Merged
merged 2 commits into from
Oct 24, 2024
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
703 changes: 703 additions & 0 deletions backend/hs_err_pid19740.log

Large diffs are not rendered by default.

733 changes: 733 additions & 0 deletions backend/hs_err_pid20488.log

Large diffs are not rendered by default.

1,087 changes: 1,087 additions & 0 deletions backend/hs_err_pid20992.log

Large diffs are not rendered by default.

10,114 changes: 10,114 additions & 0 deletions backend/replay_pid19740.log

Large diffs are not rendered by default.

13,012 changes: 13,012 additions & 0 deletions backend/replay_pid20488.log

Large diffs are not rendered by default.

12,542 changes: 12,542 additions & 0 deletions backend/replay_pid20992.log

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package mouda.backend.chamyo.service;

import static org.assertj.core.api.Assertions.*;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import mouda.backend.common.fixture.DarakbangFixture;
import mouda.backend.common.fixture.DarakbangMemberFixture;
import mouda.backend.common.fixture.MemberFixture;
import mouda.backend.common.fixture.MoimFixture;
import mouda.backend.darakbang.domain.Darakbang;
import mouda.backend.darakbang.infrastructure.DarakbangRepository;
import mouda.backend.darakbangmember.domain.DarakbangMember;
import mouda.backend.darakbangmember.infrastructure.DarakbangMemberRepository;
import mouda.backend.member.domain.Member;
import mouda.backend.member.infrastructure.MemberRepository;
import mouda.backend.moim.business.ChamyoService;
import mouda.backend.moim.domain.Moim;
import mouda.backend.moim.exception.ChamyoException;
import mouda.backend.moim.infrastructure.MoimRepository;

@SpringBootTest
class ChamyoServiceTest {

@Autowired
private ChamyoService chamyoService;

@Autowired
private DarakbangRepository darakbangRepository;

@Autowired
private DarakbangMemberRepository darakbangMemberRepository;

@Autowired
private MemberRepository memberRepository;

@Autowired
private MoimRepository moimRepository;

@DisplayName("같은 회원이 따로 따로 여러 번 참여 요청을 하면 두 번째 요청 시 참여에 실패한다.")
@Test
void chamyoMoim() throws InterruptedException {
Darakbang darakbang = DarakbangFixture.getDarakbangWithMouda();
darakbangRepository.save(darakbang);

Member member = MemberFixture.getAnna();
memberRepository.save(member);

DarakbangMember darakbangMember = DarakbangMemberFixture
.getDarakbangMemberWithWooteco(darakbang, member);
darakbangMemberRepository.save(darakbangMember);

Moim moim = MoimFixture.getBasketballMoim(darakbang.getId());
moimRepository.save(moim);

chamyoService.chamyoMoim(darakbang.getId(), moim.getId(), darakbangMember);
assertThatThrownBy(() -> chamyoService.chamyoMoim(darakbang.getId(), moim.getId(), darakbangMember))
.isInstanceOf(ChamyoException.class);
assertThat(chamyoService.findAllChamyo(darakbang.getId(), moim.getId()).chamyos()).hasSize(1);
}

@DisplayName("동시 참여 테스트")
@Nested
class ConcurrencyTest {

@DisplayName("같은 회원이 동시에 여러 번 참여 요청을 하면 동시 참여가 불가능하다.")
@Test
void chamyoMoimConcurrently() throws InterruptedException {
int threadCount = 2;
ExecutorService executorService = Executors.newFixedThreadPool(threadCount);
CountDownLatch latch = new CountDownLatch(threadCount);

Darakbang darakbang = DarakbangFixture.getDarakbangWithMouda();
darakbangRepository.save(darakbang);

Moim moim = MoimFixture.getBasketballMoim(darakbang.getId());
moimRepository.save(moim);

Member member = MemberFixture.getAnna();
memberRepository.save(member);

DarakbangMember darakbangMember = DarakbangMemberFixture
.getDarakbangMemberWithWooteco(darakbang, member);
darakbangMemberRepository.save(darakbangMember);

long startTime = System.currentTimeMillis();
for (int i = 0; i < threadCount; i++) {
executorService.execute(() -> {
try {
chamyoService.chamyoMoim(darakbang.getId(), moim.getId(), darakbangMember);
} finally {
latch.countDown();
}
});
}
latch.await();
executorService.shutdown();

long endTime = System.currentTimeMillis();
System.out.printf("Test time : %d ms\n", endTime - startTime);

assertThat(chamyoService.findAllChamyo(darakbang.getId(), moim.getId()).chamyos()).hasSize(1);
}
}
}