Skip to content

Conversation

@sehee123
Copy link
Collaborator

@sehee123 sehee123 commented Jul 15, 2025

🛰️ Issue Number

🪐 작업 내용

  • 입, 퇴장 synchronized 적용
  • 테스트 완료

입장 동시성 적용 전 테스트 실패

image

입장 동시성 적용 후 테스트 성공

image

퇴장 동시성 적용 전 테스트 실패

image

퇴장 동시성 적용 후 테스트 성공

image
  • 입장과 validation 체크를 한번에 하도록 로직 변경(RoomService - enterRoom)
  • 이때 방장은 enterRoom을 실행하지 않음.(방생서 후에 바로 웹소켓 연결-구독-요청)
  • room.getUserIdSessionMap().put(host.id,PENDING_SESSION_ID); 방 생성시 방장은 Map 에 추가됨
  • 웹소켓 연결 시 세션 id값을 저장하고, 응답을 내려줌
  return new RoomInitialData(
           getDestination(roomId),
           roomSettingResponse,
           gameSettingResponse,
           playerListResponse,
           systemNoticeResponse);
   }
  • 방 퇴장(삭제시) 원자성 구현을 위해 remove 를 마지막 순서로 이동함
            room.getUserIdSessionMap().remove(removePlayer.getId());
            playerSessionMap.remove(sessionId);

            SystemNoticeResponse systemNoticeResponse =
                ofPlayerEvent(removePlayer, RoomEventType.EXIT);

            PlayerListResponse playerListResponse = toPlayerListResponse(room);

            return new RoomExitData(destination, playerListResponse, systemNoticeResponse, false);
        }

논의사항

  • 현재 임시로 User엔티티 setter가 열려있어서 user.setId를 테스트코드에서 쓸 수 있었는데요.
  • 나중에 Setter를 지운다면 어떻게 처리해야할까요 ?.?

📚 Reference

✅ Check List

  • 코드가 정상적으로 컴파일되나요?
  • 테스트 코드를 통과했나요?
  • merge할 브랜치의 위치를 확인했나요?
  • Label을 지정했나요?

소감

구현보다 테스트가 너무나 힘들었네요 ^_ㅠ

@sehee123 sehee123 linked an issue Jul 15, 2025 that may be closed by this pull request
@sehee123 sehee123 self-assigned this Jul 15, 2025
@sehee123 sehee123 added the enhancement New feature or request label Jul 15, 2025
}

/* 방장 변경 */
if (room.getHost().getId().equals(removePlayer.getId())) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[L5-참고의견]

Room 객체 내부에서 해당 조건을 확인하는 메서드를 구현하면 비즈니스 로직의 getter 중첩을 없앨 수 있을 것 같습니다 !

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

덕분에 로직이 깔끔해지고,책임이 명확해졌습니다. 감사합니다. 😇


PlayerListResponse playerListResponse = toPlayerListResponse(room);
/* 방 삭제 */
if (playerSessionMap.size() == 1 && playerSessionMap.containsKey(sessionId)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[L4-변경제안]

주석을 다신 단위로 메서드를 분리하면 exitRoom 메서드에 포함된 메서드 이름과 파라미터만 보고 전체 동작을 파악하기 쉬울 것 같습니다 !

SystemNoticeResponse systemNoticeResponse =
ofPlayerEvent(removedPlayer, RoomEventType.EXIT);
if (removePlayer == null) {
room.getUserIdSessionMap().remove(getCurrentUserId());
Copy link
Collaborator

Choose a reason for hiding this comment

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

[L5-참고의견]

이 부분도 Room 객체 내부에서 구현할 수 있을 것 같습니다 !

sehee123 and others added 5 commits July 16, 2025 11:05
# Conflicts:
#	backend/src/main/java/io/f1/backend/domain/game/app/RoomService.java
#	backend/src/test/java/io/f1/backend/domain/game/app/RoomServiceTests.java
Copy link
Collaborator

@LimKangHyun LimKangHyun left a comment

Choose a reason for hiding this comment

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

RoomService가 슬슬 무거워지는 것 같습니다. 클래스를 어느정도 분리할 방법을 찾으면 좋을것 같습니다!
고생하셨습니다!

@PostMapping("/validation")
@PostMapping("/enterRoom")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void validateRoom(@RequestBody @Valid RoomValidationRequest request) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[L4-변경제안]
입장과 validation 검사를 한 번에 해주는 건데, 뭔가 컨트롤러는 메서드 네이밍이 validateRoom으로 남아있고, 다른 엔드포인트나 서비스 네이밍은 enterRoom이라 컨트롤러 네이밍도 enterRoom이면 좋겠다는 의견입니다 !

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

헉. 메소드 네임은 안바꾸고 경로만 바꿨네요 .. 메서드 네임 변경해서 puh했습니다. 감사합니다!

Copy link
Collaborator

@silver-eunjoo silver-eunjoo left a comment

Choose a reason for hiding this comment

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

테스트까지!! 꼼꼼하게 작업해주시고, 많이 고민해주셔서 감사합니다 :) 고생하셨습니다 !

@sehee123 sehee123 merged commit 693240f into dev Jul 16, 2025
2 checks passed
@sehee123 sehee123 deleted the feat/20 branch July 16, 2025 03:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feat] 방 입장 시 동시성 구현

6 participants