|
128 | 128 | import static redis_request.RedisRequestOuterClass.RequestType.ZMScore; |
129 | 129 | import static redis_request.RedisRequestOuterClass.RequestType.ZPopMax; |
130 | 130 | import static redis_request.RedisRequestOuterClass.RequestType.ZPopMin; |
| 131 | +import static redis_request.RedisRequestOuterClass.RequestType.ZRandMember; |
131 | 132 | import static redis_request.RedisRequestOuterClass.RequestType.ZRangeStore; |
132 | 133 | import static redis_request.RedisRequestOuterClass.RequestType.ZRemRangeByLex; |
133 | 134 | import static redis_request.RedisRequestOuterClass.RequestType.ZRemRangeByRank; |
@@ -3252,11 +3253,84 @@ public void xadd_returns_success() { |
3252 | 3253 |
|
3253 | 3254 | // exercise |
3254 | 3255 | CompletableFuture<String> response = service.xadd(key, fieldValues); |
| 3256 | + |
| 3257 | + // verify |
| 3258 | + assertEquals(testResponse, response); |
| 3259 | + assertEquals(returnId, response.get()); |
| 3260 | + } |
| 3261 | + |
| 3262 | + @SneakyThrows |
| 3263 | + @Test |
| 3264 | + public void zrandmember_returns_success() { |
| 3265 | + // setup |
| 3266 | + String key = "testKey"; |
| 3267 | + String[] arguments = new String[] {key}; |
| 3268 | + String value = "testValue"; |
| 3269 | + |
| 3270 | + CompletableFuture<String> testResponse = new CompletableFuture<>(); |
| 3271 | + testResponse.complete(value); |
| 3272 | + |
| 3273 | + // match on protobuf request |
| 3274 | + when(commandManager.<String>submitNewCommand(eq(ZRandMember), eq(arguments), any())) |
| 3275 | + .thenReturn(testResponse); |
| 3276 | + |
| 3277 | + // exercise |
| 3278 | + CompletableFuture<String> response = service.zrandmember(key); |
3255 | 3279 | String payload = response.get(); |
3256 | 3280 |
|
3257 | 3281 | // verify |
3258 | 3282 | assertEquals(testResponse, response); |
3259 | | - assertEquals(returnId, payload); |
| 3283 | + assertEquals(value, payload); |
| 3284 | + } |
| 3285 | + |
| 3286 | + @SneakyThrows |
| 3287 | + @Test |
| 3288 | + public void zrandmemberWithCount_returns_success() { |
| 3289 | + // setup |
| 3290 | + String key = "testKey"; |
| 3291 | + long count = 2L; |
| 3292 | + String[] arguments = new String[] {key, Long.toString(count)}; |
| 3293 | + String[] value = new String[] {"member1", "member2"}; |
| 3294 | + |
| 3295 | + CompletableFuture<String[]> testResponse = new CompletableFuture<>(); |
| 3296 | + testResponse.complete(value); |
| 3297 | + |
| 3298 | + // match on protobuf request |
| 3299 | + when(commandManager.<String[]>submitNewCommand(eq(ZRandMember), eq(arguments), any())) |
| 3300 | + .thenReturn(testResponse); |
| 3301 | + |
| 3302 | + // exercise |
| 3303 | + CompletableFuture<String[]> response = service.zrandmemberWithCount(key, count); |
| 3304 | + String[] payload = response.get(); |
| 3305 | + |
| 3306 | + // verify |
| 3307 | + assertEquals(testResponse, response); |
| 3308 | + assertEquals(value, payload); |
| 3309 | + } |
| 3310 | + |
| 3311 | + @SneakyThrows |
| 3312 | + @Test |
| 3313 | + public void zrandmemberWithCountWithScores_returns_success() { |
| 3314 | + // setup |
| 3315 | + String key = "testKey"; |
| 3316 | + long count = 2L; |
| 3317 | + String[] arguments = new String[] {key, Long.toString(count), WITH_SCORES_REDIS_API}; |
| 3318 | + Object[][] value = new Object[][] {{"member1", 2.0}, {"member2", 3.0}}; |
| 3319 | + |
| 3320 | + CompletableFuture<Object[][]> testResponse = new CompletableFuture<>(); |
| 3321 | + testResponse.complete(value); |
| 3322 | + |
| 3323 | + // match on protobuf request |
| 3324 | + when(commandManager.<Object[][]>submitNewCommand(eq(ZRandMember), eq(arguments), any())) |
| 3325 | + .thenReturn(testResponse); |
| 3326 | + |
| 3327 | + // exercise |
| 3328 | + CompletableFuture<Object[][]> response = service.zrandmemberWithCountWithScores(key, count); |
| 3329 | + Object[] payload = response.get(); |
| 3330 | + |
| 3331 | + // verify |
| 3332 | + assertEquals(testResponse, response); |
| 3333 | + assertEquals(value, payload); |
3260 | 3334 | } |
3261 | 3335 |
|
3262 | 3336 | private static List<Arguments> getStreamAddOptions() { |
|
0 commit comments