Skip to content

Commit 7d00bc0

Browse files
committed
Feat: currentParticipants 필드 추가 및 초기값 설정 + 전체 온라인 사용자 수 조회 테스트 수정
1 parent f653590 commit 7d00bc0

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/main/java/com/back/domain/studyroom/entity/Room.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public class Room extends BaseEntity {
2929
private boolean allowAudio;
3030
private boolean allowScreenShare;
3131

32+
@Builder.Default
33+
@Column(nullable = false)
34+
private Integer currentParticipants = 0;
35+
3236
// 방 상태
3337
@Builder.Default
3438
@Enumerated(EnumType.STRING)
@@ -161,6 +165,7 @@ public static Room create(String title, String description, boolean isPrivate,
161165
room.allowAudio = useWebRTC; // WebRTC 사용 여부에 따라 설정
162166
room.allowScreenShare = useWebRTC; // WebRTC 사용 여부에 따라 설정
163167
room.status = RoomStatus.WAITING; // 생성 시 대기 상태
168+
room.currentParticipants = 0;
164169
room.createdBy = creator;
165170
room.theme = theme;
166171

src/test/java/com/back/global/websocket/store/RedisSessionStoreTest.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -267,23 +267,17 @@ void t13() {
267267
@Test
268268
@DisplayName("전체 온라인 사용자 수 조회")
269269
void t14() {
270-
// given
271-
Long userId1 = 15L;
272-
Long userId2 = 16L;
273-
Long userId3 = 17L;
274-
275-
WebSocketSessionInfo session1 = WebSocketSessionInfo.createNewSession(userId1, "session-1");
276-
WebSocketSessionInfo session2 = WebSocketSessionInfo.createNewSession(userId2, "session-2");
277-
WebSocketSessionInfo session3 = WebSocketSessionInfo.createNewSession(userId3, "session-3");
278-
279-
// when
280-
redisSessionStore.saveUserSession(userId1, session1);
281-
redisSessionStore.saveUserSession(userId2, session2);
282-
redisSessionStore.saveUserSession(userId3, session3);
270+
// given & when
271+
// 세션 저장 대신, 카운터 증가 메서드를 직접 3번 호출
272+
redisSessionStore.incrementOnlineUserCount();
273+
redisSessionStore.incrementOnlineUserCount();
274+
redisSessionStore.incrementOnlineUserCount();
283275

276+
// 카운터 값을 조회
284277
long totalCount = redisSessionStore.getTotalOnlineUserCount();
285278

286279
// then
280+
// 증가된 카운터 값이 3인지 확인
287281
assertThat(totalCount).isEqualTo(3);
288282
}
289283

0 commit comments

Comments
 (0)