Skip to content

Commit

Permalink
Spotless cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jduo committed Jun 27, 2024
1 parent 78cf5f2 commit 5530071
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 39 deletions.
6 changes: 4 additions & 2 deletions java/client/src/main/java/glide/api/BaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2810,8 +2810,10 @@ public CompletableFuture<Object[]> zscan(@NonNull String key, long cursor) {
}

@Override
public CompletableFuture<Object[]> zscan(@NonNull String key, long cursor, @NonNull ZScanOptions zscanOptions) {
String[] arguments = concatenateArrays(new String[] {key, Long.toString(cursor)}, zscanOptions.toArgs());
public CompletableFuture<Object[]> zscan(
@NonNull String key, long cursor, @NonNull ZScanOptions zscanOptions) {
String[] arguments =
concatenateArrays(new String[] {key, Long.toString(cursor)}, zscanOptions.toArgs());
return commandManager.submitNewCommand(ZScan, arguments, this::handleArrayResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import glide.api.models.commands.WeightAggregateOptions.WeightedKeys;
import glide.api.models.commands.ZAddOptions;
import glide.api.models.commands.scan.ZScanOptions;

import java.util.Map;
import java.util.concurrent.CompletableFuture;

Expand Down Expand Up @@ -1619,7 +1618,6 @@ CompletableFuture<Map<String, Double>> zinterWithScores(
* @param key The key of the set.
* @param cursor The cursor that points to the next iteration of results.
* @param zScanOptions The {@link ZScanOptions}.
*
* @return An <code>Array</code> of <code>Objects</code>. The first element is always the <code>
* cursor</code> for the next iteration of results. <code>0</code> will be the <code>cursor
* </code> returned on the last iteration of the set. The second element is always an <code>
Expand Down
13 changes: 6 additions & 7 deletions java/client/src/test/java/glide/api/RedisClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@
import glide.managers.CommandManager;
import glide.managers.ConnectionManager;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -9033,7 +9032,7 @@ public void zscan_returns_success() {

// match on protobuf request
when(commandManager.<Object[]>submitNewCommand(eq(ZScan), eq(arguments), any()))
.thenReturn(testResponse);
.thenReturn(testResponse);

// exercise
CompletableFuture<Object[]> response = service.zscan(key, cursor);
Expand All @@ -9051,21 +9050,21 @@ public void zscan_with_options_returns_success() {
String key = "testKey";
long cursor = 0;
String[] arguments =
new String[] {
key, Long.toString(cursor), MATCH_OPTION_STRING, "*", COUNT_OPTION_STRING, "1"
};
new String[] {
key, Long.toString(cursor), MATCH_OPTION_STRING, "*", COUNT_OPTION_STRING, "1"
};
Object[] value = new Object[] {0L, new String[] {"hello", "world"}};

CompletableFuture<Object[]> testResponse = new CompletableFuture<>();
testResponse.complete(value);

// match on protobuf request
when(commandManager.<Object[]>submitNewCommand(eq(ZScan), eq(arguments), any()))
.thenReturn(testResponse);
.thenReturn(testResponse);

// exercise
CompletableFuture<Object[]> response =
service.zscan(key, cursor, ZScanOptions.builder().matchPattern("*").count(1L).build());
service.zscan(key, cursor, ZScanOptions.builder().matchPattern("*").count(1L).build());
Object[] payload = response.get();

// verify
Expand Down
60 changes: 33 additions & 27 deletions java/integTest/src/test/java/glide/SharedCommandTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -7131,12 +7131,12 @@ public void zscan(BaseClient client) {

// Setup test data
Map<String, Double> numberMap = new HashMap<>();
for(Double i = 0.0; i < 125; i ++) {
for (Double i = 0.0; i < 125; i++) {
numberMap.put(String.valueOf(i), i);
}
String[] charMembers = new String[] {"a", "b", "c", "d", "e"};
Map<String, Double> charMap = new HashMap<>();
for(Double i = 0.0; i < 5; i ++) {
for (Double i = 0.0; i < 5; i++) {
charMap.put(charMembers[i.intValue()], i);
}

Expand All @@ -7154,13 +7154,19 @@ public void zscan(BaseClient client) {
assertEquals(charMembers.length, client.zadd(key1, charMap).get());
result = client.zscan(key1, initialCursor).get();
assertEquals(String.valueOf(initialCursor), result[resultCursorIndex]);
assertEquals(charMap.size() * 2, ((Object[]) result[resultCollectionIndex]).length); // Length includes the score which is twice the map size
assertEquals(
charMap.size() * 2,
((Object[]) result[resultCollectionIndex])
.length); // Length includes the score which is twice the map size
Arrays.stream((Object[]) result[resultCollectionIndex])
.forEach(member ->
assertTrue(charMap.containsKey(member) || charMap.containsValue(Double.valueOf(member.toString()))));
.forEach(
member ->
assertTrue(
charMap.containsKey(member)
|| charMap.containsValue(Double.valueOf(member.toString()))));

result =
client.zscan(key1, initialCursor, ZScanOptions.builder().matchPattern("a").build()).get();
client.zscan(key1, initialCursor, ZScanOptions.builder().matchPattern("a").build()).get();
assertEquals(String.valueOf(initialCursor), result[resultCursorIndex]);
assertDeepEquals(new String[] {"a", "0"}, result[resultCollectionIndex]);

Expand All @@ -7177,14 +7183,14 @@ public void zscan(BaseClient client) {
assertTrue(resultCursor != newResultCursor);
resultCursor = newResultCursor;
assertFalse(
Arrays.deepEquals(
ArrayUtils.toArray(result[resultCollectionIndex]),
ArrayUtils.toArray(secondResult[resultCollectionIndex])));
Arrays.deepEquals(
ArrayUtils.toArray(result[resultCollectionIndex]),
ArrayUtils.toArray(secondResult[resultCollectionIndex])));
} while (resultCursor != 0); // 0 is returned for the cursor of the last iteration.

// Test match pattern
result =
client.zscan(key1, initialCursor, ZScanOptions.builder().matchPattern("*").build()).get();
client.zscan(key1, initialCursor, ZScanOptions.builder().matchPattern("*").build()).get();
assertTrue(Long.valueOf(result[resultCursorIndex].toString()) > 0);
assertTrue(ArrayUtils.getLength(result[resultCollectionIndex]) >= defaultCount);

Expand All @@ -7195,37 +7201,37 @@ public void zscan(BaseClient client) {

// Test count with match returns a non-empty list
result =
client
.zscan(
key1, initialCursor, ZScanOptions.builder().matchPattern("1*").count(20L).build())
.get();
client
.zscan(
key1, initialCursor, ZScanOptions.builder().matchPattern("1*").count(20L).build())
.get();
assertTrue(Long.valueOf(result[resultCursorIndex].toString()) > 0);
assertTrue(ArrayUtils.getLength(result[resultCollectionIndex]) > 0);

// Exceptions
// Non-set key
assertEquals(OK, client.set(key2, "test").get());
ExecutionException executionException =
assertThrows(ExecutionException.class, () -> client.zscan(key2, initialCursor).get());
assertThrows(ExecutionException.class, () -> client.zscan(key2, initialCursor).get());
assertInstanceOf(RequestException.class, executionException.getCause());

executionException =
assertThrows(
ExecutionException.class,
() ->
client
.zscan(
key2,
initialCursor,
ZScanOptions.builder().matchPattern("test").count(1L).build())
.get());
assertThrows(
ExecutionException.class,
() ->
client
.zscan(
key2,
initialCursor,
ZScanOptions.builder().matchPattern("test").count(1L).build())
.get());
assertInstanceOf(RequestException.class, executionException.getCause());

// Negative count
executionException =
assertThrows(
ExecutionException.class,
() -> client.zscan(key1, -1, ZScanOptions.builder().count(-1L).build()).get());
assertThrows(
ExecutionException.class,
() -> client.zscan(key1, -1, ZScanOptions.builder().count(-1L).build()).get());
assertInstanceOf(RequestException.class, executionException.getCause());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,9 @@ private static Object[] sortedSetCommands(BaseTransaction<?> transaction) {
new String[] {"one"}, // .zrandmemberWithCount(zSetKey2, 1)
new Object[][] {{"one", 1.0}}, // .zrandmemberWithCountWithScores(zSetKey2, 1);
new Object[] {"0", new Object[] {"one", "1"}}, // zscan(zSetKey2, 0)
new Object[] {"0", new Object[] {"one", "1"}}, // zscan(zSetKey2, 0, ZScanOptions.builder().count(20L).build())
new Object[] {
"0", new Object[] {"one", "1"}
}, // zscan(zSetKey2, 0, ZScanOptions.builder().count(20L).build())
new Object[] {zSetKey2, "one", 1.0}, // bzpopmin(new String[] { zsetKey2 }, .1)
};

Expand Down

0 comments on commit 5530071

Please sign in to comment.