Polishing.

Add since tags. Consistently document scan command with try-with-resources guidance. Use try-with-resources in tests.

See #2260
Original pull request: #2263.
This commit is contained in:
Mark Paluch
2022-02-23 15:25:23 +01:00
parent 04165fb747
commit e31d122e54
12 changed files with 67 additions and 44 deletions

View File

@@ -131,17 +131,18 @@ public class DefaultHashOperationsIntegrationTests<K, HK, HV> {
hashOps.put(key, key1, val1);
hashOps.put(key, key2, val2);
Cursor<Map.Entry<HK, HV>> it = hashOps.scan(key, ScanOptions.scanOptions().count(1).build());
long count = 0;
while (it.hasNext()) {
Map.Entry<HK, HV> entry = it.next();
assertThat(entry.getKey()).isIn(key1, key2);
assertThat(entry.getValue()).isIn(val1, val2);
count++;
try (Cursor<Map.Entry<HK, HV>> it = hashOps.scan(key, ScanOptions.scanOptions().count(1).build())) {
while (it.hasNext()) {
Map.Entry<HK, HV> entry = it.next();
assertThat(entry.getKey()).isIn(key1, key2);
assertThat(entry.getValue()).isIn(val1, val2);
count++;
}
}
it.close();
assertThat(count).isEqualTo(hashOps.size(key));
}

View File

@@ -208,13 +208,14 @@ public class DefaultSetOperationsIntegrationTests<K, V> {
V v3 = valueFactory.instance();
setOps.add(key, v1, v2, v3);
Cursor<V> it = setOps.scan(key, ScanOptions.scanOptions().count(1).build());
long count = 0;
while (it.hasNext()) {
assertThat(it.next()).isIn(v1, v2, v3);
count++;
try (Cursor<V> it = setOps.scan(key, ScanOptions.scanOptions().count(1).build())) {
while (it.hasNext()) {
assertThat(it.next()).isIn(v1, v2, v3);
count++;
}
}
it.close();
assertThat(count).isEqualTo(setOps.size(key));
}

View File

@@ -497,13 +497,13 @@ public class DefaultZSetOperationsIntegrationTests<K, V> {
zSetOps.add(key, values);
int count = 0;
Cursor<TypedTuple<V>> it = zSetOps.scan(key, ScanOptions.scanOptions().count(2).build());
while (it.hasNext()) {
assertThat(it.next()).isIn(tuple1, tuple2, tuple3);
count++;
try (Cursor<TypedTuple<V>> it = zSetOps.scan(key, ScanOptions.scanOptions().count(2).build())) {
while (it.hasNext()) {
assertThat(it.next()).isIn(tuple1, tuple2, tuple3);
count++;
}
}
it.close();
assertThat(count).isEqualTo(3);
}

View File

@@ -16,6 +16,7 @@
package org.springframework.data.redis.core;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assumptions.*;
import java.util.Arrays;
import java.util.Collection;
@@ -141,6 +142,14 @@ public class RedisClusterTemplateIntegrationTests<K, V> extends RedisTemplateInt
super.testGetExpireMillisUsingPipelining();
}
@ParameterizedRedisTest
void testScan() {
// Only Lettuce supports cluster-wide scanning
assumeThat(redisTemplate.getConnectionFactory()).isInstanceOf(LettuceConnectionFactory.class);
super.testScan();
}
@Parameters
public static Collection<Object[]> testParams() {

View File

@@ -133,13 +133,13 @@ public class RedisTemplateIntegrationTests<K, V> {
V value1 = valueFactory.instance();
assumeThat(key1 instanceof String || key1 instanceof byte[]).isTrue();
redisTemplate.opsForValue().set(key1, value1);
Cursor<K> cursor = redisTemplate.scan(ScanOptions.scanOptions().count(1).build());
long count = 0;
while (cursor.hasNext()) {
assertThat(cursor.next()).isEqualTo(key1);
count++;
try (Cursor<K> cursor = redisTemplate.scan(ScanOptions.scanOptions().count(1).build())) {
while (cursor.hasNext()) {
assertThat(cursor.next()).isEqualTo(key1);
count++;
}
}
cursor.close();
assertThat(count).isEqualTo(1);
}