@@ -129,19 +129,19 @@ void getDiariesByGeohash_success_allCacheHit() {
129129 DiaryMarkerResponseDto dto1 = DiaryMarkerFixture .createDiaryMarker (1L );
130130 DiaryMarkerResponseDto dto2 = DiaryMarkerFixture .createDiaryMarker (2L );
131131
132- given (diaryCacheDao .getDiaryIdSetFromCache (geohash )).willReturn (cachedIds );
133- given (diaryCacheDao .getDiaryFromCache (1L )).willReturn (dto1 );
134- given (diaryCacheDao .getDiaryFromCache (2L )).willReturn (dto2 );
132+ given (diaryCacheDao .getDiaryIdSetFromCache ("wydmt" )).willReturn (cachedIds );
133+ given (diaryCacheDao .getDiariesFromCacheBulk (List .of (1L , 2L ))).willReturn (List .of (dto1 , dto2 ));
135134
136135 // when
137- List <DiaryMarkerResponseDto > result = mapService .getDiariesByGeohash (geohash );
136+ List <DiaryMarkerResponseDto > result = mapService .getDiariesByGeohash ("wydmt" );
138137
139138 // then
140139 assertThat (result ).containsExactlyInAnyOrder (dto1 , dto2 );
141140 verify (diaryRepository , never ()).findAllById (any ());
142141 verify (diaryGeohashService , never ()).getDiaryIdsByGeohash (any ());
143142 }
144143
144+
145145 @ DisplayName ("성공 : geohash 캐시 HIT + 모든 diary 캐시 MISS" )
146146 @ Test
147147 void getDiariesByGeohash_success_allDiaryCacheMiss () {
@@ -154,17 +154,15 @@ void getDiariesByGeohash_success_allDiaryCacheMiss() {
154154 DiaryMarkerResponseDto dto2 = DiaryMarkerResponseDto .of (diary2 );
155155
156156 given (diaryCacheDao .getDiaryIdSetFromCache ("wydmt" )).willReturn (cachedIds );
157- given (diaryCacheDao .getDiaryFromCache (1L )).willReturn (null );
158- given (diaryCacheDao .getDiaryFromCache (2L )).willReturn (null );
157+ given (diaryCacheDao .getDiariesFromCacheBulk (List .of (1L , 2L ))).willReturn (List .of ());
159158 given (diaryService .getDiaries (List .of (1L , 2L ))).willReturn (List .of (diary1 , diary2 ));
160159
161160 // when
162161 List <DiaryMarkerResponseDto > result = mapService .getDiariesByGeohash ("wydmt" );
163162
164163 // then
165164 assertThat (result ).containsExactlyInAnyOrder (dto1 , dto2 );
166- verify (diaryCacheDao ).cacheDiary (1L , dto1 );
167- verify (diaryCacheDao ).cacheDiary (2L , dto2 );
165+ verify (diaryCacheDao ).cacheAllDiaries (List .of (dto1 , dto2 ));
168166 }
169167
170168 @ DisplayName ("성공 : geohash 캐시 HIT + 일부 diary 캐시 MISS" )
@@ -177,17 +175,16 @@ void getDiariesByGeohash_success_partialDiaryCacheMiss() {
177175 Diary diary2 = DiaryFixture .createDiaryFixture (2L );
178176 DiaryMarkerResponseDto dto2 = DiaryMarkerResponseDto .of (diary2 );
179177
180- given (diaryCacheDao .getDiaryIdSetFromCache (geohash )).willReturn (cachedIds );
181- given (diaryCacheDao .getDiaryFromCache (1L )).willReturn (dto1 );
182- given (diaryCacheDao .getDiaryFromCache (2L )).willReturn (null );
178+ given (diaryCacheDao .getDiaryIdSetFromCache ("wydmt" )).willReturn (cachedIds );
179+ given (diaryCacheDao .getDiariesFromCacheBulk (List .of (1L , 2L ))).willReturn (List .of (dto1 ));
183180 given (diaryService .getDiaries (List .of (2L ))).willReturn (List .of (diary2 ));
184181
185182 // when
186- List <DiaryMarkerResponseDto > result = mapService .getDiariesByGeohash (geohash );
183+ List <DiaryMarkerResponseDto > result = mapService .getDiariesByGeohash ("wydmt" );
187184
188185 // then
189186 assertThat (result ).containsExactlyInAnyOrder (dto1 , dto2 );
190- verify (diaryService ). getDiaries (List .of (2L ));
187+ verify (diaryCacheDao ). cacheAllDiaries (List .of (dto2 ));
191188 }
192189
193190 @ DisplayName ("성공 : geohash 캐시 MISS → DB 조회 → 모든 diary 캐시 HIT" )
@@ -201,8 +198,7 @@ void getDiariesByGeohash_success_geohashMiss_allDiaryCacheHit() {
201198
202199 given (diaryCacheDao .getDiaryIdSetFromCache (geohash )).willReturn (Collections .emptySet ());
203200 given (diaryGeohashService .getDiaryIdsByGeohash (geohash )).willReturn (diaryIdsFromDb );
204- given (diaryCacheDao .getDiaryFromCache (1L )).willReturn (dto1 );
205- given (diaryCacheDao .getDiaryFromCache (2L )).willReturn (dto2 );
201+ given (diaryCacheDao .getDiariesFromCacheBulk (diaryIdsFromDb )).willReturn (List .of (dto1 , dto2 ));
206202
207203 // when
208204 List <DiaryMarkerResponseDto > result = mapService .getDiariesByGeohash (geohash );
@@ -226,18 +222,16 @@ void getDiariesByGeohash_success_geohashMiss_allDiaryCacheMiss() {
226222
227223 given (diaryCacheDao .getDiaryIdSetFromCache (geohash )).willReturn (Collections .emptySet ());
228224 given (diaryGeohashService .getDiaryIdsByGeohash (geohash )).willReturn (diaryIdsFromDb );
229- given (diaryCacheDao .getDiaryFromCache (1L )).willReturn (null );
230- given (diaryCacheDao .getDiaryFromCache (2L )).willReturn (null );
231- given (diaryService .getDiaries (List .of (1L , 2L ))).willReturn (List .of (diary1 , diary2 ));
225+ given (diaryCacheDao .getDiariesFromCacheBulk (diaryIdsFromDb )).willReturn (List .of ());
226+ given (diaryService .getDiaries (diaryIdsFromDb )).willReturn (List .of (diary1 , diary2 ));
232227
233228 // when
234229 List <DiaryMarkerResponseDto > result = mapService .getDiariesByGeohash (geohash );
235230
236231 // then
237232 assertThat (result ).containsExactlyInAnyOrder (dto1 , dto2 );
238233 verify (diaryCacheDao ).cacheDiaryIdSetByGeohash (geohash , diaryIdsFromDb );
239- verify (diaryCacheDao ).cacheDiary (1L , dto1 );
240- verify (diaryCacheDao ).cacheDiary (2L , dto2 );
234+ verify (diaryCacheDao ).cacheAllDiaries (List .of (dto1 , dto2 ));
241235 }
242236
243237 @ DisplayName ("성공 : geohash 캐시 MISS → DB 조회 → diary 일부 캐시 MISS" )
@@ -252,8 +246,7 @@ void getDiariesByGeohash_success_geohashCacheMissAndDiaryCacheMiss() {
252246
253247 given (diaryCacheDao .getDiaryIdSetFromCache (geohash )).willReturn (Collections .emptySet ());
254248 given (diaryGeohashService .getDiaryIdsByGeohash (geohash )).willReturn (dbIds );
255- given (diaryCacheDao .getDiaryFromCache (1L )).willReturn (dto1 );
256- given (diaryCacheDao .getDiaryFromCache (2L )).willReturn (null );
249+ given (diaryCacheDao .getDiariesFromCacheBulk (dbIds )).willReturn (List .of (dto1 ));
257250 given (diaryService .getDiaries (List .of (2L ))).willReturn (List .of (diary2 ));
258251
259252 // when
@@ -262,6 +255,7 @@ void getDiariesByGeohash_success_geohashCacheMissAndDiaryCacheMiss() {
262255 // then
263256 assertThat (result ).containsExactlyInAnyOrder (dto1 , dto2 );
264257 verify (diaryCacheDao ).cacheDiaryIdSetByGeohash (geohash , dbIds );
258+ verify (diaryCacheDao ).cacheAllDiaries (List .of (dto2 ));
265259 }
266260
267261 @ DisplayName ("성공 : Redis 예외 발생 시 fallback 작동: DB에서 조회됨" )
@@ -285,14 +279,14 @@ void getDiariesByGeohash_redisFailureHandledInternally() {
285279 verify (diaryService ).getDiaries (diaryIds );
286280 }
287281
288- @ DisplayName ("예외 : diaryId 존재하나 DB에 diary 없음 " )
282+ @ DisplayName ("예외 : diaryId 존재하나 DB에 diary 없음" )
289283 @ Test
290284 void diaryIdExistsButDiaryMissingInDb () {
291285 // given
292286 String geohash = "wydmt" ;
293287 Set <Long > cachedIds = Set .of (100L );
294288 given (diaryCacheDao .getDiaryIdSetFromCache (geohash )).willReturn (cachedIds );
295- given (diaryCacheDao .getDiaryFromCache ( 100L )).willReturn (null ); // cache miss
289+ given (diaryCacheDao .getDiariesFromCacheBulk ( List . of ( 100L ))) .willReturn (List . of ());
296290 given (diaryService .getDiaries (List .of (100L ))).willReturn (Collections .emptyList ());
297291
298292 // when
0 commit comments