Skip to content

Commit 648e35a

Browse files
DATAREDIS-479 - Polishing.
Assert that not all values of a scan operation are captured by the first result and add tests to also run using the lettuce driver. Original Pull Request: #178
1 parent 77de777 commit 648e35a

File tree

3 files changed

+69
-23
lines changed

3 files changed

+69
-23
lines changed

src/test/java/org/springframework/data/redis/connection/ClusterConnectionTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,11 @@ public interface ClusterConnectionTests {
675675
*/
676676
void zInterStoreShouldThrowExceptionWhenKeysDoNotMapToSameSlots();
677677

678+
/**
679+
* @see DATAREDIS-479
680+
*/
681+
void zScanShouldReadEntireValueRange();
682+
678683
/**
679684
* @see DATAREDIS-315
680685
*/
@@ -745,6 +750,11 @@ public interface ClusterConnectionTests {
745750
*/
746751
void hGetAllShouldRetrieveEntriesCorrectly();
747752

753+
/**
754+
* @see DATAREDIS-479
755+
*/
756+
public void hScanShouldReadEntireValueRange();
757+
748758
/**
749759
* @see DATAREDIS-315
750760
*/

src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import static org.hamcrest.number.IsCloseTo.*;
2121
import static org.junit.Assert.*;
2222
import static org.springframework.data.redis.connection.ClusterTestVariables.*;
23-
import static org.springframework.data.redis.core.ScanOptions.scanOptions;
23+
import static org.springframework.data.redis.core.ScanOptions.*;
2424

2525
import java.io.IOException;
2626
import java.util.Arrays;
@@ -1770,32 +1770,28 @@ public void zInterStoreShouldWorkForSameSlotKeys() {
17701770
public void zInterStoreShouldThrowExceptionWhenKeysDoNotMapToSameSlots() {
17711771
clusterConnection.zInterStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES);
17721772
}
1773-
1774-
1773+
17751774
/**
17761775
* @see DATAREDIS-479
17771776
*/
17781777
@Test
17791778
public void zScanShouldReadEntireValueRange() {
17801779

1781-
nativeConnection.zadd(KEY_1_BYTES, 2, VALUE_1_BYTES);
1782-
nativeConnection.zadd(KEY_1_BYTES, 1, VALUE_2_BYTES);
1783-
nativeConnection.zadd(KEY_1_BYTES, 4, VALUE_3_BYTES);
1780+
int nrOfValues = 321;
1781+
for (int i = 0; i < nrOfValues; i++) {
1782+
nativeConnection.zadd(KEY_1_BYTES, i, JedisConverters.toBytes("value-" + i));
1783+
}
17841784

17851785
Cursor<Tuple> tuples = clusterConnection.zScan(KEY_1_BYTES, ScanOptions.NONE);
17861786

17871787
int count = 0;
17881788
while (tuples.hasNext()) {
17891789

1790-
Tuple tuple = tuples.next();
1791-
1792-
assertThat(tuple.getValue(), anyOf(equalTo(VALUE_1_BYTES), equalTo(VALUE_2_BYTES), equalTo(VALUE_3_BYTES)));
1793-
assertThat(tuple.getScore(), anyOf(equalTo(1D), equalTo(2D), equalTo(4D)));
1794-
1790+
tuples.next();
17951791
count++;
17961792
}
17971793

1798-
assertThat(count, equalTo(3));
1794+
assertThat(count, equalTo(nrOfValues));
17991795
}
18001796

18011797
/**
@@ -1980,31 +1976,29 @@ public void hGetAllShouldRetrieveEntriesCorrectly() {
19801976
assertThat(hGetAll.containsKey(KEY_2_BYTES), is(true));
19811977
assertThat(hGetAll.containsKey(KEY_3_BYTES), is(true));
19821978
}
1983-
1979+
19841980
/**
19851981
* @see DATAREDIS-479
19861982
*/
19871983
@Test
19881984
public void hScanShouldReadEntireValueRange() {
19891985

1990-
clusterConnection.hSet(KEY_1_BYTES, KEY_1_BYTES, VALUE_1_BYTES);
1991-
clusterConnection.hSet(KEY_1_BYTES, KEY_2_BYTES, VALUE_2_BYTES);
1992-
clusterConnection.hSet(KEY_1_BYTES, KEY_3_BYTES, VALUE_3_BYTES);
1986+
int nrOfValues = 321;
1987+
for (int i = 0; i < nrOfValues; i++) {
1988+
nativeConnection.hset(KEY_1_BYTES, JedisConverters.toBytes("key" + i), JedisConverters.toBytes("value-" + i));
1989+
}
19931990

1994-
Cursor<Map.Entry<byte[], byte[]>> cursor = clusterConnection
1995-
.hScan(KEY_1_BYTES, scanOptions().match("key*").build());
1991+
Cursor<Map.Entry<byte[], byte[]>> cursor = clusterConnection.hScan(KEY_1_BYTES,
1992+
scanOptions().match("key*").build());
19961993

19971994
int i = 0;
19981995
while (cursor.hasNext()) {
19991996

2000-
byte[] key = cursor.next().getKey();
2001-
2002-
assertThat(key, anyOf(equalTo(KEY_1_BYTES), equalTo(KEY_2_BYTES), equalTo(KEY_3_BYTES)));
2003-
1997+
cursor.next();
20041998
i++;
20051999
}
20062000

2007-
assertThat(i, is(3));
2001+
assertThat(i, is(nrOfValues));
20082002
}
20092003

20102004
/**

src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionTests.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.hamcrest.number.IsCloseTo.*;
2121
import static org.junit.Assert.*;
2222
import static org.springframework.data.redis.connection.ClusterTestVariables.*;
23+
import static org.springframework.data.redis.core.ScanOptions.*;
2324

2425
import java.util.Collection;
2526
import java.util.Collections;
@@ -1762,6 +1763,26 @@ public void zInterStoreShouldThrowExceptionWhenKeysDoNotMapToSameSlots() {
17621763
clusterConnection.zInterStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES);
17631764
}
17641765

1766+
@Test
1767+
public void zScanShouldReadEntireValueRange() {
1768+
1769+
int nrOfValues = 321;
1770+
for (int i = 0; i < nrOfValues; i++) {
1771+
nativeConnection.zadd(KEY_1, i, "value-" + i);
1772+
}
1773+
1774+
Cursor<Tuple> tuples = clusterConnection.zScan(KEY_1_BYTES, ScanOptions.NONE);
1775+
1776+
int count = 0;
1777+
while (tuples.hasNext()) {
1778+
1779+
tuples.next();
1780+
count++;
1781+
}
1782+
1783+
assertThat(count, equalTo(nrOfValues));
1784+
}
1785+
17651786
/**
17661787
* @see DATAREDIS-315
17671788
*/
@@ -1944,6 +1965,27 @@ public void hGetAllShouldRetrieveEntriesCorrectly() {
19441965
assertThat(hGetAll.keySet(), hasItems(KEY_2_BYTES, KEY_3_BYTES));
19451966
}
19461967

1968+
@Test
1969+
public void hScanShouldReadEntireValueRange() {
1970+
1971+
int nrOfValues = 321;
1972+
for (int i = 0; i < nrOfValues; i++) {
1973+
nativeConnection.hset(KEY_1, "key" + i, "value-" + i);
1974+
}
1975+
1976+
Cursor<Map.Entry<byte[], byte[]>> cursor = clusterConnection.hScan(KEY_1_BYTES,
1977+
scanOptions().match("key*").build());
1978+
1979+
int i = 0;
1980+
while (cursor.hasNext()) {
1981+
1982+
cursor.next();
1983+
i++;
1984+
}
1985+
1986+
assertThat(i, is(nrOfValues));
1987+
}
1988+
19471989
/**
19481990
* @see DATAREDIS-315
19491991
*/

0 commit comments

Comments
 (0)