Adapt to luajava API changes

This commit is contained in:
Chris Eager authored and Chris Eager committed 2026-08-19 11:55:13 -04:00
1 parent 3ca228c0e3
commit 8d37c148d6
2 files changed
+19 -19

No files matched your search

@@ -6,6 +6,7 @@
package org.whispersystems.textsecuregcm.util.redis;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.whispersystems.textsecuregcm.util.redis.RedisLuaScriptSandbox.tail;
@@ -27,16 +28,16 @@ public class BaseRedisCommandsHandler implements RedisCommandsHandler {
}
case "GET" -> {
assertEquals(1, args.size());
yield get(args.get(0).toString());
yield get(args.getFirst().toString());
}
case "DEL" -> {
assertTrue(args.size() >= 1);
assertFalse(args.isEmpty());
yield del(args.stream().map(Object::toString).toList());
}
case "HSET" -> {
assertTrue(args.size() > 1);
assertTrue(args.size() % 2 == 1);
yield hset(args.get(0).toString(), tail(args, 1));
assertEquals(1, args.size() % 2);
yield hset(args.getFirst().toString(), tail(args, 1));
}
case "HGET" -> {
assertEquals(2, args.size());
@@ -44,7 +45,7 @@ public class BaseRedisCommandsHandler implements RedisCommandsHandler {
}
case "HMGET" -> {
assertTrue(args.size() > 1);
yield hmget(args.get(0).toString(), tail(args, 1));
yield hmget(args.getFirst().toString(), tail(args, 1));
}
case "PEXPIRE" -> {
assertEquals(2, args.size());
@@ -52,15 +53,15 @@ public class BaseRedisCommandsHandler implements RedisCommandsHandler {
}
case "TYPE" -> {
assertEquals(1, args.size());
yield type(args.get(0).toString());
yield type(args.getFirst().toString());
}
case "RPUSH" -> {
assertTrue(args.size() > 1);
yield push(false, args.get(0).toString(), tail(args, 1));
yield push(false, args.getFirst().toString(), tail(args, 1));
}
case "LPUSH" -> {
assertTrue(args.size() > 1);
yield push(true, args.get(0).toString(), tail(args, 1));
yield push(true, args.getFirst().toString(), tail(args, 1));
}
case "RPOP" -> {
assertEquals(2, args.size());
@@ -5,9 +5,9 @@
package org.whispersystems.textsecuregcm.util.redis;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.io.Resources;
@@ -27,7 +27,7 @@ public class RedisLuaScriptSandbox {
private static final String PREFIX = """
function redis_call(...)
-- variable name needs to match the one used in the `L.setGlobal()` call
-- method name needs to match method name of the Java class
-- method name needs to match method name of the Java class
local result = proxy:redisCall(arg)
if type(result) == "userdata" then
return java.luaify(result)
@@ -86,8 +86,7 @@ public class RedisLuaScriptSandbox {
lua.setGlobal("KEYS");
lua.push(args, Lua.Conversion.FULL);
lua.setGlobal("ARGV");
final Lua.LuaError executionResult = lua.run(PREFIX + luaScript);
assertEquals("OK", executionResult.name(), "Runtime error during Lua script execution");
assertDoesNotThrow(() -> lua.run(PREFIX + luaScript));
return adaptOutputResult(lua.get());
}
}
@@ -97,10 +96,10 @@ public class RedisLuaScriptSandbox {
final Object javaValue = luaValue.toJavaObject();
// validate expected script output type
switch (scriptOutputType) {
case INTEGER -> assertTrue(javaValue instanceof Double); // lua number is always Double
case STATUS -> assertTrue(javaValue instanceof String);
case BOOLEAN -> assertTrue(javaValue instanceof Boolean);
};
case INTEGER -> assertInstanceOf(Double.class, javaValue); // lua number is always Double
case STATUS -> assertInstanceOf(String.class, javaValue);
case BOOLEAN -> assertInstanceOf(Boolean.class, javaValue);
}
if (javaValue instanceof Double d) {
return d.longValue();
}
@@ -165,8 +164,8 @@ public class RedisLuaScriptSandbox {
@SuppressWarnings("unused")
public Object redisCall(final List<Object> args) {
assertFalse(args.isEmpty(), "`redis.call()` in Lua script invoked without arguments");
assertTrue(args.get(0) instanceof String, "first argument to `redis.call()` must be of type `String`");
return handler.redisCommand((String) args.get(0), tail(args, 1));
assertInstanceOf(String.class, args.getFirst(), "first argument to `redis.call()` must be of type `String`");
return handler.redisCommand((String) args.getFirst(), tail(args, 1));
}
}
}