Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java; Fix IT #2350

Merged
merged 8 commits into from
Oct 7, 2024
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rename the test if we are no longer passing in keys

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We pass it, but don't use it


// 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
Loading