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,6 +13,7 @@
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

@Service
Expand All @@ -38,7 +39,7 @@ public CustomizeTableResponse findTable(long tableId, Member member) {
return new CustomizeTableResponse(table, timeBoxes);
}

@Transactional
@Transactional(isolation = Isolation.SERIALIZABLE)
public CustomizeTableResponse updateTable(
CustomizeTableCreateRequest tableCreateRequest,
long tableId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

@Service
Expand Down Expand Up @@ -45,7 +46,7 @@ public ParliamentaryTableResponse findTableById(long tableId, long id) {
return new ParliamentaryTableResponse(table, timeBoxes);
}

@Transactional
@Transactional(isolation = Isolation.SERIALIZABLE)
public ParliamentaryTableResponse updateTable(
ParliamentaryTableCreateRequest tableCreateRequest,
long tableId,
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ discord:
token: ${secret.discord.token}
channelId: ${secret.discord.channelId}

#logging:
# config: classpath:logging/log4j2-dev.yml
logging:
config: classpath:logging/log4j2-dev.yml
4 changes: 2 additions & 2 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ discord:
token: ${secret.discord.token}
channelId: ${secret.discord.channelId}

#logging:
# config: classpath:logging/log4j2-prod.yml
logging:
config: classpath:logging/log4j2-prod.yml
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ springdoc:
filter: true
persist-authorization: true
display-request-duration: true
default-model-expand-depth: 10
1 change: 1 addition & 0 deletions src/main/resources/logging/log4j2-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Configuration:
TimeBasedTriggeringPolicy:
Interval: 1
modulate: true #다음 롤오버 시간을 정각 바운더리에 맞추는 설정

DefaultRollOverStrategy:
max: 10
Delete:
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/logging/log4j2-prod.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Configuration:
name: Dev-Logger
name: Prod-Logger
status: debug

Properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public RestDocumentationRequest summary(String summary) {
return this;
}

public RestDocumentationRequest description(String description) {
resourceBuilder.description(description);
return this;
}

public RestDocumentationRequest pathParameter(ParameterDescriptor... descriptors) {
snippets.add(pathParameters(descriptors));
return this;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class CreateMember {
);

@Test
void 회원_생성_성공() {
MemberCreateRequest request = new MemberCreateRequest("dfsfgdsg", "http://redirectUrl");
void 회원_생성_및_로그인_성공() {
MemberCreateRequest request = new MemberCreateRequest("dfsfgdsg", "http://localhost:3000");
MemberInfo memberInfo = new MemberInfo(EXIST_MEMBER_EMAIL);
MemberCreateResponse response = new MemberCreateResponse(EXIST_MEMBER_ID, EXIST_MEMBER_EMAIL);
doReturn(memberInfo).when(authService).getMemberInfo(request);
Expand All @@ -68,6 +68,24 @@ class CreateMember {
.when().post("/api/member")
.then().statusCode(201);
}

@EnumSource(value = ClientErrorCode.class, names = {"MEMBER_NOT_FOUND"}) // PR #160 병합 시 변경
@ParameterizedTest
void 회원_생성_및_로그인_실패(ClientErrorCode errorCode) {
MemberCreateRequest request = new MemberCreateRequest("dfsfgdsg", "http://localhost:3000");
doThrow(new DTClientErrorException(errorCode)).when(authService).getMemberInfo(request);

var document = document("member/create", errorCode)
.request(requestDocument)
.response(ERROR_RESPONSE)
.build();

given(document)
.contentType(ContentType.JSON)
.body(request)
.when().post("/api/member")
.then().statusCode(errorCode.getStatus().value());
}
}

@Nested
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/com/debatetimer/service/BaseServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.debatetimer.repository.member.MemberRepository;
import com.debatetimer.repository.parliamentary.ParliamentaryTableRepository;
import com.debatetimer.repository.parliamentary.ParliamentaryTimeBoxRepository;
import java.util.List;
import java.util.stream.IntStream;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
Expand Down Expand Up @@ -48,4 +50,15 @@ public abstract class BaseServiceTest {

@Autowired
protected CustomizeTimeBoxGenerator customizeTimeBoxGenerator;

protected void runAtSameTime(int count, Runnable task) throws InterruptedException {
List<Thread> threads = IntStream.range(0, count)
.mapToObj(i -> new Thread(task))
.toList();

threads.forEach(Thread::start);
for (Thread thread : threads) {
thread.join();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,26 @@ class UpdateTable {
.isInstanceOf(DTClientErrorException.class)
.hasMessage(ClientErrorCode.NOT_TABLE_OWNER.getMessage());
}

@Test
void 테이블_정보_수정을_동시에_요청할_때_동시에_처리하지_않는다() throws InterruptedException {
Member member = memberGenerator.generate("default@gmail.com");
CustomizeTable table = customizeTableGenerator.generate(member);
CustomizeTableCreateRequest request = new CustomizeTableCreateRequest(
new CustomizeTableInfoCreateRequest("자유 테이블", "주제", "찬성",
"반대", true, true),
List.of(
new CustomizeTimeBoxCreateRequest(Stance.PROS, "입론1", CustomizeBoxType.NORMAL,
120, 60, null, "발언자1"),
new CustomizeTimeBoxCreateRequest(Stance.PROS, "입론2", CustomizeBoxType.NORMAL,
120, 60, null, "발언자2")
)
);

runAtSameTime(2, () -> customizeService.updateTable(request, table.getId(), member));

assertThat(customizeTimeBoxRepository.findAllByCustomizeTable(table)).hasSize(2);
}
}

@Nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ class UpdateTable {
.isInstanceOf(DTClientErrorException.class)
.hasMessage(ClientErrorCode.NOT_TABLE_OWNER.getMessage());
}

@Test
void 테이블_정보_수정을_동시에_요청할_때_동시에_처리하지_않는다() throws InterruptedException {
Member member = memberGenerator.generate("default@gmail.com");
ParliamentaryTable table = parliamentaryTableGenerator.generate(member);
ParliamentaryTableCreateRequest request = new ParliamentaryTableCreateRequest(
new ParliamentaryTableInfoCreateRequest("커찬의 테이블", "주제", true, true),
List.of(new ParliamentaryTimeBoxCreateRequest(Stance.PROS, ParliamentaryBoxType.OPENING, 3, 1),
new ParliamentaryTimeBoxCreateRequest(Stance.CONS, ParliamentaryBoxType.OPENING, 3, 1)));

runAtSameTime(2, () -> parliamentaryService.updateTable(request, member.getId(), member));

assertThat(parliamentaryTimeBoxRepository.findAllByParliamentaryTable(table)).hasSize(2);
}
}

@Nested
Expand Down
Loading