Skip to content

Commit

Permalink
add to integration tests the use of the API with GlideString parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Jun 25, 2024
1 parent 8b67e93 commit b44eee2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
4 changes: 1 addition & 3 deletions java/client/src/main/java/glide/api/BaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -936,9 +936,7 @@ public CompletableFuture<String> ltrim(@NonNull String key, long start, long end
public CompletableFuture<String> ltrim(@NonNull GlideString key, long start, long end) {
return commandManager.submitNewCommand(
LTrim,
new GlideString[] {
key, gs(Long.toString(start).getBytes()), gs(Long.toString(end).getBytes())
},
new GlideString[] {key, gs(Long.toString(start)), gs(Long.toString(end))},
this::handleStringResponse);
}

Expand Down
4 changes: 1 addition & 3 deletions java/client/src/main/java/glide/api/RedisClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,7 @@ public CompletableFuture<Boolean> move(@NonNull String key, long dbIndex) {
@Override
public CompletableFuture<Boolean> move(@NonNull GlideString key, long dbIndex) {
return commandManager.submitNewCommand(
Move,
new GlideString[] {key, gs(Long.toString(dbIndex).getBytes())},
this::handleBooleanResponse);
Move, new GlideString[] {key, gs(Long.toString(dbIndex))}, this::handleBooleanResponse);
}

@Override
Expand Down
10 changes: 5 additions & 5 deletions java/integTest/src/test/java/glide/SharedCommandTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ public void ltrim_existing_non_existing_key_and_type_error(BaseClient client) {
assertArrayEquals(new String[] {"value1", "value2"}, client.lrange(key, 0, -1).get());

// `start` is greater than `end` so the key will be removed.
assertEquals(OK, client.ltrim(key, 4, 2).get());
assertEquals(OK, client.ltrim(gs(key), 4, 2).get());
assertArrayEquals(new String[] {}, client.lrange(key, 0, -1).get());

assertEquals(OK, client.set(key, "foo").get());
Expand Down Expand Up @@ -1288,7 +1288,7 @@ public void sadd_srem_scard_smembers_existing_set(BaseClient client) {
Set<GlideString> expectedMembersBin = Set.of(gs("member1"), gs("member2"), gs("member4"));
assertEquals(expectedMembersBin, client.smembers(gs(key)).get());

assertEquals(1, client.srem(key, new String[] {"member1"}).get());
assertEquals(1, client.srem(gs(key), new GlideString[] {gs("member1")}).get());
assertEquals(2, client.scard(key).get());
}

Expand Down Expand Up @@ -1331,11 +1331,11 @@ public void smove(BaseClient client) {
String setKey3 = "{key}" + UUID.randomUUID();
String nonSetKey = "{key}" + UUID.randomUUID();

assertEquals(3, client.sadd(setKey1, new String[] {"1", "2", "3"}).get());
assertEquals(2, client.sadd(setKey2, new String[] {"2", "3"}).get());
assertEquals(3, client.sadd(gs(setKey1), new GlideString[] {gs("1"), gs("2"), gs("3")}).get());
assertEquals(2, client.sadd(gs(setKey2), new GlideString[] {gs("2"), gs("3")}).get());

// move an elem
assertTrue(client.smove(setKey1, setKey2, "1").get());
assertTrue(client.smove(gs(setKey1), gs(setKey2), gs("1")).get());
assertEquals(Set.of("2", "3"), client.smembers(setKey1).get());
assertEquals(Set.of("1", "2", "3"), client.smembers(setKey2).get());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import glide.api.RedisClient;
import glide.api.models.GlideString;
import glide.api.models.commands.InfoOptions;
import glide.api.models.commands.SortOptions;
import glide.api.models.exceptions.RequestException;
Expand Down Expand Up @@ -180,15 +181,15 @@ public void move() {
assertEquals(false, regularClient.move(nonExistingKey, 1L).get());
assertEquals(OK, regularClient.set(key1, value1).get());
assertEquals(OK, regularClient.set(key2, value2).get());
assertEquals(true, regularClient.move(key1, 1L).get());
assertEquals(true, regularClient.move(GlideString.gs(key1), 1L).get());
assertNull(regularClient.get(key1).get());

assertEquals(OK, regularClient.select(1).get());
assertEquals(value1, regularClient.get(key1).get());

assertEquals(OK, regularClient.set(key2, value2).get());
// Move does not occur because key2 already exists in DB 0
assertEquals(false, regularClient.move(key2, 0).get());
assertEquals(false, regularClient.move(GlideString.gs(key2), 0).get());
assertEquals(value2, regularClient.get(key2).get());

// Incorrect argument - DB index must be non-negative
Expand Down

0 comments on commit b44eee2

Please sign in to comment.