Skip to content

Commit

Permalink
Java; Fix IT (valkey-io#2350)
Browse files Browse the repository at this point in the history
Signed-off-by: Yury-Fridlyand <[email protected]>
Co-authored-by: Andrew Carbonetto <[email protected]>
  • Loading branch information
Yury-Fridlyand and acarbonetto authored Oct 7, 2024
1 parent 8cf1277 commit 615034f
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions java/integTest/src/test/java/glide/cluster/CommandTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -1604,43 +1604,42 @@ public void fcall_binary_with_keys(String prefix) {
assumeTrue(SERVER_VERSION.isGreaterThanOrEqualTo("7.0.0"), "This feature added in version 7");

String key = "{" + prefix + "}-fcall_with_keys-";
GlideString binaryString =
gs(new byte[] {(byte) 0xFE, (byte) 0xEE, (byte) 0xEF, (byte) 252, (byte) 0});
SingleNodeRoute route = new SlotKeyRoute(key, PRIMARY);
String libName = "mylib_with_keys";
GlideString funcName = gs("myfunc_with_keys");
// function $funcName returns array with first two arguments
String libName = "mylib_with_keys_" + prefix;
GlideString funcName = gs("myfunc_with_keys_" + prefix);
// function $funcName returns array with first argument
String code =
generateLuaLibCode(libName, Map.of(funcName.toString(), "return {keys[1], keys[2]}"), true);
generateLuaLibCode(libName, Map.of(funcName.toString(), "return {args[1]}"), true);

// loading function to the node where key is stored
assertEquals(libName, clusterClient.functionLoad(code, false, route).get());

// due to common prefix, all keys are mapped to the same hash slot
var functionResult =
clusterClient
.fcall(funcName, new GlideString[] {gs(key + 1), gs(key + 2)}, new GlideString[0])
.fcall(funcName, new GlideString[] {gs(key)}, new GlideString[] {binaryString})
.get();
assertArrayEquals(new Object[] {gs(key + 1), gs(key + 2)}, (Object[]) functionResult);
assertArrayEquals(new Object[] {binaryString}, (Object[]) functionResult);
functionResult =
clusterClient
.fcallReadOnly(
funcName, new GlideString[] {gs(key + 1), gs(key + 2)}, new GlideString[0])
.fcallReadOnly(funcName, new GlideString[] {gs(key)}, new GlideString[] {binaryString})
.get();
assertArrayEquals(new Object[] {gs(key + 1), gs(key + 2)}, (Object[]) functionResult);

// TODO: change to binary transaction version once available:
// var transaction =
// new ClusterTransaction()
// .fcall(funcName, new String[] {key + 1, key + 2}, new String[0])
// .fcallReadOnly(funcName, new String[] {key + 1, key + 2}, new String[0]);

// // check response from a routed transaction request
// assertDeepEquals(
// new Object[][] {{key + 1, key + 2}, {key + 1, key + 2}},
// clusterClient.exec(transaction, route).get());
// // if no route given, GLIDE should detect it automatically
// assertDeepEquals(
// new Object[][] {{key + 1, key + 2}, {key + 1, key + 2}},
// clusterClient.exec(transaction).get());
assertArrayEquals(new Object[] {binaryString}, (Object[]) functionResult);

var transaction =
new ClusterTransaction()
.withBinaryOutput()
.fcall(funcName, new GlideString[] {gs(key)}, new GlideString[] {binaryString})
.fcallReadOnly(funcName, new GlideString[] {gs(key)}, new GlideString[] {binaryString});

// check response from a routed transaction request
assertDeepEquals(
new Object[][] {{binaryString}, {binaryString}},
clusterClient.exec(transaction, route).get());
// if no route given, GLIDE should detect it automatically
assertDeepEquals(
new Object[][] {{binaryString}, {binaryString}}, clusterClient.exec(transaction).get());

assertEquals(OK, clusterClient.functionDelete(libName, route).get());
}
Expand All @@ -1649,9 +1648,6 @@ public void fcall_binary_with_keys(String prefix) {
@Test
public void fcall_readonly_function() {
assumeTrue(SERVER_VERSION.isGreaterThanOrEqualTo("7.0.0"), "This feature added in version 7");
assumeTrue(
!SERVER_VERSION.isGreaterThanOrEqualTo("8.0.0"),
"Temporary disabeling this test on valkey 8");

String libName = "fcall_readonly_function";
// intentionally using a REPLICA route
Expand All @@ -1663,6 +1659,8 @@ public void fcall_readonly_function() {
String code = generateLuaLibCode(libName, Map.of(funcName, "return 42"), false);

assertEquals(libName, clusterClient.functionLoad(code, false).get());
// let replica sync with the primary node
assertEquals(1L, clusterClient.wait(1L, 3000L).get());

// fcall on a replica node should fail, because a function isn't guaranteed to be RO
var executionException =
Expand Down

0 comments on commit 615034f

Please sign in to comment.