From 8d37c148d6c3c50a8218aeef64e44a272014ab15 Mon Sep 17 00:00:00 2001 From: Chris Eager Date: Wed, 19 Aug 2026 11:23:26 -0400 Subject: [PATCH] Adapt to luajava API changes --- .../util/redis/BaseRedisCommandsHandler.java | 17 ++++++++------- .../util/redis/RedisLuaScriptSandbox.java | 21 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/util/redis/BaseRedisCommandsHandler.java b/service/src/test/java/org/whispersystems/textsecuregcm/util/redis/BaseRedisCommandsHandler.java index 8343722b1..b4a0cdcee 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/util/redis/BaseRedisCommandsHandler.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/util/redis/BaseRedisCommandsHandler.java @@ -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()); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/util/redis/RedisLuaScriptSandbox.java b/service/src/test/java/org/whispersystems/textsecuregcm/util/redis/RedisLuaScriptSandbox.java index 734617ed5..56ef39ccd 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/util/redis/RedisLuaScriptSandbox.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/util/redis/RedisLuaScriptSandbox.java @@ -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 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)); } } }